blob: 95c52ce45f66292ac9ec093a741ecbd30123d59c [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
Jamie Madill752d2202018-11-27 13:29:48 -050050namespace gl
51{
Geoff Langf6db0982015-08-25 13:04:00 -040052namespace
53{
54
Jamie Madillb6664922017-07-25 12:55:04 -040055#define ANGLE_HANDLE_ERR(X) \
Jamie Madill4f6592f2018-11-27 16:37:45 -050056 (void)(X); \
Jamie Madillb6664922017-07-25 12:55:04 -040057 return;
58#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
59
Ian Ewell3ffd78b2016-01-22 16:09:42 -050060template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -050061std::vector<Path *> GatherPaths(PathManager &resourceManager,
62 GLsizei numPaths,
63 const void *paths,
64 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030065{
Jamie Madill752d2202018-11-27 13:29:48 -050066 std::vector<Path *> ret;
Sami Väisänend59ca052016-06-21 16:10:00 +030067 ret.reserve(numPaths);
68
69 const auto *nameArray = static_cast<const T *>(paths);
70
71 for (GLsizei i = 0; i < numPaths; ++i)
72 {
73 const GLuint pathName = nameArray[i] + pathBase;
74
75 ret.push_back(resourceManager.getPath(pathName));
76 }
77
78 return ret;
79}
80
Jamie Madill752d2202018-11-27 13:29:48 -050081std::vector<Path *> GatherPaths(PathManager &resourceManager,
82 GLsizei numPaths,
83 GLenum pathNameType,
84 const void *paths,
85 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030086{
87 switch (pathNameType)
88 {
89 case GL_UNSIGNED_BYTE:
90 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_BYTE:
93 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_UNSIGNED_SHORT:
96 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_SHORT:
99 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_UNSIGNED_INT:
102 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
103
104 case GL_INT:
105 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
106 }
107
108 UNREACHABLE();
Jamie Madill752d2202018-11-27 13:29:48 -0500109 return std::vector<Path *>();
Sami Väisänend59ca052016-06-21 16:10:00 +0300110}
111
112template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -0500113angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114{
Geoff Lang2186c382016-10-14 10:54:54 -0400115 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116
117 switch (pname)
118 {
119 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400120 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 case GL_QUERY_RESULT_AVAILABLE_EXT:
122 {
123 bool available;
Jamie Madill666818e2018-11-14 09:54:33 -0500124 ANGLE_TRY(query->isResultAvailable(context, &available));
Jamie Madill752d2202018-11-27 13:29:48 -0500125 *params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Jamie Madill666818e2018-11-14 09:54:33 -0500126 return angle::Result::Continue();
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500127 }
128 default:
129 UNREACHABLE();
Jamie Madill666818e2018-11-14 09:54:33 -0500130 return angle::Result::Stop();
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500131 }
132}
133
Jamie Madill752d2202018-11-27 13:29:48 -0500134ANGLE_INLINE void MarkTransformFeedbackBufferUsage(const Context *context,
135 TransformFeedback *transformFeedback,
Jamie Madill956ab4d2018-10-10 16:13:03 -0400136 GLsizei count,
137 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400138{
Geoff Lang1a683462015-09-29 15:09:59 -0400139 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400140 {
Jamie Madill09463932018-04-04 05:26:59 -0400141 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400142 }
143}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144
145// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300146EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400148 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149}
150
Martin Radev1be913c2016-07-11 17:59:16 +0300151EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
152{
153 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
154}
155
Jamie Madill752d2202018-11-27 13:29:48 -0500156Version GetClientVersion(const egl::AttributeMap &attribs)
Geoff Langeb66a6e2016-10-31 13:06:12 -0400157{
Jamie Madill752d2202018-11-27 13:29:48 -0500158 return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159}
160
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500161GLenum GetResetStrategy(const egl::AttributeMap &attribs)
162{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800163 EGLAttrib attrib =
164 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165 switch (attrib)
166 {
167 case EGL_NO_RESET_NOTIFICATION:
168 return GL_NO_RESET_NOTIFICATION_EXT;
169 case EGL_LOSE_CONTEXT_ON_RESET:
170 return GL_LOSE_CONTEXT_ON_RESET_EXT;
171 default:
172 UNREACHABLE();
173 return GL_NONE;
174 }
175}
176
177bool GetRobustAccess(const egl::AttributeMap &attribs)
178{
Geoff Lang077f20a2016-11-01 10:08:02 -0400179 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
180 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
181 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500182}
183
184bool GetDebug(const egl::AttributeMap &attribs)
185{
Geoff Lang077f20a2016-11-01 10:08:02 -0400186 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
187 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500188}
189
190bool GetNoError(const egl::AttributeMap &attribs)
191{
192 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
193}
194
Geoff Langc287ea62016-09-16 14:46:51 -0400195bool GetWebGLContext(const egl::AttributeMap &attribs)
196{
Jamie Madill4230d482018-09-14 10:14:45 -0400197 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400198}
199
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400200bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
201{
202 // If the context is WebGL, extensions are disabled by default
203 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
204 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
205}
206
Geoff Langf41a7152016-09-19 15:11:17 -0400207bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
208{
Jamie Madill4230d482018-09-14 10:14:45 -0400209 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400210}
211
Geoff Langfeb8c682017-02-13 16:07:35 -0500212bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
213{
214 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
215}
216
Geoff Langb433e872017-10-05 14:01:47 -0400217bool GetRobustResourceInit(const egl::AttributeMap &attribs)
218{
219 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
220}
221
Martin Radev9d901792016-07-15 15:58:58 +0300222std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
223{
224 std::string labelName;
225 if (label != nullptr)
226 {
227 size_t labelLength = length < 0 ? strlen(label) : length;
228 labelName = std::string(label, labelLength);
229 }
230 return labelName;
231}
232
233void GetObjectLabelBase(const std::string &objectLabel,
234 GLsizei bufSize,
235 GLsizei *length,
236 GLchar *label)
237{
238 size_t writeLength = objectLabel.length();
239 if (label != nullptr && bufSize > 0)
240 {
241 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
242 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
243 label[writeLength] = '\0';
244 }
245
246 if (length != nullptr)
247 {
248 *length = static_cast<GLsizei>(writeLength);
249 }
250}
251
Jamie Madill0f80ed82017-09-19 00:24:56 -0400252template <typename CapT, typename MaxT>
253void LimitCap(CapT *cap, MaxT maximum)
254{
255 *cap = std::min(*cap, static_cast<CapT>(maximum));
256}
257
Jamie Madill752d2202018-11-27 13:29:48 -0500258constexpr angle::PackedEnumMap<PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
259 {PrimitiveMode::Points, 1},
260 {PrimitiveMode::Lines, 2},
261 {PrimitiveMode::LineLoop, 2},
262 {PrimitiveMode::LineStrip, 2},
263 {PrimitiveMode::Triangles, 3},
264 {PrimitiveMode::TriangleStrip, 3},
265 {PrimitiveMode::TriangleFan, 3},
266 {PrimitiveMode::LinesAdjacency, 2},
267 {PrimitiveMode::LineStripAdjacency, 2},
268 {PrimitiveMode::TrianglesAdjacency, 3},
269 {PrimitiveMode::TriangleStripAdjacency, 3},
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600270}};
Jamie Madill752d2202018-11-27 13:29:48 -0500271
272// The rest default to false.
273constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
274 kValidBasicDrawModes = {{
275 {PrimitiveMode::Points, true},
276 {PrimitiveMode::Lines, true},
277 {PrimitiveMode::LineLoop, true},
278 {PrimitiveMode::LineStrip, true},
279 {PrimitiveMode::Triangles, true},
280 {PrimitiveMode::TriangleStrip, true},
281 {PrimitiveMode::TriangleFan, true},
282 }};
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600283
Jamie Madill6d32cef2018-08-14 02:34:28 -0400284enum SubjectIndexes : angle::SubjectIndex
285{
286 kTexture0SubjectIndex = 0,
Jamie Madille3e680c2018-12-03 17:49:08 -0500287 kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
288 kImage0SubjectIndex = kTextureMaxSubjectIndex,
289 kImageMaxSubjectIndex = kImage0SubjectIndex + IMPLEMENTATION_MAX_IMAGE_UNITS,
290 kUniformBuffer0SubjectIndex = kImageMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400291 kUniformBufferMaxSubjectIndex =
Jamie Madille3e680c2018-12-03 17:49:08 -0500292 kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400293 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
Jamie Madille3e680c2018-12-03 17:49:08 -0500294 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Jamie Madille25b8002018-09-20 13:39:49 -0400295 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400296 kReadFramebufferSubjectIndex,
297 kDrawFramebufferSubjectIndex
298};
Geoff Langf6db0982015-08-25 13:04:00 -0400299} // anonymous namespace
300
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400301Context::Context(rx::EGLImplFactory *implFactory,
302 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400303 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500304 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400305 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500306 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700307 const egl::DisplayExtensions &displayExtensions,
308 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500309 : mState(reinterpret_cast<ContextID>(this),
310 shareContext ? &shareContext->mState : nullptr,
311 shareTextures,
312 GetClientVersion(attribs),
313 &mGLState,
314 mCaps,
315 mTextureCaps,
316 mExtensions,
317 mLimitations),
318 mSkipValidation(GetNoError(attribs)),
319 mDisplayTextureShareGroup(shareTextures != nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400320 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400321 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400322 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400323 mGLState(GetDebug(attribs),
324 GetBindGeneratesResource(attribs),
325 GetClientArraysEnabled(attribs),
326 GetRobustResourceInit(attribs),
327 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400328 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500329 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400330 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500331 mHasBeenCurrent(false),
332 mContextLost(false),
333 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700334 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500335 mResetStrategy(GetResetStrategy(attribs)),
336 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400337 mSurfacelessSupported(displayExtensions.surfacelessContext),
338 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400339 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
340 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500341 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400342 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400343 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400344 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
345 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
346 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400347 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800348 mZeroFilledBuffer(1000u),
349 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000350{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400351 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
352 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
353 {
354 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
355 }
Jamie Madille25b8002018-09-20 13:39:49 -0400356
357 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
358 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
359 {
360 mSamplerObserverBindings.emplace_back(this, samplerIndex);
361 }
Jamie Madille3e680c2018-12-03 17:49:08 -0500362
363 for (angle::SubjectIndex imageIndex = kImage0SubjectIndex; imageIndex < kImageMaxSubjectIndex;
364 ++imageIndex)
365 {
366 mImageObserverBindings.emplace_back(this, imageIndex);
367 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400368}
Jamie Madill5b772312018-03-08 20:28:32 -0500369
Geoff Lang33f11fb2018-05-07 13:42:47 -0400370void Context::initialize()
371{
372 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400373
Geoff Lang33f11fb2018-05-07 13:42:47 -0400374 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700375 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400376
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400377 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100378
Shannon Woods53a94a82014-06-24 15:20:36 -0400379 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400380
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000381 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400382 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000383 // and cube map texture state vectors respectively associated with them.
384 // In order that access to these initial textures not be lost, they are treated as texture
385 // objects all of whose names are 0.
386
Corentin Wallez99d492c2018-02-27 15:17:10 -0500387 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800388 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500389
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400392
Geoff Langeb66a6e2016-10-31 13:06:12 -0400393 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400394 {
395 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500396 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800397 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400398
Corentin Wallez99d492c2018-02-27 15:17:10 -0500399 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800400 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400401 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800402 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400403 {
404 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500405 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800406 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800407 }
408 if (getClientVersion() >= Version(3, 1))
409 {
Olli Etuahod310a432018-08-24 15:40:23 +0300410 Texture *zeroTexture2DMultisampleArray =
411 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
412 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800413
Jiajia Qin6eafb042016-12-27 17:04:07 +0800414 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
415 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800416 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800417 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800418
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800419 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
420 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400421 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800422 }
Geoff Lang3b573612016-10-31 14:08:10 -0400423 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424
Geoff Langb0f917f2017-12-05 13:41:54 -0500425 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400426 {
427 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500428 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800429 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400430 }
431
Geoff Langb0f917f2017-12-05 13:41:54 -0500432 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400433 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500434 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800435 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400436 }
437
Jamie Madill4928b7c2017-06-20 12:57:39 -0400438 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500439
Jamie Madill57a89722013-07-02 11:57:03 -0400440 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000441
Geoff Langeb66a6e2016-10-31 13:06:12 -0400442 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400443 {
444 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
445 // In the initial state, a default transform feedback object is bound and treated as
446 // a transform feedback object with a name of zero. That object is bound any time
447 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400448 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400449 }
Geoff Langc8058452014-02-03 12:04:11 -0500450
Corentin Wallez336129f2017-10-17 15:55:40 -0400451 for (auto type : angle::AllEnums<BufferBinding>())
452 {
453 bindBuffer(type, 0);
454 }
455
456 bindRenderbuffer(GL_RENDERBUFFER, 0);
457
458 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
459 {
460 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
461 }
462
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700463 // Initialize GLES1 renderer if appropriate.
464 if (getClientVersion() < Version(2, 0))
465 {
466 mGLES1Renderer.reset(new GLES1Renderer());
467 }
468
Jamie Madillad9f24e2016-02-12 09:27:24 -0500469 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400470 mAllDirtyBits.set();
471
Geoff Lang9bf86f02018-07-26 11:46:34 -0400472 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
473 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500474 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400475 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400476 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400477
478 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
479 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500480 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400481 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400482
Jamie Madillc67323a2017-11-02 23:11:41 -0400483 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500484 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500485 // No dirty objects.
486
487 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400488 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500489 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400490 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500491 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
492
493 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
494 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
495 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
496 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
497 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
498 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
499 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
500 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
501 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
502 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
503 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400504 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500505 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
506
507 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
508 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700509 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400510 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
511 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500512 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
513 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400514
Xinghua Cao10a4d432017-11-28 14:46:26 +0800515 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800516 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
517 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800518 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
519 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
520 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
521 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800522 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800523 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500524 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400525 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400526 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800527
Jamie Madillb4927eb2018-07-16 11:39:46 -0400528 mImplementation->setErrorSet(&mErrors);
529
Jamie Madill4f6592f2018-11-27 16:37:45 -0500530 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000531}
532
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000534{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700535 if (mGLES1Renderer)
536 {
537 mGLES1Renderer->onDestroy(this, &mGLState);
538 }
539
Jamie Madille7b3fe22018-04-05 09:42:46 -0400540 ANGLE_TRY(releaseSurface(display));
541
Corentin Wallez80b24112015-08-25 16:41:57 -0400542 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400544 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000545 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400546 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000547
Corentin Wallez80b24112015-08-25 16:41:57 -0400548 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400550 if (query.second != nullptr)
551 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400552 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400553 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000554 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400555 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556
Corentin Wallez80b24112015-08-25 16:41:57 -0400557 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400558 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559 if (vertexArray.second)
560 {
561 vertexArray.second->onDestroy(this);
562 }
Jamie Madill57a89722013-07-02 11:57:03 -0400563 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400564 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400565
Corentin Wallez80b24112015-08-25 16:41:57 -0400566 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500567 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500568 if (transformFeedback.second != nullptr)
569 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500570 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500571 }
Geoff Langc8058452014-02-03 12:04:11 -0500572 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400573 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500574
Jamie Madill5b772312018-03-08 20:28:32 -0500575 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400576 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800577 if (zeroTexture.get() != nullptr)
578 {
Jamie Madill1c7f08c2018-10-10 16:13:02 -0400579 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800580 zeroTexture.set(this, nullptr);
581 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400582 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583
Jamie Madill2f348d22017-06-05 10:50:59 -0400584 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500585
Jamie Madill4928b7c2017-06-20 12:57:39 -0400586 mGLState.reset(this);
587
Jamie Madill6c1f6712017-02-14 19:08:04 -0500588 mState.mBuffers->release(this);
589 mState.mShaderPrograms->release(this);
590 mState.mTextures->release(this);
591 mState.mRenderbuffers->release(this);
592 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400593 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500594 mState.mPaths->release(this);
595 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800596 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400597
jchen107ae70d82018-07-06 13:47:01 +0800598 mThreadPool.reset();
599
Jamie Madill76e471e2017-10-21 09:56:01 -0400600 mImplementation->onDestroy(this);
601
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603}
604
Jamie Madillb980c562018-11-27 11:34:27 -0500605Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500606
Geoff Lang75359662018-04-11 01:42:27 -0400607void Context::setLabel(EGLLabelKHR label)
608{
609 mLabel = label;
610}
611
612EGLLabelKHR Context::getLabel() const
613{
614 return mLabel;
615}
616
Jamie Madill4928b7c2017-06-20 12:57:39 -0400617egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618{
Jamie Madill61e16b42017-06-19 11:13:23 -0400619 mCurrentDisplay = display;
620
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621 if (!mHasBeenCurrent)
622 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400623 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000624 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500625 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400626 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627
Corentin Wallezc295e512017-01-27 17:47:50 -0500628 int width = 0;
629 int height = 0;
630 if (surface != nullptr)
631 {
632 width = surface->getWidth();
633 height = surface->getHeight();
634 }
635
636 mGLState.setViewportParams(0, 0, width, height);
637 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638
639 mHasBeenCurrent = true;
640 }
641
Jamie Madill1b94d432015-08-07 13:23:23 -0400642 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700643 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400644 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400645
Jamie Madill4928b7c2017-06-20 12:57:39 -0400646 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500647
648 Framebuffer *newDefault = nullptr;
649 if (surface != nullptr)
650 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400651 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500652 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400653 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500654 }
655 else
656 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400657 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500658 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000659
Corentin Wallez37c39792015-08-20 14:19:46 -0400660 // Update default framebuffer, the binding of the previous default
661 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400662 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400663 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700664 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400665 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400666 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400667 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700668 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400669 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400670 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400671 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400672 }
Ian Ewell292f0052016-02-04 10:37:32 -0500673
Jamie Madill32643ce2018-10-19 11:38:03 -0400674 // Notify the renderer of a context switch.
Jamie Madill4f6592f2018-11-27 16:37:45 -0500675 return mImplementation->onMakeCurrent(this).toEGL();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676}
677
Jamie Madill4928b7c2017-06-20 12:57:39 -0400678egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400679{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400680 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400681
Geoff Langbf7b95d2018-05-01 16:48:21 -0400682 // Remove the default framebuffer
683 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500684 {
685 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400686 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500687 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688
689 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500690 {
691 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400692 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500693 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400694
695 if (defaultFramebuffer)
696 {
697 defaultFramebuffer->onDestroy(this);
698 delete defaultFramebuffer;
699 }
700
Corentin Wallezc295e512017-01-27 17:47:50 -0500701 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
702
703 if (mCurrentSurface)
704 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400705 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500706 mCurrentSurface = nullptr;
707 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400708
709 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400710}
711
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712GLuint Context::createBuffer()
713{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500714 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715}
716
717GLuint Context::createProgram()
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720}
721
Jiawei Shao385b3e02018-03-21 09:43:28 +0800722GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500724 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
727GLuint Context::createTexture()
728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000730}
731
732GLuint Context::createRenderbuffer()
733{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500734 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735}
736
Jamie Madill13951342018-09-30 15:24:28 -0400737void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
738{
Jamie Madill526392d2018-11-16 09:35:14 -0500739 ANGLE_CONTEXT_TRY(mState.mPaths->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400740}
741
Brandon Jones59770802018-04-02 13:18:42 -0700742GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743{
Jamie Madill13951342018-09-30 15:24:28 -0400744 GLuint created = 0;
745 tryGenPaths(range, &created);
746 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747}
748
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749// Returns an unused framebuffer name
750GLuint Context::createFramebuffer()
751{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500752 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000753}
754
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500755void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000756{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500757 for (int i = 0; i < n; i++)
758 {
759 GLuint handle = mFenceNVHandleAllocator.allocate();
760 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
761 fences[i] = handle;
762 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000763}
764
Yunchao Hea336b902017-08-02 16:05:21 +0800765GLuint Context::createProgramPipeline()
766{
767 return mState.mPipelines->createProgramPipeline();
768}
769
Jiawei Shao385b3e02018-03-21 09:43:28 +0800770GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800771{
772 UNIMPLEMENTED();
773 return 0u;
774}
775
James Darpinian4d9d4832018-03-13 12:43:28 -0700776void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777{
James Darpinian4d9d4832018-03-13 12:43:28 -0700778 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
779 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000780 {
781 detachBuffer(buffer);
782 }
Jamie Madill893ab082014-05-16 16:56:10 -0400783
James Darpinian4d9d4832018-03-13 12:43:28 -0700784 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785}
786
787void Context::deleteShader(GLuint shader)
788{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500789 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790}
791
792void Context::deleteProgram(GLuint program)
793{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500794 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795}
796
797void Context::deleteTexture(GLuint texture)
798{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500799 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800 {
801 detachTexture(texture);
802 }
803
Jamie Madill6c1f6712017-02-14 19:08:04 -0500804 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805}
806
807void Context::deleteRenderbuffer(GLuint renderbuffer)
808{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500809 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810 {
811 detachRenderbuffer(renderbuffer);
812 }
Jamie Madill893ab082014-05-16 16:56:10 -0400813
Jamie Madill6c1f6712017-02-14 19:08:04 -0500814 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815}
816
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400817void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400818{
819 // The spec specifies the underlying Fence object is not deleted until all current
820 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
821 // and since our API is currently designed for being called from a single thread, we can delete
822 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400823 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400824}
825
Yunchao Hea336b902017-08-02 16:05:21 +0800826void Context::deleteProgramPipeline(GLuint pipeline)
827{
828 if (mState.mPipelines->getProgramPipeline(pipeline))
829 {
830 detachProgramPipeline(pipeline);
831 }
832
833 mState.mPipelines->deleteObject(this, pipeline);
834}
835
Sami Väisänene45e53b2016-05-25 10:36:04 +0300836void Context::deletePaths(GLuint first, GLsizei range)
837{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500838 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300839}
840
Brandon Jones59770802018-04-02 13:18:42 -0700841bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500843 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300844 if (pathObj == nullptr)
845 return false;
846
847 return pathObj->hasPathData();
848}
849
Brandon Jones59770802018-04-02 13:18:42 -0700850bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300851{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500852 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853}
854
Brandon Jones59770802018-04-02 13:18:42 -0700855void Context::pathCommands(GLuint path,
856 GLsizei numCommands,
857 const GLubyte *commands,
858 GLsizei numCoords,
859 GLenum coordType,
860 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300863
Jamie Madill4f6592f2018-11-27 16:37:45 -0500864 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300865}
866
Jamie Madill007530e2017-12-28 14:27:04 -0500867void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868{
Jamie Madill007530e2017-12-28 14:27:04 -0500869 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300870
871 switch (pname)
872 {
873 case GL_PATH_STROKE_WIDTH_CHROMIUM:
874 pathObj->setStrokeWidth(value);
875 break;
876 case GL_PATH_END_CAPS_CHROMIUM:
877 pathObj->setEndCaps(static_cast<GLenum>(value));
878 break;
879 case GL_PATH_JOIN_STYLE_CHROMIUM:
880 pathObj->setJoinStyle(static_cast<GLenum>(value));
881 break;
882 case GL_PATH_MITER_LIMIT_CHROMIUM:
883 pathObj->setMiterLimit(value);
884 break;
885 case GL_PATH_STROKE_BOUND_CHROMIUM:
886 pathObj->setStrokeBound(value);
887 break;
888 default:
889 UNREACHABLE();
890 break;
891 }
892}
893
Jamie Madill007530e2017-12-28 14:27:04 -0500894void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300895{
Jamie Madill007530e2017-12-28 14:27:04 -0500896 // TODO(jmadill): Should use proper clamping/casting.
897 pathParameterf(path, pname, static_cast<GLfloat>(value));
898}
899
900void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
901{
902 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300903
904 switch (pname)
905 {
906 case GL_PATH_STROKE_WIDTH_CHROMIUM:
907 *value = pathObj->getStrokeWidth();
908 break;
909 case GL_PATH_END_CAPS_CHROMIUM:
910 *value = static_cast<GLfloat>(pathObj->getEndCaps());
911 break;
912 case GL_PATH_JOIN_STYLE_CHROMIUM:
913 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
914 break;
915 case GL_PATH_MITER_LIMIT_CHROMIUM:
916 *value = pathObj->getMiterLimit();
917 break;
918 case GL_PATH_STROKE_BOUND_CHROMIUM:
919 *value = pathObj->getStrokeBound();
920 break;
921 default:
922 UNREACHABLE();
923 break;
924 }
925}
926
Jamie Madill007530e2017-12-28 14:27:04 -0500927void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
928{
929 GLfloat val = 0.0f;
930 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
931 if (value)
932 *value = static_cast<GLint>(val);
933}
934
Brandon Jones59770802018-04-02 13:18:42 -0700935void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300936{
937 mGLState.setPathStencilFunc(func, ref, mask);
938}
939
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940void Context::deleteFramebuffer(GLuint framebuffer)
941{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500942 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943 {
944 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500946
Jamie Madill6c1f6712017-02-14 19:08:04 -0500947 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948}
949
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500950void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500952 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500954 GLuint fence = fences[i];
955
956 FenceNV *fenceObject = nullptr;
957 if (mFenceNVMap.erase(fence, &fenceObject))
958 {
959 mFenceNVHandleAllocator.release(fence);
960 delete fenceObject;
961 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000962 }
963}
964
Geoff Lang70d0f492015-12-10 17:45:46 -0500965Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500967 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968}
969
Geoff Lang70d0f492015-12-10 17:45:46 -0500970Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973}
974
Jamie Madill70b5bb02017-08-28 13:32:37 -0400975Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400976{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400977 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400978}
979
Jamie Madill57a89722013-07-02 11:57:03 -0400980VertexArray *Context::getVertexArray(GLuint handle) const
981{
Jamie Madill96a483b2017-06-27 16:49:21 -0400982 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400983}
984
Jamie Madilldc356042013-07-19 16:36:57 -0400985Sampler *Context::getSampler(GLuint handle) const
986{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500987 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400988}
989
Geoff Langc8058452014-02-03 12:04:11 -0500990TransformFeedback *Context::getTransformFeedback(GLuint handle) const
991{
Jamie Madill96a483b2017-06-27 16:49:21 -0400992 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500993}
994
Yunchao Hea336b902017-08-02 16:05:21 +0800995ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
996{
997 return mState.mPipelines->getProgramPipeline(handle);
998}
999
Geoff Lang75359662018-04-11 01:42:27 -04001000gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001001{
1002 switch (identifier)
1003 {
1004 case GL_BUFFER:
1005 return getBuffer(name);
1006 case GL_SHADER:
1007 return getShader(name);
1008 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001009 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -05001010 case GL_VERTEX_ARRAY:
1011 return getVertexArray(name);
1012 case GL_QUERY:
1013 return getQuery(name);
1014 case GL_TRANSFORM_FEEDBACK:
1015 return getTransformFeedback(name);
1016 case GL_SAMPLER:
1017 return getSampler(name);
1018 case GL_TEXTURE:
1019 return getTexture(name);
1020 case GL_RENDERBUFFER:
1021 return getRenderbuffer(name);
1022 case GL_FRAMEBUFFER:
1023 return getFramebuffer(name);
1024 default:
1025 UNREACHABLE();
1026 return nullptr;
1027 }
1028}
1029
Geoff Lang75359662018-04-11 01:42:27 -04001030gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001031{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001032 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001033}
1034
Martin Radev9d901792016-07-15 15:58:58 +03001035void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1036{
Geoff Lang75359662018-04-11 01:42:27 -04001037 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001038 ASSERT(object != nullptr);
1039
1040 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001041 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001042
1043 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1044 // specified object is active until we do this.
1045 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001046}
1047
1048void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1049{
Geoff Lang75359662018-04-11 01:42:27 -04001050 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001051 ASSERT(object != nullptr);
1052
1053 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001054 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001055}
1056
1057void Context::getObjectLabel(GLenum identifier,
1058 GLuint name,
1059 GLsizei bufSize,
1060 GLsizei *length,
1061 GLchar *label) const
1062{
Geoff Lang75359662018-04-11 01:42:27 -04001063 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001064 ASSERT(object != nullptr);
1065
1066 const std::string &objectLabel = object->getLabel();
1067 GetObjectLabelBase(objectLabel, bufSize, length, label);
1068}
1069
1070void Context::getObjectPtrLabel(const void *ptr,
1071 GLsizei bufSize,
1072 GLsizei *length,
1073 GLchar *label) const
1074{
Geoff Lang75359662018-04-11 01:42:27 -04001075 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001076 ASSERT(object != nullptr);
1077
1078 const std::string &objectLabel = object->getLabel();
1079 GetObjectLabelBase(objectLabel, bufSize, length, label);
1080}
1081
Jamie Madilldc356042013-07-19 16:36:57 -04001082bool Context::isSampler(GLuint samplerName) const
1083{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001084 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001085}
1086
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001087void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090
Jamie Madilldedd7b92014-11-05 16:30:36 -05001091 if (handle == 0)
1092 {
1093 texture = mZeroTextures[target].get();
1094 }
1095 else
1096 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001097 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001098 }
1099
1100 ASSERT(texture);
Jamie Madille3e680c2018-12-03 17:49:08 -05001101 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001102 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001103}
1104
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001105void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001107 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1108 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001109 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001110 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001111}
1112
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001113void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001114{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001115 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1116 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001117 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001118 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001119 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001120}
1121
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001122void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001123{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001124 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001125 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001126 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001127 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001128}
1129
Shao80957d92017-02-20 21:25:59 +08001130void Context::bindVertexBuffer(GLuint bindingIndex,
1131 GLuint bufferHandle,
1132 GLintptr offset,
1133 GLsizei stride)
1134{
1135 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001136 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001137 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001138}
1139
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001140void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001141{
Geoff Lang76b10c92014-09-05 16:28:14 -04001142 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001143 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001144 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001146 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001147}
1148
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001149void Context::bindImageTexture(GLuint unit,
1150 GLuint texture,
1151 GLint level,
1152 GLboolean layered,
1153 GLint layer,
1154 GLenum access,
1155 GLenum format)
1156{
1157 Texture *tex = mState.mTextures->getTexture(texture);
1158 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Jamie Madille3e680c2018-12-03 17:49:08 -05001159 mImageObserverBindings[unit].bind(tex);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001160}
1161
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162void Context::useProgram(GLuint program)
1163{
Jamie Madille3bb6b72018-10-03 17:51:15 -04001164 ANGLE_CONTEXT_TRY(mGLState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001165 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001166}
1167
Jiajia Qin5451d532017-11-16 17:16:34 +08001168void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1169{
1170 UNIMPLEMENTED();
1171}
1172
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001173void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001174{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001175 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001176 TransformFeedback *transformFeedback =
1177 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001178 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001179 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001180}
1181
Yunchao Hea336b902017-08-02 16:05:21 +08001182void Context::bindProgramPipeline(GLuint pipelineHandle)
1183{
1184 ProgramPipeline *pipeline =
1185 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1186 mGLState.setProgramPipelineBinding(this, pipeline);
1187}
1188
Corentin Wallezad3ae902018-03-09 13:40:42 -05001189void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001192 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001193
Geoff Lang5aad9672014-09-08 11:10:42 -04001194 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001195 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001196
1197 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001198 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001199 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200}
1201
Corentin Wallezad3ae902018-03-09 13:40:42 -05001202void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001204 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001205 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206
Jamie Madill4f6592f2018-11-27 16:37:45 -05001207 // Intentionally don't call try here. We don't want an early return.
1208 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209
Geoff Lang5aad9672014-09-08 11:10:42 -04001210 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001211 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001212 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213}
1214
Corentin Wallezad3ae902018-03-09 13:40:42 -05001215void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001216{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001217 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218
1219 Query *queryObject = getQuery(id, true, target);
1220 ASSERT(queryObject);
1221
Jamie Madill4f6592f2018-11-27 16:37:45 -05001222 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223}
1224
Corentin Wallezad3ae902018-03-09 13:40:42 -05001225void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001226{
1227 switch (pname)
1228 {
1229 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001230 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231 break;
1232 case GL_QUERY_COUNTER_BITS_EXT:
1233 switch (target)
1234 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001236 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1237 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001238 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239 params[0] = getExtensions().queryCounterBitsTimestamp;
1240 break;
1241 default:
1242 UNREACHABLE();
1243 params[0] = 0;
1244 break;
1245 }
1246 break;
1247 default:
1248 UNREACHABLE();
1249 return;
1250 }
1251}
1252
Corentin Wallezad3ae902018-03-09 13:40:42 -05001253void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001254 GLenum pname,
1255 GLsizei bufSize,
1256 GLsizei *length,
1257 GLint *params)
1258{
1259 getQueryiv(target, pname, params);
1260}
1261
Geoff Lang2186c382016-10-14 10:54:54 -04001262void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001263{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001264 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001265}
1266
Brandon Jones59770802018-04-02 13:18:42 -07001267void Context::getQueryObjectivRobust(GLuint id,
1268 GLenum pname,
1269 GLsizei bufSize,
1270 GLsizei *length,
1271 GLint *params)
1272{
1273 getQueryObjectiv(id, pname, params);
1274}
1275
Geoff Lang2186c382016-10-14 10:54:54 -04001276void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001277{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001278 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001279}
1280
Brandon Jones59770802018-04-02 13:18:42 -07001281void Context::getQueryObjectuivRobust(GLuint id,
1282 GLenum pname,
1283 GLsizei bufSize,
1284 GLsizei *length,
1285 GLuint *params)
1286{
1287 getQueryObjectuiv(id, pname, params);
1288}
1289
Geoff Lang2186c382016-10-14 10:54:54 -04001290void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001291{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001292 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001293}
1294
Brandon Jones59770802018-04-02 13:18:42 -07001295void Context::getQueryObjecti64vRobust(GLuint id,
1296 GLenum pname,
1297 GLsizei bufSize,
1298 GLsizei *length,
1299 GLint64 *params)
1300{
1301 getQueryObjecti64v(id, pname, params);
1302}
1303
Geoff Lang2186c382016-10-14 10:54:54 -04001304void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001305{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001306 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001307}
1308
Brandon Jones59770802018-04-02 13:18:42 -07001309void Context::getQueryObjectui64vRobust(GLuint id,
1310 GLenum pname,
1311 GLsizei bufSize,
1312 GLsizei *length,
1313 GLuint64 *params)
1314{
1315 getQueryObjectui64v(id, pname, params);
1316}
1317
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001318Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001320 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321}
1322
Jamie Madill2f348d22017-06-05 10:50:59 -04001323FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
Jamie Madill96a483b2017-06-27 16:49:21 -04001325 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326}
1327
Corentin Wallezad3ae902018-03-09 13:40:42 -05001328Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001329{
Jamie Madill96a483b2017-06-27 16:49:21 -04001330 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001332 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001334
1335 Query *query = mQueryMap.query(handle);
1336 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001338 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001339 query = new Query(mImplementation->createQuery(type), handle);
1340 query->addRef();
1341 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001343 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344}
1345
Geoff Lang70d0f492015-12-10 17:45:46 -05001346Query *Context::getQuery(GLuint handle) const
1347{
Jamie Madill96a483b2017-06-27 16:49:21 -04001348 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001349}
1350
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001351Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001352{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001353 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1354 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001355}
1356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001357Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001359 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360}
1361
Geoff Lang492a7e42014-11-05 13:27:06 -05001362Compiler *Context::getCompiler() const
1363{
Jamie Madill2f348d22017-06-05 10:50:59 -04001364 if (mCompiler.get() == nullptr)
1365 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001366 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001367 }
1368 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001369}
1370
Jamie Madillc1d770e2017-04-13 17:31:24 -04001371void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001372{
1373 switch (pname)
1374 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 case GL_SHADER_COMPILER:
1376 *params = GL_TRUE;
1377 break;
1378 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1379 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1380 break;
1381 default:
1382 mGLState.getBooleanv(pname, params);
1383 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001385}
1386
Jamie Madillc1d770e2017-04-13 17:31:24 -04001387void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388{
Shannon Woods53a94a82014-06-24 15:20:36 -04001389 // Queries about context capabilities and maximums are answered by Context.
1390 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001391 switch (pname)
1392 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 case GL_ALIASED_LINE_WIDTH_RANGE:
1394 params[0] = mCaps.minAliasedLineWidth;
1395 params[1] = mCaps.maxAliasedLineWidth;
1396 break;
1397 case GL_ALIASED_POINT_SIZE_RANGE:
1398 params[0] = mCaps.minAliasedPointSize;
1399 params[1] = mCaps.maxAliasedPointSize;
1400 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001401 case GL_SMOOTH_POINT_SIZE_RANGE:
1402 params[0] = mCaps.minSmoothPointSize;
1403 params[1] = mCaps.maxSmoothPointSize;
1404 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001405 case GL_SMOOTH_LINE_WIDTH_RANGE:
1406 params[0] = mCaps.minSmoothLineWidth;
1407 params[1] = mCaps.maxSmoothLineWidth;
1408 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1410 ASSERT(mExtensions.textureFilterAnisotropic);
1411 *params = mExtensions.maxTextureAnisotropy;
1412 break;
1413 case GL_MAX_TEXTURE_LOD_BIAS:
1414 *params = mCaps.maxLODBias;
1415 break;
1416
1417 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1418 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1419 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001420 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1421 // GLES1 constants for modelview/projection matrix.
1422 if (getClientVersion() < Version(2, 0))
1423 {
1424 mGLState.getFloatv(pname, params);
1425 }
1426 else
1427 {
1428 ASSERT(mExtensions.pathRendering);
1429 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1430 memcpy(params, m, 16 * sizeof(GLfloat));
1431 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001433 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001434
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 default:
1436 mGLState.getFloatv(pname, params);
1437 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001438 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001439}
1440
Jamie Madillc1d770e2017-04-13 17:31:24 -04001441void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442{
Shannon Woods53a94a82014-06-24 15:20:36 -04001443 // Queries about context capabilities and maximums are answered by Context.
1444 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001445
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446 switch (pname)
1447 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 case GL_MAX_VERTEX_ATTRIBS:
1449 *params = mCaps.maxVertexAttributes;
1450 break;
1451 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1452 *params = mCaps.maxVertexUniformVectors;
1453 break;
1454 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001455 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 break;
1457 case GL_MAX_VARYING_VECTORS:
1458 *params = mCaps.maxVaryingVectors;
1459 break;
1460 case GL_MAX_VARYING_COMPONENTS:
1461 *params = mCaps.maxVertexOutputComponents;
1462 break;
1463 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1464 *params = mCaps.maxCombinedTextureImageUnits;
1465 break;
1466 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001467 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001470 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 break;
1472 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1473 *params = mCaps.maxFragmentUniformVectors;
1474 break;
1475 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001476 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_RENDERBUFFER_SIZE:
1479 *params = mCaps.maxRenderbufferSize;
1480 break;
1481 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1482 *params = mCaps.maxColorAttachments;
1483 break;
1484 case GL_MAX_DRAW_BUFFERS_EXT:
1485 *params = mCaps.maxDrawBuffers;
1486 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 case GL_SUBPIXEL_BITS:
1488 *params = 4;
1489 break;
1490 case GL_MAX_TEXTURE_SIZE:
1491 *params = mCaps.max2DTextureSize;
1492 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001493 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1494 *params = mCaps.maxRectangleTextureSize;
1495 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001496 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1497 *params = mCaps.maxCubeMapTextureSize;
1498 break;
1499 case GL_MAX_3D_TEXTURE_SIZE:
1500 *params = mCaps.max3DTextureSize;
1501 break;
1502 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1503 *params = mCaps.maxArrayTextureLayers;
1504 break;
1505 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1506 *params = mCaps.uniformBufferOffsetAlignment;
1507 break;
1508 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1509 *params = mCaps.maxUniformBufferBindings;
1510 break;
1511 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001512 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 break;
1514 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001515 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001516 break;
1517 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1518 *params = mCaps.maxCombinedTextureImageUnits;
1519 break;
1520 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1521 *params = mCaps.maxVertexOutputComponents;
1522 break;
1523 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1524 *params = mCaps.maxFragmentInputComponents;
1525 break;
1526 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1527 *params = mCaps.minProgramTexelOffset;
1528 break;
1529 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1530 *params = mCaps.maxProgramTexelOffset;
1531 break;
1532 case GL_MAJOR_VERSION:
1533 *params = getClientVersion().major;
1534 break;
1535 case GL_MINOR_VERSION:
1536 *params = getClientVersion().minor;
1537 break;
1538 case GL_MAX_ELEMENTS_INDICES:
1539 *params = mCaps.maxElementsIndices;
1540 break;
1541 case GL_MAX_ELEMENTS_VERTICES:
1542 *params = mCaps.maxElementsVertices;
1543 break;
1544 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1545 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1546 break;
1547 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1548 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1549 break;
1550 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1551 *params = mCaps.maxTransformFeedbackSeparateComponents;
1552 break;
1553 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1554 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1555 break;
1556 case GL_MAX_SAMPLES_ANGLE:
1557 *params = mCaps.maxSamples;
1558 break;
1559 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001560 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001561 params[0] = mCaps.maxViewportWidth;
1562 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001563 }
1564 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 case GL_COMPRESSED_TEXTURE_FORMATS:
1566 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1567 params);
1568 break;
1569 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1570 *params = mResetStrategy;
1571 break;
1572 case GL_NUM_SHADER_BINARY_FORMATS:
1573 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1574 break;
1575 case GL_SHADER_BINARY_FORMATS:
1576 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1577 break;
1578 case GL_NUM_PROGRAM_BINARY_FORMATS:
1579 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1580 break;
1581 case GL_PROGRAM_BINARY_FORMATS:
1582 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1583 break;
1584 case GL_NUM_EXTENSIONS:
1585 *params = static_cast<GLint>(mExtensionStrings.size());
1586 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001587
Geoff Lang38f24ee2018-10-01 13:04:59 -04001588 // GL_ANGLE_request_extension
1589 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1590 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1591 break;
1592
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 // GL_KHR_debug
1594 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1595 *params = mExtensions.maxDebugMessageLength;
1596 break;
1597 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1598 *params = mExtensions.maxDebugLoggedMessages;
1599 break;
1600 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1601 *params = mExtensions.maxDebugGroupStackDepth;
1602 break;
1603 case GL_MAX_LABEL_LENGTH:
1604 *params = mExtensions.maxLabelLength;
1605 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001606
Martin Radeve5285d22017-07-14 16:23:53 +03001607 // GL_ANGLE_multiview
1608 case GL_MAX_VIEWS_ANGLE:
1609 *params = mExtensions.maxViews;
1610 break;
1611
Jamie Madill231c7f52017-04-26 13:45:37 -04001612 // GL_EXT_disjoint_timer_query
1613 case GL_GPU_DISJOINT_EXT:
1614 *params = mImplementation->getGPUDisjoint();
1615 break;
1616 case GL_MAX_FRAMEBUFFER_WIDTH:
1617 *params = mCaps.maxFramebufferWidth;
1618 break;
1619 case GL_MAX_FRAMEBUFFER_HEIGHT:
1620 *params = mCaps.maxFramebufferHeight;
1621 break;
1622 case GL_MAX_FRAMEBUFFER_SAMPLES:
1623 *params = mCaps.maxFramebufferSamples;
1624 break;
1625 case GL_MAX_SAMPLE_MASK_WORDS:
1626 *params = mCaps.maxSampleMaskWords;
1627 break;
1628 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1629 *params = mCaps.maxColorTextureSamples;
1630 break;
1631 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1632 *params = mCaps.maxDepthTextureSamples;
1633 break;
1634 case GL_MAX_INTEGER_SAMPLES:
1635 *params = mCaps.maxIntegerSamples;
1636 break;
1637 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1638 *params = mCaps.maxVertexAttribRelativeOffset;
1639 break;
1640 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1641 *params = mCaps.maxVertexAttribBindings;
1642 break;
1643 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1644 *params = mCaps.maxVertexAttribStride;
1645 break;
1646 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001647 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001653 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001656 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001657 break;
1658 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001659 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001668 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1671 *params = mCaps.minProgramTextureGatherOffset;
1672 break;
1673 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1674 *params = mCaps.maxProgramTextureGatherOffset;
1675 break;
1676 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1677 *params = mCaps.maxComputeWorkGroupInvocations;
1678 break;
1679 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001680 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001683 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1686 *params = mCaps.maxComputeSharedMemorySize;
1687 break;
1688 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001689 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001692 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001695 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001698 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001701 *params =
1702 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
1704 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001705 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
1707 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1708 *params = mCaps.maxCombinedShaderOutputResources;
1709 break;
1710 case GL_MAX_UNIFORM_LOCATIONS:
1711 *params = mCaps.maxUniformLocations;
1712 break;
1713 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1714 *params = mCaps.maxAtomicCounterBufferBindings;
1715 break;
1716 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1717 *params = mCaps.maxAtomicCounterBufferSize;
1718 break;
1719 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1720 *params = mCaps.maxCombinedAtomicCounterBuffers;
1721 break;
1722 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1723 *params = mCaps.maxCombinedAtomicCounters;
1724 break;
1725 case GL_MAX_IMAGE_UNITS:
1726 *params = mCaps.maxImageUnits;
1727 break;
1728 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1729 *params = mCaps.maxCombinedImageUniforms;
1730 break;
1731 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1732 *params = mCaps.maxShaderStorageBufferBindings;
1733 break;
1734 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1735 *params = mCaps.maxCombinedShaderStorageBlocks;
1736 break;
1737 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1738 *params = mCaps.shaderStorageBufferOffsetAlignment;
1739 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001740
1741 // GL_EXT_geometry_shader
1742 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1743 *params = mCaps.maxFramebufferLayers;
1744 break;
1745 case GL_LAYER_PROVOKING_VERTEX_EXT:
1746 *params = mCaps.layerProvokingVertex;
1747 break;
1748 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001749 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
1751 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001752 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001753 break;
1754 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001755 *params =
1756 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001757 break;
1758 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1759 *params = mCaps.maxGeometryInputComponents;
1760 break;
1761 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1762 *params = mCaps.maxGeometryOutputComponents;
1763 break;
1764 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1765 *params = mCaps.maxGeometryOutputVertices;
1766 break;
1767 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1768 *params = mCaps.maxGeometryTotalOutputComponents;
1769 break;
1770 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1771 *params = mCaps.maxGeometryShaderInvocations;
1772 break;
1773 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001774 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001775 break;
1776 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001777 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001778 break;
1779 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001780 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001781 break;
1782 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001783 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001784 break;
1785 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001786 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001787 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001788 // GLES1 emulation: Caps queries
1789 case GL_MAX_TEXTURE_UNITS:
1790 *params = mCaps.maxMultitextureUnits;
1791 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001792 case GL_MAX_MODELVIEW_STACK_DEPTH:
1793 *params = mCaps.maxModelviewMatrixStackDepth;
1794 break;
1795 case GL_MAX_PROJECTION_STACK_DEPTH:
1796 *params = mCaps.maxProjectionMatrixStackDepth;
1797 break;
1798 case GL_MAX_TEXTURE_STACK_DEPTH:
1799 *params = mCaps.maxTextureMatrixStackDepth;
1800 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001801 case GL_MAX_LIGHTS:
1802 *params = mCaps.maxLights;
1803 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001804 case GL_MAX_CLIP_PLANES:
1805 *params = mCaps.maxClipPlanes;
1806 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001807 // GLES1 emulation: Vertex attribute queries
1808 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1809 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1810 case GL_COLOR_ARRAY_BUFFER_BINDING:
1811 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1812 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1813 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1814 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1815 break;
1816 case GL_VERTEX_ARRAY_STRIDE:
1817 case GL_NORMAL_ARRAY_STRIDE:
1818 case GL_COLOR_ARRAY_STRIDE:
1819 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1820 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1821 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1822 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1823 break;
1824 case GL_VERTEX_ARRAY_SIZE:
1825 case GL_COLOR_ARRAY_SIZE:
1826 case GL_TEXTURE_COORD_ARRAY_SIZE:
1827 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1828 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1829 break;
1830 case GL_VERTEX_ARRAY_TYPE:
1831 case GL_COLOR_ARRAY_TYPE:
1832 case GL_NORMAL_ARRAY_TYPE:
1833 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1834 case GL_TEXTURE_COORD_ARRAY_TYPE:
1835 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1836 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1837 break;
1838
jchen1082af6202018-06-22 10:59:52 +08001839 // GL_KHR_parallel_shader_compile
1840 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1841 *params = mGLState.getMaxShaderCompilerThreads();
1842 break;
1843
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001844 // GL_EXT_blend_func_extended
1845 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1846 *params = mExtensions.maxDualSourceDrawBuffers;
1847 break;
1848
Jamie Madill231c7f52017-04-26 13:45:37 -04001849 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001850 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001851 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001852 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001853}
1854
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001855void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001856{
Shannon Woods53a94a82014-06-24 15:20:36 -04001857 // Queries about context capabilities and maximums are answered by Context.
1858 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001859 switch (pname)
1860 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001861 case GL_MAX_ELEMENT_INDEX:
1862 *params = mCaps.maxElementIndex;
1863 break;
1864 case GL_MAX_UNIFORM_BLOCK_SIZE:
1865 *params = mCaps.maxUniformBlockSize;
1866 break;
1867 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001868 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001869 break;
1870 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001871 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001872 break;
1873 case GL_MAX_SERVER_WAIT_TIMEOUT:
1874 *params = mCaps.maxServerWaitTimeout;
1875 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001876
Jamie Madill231c7f52017-04-26 13:45:37 -04001877 // GL_EXT_disjoint_timer_query
1878 case GL_TIMESTAMP_EXT:
1879 *params = mImplementation->getTimestamp();
1880 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001881
Jamie Madill231c7f52017-04-26 13:45:37 -04001882 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1883 *params = mCaps.maxShaderStorageBlockSize;
1884 break;
1885 default:
1886 UNREACHABLE();
1887 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001888 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001889}
1890
Geoff Lang70d0f492015-12-10 17:45:46 -05001891void Context::getPointerv(GLenum pname, void **params) const
1892{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001893 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001894}
1895
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001896void Context::getPointervRobustANGLERobust(GLenum pname,
1897 GLsizei bufSize,
1898 GLsizei *length,
1899 void **params)
1900{
1901 UNIMPLEMENTED();
1902}
1903
Martin Radev66fb8202016-07-28 11:45:20 +03001904void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001905{
Shannon Woods53a94a82014-06-24 15:20:36 -04001906 // Queries about context capabilities and maximums are answered by Context.
1907 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001908
1909 GLenum nativeType;
1910 unsigned int numParams;
1911 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1912 ASSERT(queryStatus);
1913
1914 if (nativeType == GL_INT)
1915 {
1916 switch (target)
1917 {
1918 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1919 ASSERT(index < 3u);
1920 *data = mCaps.maxComputeWorkGroupCount[index];
1921 break;
1922 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1923 ASSERT(index < 3u);
1924 *data = mCaps.maxComputeWorkGroupSize[index];
1925 break;
1926 default:
1927 mGLState.getIntegeri_v(target, index, data);
1928 }
1929 }
1930 else
1931 {
1932 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1933 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001934}
1935
Brandon Jones59770802018-04-02 13:18:42 -07001936void Context::getIntegeri_vRobust(GLenum target,
1937 GLuint index,
1938 GLsizei bufSize,
1939 GLsizei *length,
1940 GLint *data)
1941{
1942 getIntegeri_v(target, index, data);
1943}
1944
Martin Radev66fb8202016-07-28 11:45:20 +03001945void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001946{
Shannon Woods53a94a82014-06-24 15:20:36 -04001947 // Queries about context capabilities and maximums are answered by Context.
1948 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001949
1950 GLenum nativeType;
1951 unsigned int numParams;
1952 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1953 ASSERT(queryStatus);
1954
1955 if (nativeType == GL_INT_64_ANGLEX)
1956 {
1957 mGLState.getInteger64i_v(target, index, data);
1958 }
1959 else
1960 {
1961 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1962 }
1963}
1964
Brandon Jones59770802018-04-02 13:18:42 -07001965void Context::getInteger64i_vRobust(GLenum target,
1966 GLuint index,
1967 GLsizei bufSize,
1968 GLsizei *length,
1969 GLint64 *data)
1970{
1971 getInteger64i_v(target, index, data);
1972}
1973
Martin Radev66fb8202016-07-28 11:45:20 +03001974void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1975{
1976 // Queries about context capabilities and maximums are answered by Context.
1977 // Queries about current GL state values are answered by State.
1978
1979 GLenum nativeType;
1980 unsigned int numParams;
1981 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1982 ASSERT(queryStatus);
1983
1984 if (nativeType == GL_BOOL)
1985 {
1986 mGLState.getBooleani_v(target, index, data);
1987 }
1988 else
1989 {
1990 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1991 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001992}
1993
Brandon Jones59770802018-04-02 13:18:42 -07001994void Context::getBooleani_vRobust(GLenum target,
1995 GLuint index,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLboolean *data)
1999{
2000 getBooleani_v(target, index, data);
2001}
2002
Corentin Wallez336129f2017-10-17 15:55:40 -04002003void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Buffer *buffer = mGLState.getTargetBuffer(target);
2006 QueryBufferParameteriv(buffer, pname, params);
2007}
2008
Brandon Jones59770802018-04-02 13:18:42 -07002009void Context::getBufferParameterivRobust(BufferBinding target,
2010 GLenum pname,
2011 GLsizei bufSize,
2012 GLsizei *length,
2013 GLint *params)
2014{
2015 getBufferParameteriv(target, pname, params);
2016}
2017
He Yunchao010e4db2017-03-03 14:22:06 +08002018void Context::getFramebufferAttachmentParameteriv(GLenum target,
2019 GLenum attachment,
2020 GLenum pname,
2021 GLint *params)
2022{
2023 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002024 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002025}
2026
Brandon Jones59770802018-04-02 13:18:42 -07002027void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2028 GLenum attachment,
2029 GLenum pname,
2030 GLsizei bufSize,
2031 GLsizei *length,
2032 GLint *params)
2033{
2034 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2035}
2036
He Yunchao010e4db2017-03-03 14:22:06 +08002037void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2038{
2039 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2040 QueryRenderbufferiv(this, renderbuffer, pname, params);
2041}
2042
Brandon Jones59770802018-04-02 13:18:42 -07002043void Context::getRenderbufferParameterivRobust(GLenum target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 GLsizei *length,
2047 GLint *params)
2048{
2049 getRenderbufferParameteriv(target, pname, params);
2050}
2051
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002052void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002053{
Till Rathmannb8543632018-10-02 19:46:14 +02002054 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002055 QueryTexParameterfv(texture, pname, params);
2056}
2057
Brandon Jones59770802018-04-02 13:18:42 -07002058void Context::getTexParameterfvRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLfloat *params)
2063{
2064 getTexParameterfv(target, pname, params);
2065}
2066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002067void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002068{
Till Rathmannb8543632018-10-02 19:46:14 +02002069 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002070 QueryTexParameteriv(texture, pname, params);
2071}
Jiajia Qin5451d532017-11-16 17:16:34 +08002072
Till Rathmannb8543632018-10-02 19:46:14 +02002073void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2074{
2075 const Texture *const texture = getTargetTexture(target);
2076 QueryTexParameterIiv(texture, pname, params);
2077}
2078
2079void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2080{
2081 const Texture *const texture = getTargetTexture(target);
2082 QueryTexParameterIuiv(texture, pname, params);
2083}
2084
Brandon Jones59770802018-04-02 13:18:42 -07002085void Context::getTexParameterivRobust(TextureType target,
2086 GLenum pname,
2087 GLsizei bufSize,
2088 GLsizei *length,
2089 GLint *params)
2090{
2091 getTexParameteriv(target, pname, params);
2092}
2093
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002094void Context::getTexParameterIivRobust(TextureType target,
2095 GLenum pname,
2096 GLsizei bufSize,
2097 GLsizei *length,
2098 GLint *params)
2099{
2100 UNIMPLEMENTED();
2101}
2102
2103void Context::getTexParameterIuivRobust(TextureType target,
2104 GLenum pname,
2105 GLsizei bufSize,
2106 GLsizei *length,
2107 GLuint *params)
2108{
2109 UNIMPLEMENTED();
2110}
2111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002113{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002114 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002115 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002116}
2117
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002118void Context::getTexLevelParameterivRobust(TextureTarget target,
2119 GLint level,
2120 GLenum pname,
2121 GLsizei bufSize,
2122 GLsizei *length,
2123 GLint *params)
2124{
2125 UNIMPLEMENTED();
2126}
2127
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002128void Context::getTexLevelParameterfv(TextureTarget target,
2129 GLint level,
2130 GLenum pname,
2131 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002132{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002133 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002134 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002135}
2136
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002137void Context::getTexLevelParameterfvRobust(TextureTarget target,
2138 GLint level,
2139 GLenum pname,
2140 GLsizei bufSize,
2141 GLsizei *length,
2142 GLfloat *params)
2143{
2144 UNIMPLEMENTED();
2145}
2146
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002147void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002148{
Till Rathmannb8543632018-10-02 19:46:14 +02002149 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002150 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
Till Rathmannb8543632018-10-02 19:46:14 +02002155 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002157}
2158
Brandon Jones59770802018-04-02 13:18:42 -07002159void Context::texParameterfvRobust(TextureType target,
2160 GLenum pname,
2161 GLsizei bufSize,
2162 const GLfloat *params)
2163{
2164 texParameterfv(target, pname, params);
2165}
2166
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002167void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002168{
Till Rathmannb8543632018-10-02 19:46:14 +02002169 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002170 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002171}
2172
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002173void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002174{
Till Rathmannb8543632018-10-02 19:46:14 +02002175 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002176 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002177}
2178
Till Rathmannb8543632018-10-02 19:46:14 +02002179void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2180{
2181 Texture *const texture = getTargetTexture(target);
2182 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002183}
2184
2185void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2186{
2187 Texture *const texture = getTargetTexture(target);
2188 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002189}
2190
Brandon Jones59770802018-04-02 13:18:42 -07002191void Context::texParameterivRobust(TextureType target,
2192 GLenum pname,
2193 GLsizei bufSize,
2194 const GLint *params)
2195{
2196 texParameteriv(target, pname, params);
2197}
2198
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002199void Context::texParameterIivRobust(TextureType target,
2200 GLenum pname,
2201 GLsizei bufSize,
2202 const GLint *params)
2203{
2204 UNIMPLEMENTED();
2205}
2206
2207void Context::texParameterIuivRobust(TextureType target,
2208 GLenum pname,
2209 GLsizei bufSize,
2210 const GLuint *params)
2211{
2212 UNIMPLEMENTED();
2213}
2214
Jamie Madill493f9572018-05-24 19:52:15 -04002215void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002217 // No-op if count draws no primitives for given mode
2218 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002219 {
2220 return;
2221 }
2222
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002223 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002224 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002225 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226}
2227
Jamie Madill493f9572018-05-24 19:52:15 -04002228void Context::drawArraysInstanced(PrimitiveMode mode,
2229 GLint first,
2230 GLsizei count,
2231 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002232{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002233 // No-op if count draws no primitives for given mode
2234 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002235 {
2236 return;
2237 }
2238
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002239 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002240 ANGLE_CONTEXT_TRY(
2241 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002242 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2243 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002244}
2245
Jamie Madill8dc27f92018-11-29 11:45:44 -05002246void Context::drawElements(PrimitiveMode mode,
2247 GLsizei count,
2248 DrawElementsType type,
2249 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002251 // No-op if count draws no primitives for given mode
2252 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002253 {
2254 return;
2255 }
2256
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002257 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002258 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002259}
2260
Jamie Madill493f9572018-05-24 19:52:15 -04002261void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002262 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002263 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002264 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002265 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002266{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002267 // No-op if count draws no primitives for given mode
2268 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002269 {
2270 return;
2271 }
2272
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002273 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002274 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002275 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002276}
2277
Jamie Madill493f9572018-05-24 19:52:15 -04002278void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002279 GLuint start,
2280 GLuint end,
2281 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002282 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002283 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002284{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002285 // No-op if count draws no primitives for given mode
2286 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002287 {
2288 return;
2289 }
2290
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002291 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002292 ANGLE_CONTEXT_TRY(
2293 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002294}
2295
Jamie Madill493f9572018-05-24 19:52:15 -04002296void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002297{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002298 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002299 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002300}
2301
Jamie Madill8dc27f92018-11-29 11:45:44 -05002302void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002303{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002304 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002305 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002306}
2307
Jamie Madill675fe712016-12-19 13:07:54 -05002308void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002309{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002310 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002311}
2312
Jamie Madill675fe712016-12-19 13:07:54 -05002313void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002314{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002315 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002316}
2317
Austin Kinross6ee1e782015-05-29 17:05:37 -07002318void Context::insertEventMarker(GLsizei length, const char *marker)
2319{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002320 ASSERT(mImplementation);
2321 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002322}
2323
2324void Context::pushGroupMarker(GLsizei length, const char *marker)
2325{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002326 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002327
2328 if (marker == nullptr)
2329 {
2330 // From the EXT_debug_marker spec,
2331 // "If <marker> is null then an empty string is pushed on the stack."
2332 mImplementation->pushGroupMarker(length, "");
2333 }
2334 else
2335 {
2336 mImplementation->pushGroupMarker(length, marker);
2337 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002338}
2339
2340void Context::popGroupMarker()
2341{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002342 ASSERT(mImplementation);
2343 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002344}
2345
Geoff Langd8605522016-04-13 10:19:12 -04002346void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2347{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002348 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002349 ASSERT(programObject);
2350
2351 programObject->bindUniformLocation(location, name);
2352}
2353
Brandon Jones59770802018-04-02 13:18:42 -07002354void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002355{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002356 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002357}
2358
Brandon Jones59770802018-04-02 13:18:42 -07002359void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360{
2361 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2362}
2363
Brandon Jones59770802018-04-02 13:18:42 -07002364void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365{
2366 GLfloat I[16];
2367 angle::Matrix<GLfloat>::setToIdentity(I);
2368
2369 mGLState.loadPathRenderingMatrix(matrixMode, I);
2370}
2371
2372void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2373{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002374 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002375 if (!pathObj)
2376 return;
2377
Geoff Lang9bf86f02018-07-26 11:46:34 -04002378 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002379
2380 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2381}
2382
2383void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2384{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002385 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002386 if (!pathObj)
2387 return;
2388
Geoff Lang9bf86f02018-07-26 11:46:34 -04002389 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002390
2391 mImplementation->stencilStrokePath(pathObj, reference, mask);
2392}
2393
2394void Context::coverFillPath(GLuint path, GLenum coverMode)
2395{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002396 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002397 if (!pathObj)
2398 return;
2399
Geoff Lang9bf86f02018-07-26 11:46:34 -04002400 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002401
2402 mImplementation->coverFillPath(pathObj, coverMode);
2403}
2404
2405void Context::coverStrokePath(GLuint path, GLenum coverMode)
2406{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002407 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408 if (!pathObj)
2409 return;
2410
Geoff Lang9bf86f02018-07-26 11:46:34 -04002411 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002412
2413 mImplementation->coverStrokePath(pathObj, coverMode);
2414}
2415
2416void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2417{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002418 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002419 if (!pathObj)
2420 return;
2421
Geoff Lang9bf86f02018-07-26 11:46:34 -04002422 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002423
2424 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2425}
2426
2427void Context::stencilThenCoverStrokePath(GLuint path,
2428 GLint reference,
2429 GLuint mask,
2430 GLenum coverMode)
2431{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002432 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002433 if (!pathObj)
2434 return;
2435
Geoff Lang9bf86f02018-07-26 11:46:34 -04002436 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002437
2438 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2439}
2440
Sami Väisänend59ca052016-06-21 16:10:00 +03002441void Context::coverFillPathInstanced(GLsizei numPaths,
2442 GLenum pathNameType,
2443 const void *paths,
2444 GLuint pathBase,
2445 GLenum coverMode,
2446 GLenum transformType,
2447 const GLfloat *transformValues)
2448{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
Geoff Lang9bf86f02018-07-26 11:46:34 -04002451 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
2453 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2454}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002455
Sami Väisänend59ca052016-06-21 16:10:00 +03002456void Context::coverStrokePathInstanced(GLsizei numPaths,
2457 GLenum pathNameType,
2458 const void *paths,
2459 GLuint pathBase,
2460 GLenum coverMode,
2461 GLenum transformType,
2462 const GLfloat *transformValues)
2463{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002464 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
2466 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002467 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
2469 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2470 transformValues);
2471}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002472
Sami Väisänend59ca052016-06-21 16:10:00 +03002473void Context::stencilFillPathInstanced(GLsizei numPaths,
2474 GLenum pathNameType,
2475 const void *paths,
2476 GLuint pathBase,
2477 GLenum fillMode,
2478 GLuint mask,
2479 GLenum transformType,
2480 const GLfloat *transformValues)
2481{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002482 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002483
2484 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002485 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002486
2487 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2488 transformValues);
2489}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002490
Sami Väisänend59ca052016-06-21 16:10:00 +03002491void Context::stencilStrokePathInstanced(GLsizei numPaths,
2492 GLenum pathNameType,
2493 const void *paths,
2494 GLuint pathBase,
2495 GLint reference,
2496 GLuint mask,
2497 GLenum transformType,
2498 const GLfloat *transformValues)
2499{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002500 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002501
Geoff Lang9bf86f02018-07-26 11:46:34 -04002502 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002503
2504 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2505 transformValues);
2506}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002507
Sami Väisänend59ca052016-06-21 16:10:00 +03002508void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2509 GLenum pathNameType,
2510 const void *paths,
2511 GLuint pathBase,
2512 GLenum fillMode,
2513 GLuint mask,
2514 GLenum coverMode,
2515 GLenum transformType,
2516 const GLfloat *transformValues)
2517{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002518 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002519
Geoff Lang9bf86f02018-07-26 11:46:34 -04002520 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002521
2522 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2523 transformType, transformValues);
2524}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002525
Sami Väisänend59ca052016-06-21 16:10:00 +03002526void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2527 GLenum pathNameType,
2528 const void *paths,
2529 GLuint pathBase,
2530 GLint reference,
2531 GLuint mask,
2532 GLenum coverMode,
2533 GLenum transformType,
2534 const GLfloat *transformValues)
2535{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002536 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002537
Geoff Lang9bf86f02018-07-26 11:46:34 -04002538 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002539
2540 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2541 transformType, transformValues);
2542}
2543
Sami Väisänen46eaa942016-06-29 10:26:37 +03002544void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002546 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002547
2548 programObject->bindFragmentInputLocation(location, name);
2549}
2550
2551void Context::programPathFragmentInputGen(GLuint program,
2552 GLint location,
2553 GLenum genMode,
2554 GLint components,
2555 const GLfloat *coeffs)
2556{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002557 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002558
jchen103fd614d2018-08-13 12:21:58 +08002559 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002560}
2561
jchen1015015f72017-03-16 13:54:21 +08002562GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2563{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002564 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002565 return QueryProgramResourceIndex(programObject, programInterface, name);
2566}
2567
jchen10fd7c3b52017-03-21 15:36:03 +08002568void Context::getProgramResourceName(GLuint program,
2569 GLenum programInterface,
2570 GLuint index,
2571 GLsizei bufSize,
2572 GLsizei *length,
2573 GLchar *name)
2574{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002575 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002576 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2577}
2578
jchen10191381f2017-04-11 13:59:04 +08002579GLint Context::getProgramResourceLocation(GLuint program,
2580 GLenum programInterface,
2581 const GLchar *name)
2582{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002583 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002584 return QueryProgramResourceLocation(programObject, programInterface, name);
2585}
2586
jchen10880683b2017-04-12 16:21:55 +08002587void Context::getProgramResourceiv(GLuint program,
2588 GLenum programInterface,
2589 GLuint index,
2590 GLsizei propCount,
2591 const GLenum *props,
2592 GLsizei bufSize,
2593 GLsizei *length,
2594 GLint *params)
2595{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002596 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002597 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2598 length, params);
2599}
2600
jchen10d9cd7b72017-08-30 15:04:25 +08002601void Context::getProgramInterfaceiv(GLuint program,
2602 GLenum programInterface,
2603 GLenum pname,
2604 GLint *params)
2605{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002606 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002607 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2608}
2609
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002610void Context::getProgramInterfaceivRobust(GLuint program,
2611 GLenum programInterface,
2612 GLenum pname,
2613 GLsizei bufSize,
2614 GLsizei *length,
2615 GLint *params)
2616{
2617 UNIMPLEMENTED();
2618}
2619
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002620void Context::handleError(GLenum errorCode,
2621 const char *message,
2622 const char *file,
2623 const char *function,
2624 unsigned int line)
2625{
2626 mErrors.handleError(errorCode, message, file, function, line);
2627}
2628
Jamie Madilla139f012018-10-10 16:13:03 -04002629void Context::validationError(GLenum errorCode, const char *message)
2630{
2631 mErrors.validationError(errorCode, message);
2632}
2633
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002634// Get one of the recorded errors and clear its flag, if any.
2635// [OpenGL ES 2.0.24] section 2.5 page 13.
2636GLenum Context::getError()
2637{
Geoff Langda5777c2014-07-11 09:52:58 -04002638 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639 {
Geoff Langda5777c2014-07-11 09:52:58 -04002640 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641 }
Geoff Langda5777c2014-07-11 09:52:58 -04002642 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002644 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646}
2647
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002649void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650{
2651 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002652 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002653 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002654 mContextLostForced = true;
2655 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002656 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657}
2658
Jamie Madillfa920eb2018-01-04 11:45:50 -05002659GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002661 // Even if the application doesn't want to know about resets, we want to know
2662 // as it will allow us to skip all the calls.
2663 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002668 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002669
2670 // EXT_robustness, section 2.6: If the reset notification behavior is
2671 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2672 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2673 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002674 }
2675
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2677 // status should be returned at least once, and GL_NO_ERROR should be returned
2678 // once the device has finished resetting.
2679 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002680 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002681 ASSERT(mResetStatus == GL_NO_ERROR);
2682 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002683
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002684 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002685 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002686 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002687 }
2688 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002689 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002690 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002691 // If markContextLost was used to mark the context lost then
2692 // assume that is not recoverable, and continue to report the
2693 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002694 mResetStatus = mImplementation->getResetStatus();
2695 }
Jamie Madill893ab082014-05-16 16:56:10 -04002696
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002697 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002698}
2699
2700bool Context::isResetNotificationEnabled()
2701{
2702 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2703}
2704
Corentin Walleze3b10e82015-05-20 11:06:25 -04002705const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002706{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002707 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002708}
2709
2710EGLenum Context::getClientType() const
2711{
2712 return mClientType;
2713}
2714
2715EGLenum Context::getRenderBuffer() const
2716{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002717 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2718 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002719 {
2720 return EGL_NONE;
2721 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002722
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002723 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002724 ASSERT(backAttachment != nullptr);
2725 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002726}
2727
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002728VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002729{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002730 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002731 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2732 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002733 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002734 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2735 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002736
Jamie Madill96a483b2017-06-27 16:49:21 -04002737 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002738 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002739
2740 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002741}
2742
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002743TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002744{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002745 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002746 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2747 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002748 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002749 transformFeedback =
2750 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002751 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002752 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002753 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002754
2755 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002756}
2757
2758bool Context::isVertexArrayGenerated(GLuint vertexArray)
2759{
Jamie Madill96a483b2017-06-27 16:49:21 -04002760 ASSERT(mVertexArrayMap.contains(0));
2761 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002762}
2763
2764bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2765{
Jamie Madill96a483b2017-06-27 16:49:21 -04002766 ASSERT(mTransformFeedbackMap.contains(0));
2767 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002768}
2769
Shannon Woods53a94a82014-06-24 15:20:36 -04002770void Context::detachTexture(GLuint texture)
2771{
2772 // Simple pass-through to State's detachTexture method, as textures do not require
2773 // allocation map management either here or in the resource manager at detach time.
2774 // Zero textures are held by the Context, and we don't attempt to request them from
2775 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002776 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002777}
2778
James Darpinian4d9d4832018-03-13 12:43:28 -07002779void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002780{
Yuly Novikov5807a532015-12-03 13:01:22 -05002781 // Simple pass-through to State's detachBuffer method, since
2782 // only buffer attachments to container objects that are bound to the current context
2783 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002784
Yuly Novikov5807a532015-12-03 13:01:22 -05002785 // [OpenGL ES 3.2] section 5.1.2 page 45:
2786 // Attachments to unbound container objects, such as
2787 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2788 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002789 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790}
2791
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002792void Context::detachFramebuffer(GLuint framebuffer)
2793{
Shannon Woods53a94a82014-06-24 15:20:36 -04002794 // Framebuffer detachment is handled by Context, because 0 is a valid
2795 // Framebuffer object, and a pointer to it must be passed from Context
2796 // to State at binding time.
2797
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002799 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2800 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2801 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002802
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002803 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002804 {
2805 bindReadFramebuffer(0);
2806 }
2807
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002808 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002809 {
2810 bindDrawFramebuffer(0);
2811 }
2812}
2813
2814void Context::detachRenderbuffer(GLuint renderbuffer)
2815{
Jamie Madilla02315b2017-02-23 14:14:47 -05002816 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002817}
2818
Jamie Madill57a89722013-07-02 11:57:03 -04002819void Context::detachVertexArray(GLuint vertexArray)
2820{
Jamie Madill77a72f62015-04-14 11:18:32 -04002821 // Vertex array detachment is handled by Context, because 0 is a valid
2822 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002823 // binding time.
2824
Jamie Madill57a89722013-07-02 11:57:03 -04002825 // [OpenGL ES 3.0.2] section 2.10 page 43:
2826 // If a vertex array object that is currently bound is deleted, the binding
2827 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002828 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002829 {
2830 bindVertexArray(0);
2831 }
2832}
2833
Geoff Langc8058452014-02-03 12:04:11 -05002834void Context::detachTransformFeedback(GLuint transformFeedback)
2835{
Corentin Walleza2257da2016-04-19 16:43:12 -04002836 // Transform feedback detachment is handled by Context, because 0 is a valid
2837 // transform feedback, and a pointer to it must be passed from Context to State at
2838 // binding time.
2839
2840 // The OpenGL specification doesn't mention what should happen when the currently bound
2841 // transform feedback object is deleted. Since it is a container object, we treat it like
2842 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002843 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002844 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002845 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002846 }
Geoff Langc8058452014-02-03 12:04:11 -05002847}
2848
Jamie Madilldc356042013-07-19 16:36:57 -04002849void Context::detachSampler(GLuint sampler)
2850{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002851 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002852}
2853
Yunchao Hea336b902017-08-02 16:05:21 +08002854void Context::detachProgramPipeline(GLuint pipeline)
2855{
2856 mGLState.detachProgramPipeline(this, pipeline);
2857}
2858
Jamie Madill3ef140a2017-08-26 23:11:21 -04002859void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002860{
Shaodde78e82017-05-22 14:13:27 +08002861 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002862 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002863}
2864
Jamie Madille29d1672013-07-19 16:36:57 -04002865void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2866{
Till Rathmannb8543632018-10-02 19:46:14 +02002867 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002868 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002869 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002870}
Jamie Madille29d1672013-07-19 16:36:57 -04002871
Geoff Langc1984ed2016-10-07 12:41:00 -04002872void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2873{
Till Rathmannb8543632018-10-02 19:46:14 +02002874 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002875 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002876 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002877}
2878
Till Rathmannb8543632018-10-02 19:46:14 +02002879void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2880{
2881 Sampler *const samplerObject =
2882 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2883 SetSamplerParameterIiv(this, samplerObject, pname, param);
2884}
2885
2886void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2887{
2888 Sampler *const samplerObject =
2889 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2890 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2891}
2892
Brandon Jones59770802018-04-02 13:18:42 -07002893void Context::samplerParameterivRobust(GLuint sampler,
2894 GLenum pname,
2895 GLsizei bufSize,
2896 const GLint *param)
2897{
2898 samplerParameteriv(sampler, pname, param);
2899}
2900
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002901void Context::samplerParameterIivRobust(GLuint sampler,
2902 GLenum pname,
2903 GLsizei bufSize,
2904 const GLint *param)
2905{
2906 UNIMPLEMENTED();
2907}
2908
2909void Context::samplerParameterIuivRobust(GLuint sampler,
2910 GLenum pname,
2911 GLsizei bufSize,
2912 const GLuint *param)
2913{
2914 UNIMPLEMENTED();
2915}
2916
Jamie Madille29d1672013-07-19 16:36:57 -04002917void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2918{
Till Rathmannb8543632018-10-02 19:46:14 +02002919 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002920 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002921 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002922}
2923
Geoff Langc1984ed2016-10-07 12:41:00 -04002924void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002925{
Till Rathmannb8543632018-10-02 19:46:14 +02002926 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002927 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002928 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002929}
2930
Brandon Jones59770802018-04-02 13:18:42 -07002931void Context::samplerParameterfvRobust(GLuint sampler,
2932 GLenum pname,
2933 GLsizei bufSize,
2934 const GLfloat *param)
2935{
2936 samplerParameterfv(sampler, pname, param);
2937}
2938
Geoff Langc1984ed2016-10-07 12:41:00 -04002939void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002940{
Till Rathmannb8543632018-10-02 19:46:14 +02002941 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002942 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002943 QuerySamplerParameteriv(samplerObject, pname, params);
2944}
Jamie Madill9675b802013-07-19 16:36:59 -04002945
Till Rathmannb8543632018-10-02 19:46:14 +02002946void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2947{
2948 const Sampler *const samplerObject =
2949 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2950 QuerySamplerParameterIiv(samplerObject, pname, params);
2951}
2952
2953void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2954{
2955 const Sampler *const samplerObject =
2956 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2957 QuerySamplerParameterIuiv(samplerObject, pname, params);
2958}
2959
Brandon Jones59770802018-04-02 13:18:42 -07002960void Context::getSamplerParameterivRobust(GLuint sampler,
2961 GLenum pname,
2962 GLsizei bufSize,
2963 GLsizei *length,
2964 GLint *params)
2965{
2966 getSamplerParameteriv(sampler, pname, params);
2967}
2968
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002969void Context::getSamplerParameterIivRobust(GLuint sampler,
2970 GLenum pname,
2971 GLsizei bufSize,
2972 GLsizei *length,
2973 GLint *params)
2974{
2975 UNIMPLEMENTED();
2976}
2977
2978void Context::getSamplerParameterIuivRobust(GLuint sampler,
2979 GLenum pname,
2980 GLsizei bufSize,
2981 GLsizei *length,
2982 GLuint *params)
2983{
2984 UNIMPLEMENTED();
2985}
2986
Geoff Langc1984ed2016-10-07 12:41:00 -04002987void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2988{
Till Rathmannb8543632018-10-02 19:46:14 +02002989 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002990 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002991 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002992}
2993
Brandon Jones59770802018-04-02 13:18:42 -07002994void Context::getSamplerParameterfvRobust(GLuint sampler,
2995 GLenum pname,
2996 GLsizei bufSize,
2997 GLsizei *length,
2998 GLfloat *params)
2999{
3000 getSamplerParameterfv(sampler, pname, params);
3001}
3002
Olli Etuahof0fee072016-03-30 15:11:58 +03003003void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3004{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003005 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003006 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003007}
3008
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003009void Context::initRendererString()
3010{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003011 std::ostringstream rendererString;
3012 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003013 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003014 rendererString << ")";
3015
Geoff Langcec35902014-04-16 10:52:36 -04003016 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003017}
3018
Geoff Langc339c4e2016-11-29 10:37:36 -05003019void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003020{
Geoff Langc339c4e2016-11-29 10:37:36 -05003021 const Version &clientVersion = getClientVersion();
3022
3023 std::ostringstream versionString;
3024 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3025 << ANGLE_VERSION_STRING << ")";
3026 mVersionString = MakeStaticString(versionString.str());
3027
3028 std::ostringstream shadingLanguageVersionString;
3029 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3030 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3031 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3032 << ")";
3033 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003034}
3035
Geoff Langcec35902014-04-16 10:52:36 -04003036void Context::initExtensionStrings()
3037{
Geoff Langc339c4e2016-11-29 10:37:36 -05003038 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3039 std::ostringstream combinedStringStream;
3040 std::copy(strings.begin(), strings.end(),
3041 std::ostream_iterator<const char *>(combinedStringStream, " "));
3042 return MakeStaticString(combinedStringStream.str());
3043 };
3044
3045 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003046 for (const auto &extensionString : mExtensions.getStrings())
3047 {
3048 mExtensionStrings.push_back(MakeStaticString(extensionString));
3049 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003050 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003051
Geoff Langc339c4e2016-11-29 10:37:36 -05003052 mRequestableExtensionStrings.clear();
3053 for (const auto &extensionInfo : GetExtensionInfoMap())
3054 {
3055 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003056 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003057 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003058 {
3059 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3060 }
3061 }
3062 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003063}
3064
Geoff Langc339c4e2016-11-29 10:37:36 -05003065const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003066{
Geoff Langc339c4e2016-11-29 10:37:36 -05003067 switch (name)
3068 {
3069 case GL_VENDOR:
3070 return reinterpret_cast<const GLubyte *>("Google Inc.");
3071
3072 case GL_RENDERER:
3073 return reinterpret_cast<const GLubyte *>(mRendererString);
3074
3075 case GL_VERSION:
3076 return reinterpret_cast<const GLubyte *>(mVersionString);
3077
3078 case GL_SHADING_LANGUAGE_VERSION:
3079 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3080
3081 case GL_EXTENSIONS:
3082 return reinterpret_cast<const GLubyte *>(mExtensionString);
3083
3084 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3085 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3086
3087 default:
3088 UNREACHABLE();
3089 return nullptr;
3090 }
Geoff Langcec35902014-04-16 10:52:36 -04003091}
3092
Geoff Langc339c4e2016-11-29 10:37:36 -05003093const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003094{
Geoff Langc339c4e2016-11-29 10:37:36 -05003095 switch (name)
3096 {
3097 case GL_EXTENSIONS:
3098 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3099
3100 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3101 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3102
3103 default:
3104 UNREACHABLE();
3105 return nullptr;
3106 }
Geoff Langcec35902014-04-16 10:52:36 -04003107}
3108
3109size_t Context::getExtensionStringCount() const
3110{
3111 return mExtensionStrings.size();
3112}
3113
Geoff Lang111a99e2017-10-17 10:58:41 -04003114bool Context::isExtensionRequestable(const char *name)
3115{
3116 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3117 auto extension = extensionInfos.find(name);
3118
Geoff Lang111a99e2017-10-17 10:58:41 -04003119 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003120 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003121}
3122
Geoff Langc339c4e2016-11-29 10:37:36 -05003123void Context::requestExtension(const char *name)
3124{
3125 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3126 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3127 const auto &extension = extensionInfos.at(name);
3128 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003129 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003130
3131 if (mExtensions.*(extension.ExtensionsMember))
3132 {
3133 // Extension already enabled
3134 return;
3135 }
3136
3137 mExtensions.*(extension.ExtensionsMember) = true;
3138 updateCaps();
3139 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003140
Jamie Madill2f348d22017-06-05 10:50:59 -04003141 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3142 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003143
Jamie Madill81c2e252017-09-09 23:32:46 -04003144 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3145 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003146 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003147 for (auto &zeroTexture : mZeroTextures)
3148 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003149 if (zeroTexture.get() != nullptr)
3150 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003151 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003152 }
Geoff Lang9aded172017-04-05 11:07:56 -04003153 }
3154
Jamie Madillb983a4b2018-08-01 11:34:51 -04003155 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003156}
3157
3158size_t Context::getRequestableExtensionStringCount() const
3159{
3160 return mRequestableExtensionStrings.size();
3161}
3162
Jamie Madill493f9572018-05-24 19:52:15 -04003163void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003164{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003165 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003166 ASSERT(transformFeedback != nullptr);
3167 ASSERT(!transformFeedback->isPaused());
3168
Jamie Madill6c1f6712017-02-14 19:08:04 -05003169 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003170 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003171}
3172
3173bool Context::hasActiveTransformFeedback(GLuint program) const
3174{
3175 for (auto pair : mTransformFeedbackMap)
3176 {
3177 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3178 {
3179 return true;
3180 }
3181 }
3182 return false;
3183}
3184
Geoff Lang33f11fb2018-05-07 13:42:47 -04003185Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003186{
3187 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3188
jchen1082af6202018-06-22 10:59:52 +08003189 // Explicitly enable GL_KHR_parallel_shader_compile
3190 supportedExtensions.parallelShaderCompile = true;
3191
Geoff Langb0f917f2017-12-05 13:41:54 -05003192 if (getClientVersion() < ES_2_0)
3193 {
3194 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003195 supportedExtensions.pointSizeArray = true;
3196 supportedExtensions.textureCubeMap = true;
3197 supportedExtensions.pointSprite = true;
3198 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003199 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003200 }
3201
3202 if (getClientVersion() < ES_3_0)
3203 {
3204 // Disable ES3+ extensions
3205 supportedExtensions.colorBufferFloat = false;
3206 supportedExtensions.eglImageExternalEssl3 = false;
3207 supportedExtensions.textureNorm16 = false;
3208 supportedExtensions.multiview = false;
3209 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003210 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003211 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003212
3213 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3214 if (!supportedExtensions.sRGB)
3215 {
3216 supportedExtensions.textureSRGBDecode = false;
3217 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003218 }
3219
3220 if (getClientVersion() < ES_3_1)
3221 {
3222 // Disable ES3.1+ extensions
3223 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003224
3225 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3226 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003227 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003228 }
3229
3230 if (getClientVersion() > ES_2_0)
3231 {
3232 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3233 // supportedExtensions.sRGB = false;
3234 }
3235
3236 // Some extensions are always available because they are implemented in the GL layer.
3237 supportedExtensions.bindUniformLocation = true;
3238 supportedExtensions.vertexArrayObject = true;
3239 supportedExtensions.bindGeneratesResource = true;
3240 supportedExtensions.clientArrays = true;
3241 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003242 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003243
3244 // Enable the no error extension if the context was created with the flag.
3245 supportedExtensions.noError = mSkipValidation;
3246
3247 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003248 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003249
3250 // Explicitly enable GL_KHR_debug
3251 supportedExtensions.debug = true;
3252 supportedExtensions.maxDebugMessageLength = 1024;
3253 supportedExtensions.maxDebugLoggedMessages = 1024;
3254 supportedExtensions.maxDebugGroupStackDepth = 1024;
3255 supportedExtensions.maxLabelLength = 1024;
3256
3257 // Explicitly enable GL_ANGLE_robust_client_memory
3258 supportedExtensions.robustClientMemory = true;
3259
3260 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003261 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003262
3263 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3264 // supports it.
3265 supportedExtensions.robustBufferAccessBehavior =
3266 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3267
3268 // Enable the cache control query unconditionally.
3269 supportedExtensions.programCacheControl = true;
3270
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003271 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003272 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003273 {
3274 // GL_ANGLE_explicit_context_gles1
3275 supportedExtensions.explicitContextGles1 = true;
3276 // GL_ANGLE_explicit_context
3277 supportedExtensions.explicitContext = true;
3278 }
3279
Geoff Lang79b91402018-10-04 15:11:30 -04003280 supportedExtensions.memorySize = true;
3281
Geoff Langb0f917f2017-12-05 13:41:54 -05003282 return supportedExtensions;
3283}
3284
Geoff Lang33f11fb2018-05-07 13:42:47 -04003285void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003286{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003287 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003288
Geoff Lang33f11fb2018-05-07 13:42:47 -04003289 mSupportedExtensions = generateSupportedExtensions();
3290 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003291
3292 mLimitations = mImplementation->getNativeLimitations();
3293
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003294 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3295 if (getClientVersion() < Version(2, 0))
3296 {
3297 mCaps.maxMultitextureUnits = 4;
3298 mCaps.maxClipPlanes = 6;
3299 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003300 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3301 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3302 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003303 mCaps.minSmoothPointSize = 1.0f;
3304 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003305 mCaps.minSmoothLineWidth = 1.0f;
3306 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003307 }
3308
Luc Ferronad2ae932018-06-11 15:31:17 -04003309 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003310 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003311
Luc Ferronad2ae932018-06-11 15:31:17 -04003312 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3313
Jamie Madill0f80ed82017-09-19 00:24:56 -04003314 if (getClientVersion() < ES_3_1)
3315 {
3316 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3317 }
3318 else
3319 {
3320 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3321 }
Geoff Lang301d1612014-07-09 10:34:37 -04003322
Jiawei Shao54aafe52018-04-27 14:54:57 +08003323 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3324 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003325 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3326
Jamie Madill0f80ed82017-09-19 00:24:56 -04003327 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3328 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3329
3330 // Limit textures as well, so we can use fast bitsets with texture bindings.
3331 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003332 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3333 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3334 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3335 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003336
Jamie Madille3e680c2018-12-03 17:49:08 -05003337 LimitCap(&mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
3338
Jiawei Shaodb342272017-09-27 10:21:45 +08003339 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3340
Geoff Langc287ea62016-09-16 14:46:51 -04003341 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003342 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003343 for (const auto &extensionInfo : GetExtensionInfoMap())
3344 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003345 // If the user has requested that extensions start disabled and they are requestable,
3346 // disable them.
3347 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003348 {
3349 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3350 }
3351 }
3352
3353 // Generate texture caps
3354 updateCaps();
3355}
3356
3357void Context::updateCaps()
3358{
Geoff Lang900013c2014-07-07 11:32:19 -04003359 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003360 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003361
Jamie Madill7b62cf92017-11-02 15:20:49 -04003362 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003363 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003364 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003365 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003366
Geoff Lang0d8b7242015-09-09 14:56:53 -04003367 // Update the format caps based on the client version and extensions.
3368 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3369 // ES3.
3370 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003371 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003372 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003373 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003374 formatCaps.textureAttachment =
3375 formatCaps.textureAttachment &&
3376 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3377 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3378 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003379
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003380 // OpenGL ES does not support multisampling with non-rendererable formats
3381 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003382 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003383 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003384 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003385 {
Geoff Langd87878e2014-09-19 15:42:59 -04003386 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003387 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003388 else
3389 {
3390 // We may have limited the max samples for some required renderbuffer formats due to
3391 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3392 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3393
3394 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3395 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3396 // exception of signed and unsigned integer formats."
3397 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3398 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3399 {
3400 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3401 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3402 }
3403
3404 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003405 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003406 {
3407 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3408 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3409 // the exception that the signed and unsigned integer formats are required only to
3410 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3411 // multisamples, which must be at least one."
3412 if (formatInfo.componentType == GL_INT ||
3413 formatInfo.componentType == GL_UNSIGNED_INT)
3414 {
3415 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3416 }
3417
3418 // GLES 3.1 section 19.3.1.
3419 if (formatCaps.texturable)
3420 {
3421 if (formatInfo.depthBits > 0)
3422 {
3423 mCaps.maxDepthTextureSamples =
3424 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3425 }
3426 else if (formatInfo.redBits > 0)
3427 {
3428 mCaps.maxColorTextureSamples =
3429 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3430 }
3431 }
3432 }
3433 }
Geoff Langd87878e2014-09-19 15:42:59 -04003434
3435 if (formatCaps.texturable && formatInfo.compressed)
3436 {
Geoff Langca271392017-04-05 12:30:00 -04003437 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003438 }
3439
Geoff Langca271392017-04-05 12:30:00 -04003440 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003441 }
Jamie Madill32447362017-06-28 14:53:52 -04003442
3443 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003444 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003445 {
3446 mMemoryProgramCache = nullptr;
3447 }
Corentin Walleze4477002017-12-01 14:39:58 -05003448
3449 // Compute which buffer types are allowed
3450 mValidBufferBindings.reset();
3451 mValidBufferBindings.set(BufferBinding::ElementArray);
3452 mValidBufferBindings.set(BufferBinding::Array);
3453
3454 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3455 {
3456 mValidBufferBindings.set(BufferBinding::PixelPack);
3457 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3458 }
3459
3460 if (getClientVersion() >= ES_3_0)
3461 {
3462 mValidBufferBindings.set(BufferBinding::CopyRead);
3463 mValidBufferBindings.set(BufferBinding::CopyWrite);
3464 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3465 mValidBufferBindings.set(BufferBinding::Uniform);
3466 }
3467
3468 if (getClientVersion() >= ES_3_1)
3469 {
3470 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3471 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3472 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3473 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3474 }
jchen107ae70d82018-07-06 13:47:01 +08003475
3476 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003477
Jamie Madillef9fcd92018-11-28 14:03:59 -05003478 // Reinitialize some dirty bits that depend on extensions.
3479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS,
3480 mGLState.isRobustResourceInitEnabled());
3481 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS,
3482 mGLState.isRobustResourceInitEnabled());
3483
Jamie Madillac66f982018-10-09 18:30:01 -04003484 // Reinitialize state cache after extension changes.
3485 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003486}
3487
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003488void Context::initWorkarounds()
3489{
Jamie Madill761b02c2017-06-23 16:27:06 -04003490 // Apply back-end workarounds.
3491 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3492
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003493 // Lose the context upon out of memory error if the application is
3494 // expecting to watch for those events.
3495 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003496
3497 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3498 {
3499 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3500 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3501 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3502 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003503}
3504
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003505// Return true if the draw is a no-op, else return false.
3506// A no-op draw occurs if the count of vertices is less than the minimum required to
3507// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3508bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3509{
3510 return count < kMinimumPrimitiveCounts[mode];
3511}
3512
3513bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3514{
3515 return (instanceCount == 0) || noopDraw(mode, count);
3516}
3517
Jamie Madill6f755b22018-10-09 12:48:54 -04003518angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003519{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003520 if (mGLES1Renderer)
3521 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003522 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003523 }
3524
Geoff Lang9bf86f02018-07-26 11:46:34 -04003525 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003526
3527 if (isRobustResourceInitEnabled())
3528 {
3529 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
Jamie Madillef9fcd92018-11-28 14:03:59 -05003530 ASSERT(!mGLState.getDrawFramebuffer()->hasResourceThatNeedsInit());
Jamie Madilla59fc192017-11-02 12:57:58 -04003531 }
3532
Jamie Madill9e63a812018-11-16 12:30:04 +00003533 ANGLE_TRY(syncDirtyBits());
3534 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003535}
3536
Jamie Madill526392d2018-11-16 09:35:14 -05003537angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003538{
Geoff Langa8cb2872018-03-09 16:09:40 -05003539 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003540 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003541 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003542 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003543}
3544
Jamie Madill526392d2018-11-16 09:35:14 -05003545angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003546{
Geoff Langa8cb2872018-03-09 16:09:40 -05003547 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003548 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3549 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003550 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003551 return angle::Result::Continue();
Jamie Madill05b35b22017-10-03 09:01:44 -04003552}
3553
Jamie Madill526392d2018-11-16 09:35:14 -05003554angle::Result Context::syncState(const State::DirtyBits &bitMask,
3555 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003556{
Geoff Langa8cb2872018-03-09 16:09:40 -05003557 ANGLE_TRY(syncDirtyObjects(objectMask));
3558 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill526392d2018-11-16 09:35:14 -05003559 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003560}
3561
Jamie Madill9e63a812018-11-16 12:30:04 +00003562angle::Result Context::syncDirtyBits()
3563{
3564 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3565 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3566 mGLState.clearDirtyBits();
3567 return angle::Result::Continue();
3568}
3569
3570angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3571{
3572 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3573 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3574 mGLState.clearDirtyBits(dirtyBits);
3575 return angle::Result::Continue();
3576}
3577
Jamie Madillc29968b2016-01-20 11:17:23 -05003578void Context::blitFramebuffer(GLint srcX0,
3579 GLint srcY0,
3580 GLint srcX1,
3581 GLint srcY1,
3582 GLint dstX0,
3583 GLint dstY0,
3584 GLint dstX1,
3585 GLint dstY1,
3586 GLbitfield mask,
3587 GLenum filter)
3588{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003589 if (mask == 0)
3590 {
3591 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3592 // buffers are copied.
3593 return;
3594 }
3595
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003597 ASSERT(drawFramebuffer);
3598
3599 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3600 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3601
Jamie Madillbc918e72018-03-08 09:47:21 -05003602 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003603
Jamie Madill4f6592f2018-11-27 16:37:45 -05003604 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003605}
Jamie Madillc29968b2016-01-20 11:17:23 -05003606
3607void Context::clear(GLbitfield mask)
3608{
Geoff Langd4fff502017-09-22 11:28:28 -04003609 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3610 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003611}
3612
3613void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3614{
Olli Etuaho78df3362018-10-05 16:43:27 +03003615 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3616 const FramebufferAttachment *attachment = nullptr;
3617 if (buffer == GL_DEPTH)
3618 {
3619 attachment = framebufferObject->getDepthbuffer();
3620 }
3621 if (buffer == GL_COLOR &&
3622 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3623 {
3624 attachment = framebufferObject->getColorbuffer(drawbuffer);
3625 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003626 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3627 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003628 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003629 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003630 return;
3631 }
Geoff Langd4fff502017-09-22 11:28:28 -04003632 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003633 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003634}
3635
3636void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3637{
Olli Etuaho78df3362018-10-05 16:43:27 +03003638 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3639 const FramebufferAttachment *attachment = nullptr;
3640 if (buffer == GL_COLOR &&
3641 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3642 {
3643 attachment = framebufferObject->getColorbuffer(drawbuffer);
3644 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003645 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3646 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003647 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003648 {
3649 return;
3650 }
Geoff Langd4fff502017-09-22 11:28:28 -04003651 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003652 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003653}
3654
3655void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3656{
Olli Etuaho78df3362018-10-05 16:43:27 +03003657 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3658 const FramebufferAttachment *attachment = nullptr;
3659 if (buffer == GL_STENCIL)
3660 {
3661 attachment = framebufferObject->getStencilbuffer();
3662 }
3663 if (buffer == GL_COLOR &&
3664 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3665 {
3666 attachment = framebufferObject->getColorbuffer(drawbuffer);
3667 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003668 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3669 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003670 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003671 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003672 return;
3673 }
Geoff Langd4fff502017-09-22 11:28:28 -04003674 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003675 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003676}
3677
3678void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003681 ASSERT(framebufferObject);
3682
3683 // If a buffer is not present, the clear has no effect
3684 if (framebufferObject->getDepthbuffer() == nullptr &&
3685 framebufferObject->getStencilbuffer() == nullptr)
3686 {
3687 return;
3688 }
3689
Geoff Langd4fff502017-09-22 11:28:28 -04003690 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3691 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003692}
3693
3694void Context::readPixels(GLint x,
3695 GLint y,
3696 GLsizei width,
3697 GLsizei height,
3698 GLenum format,
3699 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003700 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003701{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003702 if (width == 0 || height == 0)
3703 {
3704 return;
3705 }
3706
Jamie Madillbc918e72018-03-08 09:47:21 -05003707 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003708
Jamie Madillb6664922017-07-25 12:55:04 -04003709 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3710 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003711
3712 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003713 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003714}
3715
Brandon Jones59770802018-04-02 13:18:42 -07003716void Context::readPixelsRobust(GLint x,
3717 GLint y,
3718 GLsizei width,
3719 GLsizei height,
3720 GLenum format,
3721 GLenum type,
3722 GLsizei bufSize,
3723 GLsizei *length,
3724 GLsizei *columns,
3725 GLsizei *rows,
3726 void *pixels)
3727{
3728 readPixels(x, y, width, height, format, type, pixels);
3729}
3730
3731void Context::readnPixelsRobust(GLint x,
3732 GLint y,
3733 GLsizei width,
3734 GLsizei height,
3735 GLenum format,
3736 GLenum type,
3737 GLsizei bufSize,
3738 GLsizei *length,
3739 GLsizei *columns,
3740 GLsizei *rows,
3741 void *data)
3742{
3743 readPixels(x, y, width, height, format, type, data);
3744}
3745
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003746void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003747 GLint level,
3748 GLenum internalformat,
3749 GLint x,
3750 GLint y,
3751 GLsizei width,
3752 GLsizei height,
3753 GLint border)
3754{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003755 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003756 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003757
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 Rectangle sourceArea(x, y, width, height);
3759
Jamie Madill05b35b22017-10-03 09:01:44 -04003760 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003761 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003762 ANGLE_CONTEXT_TRY(
3763 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003764}
3765
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003766void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003767 GLint level,
3768 GLint xoffset,
3769 GLint yoffset,
3770 GLint x,
3771 GLint y,
3772 GLsizei width,
3773 GLsizei height)
3774{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003775 if (width == 0 || height == 0)
3776 {
3777 return;
3778 }
3779
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003780 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003781 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003782
Jamie Madillc29968b2016-01-20 11:17:23 -05003783 Offset destOffset(xoffset, yoffset, 0);
3784 Rectangle sourceArea(x, y, width, height);
3785
Jamie Madill05b35b22017-10-03 09:01:44 -04003786 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003787 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003788 ANGLE_CONTEXT_TRY(
3789 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003790}
3791
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003792void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003793 GLint level,
3794 GLint xoffset,
3795 GLint yoffset,
3796 GLint zoffset,
3797 GLint x,
3798 GLint y,
3799 GLsizei width,
3800 GLsizei height)
3801{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003802 if (width == 0 || height == 0)
3803 {
3804 return;
3805 }
3806
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003807 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003808 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003809
Jamie Madillc29968b2016-01-20 11:17:23 -05003810 Offset destOffset(xoffset, yoffset, zoffset);
3811 Rectangle sourceArea(x, y, width, height);
3812
Jamie Madill05b35b22017-10-03 09:01:44 -04003813 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3814 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003815 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3816 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003817}
3818
3819void Context::framebufferTexture2D(GLenum target,
3820 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003821 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003822 GLuint texture,
3823 GLint level)
3824{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003826 ASSERT(framebuffer);
3827
3828 if (texture != 0)
3829 {
3830 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003831 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003832 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003833 }
3834 else
3835 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003836 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003837 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003838
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003840}
3841
3842void Context::framebufferRenderbuffer(GLenum target,
3843 GLenum attachment,
3844 GLenum renderbuffertarget,
3845 GLuint renderbuffer)
3846{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003847 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003848 ASSERT(framebuffer);
3849
3850 if (renderbuffer != 0)
3851 {
3852 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003853
Jamie Madillcc129372018-04-12 09:13:18 -04003854 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003855 renderbufferObject);
3856 }
3857 else
3858 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003859 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003860 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003861
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003863}
3864
3865void Context::framebufferTextureLayer(GLenum target,
3866 GLenum attachment,
3867 GLuint texture,
3868 GLint level,
3869 GLint layer)
3870{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003872 ASSERT(framebuffer);
3873
3874 if (texture != 0)
3875 {
3876 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003877 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003878 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003879 }
3880 else
3881 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003882 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003883 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003884
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003885 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003886}
3887
Brandon Jones59770802018-04-02 13:18:42 -07003888void Context::framebufferTextureMultiviewLayered(GLenum target,
3889 GLenum attachment,
3890 GLuint texture,
3891 GLint level,
3892 GLint baseViewIndex,
3893 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003894{
Martin Radev82ef7742017-08-08 17:44:58 +03003895 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3896 ASSERT(framebuffer);
3897
3898 if (texture != 0)
3899 {
3900 Texture *textureObj = getTexture(texture);
3901
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003902 ImageIndex index;
3903 if (textureObj->getType() == TextureType::_2DArray)
3904 {
3905 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3906 }
3907 else
3908 {
3909 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3910 ASSERT(level == 0);
3911 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3912 }
Martin Radev82ef7742017-08-08 17:44:58 +03003913 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3914 numViews, baseViewIndex);
3915 }
3916 else
3917 {
3918 framebuffer->resetAttachment(this, attachment);
3919 }
3920
3921 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003922}
3923
Brandon Jones59770802018-04-02 13:18:42 -07003924void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3925 GLenum attachment,
3926 GLuint texture,
3927 GLint level,
3928 GLsizei numViews,
3929 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003930{
Martin Radev5dae57b2017-07-14 16:15:55 +03003931 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3932 ASSERT(framebuffer);
3933
3934 if (texture != 0)
3935 {
3936 Texture *textureObj = getTexture(texture);
3937
3938 ImageIndex index = ImageIndex::Make2D(level);
3939 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3940 textureObj, numViews, viewportOffsets);
3941 }
3942 else
3943 {
3944 framebuffer->resetAttachment(this, attachment);
3945 }
3946
3947 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003948}
3949
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003950void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3951{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003952 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3953 ASSERT(framebuffer);
3954
3955 if (texture != 0)
3956 {
3957 Texture *textureObj = getTexture(texture);
3958
3959 ImageIndex index = ImageIndex::MakeFromType(
3960 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3961 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3962 }
3963 else
3964 {
3965 framebuffer->resetAttachment(this, attachment);
3966 }
3967
3968 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003969}
3970
Jamie Madillc29968b2016-01-20 11:17:23 -05003971void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3972{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003974 ASSERT(framebuffer);
3975 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003976 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003977 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003978}
3979
3980void Context::readBuffer(GLenum mode)
3981{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003982 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003983 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003984 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003985}
3986
3987void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3988{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003989 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003990 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003991
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003993 ASSERT(framebuffer);
3994
3995 // The specification isn't clear what should be done when the framebuffer isn't complete.
3996 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003997 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003998}
3999
4000void Context::invalidateFramebuffer(GLenum target,
4001 GLsizei numAttachments,
4002 const GLenum *attachments)
4003{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004004 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004005 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004006
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004007 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004008 ASSERT(framebuffer);
4009
Jamie Madill427064d2018-04-13 16:20:34 -04004010 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004011 {
Jamie Madill437fa652016-05-03 15:13:24 -04004012 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004013 }
Jamie Madill437fa652016-05-03 15:13:24 -04004014
Jamie Madill4f6592f2018-11-27 16:37:45 -05004015 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004016}
4017
4018void Context::invalidateSubFramebuffer(GLenum target,
4019 GLsizei numAttachments,
4020 const GLenum *attachments,
4021 GLint x,
4022 GLint y,
4023 GLsizei width,
4024 GLsizei height)
4025{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004026 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004027 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004028
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004029 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004030 ASSERT(framebuffer);
4031
Jamie Madill427064d2018-04-13 16:20:34 -04004032 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004033 {
Jamie Madill437fa652016-05-03 15:13:24 -04004034 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004035 }
Jamie Madill437fa652016-05-03 15:13:24 -04004036
4037 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004038 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004039}
4040
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004041void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004042 GLint level,
4043 GLint internalformat,
4044 GLsizei width,
4045 GLsizei height,
4046 GLint border,
4047 GLenum format,
4048 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004049 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004050{
Jamie Madillbc918e72018-03-08 09:47:21 -05004051 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004052
4053 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004054 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004055 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4056 internalformat, size, format, type,
4057 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004058}
4059
Brandon Jones59770802018-04-02 13:18:42 -07004060void Context::texImage2DRobust(TextureTarget target,
4061 GLint level,
4062 GLint internalformat,
4063 GLsizei width,
4064 GLsizei height,
4065 GLint border,
4066 GLenum format,
4067 GLenum type,
4068 GLsizei bufSize,
4069 const void *pixels)
4070{
4071 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4072}
4073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004074void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004075 GLint level,
4076 GLint internalformat,
4077 GLsizei width,
4078 GLsizei height,
4079 GLsizei depth,
4080 GLint border,
4081 GLenum format,
4082 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004083 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004084{
Jamie Madillbc918e72018-03-08 09:47:21 -05004085 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004086
4087 Extents size(width, height, depth);
4088 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004089 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4090 NonCubeTextureTypeToTarget(target), level, internalformat,
4091 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004092}
4093
Brandon Jones59770802018-04-02 13:18:42 -07004094void Context::texImage3DRobust(TextureType target,
4095 GLint level,
4096 GLint internalformat,
4097 GLsizei width,
4098 GLsizei height,
4099 GLsizei depth,
4100 GLint border,
4101 GLenum format,
4102 GLenum type,
4103 GLsizei bufSize,
4104 const void *pixels)
4105{
4106 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4107}
4108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004109void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004110 GLint level,
4111 GLint xoffset,
4112 GLint yoffset,
4113 GLsizei width,
4114 GLsizei height,
4115 GLenum format,
4116 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004117 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004118{
4119 // Zero sized uploads are valid but no-ops
4120 if (width == 0 || height == 0)
4121 {
4122 return;
4123 }
4124
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004126
4127 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004128 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004129
4130 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4131
Jamie Madill4f6592f2018-11-27 16:37:45 -05004132 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4133 level, area, format, type,
4134 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004135}
4136
Brandon Jones59770802018-04-02 13:18:42 -07004137void Context::texSubImage2DRobust(TextureTarget target,
4138 GLint level,
4139 GLint xoffset,
4140 GLint yoffset,
4141 GLsizei width,
4142 GLsizei height,
4143 GLenum format,
4144 GLenum type,
4145 GLsizei bufSize,
4146 const void *pixels)
4147{
4148 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4149}
4150
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004151void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004152 GLint level,
4153 GLint xoffset,
4154 GLint yoffset,
4155 GLint zoffset,
4156 GLsizei width,
4157 GLsizei height,
4158 GLsizei depth,
4159 GLenum format,
4160 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004161 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004162{
4163 // Zero sized uploads are valid but no-ops
4164 if (width == 0 || height == 0 || depth == 0)
4165 {
4166 return;
4167 }
4168
Jamie Madillbc918e72018-03-08 09:47:21 -05004169 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004170
4171 Box area(xoffset, yoffset, zoffset, width, height, depth);
4172 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004173
4174 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4175
Jamie Madill4f6592f2018-11-27 16:37:45 -05004176 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4177 NonCubeTextureTypeToTarget(target), level, area, format,
4178 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004179}
4180
Brandon Jones59770802018-04-02 13:18:42 -07004181void Context::texSubImage3DRobust(TextureType target,
4182 GLint level,
4183 GLint xoffset,
4184 GLint yoffset,
4185 GLint zoffset,
4186 GLsizei width,
4187 GLsizei height,
4188 GLsizei depth,
4189 GLenum format,
4190 GLenum type,
4191 GLsizei bufSize,
4192 const void *pixels)
4193{
4194 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4195 pixels);
4196}
4197
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004198void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004199 GLint level,
4200 GLenum internalformat,
4201 GLsizei width,
4202 GLsizei height,
4203 GLint border,
4204 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004205 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004206{
Jamie Madillbc918e72018-03-08 09:47:21 -05004207 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004208
4209 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004210 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004211 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4212 internalformat, size, imageSize,
4213 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004214}
4215
Brandon Jones59770802018-04-02 13:18:42 -07004216void Context::compressedTexImage2DRobust(TextureTarget target,
4217 GLint level,
4218 GLenum internalformat,
4219 GLsizei width,
4220 GLsizei height,
4221 GLint border,
4222 GLsizei imageSize,
4223 GLsizei dataSize,
4224 const GLvoid *data)
4225{
4226 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4227}
4228
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004229void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004230 GLint level,
4231 GLenum internalformat,
4232 GLsizei width,
4233 GLsizei height,
4234 GLsizei depth,
4235 GLint border,
4236 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004237 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004238{
Jamie Madillbc918e72018-03-08 09:47:21 -05004239 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004240
4241 Extents size(width, height, depth);
4242 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004243 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004244 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004245 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004246}
4247
Brandon Jones59770802018-04-02 13:18:42 -07004248void Context::compressedTexImage3DRobust(TextureType target,
4249 GLint level,
4250 GLenum internalformat,
4251 GLsizei width,
4252 GLsizei height,
4253 GLsizei depth,
4254 GLint border,
4255 GLsizei imageSize,
4256 GLsizei dataSize,
4257 const GLvoid *data)
4258{
4259 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4260 data);
4261}
4262
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004263void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004264 GLint level,
4265 GLint xoffset,
4266 GLint yoffset,
4267 GLsizei width,
4268 GLsizei height,
4269 GLenum format,
4270 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004271 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004272{
Jamie Madillbc918e72018-03-08 09:47:21 -05004273 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004274
4275 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004276 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004277 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4278 area, format, imageSize,
4279 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004280}
4281
Brandon Jones59770802018-04-02 13:18:42 -07004282void Context::compressedTexSubImage2DRobust(TextureTarget target,
4283 GLint level,
4284 GLint xoffset,
4285 GLint yoffset,
4286 GLsizei width,
4287 GLsizei height,
4288 GLenum format,
4289 GLsizei imageSize,
4290 GLsizei dataSize,
4291 const GLvoid *data)
4292{
4293 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4294 data);
4295}
4296
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004297void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004298 GLint level,
4299 GLint xoffset,
4300 GLint yoffset,
4301 GLint zoffset,
4302 GLsizei width,
4303 GLsizei height,
4304 GLsizei depth,
4305 GLenum format,
4306 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004307 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004308{
4309 // Zero sized uploads are valid but no-ops
4310 if (width == 0 || height == 0)
4311 {
4312 return;
4313 }
4314
Jamie Madillbc918e72018-03-08 09:47:21 -05004315 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004316
4317 Box area(xoffset, yoffset, zoffset, width, height, depth);
4318 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004319 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004320 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004321 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004322}
4323
Brandon Jones59770802018-04-02 13:18:42 -07004324void Context::compressedTexSubImage3DRobust(TextureType target,
4325 GLint level,
4326 GLint xoffset,
4327 GLint yoffset,
4328 GLint zoffset,
4329 GLsizei width,
4330 GLsizei height,
4331 GLsizei depth,
4332 GLenum format,
4333 GLsizei imageSize,
4334 GLsizei dataSize,
4335 const GLvoid *data)
4336{
4337 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4338 imageSize, data);
4339}
4340
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004341void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004342{
4343 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004344 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004345}
4346
Jamie Madill007530e2017-12-28 14:27:04 -05004347void Context::copyTexture(GLuint sourceId,
4348 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004349 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004350 GLuint destId,
4351 GLint destLevel,
4352 GLint internalFormat,
4353 GLenum destType,
4354 GLboolean unpackFlipY,
4355 GLboolean unpackPremultiplyAlpha,
4356 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004357{
Jamie Madillbc918e72018-03-08 09:47:21 -05004358 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004359
4360 gl::Texture *sourceTexture = getTexture(sourceId);
4361 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004362 ANGLE_CONTEXT_TRY(
4363 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4364 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4365 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004366}
4367
Jamie Madill007530e2017-12-28 14:27:04 -05004368void Context::copySubTexture(GLuint sourceId,
4369 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004370 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004371 GLuint destId,
4372 GLint destLevel,
4373 GLint xoffset,
4374 GLint yoffset,
4375 GLint x,
4376 GLint y,
4377 GLsizei width,
4378 GLsizei height,
4379 GLboolean unpackFlipY,
4380 GLboolean unpackPremultiplyAlpha,
4381 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004382{
4383 // Zero sized copies are valid but no-ops
4384 if (width == 0 || height == 0)
4385 {
4386 return;
4387 }
4388
Jamie Madillbc918e72018-03-08 09:47:21 -05004389 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004390
4391 gl::Texture *sourceTexture = getTexture(sourceId);
4392 gl::Texture *destTexture = getTexture(destId);
4393 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004394 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004395 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4396 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4397 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4398 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004399}
4400
4401void Context::copyTexture3D(GLuint sourceId,
4402 GLint sourceLevel,
4403 TextureTarget destTarget,
4404 GLuint destId,
4405 GLint destLevel,
4406 GLint internalFormat,
4407 GLenum destType,
4408 GLboolean unpackFlipY,
4409 GLboolean unpackPremultiplyAlpha,
4410 GLboolean unpackUnmultiplyAlpha)
4411{
4412 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4413
4414 Texture *sourceTexture = getTexture(sourceId);
4415 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004416 ANGLE_CONTEXT_TRY(
4417 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4418 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4419 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004420}
4421
4422void Context::copySubTexture3D(GLuint sourceId,
4423 GLint sourceLevel,
4424 TextureTarget destTarget,
4425 GLuint destId,
4426 GLint destLevel,
4427 GLint xoffset,
4428 GLint yoffset,
4429 GLint zoffset,
4430 GLint x,
4431 GLint y,
4432 GLint z,
4433 GLsizei width,
4434 GLsizei height,
4435 GLsizei depth,
4436 GLboolean unpackFlipY,
4437 GLboolean unpackPremultiplyAlpha,
4438 GLboolean unpackUnmultiplyAlpha)
4439{
4440 // Zero sized copies are valid but no-ops
4441 if (width == 0 || height == 0 || depth == 0)
4442 {
4443 return;
4444 }
4445
4446 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4447
4448 Texture *sourceTexture = getTexture(sourceId);
4449 Texture *destTexture = getTexture(destId);
4450 Offset offset(xoffset, yoffset, zoffset);
4451 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004452 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4453 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4454 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4455 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004456}
4457
Jamie Madill007530e2017-12-28 14:27:04 -05004458void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004459{
Jamie Madillbc918e72018-03-08 09:47:21 -05004460 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004461
4462 gl::Texture *sourceTexture = getTexture(sourceId);
4463 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004464 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004465}
4466
Corentin Wallez336129f2017-10-17 15:55:40 -04004467void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004468{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004469 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004470 ASSERT(buffer);
4471
Geoff Lang496c02d2016-10-20 11:38:11 -07004472 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004473}
4474
Brandon Jones59770802018-04-02 13:18:42 -07004475void Context::getBufferPointervRobust(BufferBinding target,
4476 GLenum pname,
4477 GLsizei bufSize,
4478 GLsizei *length,
4479 void **params)
4480{
4481 getBufferPointerv(target, pname, params);
4482}
4483
Corentin Wallez336129f2017-10-17 15:55:40 -04004484void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004485{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004487 ASSERT(buffer);
4488
Jamie Madill4f6592f2018-11-27 16:37:45 -05004489 if (buffer->map(this, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004490 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004491 return nullptr;
4492 }
4493
4494 return buffer->getMapPointer();
4495}
4496
Corentin Wallez336129f2017-10-17 15:55:40 -04004497GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004498{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004499 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004500 ASSERT(buffer);
4501
4502 GLboolean result;
Jamie Madill4f6592f2018-11-27 16:37:45 -05004503 if (buffer->unmap(this, &result) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004504 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004505 return GL_FALSE;
4506 }
4507
4508 return result;
4509}
4510
Corentin Wallez336129f2017-10-17 15:55:40 -04004511void *Context::mapBufferRange(BufferBinding target,
4512 GLintptr offset,
4513 GLsizeiptr length,
4514 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004517 ASSERT(buffer);
4518
Jamie Madill4f6592f2018-11-27 16:37:45 -05004519 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004520 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004521 return nullptr;
4522 }
4523
4524 return buffer->getMapPointer();
4525}
4526
Corentin Wallez336129f2017-10-17 15:55:40 -04004527void Context::flushMappedBufferRange(BufferBinding /*target*/,
4528 GLintptr /*offset*/,
4529 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004530{
4531 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4532}
4533
Jamie Madill526392d2018-11-16 09:35:14 -05004534angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004535{
Geoff Langa8cb2872018-03-09 16:09:40 -05004536 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004537}
4538
Jamie Madill526392d2018-11-16 09:35:14 -05004539angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004540{
Geoff Langa8cb2872018-03-09 16:09:40 -05004541 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004542}
4543
Jamie Madill526392d2018-11-16 09:35:14 -05004544angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004545{
Geoff Langa8cb2872018-03-09 16:09:40 -05004546 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004547}
4548
Jamie Madill526392d2018-11-16 09:35:14 -05004549angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004550{
4551 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4552
4553 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4554 ANGLE_TRY(syncDirtyBits());
4555
Jamie Madill526392d2018-11-16 09:35:14 -05004556 return angle::Result::Continue();
Geoff Lang9bf86f02018-07-26 11:46:34 -04004557}
4558
Jiajia Qin5451d532017-11-16 17:16:34 +08004559void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4560{
4561 UNIMPLEMENTED();
4562}
4563
Jamie Madillc20ab272016-06-09 07:20:46 -07004564void Context::activeTexture(GLenum texture)
4565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
Jamie Madill876429b2017-04-20 15:46:24 -04004569void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004572}
4573
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004574void Context::blendEquation(GLenum mode)
4575{
4576 mGLState.setBlendEquation(mode, mode);
4577}
4578
Jamie Madillc20ab272016-06-09 07:20:46 -07004579void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582}
4583
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004584void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4585{
4586 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4587}
4588
Jamie Madillc20ab272016-06-09 07:20:46 -07004589void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592}
4593
Jamie Madill876429b2017-04-20 15:46:24 -04004594void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597}
4598
Jamie Madill876429b2017-04-20 15:46:24 -04004599void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004600{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004601 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
4604void Context::clearStencil(GLint s)
4605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
4609void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4610{
Geoff Lang92019432017-11-20 13:09:34 -05004611 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4612 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004615void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
4620void Context::depthFunc(GLenum func)
4621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
4625void Context::depthMask(GLboolean flag)
4626{
Geoff Lang92019432017-11-20 13:09:34 -05004627 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004628}
4629
Jamie Madill876429b2017-04-20 15:46:24 -04004630void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004631{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004632 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004633}
4634
4635void Context::disable(GLenum cap)
4636{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004638 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639}
4640
4641void Context::disableVertexAttribArray(GLuint index)
4642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004644 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645}
4646
4647void Context::enable(GLenum cap)
4648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004650 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004651}
4652
4653void Context::enableVertexAttribArray(GLuint index)
4654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004656 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::frontFace(GLenum mode)
4660{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662}
4663
4664void Context::hint(GLenum target, GLenum mode)
4665{
4666 switch (target)
4667 {
4668 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004670 break;
4671
4672 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004673 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674 break;
4675
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004676 case GL_PERSPECTIVE_CORRECTION_HINT:
4677 case GL_POINT_SMOOTH_HINT:
4678 case GL_LINE_SMOOTH_HINT:
4679 case GL_FOG_HINT:
4680 mGLState.gles1().setHint(target, mode);
4681 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004682 default:
4683 UNREACHABLE();
4684 return;
4685 }
4686}
4687
4688void Context::lineWidth(GLfloat width)
4689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004690 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004691}
4692
4693void Context::pixelStorei(GLenum pname, GLint param)
4694{
4695 switch (pname)
4696 {
4697 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699 break;
4700
4701 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004703 break;
4704
4705 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004706 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004707 break;
4708
4709 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004710 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004711 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712 break;
4713
4714 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004715 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004717 break;
4718
4719 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004720 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004721 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004722 break;
4723
4724 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004725 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004726 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004727 break;
4728
4729 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004730 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004731 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004732 break;
4733
4734 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004735 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004736 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004737 break;
4738
4739 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004740 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004741 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004742 break;
4743
4744 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004745 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004746 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004747 break;
4748
4749 default:
4750 UNREACHABLE();
4751 return;
4752 }
4753}
4754
4755void Context::polygonOffset(GLfloat factor, GLfloat units)
4756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004757 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004758}
4759
Jamie Madill876429b2017-04-20 15:46:24 -04004760void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004761{
Geoff Lang92019432017-11-20 13:09:34 -05004762 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004763}
4764
Jiawei Shaodb342272017-09-27 10:21:45 +08004765void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4766{
4767 mGLState.setSampleMaskParams(maskNumber, mask);
4768}
4769
Jamie Madillc20ab272016-06-09 07:20:46 -07004770void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4771{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004772 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004773}
4774
4775void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4776{
4777 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4778 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004779 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780 }
4781
4782 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4783 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004784 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004785 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004786
4787 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004788}
4789
4790void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4791{
4792 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4793 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004794 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004795 }
4796
4797 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4798 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004799 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004800 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004801
4802 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803}
4804
4805void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4806{
4807 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4808 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004809 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810 }
4811
4812 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4813 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004815 }
4816}
4817
4818void Context::vertexAttrib1f(GLuint index, GLfloat x)
4819{
4820 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004821 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004822 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004823}
4824
4825void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4826{
4827 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004828 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004829 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004830}
4831
4832void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4833{
4834 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004835 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004836 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004837}
4838
4839void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4840{
4841 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004842 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004843 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004844}
4845
4846void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4847{
4848 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004849 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004850 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004851}
4852
4853void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4854{
4855 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004856 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004857 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004858}
4859
4860void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4861{
4862 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004863 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004864 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004865}
4866
4867void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4868{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004869 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004870 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004871}
4872
4873void Context::vertexAttribPointer(GLuint index,
4874 GLint size,
4875 GLenum type,
4876 GLboolean normalized,
4877 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004878 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004879{
Corentin Wallez336129f2017-10-17 15:55:40 -04004880 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004881 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004882 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004883}
4884
Shao80957d92017-02-20 21:25:59 +08004885void Context::vertexAttribFormat(GLuint attribIndex,
4886 GLint size,
4887 GLenum type,
4888 GLboolean normalized,
4889 GLuint relativeOffset)
4890{
Geoff Lang92019432017-11-20 13:09:34 -05004891 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004892 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004893 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004894}
4895
4896void Context::vertexAttribIFormat(GLuint attribIndex,
4897 GLint size,
4898 GLenum type,
4899 GLuint relativeOffset)
4900{
4901 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004902 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004903}
4904
4905void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4906{
Shaodde78e82017-05-22 14:13:27 +08004907 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004908 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004909}
4910
Jiajia Qin5451d532017-11-16 17:16:34 +08004911void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004912{
4913 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004914 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004915}
4916
Jamie Madillc20ab272016-06-09 07:20:46 -07004917void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4918{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004919 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004920}
4921
4922void Context::vertexAttribIPointer(GLuint index,
4923 GLint size,
4924 GLenum type,
4925 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004926 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004927{
Corentin Wallez336129f2017-10-17 15:55:40 -04004928 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4929 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004930 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004931}
4932
4933void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4934{
4935 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004936 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004937 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004938}
4939
4940void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4941{
4942 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004943 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004944 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004945}
4946
4947void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4948{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004949 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004950 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004951}
4952
4953void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4954{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004955 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004956 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004957}
4958
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004959void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4960{
4961 const VertexAttribCurrentValueData &currentValues =
4962 getGLState().getVertexAttribCurrentValue(index);
4963 const VertexArray *vao = getGLState().getVertexArray();
4964 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4965 currentValues, pname, params);
4966}
4967
Brandon Jones59770802018-04-02 13:18:42 -07004968void Context::getVertexAttribivRobust(GLuint index,
4969 GLenum pname,
4970 GLsizei bufSize,
4971 GLsizei *length,
4972 GLint *params)
4973{
4974 getVertexAttribiv(index, pname, params);
4975}
4976
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004977void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4978{
4979 const VertexAttribCurrentValueData &currentValues =
4980 getGLState().getVertexAttribCurrentValue(index);
4981 const VertexArray *vao = getGLState().getVertexArray();
4982 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4983 currentValues, pname, params);
4984}
4985
Brandon Jones59770802018-04-02 13:18:42 -07004986void Context::getVertexAttribfvRobust(GLuint index,
4987 GLenum pname,
4988 GLsizei bufSize,
4989 GLsizei *length,
4990 GLfloat *params)
4991{
4992 getVertexAttribfv(index, pname, params);
4993}
4994
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004995void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4996{
4997 const VertexAttribCurrentValueData &currentValues =
4998 getGLState().getVertexAttribCurrentValue(index);
4999 const VertexArray *vao = getGLState().getVertexArray();
5000 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5001 currentValues, pname, params);
5002}
5003
Brandon Jones59770802018-04-02 13:18:42 -07005004void Context::getVertexAttribIivRobust(GLuint index,
5005 GLenum pname,
5006 GLsizei bufSize,
5007 GLsizei *length,
5008 GLint *params)
5009{
5010 getVertexAttribIiv(index, pname, params);
5011}
5012
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005013void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5014{
5015 const VertexAttribCurrentValueData &currentValues =
5016 getGLState().getVertexAttribCurrentValue(index);
5017 const VertexArray *vao = getGLState().getVertexArray();
5018 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5019 currentValues, pname, params);
5020}
5021
Brandon Jones59770802018-04-02 13:18:42 -07005022void Context::getVertexAttribIuivRobust(GLuint index,
5023 GLenum pname,
5024 GLsizei bufSize,
5025 GLsizei *length,
5026 GLuint *params)
5027{
5028 getVertexAttribIuiv(index, pname, params);
5029}
5030
Jamie Madill876429b2017-04-20 15:46:24 -04005031void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005032{
5033 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5034 QueryVertexAttribPointerv(attrib, pname, pointer);
5035}
5036
Brandon Jones59770802018-04-02 13:18:42 -07005037void Context::getVertexAttribPointervRobust(GLuint index,
5038 GLenum pname,
5039 GLsizei bufSize,
5040 GLsizei *length,
5041 void **pointer)
5042{
5043 getVertexAttribPointerv(index, pname, pointer);
5044}
5045
Jamie Madillc20ab272016-06-09 07:20:46 -07005046void Context::debugMessageControl(GLenum source,
5047 GLenum type,
5048 GLenum severity,
5049 GLsizei count,
5050 const GLuint *ids,
5051 GLboolean enabled)
5052{
5053 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005054 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005055 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005056}
5057
5058void Context::debugMessageInsert(GLenum source,
5059 GLenum type,
5060 GLuint id,
5061 GLenum severity,
5062 GLsizei length,
5063 const GLchar *buf)
5064{
5065 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005066 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005067}
5068
5069void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5070{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005071 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005072}
5073
5074GLuint Context::getDebugMessageLog(GLuint count,
5075 GLsizei bufSize,
5076 GLenum *sources,
5077 GLenum *types,
5078 GLuint *ids,
5079 GLenum *severities,
5080 GLsizei *lengths,
5081 GLchar *messageLog)
5082{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005083 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5084 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005085}
5086
5087void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5088{
5089 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005090 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005091 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005092}
5093
5094void Context::popDebugGroup()
5095{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005096 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005097 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005098}
5099
Corentin Wallez336129f2017-10-17 15:55:40 -04005100void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005101{
5102 Buffer *buffer = mGLState.getTargetBuffer(target);
5103 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005104 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005105}
5106
Corentin Wallez336129f2017-10-17 15:55:40 -04005107void Context::bufferSubData(BufferBinding target,
5108 GLintptr offset,
5109 GLsizeiptr size,
5110 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005111{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005112 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005113 {
5114 return;
5115 }
5116
5117 Buffer *buffer = mGLState.getTargetBuffer(target);
5118 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005119 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005120}
5121
Jamie Madillef300b12016-10-07 15:12:09 -04005122void Context::attachShader(GLuint program, GLuint shader)
5123{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005124 Program *programObject = mState.mShaderPrograms->getProgram(program);
5125 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005126 ASSERT(programObject && shaderObject);
5127 programObject->attachShader(shaderObject);
5128}
5129
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005130const Workarounds &Context::getWorkarounds() const
5131{
5132 return mWorkarounds;
5133}
5134
Corentin Wallez336129f2017-10-17 15:55:40 -04005135void Context::copyBufferSubData(BufferBinding readTarget,
5136 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005137 GLintptr readOffset,
5138 GLintptr writeOffset,
5139 GLsizeiptr size)
5140{
5141 // if size is zero, the copy is a successful no-op
5142 if (size == 0)
5143 {
5144 return;
5145 }
5146
5147 // TODO(jmadill): cache these.
5148 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5149 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5150
Jamie Madill4f6592f2018-11-27 16:37:45 -05005151 ANGLE_CONTEXT_TRY(
5152 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005153}
5154
Jamie Madill01a80ee2016-11-07 12:06:18 -05005155void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5156{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005157 // Ideally we could share the program query with the validation layer if possible.
5158 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005159 ASSERT(programObject);
5160 programObject->bindAttributeLocation(index, name);
5161}
5162
Corentin Wallez336129f2017-10-17 15:55:40 -04005163void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005164{
Corentin Wallez336129f2017-10-17 15:55:40 -04005165 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5166 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005167 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005168}
5169
Corentin Wallez336129f2017-10-17 15:55:40 -04005170void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005171{
5172 bindBufferRange(target, index, buffer, 0, 0);
5173}
5174
Corentin Wallez336129f2017-10-17 15:55:40 -04005175void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005176 GLuint index,
5177 GLuint buffer,
5178 GLintptr offset,
5179 GLsizeiptr size)
5180{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005181 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5182 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5183 if (target == BufferBinding::Uniform)
5184 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005185 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005186 mStateCache.onUniformBufferStateChange(this);
5187 }
5188 else
5189 {
5190 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005191 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005192}
5193
Jamie Madill01a80ee2016-11-07 12:06:18 -05005194void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5195{
5196 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5197 {
5198 bindReadFramebuffer(framebuffer);
5199 }
5200
5201 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5202 {
5203 bindDrawFramebuffer(framebuffer);
5204 }
5205}
5206
5207void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5208{
5209 ASSERT(target == GL_RENDERBUFFER);
5210 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005211 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005212 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005213}
5214
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005215void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005216 GLsizei samples,
5217 GLenum internalformat,
5218 GLsizei width,
5219 GLsizei height,
5220 GLboolean fixedsamplelocations)
5221{
5222 Extents size(width, height, 1);
5223 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005224 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5225 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005226}
5227
Olli Etuaho89664842018-08-24 14:45:36 +03005228void Context::texStorage3DMultisample(TextureType target,
5229 GLsizei samples,
5230 GLenum internalformat,
5231 GLsizei width,
5232 GLsizei height,
5233 GLsizei depth,
5234 GLboolean fixedsamplelocations)
5235{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005236 Extents size(width, height, depth);
5237 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005238 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5239 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005240}
5241
JiangYizhoubddc46b2016-12-09 09:50:51 +08005242void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5243{
JiangYizhou5b03f472017-01-09 10:22:53 +08005244 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5245 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005246 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005247 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005248
5249 switch (pname)
5250 {
5251 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005252 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005253 break;
5254 default:
5255 UNREACHABLE();
5256 }
5257}
5258
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005259void Context::getMultisamplefvRobust(GLenum pname,
5260 GLuint index,
5261 GLsizei bufSize,
5262 GLsizei *length,
5263 GLfloat *val)
5264{
5265 UNIMPLEMENTED();
5266}
5267
Jamie Madille8fb6402017-02-14 17:56:40 -05005268void Context::renderbufferStorage(GLenum target,
5269 GLenum internalformat,
5270 GLsizei width,
5271 GLsizei height)
5272{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005273 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5274 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5275
Jamie Madille8fb6402017-02-14 17:56:40 -05005276 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005277 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005278}
5279
5280void Context::renderbufferStorageMultisample(GLenum target,
5281 GLsizei samples,
5282 GLenum internalformat,
5283 GLsizei width,
5284 GLsizei height)
5285{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005286 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5287 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005288
5289 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005290 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005291 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005292}
5293
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005294void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5295{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005296 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005297 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005298}
5299
JiangYizhoue18e6392017-02-20 10:32:23 +08005300void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5301{
5302 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5303 QueryFramebufferParameteriv(framebuffer, pname, params);
5304}
5305
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005306void Context::getFramebufferParameterivRobust(GLenum target,
5307 GLenum pname,
5308 GLsizei bufSize,
5309 GLsizei *length,
5310 GLint *params)
5311{
5312 UNIMPLEMENTED();
5313}
5314
Jiajia Qin5451d532017-11-16 17:16:34 +08005315void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005316{
5317 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005318 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005319}
5320
Jamie Madilldec86232018-07-11 09:01:18 -04005321bool Context::getScratchBuffer(size_t requstedSizeBytes,
5322 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005323{
Jamie Madilldec86232018-07-11 09:01:18 -04005324 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005325}
5326
Jamie Madilldec86232018-07-11 09:01:18 -04005327bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5328 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005329{
Jamie Madilldec86232018-07-11 09:01:18 -04005330 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005331}
5332
Jamie Madill526392d2018-11-16 09:35:14 -05005333angle::Result Context::prepareForDispatch()
Xinghua Cao10a4d432017-11-28 14:46:26 +08005334{
Jamie Madill0cc11c62018-10-12 18:07:18 -04005335 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005336
5337 if (isRobustResourceInitEnabled())
5338 {
5339 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5340 }
5341
Jamie Madill0cc11c62018-10-12 18:07:18 -04005342 return syncDirtyBits(mComputeDirtyBits);
Xinghua Cao10a4d432017-11-28 14:46:26 +08005343}
5344
Xinghua Cao2b396592017-03-29 15:36:04 +08005345void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5346{
5347 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5348 {
5349 return;
5350 }
5351
Xinghua Cao10a4d432017-11-28 14:46:26 +08005352 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005353 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005354}
5355
Jiajia Qin5451d532017-11-16 17:16:34 +08005356void Context::dispatchComputeIndirect(GLintptr indirect)
5357{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005358 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005359 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005360}
5361
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005362void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005363 GLsizei levels,
5364 GLenum internalFormat,
5365 GLsizei width,
5366 GLsizei height)
5367{
5368 Extents size(width, height, 1);
5369 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005370 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005371}
5372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005373void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005374 GLsizei levels,
5375 GLenum internalFormat,
5376 GLsizei width,
5377 GLsizei height,
5378 GLsizei depth)
5379{
5380 Extents size(width, height, depth);
5381 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005382 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005383}
5384
Jiajia Qin5451d532017-11-16 17:16:34 +08005385void Context::memoryBarrier(GLbitfield barriers)
5386{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005387 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005388}
5389
5390void Context::memoryBarrierByRegion(GLbitfield barriers)
5391{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005392 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005393}
5394
Austin Eng1bf18ce2018-10-19 15:34:02 -07005395void Context::multiDrawArrays(PrimitiveMode mode,
5396 const GLint *firsts,
5397 const GLsizei *counts,
5398 GLsizei drawcount)
5399{
5400 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5401 Program *programObject = mGLState.getLinkedProgram(this);
5402 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5403 if (hasDrawID)
5404 {
5405 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5406 {
5407 if (noopDraw(mode, counts[drawID]))
5408 {
5409 continue;
5410 }
5411 programObject->setDrawIDUniform(drawID);
5412 ANGLE_CONTEXT_TRY(
5413 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5414 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5415 counts[drawID], 1);
5416 }
5417 }
5418 else
5419 {
5420 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5421 {
5422 if (noopDraw(mode, counts[drawID]))
5423 {
5424 continue;
5425 }
5426 ANGLE_CONTEXT_TRY(
5427 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5428 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5429 counts[drawID], 1);
5430 }
5431 }
5432}
5433
5434void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5435 const GLint *firsts,
5436 const GLsizei *counts,
5437 const GLsizei *instanceCounts,
5438 GLsizei drawcount)
5439{
5440 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5441 Program *programObject = mGLState.getLinkedProgram(this);
5442 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5443 if (hasDrawID)
5444 {
5445 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5446 {
5447 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5448 {
5449 continue;
5450 }
5451 programObject->setDrawIDUniform(drawID);
5452 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5453 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5454 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5455 counts[drawID], instanceCounts[drawID]);
5456 }
5457 }
5458 else
5459 {
5460 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5461 {
5462 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5463 {
5464 continue;
5465 }
5466 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5467 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5468 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5469 counts[drawID], instanceCounts[drawID]);
5470 }
5471 }
5472}
5473
5474void Context::multiDrawElements(PrimitiveMode mode,
5475 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005476 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005477 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005478 GLsizei drawcount)
5479{
5480 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5481 Program *programObject = mGLState.getLinkedProgram(this);
5482 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5483 if (hasDrawID)
5484 {
5485 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5486 {
5487 if (noopDraw(mode, counts[drawID]))
5488 {
5489 continue;
5490 }
5491 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005492 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005493 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005494 }
5495 }
5496 else
5497 {
5498 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5499 {
5500 if (noopDraw(mode, counts[drawID]))
5501 {
5502 continue;
5503 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005504 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005505 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005506 }
5507 }
5508}
5509
5510void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5511 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005512 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005513 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005514 const GLsizei *instanceCounts,
5515 GLsizei drawcount)
5516{
5517 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5518 Program *programObject = mGLState.getLinkedProgram(this);
5519 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5520 if (hasDrawID)
5521 {
5522 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5523 {
5524 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5525 {
5526 continue;
5527 }
5528 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005529 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005530 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005531 }
5532 }
5533 else
5534 {
5535 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5536 {
5537 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5538 {
5539 continue;
5540 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005541 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005542 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005543 }
5544 }
5545}
5546
Jamie Madillc1d770e2017-04-13 17:31:24 -04005547GLenum Context::checkFramebufferStatus(GLenum target)
5548{
5549 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5550 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005551 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552}
5553
5554void Context::compileShader(GLuint shader)
5555{
5556 Shader *shaderObject = GetValidShader(this, shader);
5557 if (!shaderObject)
5558 {
5559 return;
5560 }
5561 shaderObject->compile(this);
5562}
5563
5564void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5565{
5566 for (int i = 0; i < n; i++)
5567 {
5568 deleteBuffer(buffers[i]);
5569 }
5570}
5571
5572void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5573{
5574 for (int i = 0; i < n; i++)
5575 {
5576 if (framebuffers[i] != 0)
5577 {
5578 deleteFramebuffer(framebuffers[i]);
5579 }
5580 }
5581}
5582
5583void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5584{
5585 for (int i = 0; i < n; i++)
5586 {
5587 deleteRenderbuffer(renderbuffers[i]);
5588 }
5589}
5590
5591void Context::deleteTextures(GLsizei n, const GLuint *textures)
5592{
5593 for (int i = 0; i < n; i++)
5594 {
5595 if (textures[i] != 0)
5596 {
5597 deleteTexture(textures[i]);
5598 }
5599 }
5600}
5601
5602void Context::detachShader(GLuint program, GLuint shader)
5603{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005604 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005605 ASSERT(programObject);
5606
5607 Shader *shaderObject = getShader(shader);
5608 ASSERT(shaderObject);
5609
5610 programObject->detachShader(this, shaderObject);
5611}
5612
5613void Context::genBuffers(GLsizei n, GLuint *buffers)
5614{
5615 for (int i = 0; i < n; i++)
5616 {
5617 buffers[i] = createBuffer();
5618 }
5619}
5620
5621void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5622{
5623 for (int i = 0; i < n; i++)
5624 {
5625 framebuffers[i] = createFramebuffer();
5626 }
5627}
5628
5629void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5630{
5631 for (int i = 0; i < n; i++)
5632 {
5633 renderbuffers[i] = createRenderbuffer();
5634 }
5635}
5636
5637void Context::genTextures(GLsizei n, GLuint *textures)
5638{
5639 for (int i = 0; i < n; i++)
5640 {
5641 textures[i] = createTexture();
5642 }
5643}
5644
5645void Context::getActiveAttrib(GLuint program,
5646 GLuint index,
5647 GLsizei bufsize,
5648 GLsizei *length,
5649 GLint *size,
5650 GLenum *type,
5651 GLchar *name)
5652{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005653 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005654 ASSERT(programObject);
5655 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5656}
5657
5658void Context::getActiveUniform(GLuint program,
5659 GLuint index,
5660 GLsizei bufsize,
5661 GLsizei *length,
5662 GLint *size,
5663 GLenum *type,
5664 GLchar *name)
5665{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005666 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005667 ASSERT(programObject);
5668 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5669}
5670
5671void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5672{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005673 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005674 ASSERT(programObject);
5675 programObject->getAttachedShaders(maxcount, count, shaders);
5676}
5677
5678GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5679{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005680 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005681 ASSERT(programObject);
5682 return programObject->getAttributeLocation(name);
5683}
5684
5685void Context::getBooleanv(GLenum pname, GLboolean *params)
5686{
5687 GLenum nativeType;
5688 unsigned int numParams = 0;
5689 getQueryParameterInfo(pname, &nativeType, &numParams);
5690
5691 if (nativeType == GL_BOOL)
5692 {
5693 getBooleanvImpl(pname, params);
5694 }
5695 else
5696 {
5697 CastStateValues(this, nativeType, pname, numParams, params);
5698 }
5699}
5700
Brandon Jones59770802018-04-02 13:18:42 -07005701void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5702{
5703 getBooleanv(pname, params);
5704}
5705
Jamie Madillc1d770e2017-04-13 17:31:24 -04005706void Context::getFloatv(GLenum pname, GLfloat *params)
5707{
5708 GLenum nativeType;
5709 unsigned int numParams = 0;
5710 getQueryParameterInfo(pname, &nativeType, &numParams);
5711
5712 if (nativeType == GL_FLOAT)
5713 {
5714 getFloatvImpl(pname, params);
5715 }
5716 else
5717 {
5718 CastStateValues(this, nativeType, pname, numParams, params);
5719 }
5720}
5721
Brandon Jones59770802018-04-02 13:18:42 -07005722void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5723{
5724 getFloatv(pname, params);
5725}
5726
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727void Context::getIntegerv(GLenum pname, GLint *params)
5728{
5729 GLenum nativeType;
5730 unsigned int numParams = 0;
5731 getQueryParameterInfo(pname, &nativeType, &numParams);
5732
5733 if (nativeType == GL_INT)
5734 {
5735 getIntegervImpl(pname, params);
5736 }
5737 else
5738 {
5739 CastStateValues(this, nativeType, pname, numParams, params);
5740 }
5741}
5742
Brandon Jones59770802018-04-02 13:18:42 -07005743void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5744{
5745 getIntegerv(pname, data);
5746}
5747
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5749{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005750 // Don't resolve link if checking the link completion status.
5751 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5752 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005753 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005754 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755}
5756
Brandon Jones59770802018-04-02 13:18:42 -07005757void Context::getProgramivRobust(GLuint program,
5758 GLenum pname,
5759 GLsizei bufSize,
5760 GLsizei *length,
5761 GLint *params)
5762{
5763 getProgramiv(program, pname, params);
5764}
5765
Jiajia Qin5451d532017-11-16 17:16:34 +08005766void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5767{
5768 UNIMPLEMENTED();
5769}
5770
Jamie Madillbe849e42017-05-02 15:49:00 -04005771void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005772{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005773 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005774 ASSERT(programObject);
5775 programObject->getInfoLog(bufsize, length, infolog);
5776}
5777
Jiajia Qin5451d532017-11-16 17:16:34 +08005778void Context::getProgramPipelineInfoLog(GLuint pipeline,
5779 GLsizei bufSize,
5780 GLsizei *length,
5781 GLchar *infoLog)
5782{
5783 UNIMPLEMENTED();
5784}
5785
Jamie Madillc1d770e2017-04-13 17:31:24 -04005786void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5787{
5788 Shader *shaderObject = getShader(shader);
5789 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005790 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005791}
5792
Brandon Jones59770802018-04-02 13:18:42 -07005793void Context::getShaderivRobust(GLuint shader,
5794 GLenum pname,
5795 GLsizei bufSize,
5796 GLsizei *length,
5797 GLint *params)
5798{
5799 getShaderiv(shader, pname, params);
5800}
5801
Jamie Madillc1d770e2017-04-13 17:31:24 -04005802void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5803{
5804 Shader *shaderObject = getShader(shader);
5805 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005806 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005807}
5808
5809void Context::getShaderPrecisionFormat(GLenum shadertype,
5810 GLenum precisiontype,
5811 GLint *range,
5812 GLint *precision)
5813{
5814 // TODO(jmadill): Compute shaders.
5815
5816 switch (shadertype)
5817 {
5818 case GL_VERTEX_SHADER:
5819 switch (precisiontype)
5820 {
5821 case GL_LOW_FLOAT:
5822 mCaps.vertexLowpFloat.get(range, precision);
5823 break;
5824 case GL_MEDIUM_FLOAT:
5825 mCaps.vertexMediumpFloat.get(range, precision);
5826 break;
5827 case GL_HIGH_FLOAT:
5828 mCaps.vertexHighpFloat.get(range, precision);
5829 break;
5830
5831 case GL_LOW_INT:
5832 mCaps.vertexLowpInt.get(range, precision);
5833 break;
5834 case GL_MEDIUM_INT:
5835 mCaps.vertexMediumpInt.get(range, precision);
5836 break;
5837 case GL_HIGH_INT:
5838 mCaps.vertexHighpInt.get(range, precision);
5839 break;
5840
5841 default:
5842 UNREACHABLE();
5843 return;
5844 }
5845 break;
5846
5847 case GL_FRAGMENT_SHADER:
5848 switch (precisiontype)
5849 {
5850 case GL_LOW_FLOAT:
5851 mCaps.fragmentLowpFloat.get(range, precision);
5852 break;
5853 case GL_MEDIUM_FLOAT:
5854 mCaps.fragmentMediumpFloat.get(range, precision);
5855 break;
5856 case GL_HIGH_FLOAT:
5857 mCaps.fragmentHighpFloat.get(range, precision);
5858 break;
5859
5860 case GL_LOW_INT:
5861 mCaps.fragmentLowpInt.get(range, precision);
5862 break;
5863 case GL_MEDIUM_INT:
5864 mCaps.fragmentMediumpInt.get(range, precision);
5865 break;
5866 case GL_HIGH_INT:
5867 mCaps.fragmentHighpInt.get(range, precision);
5868 break;
5869
5870 default:
5871 UNREACHABLE();
5872 return;
5873 }
5874 break;
5875
5876 default:
5877 UNREACHABLE();
5878 return;
5879 }
5880}
5881
5882void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5883{
5884 Shader *shaderObject = getShader(shader);
5885 ASSERT(shaderObject);
5886 shaderObject->getSource(bufsize, length, source);
5887}
5888
5889void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5890{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005891 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005892 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005893 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005894}
5895
Brandon Jones59770802018-04-02 13:18:42 -07005896void Context::getUniformfvRobust(GLuint program,
5897 GLint location,
5898 GLsizei bufSize,
5899 GLsizei *length,
5900 GLfloat *params)
5901{
5902 getUniformfv(program, location, params);
5903}
5904
Jamie Madillc1d770e2017-04-13 17:31:24 -04005905void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5906{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005907 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005908 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005909 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005910}
5911
Brandon Jones59770802018-04-02 13:18:42 -07005912void Context::getUniformivRobust(GLuint program,
5913 GLint location,
5914 GLsizei bufSize,
5915 GLsizei *length,
5916 GLint *params)
5917{
5918 getUniformiv(program, location, params);
5919}
5920
Jamie Madillc1d770e2017-04-13 17:31:24 -04005921GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5922{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005923 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005924 ASSERT(programObject);
5925 return programObject->getUniformLocation(name);
5926}
5927
5928GLboolean Context::isBuffer(GLuint buffer)
5929{
5930 if (buffer == 0)
5931 {
5932 return GL_FALSE;
5933 }
5934
5935 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5936}
5937
5938GLboolean Context::isEnabled(GLenum cap)
5939{
5940 return mGLState.getEnableFeature(cap);
5941}
5942
5943GLboolean Context::isFramebuffer(GLuint framebuffer)
5944{
5945 if (framebuffer == 0)
5946 {
5947 return GL_FALSE;
5948 }
5949
5950 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5951}
5952
5953GLboolean Context::isProgram(GLuint program)
5954{
5955 if (program == 0)
5956 {
5957 return GL_FALSE;
5958 }
5959
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005960 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005961}
5962
5963GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5964{
5965 if (renderbuffer == 0)
5966 {
5967 return GL_FALSE;
5968 }
5969
5970 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5971}
5972
5973GLboolean Context::isShader(GLuint shader)
5974{
5975 if (shader == 0)
5976 {
5977 return GL_FALSE;
5978 }
5979
5980 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5981}
5982
5983GLboolean Context::isTexture(GLuint texture)
5984{
5985 if (texture == 0)
5986 {
5987 return GL_FALSE;
5988 }
5989
5990 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5991}
5992
5993void Context::linkProgram(GLuint program)
5994{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005995 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005996 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005997 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005998
5999 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
6000 // don't need to worry that:
6001 // 1. Draw calls after link use the new executable code or the old one depending on the link
6002 // result.
6003 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
6004 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
6005 // ProgramD3D.
6006 if (programObject->isInUse())
6007 {
Jamie Madill785e8a02018-10-04 17:42:00 -04006008 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006009 if (programObject->isLinked())
6010 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006011 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006012 }
jchen107ae70d82018-07-06 13:47:01 +08006013 mStateCache.onProgramExecutableChange(this);
6014 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006015}
6016
6017void Context::releaseShaderCompiler()
6018{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006019 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006020}
6021
6022void Context::shaderBinary(GLsizei n,
6023 const GLuint *shaders,
6024 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006025 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006026 GLsizei length)
6027{
6028 // No binary shader formats are supported.
6029 UNIMPLEMENTED();
6030}
6031
Olli Etuaho0ca09752018-09-24 11:00:50 +03006032void Context::bindFragDataLocationIndexed(GLuint program,
6033 GLuint colorNumber,
6034 GLuint index,
6035 const char *name)
6036{
6037 Program *programObject = getProgramNoResolveLink(program);
6038 programObject->bindFragmentOutputLocation(colorNumber, name);
6039 programObject->bindFragmentOutputIndex(index, name);
6040}
6041
6042void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6043{
6044 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6045}
6046
6047int Context::getFragDataIndex(GLuint program, const char *name)
6048{
6049 Program *programObject = getProgramResolveLink(program);
6050 return programObject->getFragDataIndex(name);
6051}
6052
6053int Context::getProgramResourceLocationIndex(GLuint program,
6054 GLenum programInterface,
6055 const char *name)
6056{
6057 Program *programObject = getProgramResolveLink(program);
6058 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6059 return programObject->getFragDataIndex(name);
6060}
6061
Jamie Madillc1d770e2017-04-13 17:31:24 -04006062void Context::shaderSource(GLuint shader,
6063 GLsizei count,
6064 const GLchar *const *string,
6065 const GLint *length)
6066{
6067 Shader *shaderObject = getShader(shader);
6068 ASSERT(shaderObject);
6069 shaderObject->setSource(count, string, length);
6070}
6071
6072void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6073{
6074 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6075}
6076
6077void Context::stencilMask(GLuint mask)
6078{
6079 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6080}
6081
6082void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6083{
6084 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6085}
6086
6087void Context::uniform1f(GLint location, GLfloat x)
6088{
6089 Program *program = mGLState.getProgram();
6090 program->setUniform1fv(location, 1, &x);
6091}
6092
6093void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6094{
6095 Program *program = mGLState.getProgram();
6096 program->setUniform1fv(location, count, v);
6097}
6098
Jamie Madill7e4eff12018-08-08 15:49:26 -04006099void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006100{
Jamie Madille3e680c2018-12-03 17:49:08 -05006101 program->setUniform1iv(this, location, count, v);
6102}
6103
6104void Context::onSamplerUniformChange(size_t textureUnitIndex)
6105{
6106 mGLState.onActiveTextureChange(this, textureUnitIndex);
6107 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006108}
6109
Jamie Madill7e4eff12018-08-08 15:49:26 -04006110void Context::uniform1i(GLint location, GLint x)
6111{
6112 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6113}
6114
Jamie Madillc1d770e2017-04-13 17:31:24 -04006115void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6116{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006117 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006118}
6119
6120void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6121{
6122 GLfloat xy[2] = {x, y};
6123 Program *program = mGLState.getProgram();
6124 program->setUniform2fv(location, 1, xy);
6125}
6126
6127void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6128{
6129 Program *program = mGLState.getProgram();
6130 program->setUniform2fv(location, count, v);
6131}
6132
6133void Context::uniform2i(GLint location, GLint x, GLint y)
6134{
6135 GLint xy[2] = {x, y};
6136 Program *program = mGLState.getProgram();
6137 program->setUniform2iv(location, 1, xy);
6138}
6139
6140void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6141{
6142 Program *program = mGLState.getProgram();
6143 program->setUniform2iv(location, count, v);
6144}
6145
6146void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6147{
6148 GLfloat xyz[3] = {x, y, z};
6149 Program *program = mGLState.getProgram();
6150 program->setUniform3fv(location, 1, xyz);
6151}
6152
6153void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6154{
6155 Program *program = mGLState.getProgram();
6156 program->setUniform3fv(location, count, v);
6157}
6158
6159void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6160{
6161 GLint xyz[3] = {x, y, z};
6162 Program *program = mGLState.getProgram();
6163 program->setUniform3iv(location, 1, xyz);
6164}
6165
6166void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6167{
6168 Program *program = mGLState.getProgram();
6169 program->setUniform3iv(location, count, v);
6170}
6171
6172void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6173{
6174 GLfloat xyzw[4] = {x, y, z, w};
6175 Program *program = mGLState.getProgram();
6176 program->setUniform4fv(location, 1, xyzw);
6177}
6178
6179void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6180{
6181 Program *program = mGLState.getProgram();
6182 program->setUniform4fv(location, count, v);
6183}
6184
6185void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6186{
6187 GLint xyzw[4] = {x, y, z, w};
6188 Program *program = mGLState.getProgram();
6189 program->setUniform4iv(location, 1, xyzw);
6190}
6191
6192void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6193{
6194 Program *program = mGLState.getProgram();
6195 program->setUniform4iv(location, count, v);
6196}
6197
6198void Context::uniformMatrix2fv(GLint location,
6199 GLsizei count,
6200 GLboolean transpose,
6201 const GLfloat *value)
6202{
6203 Program *program = mGLState.getProgram();
6204 program->setUniformMatrix2fv(location, count, transpose, value);
6205}
6206
6207void Context::uniformMatrix3fv(GLint location,
6208 GLsizei count,
6209 GLboolean transpose,
6210 const GLfloat *value)
6211{
6212 Program *program = mGLState.getProgram();
6213 program->setUniformMatrix3fv(location, count, transpose, value);
6214}
6215
6216void Context::uniformMatrix4fv(GLint location,
6217 GLsizei count,
6218 GLboolean transpose,
6219 const GLfloat *value)
6220{
6221 Program *program = mGLState.getProgram();
6222 program->setUniformMatrix4fv(location, count, transpose, value);
6223}
6224
6225void Context::validateProgram(GLuint program)
6226{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006227 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006228 ASSERT(programObject);
6229 programObject->validate(mCaps);
6230}
6231
Jiajia Qin5451d532017-11-16 17:16:34 +08006232void Context::validateProgramPipeline(GLuint pipeline)
6233{
6234 UNIMPLEMENTED();
6235}
6236
Jamie Madilld04908b2017-06-09 14:15:35 -04006237void Context::getProgramBinary(GLuint program,
6238 GLsizei bufSize,
6239 GLsizei *length,
6240 GLenum *binaryFormat,
6241 void *binary)
6242{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006243 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006244 ASSERT(programObject != nullptr);
6245
Jamie Madill4f6592f2018-11-27 16:37:45 -05006246 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006247}
6248
6249void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6250{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006251 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006252 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006253
Jamie Madill4f6592f2018-11-27 16:37:45 -05006254 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006255 if (programObject->isInUse())
6256 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006257 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006258 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006259 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006260}
6261
Jamie Madillff325f12017-08-26 15:06:05 -04006262void Context::uniform1ui(GLint location, GLuint v0)
6263{
6264 Program *program = mGLState.getProgram();
6265 program->setUniform1uiv(location, 1, &v0);
6266}
6267
6268void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6269{
6270 Program *program = mGLState.getProgram();
6271 const GLuint xy[] = {v0, v1};
6272 program->setUniform2uiv(location, 1, xy);
6273}
6274
6275void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6276{
6277 Program *program = mGLState.getProgram();
6278 const GLuint xyz[] = {v0, v1, v2};
6279 program->setUniform3uiv(location, 1, xyz);
6280}
6281
6282void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6283{
6284 Program *program = mGLState.getProgram();
6285 const GLuint xyzw[] = {v0, v1, v2, v3};
6286 program->setUniform4uiv(location, 1, xyzw);
6287}
6288
6289void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6290{
6291 Program *program = mGLState.getProgram();
6292 program->setUniform1uiv(location, count, value);
6293}
6294void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6295{
6296 Program *program = mGLState.getProgram();
6297 program->setUniform2uiv(location, count, value);
6298}
6299
6300void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6301{
6302 Program *program = mGLState.getProgram();
6303 program->setUniform3uiv(location, count, value);
6304}
6305
6306void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6307{
6308 Program *program = mGLState.getProgram();
6309 program->setUniform4uiv(location, count, value);
6310}
6311
Jamie Madillf0e04492017-08-26 15:28:42 -04006312void Context::genQueries(GLsizei n, GLuint *ids)
6313{
6314 for (GLsizei i = 0; i < n; i++)
6315 {
6316 GLuint handle = mQueryHandleAllocator.allocate();
6317 mQueryMap.assign(handle, nullptr);
6318 ids[i] = handle;
6319 }
6320}
6321
6322void Context::deleteQueries(GLsizei n, const GLuint *ids)
6323{
6324 for (int i = 0; i < n; i++)
6325 {
6326 GLuint query = ids[i];
6327
6328 Query *queryObject = nullptr;
6329 if (mQueryMap.erase(query, &queryObject))
6330 {
6331 mQueryHandleAllocator.release(query);
6332 if (queryObject)
6333 {
6334 queryObject->release(this);
6335 }
6336 }
6337 }
6338}
6339
6340GLboolean Context::isQuery(GLuint id)
6341{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006342 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006343}
6344
Jamie Madillc8c95812017-08-26 18:40:09 -04006345void Context::uniformMatrix2x3fv(GLint location,
6346 GLsizei count,
6347 GLboolean transpose,
6348 const GLfloat *value)
6349{
6350 Program *program = mGLState.getProgram();
6351 program->setUniformMatrix2x3fv(location, count, transpose, value);
6352}
6353
6354void Context::uniformMatrix3x2fv(GLint location,
6355 GLsizei count,
6356 GLboolean transpose,
6357 const GLfloat *value)
6358{
6359 Program *program = mGLState.getProgram();
6360 program->setUniformMatrix3x2fv(location, count, transpose, value);
6361}
6362
6363void Context::uniformMatrix2x4fv(GLint location,
6364 GLsizei count,
6365 GLboolean transpose,
6366 const GLfloat *value)
6367{
6368 Program *program = mGLState.getProgram();
6369 program->setUniformMatrix2x4fv(location, count, transpose, value);
6370}
6371
6372void Context::uniformMatrix4x2fv(GLint location,
6373 GLsizei count,
6374 GLboolean transpose,
6375 const GLfloat *value)
6376{
6377 Program *program = mGLState.getProgram();
6378 program->setUniformMatrix4x2fv(location, count, transpose, value);
6379}
6380
6381void Context::uniformMatrix3x4fv(GLint location,
6382 GLsizei count,
6383 GLboolean transpose,
6384 const GLfloat *value)
6385{
6386 Program *program = mGLState.getProgram();
6387 program->setUniformMatrix3x4fv(location, count, transpose, value);
6388}
6389
6390void Context::uniformMatrix4x3fv(GLint location,
6391 GLsizei count,
6392 GLboolean transpose,
6393 const GLfloat *value)
6394{
6395 Program *program = mGLState.getProgram();
6396 program->setUniformMatrix4x3fv(location, count, transpose, value);
6397}
6398
Jamie Madilld7576732017-08-26 18:49:50 -04006399void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6400{
6401 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6402 {
6403 GLuint vertexArray = arrays[arrayIndex];
6404
6405 if (arrays[arrayIndex] != 0)
6406 {
6407 VertexArray *vertexArrayObject = nullptr;
6408 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6409 {
6410 if (vertexArrayObject != nullptr)
6411 {
6412 detachVertexArray(vertexArray);
6413 vertexArrayObject->onDestroy(this);
6414 }
6415
6416 mVertexArrayHandleAllocator.release(vertexArray);
6417 }
6418 }
6419 }
6420}
6421
6422void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6423{
6424 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6425 {
6426 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6427 mVertexArrayMap.assign(vertexArray, nullptr);
6428 arrays[arrayIndex] = vertexArray;
6429 }
6430}
6431
6432bool Context::isVertexArray(GLuint array)
6433{
6434 if (array == 0)
6435 {
6436 return GL_FALSE;
6437 }
6438
6439 VertexArray *vao = getVertexArray(array);
6440 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6441}
6442
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006443void Context::endTransformFeedback()
6444{
6445 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6446 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006447 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006448}
6449
6450void Context::transformFeedbackVaryings(GLuint program,
6451 GLsizei count,
6452 const GLchar *const *varyings,
6453 GLenum bufferMode)
6454{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006455 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006456 ASSERT(programObject);
6457 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6458}
6459
6460void Context::getTransformFeedbackVarying(GLuint program,
6461 GLuint index,
6462 GLsizei bufSize,
6463 GLsizei *length,
6464 GLsizei *size,
6465 GLenum *type,
6466 GLchar *name)
6467{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006468 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006469 ASSERT(programObject);
6470 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6471}
6472
6473void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6474{
6475 for (int i = 0; i < n; i++)
6476 {
6477 GLuint transformFeedback = ids[i];
6478 if (transformFeedback == 0)
6479 {
6480 continue;
6481 }
6482
6483 TransformFeedback *transformFeedbackObject = nullptr;
6484 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6485 {
6486 if (transformFeedbackObject != nullptr)
6487 {
6488 detachTransformFeedback(transformFeedback);
6489 transformFeedbackObject->release(this);
6490 }
6491
6492 mTransformFeedbackHandleAllocator.release(transformFeedback);
6493 }
6494 }
6495}
6496
6497void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6498{
6499 for (int i = 0; i < n; i++)
6500 {
6501 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6502 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6503 ids[i] = transformFeedback;
6504 }
6505}
6506
6507bool Context::isTransformFeedback(GLuint id)
6508{
6509 if (id == 0)
6510 {
6511 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6512 // returns FALSE
6513 return GL_FALSE;
6514 }
6515
6516 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6517 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6518}
6519
6520void Context::pauseTransformFeedback()
6521{
6522 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6523 transformFeedback->pause();
6524}
6525
6526void Context::resumeTransformFeedback()
6527{
6528 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6529 transformFeedback->resume();
6530}
6531
Jamie Madill12e957f2017-08-26 21:42:26 -04006532void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6533{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006534 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006535 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006536}
6537
Brandon Jones59770802018-04-02 13:18:42 -07006538void Context::getUniformuivRobust(GLuint program,
6539 GLint location,
6540 GLsizei bufSize,
6541 GLsizei *length,
6542 GLuint *params)
6543{
6544 getUniformuiv(program, location, params);
6545}
6546
Jamie Madill12e957f2017-08-26 21:42:26 -04006547GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6548{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006549 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006550 return programObject->getFragDataLocation(name);
6551}
6552
6553void Context::getUniformIndices(GLuint program,
6554 GLsizei uniformCount,
6555 const GLchar *const *uniformNames,
6556 GLuint *uniformIndices)
6557{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006558 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006559 if (!programObject->isLinked())
6560 {
6561 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6562 {
6563 uniformIndices[uniformId] = GL_INVALID_INDEX;
6564 }
6565 }
6566 else
6567 {
6568 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6569 {
6570 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6571 }
6572 }
6573}
6574
6575void Context::getActiveUniformsiv(GLuint program,
6576 GLsizei uniformCount,
6577 const GLuint *uniformIndices,
6578 GLenum pname,
6579 GLint *params)
6580{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006581 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006582 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6583 {
6584 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006585 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006586 }
6587}
6588
6589GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6590{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006591 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006592 return programObject->getUniformBlockIndex(uniformBlockName);
6593}
6594
6595void Context::getActiveUniformBlockiv(GLuint program,
6596 GLuint uniformBlockIndex,
6597 GLenum pname,
6598 GLint *params)
6599{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006600 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006601 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6602}
6603
Brandon Jones59770802018-04-02 13:18:42 -07006604void Context::getActiveUniformBlockivRobust(GLuint program,
6605 GLuint uniformBlockIndex,
6606 GLenum pname,
6607 GLsizei bufSize,
6608 GLsizei *length,
6609 GLint *params)
6610{
6611 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6612}
6613
Jamie Madill12e957f2017-08-26 21:42:26 -04006614void Context::getActiveUniformBlockName(GLuint program,
6615 GLuint uniformBlockIndex,
6616 GLsizei bufSize,
6617 GLsizei *length,
6618 GLchar *uniformBlockName)
6619{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006620 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006621 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6622}
6623
6624void Context::uniformBlockBinding(GLuint program,
6625 GLuint uniformBlockIndex,
6626 GLuint uniformBlockBinding)
6627{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006628 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006629 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006630
Jamie Madill956ab4d2018-10-10 16:13:03 -04006631 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006632 if (programObject->isInUse())
6633 {
6634 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006635 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006636 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006637}
6638
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006639GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6640{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006641 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6642 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006643
Jamie Madill70b5bb02017-08-28 13:32:37 -04006644 Sync *syncObject = getSync(syncHandle);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006645 if (syncObject->set(this, condition, flags) == angle::Result::Stop())
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006646 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006647 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006648 return nullptr;
6649 }
6650
Jamie Madill70b5bb02017-08-28 13:32:37 -04006651 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006652}
6653
6654GLboolean Context::isSync(GLsync sync)
6655{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006656 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006657}
6658
6659GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6660{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006661 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006662
6663 GLenum result = GL_WAIT_FAILED;
Jamie Madill4f6592f2018-11-27 16:37:45 -05006664 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop())
6665 {
6666 return GL_WAIT_FAILED;
6667 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006668 return result;
6669}
6670
6671void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6672{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006673 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006674 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006675}
6676
6677void Context::getInteger64v(GLenum pname, GLint64 *params)
6678{
6679 GLenum nativeType = GL_NONE;
6680 unsigned int numParams = 0;
6681 getQueryParameterInfo(pname, &nativeType, &numParams);
6682
6683 if (nativeType == GL_INT_64_ANGLEX)
6684 {
6685 getInteger64vImpl(pname, params);
6686 }
6687 else
6688 {
6689 CastStateValues(this, nativeType, pname, numParams, params);
6690 }
6691}
6692
Brandon Jones59770802018-04-02 13:18:42 -07006693void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6694{
6695 getInteger64v(pname, data);
6696}
6697
Corentin Wallez336129f2017-10-17 15:55:40 -04006698void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006699{
6700 Buffer *buffer = mGLState.getTargetBuffer(target);
6701 QueryBufferParameteri64v(buffer, pname, params);
6702}
6703
Brandon Jones59770802018-04-02 13:18:42 -07006704void Context::getBufferParameteri64vRobust(BufferBinding target,
6705 GLenum pname,
6706 GLsizei bufSize,
6707 GLsizei *length,
6708 GLint64 *params)
6709{
6710 getBufferParameteri64v(target, pname, params);
6711}
6712
Jamie Madill3ef140a2017-08-26 23:11:21 -04006713void Context::genSamplers(GLsizei count, GLuint *samplers)
6714{
6715 for (int i = 0; i < count; i++)
6716 {
6717 samplers[i] = mState.mSamplers->createSampler();
6718 }
6719}
6720
6721void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6722{
6723 for (int i = 0; i < count; i++)
6724 {
6725 GLuint sampler = samplers[i];
6726
6727 if (mState.mSamplers->getSampler(sampler))
6728 {
6729 detachSampler(sampler);
6730 }
6731
6732 mState.mSamplers->deleteObject(this, sampler);
6733 }
6734}
6735
6736void Context::getInternalformativ(GLenum target,
6737 GLenum internalformat,
6738 GLenum pname,
6739 GLsizei bufSize,
6740 GLint *params)
6741{
6742 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6743 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6744}
6745
Brandon Jones59770802018-04-02 13:18:42 -07006746void Context::getInternalformativRobust(GLenum target,
6747 GLenum internalformat,
6748 GLenum pname,
6749 GLsizei bufSize,
6750 GLsizei *length,
6751 GLint *params)
6752{
6753 getInternalformativ(target, internalformat, pname, bufSize, params);
6754}
6755
Jiajia Qin5451d532017-11-16 17:16:34 +08006756void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6757{
6758 programUniform1iv(program, location, 1, &v0);
6759}
6760
6761void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6762{
6763 GLint xy[2] = {v0, v1};
6764 programUniform2iv(program, location, 1, xy);
6765}
6766
6767void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6768{
6769 GLint xyz[3] = {v0, v1, v2};
6770 programUniform3iv(program, location, 1, xyz);
6771}
6772
6773void Context::programUniform4i(GLuint program,
6774 GLint location,
6775 GLint v0,
6776 GLint v1,
6777 GLint v2,
6778 GLint v3)
6779{
6780 GLint xyzw[4] = {v0, v1, v2, v3};
6781 programUniform4iv(program, location, 1, xyzw);
6782}
6783
6784void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6785{
6786 programUniform1uiv(program, location, 1, &v0);
6787}
6788
6789void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6790{
6791 GLuint xy[2] = {v0, v1};
6792 programUniform2uiv(program, location, 1, xy);
6793}
6794
6795void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6796{
6797 GLuint xyz[3] = {v0, v1, v2};
6798 programUniform3uiv(program, location, 1, xyz);
6799}
6800
6801void Context::programUniform4ui(GLuint program,
6802 GLint location,
6803 GLuint v0,
6804 GLuint v1,
6805 GLuint v2,
6806 GLuint v3)
6807{
6808 GLuint xyzw[4] = {v0, v1, v2, v3};
6809 programUniform4uiv(program, location, 1, xyzw);
6810}
6811
6812void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6813{
6814 programUniform1fv(program, location, 1, &v0);
6815}
6816
6817void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6818{
6819 GLfloat xy[2] = {v0, v1};
6820 programUniform2fv(program, location, 1, xy);
6821}
6822
6823void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6824{
6825 GLfloat xyz[3] = {v0, v1, v2};
6826 programUniform3fv(program, location, 1, xyz);
6827}
6828
6829void Context::programUniform4f(GLuint program,
6830 GLint location,
6831 GLfloat v0,
6832 GLfloat v1,
6833 GLfloat v2,
6834 GLfloat v3)
6835{
6836 GLfloat xyzw[4] = {v0, v1, v2, v3};
6837 programUniform4fv(program, location, 1, xyzw);
6838}
6839
Jamie Madill81c2e252017-09-09 23:32:46 -04006840void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6841{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006842 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006843 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006844 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006845}
6846
Jiajia Qin5451d532017-11-16 17:16:34 +08006847void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6848{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006849 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006850 ASSERT(programObject);
6851 programObject->setUniform2iv(location, count, value);
6852}
6853
6854void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6855{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006856 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006857 ASSERT(programObject);
6858 programObject->setUniform3iv(location, count, value);
6859}
6860
6861void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6862{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006863 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006864 ASSERT(programObject);
6865 programObject->setUniform4iv(location, count, value);
6866}
6867
6868void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6869{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006870 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006871 ASSERT(programObject);
6872 programObject->setUniform1uiv(location, count, value);
6873}
6874
6875void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6876{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006877 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006878 ASSERT(programObject);
6879 programObject->setUniform2uiv(location, count, value);
6880}
6881
6882void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6883{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006884 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006885 ASSERT(programObject);
6886 programObject->setUniform3uiv(location, count, value);
6887}
6888
6889void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6890{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006891 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006892 ASSERT(programObject);
6893 programObject->setUniform4uiv(location, count, value);
6894}
6895
6896void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6897{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006898 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006899 ASSERT(programObject);
6900 programObject->setUniform1fv(location, count, value);
6901}
6902
6903void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6904{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006905 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006906 ASSERT(programObject);
6907 programObject->setUniform2fv(location, count, value);
6908}
6909
6910void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6911{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006912 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006913 ASSERT(programObject);
6914 programObject->setUniform3fv(location, count, value);
6915}
6916
6917void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6918{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006919 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006920 ASSERT(programObject);
6921 programObject->setUniform4fv(location, count, value);
6922}
6923
6924void Context::programUniformMatrix2fv(GLuint program,
6925 GLint location,
6926 GLsizei count,
6927 GLboolean transpose,
6928 const GLfloat *value)
6929{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006930 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006931 ASSERT(programObject);
6932 programObject->setUniformMatrix2fv(location, count, transpose, value);
6933}
6934
6935void Context::programUniformMatrix3fv(GLuint program,
6936 GLint location,
6937 GLsizei count,
6938 GLboolean transpose,
6939 const GLfloat *value)
6940{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006941 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006942 ASSERT(programObject);
6943 programObject->setUniformMatrix3fv(location, count, transpose, value);
6944}
6945
6946void Context::programUniformMatrix4fv(GLuint program,
6947 GLint location,
6948 GLsizei count,
6949 GLboolean transpose,
6950 const GLfloat *value)
6951{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006952 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006953 ASSERT(programObject);
6954 programObject->setUniformMatrix4fv(location, count, transpose, value);
6955}
6956
6957void Context::programUniformMatrix2x3fv(GLuint program,
6958 GLint location,
6959 GLsizei count,
6960 GLboolean transpose,
6961 const GLfloat *value)
6962{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006963 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006964 ASSERT(programObject);
6965 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6966}
6967
6968void Context::programUniformMatrix3x2fv(GLuint program,
6969 GLint location,
6970 GLsizei count,
6971 GLboolean transpose,
6972 const GLfloat *value)
6973{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006974 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006975 ASSERT(programObject);
6976 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6977}
6978
6979void Context::programUniformMatrix2x4fv(GLuint program,
6980 GLint location,
6981 GLsizei count,
6982 GLboolean transpose,
6983 const GLfloat *value)
6984{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006985 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006986 ASSERT(programObject);
6987 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6988}
6989
6990void Context::programUniformMatrix4x2fv(GLuint program,
6991 GLint location,
6992 GLsizei count,
6993 GLboolean transpose,
6994 const GLfloat *value)
6995{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006996 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006997 ASSERT(programObject);
6998 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6999}
7000
7001void Context::programUniformMatrix3x4fv(GLuint program,
7002 GLint location,
7003 GLsizei count,
7004 GLboolean transpose,
7005 const GLfloat *value)
7006{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007007 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007008 ASSERT(programObject);
7009 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7010}
7011
7012void Context::programUniformMatrix4x3fv(GLuint program,
7013 GLint location,
7014 GLsizei count,
7015 GLboolean transpose,
7016 const GLfloat *value)
7017{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007018 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007019 ASSERT(programObject);
7020 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7021}
7022
James Darpiniane8a93c62018-01-04 18:02:24 -08007023bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7024{
7025 return mGLState.isCurrentTransformFeedback(tf);
7026}
James Darpiniane8a93c62018-01-04 18:02:24 -08007027
Yunchao Hea336b902017-08-02 16:05:21 +08007028void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7029{
7030 for (int i = 0; i < count; i++)
7031 {
7032 pipelines[i] = createProgramPipeline();
7033 }
7034}
7035
7036void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7037{
7038 for (int i = 0; i < count; i++)
7039 {
7040 if (pipelines[i] != 0)
7041 {
7042 deleteProgramPipeline(pipelines[i]);
7043 }
7044 }
7045}
7046
7047GLboolean Context::isProgramPipeline(GLuint pipeline)
7048{
7049 if (pipeline == 0)
7050 {
7051 return GL_FALSE;
7052 }
7053
7054 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7055}
7056
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007057void Context::finishFenceNV(GLuint fence)
7058{
7059 FenceNV *fenceObject = getFenceNV(fence);
7060
7061 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007062 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007063}
7064
7065void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7066{
7067 FenceNV *fenceObject = getFenceNV(fence);
7068
7069 ASSERT(fenceObject && fenceObject->isSet());
7070
7071 switch (pname)
7072 {
7073 case GL_FENCE_STATUS_NV:
7074 {
7075 // GL_NV_fence spec:
7076 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7077 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7078 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7079 GLboolean status = GL_TRUE;
7080 if (fenceObject->getStatus() != GL_TRUE)
7081 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007082 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007083 }
7084 *params = status;
7085 break;
7086 }
7087
7088 case GL_FENCE_CONDITION_NV:
7089 {
7090 *params = static_cast<GLint>(fenceObject->getCondition());
7091 break;
7092 }
7093
7094 default:
7095 UNREACHABLE();
7096 }
7097}
7098
7099void Context::getTranslatedShaderSource(GLuint shader,
7100 GLsizei bufsize,
7101 GLsizei *length,
7102 GLchar *source)
7103{
7104 Shader *shaderObject = getShader(shader);
7105 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007106 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007107}
7108
7109void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7110{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007111 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007112 ASSERT(programObject);
7113
7114 programObject->getUniformfv(this, location, params);
7115}
7116
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007117void Context::getnUniformfvRobust(GLuint program,
7118 GLint location,
7119 GLsizei bufSize,
7120 GLsizei *length,
7121 GLfloat *params)
7122{
7123 UNIMPLEMENTED();
7124}
7125
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007126void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7127{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007128 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007129 ASSERT(programObject);
7130
7131 programObject->getUniformiv(this, location, params);
7132}
7133
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007134void Context::getnUniformivRobust(GLuint program,
7135 GLint location,
7136 GLsizei bufSize,
7137 GLsizei *length,
7138 GLint *params)
7139{
7140 UNIMPLEMENTED();
7141}
7142
7143void Context::getnUniformuivRobust(GLuint program,
7144 GLint location,
7145 GLsizei bufSize,
7146 GLsizei *length,
7147 GLuint *params)
7148{
7149 UNIMPLEMENTED();
7150}
7151
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007152GLboolean Context::isFenceNV(GLuint fence)
7153{
7154 FenceNV *fenceObject = getFenceNV(fence);
7155
7156 if (fenceObject == nullptr)
7157 {
7158 return GL_FALSE;
7159 }
7160
7161 // GL_NV_fence spec:
7162 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7163 // existing fence.
7164 return fenceObject->isSet();
7165}
7166
7167void Context::readnPixels(GLint x,
7168 GLint y,
7169 GLsizei width,
7170 GLsizei height,
7171 GLenum format,
7172 GLenum type,
7173 GLsizei bufSize,
7174 void *data)
7175{
7176 return readPixels(x, y, width, height, format, type, data);
7177}
7178
Jamie Madill007530e2017-12-28 14:27:04 -05007179void Context::setFenceNV(GLuint fence, GLenum condition)
7180{
7181 ASSERT(condition == GL_ALL_COMPLETED_NV);
7182
7183 FenceNV *fenceObject = getFenceNV(fence);
7184 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007185 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007186}
7187
7188GLboolean Context::testFenceNV(GLuint fence)
7189{
7190 FenceNV *fenceObject = getFenceNV(fence);
7191
7192 ASSERT(fenceObject != nullptr);
7193 ASSERT(fenceObject->isSet() == GL_TRUE);
7194
7195 GLboolean result = GL_TRUE;
Jamie Madill4f6592f2018-11-27 16:37:45 -05007196 if (fenceObject->test(this, &result) == angle::Result::Stop())
Jamie Madill007530e2017-12-28 14:27:04 -05007197 {
Jamie Madill007530e2017-12-28 14:27:04 -05007198 return GL_TRUE;
7199 }
7200
7201 return result;
7202}
7203
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007204void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007205{
7206 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007207 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007208 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007209}
7210
Jamie Madillfa920eb2018-01-04 11:45:50 -05007211void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007212{
7213 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007214 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007215 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007216}
7217
Jamie Madillfa920eb2018-01-04 11:45:50 -05007218void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7219{
7220 UNIMPLEMENTED();
7221}
7222
Jamie Madill5b772312018-03-08 20:28:32 -05007223bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7224{
7225 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7226 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7227 // to the fact that it is stored internally as a float, and so would require conversion
7228 // if returned from Context::getIntegerv. Since this conversion is already implemented
7229 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7230 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7231 // application.
7232 switch (pname)
7233 {
7234 case GL_COMPRESSED_TEXTURE_FORMATS:
7235 {
7236 *type = GL_INT;
7237 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7238 return true;
7239 }
7240 case GL_SHADER_BINARY_FORMATS:
7241 {
7242 *type = GL_INT;
7243 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7244 return true;
7245 }
7246
7247 case GL_MAX_VERTEX_ATTRIBS:
7248 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7249 case GL_MAX_VARYING_VECTORS:
7250 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7251 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7252 case GL_MAX_TEXTURE_IMAGE_UNITS:
7253 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7254 case GL_MAX_RENDERBUFFER_SIZE:
7255 case GL_NUM_SHADER_BINARY_FORMATS:
7256 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7257 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007258 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7259 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007260 case GL_RENDERBUFFER_BINDING:
7261 case GL_CURRENT_PROGRAM:
7262 case GL_PACK_ALIGNMENT:
7263 case GL_UNPACK_ALIGNMENT:
7264 case GL_GENERATE_MIPMAP_HINT:
7265 case GL_RED_BITS:
7266 case GL_GREEN_BITS:
7267 case GL_BLUE_BITS:
7268 case GL_ALPHA_BITS:
7269 case GL_DEPTH_BITS:
7270 case GL_STENCIL_BITS:
7271 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7272 case GL_CULL_FACE_MODE:
7273 case GL_FRONT_FACE:
7274 case GL_ACTIVE_TEXTURE:
7275 case GL_STENCIL_FUNC:
7276 case GL_STENCIL_VALUE_MASK:
7277 case GL_STENCIL_REF:
7278 case GL_STENCIL_FAIL:
7279 case GL_STENCIL_PASS_DEPTH_FAIL:
7280 case GL_STENCIL_PASS_DEPTH_PASS:
7281 case GL_STENCIL_BACK_FUNC:
7282 case GL_STENCIL_BACK_VALUE_MASK:
7283 case GL_STENCIL_BACK_REF:
7284 case GL_STENCIL_BACK_FAIL:
7285 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7286 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7287 case GL_DEPTH_FUNC:
7288 case GL_BLEND_SRC_RGB:
7289 case GL_BLEND_SRC_ALPHA:
7290 case GL_BLEND_DST_RGB:
7291 case GL_BLEND_DST_ALPHA:
7292 case GL_BLEND_EQUATION_RGB:
7293 case GL_BLEND_EQUATION_ALPHA:
7294 case GL_STENCIL_WRITEMASK:
7295 case GL_STENCIL_BACK_WRITEMASK:
7296 case GL_STENCIL_CLEAR_VALUE:
7297 case GL_SUBPIXEL_BITS:
7298 case GL_MAX_TEXTURE_SIZE:
7299 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7300 case GL_SAMPLE_BUFFERS:
7301 case GL_SAMPLES:
7302 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7303 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7304 case GL_TEXTURE_BINDING_2D:
7305 case GL_TEXTURE_BINDING_CUBE_MAP:
7306 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7307 {
7308 *type = GL_INT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7313 {
7314 if (!getExtensions().packReverseRowOrder)
7315 {
7316 return false;
7317 }
7318 *type = GL_INT;
7319 *numParams = 1;
7320 return true;
7321 }
7322 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7323 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7324 {
7325 if (!getExtensions().textureRectangle)
7326 {
7327 return false;
7328 }
7329 *type = GL_INT;
7330 *numParams = 1;
7331 return true;
7332 }
7333 case GL_MAX_DRAW_BUFFERS_EXT:
7334 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7335 {
7336 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7337 {
7338 return false;
7339 }
7340 *type = GL_INT;
7341 *numParams = 1;
7342 return true;
7343 }
7344 case GL_MAX_VIEWPORT_DIMS:
7345 {
7346 *type = GL_INT;
7347 *numParams = 2;
7348 return true;
7349 }
7350 case GL_VIEWPORT:
7351 case GL_SCISSOR_BOX:
7352 {
7353 *type = GL_INT;
7354 *numParams = 4;
7355 return true;
7356 }
7357 case GL_SHADER_COMPILER:
7358 case GL_SAMPLE_COVERAGE_INVERT:
7359 case GL_DEPTH_WRITEMASK:
7360 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7361 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7362 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7363 // bool-natural
7364 case GL_SAMPLE_COVERAGE:
7365 case GL_SCISSOR_TEST:
7366 case GL_STENCIL_TEST:
7367 case GL_DEPTH_TEST:
7368 case GL_BLEND:
7369 case GL_DITHER:
7370 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7371 {
7372 *type = GL_BOOL;
7373 *numParams = 1;
7374 return true;
7375 }
7376 case GL_COLOR_WRITEMASK:
7377 {
7378 *type = GL_BOOL;
7379 *numParams = 4;
7380 return true;
7381 }
7382 case GL_POLYGON_OFFSET_FACTOR:
7383 case GL_POLYGON_OFFSET_UNITS:
7384 case GL_SAMPLE_COVERAGE_VALUE:
7385 case GL_DEPTH_CLEAR_VALUE:
7386 case GL_LINE_WIDTH:
7387 {
7388 *type = GL_FLOAT;
7389 *numParams = 1;
7390 return true;
7391 }
7392 case GL_ALIASED_LINE_WIDTH_RANGE:
7393 case GL_ALIASED_POINT_SIZE_RANGE:
7394 case GL_DEPTH_RANGE:
7395 {
7396 *type = GL_FLOAT;
7397 *numParams = 2;
7398 return true;
7399 }
7400 case GL_COLOR_CLEAR_VALUE:
7401 case GL_BLEND_COLOR:
7402 {
7403 *type = GL_FLOAT;
7404 *numParams = 4;
7405 return true;
7406 }
7407 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7408 if (!getExtensions().textureFilterAnisotropic)
7409 {
7410 return false;
7411 }
7412 *type = GL_FLOAT;
7413 *numParams = 1;
7414 return true;
7415 case GL_TIMESTAMP_EXT:
7416 if (!getExtensions().disjointTimerQuery)
7417 {
7418 return false;
7419 }
7420 *type = GL_INT_64_ANGLEX;
7421 *numParams = 1;
7422 return true;
7423 case GL_GPU_DISJOINT_EXT:
7424 if (!getExtensions().disjointTimerQuery)
7425 {
7426 return false;
7427 }
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 case GL_COVERAGE_MODULATION_CHROMIUM:
7432 if (!getExtensions().framebufferMixedSamples)
7433 {
7434 return false;
7435 }
7436 *type = GL_INT;
7437 *numParams = 1;
7438 return true;
7439 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7440 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7441 {
7442 return false;
7443 }
7444 *type = GL_INT;
7445 *numParams = 1;
7446 return true;
7447 }
7448
7449 if (getExtensions().debug)
7450 {
7451 switch (pname)
7452 {
7453 case GL_DEBUG_LOGGED_MESSAGES:
7454 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7455 case GL_DEBUG_GROUP_STACK_DEPTH:
7456 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7457 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7458 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7459 case GL_MAX_LABEL_LENGTH:
7460 *type = GL_INT;
7461 *numParams = 1;
7462 return true;
7463
7464 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7465 case GL_DEBUG_OUTPUT:
7466 *type = GL_BOOL;
7467 *numParams = 1;
7468 return true;
7469 }
7470 }
7471
7472 if (getExtensions().multisampleCompatibility)
7473 {
7474 switch (pname)
7475 {
7476 case GL_MULTISAMPLE_EXT:
7477 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7478 *type = GL_BOOL;
7479 *numParams = 1;
7480 return true;
7481 }
7482 }
7483
7484 if (getExtensions().pathRendering)
7485 {
7486 switch (pname)
7487 {
7488 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7489 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7490 *type = GL_FLOAT;
7491 *numParams = 16;
7492 return true;
7493 }
7494 }
7495
7496 if (getExtensions().bindGeneratesResource)
7497 {
7498 switch (pname)
7499 {
7500 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7501 *type = GL_BOOL;
7502 *numParams = 1;
7503 return true;
7504 }
7505 }
7506
7507 if (getExtensions().clientArrays)
7508 {
7509 switch (pname)
7510 {
7511 case GL_CLIENT_ARRAYS_ANGLE:
7512 *type = GL_BOOL;
7513 *numParams = 1;
7514 return true;
7515 }
7516 }
7517
7518 if (getExtensions().sRGBWriteControl)
7519 {
7520 switch (pname)
7521 {
7522 case GL_FRAMEBUFFER_SRGB_EXT:
7523 *type = GL_BOOL;
7524 *numParams = 1;
7525 return true;
7526 }
7527 }
7528
7529 if (getExtensions().robustResourceInitialization &&
7530 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7531 {
7532 *type = GL_BOOL;
7533 *numParams = 1;
7534 return true;
7535 }
7536
7537 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7538 {
7539 *type = GL_BOOL;
7540 *numParams = 1;
7541 return true;
7542 }
7543
jchen1082af6202018-06-22 10:59:52 +08007544 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7545 {
7546 *type = GL_INT;
7547 *numParams = 1;
7548 return true;
7549 }
7550
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007551 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7552 {
7553 *type = GL_INT;
7554 *numParams = 1;
7555 return true;
7556 }
7557
Jamie Madill5b772312018-03-08 20:28:32 -05007558 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7559 switch (pname)
7560 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007561 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007562 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7563 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7564 {
7565 return false;
7566 }
7567 *type = GL_INT;
7568 *numParams = 1;
7569 return true;
7570
7571 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7572 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7573 {
7574 return false;
7575 }
7576 *type = GL_INT;
7577 *numParams = 1;
7578 return true;
7579
7580 case GL_PROGRAM_BINARY_FORMATS_OES:
7581 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7582 {
7583 return false;
7584 }
7585 *type = GL_INT;
7586 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7587 return true;
7588
7589 case GL_PACK_ROW_LENGTH:
7590 case GL_PACK_SKIP_ROWS:
7591 case GL_PACK_SKIP_PIXELS:
7592 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7593 {
7594 return false;
7595 }
7596 *type = GL_INT;
7597 *numParams = 1;
7598 return true;
7599 case GL_UNPACK_ROW_LENGTH:
7600 case GL_UNPACK_SKIP_ROWS:
7601 case GL_UNPACK_SKIP_PIXELS:
7602 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7603 {
7604 return false;
7605 }
7606 *type = GL_INT;
7607 *numParams = 1;
7608 return true;
7609 case GL_VERTEX_ARRAY_BINDING:
7610 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7611 {
7612 return false;
7613 }
7614 *type = GL_INT;
7615 *numParams = 1;
7616 return true;
7617 case GL_PIXEL_PACK_BUFFER_BINDING:
7618 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7619 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7620 {
7621 return false;
7622 }
7623 *type = GL_INT;
7624 *numParams = 1;
7625 return true;
7626 case GL_MAX_SAMPLES:
7627 {
7628 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7629 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7630 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7631 {
7632 return false;
7633 }
7634 *type = GL_INT;
7635 *numParams = 1;
7636 return true;
7637
7638 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7639 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7640 {
7641 return false;
7642 }
7643 *type = GL_INT;
7644 *numParams = 1;
7645 return true;
7646 }
7647 }
7648
7649 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7650 {
7651 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7652 {
7653 return false;
7654 }
7655 *type = GL_INT;
7656 *numParams = 1;
7657 return true;
7658 }
7659
7660 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7661 {
7662 *type = GL_INT;
7663 *numParams = 1;
7664 return true;
7665 }
7666
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007667 if (getClientVersion() < Version(2, 0))
7668 {
7669 switch (pname)
7670 {
7671 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007672 case GL_CLIENT_ACTIVE_TEXTURE:
7673 case GL_MATRIX_MODE:
7674 case GL_MAX_TEXTURE_UNITS:
7675 case GL_MAX_MODELVIEW_STACK_DEPTH:
7676 case GL_MAX_PROJECTION_STACK_DEPTH:
7677 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007678 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007679 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007680 case GL_VERTEX_ARRAY_STRIDE:
7681 case GL_NORMAL_ARRAY_STRIDE:
7682 case GL_COLOR_ARRAY_STRIDE:
7683 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7684 case GL_VERTEX_ARRAY_SIZE:
7685 case GL_COLOR_ARRAY_SIZE:
7686 case GL_TEXTURE_COORD_ARRAY_SIZE:
7687 case GL_VERTEX_ARRAY_TYPE:
7688 case GL_NORMAL_ARRAY_TYPE:
7689 case GL_COLOR_ARRAY_TYPE:
7690 case GL_TEXTURE_COORD_ARRAY_TYPE:
7691 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7692 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7693 case GL_COLOR_ARRAY_BUFFER_BINDING:
7694 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7695 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7696 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7697 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007698 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007699 case GL_MODELVIEW_STACK_DEPTH:
7700 case GL_PROJECTION_STACK_DEPTH:
7701 case GL_TEXTURE_STACK_DEPTH:
7702 case GL_LOGIC_OP_MODE:
7703 case GL_BLEND_SRC:
7704 case GL_BLEND_DST:
7705 case GL_PERSPECTIVE_CORRECTION_HINT:
7706 case GL_POINT_SMOOTH_HINT:
7707 case GL_LINE_SMOOTH_HINT:
7708 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007709 *type = GL_INT;
7710 *numParams = 1;
7711 return true;
7712 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007713 case GL_FOG_DENSITY:
7714 case GL_FOG_START:
7715 case GL_FOG_END:
7716 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007717 case GL_POINT_SIZE:
7718 case GL_POINT_SIZE_MIN:
7719 case GL_POINT_SIZE_MAX:
7720 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007721 *type = GL_FLOAT;
7722 *numParams = 1;
7723 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007724 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007725 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007726 *type = GL_FLOAT;
7727 *numParams = 2;
7728 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007729 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007730 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007731 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007732 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007733 *type = GL_FLOAT;
7734 *numParams = 4;
7735 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007736 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007737 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007738 *type = GL_FLOAT;
7739 *numParams = 3;
7740 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007741 case GL_MODELVIEW_MATRIX:
7742 case GL_PROJECTION_MATRIX:
7743 case GL_TEXTURE_MATRIX:
7744 *type = GL_FLOAT;
7745 *numParams = 16;
7746 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007747 case GL_LIGHT_MODEL_TWO_SIDE:
7748 *type = GL_BOOL;
7749 *numParams = 1;
7750 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007751 }
7752 }
7753
Jamie Madill5b772312018-03-08 20:28:32 -05007754 if (getClientVersion() < Version(3, 0))
7755 {
7756 return false;
7757 }
7758
7759 // Check for ES3.0+ parameter names
7760 switch (pname)
7761 {
7762 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7763 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7764 case GL_UNIFORM_BUFFER_BINDING:
7765 case GL_TRANSFORM_FEEDBACK_BINDING:
7766 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7767 case GL_COPY_READ_BUFFER_BINDING:
7768 case GL_COPY_WRITE_BUFFER_BINDING:
7769 case GL_SAMPLER_BINDING:
7770 case GL_READ_BUFFER:
7771 case GL_TEXTURE_BINDING_3D:
7772 case GL_TEXTURE_BINDING_2D_ARRAY:
7773 case GL_MAX_3D_TEXTURE_SIZE:
7774 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7775 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7776 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7777 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7778 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7779 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7780 case GL_MAX_VARYING_COMPONENTS:
7781 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7782 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7783 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7784 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7785 case GL_NUM_EXTENSIONS:
7786 case GL_MAJOR_VERSION:
7787 case GL_MINOR_VERSION:
7788 case GL_MAX_ELEMENTS_INDICES:
7789 case GL_MAX_ELEMENTS_VERTICES:
7790 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7791 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7792 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7793 case GL_UNPACK_IMAGE_HEIGHT:
7794 case GL_UNPACK_SKIP_IMAGES:
7795 {
7796 *type = GL_INT;
7797 *numParams = 1;
7798 return true;
7799 }
7800
7801 case GL_MAX_ELEMENT_INDEX:
7802 case GL_MAX_UNIFORM_BLOCK_SIZE:
7803 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7804 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7805 case GL_MAX_SERVER_WAIT_TIMEOUT:
7806 {
7807 *type = GL_INT_64_ANGLEX;
7808 *numParams = 1;
7809 return true;
7810 }
7811
7812 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7813 case GL_TRANSFORM_FEEDBACK_PAUSED:
7814 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7815 case GL_RASTERIZER_DISCARD:
7816 {
7817 *type = GL_BOOL;
7818 *numParams = 1;
7819 return true;
7820 }
7821
7822 case GL_MAX_TEXTURE_LOD_BIAS:
7823 {
7824 *type = GL_FLOAT;
7825 *numParams = 1;
7826 return true;
7827 }
7828 }
7829
7830 if (getExtensions().requestExtension)
7831 {
7832 switch (pname)
7833 {
7834 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7835 *type = GL_INT;
7836 *numParams = 1;
7837 return true;
7838 }
7839 }
7840
Yizhou Jiang7818a852018-09-06 15:02:04 +08007841 if (getExtensions().textureMultisample)
7842 {
7843 switch (pname)
7844 {
7845 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7846 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7847 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7848 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007849 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007850 *type = GL_INT;
7851 *numParams = 1;
7852 return true;
7853 }
7854 }
7855
Jamie Madill5b772312018-03-08 20:28:32 -05007856 if (getClientVersion() < Version(3, 1))
7857 {
7858 return false;
7859 }
7860
7861 switch (pname)
7862 {
7863 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7864 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7865 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7866 case GL_MAX_FRAMEBUFFER_WIDTH:
7867 case GL_MAX_FRAMEBUFFER_HEIGHT:
7868 case GL_MAX_FRAMEBUFFER_SAMPLES:
7869 case GL_MAX_SAMPLE_MASK_WORDS:
7870 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7871 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7872 case GL_MAX_INTEGER_SAMPLES:
7873 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7874 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7875 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7876 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7877 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7878 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7879 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7880 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7881 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7882 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7883 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7884 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7885 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7886 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7887 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7888 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7889 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7890 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7891 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7892 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7893 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7894 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7895 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7896 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7897 case GL_MAX_UNIFORM_LOCATIONS:
7898 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7899 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7900 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7901 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7902 case GL_MAX_IMAGE_UNITS:
7903 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7904 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7905 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7906 case GL_SHADER_STORAGE_BUFFER_BINDING:
7907 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7908 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007909 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007910 *type = GL_INT;
7911 *numParams = 1;
7912 return true;
7913 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7914 *type = GL_INT_64_ANGLEX;
7915 *numParams = 1;
7916 return true;
7917 case GL_SAMPLE_MASK:
7918 *type = GL_BOOL;
7919 *numParams = 1;
7920 return true;
7921 }
7922
7923 if (getExtensions().geometryShader)
7924 {
7925 switch (pname)
7926 {
7927 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7928 case GL_LAYER_PROVOKING_VERTEX_EXT:
7929 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7930 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7931 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7932 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7933 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7934 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7935 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7936 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7937 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7938 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7939 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7940 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7941 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7942 *type = GL_INT;
7943 *numParams = 1;
7944 return true;
7945 }
7946 }
7947
7948 return false;
7949}
7950
7951bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7952{
7953 if (getClientVersion() < Version(3, 0))
7954 {
7955 return false;
7956 }
7957
7958 switch (target)
7959 {
7960 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7961 case GL_UNIFORM_BUFFER_BINDING:
7962 {
7963 *type = GL_INT;
7964 *numParams = 1;
7965 return true;
7966 }
7967 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7968 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7969 case GL_UNIFORM_BUFFER_START:
7970 case GL_UNIFORM_BUFFER_SIZE:
7971 {
7972 *type = GL_INT_64_ANGLEX;
7973 *numParams = 1;
7974 return true;
7975 }
7976 }
7977
7978 if (getClientVersion() < Version(3, 1))
7979 {
7980 return false;
7981 }
7982
7983 switch (target)
7984 {
7985 case GL_IMAGE_BINDING_LAYERED:
7986 {
7987 *type = GL_BOOL;
7988 *numParams = 1;
7989 return true;
7990 }
7991 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7992 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7993 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7994 case GL_SHADER_STORAGE_BUFFER_BINDING:
7995 case GL_VERTEX_BINDING_BUFFER:
7996 case GL_VERTEX_BINDING_DIVISOR:
7997 case GL_VERTEX_BINDING_OFFSET:
7998 case GL_VERTEX_BINDING_STRIDE:
7999 case GL_SAMPLE_MASK_VALUE:
8000 case GL_IMAGE_BINDING_NAME:
8001 case GL_IMAGE_BINDING_LEVEL:
8002 case GL_IMAGE_BINDING_LAYER:
8003 case GL_IMAGE_BINDING_ACCESS:
8004 case GL_IMAGE_BINDING_FORMAT:
8005 {
8006 *type = GL_INT;
8007 *numParams = 1;
8008 return true;
8009 }
8010 case GL_ATOMIC_COUNTER_BUFFER_START:
8011 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8012 case GL_SHADER_STORAGE_BUFFER_START:
8013 case GL_SHADER_STORAGE_BUFFER_SIZE:
8014 {
8015 *type = GL_INT_64_ANGLEX;
8016 *numParams = 1;
8017 return true;
8018 }
8019 }
8020
8021 return false;
8022}
8023
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008024Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008025{
8026 return mState.mShaderPrograms->getProgram(handle);
8027}
8028
8029Shader *Context::getShader(GLuint handle) const
8030{
8031 return mState.mShaderPrograms->getShader(handle);
8032}
8033
Jamie Madill5b772312018-03-08 20:28:32 -05008034bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8035{
8036 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8037}
8038
8039bool Context::isFramebufferGenerated(GLuint framebuffer) const
8040{
8041 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8042}
8043
8044bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8045{
8046 return mState.mPipelines->isHandleGenerated(pipeline);
8047}
8048
8049bool Context::usingDisplayTextureShareGroup() const
8050{
8051 return mDisplayTextureShareGroup;
8052}
8053
8054GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8055{
8056 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8057 internalformat == GL_DEPTH_STENCIL
8058 ? GL_DEPTH24_STENCIL8
8059 : internalformat;
8060}
8061
jchen1082af6202018-06-22 10:59:52 +08008062void Context::maxShaderCompilerThreads(GLuint count)
8063{
jchen107ae70d82018-07-06 13:47:01 +08008064 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008065 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008066 // A count of zero specifies a request for no parallel compiling or linking.
8067 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8068 {
8069 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8070 }
8071 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008072}
8073
Jamie Madill2eb65032018-07-30 10:25:57 -04008074bool Context::isGLES1() const
8075{
8076 return mState.getClientVersion() < Version(2, 0);
8077}
8078
Jamie Madilla11819d2018-07-30 10:26:01 -04008079void Context::onSubjectStateChange(const Context *context,
8080 angle::SubjectIndex index,
8081 angle::SubjectMessage message)
8082{
Jamie Madilla11819d2018-07-30 10:26:01 -04008083 switch (index)
8084 {
8085 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008086 switch (message)
8087 {
8088 case angle::SubjectMessage::CONTENTS_CHANGED:
8089 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8090 mStateCache.onVertexArrayBufferContentsChange(this);
8091 break;
8092 case angle::SubjectMessage::RESOURCE_MAPPED:
8093 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8094 case angle::SubjectMessage::BINDING_CHANGED:
8095 mStateCache.onVertexArrayBufferStateChange(this);
8096 break;
8097 default:
8098 break;
8099 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008100 break;
8101
8102 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008103 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8104 {
8105 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8106 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008107 break;
8108
8109 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008110 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8111 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008112 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008113 }
8114 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008115 break;
8116
8117 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008118 if (index < kTextureMaxSubjectIndex)
8119 {
Jamie Madille3e680c2018-12-03 17:49:08 -05008120 mGLState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008121 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008122 }
Jamie Madille3e680c2018-12-03 17:49:08 -05008123 else if (index < kImageMaxSubjectIndex)
8124 {
8125 mGLState.onImageStateChange(this, index - kImage0SubjectIndex);
8126 }
Jamie Madille25b8002018-09-20 13:39:49 -04008127 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008128 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008129 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008130 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008131 }
Jamie Madille25b8002018-09-20 13:39:49 -04008132 else
8133 {
8134 ASSERT(index < kSamplerMaxSubjectIndex);
8135 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8136 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008137 break;
8138 }
8139}
8140
Jamie Madill6b873dd2018-07-12 23:56:30 -04008141// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008142ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008143
8144ErrorSet::~ErrorSet() = default;
8145
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008146void ErrorSet::handleError(GLenum errorCode,
8147 const char *message,
8148 const char *file,
8149 const char *function,
8150 unsigned int line)
8151{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008152 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8153 {
8154 mContext->markContextLost();
8155 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008156
Jamie Madill4f6592f2018-11-27 16:37:45 -05008157 std::stringstream errorStream;
8158 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8159 << line << ". " << message;
8160
8161 // validationError does the necessary work to process the error.
8162 validationError(errorCode, errorStream.str().c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008163}
8164
Jamie Madilla139f012018-10-10 16:13:03 -04008165void ErrorSet::validationError(GLenum errorCode, const char *message)
8166{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008167 ASSERT(errorCode != GL_NO_ERROR);
8168 mErrors.insert(errorCode);
8169
8170 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8171 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008172}
8173
Jamie Madill6b873dd2018-07-12 23:56:30 -04008174bool ErrorSet::empty() const
8175{
8176 return mErrors.empty();
8177}
8178
8179GLenum ErrorSet::popError()
8180{
8181 ASSERT(!empty());
8182 GLenum error = *mErrors.begin();
8183 mErrors.erase(mErrors.begin());
8184 return error;
8185}
Jamie Madilldc358af2018-07-31 11:22:13 -04008186
8187// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008188StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008189 : mCachedHasAnyEnabledClientAttrib(false),
8190 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008191 mCachedInstancedVertexElementLimit(0),
8192 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008193{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008194
8195StateCache::~StateCache() = default;
8196
Jamie Madillac66f982018-10-09 18:30:01 -04008197void StateCache::initialize(Context *context)
8198{
8199 updateValidDrawModes(context);
8200 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008201 updateValidDrawElementsTypes(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008202}
8203
Jamie Madilldc358af2018-07-31 11:22:13 -04008204void StateCache::updateActiveAttribsMask(Context *context)
8205{
8206 bool isGLES1 = context->isGLES1();
8207 const State &glState = context->getGLState();
8208
8209 if (!isGLES1 && !glState.getProgram())
8210 {
8211 mCachedActiveBufferedAttribsMask = AttributesMask();
8212 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008213 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008214 return;
8215 }
8216
8217 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8218 : glState.getProgram()->getActiveAttribLocationsMask();
8219
8220 const VertexArray *vao = glState.getVertexArray();
8221 ASSERT(vao);
8222
8223 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8224 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008225 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008226
Jamie Madill0a17e482018-08-31 17:19:11 -04008227 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8228 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008229 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008230 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8231}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008232
8233void StateCache::updateVertexElementLimits(Context *context)
8234{
8235 const VertexArray *vao = context->getGLState().getVertexArray();
8236
8237 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8238 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8239
8240 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8241 // If there are no buffered attributes then we should not limit the draw call count.
8242 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8243 {
8244 return;
8245 }
8246
8247 const auto &vertexAttribs = vao->getVertexAttributes();
8248 const auto &vertexBindings = vao->getVertexBindings();
8249
8250 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8251 {
8252 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8253 ASSERT(attrib.enabled);
8254
8255 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8256 ASSERT(context->isGLES1() ||
8257 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8258
8259 GLint64 limit = attrib.getCachedElementLimit();
8260 if (binding.getDivisor() > 0)
8261 {
8262 mCachedInstancedVertexElementLimit =
8263 std::min(mCachedInstancedVertexElementLimit, limit);
8264 }
8265 else
8266 {
8267 mCachedNonInstancedVertexElementLimit =
8268 std::min(mCachedNonInstancedVertexElementLimit, limit);
8269 }
8270 }
8271}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008272
Jamie Madilld84b6732018-09-06 15:54:35 -04008273void StateCache::updateBasicDrawStatesError()
8274{
8275 mCachedBasicDrawStatesError = kInvalidPointer;
8276}
8277
8278intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8279{
8280 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8281 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8282 return mCachedBasicDrawStatesError;
8283}
8284
Jamie Madillc43cdad2018-08-08 15:49:25 -04008285void StateCache::onVertexArrayBindingChange(Context *context)
8286{
8287 updateActiveAttribsMask(context);
8288 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008289 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008290}
8291
8292void StateCache::onProgramExecutableChange(Context *context)
8293{
8294 updateActiveAttribsMask(context);
8295 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008296 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008297 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008298}
8299
Jamie Madilld84b6732018-09-06 15:54:35 -04008300void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008301{
8302 updateVertexElementLimits(context);
8303}
8304
Jamie Madilld84b6732018-09-06 15:54:35 -04008305void StateCache::onVertexArrayBufferContentsChange(Context *context)
8306{
8307 updateVertexElementLimits(context);
8308 updateBasicDrawStatesError();
8309}
8310
Jamie Madillc43cdad2018-08-08 15:49:25 -04008311void StateCache::onVertexArrayStateChange(Context *context)
8312{
8313 updateActiveAttribsMask(context);
8314 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008315 updateBasicDrawStatesError();
8316}
8317
8318void StateCache::onVertexArrayBufferStateChange(Context *context)
8319{
8320 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008321}
8322
8323void StateCache::onGLES1ClientStateChange(Context *context)
8324{
8325 updateActiveAttribsMask(context);
8326}
Jamie Madilld84b6732018-09-06 15:54:35 -04008327
8328void StateCache::onDrawFramebufferChange(Context *context)
8329{
8330 updateBasicDrawStatesError();
8331}
8332
8333void StateCache::onContextCapChange(Context *context)
8334{
8335 updateBasicDrawStatesError();
8336}
8337
8338void StateCache::onStencilStateChange(Context *context)
8339{
8340 updateBasicDrawStatesError();
8341}
8342
8343void StateCache::onDefaultVertexAttributeChange(Context *context)
8344{
8345 updateBasicDrawStatesError();
8346}
8347
8348void StateCache::onActiveTextureChange(Context *context)
8349{
8350 updateBasicDrawStatesError();
8351}
8352
8353void StateCache::onQueryChange(Context *context)
8354{
8355 updateBasicDrawStatesError();
8356}
8357
8358void StateCache::onTransformFeedbackChange(Context *context)
8359{
8360 updateBasicDrawStatesError();
8361}
8362
8363void StateCache::onUniformBufferStateChange(Context *context)
8364{
8365 updateBasicDrawStatesError();
8366}
8367
8368void StateCache::onBufferBindingChange(Context *context)
8369{
8370 updateBasicDrawStatesError();
8371}
Jamie Madill526a6f62018-09-12 11:03:05 -04008372
8373void StateCache::updateValidDrawModes(Context *context)
8374{
8375 Program *program = context->getGLState().getProgram();
8376 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8377 {
Jamie Madill752d2202018-11-27 13:29:48 -05008378 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008379 }
8380 else
8381 {
8382 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8383
8384 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8385
8386 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008387 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8388 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8389 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8390 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8391 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8392 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8393 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8394 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8395 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8396 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8397 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008398 }};
8399 }
8400}
Jamie Madillac66f982018-10-09 18:30:01 -04008401
8402void StateCache::updateValidBindTextureTypes(Context *context)
8403{
8404 const Extensions &exts = context->getExtensions();
8405 bool isGLES3 = context->getClientMajorVersion() >= 3;
8406 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8407
8408 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008409 {TextureType::_2D, true},
8410 {TextureType::_2DArray, isGLES3},
8411 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8412 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8413 {TextureType::_3D, isGLES3},
8414 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8415 {TextureType::Rectangle, exts.textureRectangle},
8416 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008417 }};
8418}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008419
8420void StateCache::updateValidDrawElementsTypes(Context *context)
8421{
8422 bool supportsUint =
8423 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8424
8425 mCachedValidDrawElementsTypes = {{
8426 {DrawElementsType::UnsignedByte, true},
8427 {DrawElementsType::UnsignedShort, true},
8428 {DrawElementsType::UnsignedInt, supportsUint},
8429 }};
8430}
Jamie Madillc29968b2016-01-20 11:17:23 -05008431} // namespace gl