blob: dc6326a684a4d4cdfb115caa412884e61bfa31d0 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill6d32cef2018-08-14 02:34:28 -040044#include "libANGLE/renderer/BufferImpl.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/renderer/ContextImpl.h"
46#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040047#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040048#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000049
Geoff Langf6db0982015-08-25 13:04:00 -040050namespace
51{
52
Jamie Madillb6664922017-07-25 12:55:04 -040053#define ANGLE_HANDLE_ERR(X) \
54 handleError(X); \
55 return;
56#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
57
Ian Ewell3ffd78b2016-01-22 16:09:42 -050058template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050059std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030060 GLsizei numPaths,
61 const void *paths,
62 GLuint pathBase)
63{
64 std::vector<gl::Path *> ret;
65 ret.reserve(numPaths);
66
67 const auto *nameArray = static_cast<const T *>(paths);
68
69 for (GLsizei i = 0; i < numPaths; ++i)
70 {
71 const GLuint pathName = nameArray[i] + pathBase;
72
73 ret.push_back(resourceManager.getPath(pathName));
74 }
75
76 return ret;
77}
78
Geoff Lang4ddf5af2016-12-01 14:30:44 -050079std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030080 GLsizei numPaths,
81 GLenum pathNameType,
82 const void *paths,
83 GLuint pathBase)
84{
85 switch (pathNameType)
86 {
87 case GL_UNSIGNED_BYTE:
88 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_BYTE:
91 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_UNSIGNED_SHORT:
94 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_SHORT:
97 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_UNSIGNED_INT:
100 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
101
102 case GL_INT:
103 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
104 }
105
106 UNREACHABLE();
107 return std::vector<gl::Path *>();
108}
109
110template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400111gl::Error GetQueryObjectParameter(const gl::Context *context,
112 gl::Query *query,
113 GLenum pname,
114 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115{
Geoff Lang2186c382016-10-14 10:54:54 -0400116 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117
118 switch (pname)
119 {
120 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400121 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 case GL_QUERY_RESULT_AVAILABLE_EXT:
123 {
124 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400125 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 if (!error.isError())
127 {
jchen10a99ed552017-09-22 08:10:32 +0800128 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130 return error;
131 }
132 default:
133 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500134 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500135 }
136}
137
Jamie Madill09463932018-04-04 05:26:59 -0400138void MarkTransformFeedbackBufferUsage(const gl::Context *context,
139 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700140 GLsizei count,
141 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400142{
Geoff Lang1a683462015-09-29 15:09:59 -0400143 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400144 {
Jamie Madill09463932018-04-04 05:26:59 -0400145 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
Jamie Madill4230d482018-09-14 10:14:45 -0400201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
Jamie Madill4230d482018-09-14 10:14:45 -0400213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600262constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400263 1, /* Points */
264 2, /* Lines */
265 2, /* LineLoop */
266 2, /* LineStrip */
267 3, /* Triangles */
268 3, /* TriangleStrip */
269 3, /* TriangleFan */
270 2, /* LinesAdjacency */
271 2, /* LineStripAdjacency */
272 3, /* TrianglesAdjacency */
273 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600274}};
275// Indices above are code-gen'd so make sure they don't change
276// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
277static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
298 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
299static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
300 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
301
Jamie Madill6d32cef2018-08-14 02:34:28 -0400302enum SubjectIndexes : angle::SubjectIndex
303{
304 kTexture0SubjectIndex = 0,
305 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
306 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
307 kUniformBufferMaxSubjectIndex =
308 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
309 kVertexArraySubjectIndex = kUniformBufferMaxSubjectIndex,
310 kReadFramebufferSubjectIndex,
311 kDrawFramebufferSubjectIndex
312};
Geoff Langf6db0982015-08-25 13:04:00 -0400313} // anonymous namespace
314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315namespace gl
316{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000317
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400318Context::Context(rx::EGLImplFactory *implFactory,
319 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400320 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500321 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400322 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500323 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700324 const egl::DisplayExtensions &displayExtensions,
325 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500326 : mState(reinterpret_cast<ContextID>(this),
327 shareContext ? &shareContext->mState : nullptr,
328 shareTextures,
329 GetClientVersion(attribs),
330 &mGLState,
331 mCaps,
332 mTextureCaps,
333 mExtensions,
334 mLimitations),
335 mSkipValidation(GetNoError(attribs)),
336 mDisplayTextureShareGroup(shareTextures != nullptr),
337 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400338 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400339 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400340 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400341 mGLState(GetDebug(attribs),
342 GetBindGeneratesResource(attribs),
343 GetClientArraysEnabled(attribs),
344 GetRobustResourceInit(attribs),
345 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400346 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500347 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400348 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mHasBeenCurrent(false),
350 mContextLost(false),
351 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700352 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500353 mResetStrategy(GetResetStrategy(attribs)),
354 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355 mSurfacelessSupported(displayExtensions.surfacelessContext),
356 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400357 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
358 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500359 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400360 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400361 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400362 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400363 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
364 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
365 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400366 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800367 mZeroFilledBuffer(1000u),
368 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369{
Jamie Madill5b772312018-03-08 20:28:32 -0500370 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400371 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
372 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400373
374 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
375 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
376 {
377 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
378 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400379}
Jamie Madill5b772312018-03-08 20:28:32 -0500380
Geoff Lang33f11fb2018-05-07 13:42:47 -0400381void Context::initialize()
382{
383 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400384
Geoff Lang33f11fb2018-05-07 13:42:47 -0400385 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700386 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400387
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400388 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100389
Shannon Woods53a94a82014-06-24 15:20:36 -0400390 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400391
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000392 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400393 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000394 // and cube map texture state vectors respectively associated with them.
395 // In order that access to these initial textures not be lost, they are treated as texture
396 // objects all of whose names are 0.
397
Corentin Wallez99d492c2018-02-27 15:17:10 -0500398 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500400
Corentin Wallez99d492c2018-02-27 15:17:10 -0500401 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800402 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400403
Geoff Langeb66a6e2016-10-31 13:06:12 -0400404 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400405 {
406 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500407 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800408 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400409
Corentin Wallez99d492c2018-02-27 15:17:10 -0500410 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800411 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400412 }
Geoff Lang3b573612016-10-31 14:08:10 -0400413 if (getClientVersion() >= Version(3, 1))
414 {
Olli Etuahod310a432018-08-24 15:40:23 +0300415 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400416 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500417 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800418 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300419 Texture *zeroTexture2DMultisampleArray =
420 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
421 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800422
Jiajia Qin6eafb042016-12-27 17:04:07 +0800423 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
424 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800425 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800426 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800427
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800428 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
429 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400430 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800431 }
Geoff Lang3b573612016-10-31 14:08:10 -0400432 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433
Geoff Langb0f917f2017-12-05 13:41:54 -0500434 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400435 {
436 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500437 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800438 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400439 }
440
Geoff Langb0f917f2017-12-05 13:41:54 -0500441 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400442 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500443 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800444 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400445 }
446
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500448
Jamie Madill57a89722013-07-02 11:57:03 -0400449 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000450
Geoff Langeb66a6e2016-10-31 13:06:12 -0400451 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400452 {
453 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
454 // In the initial state, a default transform feedback object is bound and treated as
455 // a transform feedback object with a name of zero. That object is bound any time
456 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400457 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400458 }
Geoff Langc8058452014-02-03 12:04:11 -0500459
Corentin Wallez336129f2017-10-17 15:55:40 -0400460 for (auto type : angle::AllEnums<BufferBinding>())
461 {
462 bindBuffer(type, 0);
463 }
464
465 bindRenderbuffer(GL_RENDERBUFFER, 0);
466
467 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
468 {
469 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
470 }
471
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700472 // Initialize GLES1 renderer if appropriate.
473 if (getClientVersion() < Version(2, 0))
474 {
475 mGLES1Renderer.reset(new GLES1Renderer());
476 }
477
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400482 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400483
484 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
485 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
486 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
487
Jamie Madillc67323a2017-11-02 23:11:41 -0400488 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500489 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500490 // No dirty objects.
491
492 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400493 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500494 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400495 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500496 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
497
498 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
499 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
500 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
501 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
502 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
503 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
504 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
505 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
506 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
507 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
508 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400509 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500510 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
511
512 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
513 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700514 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400515 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
516 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500517 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
518 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400519
Xinghua Cao10a4d432017-11-28 14:46:26 +0800520 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
521 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
522 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
523 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
524 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
525 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800526 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800527 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400528 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800529
Jamie Madillb4927eb2018-07-16 11:39:46 -0400530 mImplementation->setErrorSet(&mErrors);
531
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400532 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000533}
534
Jamie Madill4928b7c2017-06-20 12:57:39 -0400535egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700537 if (mGLES1Renderer)
538 {
539 mGLES1Renderer->onDestroy(this, &mGLState);
540 }
541
Jamie Madille7b3fe22018-04-05 09:42:46 -0400542 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400543 ANGLE_TRY(releaseSurface(display));
544
Corentin Wallez80b24112015-08-25 16:41:57 -0400545 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400547 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400549 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550
Corentin Wallez80b24112015-08-25 16:41:57 -0400551 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000552 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400553 if (query.second != nullptr)
554 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400556 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400558 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559
Corentin Wallez80b24112015-08-25 16:41:57 -0400560 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400561 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400562 if (vertexArray.second)
563 {
564 vertexArray.second->onDestroy(this);
565 }
Jamie Madill57a89722013-07-02 11:57:03 -0400566 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400567 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400568
Corentin Wallez80b24112015-08-25 16:41:57 -0400569 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500570 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500571 if (transformFeedback.second != nullptr)
572 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500573 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500574 }
Geoff Langc8058452014-02-03 12:04:11 -0500575 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400576 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500577
Jamie Madill5b772312018-03-08 20:28:32 -0500578 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400579 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800580 if (zeroTexture.get() != nullptr)
581 {
582 ANGLE_TRY(zeroTexture->onDestroy(this));
583 zeroTexture.set(this, nullptr);
584 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400585 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586
Jamie Madill2f348d22017-06-05 10:50:59 -0400587 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500588
Jamie Madill4928b7c2017-06-20 12:57:39 -0400589 mGLState.reset(this);
590
Jamie Madill6c1f6712017-02-14 19:08:04 -0500591 mState.mBuffers->release(this);
592 mState.mShaderPrograms->release(this);
593 mState.mTextures->release(this);
594 mState.mRenderbuffers->release(this);
595 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400596 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500597 mState.mPaths->release(this);
598 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800599 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400600
jchen107ae70d82018-07-06 13:47:01 +0800601 mThreadPool.reset();
602
Jamie Madill76e471e2017-10-21 09:56:01 -0400603 mImplementation->onDestroy(this);
604
Jamie Madill4928b7c2017-06-20 12:57:39 -0400605 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
Jamie Madill70ee0f62017-02-06 16:04:20 -0500608Context::~Context()
609{
610}
611
Geoff Lang75359662018-04-11 01:42:27 -0400612void Context::setLabel(EGLLabelKHR label)
613{
614 mLabel = label;
615}
616
617EGLLabelKHR Context::getLabel() const
618{
619 return mLabel;
620}
621
Jamie Madill4928b7c2017-06-20 12:57:39 -0400622egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623{
Jamie Madill61e16b42017-06-19 11:13:23 -0400624 mCurrentDisplay = display;
625
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626 if (!mHasBeenCurrent)
627 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400628 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500630 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400631 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632
Corentin Wallezc295e512017-01-27 17:47:50 -0500633 int width = 0;
634 int height = 0;
635 if (surface != nullptr)
636 {
637 width = surface->getWidth();
638 height = surface->getHeight();
639 }
640
641 mGLState.setViewportParams(0, 0, width, height);
642 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643
644 mHasBeenCurrent = true;
645 }
646
Jamie Madill1b94d432015-08-07 13:23:23 -0400647 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700648 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400649 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400650
Jamie Madill4928b7c2017-06-20 12:57:39 -0400651 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500652
653 Framebuffer *newDefault = nullptr;
654 if (surface != nullptr)
655 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400656 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500657 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400658 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500659 }
660 else
661 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400662 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500663 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000664
Corentin Wallez37c39792015-08-20 14:19:46 -0400665 // Update default framebuffer, the binding of the previous default
666 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400667 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400668 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700669 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400670 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400671 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400672 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700673 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400674 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400675 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400676 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400677 }
Ian Ewell292f0052016-02-04 10:37:32 -0500678
679 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400680 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400681 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
Jamie Madill4928b7c2017-06-20 12:57:39 -0400684egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400685{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400686 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400687
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688 // Remove the default framebuffer
689 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500690 {
691 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400692 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500693 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400694
695 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500696 {
697 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400698 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500699 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400700
701 if (defaultFramebuffer)
702 {
703 defaultFramebuffer->onDestroy(this);
704 delete defaultFramebuffer;
705 }
706
Corentin Wallezc295e512017-01-27 17:47:50 -0500707 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
708
709 if (mCurrentSurface)
710 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400711 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500712 mCurrentSurface = nullptr;
713 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400714
715 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400716}
717
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718GLuint Context::createBuffer()
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
723GLuint Context::createProgram()
724{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500725 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000726}
727
Jiawei Shao385b3e02018-03-21 09:43:28 +0800728GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000729{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500730 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731}
732
733GLuint Context::createTexture()
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736}
737
738GLuint Context::createRenderbuffer()
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741}
742
Brandon Jones59770802018-04-02 13:18:42 -0700743GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746 if (resultOrError.isError())
747 {
748 handleError(resultOrError.getError());
749 return 0;
750 }
751 return resultOrError.getResult();
752}
753
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754// Returns an unused framebuffer name
755GLuint Context::createFramebuffer()
756{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500757 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000758}
759
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500760void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000761{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500762 for (int i = 0; i < n; i++)
763 {
764 GLuint handle = mFenceNVHandleAllocator.allocate();
765 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
766 fences[i] = handle;
767 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000768}
769
Yunchao Hea336b902017-08-02 16:05:21 +0800770GLuint Context::createProgramPipeline()
771{
772 return mState.mPipelines->createProgramPipeline();
773}
774
Jiawei Shao385b3e02018-03-21 09:43:28 +0800775GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800776{
777 UNIMPLEMENTED();
778 return 0u;
779}
780
James Darpinian4d9d4832018-03-13 12:43:28 -0700781void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782{
James Darpinian4d9d4832018-03-13 12:43:28 -0700783 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
784 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785 {
786 detachBuffer(buffer);
787 }
Jamie Madill893ab082014-05-16 16:56:10 -0400788
James Darpinian4d9d4832018-03-13 12:43:28 -0700789 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790}
791
792void Context::deleteShader(GLuint shader)
793{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500794 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795}
796
797void Context::deleteProgram(GLuint program)
798{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500799 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800}
801
802void Context::deleteTexture(GLuint texture)
803{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500804 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805 {
806 detachTexture(texture);
807 }
808
Jamie Madill6c1f6712017-02-14 19:08:04 -0500809 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810}
811
812void Context::deleteRenderbuffer(GLuint renderbuffer)
813{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500814 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815 {
816 detachRenderbuffer(renderbuffer);
817 }
Jamie Madill893ab082014-05-16 16:56:10 -0400818
Jamie Madill6c1f6712017-02-14 19:08:04 -0500819 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820}
821
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400822void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400823{
824 // The spec specifies the underlying Fence object is not deleted until all current
825 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
826 // and since our API is currently designed for being called from a single thread, we can delete
827 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400828 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400829}
830
Yunchao Hea336b902017-08-02 16:05:21 +0800831void Context::deleteProgramPipeline(GLuint pipeline)
832{
833 if (mState.mPipelines->getProgramPipeline(pipeline))
834 {
835 detachProgramPipeline(pipeline);
836 }
837
838 mState.mPipelines->deleteObject(this, pipeline);
839}
840
Sami Väisänene45e53b2016-05-25 10:36:04 +0300841void Context::deletePaths(GLuint first, GLsizei range)
842{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500843 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300844}
845
Brandon Jones59770802018-04-02 13:18:42 -0700846bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300847{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500848 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849 if (pathObj == nullptr)
850 return false;
851
852 return pathObj->hasPathData();
853}
854
Brandon Jones59770802018-04-02 13:18:42 -0700855bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300858}
859
Brandon Jones59770802018-04-02 13:18:42 -0700860void Context::pathCommands(GLuint path,
861 GLsizei numCommands,
862 const GLubyte *commands,
863 GLsizei numCoords,
864 GLenum coordType,
865 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868
869 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
870}
871
Jamie Madill007530e2017-12-28 14:27:04 -0500872void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300873{
Jamie Madill007530e2017-12-28 14:27:04 -0500874 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875
876 switch (pname)
877 {
878 case GL_PATH_STROKE_WIDTH_CHROMIUM:
879 pathObj->setStrokeWidth(value);
880 break;
881 case GL_PATH_END_CAPS_CHROMIUM:
882 pathObj->setEndCaps(static_cast<GLenum>(value));
883 break;
884 case GL_PATH_JOIN_STYLE_CHROMIUM:
885 pathObj->setJoinStyle(static_cast<GLenum>(value));
886 break;
887 case GL_PATH_MITER_LIMIT_CHROMIUM:
888 pathObj->setMiterLimit(value);
889 break;
890 case GL_PATH_STROKE_BOUND_CHROMIUM:
891 pathObj->setStrokeBound(value);
892 break;
893 default:
894 UNREACHABLE();
895 break;
896 }
897}
898
Jamie Madill007530e2017-12-28 14:27:04 -0500899void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300900{
Jamie Madill007530e2017-12-28 14:27:04 -0500901 // TODO(jmadill): Should use proper clamping/casting.
902 pathParameterf(path, pname, static_cast<GLfloat>(value));
903}
904
905void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
906{
907 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300908
909 switch (pname)
910 {
911 case GL_PATH_STROKE_WIDTH_CHROMIUM:
912 *value = pathObj->getStrokeWidth();
913 break;
914 case GL_PATH_END_CAPS_CHROMIUM:
915 *value = static_cast<GLfloat>(pathObj->getEndCaps());
916 break;
917 case GL_PATH_JOIN_STYLE_CHROMIUM:
918 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
919 break;
920 case GL_PATH_MITER_LIMIT_CHROMIUM:
921 *value = pathObj->getMiterLimit();
922 break;
923 case GL_PATH_STROKE_BOUND_CHROMIUM:
924 *value = pathObj->getStrokeBound();
925 break;
926 default:
927 UNREACHABLE();
928 break;
929 }
930}
931
Jamie Madill007530e2017-12-28 14:27:04 -0500932void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
933{
934 GLfloat val = 0.0f;
935 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
936 if (value)
937 *value = static_cast<GLint>(val);
938}
939
Brandon Jones59770802018-04-02 13:18:42 -0700940void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300941{
942 mGLState.setPathStencilFunc(func, ref, mask);
943}
944
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945void Context::deleteFramebuffer(GLuint framebuffer)
946{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500947 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948 {
949 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500951
Jamie Madill6c1f6712017-02-14 19:08:04 -0500952 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500955void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500957 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500959 GLuint fence = fences[i];
960
961 FenceNV *fenceObject = nullptr;
962 if (mFenceNVMap.erase(fence, &fenceObject))
963 {
964 mFenceNVHandleAllocator.release(fence);
965 delete fenceObject;
966 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000967 }
968}
969
Geoff Lang70d0f492015-12-10 17:45:46 -0500970Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973}
974
Jamie Madill570f7c82014-07-03 10:38:54 -0400975Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000976{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500977 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978}
979
Geoff Lang70d0f492015-12-10 17:45:46 -0500980Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000981{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500982 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000983}
984
Jamie Madill70b5bb02017-08-28 13:32:37 -0400985Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400986{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400987 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400988}
989
Jamie Madill57a89722013-07-02 11:57:03 -0400990VertexArray *Context::getVertexArray(GLuint handle) const
991{
Jamie Madill96a483b2017-06-27 16:49:21 -0400992 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400993}
994
Jamie Madilldc356042013-07-19 16:36:57 -0400995Sampler *Context::getSampler(GLuint handle) const
996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500997 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400998}
999
Geoff Langc8058452014-02-03 12:04:11 -05001000TransformFeedback *Context::getTransformFeedback(GLuint handle) const
1001{
Jamie Madill96a483b2017-06-27 16:49:21 -04001002 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001003}
1004
Yunchao Hea336b902017-08-02 16:05:21 +08001005ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1006{
1007 return mState.mPipelines->getProgramPipeline(handle);
1008}
1009
Geoff Lang75359662018-04-11 01:42:27 -04001010gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001011{
1012 switch (identifier)
1013 {
1014 case GL_BUFFER:
1015 return getBuffer(name);
1016 case GL_SHADER:
1017 return getShader(name);
1018 case GL_PROGRAM:
1019 return getProgram(name);
1020 case GL_VERTEX_ARRAY:
1021 return getVertexArray(name);
1022 case GL_QUERY:
1023 return getQuery(name);
1024 case GL_TRANSFORM_FEEDBACK:
1025 return getTransformFeedback(name);
1026 case GL_SAMPLER:
1027 return getSampler(name);
1028 case GL_TEXTURE:
1029 return getTexture(name);
1030 case GL_RENDERBUFFER:
1031 return getRenderbuffer(name);
1032 case GL_FRAMEBUFFER:
1033 return getFramebuffer(name);
1034 default:
1035 UNREACHABLE();
1036 return nullptr;
1037 }
1038}
1039
Geoff Lang75359662018-04-11 01:42:27 -04001040gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001041{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001042 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001043}
1044
Martin Radev9d901792016-07-15 15:58:58 +03001045void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1046{
Geoff Lang75359662018-04-11 01:42:27 -04001047 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001048 ASSERT(object != nullptr);
1049
1050 std::string labelName = GetObjectLabelFromPointer(length, label);
1051 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001052
1053 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1054 // specified object is active until we do this.
1055 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001056}
1057
1058void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1059{
Geoff Lang75359662018-04-11 01:42:27 -04001060 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001061 ASSERT(object != nullptr);
1062
1063 std::string labelName = GetObjectLabelFromPointer(length, label);
1064 object->setLabel(labelName);
1065}
1066
1067void Context::getObjectLabel(GLenum identifier,
1068 GLuint name,
1069 GLsizei bufSize,
1070 GLsizei *length,
1071 GLchar *label) const
1072{
Geoff Lang75359662018-04-11 01:42:27 -04001073 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001074 ASSERT(object != nullptr);
1075
1076 const std::string &objectLabel = object->getLabel();
1077 GetObjectLabelBase(objectLabel, bufSize, length, label);
1078}
1079
1080void Context::getObjectPtrLabel(const void *ptr,
1081 GLsizei bufSize,
1082 GLsizei *length,
1083 GLchar *label) const
1084{
Geoff Lang75359662018-04-11 01:42:27 -04001085 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001086 ASSERT(object != nullptr);
1087
1088 const std::string &objectLabel = object->getLabel();
1089 GetObjectLabelBase(objectLabel, bufSize, length, label);
1090}
1091
Jamie Madilldc356042013-07-19 16:36:57 -04001092bool Context::isSampler(GLuint samplerName) const
1093{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001094 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001095}
1096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001097void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001099 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001100
Jamie Madilldedd7b92014-11-05 16:30:36 -05001101 if (handle == 0)
1102 {
1103 texture = mZeroTextures[target].get();
1104 }
1105 else
1106 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001107 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001108 }
1109
1110 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001111 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001112 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001113}
1114
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001115void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001117 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1118 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001119 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001120 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121}
1122
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001123void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001124{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001125 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1126 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001128 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001129 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001130}
1131
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001132void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001133{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001134 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001135 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001136 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001137 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001138}
1139
Shao80957d92017-02-20 21:25:59 +08001140void Context::bindVertexBuffer(GLuint bindingIndex,
1141 GLuint bufferHandle,
1142 GLintptr offset,
1143 GLsizei stride)
1144{
1145 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001146 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001147 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001148}
1149
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001150void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001151{
Geoff Lang76b10c92014-09-05 16:28:14 -04001152 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001153 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001154 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001155 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001156}
1157
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001158void Context::bindImageTexture(GLuint unit,
1159 GLuint texture,
1160 GLint level,
1161 GLboolean layered,
1162 GLint layer,
1163 GLenum access,
1164 GLenum format)
1165{
1166 Texture *tex = mState.mTextures->getTexture(texture);
1167 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1168}
1169
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001170void Context::useProgram(GLuint program)
1171{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001172 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001173 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001174}
1175
Jiajia Qin5451d532017-11-16 17:16:34 +08001176void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1177{
1178 UNIMPLEMENTED();
1179}
1180
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001181void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001182{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001183 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001184 TransformFeedback *transformFeedback =
1185 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001186 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001187 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001188}
1189
Yunchao Hea336b902017-08-02 16:05:21 +08001190void Context::bindProgramPipeline(GLuint pipelineHandle)
1191{
1192 ProgramPipeline *pipeline =
1193 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1194 mGLState.setProgramPipelineBinding(this, pipeline);
1195}
1196
Corentin Wallezad3ae902018-03-09 13:40:42 -05001197void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001200 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201
Geoff Lang5aad9672014-09-08 11:10:42 -04001202 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001203 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001204
1205 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001206 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001207 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208}
1209
Corentin Wallezad3ae902018-03-09 13:40:42 -05001210void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001212 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001213 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214
Jamie Madill5188a272018-07-25 10:53:56 -04001215 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216
Geoff Lang5aad9672014-09-08 11:10:42 -04001217 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001218 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001219 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220}
1221
Corentin Wallezad3ae902018-03-09 13:40:42 -05001222void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001224 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225
1226 Query *queryObject = getQuery(id, true, target);
1227 ASSERT(queryObject);
1228
Jamie Madill5188a272018-07-25 10:53:56 -04001229 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001230}
1231
Corentin Wallezad3ae902018-03-09 13:40:42 -05001232void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001233{
1234 switch (pname)
1235 {
1236 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001237 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001238 break;
1239 case GL_QUERY_COUNTER_BITS_EXT:
1240 switch (target)
1241 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001242 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1244 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001245 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001246 params[0] = getExtensions().queryCounterBitsTimestamp;
1247 break;
1248 default:
1249 UNREACHABLE();
1250 params[0] = 0;
1251 break;
1252 }
1253 break;
1254 default:
1255 UNREACHABLE();
1256 return;
1257 }
1258}
1259
Corentin Wallezad3ae902018-03-09 13:40:42 -05001260void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001261 GLenum pname,
1262 GLsizei bufSize,
1263 GLsizei *length,
1264 GLint *params)
1265{
1266 getQueryiv(target, pname, params);
1267}
1268
Geoff Lang2186c382016-10-14 10:54:54 -04001269void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001270{
Jamie Madill5188a272018-07-25 10:53:56 -04001271 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001272}
1273
Brandon Jones59770802018-04-02 13:18:42 -07001274void Context::getQueryObjectivRobust(GLuint id,
1275 GLenum pname,
1276 GLsizei bufSize,
1277 GLsizei *length,
1278 GLint *params)
1279{
1280 getQueryObjectiv(id, pname, params);
1281}
1282
Geoff Lang2186c382016-10-14 10:54:54 -04001283void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001284{
Jamie Madill5188a272018-07-25 10:53:56 -04001285 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001286}
1287
Brandon Jones59770802018-04-02 13:18:42 -07001288void Context::getQueryObjectuivRobust(GLuint id,
1289 GLenum pname,
1290 GLsizei bufSize,
1291 GLsizei *length,
1292 GLuint *params)
1293{
1294 getQueryObjectuiv(id, pname, params);
1295}
1296
Geoff Lang2186c382016-10-14 10:54:54 -04001297void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001298{
Jamie Madill5188a272018-07-25 10:53:56 -04001299 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001300}
1301
Brandon Jones59770802018-04-02 13:18:42 -07001302void Context::getQueryObjecti64vRobust(GLuint id,
1303 GLenum pname,
1304 GLsizei bufSize,
1305 GLsizei *length,
1306 GLint64 *params)
1307{
1308 getQueryObjecti64v(id, pname, params);
1309}
1310
Geoff Lang2186c382016-10-14 10:54:54 -04001311void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001312{
Jamie Madill5188a272018-07-25 10:53:56 -04001313 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001314}
1315
Brandon Jones59770802018-04-02 13:18:42 -07001316void Context::getQueryObjectui64vRobust(GLuint id,
1317 GLenum pname,
1318 GLsizei bufSize,
1319 GLsizei *length,
1320 GLuint64 *params)
1321{
1322 getQueryObjectui64v(id, pname, params);
1323}
1324
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001325Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001327 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Jamie Madill2f348d22017-06-05 10:50:59 -04001330FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
Jamie Madill96a483b2017-06-27 16:49:21 -04001332 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333}
1334
Corentin Wallezad3ae902018-03-09 13:40:42 -05001335Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001336{
Jamie Madill96a483b2017-06-27 16:49:21 -04001337 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001339 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001341
1342 Query *query = mQueryMap.query(handle);
1343 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001345 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001346 query = new Query(mImplementation->createQuery(type), handle);
1347 query->addRef();
1348 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001350 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351}
1352
Geoff Lang70d0f492015-12-10 17:45:46 -05001353Query *Context::getQuery(GLuint handle) const
1354{
Jamie Madill96a483b2017-06-27 16:49:21 -04001355 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001356}
1357
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001358Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001359{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001360 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1361 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001362}
1363
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001364Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001366 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367}
1368
Geoff Lang492a7e42014-11-05 13:27:06 -05001369Compiler *Context::getCompiler() const
1370{
Jamie Madill2f348d22017-06-05 10:50:59 -04001371 if (mCompiler.get() == nullptr)
1372 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001373 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001374 }
1375 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001376}
1377
Jamie Madillc1d770e2017-04-13 17:31:24 -04001378void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001379{
1380 switch (pname)
1381 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001382 case GL_SHADER_COMPILER:
1383 *params = GL_TRUE;
1384 break;
1385 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1386 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1387 break;
1388 default:
1389 mGLState.getBooleanv(pname, params);
1390 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001391 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001392}
1393
Jamie Madillc1d770e2017-04-13 17:31:24 -04001394void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001395{
Shannon Woods53a94a82014-06-24 15:20:36 -04001396 // Queries about context capabilities and maximums are answered by Context.
1397 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001398 switch (pname)
1399 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001400 case GL_ALIASED_LINE_WIDTH_RANGE:
1401 params[0] = mCaps.minAliasedLineWidth;
1402 params[1] = mCaps.maxAliasedLineWidth;
1403 break;
1404 case GL_ALIASED_POINT_SIZE_RANGE:
1405 params[0] = mCaps.minAliasedPointSize;
1406 params[1] = mCaps.maxAliasedPointSize;
1407 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001408 case GL_SMOOTH_POINT_SIZE_RANGE:
1409 params[0] = mCaps.minSmoothPointSize;
1410 params[1] = mCaps.maxSmoothPointSize;
1411 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001412 case GL_SMOOTH_LINE_WIDTH_RANGE:
1413 params[0] = mCaps.minSmoothLineWidth;
1414 params[1] = mCaps.maxSmoothLineWidth;
1415 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1417 ASSERT(mExtensions.textureFilterAnisotropic);
1418 *params = mExtensions.maxTextureAnisotropy;
1419 break;
1420 case GL_MAX_TEXTURE_LOD_BIAS:
1421 *params = mCaps.maxLODBias;
1422 break;
1423
1424 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1425 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1426 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001427 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1428 // GLES1 constants for modelview/projection matrix.
1429 if (getClientVersion() < Version(2, 0))
1430 {
1431 mGLState.getFloatv(pname, params);
1432 }
1433 else
1434 {
1435 ASSERT(mExtensions.pathRendering);
1436 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1437 memcpy(params, m, 16 * sizeof(GLfloat));
1438 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001440 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001441
Jamie Madill231c7f52017-04-26 13:45:37 -04001442 default:
1443 mGLState.getFloatv(pname, params);
1444 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001445 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446}
1447
Jamie Madillc1d770e2017-04-13 17:31:24 -04001448void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001449{
Shannon Woods53a94a82014-06-24 15:20:36 -04001450 // Queries about context capabilities and maximums are answered by Context.
1451 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001452
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001453 switch (pname)
1454 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001455 case GL_MAX_VERTEX_ATTRIBS:
1456 *params = mCaps.maxVertexAttributes;
1457 break;
1458 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1459 *params = mCaps.maxVertexUniformVectors;
1460 break;
1461 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001462 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001463 break;
1464 case GL_MAX_VARYING_VECTORS:
1465 *params = mCaps.maxVaryingVectors;
1466 break;
1467 case GL_MAX_VARYING_COMPONENTS:
1468 *params = mCaps.maxVertexOutputComponents;
1469 break;
1470 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1471 *params = mCaps.maxCombinedTextureImageUnits;
1472 break;
1473 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001474 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 break;
1476 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001477 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001478 break;
1479 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1480 *params = mCaps.maxFragmentUniformVectors;
1481 break;
1482 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001483 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001484 break;
1485 case GL_MAX_RENDERBUFFER_SIZE:
1486 *params = mCaps.maxRenderbufferSize;
1487 break;
1488 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1489 *params = mCaps.maxColorAttachments;
1490 break;
1491 case GL_MAX_DRAW_BUFFERS_EXT:
1492 *params = mCaps.maxDrawBuffers;
1493 break;
1494 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1495 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1496 case GL_SUBPIXEL_BITS:
1497 *params = 4;
1498 break;
1499 case GL_MAX_TEXTURE_SIZE:
1500 *params = mCaps.max2DTextureSize;
1501 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001502 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1503 *params = mCaps.maxRectangleTextureSize;
1504 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001505 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1506 *params = mCaps.maxCubeMapTextureSize;
1507 break;
1508 case GL_MAX_3D_TEXTURE_SIZE:
1509 *params = mCaps.max3DTextureSize;
1510 break;
1511 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1512 *params = mCaps.maxArrayTextureLayers;
1513 break;
1514 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1515 *params = mCaps.uniformBufferOffsetAlignment;
1516 break;
1517 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1518 *params = mCaps.maxUniformBufferBindings;
1519 break;
1520 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001521 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001522 break;
1523 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001524 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 break;
1526 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1527 *params = mCaps.maxCombinedTextureImageUnits;
1528 break;
1529 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1530 *params = mCaps.maxVertexOutputComponents;
1531 break;
1532 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1533 *params = mCaps.maxFragmentInputComponents;
1534 break;
1535 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1536 *params = mCaps.minProgramTexelOffset;
1537 break;
1538 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1539 *params = mCaps.maxProgramTexelOffset;
1540 break;
1541 case GL_MAJOR_VERSION:
1542 *params = getClientVersion().major;
1543 break;
1544 case GL_MINOR_VERSION:
1545 *params = getClientVersion().minor;
1546 break;
1547 case GL_MAX_ELEMENTS_INDICES:
1548 *params = mCaps.maxElementsIndices;
1549 break;
1550 case GL_MAX_ELEMENTS_VERTICES:
1551 *params = mCaps.maxElementsVertices;
1552 break;
1553 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1554 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1555 break;
1556 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1557 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1558 break;
1559 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1560 *params = mCaps.maxTransformFeedbackSeparateComponents;
1561 break;
1562 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1563 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1564 break;
1565 case GL_MAX_SAMPLES_ANGLE:
1566 *params = mCaps.maxSamples;
1567 break;
1568 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001569 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001570 params[0] = mCaps.maxViewportWidth;
1571 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001572 }
1573 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 case GL_COMPRESSED_TEXTURE_FORMATS:
1575 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1576 params);
1577 break;
1578 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1579 *params = mResetStrategy;
1580 break;
1581 case GL_NUM_SHADER_BINARY_FORMATS:
1582 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1583 break;
1584 case GL_SHADER_BINARY_FORMATS:
1585 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1586 break;
1587 case GL_NUM_PROGRAM_BINARY_FORMATS:
1588 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1589 break;
1590 case GL_PROGRAM_BINARY_FORMATS:
1591 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1592 break;
1593 case GL_NUM_EXTENSIONS:
1594 *params = static_cast<GLint>(mExtensionStrings.size());
1595 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001596
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 // GL_KHR_debug
1598 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1599 *params = mExtensions.maxDebugMessageLength;
1600 break;
1601 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1602 *params = mExtensions.maxDebugLoggedMessages;
1603 break;
1604 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1605 *params = mExtensions.maxDebugGroupStackDepth;
1606 break;
1607 case GL_MAX_LABEL_LENGTH:
1608 *params = mExtensions.maxLabelLength;
1609 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001610
Martin Radeve5285d22017-07-14 16:23:53 +03001611 // GL_ANGLE_multiview
1612 case GL_MAX_VIEWS_ANGLE:
1613 *params = mExtensions.maxViews;
1614 break;
1615
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 // GL_EXT_disjoint_timer_query
1617 case GL_GPU_DISJOINT_EXT:
1618 *params = mImplementation->getGPUDisjoint();
1619 break;
1620 case GL_MAX_FRAMEBUFFER_WIDTH:
1621 *params = mCaps.maxFramebufferWidth;
1622 break;
1623 case GL_MAX_FRAMEBUFFER_HEIGHT:
1624 *params = mCaps.maxFramebufferHeight;
1625 break;
1626 case GL_MAX_FRAMEBUFFER_SAMPLES:
1627 *params = mCaps.maxFramebufferSamples;
1628 break;
1629 case GL_MAX_SAMPLE_MASK_WORDS:
1630 *params = mCaps.maxSampleMaskWords;
1631 break;
1632 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1633 *params = mCaps.maxColorTextureSamples;
1634 break;
1635 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1636 *params = mCaps.maxDepthTextureSamples;
1637 break;
1638 case GL_MAX_INTEGER_SAMPLES:
1639 *params = mCaps.maxIntegerSamples;
1640 break;
1641 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1642 *params = mCaps.maxVertexAttribRelativeOffset;
1643 break;
1644 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1645 *params = mCaps.maxVertexAttribBindings;
1646 break;
1647 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1648 *params = mCaps.maxVertexAttribStride;
1649 break;
1650 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001660 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001669 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001672 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001673 break;
1674 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1675 *params = mCaps.minProgramTextureGatherOffset;
1676 break;
1677 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1678 *params = mCaps.maxProgramTextureGatherOffset;
1679 break;
1680 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1681 *params = mCaps.maxComputeWorkGroupInvocations;
1682 break;
1683 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001684 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 break;
1686 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001687 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001688 break;
1689 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1690 *params = mCaps.maxComputeSharedMemorySize;
1691 break;
1692 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001693 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001696 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001699 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 break;
1701 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001702 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
1704 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001705 *params =
1706 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001707 break;
1708 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001709 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001710 break;
1711 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1712 *params = mCaps.maxCombinedShaderOutputResources;
1713 break;
1714 case GL_MAX_UNIFORM_LOCATIONS:
1715 *params = mCaps.maxUniformLocations;
1716 break;
1717 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1718 *params = mCaps.maxAtomicCounterBufferBindings;
1719 break;
1720 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1721 *params = mCaps.maxAtomicCounterBufferSize;
1722 break;
1723 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1724 *params = mCaps.maxCombinedAtomicCounterBuffers;
1725 break;
1726 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1727 *params = mCaps.maxCombinedAtomicCounters;
1728 break;
1729 case GL_MAX_IMAGE_UNITS:
1730 *params = mCaps.maxImageUnits;
1731 break;
1732 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1733 *params = mCaps.maxCombinedImageUniforms;
1734 break;
1735 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1736 *params = mCaps.maxShaderStorageBufferBindings;
1737 break;
1738 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1739 *params = mCaps.maxCombinedShaderStorageBlocks;
1740 break;
1741 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1742 *params = mCaps.shaderStorageBufferOffsetAlignment;
1743 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001744
1745 // GL_EXT_geometry_shader
1746 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1747 *params = mCaps.maxFramebufferLayers;
1748 break;
1749 case GL_LAYER_PROVOKING_VERTEX_EXT:
1750 *params = mCaps.layerProvokingVertex;
1751 break;
1752 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001753 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001754 break;
1755 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001756 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001757 break;
1758 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001759 *params =
1760 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001761 break;
1762 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1763 *params = mCaps.maxGeometryInputComponents;
1764 break;
1765 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1766 *params = mCaps.maxGeometryOutputComponents;
1767 break;
1768 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1769 *params = mCaps.maxGeometryOutputVertices;
1770 break;
1771 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1772 *params = mCaps.maxGeometryTotalOutputComponents;
1773 break;
1774 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1775 *params = mCaps.maxGeometryShaderInvocations;
1776 break;
1777 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001778 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001779 break;
1780 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001781 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001782 break;
1783 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001784 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001785 break;
1786 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001787 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001788 break;
1789 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001790 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001791 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001792 // GLES1 emulation: Caps queries
1793 case GL_MAX_TEXTURE_UNITS:
1794 *params = mCaps.maxMultitextureUnits;
1795 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001796 case GL_MAX_MODELVIEW_STACK_DEPTH:
1797 *params = mCaps.maxModelviewMatrixStackDepth;
1798 break;
1799 case GL_MAX_PROJECTION_STACK_DEPTH:
1800 *params = mCaps.maxProjectionMatrixStackDepth;
1801 break;
1802 case GL_MAX_TEXTURE_STACK_DEPTH:
1803 *params = mCaps.maxTextureMatrixStackDepth;
1804 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001805 case GL_MAX_LIGHTS:
1806 *params = mCaps.maxLights;
1807 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001808 case GL_MAX_CLIP_PLANES:
1809 *params = mCaps.maxClipPlanes;
1810 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001811 // GLES1 emulation: Vertex attribute queries
1812 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1813 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1814 case GL_COLOR_ARRAY_BUFFER_BINDING:
1815 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1816 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1817 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1818 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1819 break;
1820 case GL_VERTEX_ARRAY_STRIDE:
1821 case GL_NORMAL_ARRAY_STRIDE:
1822 case GL_COLOR_ARRAY_STRIDE:
1823 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1824 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1825 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1826 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1827 break;
1828 case GL_VERTEX_ARRAY_SIZE:
1829 case GL_COLOR_ARRAY_SIZE:
1830 case GL_TEXTURE_COORD_ARRAY_SIZE:
1831 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1832 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1833 break;
1834 case GL_VERTEX_ARRAY_TYPE:
1835 case GL_COLOR_ARRAY_TYPE:
1836 case GL_NORMAL_ARRAY_TYPE:
1837 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1838 case GL_TEXTURE_COORD_ARRAY_TYPE:
1839 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1840 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1841 break;
1842
jchen1082af6202018-06-22 10:59:52 +08001843 // GL_KHR_parallel_shader_compile
1844 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1845 *params = mGLState.getMaxShaderCompilerThreads();
1846 break;
1847
Jamie Madill231c7f52017-04-26 13:45:37 -04001848 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001849 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001850 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001851 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001852}
1853
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001854void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001855{
Shannon Woods53a94a82014-06-24 15:20:36 -04001856 // Queries about context capabilities and maximums are answered by Context.
1857 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001858 switch (pname)
1859 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001860 case GL_MAX_ELEMENT_INDEX:
1861 *params = mCaps.maxElementIndex;
1862 break;
1863 case GL_MAX_UNIFORM_BLOCK_SIZE:
1864 *params = mCaps.maxUniformBlockSize;
1865 break;
1866 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001867 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001868 break;
1869 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001870 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001871 break;
1872 case GL_MAX_SERVER_WAIT_TIMEOUT:
1873 *params = mCaps.maxServerWaitTimeout;
1874 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001875
Jamie Madill231c7f52017-04-26 13:45:37 -04001876 // GL_EXT_disjoint_timer_query
1877 case GL_TIMESTAMP_EXT:
1878 *params = mImplementation->getTimestamp();
1879 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001880
Jamie Madill231c7f52017-04-26 13:45:37 -04001881 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1882 *params = mCaps.maxShaderStorageBlockSize;
1883 break;
1884 default:
1885 UNREACHABLE();
1886 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001887 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001888}
1889
Geoff Lang70d0f492015-12-10 17:45:46 -05001890void Context::getPointerv(GLenum pname, void **params) const
1891{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001892 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001893}
1894
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001895void Context::getPointervRobustANGLERobust(GLenum pname,
1896 GLsizei bufSize,
1897 GLsizei *length,
1898 void **params)
1899{
1900 UNIMPLEMENTED();
1901}
1902
Martin Radev66fb8202016-07-28 11:45:20 +03001903void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001904{
Shannon Woods53a94a82014-06-24 15:20:36 -04001905 // Queries about context capabilities and maximums are answered by Context.
1906 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001907
1908 GLenum nativeType;
1909 unsigned int numParams;
1910 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1911 ASSERT(queryStatus);
1912
1913 if (nativeType == GL_INT)
1914 {
1915 switch (target)
1916 {
1917 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1918 ASSERT(index < 3u);
1919 *data = mCaps.maxComputeWorkGroupCount[index];
1920 break;
1921 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1922 ASSERT(index < 3u);
1923 *data = mCaps.maxComputeWorkGroupSize[index];
1924 break;
1925 default:
1926 mGLState.getIntegeri_v(target, index, data);
1927 }
1928 }
1929 else
1930 {
1931 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1932 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001933}
1934
Brandon Jones59770802018-04-02 13:18:42 -07001935void Context::getIntegeri_vRobust(GLenum target,
1936 GLuint index,
1937 GLsizei bufSize,
1938 GLsizei *length,
1939 GLint *data)
1940{
1941 getIntegeri_v(target, index, data);
1942}
1943
Martin Radev66fb8202016-07-28 11:45:20 +03001944void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001945{
Shannon Woods53a94a82014-06-24 15:20:36 -04001946 // Queries about context capabilities and maximums are answered by Context.
1947 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001948
1949 GLenum nativeType;
1950 unsigned int numParams;
1951 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1952 ASSERT(queryStatus);
1953
1954 if (nativeType == GL_INT_64_ANGLEX)
1955 {
1956 mGLState.getInteger64i_v(target, index, data);
1957 }
1958 else
1959 {
1960 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1961 }
1962}
1963
Brandon Jones59770802018-04-02 13:18:42 -07001964void Context::getInteger64i_vRobust(GLenum target,
1965 GLuint index,
1966 GLsizei bufSize,
1967 GLsizei *length,
1968 GLint64 *data)
1969{
1970 getInteger64i_v(target, index, data);
1971}
1972
Martin Radev66fb8202016-07-28 11:45:20 +03001973void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1974{
1975 // Queries about context capabilities and maximums are answered by Context.
1976 // Queries about current GL state values are answered by State.
1977
1978 GLenum nativeType;
1979 unsigned int numParams;
1980 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1981 ASSERT(queryStatus);
1982
1983 if (nativeType == GL_BOOL)
1984 {
1985 mGLState.getBooleani_v(target, index, data);
1986 }
1987 else
1988 {
1989 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1990 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001991}
1992
Brandon Jones59770802018-04-02 13:18:42 -07001993void Context::getBooleani_vRobust(GLenum target,
1994 GLuint index,
1995 GLsizei bufSize,
1996 GLsizei *length,
1997 GLboolean *data)
1998{
1999 getBooleani_v(target, index, data);
2000}
2001
Corentin Wallez336129f2017-10-17 15:55:40 -04002002void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002003{
2004 Buffer *buffer = mGLState.getTargetBuffer(target);
2005 QueryBufferParameteriv(buffer, pname, params);
2006}
2007
Brandon Jones59770802018-04-02 13:18:42 -07002008void Context::getBufferParameterivRobust(BufferBinding target,
2009 GLenum pname,
2010 GLsizei bufSize,
2011 GLsizei *length,
2012 GLint *params)
2013{
2014 getBufferParameteriv(target, pname, params);
2015}
2016
He Yunchao010e4db2017-03-03 14:22:06 +08002017void Context::getFramebufferAttachmentParameteriv(GLenum target,
2018 GLenum attachment,
2019 GLenum pname,
2020 GLint *params)
2021{
2022 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002023 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002024}
2025
Brandon Jones59770802018-04-02 13:18:42 -07002026void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2027 GLenum attachment,
2028 GLenum pname,
2029 GLsizei bufSize,
2030 GLsizei *length,
2031 GLint *params)
2032{
2033 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2034}
2035
He Yunchao010e4db2017-03-03 14:22:06 +08002036void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2037{
2038 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2039 QueryRenderbufferiv(this, renderbuffer, pname, params);
2040}
2041
Brandon Jones59770802018-04-02 13:18:42 -07002042void Context::getRenderbufferParameterivRobust(GLenum target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 GLsizei *length,
2046 GLint *params)
2047{
2048 getRenderbufferParameteriv(target, pname, params);
2049}
2050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002051void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002052{
2053 Texture *texture = getTargetTexture(target);
2054 QueryTexParameterfv(texture, pname, params);
2055}
2056
Brandon Jones59770802018-04-02 13:18:42 -07002057void Context::getTexParameterfvRobust(TextureType target,
2058 GLenum pname,
2059 GLsizei bufSize,
2060 GLsizei *length,
2061 GLfloat *params)
2062{
2063 getTexParameterfv(target, pname, params);
2064}
2065
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002066void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002067{
2068 Texture *texture = getTargetTexture(target);
2069 QueryTexParameteriv(texture, pname, params);
2070}
Jiajia Qin5451d532017-11-16 17:16:34 +08002071
Brandon Jones59770802018-04-02 13:18:42 -07002072void Context::getTexParameterivRobust(TextureType target,
2073 GLenum pname,
2074 GLsizei bufSize,
2075 GLsizei *length,
2076 GLint *params)
2077{
2078 getTexParameteriv(target, pname, params);
2079}
2080
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002081void Context::getTexParameterIivRobust(TextureType target,
2082 GLenum pname,
2083 GLsizei bufSize,
2084 GLsizei *length,
2085 GLint *params)
2086{
2087 UNIMPLEMENTED();
2088}
2089
2090void Context::getTexParameterIuivRobust(TextureType target,
2091 GLenum pname,
2092 GLsizei bufSize,
2093 GLsizei *length,
2094 GLuint *params)
2095{
2096 UNIMPLEMENTED();
2097}
2098
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002099void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002100{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002101 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002102 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002103}
2104
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002105void Context::getTexLevelParameterivRobust(TextureTarget target,
2106 GLint level,
2107 GLenum pname,
2108 GLsizei bufSize,
2109 GLsizei *length,
2110 GLint *params)
2111{
2112 UNIMPLEMENTED();
2113}
2114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115void Context::getTexLevelParameterfv(TextureTarget target,
2116 GLint level,
2117 GLenum pname,
2118 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002119{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002120 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002121 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002122}
2123
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002124void Context::getTexLevelParameterfvRobust(TextureTarget target,
2125 GLint level,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 GLsizei *length,
2129 GLfloat *params)
2130{
2131 UNIMPLEMENTED();
2132}
2133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002134void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002135{
2136 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002137 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002138 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002139}
2140
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002141void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002142{
2143 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002144 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002145 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002146}
2147
Brandon Jones59770802018-04-02 13:18:42 -07002148void Context::texParameterfvRobust(TextureType target,
2149 GLenum pname,
2150 GLsizei bufSize,
2151 const GLfloat *params)
2152{
2153 texParameterfv(target, pname, params);
2154}
2155
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002156void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002157{
2158 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002159 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002160 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002161}
2162
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002163void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002164{
2165 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002166 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002167 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002168}
2169
Brandon Jones59770802018-04-02 13:18:42 -07002170void Context::texParameterivRobust(TextureType target,
2171 GLenum pname,
2172 GLsizei bufSize,
2173 const GLint *params)
2174{
2175 texParameteriv(target, pname, params);
2176}
2177
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002178void Context::texParameterIivRobust(TextureType target,
2179 GLenum pname,
2180 GLsizei bufSize,
2181 const GLint *params)
2182{
2183 UNIMPLEMENTED();
2184}
2185
2186void Context::texParameterIuivRobust(TextureType target,
2187 GLenum pname,
2188 GLsizei bufSize,
2189 const GLuint *params)
2190{
2191 UNIMPLEMENTED();
2192}
2193
Jamie Madill493f9572018-05-24 19:52:15 -04002194void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002195{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002196 // No-op if count draws no primitives for given mode
2197 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002198 {
2199 return;
2200 }
2201
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002202 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002203 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002204 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002205}
2206
Jamie Madill493f9572018-05-24 19:52:15 -04002207void Context::drawArraysInstanced(PrimitiveMode mode,
2208 GLint first,
2209 GLsizei count,
2210 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002211{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002212 // No-op if count draws no primitives for given mode
2213 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002214 {
2215 return;
2216 }
2217
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002218 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002219 ANGLE_CONTEXT_TRY(
2220 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002221 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2222 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002223}
2224
Jamie Madill493f9572018-05-24 19:52:15 -04002225void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002227 // No-op if count draws no primitives for given mode
2228 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002229 {
2230 return;
2231 }
2232
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002233 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002234 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002235}
2236
Jamie Madill493f9572018-05-24 19:52:15 -04002237void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002238 GLsizei count,
2239 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002240 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002241 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002242{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002243 // No-op if count draws no primitives for given mode
2244 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002245 {
2246 return;
2247 }
2248
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002249 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002250 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002251 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002252}
2253
Jamie Madill493f9572018-05-24 19:52:15 -04002254void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002255 GLuint start,
2256 GLuint end,
2257 GLsizei count,
2258 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002259 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002260{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002261 // No-op if count draws no primitives for given mode
2262 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002263 {
2264 return;
2265 }
2266
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002267 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002268 ANGLE_CONTEXT_TRY(
2269 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002270}
2271
Jamie Madill493f9572018-05-24 19:52:15 -04002272void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002273{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002274 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002275 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002276}
2277
Jamie Madill493f9572018-05-24 19:52:15 -04002278void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002279{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002280 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002281 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002282}
2283
Jamie Madill675fe712016-12-19 13:07:54 -05002284void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002285{
Jamie Madillafa02a22017-11-23 12:57:38 -05002286 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002287}
2288
Jamie Madill675fe712016-12-19 13:07:54 -05002289void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002290{
Jamie Madillafa02a22017-11-23 12:57:38 -05002291 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002292}
2293
Austin Kinross6ee1e782015-05-29 17:05:37 -07002294void Context::insertEventMarker(GLsizei length, const char *marker)
2295{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002296 ASSERT(mImplementation);
2297 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002298}
2299
2300void Context::pushGroupMarker(GLsizei length, const char *marker)
2301{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002302 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002303
2304 if (marker == nullptr)
2305 {
2306 // From the EXT_debug_marker spec,
2307 // "If <marker> is null then an empty string is pushed on the stack."
2308 mImplementation->pushGroupMarker(length, "");
2309 }
2310 else
2311 {
2312 mImplementation->pushGroupMarker(length, marker);
2313 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002314}
2315
2316void Context::popGroupMarker()
2317{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002318 ASSERT(mImplementation);
2319 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002320}
2321
Geoff Langd8605522016-04-13 10:19:12 -04002322void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2323{
2324 Program *programObject = getProgram(program);
2325 ASSERT(programObject);
2326
2327 programObject->bindUniformLocation(location, name);
2328}
2329
Brandon Jones59770802018-04-02 13:18:42 -07002330void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002331{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002332 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002333}
2334
Brandon Jones59770802018-04-02 13:18:42 -07002335void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336{
2337 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2338}
2339
Brandon Jones59770802018-04-02 13:18:42 -07002340void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002341{
2342 GLfloat I[16];
2343 angle::Matrix<GLfloat>::setToIdentity(I);
2344
2345 mGLState.loadPathRenderingMatrix(matrixMode, I);
2346}
2347
2348void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2349{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002350 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002351 if (!pathObj)
2352 return;
2353
Geoff Lang9bf86f02018-07-26 11:46:34 -04002354 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355
2356 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2357}
2358
2359void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2360{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002361 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002362 if (!pathObj)
2363 return;
2364
Geoff Lang9bf86f02018-07-26 11:46:34 -04002365 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002366
2367 mImplementation->stencilStrokePath(pathObj, reference, mask);
2368}
2369
2370void Context::coverFillPath(GLuint path, GLenum coverMode)
2371{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002372 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002373 if (!pathObj)
2374 return;
2375
Geoff Lang9bf86f02018-07-26 11:46:34 -04002376 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002377
2378 mImplementation->coverFillPath(pathObj, coverMode);
2379}
2380
2381void Context::coverStrokePath(GLuint path, GLenum coverMode)
2382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002384 if (!pathObj)
2385 return;
2386
Geoff Lang9bf86f02018-07-26 11:46:34 -04002387 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002388
2389 mImplementation->coverStrokePath(pathObj, coverMode);
2390}
2391
2392void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002394 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002395 if (!pathObj)
2396 return;
2397
Geoff Lang9bf86f02018-07-26 11:46:34 -04002398 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002399
2400 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2401}
2402
2403void Context::stencilThenCoverStrokePath(GLuint path,
2404 GLint reference,
2405 GLuint mask,
2406 GLenum coverMode)
2407{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002408 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002409 if (!pathObj)
2410 return;
2411
Geoff Lang9bf86f02018-07-26 11:46:34 -04002412 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002413
2414 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2415}
2416
Sami Väisänend59ca052016-06-21 16:10:00 +03002417void Context::coverFillPathInstanced(GLsizei numPaths,
2418 GLenum pathNameType,
2419 const void *paths,
2420 GLuint pathBase,
2421 GLenum coverMode,
2422 GLenum transformType,
2423 const GLfloat *transformValues)
2424{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002425 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002426
Geoff Lang9bf86f02018-07-26 11:46:34 -04002427 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002428
2429 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2430}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002431
Sami Väisänend59ca052016-06-21 16:10:00 +03002432void Context::coverStrokePathInstanced(GLsizei numPaths,
2433 GLenum pathNameType,
2434 const void *paths,
2435 GLuint pathBase,
2436 GLenum coverMode,
2437 GLenum transformType,
2438 const GLfloat *transformValues)
2439{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002440 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002443 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002444
2445 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2446 transformValues);
2447}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002448
Sami Väisänend59ca052016-06-21 16:10:00 +03002449void Context::stencilFillPathInstanced(GLsizei numPaths,
2450 GLenum pathNameType,
2451 const void *paths,
2452 GLuint pathBase,
2453 GLenum fillMode,
2454 GLuint mask,
2455 GLenum transformType,
2456 const GLfloat *transformValues)
2457{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002458 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
2460 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002461 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002462
2463 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2464 transformValues);
2465}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002466
Sami Väisänend59ca052016-06-21 16:10:00 +03002467void Context::stencilStrokePathInstanced(GLsizei numPaths,
2468 GLenum pathNameType,
2469 const void *paths,
2470 GLuint pathBase,
2471 GLint reference,
2472 GLuint mask,
2473 GLenum transformType,
2474 const GLfloat *transformValues)
2475{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002476 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002477
Geoff Lang9bf86f02018-07-26 11:46:34 -04002478 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002479
2480 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2481 transformValues);
2482}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002483
Sami Väisänend59ca052016-06-21 16:10:00 +03002484void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2485 GLenum pathNameType,
2486 const void *paths,
2487 GLuint pathBase,
2488 GLenum fillMode,
2489 GLuint mask,
2490 GLenum coverMode,
2491 GLenum transformType,
2492 const GLfloat *transformValues)
2493{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002494 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002495
Geoff Lang9bf86f02018-07-26 11:46:34 -04002496 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002497
2498 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2499 transformType, transformValues);
2500}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002501
Sami Väisänend59ca052016-06-21 16:10:00 +03002502void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2503 GLenum pathNameType,
2504 const void *paths,
2505 GLuint pathBase,
2506 GLint reference,
2507 GLuint mask,
2508 GLenum coverMode,
2509 GLenum transformType,
2510 const GLfloat *transformValues)
2511{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002512 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002513
Geoff Lang9bf86f02018-07-26 11:46:34 -04002514 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002515
2516 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2517 transformType, transformValues);
2518}
2519
Sami Väisänen46eaa942016-06-29 10:26:37 +03002520void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2521{
2522 auto *programObject = getProgram(program);
2523
2524 programObject->bindFragmentInputLocation(location, name);
2525}
2526
2527void Context::programPathFragmentInputGen(GLuint program,
2528 GLint location,
2529 GLenum genMode,
2530 GLint components,
2531 const GLfloat *coeffs)
2532{
2533 auto *programObject = getProgram(program);
2534
jchen103fd614d2018-08-13 12:21:58 +08002535 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002536}
2537
jchen1015015f72017-03-16 13:54:21 +08002538GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2539{
jchen10fd7c3b52017-03-21 15:36:03 +08002540 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002541 return QueryProgramResourceIndex(programObject, programInterface, name);
2542}
2543
jchen10fd7c3b52017-03-21 15:36:03 +08002544void Context::getProgramResourceName(GLuint program,
2545 GLenum programInterface,
2546 GLuint index,
2547 GLsizei bufSize,
2548 GLsizei *length,
2549 GLchar *name)
2550{
2551 const auto *programObject = getProgram(program);
2552 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2553}
2554
jchen10191381f2017-04-11 13:59:04 +08002555GLint Context::getProgramResourceLocation(GLuint program,
2556 GLenum programInterface,
2557 const GLchar *name)
2558{
2559 const auto *programObject = getProgram(program);
2560 return QueryProgramResourceLocation(programObject, programInterface, name);
2561}
2562
jchen10880683b2017-04-12 16:21:55 +08002563void Context::getProgramResourceiv(GLuint program,
2564 GLenum programInterface,
2565 GLuint index,
2566 GLsizei propCount,
2567 const GLenum *props,
2568 GLsizei bufSize,
2569 GLsizei *length,
2570 GLint *params)
2571{
2572 const auto *programObject = getProgram(program);
2573 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2574 length, params);
2575}
2576
jchen10d9cd7b72017-08-30 15:04:25 +08002577void Context::getProgramInterfaceiv(GLuint program,
2578 GLenum programInterface,
2579 GLenum pname,
2580 GLint *params)
2581{
2582 const auto *programObject = getProgram(program);
2583 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2584}
2585
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002586void Context::getProgramInterfaceivRobust(GLuint program,
2587 GLenum programInterface,
2588 GLenum pname,
2589 GLsizei bufSize,
2590 GLsizei *length,
2591 GLint *params)
2592{
2593 UNIMPLEMENTED();
2594}
2595
Jamie Madill306b6c12018-07-27 08:12:49 -04002596void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002597{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002598 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002599}
2600
2601// Get one of the recorded errors and clear its flag, if any.
2602// [OpenGL ES 2.0.24] section 2.5 page 13.
2603GLenum Context::getError()
2604{
Geoff Langda5777c2014-07-11 09:52:58 -04002605 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002606 {
Geoff Langda5777c2014-07-11 09:52:58 -04002607 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 }
Geoff Langda5777c2014-07-11 09:52:58 -04002609 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002610 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002611 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002612 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613}
2614
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002616void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002617{
2618 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002619 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002620 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002621 mContextLostForced = true;
2622 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002623 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624}
2625
Jamie Madill427064d2018-04-13 16:20:34 -04002626bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002627{
2628 return mContextLost;
2629}
2630
Jamie Madillfa920eb2018-01-04 11:45:50 -05002631GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 // Even if the application doesn't want to know about resets, we want to know
2634 // as it will allow us to skip all the calls.
2635 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002636 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002638 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002639 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002640 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002641
2642 // EXT_robustness, section 2.6: If the reset notification behavior is
2643 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2644 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2645 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646 }
2647
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2649 // status should be returned at least once, and GL_NO_ERROR should be returned
2650 // once the device has finished resetting.
2651 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002652 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 ASSERT(mResetStatus == GL_NO_ERROR);
2654 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002655
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002656 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002657 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002658 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659 }
2660 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002661 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002663 // If markContextLost was used to mark the context lost then
2664 // assume that is not recoverable, and continue to report the
2665 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 mResetStatus = mImplementation->getResetStatus();
2667 }
Jamie Madill893ab082014-05-16 16:56:10 -04002668
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002669 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670}
2671
2672bool Context::isResetNotificationEnabled()
2673{
2674 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2675}
2676
Corentin Walleze3b10e82015-05-20 11:06:25 -04002677const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002678{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002679 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002680}
2681
2682EGLenum Context::getClientType() const
2683{
2684 return mClientType;
2685}
2686
2687EGLenum Context::getRenderBuffer() const
2688{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002689 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2690 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002691 {
2692 return EGL_NONE;
2693 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002694
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002695 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002696 ASSERT(backAttachment != nullptr);
2697 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002698}
2699
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002700VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002701{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002702 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002703 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2704 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002705 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002706 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2707 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002708
Jamie Madill96a483b2017-06-27 16:49:21 -04002709 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002710 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002711
2712 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002713}
2714
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002715TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002716{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002717 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002718 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2719 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002720 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002721 transformFeedback =
2722 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002723 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002724 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002725 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002726
2727 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002728}
2729
2730bool Context::isVertexArrayGenerated(GLuint vertexArray)
2731{
Jamie Madill96a483b2017-06-27 16:49:21 -04002732 ASSERT(mVertexArrayMap.contains(0));
2733 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002734}
2735
2736bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2737{
Jamie Madill96a483b2017-06-27 16:49:21 -04002738 ASSERT(mTransformFeedbackMap.contains(0));
2739 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002740}
2741
Shannon Woods53a94a82014-06-24 15:20:36 -04002742void Context::detachTexture(GLuint texture)
2743{
2744 // Simple pass-through to State's detachTexture method, as textures do not require
2745 // allocation map management either here or in the resource manager at detach time.
2746 // Zero textures are held by the Context, and we don't attempt to request them from
2747 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002748 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002749}
2750
James Darpinian4d9d4832018-03-13 12:43:28 -07002751void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002752{
Yuly Novikov5807a532015-12-03 13:01:22 -05002753 // Simple pass-through to State's detachBuffer method, since
2754 // only buffer attachments to container objects that are bound to the current context
2755 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002756
Yuly Novikov5807a532015-12-03 13:01:22 -05002757 // [OpenGL ES 3.2] section 5.1.2 page 45:
2758 // Attachments to unbound container objects, such as
2759 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2760 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002761 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002762}
2763
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002764void Context::detachFramebuffer(GLuint framebuffer)
2765{
Shannon Woods53a94a82014-06-24 15:20:36 -04002766 // Framebuffer detachment is handled by Context, because 0 is a valid
2767 // Framebuffer object, and a pointer to it must be passed from Context
2768 // to State at binding time.
2769
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002770 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002771 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2772 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2773 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002774
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002775 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776 {
2777 bindReadFramebuffer(0);
2778 }
2779
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002780 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002781 {
2782 bindDrawFramebuffer(0);
2783 }
2784}
2785
2786void Context::detachRenderbuffer(GLuint renderbuffer)
2787{
Jamie Madilla02315b2017-02-23 14:14:47 -05002788 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002789}
2790
Jamie Madill57a89722013-07-02 11:57:03 -04002791void Context::detachVertexArray(GLuint vertexArray)
2792{
Jamie Madill77a72f62015-04-14 11:18:32 -04002793 // Vertex array detachment is handled by Context, because 0 is a valid
2794 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002795 // binding time.
2796
Jamie Madill57a89722013-07-02 11:57:03 -04002797 // [OpenGL ES 3.0.2] section 2.10 page 43:
2798 // If a vertex array object that is currently bound is deleted, the binding
2799 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002800 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002801 {
2802 bindVertexArray(0);
2803 }
2804}
2805
Geoff Langc8058452014-02-03 12:04:11 -05002806void Context::detachTransformFeedback(GLuint transformFeedback)
2807{
Corentin Walleza2257da2016-04-19 16:43:12 -04002808 // Transform feedback detachment is handled by Context, because 0 is a valid
2809 // transform feedback, and a pointer to it must be passed from Context to State at
2810 // binding time.
2811
2812 // The OpenGL specification doesn't mention what should happen when the currently bound
2813 // transform feedback object is deleted. Since it is a container object, we treat it like
2814 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002815 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002816 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002817 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002818 }
Geoff Langc8058452014-02-03 12:04:11 -05002819}
2820
Jamie Madilldc356042013-07-19 16:36:57 -04002821void Context::detachSampler(GLuint sampler)
2822{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002823 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002824}
2825
Yunchao Hea336b902017-08-02 16:05:21 +08002826void Context::detachProgramPipeline(GLuint pipeline)
2827{
2828 mGLState.detachProgramPipeline(this, pipeline);
2829}
2830
Jamie Madill3ef140a2017-08-26 23:11:21 -04002831void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002832{
Shaodde78e82017-05-22 14:13:27 +08002833 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002834 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002835}
2836
Jamie Madille29d1672013-07-19 16:36:57 -04002837void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2838{
Geoff Langc1984ed2016-10-07 12:41:00 -04002839 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002840 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002841 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002842 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002843}
Jamie Madille29d1672013-07-19 16:36:57 -04002844
Geoff Langc1984ed2016-10-07 12:41:00 -04002845void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2846{
2847 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002848 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002849 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002850 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002851}
2852
Brandon Jones59770802018-04-02 13:18:42 -07002853void Context::samplerParameterivRobust(GLuint sampler,
2854 GLenum pname,
2855 GLsizei bufSize,
2856 const GLint *param)
2857{
2858 samplerParameteriv(sampler, pname, param);
2859}
2860
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002861void Context::samplerParameterIivRobust(GLuint sampler,
2862 GLenum pname,
2863 GLsizei bufSize,
2864 const GLint *param)
2865{
2866 UNIMPLEMENTED();
2867}
2868
2869void Context::samplerParameterIuivRobust(GLuint sampler,
2870 GLenum pname,
2871 GLsizei bufSize,
2872 const GLuint *param)
2873{
2874 UNIMPLEMENTED();
2875}
2876
Jamie Madille29d1672013-07-19 16:36:57 -04002877void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2878{
Geoff Langc1984ed2016-10-07 12:41:00 -04002879 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002880 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002881 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002882 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002883}
2884
Geoff Langc1984ed2016-10-07 12:41:00 -04002885void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002886{
Geoff Langc1984ed2016-10-07 12:41:00 -04002887 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002888 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002889 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002890 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002891}
2892
Brandon Jones59770802018-04-02 13:18:42 -07002893void Context::samplerParameterfvRobust(GLuint sampler,
2894 GLenum pname,
2895 GLsizei bufSize,
2896 const GLfloat *param)
2897{
2898 samplerParameterfv(sampler, pname, param);
2899}
2900
Geoff Langc1984ed2016-10-07 12:41:00 -04002901void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002902{
Geoff Langc1984ed2016-10-07 12:41:00 -04002903 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002904 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002905 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002906 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002907}
Jamie Madill9675b802013-07-19 16:36:59 -04002908
Brandon Jones59770802018-04-02 13:18:42 -07002909void Context::getSamplerParameterivRobust(GLuint sampler,
2910 GLenum pname,
2911 GLsizei bufSize,
2912 GLsizei *length,
2913 GLint *params)
2914{
2915 getSamplerParameteriv(sampler, pname, params);
2916}
2917
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002918void Context::getSamplerParameterIivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLint *params)
2923{
2924 UNIMPLEMENTED();
2925}
2926
2927void Context::getSamplerParameterIuivRobust(GLuint sampler,
2928 GLenum pname,
2929 GLsizei bufSize,
2930 GLsizei *length,
2931 GLuint *params)
2932{
2933 UNIMPLEMENTED();
2934}
2935
Geoff Langc1984ed2016-10-07 12:41:00 -04002936void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2937{
2938 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002939 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002940 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002941 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002942}
2943
Brandon Jones59770802018-04-02 13:18:42 -07002944void Context::getSamplerParameterfvRobust(GLuint sampler,
2945 GLenum pname,
2946 GLsizei bufSize,
2947 GLsizei *length,
2948 GLfloat *params)
2949{
2950 getSamplerParameterfv(sampler, pname, params);
2951}
2952
Olli Etuahof0fee072016-03-30 15:11:58 +03002953void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2954{
2955 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002956 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002957}
2958
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002959void Context::initRendererString()
2960{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002961 std::ostringstream rendererString;
2962 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002963 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002964 rendererString << ")";
2965
Geoff Langcec35902014-04-16 10:52:36 -04002966 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967}
2968
Geoff Langc339c4e2016-11-29 10:37:36 -05002969void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002970{
Geoff Langc339c4e2016-11-29 10:37:36 -05002971 const Version &clientVersion = getClientVersion();
2972
2973 std::ostringstream versionString;
2974 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2975 << ANGLE_VERSION_STRING << ")";
2976 mVersionString = MakeStaticString(versionString.str());
2977
2978 std::ostringstream shadingLanguageVersionString;
2979 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2980 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2981 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2982 << ")";
2983 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002984}
2985
Geoff Langcec35902014-04-16 10:52:36 -04002986void Context::initExtensionStrings()
2987{
Geoff Langc339c4e2016-11-29 10:37:36 -05002988 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2989 std::ostringstream combinedStringStream;
2990 std::copy(strings.begin(), strings.end(),
2991 std::ostream_iterator<const char *>(combinedStringStream, " "));
2992 return MakeStaticString(combinedStringStream.str());
2993 };
2994
2995 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002996 for (const auto &extensionString : mExtensions.getStrings())
2997 {
2998 mExtensionStrings.push_back(MakeStaticString(extensionString));
2999 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003000 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003001
Geoff Langc339c4e2016-11-29 10:37:36 -05003002 mRequestableExtensionStrings.clear();
3003 for (const auto &extensionInfo : GetExtensionInfoMap())
3004 {
3005 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003006 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003007 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003008 {
3009 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3010 }
3011 }
3012 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003013}
3014
Geoff Langc339c4e2016-11-29 10:37:36 -05003015const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003016{
Geoff Langc339c4e2016-11-29 10:37:36 -05003017 switch (name)
3018 {
3019 case GL_VENDOR:
3020 return reinterpret_cast<const GLubyte *>("Google Inc.");
3021
3022 case GL_RENDERER:
3023 return reinterpret_cast<const GLubyte *>(mRendererString);
3024
3025 case GL_VERSION:
3026 return reinterpret_cast<const GLubyte *>(mVersionString);
3027
3028 case GL_SHADING_LANGUAGE_VERSION:
3029 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3030
3031 case GL_EXTENSIONS:
3032 return reinterpret_cast<const GLubyte *>(mExtensionString);
3033
3034 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3035 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3036
3037 default:
3038 UNREACHABLE();
3039 return nullptr;
3040 }
Geoff Langcec35902014-04-16 10:52:36 -04003041}
3042
Geoff Langc339c4e2016-11-29 10:37:36 -05003043const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003044{
Geoff Langc339c4e2016-11-29 10:37:36 -05003045 switch (name)
3046 {
3047 case GL_EXTENSIONS:
3048 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3049
3050 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3051 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3052
3053 default:
3054 UNREACHABLE();
3055 return nullptr;
3056 }
Geoff Langcec35902014-04-16 10:52:36 -04003057}
3058
3059size_t Context::getExtensionStringCount() const
3060{
3061 return mExtensionStrings.size();
3062}
3063
Geoff Lang111a99e2017-10-17 10:58:41 -04003064bool Context::isExtensionRequestable(const char *name)
3065{
3066 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3067 auto extension = extensionInfos.find(name);
3068
Geoff Lang111a99e2017-10-17 10:58:41 -04003069 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003070 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003071}
3072
Geoff Langc339c4e2016-11-29 10:37:36 -05003073void Context::requestExtension(const char *name)
3074{
3075 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3076 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3077 const auto &extension = extensionInfos.at(name);
3078 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003079 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003080
3081 if (mExtensions.*(extension.ExtensionsMember))
3082 {
3083 // Extension already enabled
3084 return;
3085 }
3086
3087 mExtensions.*(extension.ExtensionsMember) = true;
3088 updateCaps();
3089 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003090
Jamie Madill2f348d22017-06-05 10:50:59 -04003091 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3092 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003093
Jamie Madill81c2e252017-09-09 23:32:46 -04003094 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3095 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003096 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003097 for (auto &zeroTexture : mZeroTextures)
3098 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003099 if (zeroTexture.get() != nullptr)
3100 {
3101 zeroTexture->signalDirty(this, InitState::Initialized);
3102 }
Geoff Lang9aded172017-04-05 11:07:56 -04003103 }
3104
Jamie Madillb983a4b2018-08-01 11:34:51 -04003105 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003106}
3107
3108size_t Context::getRequestableExtensionStringCount() const
3109{
3110 return mRequestableExtensionStrings.size();
3111}
3112
Jamie Madill493f9572018-05-24 19:52:15 -04003113void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003114{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003115 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003116 ASSERT(transformFeedback != nullptr);
3117 ASSERT(!transformFeedback->isPaused());
3118
Jamie Madill6c1f6712017-02-14 19:08:04 -05003119 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003120 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003121}
3122
3123bool Context::hasActiveTransformFeedback(GLuint program) const
3124{
3125 for (auto pair : mTransformFeedbackMap)
3126 {
3127 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3128 {
3129 return true;
3130 }
3131 }
3132 return false;
3133}
3134
Geoff Lang33f11fb2018-05-07 13:42:47 -04003135Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003136{
3137 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3138
jchen1082af6202018-06-22 10:59:52 +08003139 // Explicitly enable GL_KHR_parallel_shader_compile
3140 supportedExtensions.parallelShaderCompile = true;
3141
Geoff Langb0f917f2017-12-05 13:41:54 -05003142 if (getClientVersion() < ES_2_0)
3143 {
3144 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003145 supportedExtensions.pointSizeArray = true;
3146 supportedExtensions.textureCubeMap = true;
3147 supportedExtensions.pointSprite = true;
3148 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003149 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003150 }
3151
3152 if (getClientVersion() < ES_3_0)
3153 {
3154 // Disable ES3+ extensions
3155 supportedExtensions.colorBufferFloat = false;
3156 supportedExtensions.eglImageExternalEssl3 = false;
3157 supportedExtensions.textureNorm16 = false;
3158 supportedExtensions.multiview = false;
3159 supportedExtensions.maxViews = 1u;
3160 }
3161
3162 if (getClientVersion() < ES_3_1)
3163 {
3164 // Disable ES3.1+ extensions
3165 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003166
3167 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3168 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003169 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003170 }
3171
3172 if (getClientVersion() > ES_2_0)
3173 {
3174 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3175 // supportedExtensions.sRGB = false;
3176 }
3177
3178 // Some extensions are always available because they are implemented in the GL layer.
3179 supportedExtensions.bindUniformLocation = true;
3180 supportedExtensions.vertexArrayObject = true;
3181 supportedExtensions.bindGeneratesResource = true;
3182 supportedExtensions.clientArrays = true;
3183 supportedExtensions.requestExtension = true;
3184
3185 // Enable the no error extension if the context was created with the flag.
3186 supportedExtensions.noError = mSkipValidation;
3187
3188 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003189 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003190
3191 // Explicitly enable GL_KHR_debug
3192 supportedExtensions.debug = true;
3193 supportedExtensions.maxDebugMessageLength = 1024;
3194 supportedExtensions.maxDebugLoggedMessages = 1024;
3195 supportedExtensions.maxDebugGroupStackDepth = 1024;
3196 supportedExtensions.maxLabelLength = 1024;
3197
3198 // Explicitly enable GL_ANGLE_robust_client_memory
3199 supportedExtensions.robustClientMemory = true;
3200
3201 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003202 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003203
3204 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3205 // supports it.
3206 supportedExtensions.robustBufferAccessBehavior =
3207 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3208
3209 // Enable the cache control query unconditionally.
3210 supportedExtensions.programCacheControl = true;
3211
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003212 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003213 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003214 {
3215 // GL_ANGLE_explicit_context_gles1
3216 supportedExtensions.explicitContextGles1 = true;
3217 // GL_ANGLE_explicit_context
3218 supportedExtensions.explicitContext = true;
3219 }
3220
Geoff Langb0f917f2017-12-05 13:41:54 -05003221 return supportedExtensions;
3222}
3223
Geoff Lang33f11fb2018-05-07 13:42:47 -04003224void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003225{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003226 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003227
Geoff Lang33f11fb2018-05-07 13:42:47 -04003228 mSupportedExtensions = generateSupportedExtensions();
3229 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003230
3231 mLimitations = mImplementation->getNativeLimitations();
3232
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003233 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3234 if (getClientVersion() < Version(2, 0))
3235 {
3236 mCaps.maxMultitextureUnits = 4;
3237 mCaps.maxClipPlanes = 6;
3238 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003239 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3240 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3241 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003242 mCaps.minSmoothPointSize = 1.0f;
3243 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003244 mCaps.minSmoothLineWidth = 1.0f;
3245 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003246 }
3247
Luc Ferronad2ae932018-06-11 15:31:17 -04003248 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003249 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003250
Luc Ferronad2ae932018-06-11 15:31:17 -04003251 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3252
Jamie Madill0f80ed82017-09-19 00:24:56 -04003253 if (getClientVersion() < ES_3_1)
3254 {
3255 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3256 }
3257 else
3258 {
3259 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3260 }
Geoff Lang301d1612014-07-09 10:34:37 -04003261
Jiawei Shao54aafe52018-04-27 14:54:57 +08003262 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3263 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003264 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3265
Jamie Madill0f80ed82017-09-19 00:24:56 -04003266 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3267 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3268
3269 // Limit textures as well, so we can use fast bitsets with texture bindings.
3270 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003271 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3272 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3273 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3274 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003275
Jiawei Shaodb342272017-09-27 10:21:45 +08003276 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3277
Geoff Langc287ea62016-09-16 14:46:51 -04003278 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003279 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003280 for (const auto &extensionInfo : GetExtensionInfoMap())
3281 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003282 // If the user has requested that extensions start disabled and they are requestable,
3283 // disable them.
3284 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003285 {
3286 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3287 }
3288 }
3289
3290 // Generate texture caps
3291 updateCaps();
3292}
3293
3294void Context::updateCaps()
3295{
Geoff Lang900013c2014-07-07 11:32:19 -04003296 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003297 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003298
Jamie Madill7b62cf92017-11-02 15:20:49 -04003299 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003300 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003301 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003302 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003303
Geoff Lang0d8b7242015-09-09 14:56:53 -04003304 // Update the format caps based on the client version and extensions.
3305 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3306 // ES3.
3307 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003308 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003309 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003310 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003311 formatCaps.textureAttachment =
3312 formatCaps.textureAttachment &&
3313 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3314 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3315 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003316
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003317 // OpenGL ES does not support multisampling with non-rendererable formats
3318 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003319 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003320 (getClientVersion() < ES_3_1 &&
3321 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003322 {
Geoff Langd87878e2014-09-19 15:42:59 -04003323 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003324 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003325 else
3326 {
3327 // We may have limited the max samples for some required renderbuffer formats due to
3328 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3329 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3330
3331 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3332 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3333 // exception of signed and unsigned integer formats."
3334 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3335 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3336 {
3337 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3338 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3339 }
3340
3341 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3342 if (getClientVersion() >= ES_3_1)
3343 {
3344 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3345 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3346 // the exception that the signed and unsigned integer formats are required only to
3347 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3348 // multisamples, which must be at least one."
3349 if (formatInfo.componentType == GL_INT ||
3350 formatInfo.componentType == GL_UNSIGNED_INT)
3351 {
3352 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3353 }
3354
3355 // GLES 3.1 section 19.3.1.
3356 if (formatCaps.texturable)
3357 {
3358 if (formatInfo.depthBits > 0)
3359 {
3360 mCaps.maxDepthTextureSamples =
3361 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3362 }
3363 else if (formatInfo.redBits > 0)
3364 {
3365 mCaps.maxColorTextureSamples =
3366 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3367 }
3368 }
3369 }
3370 }
Geoff Langd87878e2014-09-19 15:42:59 -04003371
3372 if (formatCaps.texturable && formatInfo.compressed)
3373 {
Geoff Langca271392017-04-05 12:30:00 -04003374 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003375 }
3376
Geoff Langca271392017-04-05 12:30:00 -04003377 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003378 }
Jamie Madill32447362017-06-28 14:53:52 -04003379
3380 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003381 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003382 {
3383 mMemoryProgramCache = nullptr;
3384 }
Corentin Walleze4477002017-12-01 14:39:58 -05003385
3386 // Compute which buffer types are allowed
3387 mValidBufferBindings.reset();
3388 mValidBufferBindings.set(BufferBinding::ElementArray);
3389 mValidBufferBindings.set(BufferBinding::Array);
3390
3391 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3392 {
3393 mValidBufferBindings.set(BufferBinding::PixelPack);
3394 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3395 }
3396
3397 if (getClientVersion() >= ES_3_0)
3398 {
3399 mValidBufferBindings.set(BufferBinding::CopyRead);
3400 mValidBufferBindings.set(BufferBinding::CopyWrite);
3401 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3402 mValidBufferBindings.set(BufferBinding::Uniform);
3403 }
3404
3405 if (getClientVersion() >= ES_3_1)
3406 {
3407 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3408 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3409 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3410 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3411 }
jchen107ae70d82018-07-06 13:47:01 +08003412
3413 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003414}
3415
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003416void Context::initWorkarounds()
3417{
Jamie Madill761b02c2017-06-23 16:27:06 -04003418 // Apply back-end workarounds.
3419 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3420
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003421 // Lose the context upon out of memory error if the application is
3422 // expecting to watch for those events.
3423 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3424}
3425
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003426// Return true if the draw is a no-op, else return false.
3427// A no-op draw occurs if the count of vertices is less than the minimum required to
3428// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3429bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3430{
3431 return count < kMinimumPrimitiveCounts[mode];
3432}
3433
3434bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3435{
3436 return (instanceCount == 0) || noopDraw(mode, count);
3437}
3438
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003439Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003440{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003441 if (mGLES1Renderer)
3442 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003443 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003444 }
3445
Geoff Lang9bf86f02018-07-26 11:46:34 -04003446 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003447
3448 if (isRobustResourceInitEnabled())
3449 {
3450 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3451 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3452 }
3453
Geoff Langa8cb2872018-03-09 16:09:40 -05003454 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003455 return NoError();
3456}
3457
3458Error Context::prepareForClear(GLbitfield mask)
3459{
Geoff Langa8cb2872018-03-09 16:09:40 -05003460 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003461 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003462 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003463 return NoError();
3464}
3465
3466Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3467{
Geoff Langa8cb2872018-03-09 16:09:40 -05003468 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003469 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3470 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003471 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003472 return NoError();
3473}
3474
Geoff Langa8cb2872018-03-09 16:09:40 -05003475Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003476{
Geoff Langa8cb2872018-03-09 16:09:40 -05003477 ANGLE_TRY(syncDirtyObjects(objectMask));
3478 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003479 return NoError();
3480}
3481
Geoff Langa8cb2872018-03-09 16:09:40 -05003482Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003483{
3484 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003485 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003486 mGLState.clearDirtyBits();
3487 return NoError();
3488}
3489
Geoff Langa8cb2872018-03-09 16:09:40 -05003490Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003492 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003493 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003494 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003495 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003496}
Jamie Madillc29968b2016-01-20 11:17:23 -05003497
Geoff Langa8cb2872018-03-09 16:09:40 -05003498Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003499{
3500 return mGLState.syncDirtyObjects(this, objectMask);
3501}
3502
Jamie Madillc29968b2016-01-20 11:17:23 -05003503void Context::blitFramebuffer(GLint srcX0,
3504 GLint srcY0,
3505 GLint srcX1,
3506 GLint srcY1,
3507 GLint dstX0,
3508 GLint dstY0,
3509 GLint dstX1,
3510 GLint dstY1,
3511 GLbitfield mask,
3512 GLenum filter)
3513{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003514 if (mask == 0)
3515 {
3516 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3517 // buffers are copied.
3518 return;
3519 }
3520
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003521 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003522 ASSERT(drawFramebuffer);
3523
3524 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3525 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3526
Jamie Madillbc918e72018-03-08 09:47:21 -05003527 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003528
Jamie Madillc564c072017-06-01 12:45:42 -04003529 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003530}
Jamie Madillc29968b2016-01-20 11:17:23 -05003531
3532void Context::clear(GLbitfield mask)
3533{
Geoff Langd4fff502017-09-22 11:28:28 -04003534 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3535 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003536}
3537
3538void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3539{
Geoff Langd4fff502017-09-22 11:28:28 -04003540 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3541 ANGLE_CONTEXT_TRY(
3542 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
3545void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3546{
Geoff Langd4fff502017-09-22 11:28:28 -04003547 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3548 ANGLE_CONTEXT_TRY(
3549 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003550}
3551
3552void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3553{
Geoff Langd4fff502017-09-22 11:28:28 -04003554 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3555 ANGLE_CONTEXT_TRY(
3556 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003557}
3558
3559void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3560{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003561 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003562 ASSERT(framebufferObject);
3563
3564 // If a buffer is not present, the clear has no effect
3565 if (framebufferObject->getDepthbuffer() == nullptr &&
3566 framebufferObject->getStencilbuffer() == nullptr)
3567 {
3568 return;
3569 }
3570
Geoff Langd4fff502017-09-22 11:28:28 -04003571 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3572 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003573}
3574
3575void Context::readPixels(GLint x,
3576 GLint y,
3577 GLsizei width,
3578 GLsizei height,
3579 GLenum format,
3580 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003581 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003582{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003583 if (width == 0 || height == 0)
3584 {
3585 return;
3586 }
3587
Jamie Madillbc918e72018-03-08 09:47:21 -05003588 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003589
Jamie Madillb6664922017-07-25 12:55:04 -04003590 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3591 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003592
3593 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003594 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003595}
3596
Brandon Jones59770802018-04-02 13:18:42 -07003597void Context::readPixelsRobust(GLint x,
3598 GLint y,
3599 GLsizei width,
3600 GLsizei height,
3601 GLenum format,
3602 GLenum type,
3603 GLsizei bufSize,
3604 GLsizei *length,
3605 GLsizei *columns,
3606 GLsizei *rows,
3607 void *pixels)
3608{
3609 readPixels(x, y, width, height, format, type, pixels);
3610}
3611
3612void Context::readnPixelsRobust(GLint x,
3613 GLint y,
3614 GLsizei width,
3615 GLsizei height,
3616 GLenum format,
3617 GLenum type,
3618 GLsizei bufSize,
3619 GLsizei *length,
3620 GLsizei *columns,
3621 GLsizei *rows,
3622 void *data)
3623{
3624 readPixels(x, y, width, height, format, type, data);
3625}
3626
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003627void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003628 GLint level,
3629 GLenum internalformat,
3630 GLint x,
3631 GLint y,
3632 GLsizei width,
3633 GLsizei height,
3634 GLint border)
3635{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003636 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003637 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003638
Jamie Madillc29968b2016-01-20 11:17:23 -05003639 Rectangle sourceArea(x, y, width, height);
3640
Jamie Madill05b35b22017-10-03 09:01:44 -04003641 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003642 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003643 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003644}
3645
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003646void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003647 GLint level,
3648 GLint xoffset,
3649 GLint yoffset,
3650 GLint x,
3651 GLint y,
3652 GLsizei width,
3653 GLsizei height)
3654{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003655 if (width == 0 || height == 0)
3656 {
3657 return;
3658 }
3659
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003660 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003661 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003662
Jamie Madillc29968b2016-01-20 11:17:23 -05003663 Offset destOffset(xoffset, yoffset, 0);
3664 Rectangle sourceArea(x, y, width, height);
3665
Jamie Madill05b35b22017-10-03 09:01:44 -04003666 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003667 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003668 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003669}
3670
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003671void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003672 GLint level,
3673 GLint xoffset,
3674 GLint yoffset,
3675 GLint zoffset,
3676 GLint x,
3677 GLint y,
3678 GLsizei width,
3679 GLsizei height)
3680{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003681 if (width == 0 || height == 0)
3682 {
3683 return;
3684 }
3685
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003686 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003687 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003688
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 Offset destOffset(xoffset, yoffset, zoffset);
3690 Rectangle sourceArea(x, y, width, height);
3691
Jamie Madill05b35b22017-10-03 09:01:44 -04003692 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3693 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003694 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3695 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003696}
3697
3698void Context::framebufferTexture2D(GLenum target,
3699 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003700 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 GLuint texture,
3702 GLint level)
3703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003705 ASSERT(framebuffer);
3706
3707 if (texture != 0)
3708 {
3709 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003710 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003711 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 }
3713 else
3714 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003715 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003717
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719}
3720
3721void Context::framebufferRenderbuffer(GLenum target,
3722 GLenum attachment,
3723 GLenum renderbuffertarget,
3724 GLuint renderbuffer)
3725{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003727 ASSERT(framebuffer);
3728
3729 if (renderbuffer != 0)
3730 {
3731 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003732
Jamie Madillcc129372018-04-12 09:13:18 -04003733 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 renderbufferObject);
3735 }
3736 else
3737 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003738 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003739 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003740
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003742}
3743
3744void Context::framebufferTextureLayer(GLenum target,
3745 GLenum attachment,
3746 GLuint texture,
3747 GLint level,
3748 GLint layer)
3749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 ASSERT(framebuffer);
3752
3753 if (texture != 0)
3754 {
3755 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003756 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003757 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 }
3759 else
3760 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003761 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003762 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003763
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003764 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003765}
3766
Brandon Jones59770802018-04-02 13:18:42 -07003767void Context::framebufferTextureMultiviewLayered(GLenum target,
3768 GLenum attachment,
3769 GLuint texture,
3770 GLint level,
3771 GLint baseViewIndex,
3772 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003773{
Martin Radev82ef7742017-08-08 17:44:58 +03003774 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3775 ASSERT(framebuffer);
3776
3777 if (texture != 0)
3778 {
3779 Texture *textureObj = getTexture(texture);
3780
Martin Radev18b75ba2017-08-15 15:50:40 +03003781 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003782 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3783 numViews, baseViewIndex);
3784 }
3785 else
3786 {
3787 framebuffer->resetAttachment(this, attachment);
3788 }
3789
3790 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003791}
3792
Brandon Jones59770802018-04-02 13:18:42 -07003793void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3794 GLenum attachment,
3795 GLuint texture,
3796 GLint level,
3797 GLsizei numViews,
3798 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003799{
Martin Radev5dae57b2017-07-14 16:15:55 +03003800 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3801 ASSERT(framebuffer);
3802
3803 if (texture != 0)
3804 {
3805 Texture *textureObj = getTexture(texture);
3806
3807 ImageIndex index = ImageIndex::Make2D(level);
3808 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3809 textureObj, numViews, viewportOffsets);
3810 }
3811 else
3812 {
3813 framebuffer->resetAttachment(this, attachment);
3814 }
3815
3816 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003817}
3818
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003819void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3820{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003821 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3822 ASSERT(framebuffer);
3823
3824 if (texture != 0)
3825 {
3826 Texture *textureObj = getTexture(texture);
3827
3828 ImageIndex index = ImageIndex::MakeFromType(
3829 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3830 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3831 }
3832 else
3833 {
3834 framebuffer->resetAttachment(this, attachment);
3835 }
3836
3837 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003838}
3839
Jamie Madillc29968b2016-01-20 11:17:23 -05003840void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3841{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003842 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 ASSERT(framebuffer);
3844 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003846 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003847}
3848
3849void Context::readBuffer(GLenum mode)
3850{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003851 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003852 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003853 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003854}
3855
3856void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3857{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003858 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003859 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003860
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003861 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003862 ASSERT(framebuffer);
3863
3864 // The specification isn't clear what should be done when the framebuffer isn't complete.
3865 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003866 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003867}
3868
3869void Context::invalidateFramebuffer(GLenum target,
3870 GLsizei numAttachments,
3871 const GLenum *attachments)
3872{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003873 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003874 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003875
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003877 ASSERT(framebuffer);
3878
Jamie Madill427064d2018-04-13 16:20:34 -04003879 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003880 {
Jamie Madill437fa652016-05-03 15:13:24 -04003881 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003882 }
Jamie Madill437fa652016-05-03 15:13:24 -04003883
Jamie Madill4928b7c2017-06-20 12:57:39 -04003884 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003885}
3886
3887void Context::invalidateSubFramebuffer(GLenum target,
3888 GLsizei numAttachments,
3889 const GLenum *attachments,
3890 GLint x,
3891 GLint y,
3892 GLsizei width,
3893 GLsizei height)
3894{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003895 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003896 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003897
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003898 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003899 ASSERT(framebuffer);
3900
Jamie Madill427064d2018-04-13 16:20:34 -04003901 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003902 {
Jamie Madill437fa652016-05-03 15:13:24 -04003903 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003904 }
Jamie Madill437fa652016-05-03 15:13:24 -04003905
3906 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003907 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003908}
3909
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003910void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003911 GLint level,
3912 GLint internalformat,
3913 GLsizei width,
3914 GLsizei height,
3915 GLint border,
3916 GLenum format,
3917 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003918 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003919{
Jamie Madillbc918e72018-03-08 09:47:21 -05003920 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003921
3922 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003923 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003924 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003925 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003926}
3927
Brandon Jones59770802018-04-02 13:18:42 -07003928void Context::texImage2DRobust(TextureTarget target,
3929 GLint level,
3930 GLint internalformat,
3931 GLsizei width,
3932 GLsizei height,
3933 GLint border,
3934 GLenum format,
3935 GLenum type,
3936 GLsizei bufSize,
3937 const void *pixels)
3938{
3939 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3940}
3941
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003942void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003943 GLint level,
3944 GLint internalformat,
3945 GLsizei width,
3946 GLsizei height,
3947 GLsizei depth,
3948 GLint border,
3949 GLenum format,
3950 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003951 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003952{
Jamie Madillbc918e72018-03-08 09:47:21 -05003953 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003954
3955 Extents size(width, height, depth);
3956 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003957 handleError(texture->setImage(this, mGLState.getUnpackState(),
3958 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003959 format, 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::texImage3DRobust(TextureType target,
3963 GLint level,
3964 GLint internalformat,
3965 GLsizei width,
3966 GLsizei height,
3967 GLsizei depth,
3968 GLint border,
3969 GLenum format,
3970 GLenum type,
3971 GLsizei bufSize,
3972 const void *pixels)
3973{
3974 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3975}
3976
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003977void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003978 GLint level,
3979 GLint xoffset,
3980 GLint yoffset,
3981 GLsizei width,
3982 GLsizei height,
3983 GLenum format,
3984 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003985 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003986{
3987 // Zero sized uploads are valid but no-ops
3988 if (width == 0 || height == 0)
3989 {
3990 return;
3991 }
3992
Jamie Madillbc918e72018-03-08 09:47:21 -05003993 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003994
3995 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003996 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04003997
3998 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
3999
4000 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4001 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004002}
4003
Brandon Jones59770802018-04-02 13:18:42 -07004004void Context::texSubImage2DRobust(TextureTarget target,
4005 GLint level,
4006 GLint xoffset,
4007 GLint yoffset,
4008 GLsizei width,
4009 GLsizei height,
4010 GLenum format,
4011 GLenum type,
4012 GLsizei bufSize,
4013 const void *pixels)
4014{
4015 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4016}
4017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004018void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004019 GLint level,
4020 GLint xoffset,
4021 GLint yoffset,
4022 GLint zoffset,
4023 GLsizei width,
4024 GLsizei height,
4025 GLsizei depth,
4026 GLenum format,
4027 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004028 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004029{
4030 // Zero sized uploads are valid but no-ops
4031 if (width == 0 || height == 0 || depth == 0)
4032 {
4033 return;
4034 }
4035
Jamie Madillbc918e72018-03-08 09:47:21 -05004036 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004037
4038 Box area(xoffset, yoffset, zoffset, width, height, depth);
4039 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004040
4041 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4042
4043 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004044 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004045 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004046}
4047
Brandon Jones59770802018-04-02 13:18:42 -07004048void Context::texSubImage3DRobust(TextureType target,
4049 GLint level,
4050 GLint xoffset,
4051 GLint yoffset,
4052 GLint zoffset,
4053 GLsizei width,
4054 GLsizei height,
4055 GLsizei depth,
4056 GLenum format,
4057 GLenum type,
4058 GLsizei bufSize,
4059 const void *pixels)
4060{
4061 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4062 pixels);
4063}
4064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004065void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004066 GLint level,
4067 GLenum internalformat,
4068 GLsizei width,
4069 GLsizei height,
4070 GLint border,
4071 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004072 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004073{
Jamie Madillbc918e72018-03-08 09:47:21 -05004074 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004075
4076 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004077 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004078 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4079 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004080 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004081}
4082
Brandon Jones59770802018-04-02 13:18:42 -07004083void Context::compressedTexImage2DRobust(TextureTarget target,
4084 GLint level,
4085 GLenum internalformat,
4086 GLsizei width,
4087 GLsizei height,
4088 GLint border,
4089 GLsizei imageSize,
4090 GLsizei dataSize,
4091 const GLvoid *data)
4092{
4093 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4094}
4095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004096void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004097 GLint level,
4098 GLenum internalformat,
4099 GLsizei width,
4100 GLsizei height,
4101 GLsizei depth,
4102 GLint border,
4103 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004104 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004105{
Jamie Madillbc918e72018-03-08 09:47:21 -05004106 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004107
4108 Extents size(width, height, depth);
4109 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004110 handleError(texture->setCompressedImage(
4111 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004112 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004113}
4114
Brandon Jones59770802018-04-02 13:18:42 -07004115void Context::compressedTexImage3DRobust(TextureType target,
4116 GLint level,
4117 GLenum internalformat,
4118 GLsizei width,
4119 GLsizei height,
4120 GLsizei depth,
4121 GLint border,
4122 GLsizei imageSize,
4123 GLsizei dataSize,
4124 const GLvoid *data)
4125{
4126 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4127 data);
4128}
4129
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004130void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004131 GLint level,
4132 GLint xoffset,
4133 GLint yoffset,
4134 GLsizei width,
4135 GLsizei height,
4136 GLenum format,
4137 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004138 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004139{
Jamie Madillbc918e72018-03-08 09:47:21 -05004140 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004141
4142 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004143 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004144 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4145 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004146 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004147}
4148
Brandon Jones59770802018-04-02 13:18:42 -07004149void Context::compressedTexSubImage2DRobust(TextureTarget target,
4150 GLint level,
4151 GLint xoffset,
4152 GLint yoffset,
4153 GLsizei width,
4154 GLsizei height,
4155 GLenum format,
4156 GLsizei imageSize,
4157 GLsizei dataSize,
4158 const GLvoid *data)
4159{
4160 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4161 data);
4162}
4163
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004164void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004165 GLint level,
4166 GLint xoffset,
4167 GLint yoffset,
4168 GLint zoffset,
4169 GLsizei width,
4170 GLsizei height,
4171 GLsizei depth,
4172 GLenum format,
4173 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004174 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004175{
4176 // Zero sized uploads are valid but no-ops
4177 if (width == 0 || height == 0)
4178 {
4179 return;
4180 }
4181
Jamie Madillbc918e72018-03-08 09:47:21 -05004182 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004183
4184 Box area(xoffset, yoffset, zoffset, width, height, depth);
4185 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004186 handleError(texture->setCompressedSubImage(
4187 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004188 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004189}
4190
Brandon Jones59770802018-04-02 13:18:42 -07004191void Context::compressedTexSubImage3DRobust(TextureType target,
4192 GLint level,
4193 GLint xoffset,
4194 GLint yoffset,
4195 GLint zoffset,
4196 GLsizei width,
4197 GLsizei height,
4198 GLsizei depth,
4199 GLenum format,
4200 GLsizei imageSize,
4201 GLsizei dataSize,
4202 const GLvoid *data)
4203{
4204 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4205 imageSize, data);
4206}
4207
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004208void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004209{
4210 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004211 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004212}
4213
Jamie Madill007530e2017-12-28 14:27:04 -05004214void Context::copyTexture(GLuint sourceId,
4215 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004216 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004217 GLuint destId,
4218 GLint destLevel,
4219 GLint internalFormat,
4220 GLenum destType,
4221 GLboolean unpackFlipY,
4222 GLboolean unpackPremultiplyAlpha,
4223 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004224{
Jamie Madillbc918e72018-03-08 09:47:21 -05004225 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004226
4227 gl::Texture *sourceTexture = getTexture(sourceId);
4228 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004229 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4230 sourceLevel, ConvertToBool(unpackFlipY),
4231 ConvertToBool(unpackPremultiplyAlpha),
4232 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004233}
4234
Jamie Madill007530e2017-12-28 14:27:04 -05004235void Context::copySubTexture(GLuint sourceId,
4236 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004237 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004238 GLuint destId,
4239 GLint destLevel,
4240 GLint xoffset,
4241 GLint yoffset,
4242 GLint x,
4243 GLint y,
4244 GLsizei width,
4245 GLsizei height,
4246 GLboolean unpackFlipY,
4247 GLboolean unpackPremultiplyAlpha,
4248 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004249{
4250 // Zero sized copies are valid but no-ops
4251 if (width == 0 || height == 0)
4252 {
4253 return;
4254 }
4255
Jamie Madillbc918e72018-03-08 09:47:21 -05004256 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004257
4258 gl::Texture *sourceTexture = getTexture(sourceId);
4259 gl::Texture *destTexture = getTexture(destId);
4260 Offset offset(xoffset, yoffset, 0);
4261 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004262 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4263 ConvertToBool(unpackFlipY),
4264 ConvertToBool(unpackPremultiplyAlpha),
4265 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004266}
4267
Jamie Madill007530e2017-12-28 14:27:04 -05004268void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004269{
Jamie Madillbc918e72018-03-08 09:47:21 -05004270 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004271
4272 gl::Texture *sourceTexture = getTexture(sourceId);
4273 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004274 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004275}
4276
Corentin Wallez336129f2017-10-17 15:55:40 -04004277void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004278{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004279 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004280 ASSERT(buffer);
4281
Geoff Lang496c02d2016-10-20 11:38:11 -07004282 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004283}
4284
Brandon Jones59770802018-04-02 13:18:42 -07004285void Context::getBufferPointervRobust(BufferBinding target,
4286 GLenum pname,
4287 GLsizei bufSize,
4288 GLsizei *length,
4289 void **params)
4290{
4291 getBufferPointerv(target, pname, params);
4292}
4293
Corentin Wallez336129f2017-10-17 15:55:40 -04004294void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004295{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004297 ASSERT(buffer);
4298
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004299 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004300 if (error.isError())
4301 {
Jamie Madill437fa652016-05-03 15:13:24 -04004302 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004303 return nullptr;
4304 }
4305
4306 return buffer->getMapPointer();
4307}
4308
Corentin Wallez336129f2017-10-17 15:55:40 -04004309GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004310{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004311 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004312 ASSERT(buffer);
4313
4314 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004315 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004316 if (error.isError())
4317 {
Jamie Madill437fa652016-05-03 15:13:24 -04004318 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004319 return GL_FALSE;
4320 }
4321
4322 return result;
4323}
4324
Corentin Wallez336129f2017-10-17 15:55:40 -04004325void *Context::mapBufferRange(BufferBinding target,
4326 GLintptr offset,
4327 GLsizeiptr length,
4328 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004331 ASSERT(buffer);
4332
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004333 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004334 if (error.isError())
4335 {
Jamie Madill437fa652016-05-03 15:13:24 -04004336 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004337 return nullptr;
4338 }
4339
4340 return buffer->getMapPointer();
4341}
4342
Corentin Wallez336129f2017-10-17 15:55:40 -04004343void Context::flushMappedBufferRange(BufferBinding /*target*/,
4344 GLintptr /*offset*/,
4345 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004346{
4347 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4348}
4349
Jamie Madillbc918e72018-03-08 09:47:21 -05004350Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004351{
Geoff Langa8cb2872018-03-09 16:09:40 -05004352 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004353}
4354
Jamie Madillbc918e72018-03-08 09:47:21 -05004355Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004356{
Geoff Langa8cb2872018-03-09 16:09:40 -05004357 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004358}
4359
Jamie Madillbc918e72018-03-08 09:47:21 -05004360Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004361{
Geoff Langa8cb2872018-03-09 16:09:40 -05004362 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004363}
4364
Geoff Lang9bf86f02018-07-26 11:46:34 -04004365Error Context::syncStateForPathOperation()
4366{
4367 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4368
4369 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4370 ANGLE_TRY(syncDirtyBits());
4371
4372 return NoError();
4373}
4374
Jiajia Qin5451d532017-11-16 17:16:34 +08004375void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4376{
4377 UNIMPLEMENTED();
4378}
4379
Jamie Madillc20ab272016-06-09 07:20:46 -07004380void Context::activeTexture(GLenum texture)
4381{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383}
4384
Jamie Madill876429b2017-04-20 15:46:24 -04004385void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004386{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004388}
4389
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004390void Context::blendEquation(GLenum mode)
4391{
4392 mGLState.setBlendEquation(mode, mode);
4393}
4394
Jamie Madillc20ab272016-06-09 07:20:46 -07004395void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4396{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398}
4399
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004400void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4401{
4402 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4403}
4404
Jamie Madillc20ab272016-06-09 07:20:46 -07004405void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4406{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
Jamie Madill876429b2017-04-20 15:46:24 -04004410void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004411{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
Jamie Madill876429b2017-04-20 15:46:24 -04004415void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004416{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418}
4419
4420void Context::clearStencil(GLint s)
4421{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004422 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004423}
4424
4425void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4426{
Geoff Lang92019432017-11-20 13:09:34 -05004427 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4428 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004429}
4430
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004431void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::depthFunc(GLenum func)
4437{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004438 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004439}
4440
4441void Context::depthMask(GLboolean flag)
4442{
Geoff Lang92019432017-11-20 13:09:34 -05004443 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004444}
4445
Jamie Madill876429b2017-04-20 15:46:24 -04004446void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449}
4450
4451void Context::disable(GLenum cap)
4452{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004454 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004455}
4456
4457void Context::disableVertexAttribArray(GLuint index)
4458{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004460 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461}
4462
4463void Context::enable(GLenum cap)
4464{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004466 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::enableVertexAttribArray(GLuint index)
4470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004472 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004473}
4474
4475void Context::frontFace(GLenum mode)
4476{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::hint(GLenum target, GLenum mode)
4481{
4482 switch (target)
4483 {
4484 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004485 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004486 break;
4487
4488 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490 break;
4491
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004492 case GL_PERSPECTIVE_CORRECTION_HINT:
4493 case GL_POINT_SMOOTH_HINT:
4494 case GL_LINE_SMOOTH_HINT:
4495 case GL_FOG_HINT:
4496 mGLState.gles1().setHint(target, mode);
4497 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004498 default:
4499 UNREACHABLE();
4500 return;
4501 }
4502}
4503
4504void Context::lineWidth(GLfloat width)
4505{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
4509void Context::pixelStorei(GLenum pname, GLint param)
4510{
4511 switch (pname)
4512 {
4513 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004514 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004515 break;
4516
4517 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519 break;
4520
4521 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523 break;
4524
4525 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004526 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004527 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004528 break;
4529
4530 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004531 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004532 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533 break;
4534
4535 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004536 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538 break;
4539
4540 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004541 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 break;
4544
4545 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004546 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 break;
4549
4550 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004551 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004552 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553 break;
4554
4555 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004556 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558 break;
4559
4560 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004561 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563 break;
4564
4565 default:
4566 UNREACHABLE();
4567 return;
4568 }
4569}
4570
4571void Context::polygonOffset(GLfloat factor, GLfloat units)
4572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
Jamie Madill876429b2017-04-20 15:46:24 -04004576void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004577{
Geoff Lang92019432017-11-20 13:09:34 -05004578 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
Jiawei Shaodb342272017-09-27 10:21:45 +08004581void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4582{
4583 mGLState.setSampleMaskParams(maskNumber, mask);
4584}
4585
Jamie Madillc20ab272016-06-09 07:20:46 -07004586void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004588 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004589}
4590
4591void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4592{
4593 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4594 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004595 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596 }
4597
4598 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4599 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004600 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004602
4603 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004604}
4605
4606void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4607{
4608 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4609 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611 }
4612
4613 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4614 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004615 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004617
4618 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004619}
4620
4621void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4622{
4623 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4624 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626 }
4627
4628 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4629 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631 }
4632}
4633
4634void Context::vertexAttrib1f(GLuint index, GLfloat x)
4635{
4636 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004638 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639}
4640
4641void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4642{
4643 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004645 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
4648void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4649{
4650 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004651 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004652 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4656{
4657 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004659 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660}
4661
4662void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4663{
4664 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004665 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004666 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
4669void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4670{
4671 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004673 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
4676void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4677{
4678 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004680 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004681}
4682
4683void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4684{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004685 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004686 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004687}
4688
4689void Context::vertexAttribPointer(GLuint index,
4690 GLint size,
4691 GLenum type,
4692 GLboolean normalized,
4693 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004694 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004695{
Corentin Wallez336129f2017-10-17 15:55:40 -04004696 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004697 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004698 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
Shao80957d92017-02-20 21:25:59 +08004701void Context::vertexAttribFormat(GLuint attribIndex,
4702 GLint size,
4703 GLenum type,
4704 GLboolean normalized,
4705 GLuint relativeOffset)
4706{
Geoff Lang92019432017-11-20 13:09:34 -05004707 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004708 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004709 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004710}
4711
4712void Context::vertexAttribIFormat(GLuint attribIndex,
4713 GLint size,
4714 GLenum type,
4715 GLuint relativeOffset)
4716{
4717 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004718 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004719}
4720
4721void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4722{
Shaodde78e82017-05-22 14:13:27 +08004723 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004724 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004725}
4726
Jiajia Qin5451d532017-11-16 17:16:34 +08004727void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004728{
4729 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004730 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004731}
4732
Jamie Madillc20ab272016-06-09 07:20:46 -07004733void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004735 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004736}
4737
4738void Context::vertexAttribIPointer(GLuint index,
4739 GLint size,
4740 GLenum type,
4741 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004742 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004743{
Corentin Wallez336129f2017-10-17 15:55:40 -04004744 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4745 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004746 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004747}
4748
4749void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4750{
4751 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004752 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004753 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004754}
4755
4756void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4757{
4758 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004759 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004760 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004761}
4762
4763void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004765 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004766 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004767}
4768
4769void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004771 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004772 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004773}
4774
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004775void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4776{
4777 const VertexAttribCurrentValueData &currentValues =
4778 getGLState().getVertexAttribCurrentValue(index);
4779 const VertexArray *vao = getGLState().getVertexArray();
4780 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4781 currentValues, pname, params);
4782}
4783
Brandon Jones59770802018-04-02 13:18:42 -07004784void Context::getVertexAttribivRobust(GLuint index,
4785 GLenum pname,
4786 GLsizei bufSize,
4787 GLsizei *length,
4788 GLint *params)
4789{
4790 getVertexAttribiv(index, pname, params);
4791}
4792
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004793void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4794{
4795 const VertexAttribCurrentValueData &currentValues =
4796 getGLState().getVertexAttribCurrentValue(index);
4797 const VertexArray *vao = getGLState().getVertexArray();
4798 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4799 currentValues, pname, params);
4800}
4801
Brandon Jones59770802018-04-02 13:18:42 -07004802void Context::getVertexAttribfvRobust(GLuint index,
4803 GLenum pname,
4804 GLsizei bufSize,
4805 GLsizei *length,
4806 GLfloat *params)
4807{
4808 getVertexAttribfv(index, pname, params);
4809}
4810
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004811void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4812{
4813 const VertexAttribCurrentValueData &currentValues =
4814 getGLState().getVertexAttribCurrentValue(index);
4815 const VertexArray *vao = getGLState().getVertexArray();
4816 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4817 currentValues, pname, params);
4818}
4819
Brandon Jones59770802018-04-02 13:18:42 -07004820void Context::getVertexAttribIivRobust(GLuint index,
4821 GLenum pname,
4822 GLsizei bufSize,
4823 GLsizei *length,
4824 GLint *params)
4825{
4826 getVertexAttribIiv(index, pname, params);
4827}
4828
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004829void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4830{
4831 const VertexAttribCurrentValueData &currentValues =
4832 getGLState().getVertexAttribCurrentValue(index);
4833 const VertexArray *vao = getGLState().getVertexArray();
4834 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4835 currentValues, pname, params);
4836}
4837
Brandon Jones59770802018-04-02 13:18:42 -07004838void Context::getVertexAttribIuivRobust(GLuint index,
4839 GLenum pname,
4840 GLsizei bufSize,
4841 GLsizei *length,
4842 GLuint *params)
4843{
4844 getVertexAttribIuiv(index, pname, params);
4845}
4846
Jamie Madill876429b2017-04-20 15:46:24 -04004847void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004848{
4849 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4850 QueryVertexAttribPointerv(attrib, pname, pointer);
4851}
4852
Brandon Jones59770802018-04-02 13:18:42 -07004853void Context::getVertexAttribPointervRobust(GLuint index,
4854 GLenum pname,
4855 GLsizei bufSize,
4856 GLsizei *length,
4857 void **pointer)
4858{
4859 getVertexAttribPointerv(index, pname, pointer);
4860}
4861
Jamie Madillc20ab272016-06-09 07:20:46 -07004862void Context::debugMessageControl(GLenum source,
4863 GLenum type,
4864 GLenum severity,
4865 GLsizei count,
4866 const GLuint *ids,
4867 GLboolean enabled)
4868{
4869 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004870 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004871 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004872}
4873
4874void Context::debugMessageInsert(GLenum source,
4875 GLenum type,
4876 GLuint id,
4877 GLenum severity,
4878 GLsizei length,
4879 const GLchar *buf)
4880{
4881 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004882 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004883}
4884
4885void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4886{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004887 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004888}
4889
4890GLuint Context::getDebugMessageLog(GLuint count,
4891 GLsizei bufSize,
4892 GLenum *sources,
4893 GLenum *types,
4894 GLuint *ids,
4895 GLenum *severities,
4896 GLsizei *lengths,
4897 GLchar *messageLog)
4898{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004899 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4900 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004901}
4902
4903void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4904{
4905 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004906 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004907 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004908}
4909
4910void Context::popDebugGroup()
4911{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004912 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004913 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004914}
4915
Corentin Wallez336129f2017-10-17 15:55:40 -04004916void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004917{
4918 Buffer *buffer = mGLState.getTargetBuffer(target);
4919 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004920 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004921}
4922
Corentin Wallez336129f2017-10-17 15:55:40 -04004923void Context::bufferSubData(BufferBinding target,
4924 GLintptr offset,
4925 GLsizeiptr size,
4926 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004927{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004928 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004929 {
4930 return;
4931 }
4932
4933 Buffer *buffer = mGLState.getTargetBuffer(target);
4934 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004935 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004936}
4937
Jamie Madillef300b12016-10-07 15:12:09 -04004938void Context::attachShader(GLuint program, GLuint shader)
4939{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004940 Program *programObject = mState.mShaderPrograms->getProgram(program);
4941 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004942 ASSERT(programObject && shaderObject);
4943 programObject->attachShader(shaderObject);
4944}
4945
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004946const Workarounds &Context::getWorkarounds() const
4947{
4948 return mWorkarounds;
4949}
4950
Corentin Wallez336129f2017-10-17 15:55:40 -04004951void Context::copyBufferSubData(BufferBinding readTarget,
4952 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004953 GLintptr readOffset,
4954 GLintptr writeOffset,
4955 GLsizeiptr size)
4956{
4957 // if size is zero, the copy is a successful no-op
4958 if (size == 0)
4959 {
4960 return;
4961 }
4962
4963 // TODO(jmadill): cache these.
4964 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4965 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4966
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004967 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004968}
4969
Jamie Madill01a80ee2016-11-07 12:06:18 -05004970void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4971{
4972 Program *programObject = getProgram(program);
4973 // TODO(jmadill): Re-use this from the validation if possible.
4974 ASSERT(programObject);
4975 programObject->bindAttributeLocation(index, name);
4976}
4977
Corentin Wallez336129f2017-10-17 15:55:40 -04004978void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004979{
Corentin Wallez336129f2017-10-17 15:55:40 -04004980 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4981 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004982 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004983}
4984
Corentin Wallez336129f2017-10-17 15:55:40 -04004985void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004986{
4987 bindBufferRange(target, index, buffer, 0, 0);
4988}
4989
Corentin Wallez336129f2017-10-17 15:55:40 -04004990void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004991 GLuint index,
4992 GLuint buffer,
4993 GLintptr offset,
4994 GLsizeiptr size)
4995{
Jamie Madill6d32cef2018-08-14 02:34:28 -04004996 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4997 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
4998 if (target == BufferBinding::Uniform)
4999 {
5000 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005001 mStateCache.onUniformBufferStateChange(this);
5002 }
5003 else
5004 {
5005 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005006 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005007}
5008
Jamie Madill01a80ee2016-11-07 12:06:18 -05005009void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5010{
5011 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5012 {
5013 bindReadFramebuffer(framebuffer);
5014 }
5015
5016 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5017 {
5018 bindDrawFramebuffer(framebuffer);
5019 }
5020}
5021
5022void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5023{
5024 ASSERT(target == GL_RENDERBUFFER);
5025 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005026 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005027 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005028}
5029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005030void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005031 GLsizei samples,
5032 GLenum internalformat,
5033 GLsizei width,
5034 GLsizei height,
5035 GLboolean fixedsamplelocations)
5036{
5037 Extents size(width, height, 1);
5038 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005039 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5040 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005041}
5042
Olli Etuaho89664842018-08-24 14:45:36 +03005043void Context::texStorage3DMultisample(TextureType target,
5044 GLsizei samples,
5045 GLenum internalformat,
5046 GLsizei width,
5047 GLsizei height,
5048 GLsizei depth,
5049 GLboolean fixedsamplelocations)
5050{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005051 Extents size(width, height, depth);
5052 Texture *texture = getTargetTexture(target);
5053 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5054 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005055}
5056
JiangYizhoubddc46b2016-12-09 09:50:51 +08005057void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5058{
JiangYizhou5b03f472017-01-09 10:22:53 +08005059 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5060 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005061 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005062 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005063
5064 switch (pname)
5065 {
5066 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005067 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005068 break;
5069 default:
5070 UNREACHABLE();
5071 }
5072}
5073
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005074void Context::getMultisamplefvRobust(GLenum pname,
5075 GLuint index,
5076 GLsizei bufSize,
5077 GLsizei *length,
5078 GLfloat *val)
5079{
5080 UNIMPLEMENTED();
5081}
5082
Jamie Madille8fb6402017-02-14 17:56:40 -05005083void Context::renderbufferStorage(GLenum target,
5084 GLenum internalformat,
5085 GLsizei width,
5086 GLsizei height)
5087{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005088 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5089 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5090
Jamie Madille8fb6402017-02-14 17:56:40 -05005091 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005092 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005093}
5094
5095void Context::renderbufferStorageMultisample(GLenum target,
5096 GLsizei samples,
5097 GLenum internalformat,
5098 GLsizei width,
5099 GLsizei height)
5100{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005101 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5102 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005103
5104 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005105 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005106 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005107}
5108
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005109void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5110{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005111 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005112 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005113}
5114
JiangYizhoue18e6392017-02-20 10:32:23 +08005115void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5116{
5117 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5118 QueryFramebufferParameteriv(framebuffer, pname, params);
5119}
5120
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005121void Context::getFramebufferParameterivRobust(GLenum target,
5122 GLenum pname,
5123 GLsizei bufSize,
5124 GLsizei *length,
5125 GLint *params)
5126{
5127 UNIMPLEMENTED();
5128}
5129
Jiajia Qin5451d532017-11-16 17:16:34 +08005130void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005131{
5132 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005133 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005134}
5135
Jamie Madilldec86232018-07-11 09:01:18 -04005136bool Context::getScratchBuffer(size_t requstedSizeBytes,
5137 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005138{
Jamie Madilldec86232018-07-11 09:01:18 -04005139 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005140}
5141
Jamie Madilldec86232018-07-11 09:01:18 -04005142bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5143 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005144{
Jamie Madilldec86232018-07-11 09:01:18 -04005145 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005146}
5147
Xinghua Cao10a4d432017-11-28 14:46:26 +08005148Error Context::prepareForDispatch()
5149{
Geoff Langa8cb2872018-03-09 16:09:40 -05005150 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005151
5152 if (isRobustResourceInitEnabled())
5153 {
5154 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5155 }
5156
5157 return NoError();
5158}
5159
Xinghua Cao2b396592017-03-29 15:36:04 +08005160void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5161{
5162 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5163 {
5164 return;
5165 }
5166
Xinghua Cao10a4d432017-11-28 14:46:26 +08005167 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005168 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005169}
5170
Jiajia Qin5451d532017-11-16 17:16:34 +08005171void Context::dispatchComputeIndirect(GLintptr indirect)
5172{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005173 ANGLE_CONTEXT_TRY(prepareForDispatch());
5174 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005175}
5176
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005177void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005178 GLsizei levels,
5179 GLenum internalFormat,
5180 GLsizei width,
5181 GLsizei height)
5182{
5183 Extents size(width, height, 1);
5184 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005185 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005186}
5187
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005188void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005189 GLsizei levels,
5190 GLenum internalFormat,
5191 GLsizei width,
5192 GLsizei height,
5193 GLsizei depth)
5194{
5195 Extents size(width, height, depth);
5196 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005197 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005198}
5199
Jiajia Qin5451d532017-11-16 17:16:34 +08005200void Context::memoryBarrier(GLbitfield barriers)
5201{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005202 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005203}
5204
5205void Context::memoryBarrierByRegion(GLbitfield barriers)
5206{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005207 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005208}
5209
Jamie Madillc1d770e2017-04-13 17:31:24 -04005210GLenum Context::checkFramebufferStatus(GLenum target)
5211{
5212 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5213 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005214 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005215}
5216
5217void Context::compileShader(GLuint shader)
5218{
5219 Shader *shaderObject = GetValidShader(this, shader);
5220 if (!shaderObject)
5221 {
5222 return;
5223 }
5224 shaderObject->compile(this);
5225}
5226
5227void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5228{
5229 for (int i = 0; i < n; i++)
5230 {
5231 deleteBuffer(buffers[i]);
5232 }
5233}
5234
5235void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5236{
5237 for (int i = 0; i < n; i++)
5238 {
5239 if (framebuffers[i] != 0)
5240 {
5241 deleteFramebuffer(framebuffers[i]);
5242 }
5243 }
5244}
5245
5246void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5247{
5248 for (int i = 0; i < n; i++)
5249 {
5250 deleteRenderbuffer(renderbuffers[i]);
5251 }
5252}
5253
5254void Context::deleteTextures(GLsizei n, const GLuint *textures)
5255{
5256 for (int i = 0; i < n; i++)
5257 {
5258 if (textures[i] != 0)
5259 {
5260 deleteTexture(textures[i]);
5261 }
5262 }
5263}
5264
5265void Context::detachShader(GLuint program, GLuint shader)
5266{
5267 Program *programObject = getProgram(program);
5268 ASSERT(programObject);
5269
5270 Shader *shaderObject = getShader(shader);
5271 ASSERT(shaderObject);
5272
5273 programObject->detachShader(this, shaderObject);
5274}
5275
5276void Context::genBuffers(GLsizei n, GLuint *buffers)
5277{
5278 for (int i = 0; i < n; i++)
5279 {
5280 buffers[i] = createBuffer();
5281 }
5282}
5283
5284void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5285{
5286 for (int i = 0; i < n; i++)
5287 {
5288 framebuffers[i] = createFramebuffer();
5289 }
5290}
5291
5292void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5293{
5294 for (int i = 0; i < n; i++)
5295 {
5296 renderbuffers[i] = createRenderbuffer();
5297 }
5298}
5299
5300void Context::genTextures(GLsizei n, GLuint *textures)
5301{
5302 for (int i = 0; i < n; i++)
5303 {
5304 textures[i] = createTexture();
5305 }
5306}
5307
5308void Context::getActiveAttrib(GLuint program,
5309 GLuint index,
5310 GLsizei bufsize,
5311 GLsizei *length,
5312 GLint *size,
5313 GLenum *type,
5314 GLchar *name)
5315{
5316 Program *programObject = getProgram(program);
5317 ASSERT(programObject);
5318 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5319}
5320
5321void Context::getActiveUniform(GLuint program,
5322 GLuint index,
5323 GLsizei bufsize,
5324 GLsizei *length,
5325 GLint *size,
5326 GLenum *type,
5327 GLchar *name)
5328{
5329 Program *programObject = getProgram(program);
5330 ASSERT(programObject);
5331 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5332}
5333
5334void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5335{
5336 Program *programObject = getProgram(program);
5337 ASSERT(programObject);
5338 programObject->getAttachedShaders(maxcount, count, shaders);
5339}
5340
5341GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5342{
5343 Program *programObject = getProgram(program);
5344 ASSERT(programObject);
5345 return programObject->getAttributeLocation(name);
5346}
5347
5348void Context::getBooleanv(GLenum pname, GLboolean *params)
5349{
5350 GLenum nativeType;
5351 unsigned int numParams = 0;
5352 getQueryParameterInfo(pname, &nativeType, &numParams);
5353
5354 if (nativeType == GL_BOOL)
5355 {
5356 getBooleanvImpl(pname, params);
5357 }
5358 else
5359 {
5360 CastStateValues(this, nativeType, pname, numParams, params);
5361 }
5362}
5363
Brandon Jones59770802018-04-02 13:18:42 -07005364void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5365{
5366 getBooleanv(pname, params);
5367}
5368
Jamie Madillc1d770e2017-04-13 17:31:24 -04005369void Context::getFloatv(GLenum pname, GLfloat *params)
5370{
5371 GLenum nativeType;
5372 unsigned int numParams = 0;
5373 getQueryParameterInfo(pname, &nativeType, &numParams);
5374
5375 if (nativeType == GL_FLOAT)
5376 {
5377 getFloatvImpl(pname, params);
5378 }
5379 else
5380 {
5381 CastStateValues(this, nativeType, pname, numParams, params);
5382 }
5383}
5384
Brandon Jones59770802018-04-02 13:18:42 -07005385void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5386{
5387 getFloatv(pname, params);
5388}
5389
Jamie Madillc1d770e2017-04-13 17:31:24 -04005390void Context::getIntegerv(GLenum pname, GLint *params)
5391{
5392 GLenum nativeType;
5393 unsigned int numParams = 0;
5394 getQueryParameterInfo(pname, &nativeType, &numParams);
5395
5396 if (nativeType == GL_INT)
5397 {
5398 getIntegervImpl(pname, params);
5399 }
5400 else
5401 {
5402 CastStateValues(this, nativeType, pname, numParams, params);
5403 }
5404}
5405
Brandon Jones59770802018-04-02 13:18:42 -07005406void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5407{
5408 getIntegerv(pname, data);
5409}
5410
Jamie Madillc1d770e2017-04-13 17:31:24 -04005411void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5412{
5413 Program *programObject = getProgram(program);
5414 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005415 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005416}
5417
Brandon Jones59770802018-04-02 13:18:42 -07005418void Context::getProgramivRobust(GLuint program,
5419 GLenum pname,
5420 GLsizei bufSize,
5421 GLsizei *length,
5422 GLint *params)
5423{
5424 getProgramiv(program, pname, params);
5425}
5426
Jiajia Qin5451d532017-11-16 17:16:34 +08005427void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5428{
5429 UNIMPLEMENTED();
5430}
5431
Jamie Madillbe849e42017-05-02 15:49:00 -04005432void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433{
5434 Program *programObject = getProgram(program);
5435 ASSERT(programObject);
5436 programObject->getInfoLog(bufsize, length, infolog);
5437}
5438
Jiajia Qin5451d532017-11-16 17:16:34 +08005439void Context::getProgramPipelineInfoLog(GLuint pipeline,
5440 GLsizei bufSize,
5441 GLsizei *length,
5442 GLchar *infoLog)
5443{
5444 UNIMPLEMENTED();
5445}
5446
Jamie Madillc1d770e2017-04-13 17:31:24 -04005447void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5448{
5449 Shader *shaderObject = getShader(shader);
5450 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005451 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452}
5453
Brandon Jones59770802018-04-02 13:18:42 -07005454void Context::getShaderivRobust(GLuint shader,
5455 GLenum pname,
5456 GLsizei bufSize,
5457 GLsizei *length,
5458 GLint *params)
5459{
5460 getShaderiv(shader, pname, params);
5461}
5462
Jamie Madillc1d770e2017-04-13 17:31:24 -04005463void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5464{
5465 Shader *shaderObject = getShader(shader);
5466 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005467 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005468}
5469
5470void Context::getShaderPrecisionFormat(GLenum shadertype,
5471 GLenum precisiontype,
5472 GLint *range,
5473 GLint *precision)
5474{
5475 // TODO(jmadill): Compute shaders.
5476
5477 switch (shadertype)
5478 {
5479 case GL_VERTEX_SHADER:
5480 switch (precisiontype)
5481 {
5482 case GL_LOW_FLOAT:
5483 mCaps.vertexLowpFloat.get(range, precision);
5484 break;
5485 case GL_MEDIUM_FLOAT:
5486 mCaps.vertexMediumpFloat.get(range, precision);
5487 break;
5488 case GL_HIGH_FLOAT:
5489 mCaps.vertexHighpFloat.get(range, precision);
5490 break;
5491
5492 case GL_LOW_INT:
5493 mCaps.vertexLowpInt.get(range, precision);
5494 break;
5495 case GL_MEDIUM_INT:
5496 mCaps.vertexMediumpInt.get(range, precision);
5497 break;
5498 case GL_HIGH_INT:
5499 mCaps.vertexHighpInt.get(range, precision);
5500 break;
5501
5502 default:
5503 UNREACHABLE();
5504 return;
5505 }
5506 break;
5507
5508 case GL_FRAGMENT_SHADER:
5509 switch (precisiontype)
5510 {
5511 case GL_LOW_FLOAT:
5512 mCaps.fragmentLowpFloat.get(range, precision);
5513 break;
5514 case GL_MEDIUM_FLOAT:
5515 mCaps.fragmentMediumpFloat.get(range, precision);
5516 break;
5517 case GL_HIGH_FLOAT:
5518 mCaps.fragmentHighpFloat.get(range, precision);
5519 break;
5520
5521 case GL_LOW_INT:
5522 mCaps.fragmentLowpInt.get(range, precision);
5523 break;
5524 case GL_MEDIUM_INT:
5525 mCaps.fragmentMediumpInt.get(range, precision);
5526 break;
5527 case GL_HIGH_INT:
5528 mCaps.fragmentHighpInt.get(range, precision);
5529 break;
5530
5531 default:
5532 UNREACHABLE();
5533 return;
5534 }
5535 break;
5536
5537 default:
5538 UNREACHABLE();
5539 return;
5540 }
5541}
5542
5543void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5544{
5545 Shader *shaderObject = getShader(shader);
5546 ASSERT(shaderObject);
5547 shaderObject->getSource(bufsize, length, source);
5548}
5549
5550void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5551{
5552 Program *programObject = getProgram(program);
5553 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005554 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005555}
5556
Brandon Jones59770802018-04-02 13:18:42 -07005557void Context::getUniformfvRobust(GLuint program,
5558 GLint location,
5559 GLsizei bufSize,
5560 GLsizei *length,
5561 GLfloat *params)
5562{
5563 getUniformfv(program, location, params);
5564}
5565
Jamie Madillc1d770e2017-04-13 17:31:24 -04005566void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5567{
5568 Program *programObject = getProgram(program);
5569 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005570 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005571}
5572
Brandon Jones59770802018-04-02 13:18:42 -07005573void Context::getUniformivRobust(GLuint program,
5574 GLint location,
5575 GLsizei bufSize,
5576 GLsizei *length,
5577 GLint *params)
5578{
5579 getUniformiv(program, location, params);
5580}
5581
Jamie Madillc1d770e2017-04-13 17:31:24 -04005582GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5583{
5584 Program *programObject = getProgram(program);
5585 ASSERT(programObject);
5586 return programObject->getUniformLocation(name);
5587}
5588
5589GLboolean Context::isBuffer(GLuint buffer)
5590{
5591 if (buffer == 0)
5592 {
5593 return GL_FALSE;
5594 }
5595
5596 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5597}
5598
5599GLboolean Context::isEnabled(GLenum cap)
5600{
5601 return mGLState.getEnableFeature(cap);
5602}
5603
5604GLboolean Context::isFramebuffer(GLuint framebuffer)
5605{
5606 if (framebuffer == 0)
5607 {
5608 return GL_FALSE;
5609 }
5610
5611 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5612}
5613
5614GLboolean Context::isProgram(GLuint program)
5615{
5616 if (program == 0)
5617 {
5618 return GL_FALSE;
5619 }
5620
5621 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5622}
5623
5624GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5625{
5626 if (renderbuffer == 0)
5627 {
5628 return GL_FALSE;
5629 }
5630
5631 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5632}
5633
5634GLboolean Context::isShader(GLuint shader)
5635{
5636 if (shader == 0)
5637 {
5638 return GL_FALSE;
5639 }
5640
5641 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5642}
5643
5644GLboolean Context::isTexture(GLuint texture)
5645{
5646 if (texture == 0)
5647 {
5648 return GL_FALSE;
5649 }
5650
5651 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5652}
5653
5654void Context::linkProgram(GLuint program)
5655{
5656 Program *programObject = getProgram(program);
5657 ASSERT(programObject);
5658 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005659
5660 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5661 // don't need to worry that:
5662 // 1. Draw calls after link use the new executable code or the old one depending on the link
5663 // result.
5664 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5665 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5666 // ProgramD3D.
5667 if (programObject->isInUse())
5668 {
5669 // isLinked() which forces to resolve linking, will be called.
5670 mGLState.onProgramExecutableChange(programObject);
5671 mStateCache.onProgramExecutableChange(this);
5672 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005673}
5674
5675void Context::releaseShaderCompiler()
5676{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005677 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005678}
5679
5680void Context::shaderBinary(GLsizei n,
5681 const GLuint *shaders,
5682 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005683 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005684 GLsizei length)
5685{
5686 // No binary shader formats are supported.
5687 UNIMPLEMENTED();
5688}
5689
5690void Context::shaderSource(GLuint shader,
5691 GLsizei count,
5692 const GLchar *const *string,
5693 const GLint *length)
5694{
5695 Shader *shaderObject = getShader(shader);
5696 ASSERT(shaderObject);
5697 shaderObject->setSource(count, string, length);
5698}
5699
5700void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5701{
5702 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5703}
5704
5705void Context::stencilMask(GLuint mask)
5706{
5707 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5708}
5709
5710void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5711{
5712 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5713}
5714
5715void Context::uniform1f(GLint location, GLfloat x)
5716{
5717 Program *program = mGLState.getProgram();
5718 program->setUniform1fv(location, 1, &x);
5719}
5720
5721void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5722{
5723 Program *program = mGLState.getProgram();
5724 program->setUniform1fv(location, count, v);
5725}
5726
Jamie Madill7e4eff12018-08-08 15:49:26 -04005727void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005729 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005730 {
5731 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005732 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005733 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005734}
5735
Jamie Madill7e4eff12018-08-08 15:49:26 -04005736void Context::uniform1i(GLint location, GLint x)
5737{
5738 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5739}
5740
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5742{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005743 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744}
5745
5746void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5747{
5748 GLfloat xy[2] = {x, y};
5749 Program *program = mGLState.getProgram();
5750 program->setUniform2fv(location, 1, xy);
5751}
5752
5753void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5754{
5755 Program *program = mGLState.getProgram();
5756 program->setUniform2fv(location, count, v);
5757}
5758
5759void Context::uniform2i(GLint location, GLint x, GLint y)
5760{
5761 GLint xy[2] = {x, y};
5762 Program *program = mGLState.getProgram();
5763 program->setUniform2iv(location, 1, xy);
5764}
5765
5766void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5767{
5768 Program *program = mGLState.getProgram();
5769 program->setUniform2iv(location, count, v);
5770}
5771
5772void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5773{
5774 GLfloat xyz[3] = {x, y, z};
5775 Program *program = mGLState.getProgram();
5776 program->setUniform3fv(location, 1, xyz);
5777}
5778
5779void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5780{
5781 Program *program = mGLState.getProgram();
5782 program->setUniform3fv(location, count, v);
5783}
5784
5785void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5786{
5787 GLint xyz[3] = {x, y, z};
5788 Program *program = mGLState.getProgram();
5789 program->setUniform3iv(location, 1, xyz);
5790}
5791
5792void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5793{
5794 Program *program = mGLState.getProgram();
5795 program->setUniform3iv(location, count, v);
5796}
5797
5798void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5799{
5800 GLfloat xyzw[4] = {x, y, z, w};
5801 Program *program = mGLState.getProgram();
5802 program->setUniform4fv(location, 1, xyzw);
5803}
5804
5805void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5806{
5807 Program *program = mGLState.getProgram();
5808 program->setUniform4fv(location, count, v);
5809}
5810
5811void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5812{
5813 GLint xyzw[4] = {x, y, z, w};
5814 Program *program = mGLState.getProgram();
5815 program->setUniform4iv(location, 1, xyzw);
5816}
5817
5818void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5819{
5820 Program *program = mGLState.getProgram();
5821 program->setUniform4iv(location, count, v);
5822}
5823
5824void Context::uniformMatrix2fv(GLint location,
5825 GLsizei count,
5826 GLboolean transpose,
5827 const GLfloat *value)
5828{
5829 Program *program = mGLState.getProgram();
5830 program->setUniformMatrix2fv(location, count, transpose, value);
5831}
5832
5833void Context::uniformMatrix3fv(GLint location,
5834 GLsizei count,
5835 GLboolean transpose,
5836 const GLfloat *value)
5837{
5838 Program *program = mGLState.getProgram();
5839 program->setUniformMatrix3fv(location, count, transpose, value);
5840}
5841
5842void Context::uniformMatrix4fv(GLint location,
5843 GLsizei count,
5844 GLboolean transpose,
5845 const GLfloat *value)
5846{
5847 Program *program = mGLState.getProgram();
5848 program->setUniformMatrix4fv(location, count, transpose, value);
5849}
5850
5851void Context::validateProgram(GLuint program)
5852{
5853 Program *programObject = getProgram(program);
5854 ASSERT(programObject);
5855 programObject->validate(mCaps);
5856}
5857
Jiajia Qin5451d532017-11-16 17:16:34 +08005858void Context::validateProgramPipeline(GLuint pipeline)
5859{
5860 UNIMPLEMENTED();
5861}
5862
Jamie Madilld04908b2017-06-09 14:15:35 -04005863void Context::getProgramBinary(GLuint program,
5864 GLsizei bufSize,
5865 GLsizei *length,
5866 GLenum *binaryFormat,
5867 void *binary)
5868{
5869 Program *programObject = getProgram(program);
5870 ASSERT(programObject != nullptr);
5871
5872 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5873}
5874
5875void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5876{
5877 Program *programObject = getProgram(program);
5878 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005879
Jamie Madilld04908b2017-06-09 14:15:35 -04005880 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005881 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005882 if (programObject->isInUse())
5883 {
5884 mGLState.setObjectDirty(GL_PROGRAM);
5885 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005886}
5887
Jamie Madillff325f12017-08-26 15:06:05 -04005888void Context::uniform1ui(GLint location, GLuint v0)
5889{
5890 Program *program = mGLState.getProgram();
5891 program->setUniform1uiv(location, 1, &v0);
5892}
5893
5894void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5895{
5896 Program *program = mGLState.getProgram();
5897 const GLuint xy[] = {v0, v1};
5898 program->setUniform2uiv(location, 1, xy);
5899}
5900
5901void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5902{
5903 Program *program = mGLState.getProgram();
5904 const GLuint xyz[] = {v0, v1, v2};
5905 program->setUniform3uiv(location, 1, xyz);
5906}
5907
5908void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5909{
5910 Program *program = mGLState.getProgram();
5911 const GLuint xyzw[] = {v0, v1, v2, v3};
5912 program->setUniform4uiv(location, 1, xyzw);
5913}
5914
5915void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5916{
5917 Program *program = mGLState.getProgram();
5918 program->setUniform1uiv(location, count, value);
5919}
5920void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5921{
5922 Program *program = mGLState.getProgram();
5923 program->setUniform2uiv(location, count, value);
5924}
5925
5926void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5927{
5928 Program *program = mGLState.getProgram();
5929 program->setUniform3uiv(location, count, value);
5930}
5931
5932void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5933{
5934 Program *program = mGLState.getProgram();
5935 program->setUniform4uiv(location, count, value);
5936}
5937
Jamie Madillf0e04492017-08-26 15:28:42 -04005938void Context::genQueries(GLsizei n, GLuint *ids)
5939{
5940 for (GLsizei i = 0; i < n; i++)
5941 {
5942 GLuint handle = mQueryHandleAllocator.allocate();
5943 mQueryMap.assign(handle, nullptr);
5944 ids[i] = handle;
5945 }
5946}
5947
5948void Context::deleteQueries(GLsizei n, const GLuint *ids)
5949{
5950 for (int i = 0; i < n; i++)
5951 {
5952 GLuint query = ids[i];
5953
5954 Query *queryObject = nullptr;
5955 if (mQueryMap.erase(query, &queryObject))
5956 {
5957 mQueryHandleAllocator.release(query);
5958 if (queryObject)
5959 {
5960 queryObject->release(this);
5961 }
5962 }
5963 }
5964}
5965
5966GLboolean Context::isQuery(GLuint id)
5967{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005968 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005969}
5970
Jamie Madillc8c95812017-08-26 18:40:09 -04005971void Context::uniformMatrix2x3fv(GLint location,
5972 GLsizei count,
5973 GLboolean transpose,
5974 const GLfloat *value)
5975{
5976 Program *program = mGLState.getProgram();
5977 program->setUniformMatrix2x3fv(location, count, transpose, value);
5978}
5979
5980void Context::uniformMatrix3x2fv(GLint location,
5981 GLsizei count,
5982 GLboolean transpose,
5983 const GLfloat *value)
5984{
5985 Program *program = mGLState.getProgram();
5986 program->setUniformMatrix3x2fv(location, count, transpose, value);
5987}
5988
5989void Context::uniformMatrix2x4fv(GLint location,
5990 GLsizei count,
5991 GLboolean transpose,
5992 const GLfloat *value)
5993{
5994 Program *program = mGLState.getProgram();
5995 program->setUniformMatrix2x4fv(location, count, transpose, value);
5996}
5997
5998void Context::uniformMatrix4x2fv(GLint location,
5999 GLsizei count,
6000 GLboolean transpose,
6001 const GLfloat *value)
6002{
6003 Program *program = mGLState.getProgram();
6004 program->setUniformMatrix4x2fv(location, count, transpose, value);
6005}
6006
6007void Context::uniformMatrix3x4fv(GLint location,
6008 GLsizei count,
6009 GLboolean transpose,
6010 const GLfloat *value)
6011{
6012 Program *program = mGLState.getProgram();
6013 program->setUniformMatrix3x4fv(location, count, transpose, value);
6014}
6015
6016void Context::uniformMatrix4x3fv(GLint location,
6017 GLsizei count,
6018 GLboolean transpose,
6019 const GLfloat *value)
6020{
6021 Program *program = mGLState.getProgram();
6022 program->setUniformMatrix4x3fv(location, count, transpose, value);
6023}
6024
Jamie Madilld7576732017-08-26 18:49:50 -04006025void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6026{
6027 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6028 {
6029 GLuint vertexArray = arrays[arrayIndex];
6030
6031 if (arrays[arrayIndex] != 0)
6032 {
6033 VertexArray *vertexArrayObject = nullptr;
6034 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6035 {
6036 if (vertexArrayObject != nullptr)
6037 {
6038 detachVertexArray(vertexArray);
6039 vertexArrayObject->onDestroy(this);
6040 }
6041
6042 mVertexArrayHandleAllocator.release(vertexArray);
6043 }
6044 }
6045 }
6046}
6047
6048void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6049{
6050 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6051 {
6052 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6053 mVertexArrayMap.assign(vertexArray, nullptr);
6054 arrays[arrayIndex] = vertexArray;
6055 }
6056}
6057
6058bool Context::isVertexArray(GLuint array)
6059{
6060 if (array == 0)
6061 {
6062 return GL_FALSE;
6063 }
6064
6065 VertexArray *vao = getVertexArray(array);
6066 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6067}
6068
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006069void Context::endTransformFeedback()
6070{
6071 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6072 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006073 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006074}
6075
6076void Context::transformFeedbackVaryings(GLuint program,
6077 GLsizei count,
6078 const GLchar *const *varyings,
6079 GLenum bufferMode)
6080{
6081 Program *programObject = getProgram(program);
6082 ASSERT(programObject);
6083 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6084}
6085
6086void Context::getTransformFeedbackVarying(GLuint program,
6087 GLuint index,
6088 GLsizei bufSize,
6089 GLsizei *length,
6090 GLsizei *size,
6091 GLenum *type,
6092 GLchar *name)
6093{
6094 Program *programObject = getProgram(program);
6095 ASSERT(programObject);
6096 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6097}
6098
6099void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6100{
6101 for (int i = 0; i < n; i++)
6102 {
6103 GLuint transformFeedback = ids[i];
6104 if (transformFeedback == 0)
6105 {
6106 continue;
6107 }
6108
6109 TransformFeedback *transformFeedbackObject = nullptr;
6110 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6111 {
6112 if (transformFeedbackObject != nullptr)
6113 {
6114 detachTransformFeedback(transformFeedback);
6115 transformFeedbackObject->release(this);
6116 }
6117
6118 mTransformFeedbackHandleAllocator.release(transformFeedback);
6119 }
6120 }
6121}
6122
6123void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6124{
6125 for (int i = 0; i < n; i++)
6126 {
6127 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6128 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6129 ids[i] = transformFeedback;
6130 }
6131}
6132
6133bool Context::isTransformFeedback(GLuint id)
6134{
6135 if (id == 0)
6136 {
6137 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6138 // returns FALSE
6139 return GL_FALSE;
6140 }
6141
6142 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6143 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6144}
6145
6146void Context::pauseTransformFeedback()
6147{
6148 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6149 transformFeedback->pause();
6150}
6151
6152void Context::resumeTransformFeedback()
6153{
6154 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6155 transformFeedback->resume();
6156}
6157
Jamie Madill12e957f2017-08-26 21:42:26 -04006158void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6159{
6160 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006161 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006162}
6163
Brandon Jones59770802018-04-02 13:18:42 -07006164void Context::getUniformuivRobust(GLuint program,
6165 GLint location,
6166 GLsizei bufSize,
6167 GLsizei *length,
6168 GLuint *params)
6169{
6170 getUniformuiv(program, location, params);
6171}
6172
Jamie Madill12e957f2017-08-26 21:42:26 -04006173GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6174{
6175 const Program *programObject = getProgram(program);
6176 return programObject->getFragDataLocation(name);
6177}
6178
6179void Context::getUniformIndices(GLuint program,
6180 GLsizei uniformCount,
6181 const GLchar *const *uniformNames,
6182 GLuint *uniformIndices)
6183{
6184 const Program *programObject = getProgram(program);
6185 if (!programObject->isLinked())
6186 {
6187 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6188 {
6189 uniformIndices[uniformId] = GL_INVALID_INDEX;
6190 }
6191 }
6192 else
6193 {
6194 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6195 {
6196 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6197 }
6198 }
6199}
6200
6201void Context::getActiveUniformsiv(GLuint program,
6202 GLsizei uniformCount,
6203 const GLuint *uniformIndices,
6204 GLenum pname,
6205 GLint *params)
6206{
6207 const Program *programObject = getProgram(program);
6208 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6209 {
6210 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006211 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006212 }
6213}
6214
6215GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6216{
6217 const Program *programObject = getProgram(program);
6218 return programObject->getUniformBlockIndex(uniformBlockName);
6219}
6220
6221void Context::getActiveUniformBlockiv(GLuint program,
6222 GLuint uniformBlockIndex,
6223 GLenum pname,
6224 GLint *params)
6225{
6226 const Program *programObject = getProgram(program);
6227 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6228}
6229
Brandon Jones59770802018-04-02 13:18:42 -07006230void Context::getActiveUniformBlockivRobust(GLuint program,
6231 GLuint uniformBlockIndex,
6232 GLenum pname,
6233 GLsizei bufSize,
6234 GLsizei *length,
6235 GLint *params)
6236{
6237 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6238}
6239
Jamie Madill12e957f2017-08-26 21:42:26 -04006240void Context::getActiveUniformBlockName(GLuint program,
6241 GLuint uniformBlockIndex,
6242 GLsizei bufSize,
6243 GLsizei *length,
6244 GLchar *uniformBlockName)
6245{
6246 const Program *programObject = getProgram(program);
6247 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6248}
6249
6250void Context::uniformBlockBinding(GLuint program,
6251 GLuint uniformBlockIndex,
6252 GLuint uniformBlockBinding)
6253{
6254 Program *programObject = getProgram(program);
6255 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006256
6257 if (programObject->isInUse())
6258 {
6259 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006260 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006261 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006262}
6263
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006264GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6265{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006266 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6267 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006268
Jamie Madill70b5bb02017-08-28 13:32:37 -04006269 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006270 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006271 if (error.isError())
6272 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006273 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006274 handleError(error);
6275 return nullptr;
6276 }
6277
Jamie Madill70b5bb02017-08-28 13:32:37 -04006278 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006279}
6280
6281GLboolean Context::isSync(GLsync sync)
6282{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006283 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006284}
6285
6286GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6287{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006288 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006289
6290 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006291 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006292 return result;
6293}
6294
6295void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6296{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006297 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006298 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006299}
6300
6301void Context::getInteger64v(GLenum pname, GLint64 *params)
6302{
6303 GLenum nativeType = GL_NONE;
6304 unsigned int numParams = 0;
6305 getQueryParameterInfo(pname, &nativeType, &numParams);
6306
6307 if (nativeType == GL_INT_64_ANGLEX)
6308 {
6309 getInteger64vImpl(pname, params);
6310 }
6311 else
6312 {
6313 CastStateValues(this, nativeType, pname, numParams, params);
6314 }
6315}
6316
Brandon Jones59770802018-04-02 13:18:42 -07006317void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6318{
6319 getInteger64v(pname, data);
6320}
6321
Corentin Wallez336129f2017-10-17 15:55:40 -04006322void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006323{
6324 Buffer *buffer = mGLState.getTargetBuffer(target);
6325 QueryBufferParameteri64v(buffer, pname, params);
6326}
6327
Brandon Jones59770802018-04-02 13:18:42 -07006328void Context::getBufferParameteri64vRobust(BufferBinding target,
6329 GLenum pname,
6330 GLsizei bufSize,
6331 GLsizei *length,
6332 GLint64 *params)
6333{
6334 getBufferParameteri64v(target, pname, params);
6335}
6336
Jamie Madill3ef140a2017-08-26 23:11:21 -04006337void Context::genSamplers(GLsizei count, GLuint *samplers)
6338{
6339 for (int i = 0; i < count; i++)
6340 {
6341 samplers[i] = mState.mSamplers->createSampler();
6342 }
6343}
6344
6345void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6346{
6347 for (int i = 0; i < count; i++)
6348 {
6349 GLuint sampler = samplers[i];
6350
6351 if (mState.mSamplers->getSampler(sampler))
6352 {
6353 detachSampler(sampler);
6354 }
6355
6356 mState.mSamplers->deleteObject(this, sampler);
6357 }
6358}
6359
6360void Context::getInternalformativ(GLenum target,
6361 GLenum internalformat,
6362 GLenum pname,
6363 GLsizei bufSize,
6364 GLint *params)
6365{
6366 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6367 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6368}
6369
Brandon Jones59770802018-04-02 13:18:42 -07006370void Context::getInternalformativRobust(GLenum target,
6371 GLenum internalformat,
6372 GLenum pname,
6373 GLsizei bufSize,
6374 GLsizei *length,
6375 GLint *params)
6376{
6377 getInternalformativ(target, internalformat, pname, bufSize, params);
6378}
6379
Jiajia Qin5451d532017-11-16 17:16:34 +08006380void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6381{
6382 programUniform1iv(program, location, 1, &v0);
6383}
6384
6385void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6386{
6387 GLint xy[2] = {v0, v1};
6388 programUniform2iv(program, location, 1, xy);
6389}
6390
6391void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6392{
6393 GLint xyz[3] = {v0, v1, v2};
6394 programUniform3iv(program, location, 1, xyz);
6395}
6396
6397void Context::programUniform4i(GLuint program,
6398 GLint location,
6399 GLint v0,
6400 GLint v1,
6401 GLint v2,
6402 GLint v3)
6403{
6404 GLint xyzw[4] = {v0, v1, v2, v3};
6405 programUniform4iv(program, location, 1, xyzw);
6406}
6407
6408void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6409{
6410 programUniform1uiv(program, location, 1, &v0);
6411}
6412
6413void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6414{
6415 GLuint xy[2] = {v0, v1};
6416 programUniform2uiv(program, location, 1, xy);
6417}
6418
6419void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6420{
6421 GLuint xyz[3] = {v0, v1, v2};
6422 programUniform3uiv(program, location, 1, xyz);
6423}
6424
6425void Context::programUniform4ui(GLuint program,
6426 GLint location,
6427 GLuint v0,
6428 GLuint v1,
6429 GLuint v2,
6430 GLuint v3)
6431{
6432 GLuint xyzw[4] = {v0, v1, v2, v3};
6433 programUniform4uiv(program, location, 1, xyzw);
6434}
6435
6436void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6437{
6438 programUniform1fv(program, location, 1, &v0);
6439}
6440
6441void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6442{
6443 GLfloat xy[2] = {v0, v1};
6444 programUniform2fv(program, location, 1, xy);
6445}
6446
6447void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6448{
6449 GLfloat xyz[3] = {v0, v1, v2};
6450 programUniform3fv(program, location, 1, xyz);
6451}
6452
6453void Context::programUniform4f(GLuint program,
6454 GLint location,
6455 GLfloat v0,
6456 GLfloat v1,
6457 GLfloat v2,
6458 GLfloat v3)
6459{
6460 GLfloat xyzw[4] = {v0, v1, v2, v3};
6461 programUniform4fv(program, location, 1, xyzw);
6462}
6463
Jamie Madill81c2e252017-09-09 23:32:46 -04006464void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6465{
6466 Program *programObject = getProgram(program);
6467 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006468 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006469}
6470
Jiajia Qin5451d532017-11-16 17:16:34 +08006471void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6472{
6473 Program *programObject = getProgram(program);
6474 ASSERT(programObject);
6475 programObject->setUniform2iv(location, count, value);
6476}
6477
6478void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6479{
6480 Program *programObject = getProgram(program);
6481 ASSERT(programObject);
6482 programObject->setUniform3iv(location, count, value);
6483}
6484
6485void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6486{
6487 Program *programObject = getProgram(program);
6488 ASSERT(programObject);
6489 programObject->setUniform4iv(location, count, value);
6490}
6491
6492void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6493{
6494 Program *programObject = getProgram(program);
6495 ASSERT(programObject);
6496 programObject->setUniform1uiv(location, count, value);
6497}
6498
6499void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6500{
6501 Program *programObject = getProgram(program);
6502 ASSERT(programObject);
6503 programObject->setUniform2uiv(location, count, value);
6504}
6505
6506void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6507{
6508 Program *programObject = getProgram(program);
6509 ASSERT(programObject);
6510 programObject->setUniform3uiv(location, count, value);
6511}
6512
6513void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
6517 programObject->setUniform4uiv(location, count, value);
6518}
6519
6520void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6521{
6522 Program *programObject = getProgram(program);
6523 ASSERT(programObject);
6524 programObject->setUniform1fv(location, count, value);
6525}
6526
6527void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531 programObject->setUniform2fv(location, count, value);
6532}
6533
6534void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6535{
6536 Program *programObject = getProgram(program);
6537 ASSERT(programObject);
6538 programObject->setUniform3fv(location, count, value);
6539}
6540
6541void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6542{
6543 Program *programObject = getProgram(program);
6544 ASSERT(programObject);
6545 programObject->setUniform4fv(location, count, value);
6546}
6547
6548void Context::programUniformMatrix2fv(GLuint program,
6549 GLint location,
6550 GLsizei count,
6551 GLboolean transpose,
6552 const GLfloat *value)
6553{
6554 Program *programObject = getProgram(program);
6555 ASSERT(programObject);
6556 programObject->setUniformMatrix2fv(location, count, transpose, value);
6557}
6558
6559void Context::programUniformMatrix3fv(GLuint program,
6560 GLint location,
6561 GLsizei count,
6562 GLboolean transpose,
6563 const GLfloat *value)
6564{
6565 Program *programObject = getProgram(program);
6566 ASSERT(programObject);
6567 programObject->setUniformMatrix3fv(location, count, transpose, value);
6568}
6569
6570void Context::programUniformMatrix4fv(GLuint program,
6571 GLint location,
6572 GLsizei count,
6573 GLboolean transpose,
6574 const GLfloat *value)
6575{
6576 Program *programObject = getProgram(program);
6577 ASSERT(programObject);
6578 programObject->setUniformMatrix4fv(location, count, transpose, value);
6579}
6580
6581void Context::programUniformMatrix2x3fv(GLuint program,
6582 GLint location,
6583 GLsizei count,
6584 GLboolean transpose,
6585 const GLfloat *value)
6586{
6587 Program *programObject = getProgram(program);
6588 ASSERT(programObject);
6589 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6590}
6591
6592void Context::programUniformMatrix3x2fv(GLuint program,
6593 GLint location,
6594 GLsizei count,
6595 GLboolean transpose,
6596 const GLfloat *value)
6597{
6598 Program *programObject = getProgram(program);
6599 ASSERT(programObject);
6600 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6601}
6602
6603void Context::programUniformMatrix2x4fv(GLuint program,
6604 GLint location,
6605 GLsizei count,
6606 GLboolean transpose,
6607 const GLfloat *value)
6608{
6609 Program *programObject = getProgram(program);
6610 ASSERT(programObject);
6611 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6612}
6613
6614void Context::programUniformMatrix4x2fv(GLuint program,
6615 GLint location,
6616 GLsizei count,
6617 GLboolean transpose,
6618 const GLfloat *value)
6619{
6620 Program *programObject = getProgram(program);
6621 ASSERT(programObject);
6622 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6623}
6624
6625void Context::programUniformMatrix3x4fv(GLuint program,
6626 GLint location,
6627 GLsizei count,
6628 GLboolean transpose,
6629 const GLfloat *value)
6630{
6631 Program *programObject = getProgram(program);
6632 ASSERT(programObject);
6633 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6634}
6635
6636void Context::programUniformMatrix4x3fv(GLuint program,
6637 GLint location,
6638 GLsizei count,
6639 GLboolean transpose,
6640 const GLfloat *value)
6641{
6642 Program *programObject = getProgram(program);
6643 ASSERT(programObject);
6644 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6645}
6646
Jamie Madill81c2e252017-09-09 23:32:46 -04006647void Context::onTextureChange(const Texture *texture)
6648{
6649 // Conservatively assume all textures are dirty.
6650 // TODO(jmadill): More fine-grained update.
6651 mGLState.setObjectDirty(GL_TEXTURE);
6652}
6653
James Darpiniane8a93c62018-01-04 18:02:24 -08006654bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6655{
6656 return mGLState.isCurrentTransformFeedback(tf);
6657}
James Darpiniane8a93c62018-01-04 18:02:24 -08006658
Yunchao Hea336b902017-08-02 16:05:21 +08006659void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6660{
6661 for (int i = 0; i < count; i++)
6662 {
6663 pipelines[i] = createProgramPipeline();
6664 }
6665}
6666
6667void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6668{
6669 for (int i = 0; i < count; i++)
6670 {
6671 if (pipelines[i] != 0)
6672 {
6673 deleteProgramPipeline(pipelines[i]);
6674 }
6675 }
6676}
6677
6678GLboolean Context::isProgramPipeline(GLuint pipeline)
6679{
6680 if (pipeline == 0)
6681 {
6682 return GL_FALSE;
6683 }
6684
6685 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6686}
6687
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006688void Context::finishFenceNV(GLuint fence)
6689{
6690 FenceNV *fenceObject = getFenceNV(fence);
6691
6692 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006693 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006694}
6695
6696void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6697{
6698 FenceNV *fenceObject = getFenceNV(fence);
6699
6700 ASSERT(fenceObject && fenceObject->isSet());
6701
6702 switch (pname)
6703 {
6704 case GL_FENCE_STATUS_NV:
6705 {
6706 // GL_NV_fence spec:
6707 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6708 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6709 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6710 GLboolean status = GL_TRUE;
6711 if (fenceObject->getStatus() != GL_TRUE)
6712 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006713 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006714 }
6715 *params = status;
6716 break;
6717 }
6718
6719 case GL_FENCE_CONDITION_NV:
6720 {
6721 *params = static_cast<GLint>(fenceObject->getCondition());
6722 break;
6723 }
6724
6725 default:
6726 UNREACHABLE();
6727 }
6728}
6729
6730void Context::getTranslatedShaderSource(GLuint shader,
6731 GLsizei bufsize,
6732 GLsizei *length,
6733 GLchar *source)
6734{
6735 Shader *shaderObject = getShader(shader);
6736 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006737 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006738}
6739
6740void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6741{
6742 Program *programObject = getProgram(program);
6743 ASSERT(programObject);
6744
6745 programObject->getUniformfv(this, location, params);
6746}
6747
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006748void Context::getnUniformfvRobust(GLuint program,
6749 GLint location,
6750 GLsizei bufSize,
6751 GLsizei *length,
6752 GLfloat *params)
6753{
6754 UNIMPLEMENTED();
6755}
6756
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006757void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6758{
6759 Program *programObject = getProgram(program);
6760 ASSERT(programObject);
6761
6762 programObject->getUniformiv(this, location, params);
6763}
6764
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006765void Context::getnUniformivRobust(GLuint program,
6766 GLint location,
6767 GLsizei bufSize,
6768 GLsizei *length,
6769 GLint *params)
6770{
6771 UNIMPLEMENTED();
6772}
6773
6774void Context::getnUniformuivRobust(GLuint program,
6775 GLint location,
6776 GLsizei bufSize,
6777 GLsizei *length,
6778 GLuint *params)
6779{
6780 UNIMPLEMENTED();
6781}
6782
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006783GLboolean Context::isFenceNV(GLuint fence)
6784{
6785 FenceNV *fenceObject = getFenceNV(fence);
6786
6787 if (fenceObject == nullptr)
6788 {
6789 return GL_FALSE;
6790 }
6791
6792 // GL_NV_fence spec:
6793 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6794 // existing fence.
6795 return fenceObject->isSet();
6796}
6797
6798void Context::readnPixels(GLint x,
6799 GLint y,
6800 GLsizei width,
6801 GLsizei height,
6802 GLenum format,
6803 GLenum type,
6804 GLsizei bufSize,
6805 void *data)
6806{
6807 return readPixels(x, y, width, height, format, type, data);
6808}
6809
Jamie Madill007530e2017-12-28 14:27:04 -05006810void Context::setFenceNV(GLuint fence, GLenum condition)
6811{
6812 ASSERT(condition == GL_ALL_COMPLETED_NV);
6813
6814 FenceNV *fenceObject = getFenceNV(fence);
6815 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006816 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006817}
6818
6819GLboolean Context::testFenceNV(GLuint fence)
6820{
6821 FenceNV *fenceObject = getFenceNV(fence);
6822
6823 ASSERT(fenceObject != nullptr);
6824 ASSERT(fenceObject->isSet() == GL_TRUE);
6825
6826 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006827 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006828 if (error.isError())
6829 {
6830 handleError(error);
6831 return GL_TRUE;
6832 }
6833
6834 return result;
6835}
6836
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006837void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006838{
6839 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006840 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006841 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006842}
6843
Jamie Madillfa920eb2018-01-04 11:45:50 -05006844void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006845{
6846 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006847 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006848 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6849}
6850
Jamie Madillfa920eb2018-01-04 11:45:50 -05006851void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6852{
6853 UNIMPLEMENTED();
6854}
6855
Jamie Madill5b772312018-03-08 20:28:32 -05006856bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6857{
6858 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6859 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6860 // to the fact that it is stored internally as a float, and so would require conversion
6861 // if returned from Context::getIntegerv. Since this conversion is already implemented
6862 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6863 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6864 // application.
6865 switch (pname)
6866 {
6867 case GL_COMPRESSED_TEXTURE_FORMATS:
6868 {
6869 *type = GL_INT;
6870 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6871 return true;
6872 }
6873 case GL_SHADER_BINARY_FORMATS:
6874 {
6875 *type = GL_INT;
6876 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6877 return true;
6878 }
6879
6880 case GL_MAX_VERTEX_ATTRIBS:
6881 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6882 case GL_MAX_VARYING_VECTORS:
6883 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6884 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6885 case GL_MAX_TEXTURE_IMAGE_UNITS:
6886 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6887 case GL_MAX_RENDERBUFFER_SIZE:
6888 case GL_NUM_SHADER_BINARY_FORMATS:
6889 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6890 case GL_ARRAY_BUFFER_BINDING:
6891 case GL_FRAMEBUFFER_BINDING:
6892 case GL_RENDERBUFFER_BINDING:
6893 case GL_CURRENT_PROGRAM:
6894 case GL_PACK_ALIGNMENT:
6895 case GL_UNPACK_ALIGNMENT:
6896 case GL_GENERATE_MIPMAP_HINT:
6897 case GL_RED_BITS:
6898 case GL_GREEN_BITS:
6899 case GL_BLUE_BITS:
6900 case GL_ALPHA_BITS:
6901 case GL_DEPTH_BITS:
6902 case GL_STENCIL_BITS:
6903 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6904 case GL_CULL_FACE_MODE:
6905 case GL_FRONT_FACE:
6906 case GL_ACTIVE_TEXTURE:
6907 case GL_STENCIL_FUNC:
6908 case GL_STENCIL_VALUE_MASK:
6909 case GL_STENCIL_REF:
6910 case GL_STENCIL_FAIL:
6911 case GL_STENCIL_PASS_DEPTH_FAIL:
6912 case GL_STENCIL_PASS_DEPTH_PASS:
6913 case GL_STENCIL_BACK_FUNC:
6914 case GL_STENCIL_BACK_VALUE_MASK:
6915 case GL_STENCIL_BACK_REF:
6916 case GL_STENCIL_BACK_FAIL:
6917 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6918 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6919 case GL_DEPTH_FUNC:
6920 case GL_BLEND_SRC_RGB:
6921 case GL_BLEND_SRC_ALPHA:
6922 case GL_BLEND_DST_RGB:
6923 case GL_BLEND_DST_ALPHA:
6924 case GL_BLEND_EQUATION_RGB:
6925 case GL_BLEND_EQUATION_ALPHA:
6926 case GL_STENCIL_WRITEMASK:
6927 case GL_STENCIL_BACK_WRITEMASK:
6928 case GL_STENCIL_CLEAR_VALUE:
6929 case GL_SUBPIXEL_BITS:
6930 case GL_MAX_TEXTURE_SIZE:
6931 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6932 case GL_SAMPLE_BUFFERS:
6933 case GL_SAMPLES:
6934 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6935 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6936 case GL_TEXTURE_BINDING_2D:
6937 case GL_TEXTURE_BINDING_CUBE_MAP:
6938 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6939 {
6940 *type = GL_INT;
6941 *numParams = 1;
6942 return true;
6943 }
6944 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6945 {
6946 if (!getExtensions().packReverseRowOrder)
6947 {
6948 return false;
6949 }
6950 *type = GL_INT;
6951 *numParams = 1;
6952 return true;
6953 }
6954 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6955 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6956 {
6957 if (!getExtensions().textureRectangle)
6958 {
6959 return false;
6960 }
6961 *type = GL_INT;
6962 *numParams = 1;
6963 return true;
6964 }
6965 case GL_MAX_DRAW_BUFFERS_EXT:
6966 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6967 {
6968 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6969 {
6970 return false;
6971 }
6972 *type = GL_INT;
6973 *numParams = 1;
6974 return true;
6975 }
6976 case GL_MAX_VIEWPORT_DIMS:
6977 {
6978 *type = GL_INT;
6979 *numParams = 2;
6980 return true;
6981 }
6982 case GL_VIEWPORT:
6983 case GL_SCISSOR_BOX:
6984 {
6985 *type = GL_INT;
6986 *numParams = 4;
6987 return true;
6988 }
6989 case GL_SHADER_COMPILER:
6990 case GL_SAMPLE_COVERAGE_INVERT:
6991 case GL_DEPTH_WRITEMASK:
6992 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6993 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6994 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6995 // bool-natural
6996 case GL_SAMPLE_COVERAGE:
6997 case GL_SCISSOR_TEST:
6998 case GL_STENCIL_TEST:
6999 case GL_DEPTH_TEST:
7000 case GL_BLEND:
7001 case GL_DITHER:
7002 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7003 {
7004 *type = GL_BOOL;
7005 *numParams = 1;
7006 return true;
7007 }
7008 case GL_COLOR_WRITEMASK:
7009 {
7010 *type = GL_BOOL;
7011 *numParams = 4;
7012 return true;
7013 }
7014 case GL_POLYGON_OFFSET_FACTOR:
7015 case GL_POLYGON_OFFSET_UNITS:
7016 case GL_SAMPLE_COVERAGE_VALUE:
7017 case GL_DEPTH_CLEAR_VALUE:
7018 case GL_LINE_WIDTH:
7019 {
7020 *type = GL_FLOAT;
7021 *numParams = 1;
7022 return true;
7023 }
7024 case GL_ALIASED_LINE_WIDTH_RANGE:
7025 case GL_ALIASED_POINT_SIZE_RANGE:
7026 case GL_DEPTH_RANGE:
7027 {
7028 *type = GL_FLOAT;
7029 *numParams = 2;
7030 return true;
7031 }
7032 case GL_COLOR_CLEAR_VALUE:
7033 case GL_BLEND_COLOR:
7034 {
7035 *type = GL_FLOAT;
7036 *numParams = 4;
7037 return true;
7038 }
7039 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7040 if (!getExtensions().textureFilterAnisotropic)
7041 {
7042 return false;
7043 }
7044 *type = GL_FLOAT;
7045 *numParams = 1;
7046 return true;
7047 case GL_TIMESTAMP_EXT:
7048 if (!getExtensions().disjointTimerQuery)
7049 {
7050 return false;
7051 }
7052 *type = GL_INT_64_ANGLEX;
7053 *numParams = 1;
7054 return true;
7055 case GL_GPU_DISJOINT_EXT:
7056 if (!getExtensions().disjointTimerQuery)
7057 {
7058 return false;
7059 }
7060 *type = GL_INT;
7061 *numParams = 1;
7062 return true;
7063 case GL_COVERAGE_MODULATION_CHROMIUM:
7064 if (!getExtensions().framebufferMixedSamples)
7065 {
7066 return false;
7067 }
7068 *type = GL_INT;
7069 *numParams = 1;
7070 return true;
7071 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7072 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7073 {
7074 return false;
7075 }
7076 *type = GL_INT;
7077 *numParams = 1;
7078 return true;
7079 }
7080
7081 if (getExtensions().debug)
7082 {
7083 switch (pname)
7084 {
7085 case GL_DEBUG_LOGGED_MESSAGES:
7086 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7087 case GL_DEBUG_GROUP_STACK_DEPTH:
7088 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7089 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7090 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7091 case GL_MAX_LABEL_LENGTH:
7092 *type = GL_INT;
7093 *numParams = 1;
7094 return true;
7095
7096 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7097 case GL_DEBUG_OUTPUT:
7098 *type = GL_BOOL;
7099 *numParams = 1;
7100 return true;
7101 }
7102 }
7103
7104 if (getExtensions().multisampleCompatibility)
7105 {
7106 switch (pname)
7107 {
7108 case GL_MULTISAMPLE_EXT:
7109 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7110 *type = GL_BOOL;
7111 *numParams = 1;
7112 return true;
7113 }
7114 }
7115
7116 if (getExtensions().pathRendering)
7117 {
7118 switch (pname)
7119 {
7120 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7121 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7122 *type = GL_FLOAT;
7123 *numParams = 16;
7124 return true;
7125 }
7126 }
7127
7128 if (getExtensions().bindGeneratesResource)
7129 {
7130 switch (pname)
7131 {
7132 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7133 *type = GL_BOOL;
7134 *numParams = 1;
7135 return true;
7136 }
7137 }
7138
7139 if (getExtensions().clientArrays)
7140 {
7141 switch (pname)
7142 {
7143 case GL_CLIENT_ARRAYS_ANGLE:
7144 *type = GL_BOOL;
7145 *numParams = 1;
7146 return true;
7147 }
7148 }
7149
7150 if (getExtensions().sRGBWriteControl)
7151 {
7152 switch (pname)
7153 {
7154 case GL_FRAMEBUFFER_SRGB_EXT:
7155 *type = GL_BOOL;
7156 *numParams = 1;
7157 return true;
7158 }
7159 }
7160
7161 if (getExtensions().robustResourceInitialization &&
7162 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7163 {
7164 *type = GL_BOOL;
7165 *numParams = 1;
7166 return true;
7167 }
7168
7169 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7170 {
7171 *type = GL_BOOL;
7172 *numParams = 1;
7173 return true;
7174 }
7175
jchen1082af6202018-06-22 10:59:52 +08007176 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7177 {
7178 *type = GL_INT;
7179 *numParams = 1;
7180 return true;
7181 }
7182
Jamie Madill5b772312018-03-08 20:28:32 -05007183 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7184 switch (pname)
7185 {
7186 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7187 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7188 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7189 {
7190 return false;
7191 }
7192 *type = GL_INT;
7193 *numParams = 1;
7194 return true;
7195
7196 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7197 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7198 {
7199 return false;
7200 }
7201 *type = GL_INT;
7202 *numParams = 1;
7203 return true;
7204
7205 case GL_PROGRAM_BINARY_FORMATS_OES:
7206 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7207 {
7208 return false;
7209 }
7210 *type = GL_INT;
7211 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7212 return true;
7213
7214 case GL_PACK_ROW_LENGTH:
7215 case GL_PACK_SKIP_ROWS:
7216 case GL_PACK_SKIP_PIXELS:
7217 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7218 {
7219 return false;
7220 }
7221 *type = GL_INT;
7222 *numParams = 1;
7223 return true;
7224 case GL_UNPACK_ROW_LENGTH:
7225 case GL_UNPACK_SKIP_ROWS:
7226 case GL_UNPACK_SKIP_PIXELS:
7227 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7228 {
7229 return false;
7230 }
7231 *type = GL_INT;
7232 *numParams = 1;
7233 return true;
7234 case GL_VERTEX_ARRAY_BINDING:
7235 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7236 {
7237 return false;
7238 }
7239 *type = GL_INT;
7240 *numParams = 1;
7241 return true;
7242 case GL_PIXEL_PACK_BUFFER_BINDING:
7243 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7244 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7245 {
7246 return false;
7247 }
7248 *type = GL_INT;
7249 *numParams = 1;
7250 return true;
7251 case GL_MAX_SAMPLES:
7252 {
7253 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7254 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7255 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7256 {
7257 return false;
7258 }
7259 *type = GL_INT;
7260 *numParams = 1;
7261 return true;
7262
7263 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7264 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7265 {
7266 return false;
7267 }
7268 *type = GL_INT;
7269 *numParams = 1;
7270 return true;
7271 }
7272 }
7273
7274 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7275 {
7276 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7277 {
7278 return false;
7279 }
7280 *type = GL_INT;
7281 *numParams = 1;
7282 return true;
7283 }
7284
7285 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7286 {
7287 *type = GL_INT;
7288 *numParams = 1;
7289 return true;
7290 }
7291
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007292 if (getClientVersion() < Version(2, 0))
7293 {
7294 switch (pname)
7295 {
7296 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007297 case GL_CLIENT_ACTIVE_TEXTURE:
7298 case GL_MATRIX_MODE:
7299 case GL_MAX_TEXTURE_UNITS:
7300 case GL_MAX_MODELVIEW_STACK_DEPTH:
7301 case GL_MAX_PROJECTION_STACK_DEPTH:
7302 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007303 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007304 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007305 case GL_VERTEX_ARRAY_STRIDE:
7306 case GL_NORMAL_ARRAY_STRIDE:
7307 case GL_COLOR_ARRAY_STRIDE:
7308 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7309 case GL_VERTEX_ARRAY_SIZE:
7310 case GL_COLOR_ARRAY_SIZE:
7311 case GL_TEXTURE_COORD_ARRAY_SIZE:
7312 case GL_VERTEX_ARRAY_TYPE:
7313 case GL_NORMAL_ARRAY_TYPE:
7314 case GL_COLOR_ARRAY_TYPE:
7315 case GL_TEXTURE_COORD_ARRAY_TYPE:
7316 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7317 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7318 case GL_COLOR_ARRAY_BUFFER_BINDING:
7319 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7320 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7321 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7322 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007323 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007324 case GL_MODELVIEW_STACK_DEPTH:
7325 case GL_PROJECTION_STACK_DEPTH:
7326 case GL_TEXTURE_STACK_DEPTH:
7327 case GL_LOGIC_OP_MODE:
7328 case GL_BLEND_SRC:
7329 case GL_BLEND_DST:
7330 case GL_PERSPECTIVE_CORRECTION_HINT:
7331 case GL_POINT_SMOOTH_HINT:
7332 case GL_LINE_SMOOTH_HINT:
7333 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007334 *type = GL_INT;
7335 *numParams = 1;
7336 return true;
7337 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007338 case GL_FOG_DENSITY:
7339 case GL_FOG_START:
7340 case GL_FOG_END:
7341 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007342 case GL_POINT_SIZE:
7343 case GL_POINT_SIZE_MIN:
7344 case GL_POINT_SIZE_MAX:
7345 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007346 *type = GL_FLOAT;
7347 *numParams = 1;
7348 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007349 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007350 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007351 *type = GL_FLOAT;
7352 *numParams = 2;
7353 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007354 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007355 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007356 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007357 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007358 *type = GL_FLOAT;
7359 *numParams = 4;
7360 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007361 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007362 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007363 *type = GL_FLOAT;
7364 *numParams = 3;
7365 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007366 case GL_MODELVIEW_MATRIX:
7367 case GL_PROJECTION_MATRIX:
7368 case GL_TEXTURE_MATRIX:
7369 *type = GL_FLOAT;
7370 *numParams = 16;
7371 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007372 case GL_LIGHT_MODEL_TWO_SIDE:
7373 *type = GL_BOOL;
7374 *numParams = 1;
7375 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007376 }
7377 }
7378
Jamie Madill5b772312018-03-08 20:28:32 -05007379 if (getClientVersion() < Version(3, 0))
7380 {
7381 return false;
7382 }
7383
7384 // Check for ES3.0+ parameter names
7385 switch (pname)
7386 {
7387 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7388 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7389 case GL_UNIFORM_BUFFER_BINDING:
7390 case GL_TRANSFORM_FEEDBACK_BINDING:
7391 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7392 case GL_COPY_READ_BUFFER_BINDING:
7393 case GL_COPY_WRITE_BUFFER_BINDING:
7394 case GL_SAMPLER_BINDING:
7395 case GL_READ_BUFFER:
7396 case GL_TEXTURE_BINDING_3D:
7397 case GL_TEXTURE_BINDING_2D_ARRAY:
7398 case GL_MAX_3D_TEXTURE_SIZE:
7399 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7400 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7401 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7402 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7403 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7404 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7405 case GL_MAX_VARYING_COMPONENTS:
7406 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7407 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7408 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7409 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7410 case GL_NUM_EXTENSIONS:
7411 case GL_MAJOR_VERSION:
7412 case GL_MINOR_VERSION:
7413 case GL_MAX_ELEMENTS_INDICES:
7414 case GL_MAX_ELEMENTS_VERTICES:
7415 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7416 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7417 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7418 case GL_UNPACK_IMAGE_HEIGHT:
7419 case GL_UNPACK_SKIP_IMAGES:
7420 {
7421 *type = GL_INT;
7422 *numParams = 1;
7423 return true;
7424 }
7425
7426 case GL_MAX_ELEMENT_INDEX:
7427 case GL_MAX_UNIFORM_BLOCK_SIZE:
7428 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7429 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7430 case GL_MAX_SERVER_WAIT_TIMEOUT:
7431 {
7432 *type = GL_INT_64_ANGLEX;
7433 *numParams = 1;
7434 return true;
7435 }
7436
7437 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7438 case GL_TRANSFORM_FEEDBACK_PAUSED:
7439 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7440 case GL_RASTERIZER_DISCARD:
7441 {
7442 *type = GL_BOOL;
7443 *numParams = 1;
7444 return true;
7445 }
7446
7447 case GL_MAX_TEXTURE_LOD_BIAS:
7448 {
7449 *type = GL_FLOAT;
7450 *numParams = 1;
7451 return true;
7452 }
7453 }
7454
7455 if (getExtensions().requestExtension)
7456 {
7457 switch (pname)
7458 {
7459 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7460 *type = GL_INT;
7461 *numParams = 1;
7462 return true;
7463 }
7464 }
7465
7466 if (getClientVersion() < Version(3, 1))
7467 {
7468 return false;
7469 }
7470
7471 switch (pname)
7472 {
7473 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7474 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7475 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7476 case GL_MAX_FRAMEBUFFER_WIDTH:
7477 case GL_MAX_FRAMEBUFFER_HEIGHT:
7478 case GL_MAX_FRAMEBUFFER_SAMPLES:
7479 case GL_MAX_SAMPLE_MASK_WORDS:
7480 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7481 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7482 case GL_MAX_INTEGER_SAMPLES:
7483 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7484 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7485 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7486 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7487 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7488 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7489 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7490 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7491 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7492 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7493 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7494 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7495 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7496 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7497 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7498 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7499 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7500 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7501 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7502 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7503 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7504 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7505 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7506 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7507 case GL_MAX_UNIFORM_LOCATIONS:
7508 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7509 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7510 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7511 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7512 case GL_MAX_IMAGE_UNITS:
7513 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7514 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7515 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7516 case GL_SHADER_STORAGE_BUFFER_BINDING:
7517 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7518 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007519 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007520 *type = GL_INT;
7521 *numParams = 1;
7522 return true;
7523 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7524 *type = GL_INT_64_ANGLEX;
7525 *numParams = 1;
7526 return true;
7527 case GL_SAMPLE_MASK:
7528 *type = GL_BOOL;
7529 *numParams = 1;
7530 return true;
7531 }
7532
7533 if (getExtensions().geometryShader)
7534 {
7535 switch (pname)
7536 {
7537 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7538 case GL_LAYER_PROVOKING_VERTEX_EXT:
7539 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7540 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7541 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7542 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7543 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7544 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7545 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7546 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7547 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7548 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7549 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7550 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7551 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7552 *type = GL_INT;
7553 *numParams = 1;
7554 return true;
7555 }
7556 }
7557
7558 return false;
7559}
7560
7561bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7562{
7563 if (getClientVersion() < Version(3, 0))
7564 {
7565 return false;
7566 }
7567
7568 switch (target)
7569 {
7570 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7571 case GL_UNIFORM_BUFFER_BINDING:
7572 {
7573 *type = GL_INT;
7574 *numParams = 1;
7575 return true;
7576 }
7577 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7578 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7579 case GL_UNIFORM_BUFFER_START:
7580 case GL_UNIFORM_BUFFER_SIZE:
7581 {
7582 *type = GL_INT_64_ANGLEX;
7583 *numParams = 1;
7584 return true;
7585 }
7586 }
7587
7588 if (getClientVersion() < Version(3, 1))
7589 {
7590 return false;
7591 }
7592
7593 switch (target)
7594 {
7595 case GL_IMAGE_BINDING_LAYERED:
7596 {
7597 *type = GL_BOOL;
7598 *numParams = 1;
7599 return true;
7600 }
7601 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7602 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7603 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7604 case GL_SHADER_STORAGE_BUFFER_BINDING:
7605 case GL_VERTEX_BINDING_BUFFER:
7606 case GL_VERTEX_BINDING_DIVISOR:
7607 case GL_VERTEX_BINDING_OFFSET:
7608 case GL_VERTEX_BINDING_STRIDE:
7609 case GL_SAMPLE_MASK_VALUE:
7610 case GL_IMAGE_BINDING_NAME:
7611 case GL_IMAGE_BINDING_LEVEL:
7612 case GL_IMAGE_BINDING_LAYER:
7613 case GL_IMAGE_BINDING_ACCESS:
7614 case GL_IMAGE_BINDING_FORMAT:
7615 {
7616 *type = GL_INT;
7617 *numParams = 1;
7618 return true;
7619 }
7620 case GL_ATOMIC_COUNTER_BUFFER_START:
7621 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7622 case GL_SHADER_STORAGE_BUFFER_START:
7623 case GL_SHADER_STORAGE_BUFFER_SIZE:
7624 {
7625 *type = GL_INT_64_ANGLEX;
7626 *numParams = 1;
7627 return true;
7628 }
7629 }
7630
7631 return false;
7632}
7633
7634Program *Context::getProgram(GLuint handle) const
7635{
7636 return mState.mShaderPrograms->getProgram(handle);
7637}
7638
7639Shader *Context::getShader(GLuint handle) const
7640{
7641 return mState.mShaderPrograms->getShader(handle);
7642}
7643
7644bool Context::isTextureGenerated(GLuint texture) const
7645{
7646 return mState.mTextures->isHandleGenerated(texture);
7647}
7648
Jamie Madill5b772312018-03-08 20:28:32 -05007649bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7650{
7651 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7652}
7653
7654bool Context::isFramebufferGenerated(GLuint framebuffer) const
7655{
7656 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7657}
7658
7659bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7660{
7661 return mState.mPipelines->isHandleGenerated(pipeline);
7662}
7663
7664bool Context::usingDisplayTextureShareGroup() const
7665{
7666 return mDisplayTextureShareGroup;
7667}
7668
7669GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7670{
7671 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7672 internalformat == GL_DEPTH_STENCIL
7673 ? GL_DEPTH24_STENCIL8
7674 : internalformat;
7675}
7676
jchen1082af6202018-06-22 10:59:52 +08007677void Context::maxShaderCompilerThreads(GLuint count)
7678{
jchen107ae70d82018-07-06 13:47:01 +08007679 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007680 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007681 // A count of zero specifies a request for no parallel compiling or linking.
7682 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7683 {
7684 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7685 }
7686 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007687}
7688
Jamie Madill2eb65032018-07-30 10:25:57 -04007689bool Context::isGLES1() const
7690{
7691 return mState.getClientVersion() < Version(2, 0);
7692}
7693
Jamie Madilla11819d2018-07-30 10:26:01 -04007694void Context::onSubjectStateChange(const Context *context,
7695 angle::SubjectIndex index,
7696 angle::SubjectMessage message)
7697{
Jamie Madilla11819d2018-07-30 10:26:01 -04007698 switch (index)
7699 {
7700 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007701 switch (message)
7702 {
7703 case angle::SubjectMessage::CONTENTS_CHANGED:
7704 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7705 mStateCache.onVertexArrayBufferContentsChange(this);
7706 break;
7707 case angle::SubjectMessage::RESOURCE_MAPPED:
7708 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7709 case angle::SubjectMessage::BINDING_CHANGED:
7710 mStateCache.onVertexArrayBufferStateChange(this);
7711 break;
7712 default:
7713 break;
7714 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007715 break;
7716
7717 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007718 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7719 {
7720 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7721 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007722 break;
7723
7724 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007725 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7726 {
7727 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7728 }
7729 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007730 break;
7731
7732 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007733 if (index < kTextureMaxSubjectIndex)
7734 {
7735 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007736 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007737 }
7738 else
7739 {
7740 ASSERT(index < kUniformBufferMaxSubjectIndex);
7741 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007742 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007743 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007744 break;
7745 }
7746}
7747
Jamie Madill6b873dd2018-07-12 23:56:30 -04007748// ErrorSet implementation.
7749ErrorSet::ErrorSet(Context *context) : mContext(context)
7750{
7751}
7752
7753ErrorSet::~ErrorSet() = default;
7754
Jamie Madill306b6c12018-07-27 08:12:49 -04007755void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007756{
7757 // This internal enum is used to filter internal errors that are already handled.
7758 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7759 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7760 {
7761 return;
7762 }
7763
7764 if (ANGLE_UNLIKELY(error.isError()))
7765 {
7766 GLenum code = error.getCode();
7767 mErrors.insert(code);
7768 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7769 {
7770 mContext->markContextLost();
7771 }
7772
7773 ASSERT(!error.getMessage().empty());
7774 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7775 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7776 error.getMessage());
7777 }
7778}
7779
7780bool ErrorSet::empty() const
7781{
7782 return mErrors.empty();
7783}
7784
7785GLenum ErrorSet::popError()
7786{
7787 ASSERT(!empty());
7788 GLenum error = *mErrors.begin();
7789 mErrors.erase(mErrors.begin());
7790 return error;
7791}
Jamie Madilldc358af2018-07-31 11:22:13 -04007792
7793// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007794StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007795 : mCachedHasAnyEnabledClientAttrib(false),
7796 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007797 mCachedInstancedVertexElementLimit(0),
7798 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007799{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007800 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007801}
7802
7803StateCache::~StateCache() = default;
7804
7805void StateCache::updateActiveAttribsMask(Context *context)
7806{
7807 bool isGLES1 = context->isGLES1();
7808 const State &glState = context->getGLState();
7809
7810 if (!isGLES1 && !glState.getProgram())
7811 {
7812 mCachedActiveBufferedAttribsMask = AttributesMask();
7813 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007814 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007815 return;
7816 }
7817
7818 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7819 : glState.getProgram()->getActiveAttribLocationsMask();
7820
7821 const VertexArray *vao = glState.getVertexArray();
7822 ASSERT(vao);
7823
7824 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7825 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007826 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007827
Jamie Madill0a17e482018-08-31 17:19:11 -04007828 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7829 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007830 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007831 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7832}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007833
7834void StateCache::updateVertexElementLimits(Context *context)
7835{
7836 const VertexArray *vao = context->getGLState().getVertexArray();
7837
7838 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7839 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7840
7841 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7842 // If there are no buffered attributes then we should not limit the draw call count.
7843 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7844 {
7845 return;
7846 }
7847
7848 const auto &vertexAttribs = vao->getVertexAttributes();
7849 const auto &vertexBindings = vao->getVertexBindings();
7850
7851 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7852 {
7853 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7854 ASSERT(attrib.enabled);
7855
7856 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7857 ASSERT(context->isGLES1() ||
7858 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7859
7860 GLint64 limit = attrib.getCachedElementLimit();
7861 if (binding.getDivisor() > 0)
7862 {
7863 mCachedInstancedVertexElementLimit =
7864 std::min(mCachedInstancedVertexElementLimit, limit);
7865 }
7866 else
7867 {
7868 mCachedNonInstancedVertexElementLimit =
7869 std::min(mCachedNonInstancedVertexElementLimit, limit);
7870 }
7871 }
7872}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007873
Jamie Madilld84b6732018-09-06 15:54:35 -04007874void StateCache::updateBasicDrawStatesError()
7875{
7876 mCachedBasicDrawStatesError = kInvalidPointer;
7877}
7878
7879intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7880{
7881 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7882 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7883 return mCachedBasicDrawStatesError;
7884}
7885
Jamie Madillc43cdad2018-08-08 15:49:25 -04007886void StateCache::onVertexArrayBindingChange(Context *context)
7887{
7888 updateActiveAttribsMask(context);
7889 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007890 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007891}
7892
7893void StateCache::onProgramExecutableChange(Context *context)
7894{
7895 updateActiveAttribsMask(context);
7896 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007897 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007898 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007899}
7900
Jamie Madilld84b6732018-09-06 15:54:35 -04007901void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007902{
7903 updateVertexElementLimits(context);
7904}
7905
Jamie Madilld84b6732018-09-06 15:54:35 -04007906void StateCache::onVertexArrayBufferContentsChange(Context *context)
7907{
7908 updateVertexElementLimits(context);
7909 updateBasicDrawStatesError();
7910}
7911
Jamie Madillc43cdad2018-08-08 15:49:25 -04007912void StateCache::onVertexArrayStateChange(Context *context)
7913{
7914 updateActiveAttribsMask(context);
7915 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007916 updateBasicDrawStatesError();
7917}
7918
7919void StateCache::onVertexArrayBufferStateChange(Context *context)
7920{
7921 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007922}
7923
7924void StateCache::onGLES1ClientStateChange(Context *context)
7925{
7926 updateActiveAttribsMask(context);
7927}
Jamie Madilld84b6732018-09-06 15:54:35 -04007928
7929void StateCache::onDrawFramebufferChange(Context *context)
7930{
7931 updateBasicDrawStatesError();
7932}
7933
7934void StateCache::onContextCapChange(Context *context)
7935{
7936 updateBasicDrawStatesError();
7937}
7938
7939void StateCache::onStencilStateChange(Context *context)
7940{
7941 updateBasicDrawStatesError();
7942}
7943
7944void StateCache::onDefaultVertexAttributeChange(Context *context)
7945{
7946 updateBasicDrawStatesError();
7947}
7948
7949void StateCache::onActiveTextureChange(Context *context)
7950{
7951 updateBasicDrawStatesError();
7952}
7953
7954void StateCache::onQueryChange(Context *context)
7955{
7956 updateBasicDrawStatesError();
7957}
7958
7959void StateCache::onTransformFeedbackChange(Context *context)
7960{
7961 updateBasicDrawStatesError();
7962}
7963
7964void StateCache::onUniformBufferStateChange(Context *context)
7965{
7966 updateBasicDrawStatesError();
7967}
7968
7969void StateCache::onBufferBindingChange(Context *context)
7970{
7971 updateBasicDrawStatesError();
7972}
Jamie Madill526a6f62018-09-12 11:03:05 -04007973
7974void StateCache::updateValidDrawModes(Context *context)
7975{
7976 Program *program = context->getGLState().getProgram();
7977 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7978 {
7979 mCachedValidDrawModes = {{
7980 true, /* Points */
7981 true, /* Lines */
7982 true, /* LineLoop */
7983 true, /* LineStrip */
7984 true, /* Triangles */
7985 true, /* TriangleStrip */
7986 true, /* TriangleFan */
7987 false, /* LinesAdjacency */
7988 false, /* LineStripAdjacency */
7989 false, /* TrianglesAdjacency */
7990 false, /* TriangleStripAdjacency */
7991 false, /* InvalidEnum */
7992 }};
7993 }
7994 else
7995 {
7996 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
7997
7998 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
7999
8000 mCachedValidDrawModes = {{
8001 gsMode == PrimitiveMode::Points, /* Points */
8002 gsMode == PrimitiveMode::Lines, /* Lines */
8003 gsMode == PrimitiveMode::Lines, /* LineLoop */
8004 gsMode == PrimitiveMode::Lines, /* LineStrip */
8005 gsMode == PrimitiveMode::Triangles, /* Triangles */
8006 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8007 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8008 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8009 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8010 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8011 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8012 false, /* InvalidEnum */
8013 }};
8014 }
8015}
Jamie Madillc29968b2016-01-20 11:17:23 -05008016} // namespace gl