blob: e69cc3c8d101043ccf5fbd77c04ea30af3d85ccf [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,
287 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
288 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
289 kUniformBufferMaxSubjectIndex =
290 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400291 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
292 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
293 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400294 kReadFramebufferSubjectIndex,
295 kDrawFramebufferSubjectIndex
296};
Geoff Langf6db0982015-08-25 13:04:00 -0400297} // anonymous namespace
298
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400299Context::Context(rx::EGLImplFactory *implFactory,
300 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400301 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500302 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400303 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500304 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700305 const egl::DisplayExtensions &displayExtensions,
306 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500307 : mState(reinterpret_cast<ContextID>(this),
308 shareContext ? &shareContext->mState : nullptr,
309 shareTextures,
310 GetClientVersion(attribs),
311 &mGLState,
312 mCaps,
313 mTextureCaps,
314 mExtensions,
315 mLimitations),
316 mSkipValidation(GetNoError(attribs)),
317 mDisplayTextureShareGroup(shareTextures != nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400318 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400319 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400320 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400321 mGLState(GetDebug(attribs),
322 GetBindGeneratesResource(attribs),
323 GetClientArraysEnabled(attribs),
324 GetRobustResourceInit(attribs),
325 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400326 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500327 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400328 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500329 mHasBeenCurrent(false),
330 mContextLost(false),
331 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700332 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500333 mResetStrategy(GetResetStrategy(attribs)),
334 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400335 mSurfacelessSupported(displayExtensions.surfacelessContext),
336 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400337 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
338 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500339 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400340 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400341 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400342 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
343 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
344 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400345 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800346 mZeroFilledBuffer(1000u),
347 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000348{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400349 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
350 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
351 {
352 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
353 }
Jamie Madille25b8002018-09-20 13:39:49 -0400354
355 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
356 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
357 {
358 mSamplerObserverBindings.emplace_back(this, samplerIndex);
359 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400360}
Jamie Madill5b772312018-03-08 20:28:32 -0500361
Geoff Lang33f11fb2018-05-07 13:42:47 -0400362void Context::initialize()
363{
364 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400365
Geoff Lang33f11fb2018-05-07 13:42:47 -0400366 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700367 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400368
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400369 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100370
Shannon Woods53a94a82014-06-24 15:20:36 -0400371 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400372
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000373 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400374 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000375 // and cube map texture state vectors respectively associated with them.
376 // In order that access to these initial textures not be lost, they are treated as texture
377 // objects all of whose names are 0.
378
Corentin Wallez99d492c2018-02-27 15:17:10 -0500379 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800380 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500381
Corentin Wallez99d492c2018-02-27 15:17:10 -0500382 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800383 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400384
Geoff Langeb66a6e2016-10-31 13:06:12 -0400385 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400386 {
387 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500388 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800389 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400390
Corentin Wallez99d492c2018-02-27 15:17:10 -0500391 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800392 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400393 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800394 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400395 {
396 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500397 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800398 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800399 }
400 if (getClientVersion() >= Version(3, 1))
401 {
Olli Etuahod310a432018-08-24 15:40:23 +0300402 Texture *zeroTexture2DMultisampleArray =
403 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
404 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800405
Jiajia Qin6eafb042016-12-27 17:04:07 +0800406 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
407 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800408 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800409 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800410
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800411 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
412 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400413 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800414 }
Geoff Lang3b573612016-10-31 14:08:10 -0400415 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000416
Geoff Langb0f917f2017-12-05 13:41:54 -0500417 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400418 {
419 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500420 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800421 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400422 }
423
Geoff Langb0f917f2017-12-05 13:41:54 -0500424 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400425 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500426 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800427 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400428 }
429
Jamie Madill4928b7c2017-06-20 12:57:39 -0400430 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500431
Jamie Madill57a89722013-07-02 11:57:03 -0400432 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000433
Geoff Langeb66a6e2016-10-31 13:06:12 -0400434 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400435 {
436 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
437 // In the initial state, a default transform feedback object is bound and treated as
438 // a transform feedback object with a name of zero. That object is bound any time
439 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400440 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400441 }
Geoff Langc8058452014-02-03 12:04:11 -0500442
Corentin Wallez336129f2017-10-17 15:55:40 -0400443 for (auto type : angle::AllEnums<BufferBinding>())
444 {
445 bindBuffer(type, 0);
446 }
447
448 bindRenderbuffer(GL_RENDERBUFFER, 0);
449
450 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
451 {
452 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
453 }
454
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700455 // Initialize GLES1 renderer if appropriate.
456 if (getClientVersion() < Version(2, 0))
457 {
458 mGLES1Renderer.reset(new GLES1Renderer());
459 }
460
Jamie Madillad9f24e2016-02-12 09:27:24 -0500461 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400462 mAllDirtyBits.set();
463
Geoff Lang9bf86f02018-07-26 11:46:34 -0400464 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
465 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
466 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400467 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400468 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400469
470 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
471 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
472 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400473 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400474
Jamie Madillc67323a2017-11-02 23:11:41 -0400475 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500476 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500477 // No dirty objects.
478
479 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400480 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500481 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400482 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500483 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
484
485 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
486 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
487 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
488 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
489 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
490 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
491 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
492 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
493 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
494 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
495 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400496 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500497 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
498
499 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
500 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700501 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400502 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
503 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500504 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
505 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400506
Xinghua Cao10a4d432017-11-28 14:46:26 +0800507 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800508 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
509 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800510 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
511 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
512 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
513 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800514 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800515 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800516 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400517 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400518 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800519
Jamie Madillb4927eb2018-07-16 11:39:46 -0400520 mImplementation->setErrorSet(&mErrors);
521
Jamie Madill4f6592f2018-11-27 16:37:45 -0500522 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523}
524
Jamie Madill4928b7c2017-06-20 12:57:39 -0400525egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000526{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700527 if (mGLES1Renderer)
528 {
529 mGLES1Renderer->onDestroy(this, &mGLState);
530 }
531
Jamie Madille7b3fe22018-04-05 09:42:46 -0400532 ANGLE_TRY(releaseSurface(display));
533
Corentin Wallez80b24112015-08-25 16:41:57 -0400534 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000535 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400536 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400538 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000539
Corentin Wallez80b24112015-08-25 16:41:57 -0400540 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400542 if (query.second != nullptr)
543 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400544 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400545 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400547 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548
Corentin Wallez80b24112015-08-25 16:41:57 -0400549 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400550 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400551 if (vertexArray.second)
552 {
553 vertexArray.second->onDestroy(this);
554 }
Jamie Madill57a89722013-07-02 11:57:03 -0400555 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400556 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400557
Corentin Wallez80b24112015-08-25 16:41:57 -0400558 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500559 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500560 if (transformFeedback.second != nullptr)
561 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500562 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500563 }
Geoff Langc8058452014-02-03 12:04:11 -0500564 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400565 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500566
Jamie Madill5b772312018-03-08 20:28:32 -0500567 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400568 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800569 if (zeroTexture.get() != nullptr)
570 {
Jamie Madill1c7f08c2018-10-10 16:13:02 -0400571 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800572 zeroTexture.set(this, nullptr);
573 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400574 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000575
Jamie Madill2f348d22017-06-05 10:50:59 -0400576 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500577
Jamie Madill4928b7c2017-06-20 12:57:39 -0400578 mGLState.reset(this);
579
Jamie Madill6c1f6712017-02-14 19:08:04 -0500580 mState.mBuffers->release(this);
581 mState.mShaderPrograms->release(this);
582 mState.mTextures->release(this);
583 mState.mRenderbuffers->release(this);
584 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400585 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500586 mState.mPaths->release(this);
587 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800588 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400589
jchen107ae70d82018-07-06 13:47:01 +0800590 mThreadPool.reset();
591
Jamie Madill76e471e2017-10-21 09:56:01 -0400592 mImplementation->onDestroy(this);
593
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
Jamie Madillb980c562018-11-27 11:34:27 -0500597Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500598
Geoff Lang75359662018-04-11 01:42:27 -0400599void Context::setLabel(EGLLabelKHR label)
600{
601 mLabel = label;
602}
603
604EGLLabelKHR Context::getLabel() const
605{
606 return mLabel;
607}
608
Jamie Madill4928b7c2017-06-20 12:57:39 -0400609egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610{
Jamie Madill61e16b42017-06-19 11:13:23 -0400611 mCurrentDisplay = display;
612
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613 if (!mHasBeenCurrent)
614 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400615 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500617 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400618 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619
Corentin Wallezc295e512017-01-27 17:47:50 -0500620 int width = 0;
621 int height = 0;
622 if (surface != nullptr)
623 {
624 width = surface->getWidth();
625 height = surface->getHeight();
626 }
627
628 mGLState.setViewportParams(0, 0, width, height);
629 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630
631 mHasBeenCurrent = true;
632 }
633
Jamie Madill1b94d432015-08-07 13:23:23 -0400634 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700635 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400636 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400637
Jamie Madill4928b7c2017-06-20 12:57:39 -0400638 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500639
640 Framebuffer *newDefault = nullptr;
641 if (surface != nullptr)
642 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400643 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500644 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400645 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500646 }
647 else
648 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400649 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500650 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000651
Corentin Wallez37c39792015-08-20 14:19:46 -0400652 // Update default framebuffer, the binding of the previous default
653 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400654 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400655 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700656 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400657 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400658 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400659 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700660 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400661 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400662 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400663 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400664 }
Ian Ewell292f0052016-02-04 10:37:32 -0500665
Jamie Madill32643ce2018-10-19 11:38:03 -0400666 // Notify the renderer of a context switch.
Jamie Madill4f6592f2018-11-27 16:37:45 -0500667 return mImplementation->onMakeCurrent(this).toEGL();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
Jamie Madill4928b7c2017-06-20 12:57:39 -0400670egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400671{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400672 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400673
Geoff Langbf7b95d2018-05-01 16:48:21 -0400674 // Remove the default framebuffer
675 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500676 {
677 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400678 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500679 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400680
681 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500682 {
683 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400684 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500685 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400686
687 if (defaultFramebuffer)
688 {
689 defaultFramebuffer->onDestroy(this);
690 delete defaultFramebuffer;
691 }
692
Corentin Wallezc295e512017-01-27 17:47:50 -0500693 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
694
695 if (mCurrentSurface)
696 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400697 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500698 mCurrentSurface = nullptr;
699 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400700
701 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400702}
703
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704GLuint Context::createBuffer()
705{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500706 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
709GLuint Context::createProgram()
710{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500711 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
Jiawei Shao385b3e02018-03-21 09:43:28 +0800714GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717}
718
719GLuint Context::createTexture()
720{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500721 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722}
723
724GLuint Context::createRenderbuffer()
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000727}
728
Jamie Madill13951342018-09-30 15:24:28 -0400729void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
730{
Jamie Madill526392d2018-11-16 09:35:14 -0500731 ANGLE_CONTEXT_TRY(mState.mPaths->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400732}
733
Brandon Jones59770802018-04-02 13:18:42 -0700734GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300735{
Jamie Madill13951342018-09-30 15:24:28 -0400736 GLuint created = 0;
737 tryGenPaths(range, &created);
738 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300739}
740
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741// Returns an unused framebuffer name
742GLuint Context::createFramebuffer()
743{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500744 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000745}
746
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500747void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000748{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500749 for (int i = 0; i < n; i++)
750 {
751 GLuint handle = mFenceNVHandleAllocator.allocate();
752 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
753 fences[i] = handle;
754 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000755}
756
Yunchao Hea336b902017-08-02 16:05:21 +0800757GLuint Context::createProgramPipeline()
758{
759 return mState.mPipelines->createProgramPipeline();
760}
761
Jiawei Shao385b3e02018-03-21 09:43:28 +0800762GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800763{
764 UNIMPLEMENTED();
765 return 0u;
766}
767
James Darpinian4d9d4832018-03-13 12:43:28 -0700768void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769{
James Darpinian4d9d4832018-03-13 12:43:28 -0700770 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
771 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772 {
773 detachBuffer(buffer);
774 }
Jamie Madill893ab082014-05-16 16:56:10 -0400775
James Darpinian4d9d4832018-03-13 12:43:28 -0700776 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777}
778
779void Context::deleteShader(GLuint shader)
780{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500781 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782}
783
784void Context::deleteProgram(GLuint program)
785{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500786 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787}
788
789void Context::deleteTexture(GLuint texture)
790{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500791 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792 {
793 detachTexture(texture);
794 }
795
Jamie Madill6c1f6712017-02-14 19:08:04 -0500796 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797}
798
799void Context::deleteRenderbuffer(GLuint renderbuffer)
800{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500801 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802 {
803 detachRenderbuffer(renderbuffer);
804 }
Jamie Madill893ab082014-05-16 16:56:10 -0400805
Jamie Madill6c1f6712017-02-14 19:08:04 -0500806 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807}
808
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400809void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400810{
811 // The spec specifies the underlying Fence object is not deleted until all current
812 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
813 // and since our API is currently designed for being called from a single thread, we can delete
814 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400815 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400816}
817
Yunchao Hea336b902017-08-02 16:05:21 +0800818void Context::deleteProgramPipeline(GLuint pipeline)
819{
820 if (mState.mPipelines->getProgramPipeline(pipeline))
821 {
822 detachProgramPipeline(pipeline);
823 }
824
825 mState.mPipelines->deleteObject(this, pipeline);
826}
827
Sami Väisänene45e53b2016-05-25 10:36:04 +0300828void Context::deletePaths(GLuint first, GLsizei range)
829{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500830 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300831}
832
Brandon Jones59770802018-04-02 13:18:42 -0700833bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300834{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500835 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300836 if (pathObj == nullptr)
837 return false;
838
839 return pathObj->hasPathData();
840}
841
Brandon Jones59770802018-04-02 13:18:42 -0700842bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500844 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300845}
846
Brandon Jones59770802018-04-02 13:18:42 -0700847void Context::pathCommands(GLuint path,
848 GLsizei numCommands,
849 const GLubyte *commands,
850 GLsizei numCoords,
851 GLenum coordType,
852 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500854 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855
Jamie Madill4f6592f2018-11-27 16:37:45 -0500856 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857}
858
Jamie Madill007530e2017-12-28 14:27:04 -0500859void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860{
Jamie Madill007530e2017-12-28 14:27:04 -0500861 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862
863 switch (pname)
864 {
865 case GL_PATH_STROKE_WIDTH_CHROMIUM:
866 pathObj->setStrokeWidth(value);
867 break;
868 case GL_PATH_END_CAPS_CHROMIUM:
869 pathObj->setEndCaps(static_cast<GLenum>(value));
870 break;
871 case GL_PATH_JOIN_STYLE_CHROMIUM:
872 pathObj->setJoinStyle(static_cast<GLenum>(value));
873 break;
874 case GL_PATH_MITER_LIMIT_CHROMIUM:
875 pathObj->setMiterLimit(value);
876 break;
877 case GL_PATH_STROKE_BOUND_CHROMIUM:
878 pathObj->setStrokeBound(value);
879 break;
880 default:
881 UNREACHABLE();
882 break;
883 }
884}
885
Jamie Madill007530e2017-12-28 14:27:04 -0500886void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300887{
Jamie Madill007530e2017-12-28 14:27:04 -0500888 // TODO(jmadill): Should use proper clamping/casting.
889 pathParameterf(path, pname, static_cast<GLfloat>(value));
890}
891
892void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
893{
894 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300895
896 switch (pname)
897 {
898 case GL_PATH_STROKE_WIDTH_CHROMIUM:
899 *value = pathObj->getStrokeWidth();
900 break;
901 case GL_PATH_END_CAPS_CHROMIUM:
902 *value = static_cast<GLfloat>(pathObj->getEndCaps());
903 break;
904 case GL_PATH_JOIN_STYLE_CHROMIUM:
905 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
906 break;
907 case GL_PATH_MITER_LIMIT_CHROMIUM:
908 *value = pathObj->getMiterLimit();
909 break;
910 case GL_PATH_STROKE_BOUND_CHROMIUM:
911 *value = pathObj->getStrokeBound();
912 break;
913 default:
914 UNREACHABLE();
915 break;
916 }
917}
918
Jamie Madill007530e2017-12-28 14:27:04 -0500919void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
920{
921 GLfloat val = 0.0f;
922 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
923 if (value)
924 *value = static_cast<GLint>(val);
925}
926
Brandon Jones59770802018-04-02 13:18:42 -0700927void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300928{
929 mGLState.setPathStencilFunc(func, ref, mask);
930}
931
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932void Context::deleteFramebuffer(GLuint framebuffer)
933{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500934 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000935 {
936 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000937 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500938
Jamie Madill6c1f6712017-02-14 19:08:04 -0500939 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940}
941
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500942void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500944 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500946 GLuint fence = fences[i];
947
948 FenceNV *fenceObject = nullptr;
949 if (mFenceNVMap.erase(fence, &fenceObject))
950 {
951 mFenceNVHandleAllocator.release(fence);
952 delete fenceObject;
953 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000954 }
955}
956
Geoff Lang70d0f492015-12-10 17:45:46 -0500957Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500959 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960}
961
Geoff Lang70d0f492015-12-10 17:45:46 -0500962Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500964 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000965}
966
Jamie Madill70b5bb02017-08-28 13:32:37 -0400967Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400968{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400969 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400970}
971
Jamie Madill57a89722013-07-02 11:57:03 -0400972VertexArray *Context::getVertexArray(GLuint handle) const
973{
Jamie Madill96a483b2017-06-27 16:49:21 -0400974 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400975}
976
Jamie Madilldc356042013-07-19 16:36:57 -0400977Sampler *Context::getSampler(GLuint handle) const
978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400980}
981
Geoff Langc8058452014-02-03 12:04:11 -0500982TransformFeedback *Context::getTransformFeedback(GLuint handle) const
983{
Jamie Madill96a483b2017-06-27 16:49:21 -0400984 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500985}
986
Yunchao Hea336b902017-08-02 16:05:21 +0800987ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
988{
989 return mState.mPipelines->getProgramPipeline(handle);
990}
991
Geoff Lang75359662018-04-11 01:42:27 -0400992gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500993{
994 switch (identifier)
995 {
996 case GL_BUFFER:
997 return getBuffer(name);
998 case GL_SHADER:
999 return getShader(name);
1000 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001001 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -05001002 case GL_VERTEX_ARRAY:
1003 return getVertexArray(name);
1004 case GL_QUERY:
1005 return getQuery(name);
1006 case GL_TRANSFORM_FEEDBACK:
1007 return getTransformFeedback(name);
1008 case GL_SAMPLER:
1009 return getSampler(name);
1010 case GL_TEXTURE:
1011 return getTexture(name);
1012 case GL_RENDERBUFFER:
1013 return getRenderbuffer(name);
1014 case GL_FRAMEBUFFER:
1015 return getFramebuffer(name);
1016 default:
1017 UNREACHABLE();
1018 return nullptr;
1019 }
1020}
1021
Geoff Lang75359662018-04-11 01:42:27 -04001022gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001023{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001024 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001025}
1026
Martin Radev9d901792016-07-15 15:58:58 +03001027void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1028{
Geoff Lang75359662018-04-11 01:42:27 -04001029 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001030 ASSERT(object != nullptr);
1031
1032 std::string labelName = GetObjectLabelFromPointer(length, label);
1033 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001034
1035 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1036 // specified object is active until we do this.
1037 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001038}
1039
1040void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1041{
Geoff Lang75359662018-04-11 01:42:27 -04001042 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001043 ASSERT(object != nullptr);
1044
1045 std::string labelName = GetObjectLabelFromPointer(length, label);
1046 object->setLabel(labelName);
1047}
1048
1049void Context::getObjectLabel(GLenum identifier,
1050 GLuint name,
1051 GLsizei bufSize,
1052 GLsizei *length,
1053 GLchar *label) const
1054{
Geoff Lang75359662018-04-11 01:42:27 -04001055 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001056 ASSERT(object != nullptr);
1057
1058 const std::string &objectLabel = object->getLabel();
1059 GetObjectLabelBase(objectLabel, bufSize, length, label);
1060}
1061
1062void Context::getObjectPtrLabel(const void *ptr,
1063 GLsizei bufSize,
1064 GLsizei *length,
1065 GLchar *label) const
1066{
Geoff Lang75359662018-04-11 01:42:27 -04001067 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001068 ASSERT(object != nullptr);
1069
1070 const std::string &objectLabel = object->getLabel();
1071 GetObjectLabelBase(objectLabel, bufSize, length, label);
1072}
1073
Jamie Madilldc356042013-07-19 16:36:57 -04001074bool Context::isSampler(GLuint samplerName) const
1075{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001076 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001077}
1078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001079void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082
Jamie Madilldedd7b92014-11-05 16:30:36 -05001083 if (handle == 0)
1084 {
1085 texture = mZeroTextures[target].get();
1086 }
1087 else
1088 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001089 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001090 }
1091
1092 ASSERT(texture);
Jamie Madill14246812018-10-03 17:51:16 -04001093 ANGLE_CONTEXT_TRY(mGLState.setSamplerTexture(this, target, texture));
Jamie Madilld84b6732018-09-06 15:54:35 -04001094 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001095}
1096
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001097void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001099 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1100 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001101 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001102 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103}
1104
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001105void Context::bindDrawFramebuffer(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.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001110 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001111 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001112}
1113
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001114void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001115{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001116 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001117 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001118 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001119 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001120}
1121
Shao80957d92017-02-20 21:25:59 +08001122void Context::bindVertexBuffer(GLuint bindingIndex,
1123 GLuint bufferHandle,
1124 GLintptr offset,
1125 GLsizei stride)
1126{
1127 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001128 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001129 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001130}
1131
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001132void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001133{
Geoff Lang76b10c92014-09-05 16:28:14 -04001134 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001135 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001136 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001137 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001138 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001139}
1140
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001141void Context::bindImageTexture(GLuint unit,
1142 GLuint texture,
1143 GLint level,
1144 GLboolean layered,
1145 GLint layer,
1146 GLenum access,
1147 GLenum format)
1148{
1149 Texture *tex = mState.mTextures->getTexture(texture);
1150 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1151}
1152
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153void Context::useProgram(GLuint program)
1154{
Jamie Madille3bb6b72018-10-03 17:51:15 -04001155 ANGLE_CONTEXT_TRY(mGLState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001156 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001157}
1158
Jiajia Qin5451d532017-11-16 17:16:34 +08001159void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1160{
1161 UNIMPLEMENTED();
1162}
1163
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001164void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001165{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001166 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001167 TransformFeedback *transformFeedback =
1168 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001169 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001170 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001171}
1172
Yunchao Hea336b902017-08-02 16:05:21 +08001173void Context::bindProgramPipeline(GLuint pipelineHandle)
1174{
1175 ProgramPipeline *pipeline =
1176 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1177 mGLState.setProgramPipelineBinding(this, pipeline);
1178}
1179
Corentin Wallezad3ae902018-03-09 13:40:42 -05001180void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001182 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001183 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001184
Geoff Lang5aad9672014-09-08 11:10:42 -04001185 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001186 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001187
1188 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001189 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001190 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191}
1192
Corentin Wallezad3ae902018-03-09 13:40:42 -05001193void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001195 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001196 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001197
Jamie Madill4f6592f2018-11-27 16:37:45 -05001198 // Intentionally don't call try here. We don't want an early return.
1199 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200
Geoff Lang5aad9672014-09-08 11:10:42 -04001201 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001202 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001203 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001204}
1205
Corentin Wallezad3ae902018-03-09 13:40:42 -05001206void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001207{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001208 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001209
1210 Query *queryObject = getQuery(id, true, target);
1211 ASSERT(queryObject);
1212
Jamie Madill4f6592f2018-11-27 16:37:45 -05001213 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001214}
1215
Corentin Wallezad3ae902018-03-09 13:40:42 -05001216void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001217{
1218 switch (pname)
1219 {
1220 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001221 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222 break;
1223 case GL_QUERY_COUNTER_BITS_EXT:
1224 switch (target)
1225 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001226 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1228 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001229 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001230 params[0] = getExtensions().queryCounterBitsTimestamp;
1231 break;
1232 default:
1233 UNREACHABLE();
1234 params[0] = 0;
1235 break;
1236 }
1237 break;
1238 default:
1239 UNREACHABLE();
1240 return;
1241 }
1242}
1243
Corentin Wallezad3ae902018-03-09 13:40:42 -05001244void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001245 GLenum pname,
1246 GLsizei bufSize,
1247 GLsizei *length,
1248 GLint *params)
1249{
1250 getQueryiv(target, pname, params);
1251}
1252
Geoff Lang2186c382016-10-14 10:54:54 -04001253void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001255 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256}
1257
Brandon Jones59770802018-04-02 13:18:42 -07001258void Context::getQueryObjectivRobust(GLuint id,
1259 GLenum pname,
1260 GLsizei bufSize,
1261 GLsizei *length,
1262 GLint *params)
1263{
1264 getQueryObjectiv(id, pname, params);
1265}
1266
Geoff Lang2186c382016-10-14 10:54:54 -04001267void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001268{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001269 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001270}
1271
Brandon Jones59770802018-04-02 13:18:42 -07001272void Context::getQueryObjectuivRobust(GLuint id,
1273 GLenum pname,
1274 GLsizei bufSize,
1275 GLsizei *length,
1276 GLuint *params)
1277{
1278 getQueryObjectuiv(id, pname, params);
1279}
1280
Geoff Lang2186c382016-10-14 10:54:54 -04001281void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001282{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001283 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001284}
1285
Brandon Jones59770802018-04-02 13:18:42 -07001286void Context::getQueryObjecti64vRobust(GLuint id,
1287 GLenum pname,
1288 GLsizei bufSize,
1289 GLsizei *length,
1290 GLint64 *params)
1291{
1292 getQueryObjecti64v(id, pname, params);
1293}
1294
Geoff Lang2186c382016-10-14 10:54:54 -04001295void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001296{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001297 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001298}
1299
Brandon Jones59770802018-04-02 13:18:42 -07001300void Context::getQueryObjectui64vRobust(GLuint id,
1301 GLenum pname,
1302 GLsizei bufSize,
1303 GLsizei *length,
1304 GLuint64 *params)
1305{
1306 getQueryObjectui64v(id, pname, params);
1307}
1308
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001309Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001311 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312}
1313
Jamie Madill2f348d22017-06-05 10:50:59 -04001314FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315{
Jamie Madill96a483b2017-06-27 16:49:21 -04001316 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317}
1318
Corentin Wallezad3ae902018-03-09 13:40:42 -05001319Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320{
Jamie Madill96a483b2017-06-27 16:49:21 -04001321 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001323 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001325
1326 Query *query = mQueryMap.query(handle);
1327 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001329 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001330 query = new Query(mImplementation->createQuery(type), handle);
1331 query->addRef();
1332 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001334 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335}
1336
Geoff Lang70d0f492015-12-10 17:45:46 -05001337Query *Context::getQuery(GLuint handle) const
1338{
Jamie Madill96a483b2017-06-27 16:49:21 -04001339 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001340}
1341
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001342Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001343{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001344 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1345 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001346}
1347
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001348Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001350 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351}
1352
Geoff Lang492a7e42014-11-05 13:27:06 -05001353Compiler *Context::getCompiler() const
1354{
Jamie Madill2f348d22017-06-05 10:50:59 -04001355 if (mCompiler.get() == nullptr)
1356 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001357 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001358 }
1359 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001360}
1361
Jamie Madillc1d770e2017-04-13 17:31:24 -04001362void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001363{
1364 switch (pname)
1365 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001366 case GL_SHADER_COMPILER:
1367 *params = GL_TRUE;
1368 break;
1369 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1370 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1371 break;
1372 default:
1373 mGLState.getBooleanv(pname, params);
1374 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001375 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376}
1377
Jamie Madillc1d770e2017-04-13 17:31:24 -04001378void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001379{
Shannon Woods53a94a82014-06-24 15:20:36 -04001380 // Queries about context capabilities and maximums are answered by Context.
1381 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001382 switch (pname)
1383 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001384 case GL_ALIASED_LINE_WIDTH_RANGE:
1385 params[0] = mCaps.minAliasedLineWidth;
1386 params[1] = mCaps.maxAliasedLineWidth;
1387 break;
1388 case GL_ALIASED_POINT_SIZE_RANGE:
1389 params[0] = mCaps.minAliasedPointSize;
1390 params[1] = mCaps.maxAliasedPointSize;
1391 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001392 case GL_SMOOTH_POINT_SIZE_RANGE:
1393 params[0] = mCaps.minSmoothPointSize;
1394 params[1] = mCaps.maxSmoothPointSize;
1395 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001396 case GL_SMOOTH_LINE_WIDTH_RANGE:
1397 params[0] = mCaps.minSmoothLineWidth;
1398 params[1] = mCaps.maxSmoothLineWidth;
1399 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001400 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1401 ASSERT(mExtensions.textureFilterAnisotropic);
1402 *params = mExtensions.maxTextureAnisotropy;
1403 break;
1404 case GL_MAX_TEXTURE_LOD_BIAS:
1405 *params = mCaps.maxLODBias;
1406 break;
1407
1408 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1409 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1410 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001411 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1412 // GLES1 constants for modelview/projection matrix.
1413 if (getClientVersion() < Version(2, 0))
1414 {
1415 mGLState.getFloatv(pname, params);
1416 }
1417 else
1418 {
1419 ASSERT(mExtensions.pathRendering);
1420 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1421 memcpy(params, m, 16 * sizeof(GLfloat));
1422 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001424 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001425
Jamie Madill231c7f52017-04-26 13:45:37 -04001426 default:
1427 mGLState.getFloatv(pname, params);
1428 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001429 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001430}
1431
Jamie Madillc1d770e2017-04-13 17:31:24 -04001432void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001433{
Shannon Woods53a94a82014-06-24 15:20:36 -04001434 // Queries about context capabilities and maximums are answered by Context.
1435 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001436
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437 switch (pname)
1438 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 case GL_MAX_VERTEX_ATTRIBS:
1440 *params = mCaps.maxVertexAttributes;
1441 break;
1442 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1443 *params = mCaps.maxVertexUniformVectors;
1444 break;
1445 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001446 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 break;
1448 case GL_MAX_VARYING_VECTORS:
1449 *params = mCaps.maxVaryingVectors;
1450 break;
1451 case GL_MAX_VARYING_COMPONENTS:
1452 *params = mCaps.maxVertexOutputComponents;
1453 break;
1454 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1455 *params = mCaps.maxCombinedTextureImageUnits;
1456 break;
1457 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001458 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001459 break;
1460 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001461 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 break;
1463 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1464 *params = mCaps.maxFragmentUniformVectors;
1465 break;
1466 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001467 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_RENDERBUFFER_SIZE:
1470 *params = mCaps.maxRenderbufferSize;
1471 break;
1472 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1473 *params = mCaps.maxColorAttachments;
1474 break;
1475 case GL_MAX_DRAW_BUFFERS_EXT:
1476 *params = mCaps.maxDrawBuffers;
1477 break;
1478 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1479 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1480 case GL_SUBPIXEL_BITS:
1481 *params = 4;
1482 break;
1483 case GL_MAX_TEXTURE_SIZE:
1484 *params = mCaps.max2DTextureSize;
1485 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001486 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1487 *params = mCaps.maxRectangleTextureSize;
1488 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1490 *params = mCaps.maxCubeMapTextureSize;
1491 break;
1492 case GL_MAX_3D_TEXTURE_SIZE:
1493 *params = mCaps.max3DTextureSize;
1494 break;
1495 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1496 *params = mCaps.maxArrayTextureLayers;
1497 break;
1498 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1499 *params = mCaps.uniformBufferOffsetAlignment;
1500 break;
1501 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1502 *params = mCaps.maxUniformBufferBindings;
1503 break;
1504 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001505 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001506 break;
1507 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001508 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001509 break;
1510 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1511 *params = mCaps.maxCombinedTextureImageUnits;
1512 break;
1513 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1514 *params = mCaps.maxVertexOutputComponents;
1515 break;
1516 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1517 *params = mCaps.maxFragmentInputComponents;
1518 break;
1519 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1520 *params = mCaps.minProgramTexelOffset;
1521 break;
1522 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1523 *params = mCaps.maxProgramTexelOffset;
1524 break;
1525 case GL_MAJOR_VERSION:
1526 *params = getClientVersion().major;
1527 break;
1528 case GL_MINOR_VERSION:
1529 *params = getClientVersion().minor;
1530 break;
1531 case GL_MAX_ELEMENTS_INDICES:
1532 *params = mCaps.maxElementsIndices;
1533 break;
1534 case GL_MAX_ELEMENTS_VERTICES:
1535 *params = mCaps.maxElementsVertices;
1536 break;
1537 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1538 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1539 break;
1540 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1541 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1542 break;
1543 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1544 *params = mCaps.maxTransformFeedbackSeparateComponents;
1545 break;
1546 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1547 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1548 break;
1549 case GL_MAX_SAMPLES_ANGLE:
1550 *params = mCaps.maxSamples;
1551 break;
1552 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001553 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001554 params[0] = mCaps.maxViewportWidth;
1555 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001556 }
1557 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 case GL_COMPRESSED_TEXTURE_FORMATS:
1559 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1560 params);
1561 break;
1562 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1563 *params = mResetStrategy;
1564 break;
1565 case GL_NUM_SHADER_BINARY_FORMATS:
1566 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1567 break;
1568 case GL_SHADER_BINARY_FORMATS:
1569 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1570 break;
1571 case GL_NUM_PROGRAM_BINARY_FORMATS:
1572 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1573 break;
1574 case GL_PROGRAM_BINARY_FORMATS:
1575 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1576 break;
1577 case GL_NUM_EXTENSIONS:
1578 *params = static_cast<GLint>(mExtensionStrings.size());
1579 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001580
Geoff Lang38f24ee2018-10-01 13:04:59 -04001581 // GL_ANGLE_request_extension
1582 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1583 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1584 break;
1585
Jamie Madill231c7f52017-04-26 13:45:37 -04001586 // GL_KHR_debug
1587 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1588 *params = mExtensions.maxDebugMessageLength;
1589 break;
1590 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1591 *params = mExtensions.maxDebugLoggedMessages;
1592 break;
1593 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1594 *params = mExtensions.maxDebugGroupStackDepth;
1595 break;
1596 case GL_MAX_LABEL_LENGTH:
1597 *params = mExtensions.maxLabelLength;
1598 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001599
Martin Radeve5285d22017-07-14 16:23:53 +03001600 // GL_ANGLE_multiview
1601 case GL_MAX_VIEWS_ANGLE:
1602 *params = mExtensions.maxViews;
1603 break;
1604
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 // GL_EXT_disjoint_timer_query
1606 case GL_GPU_DISJOINT_EXT:
1607 *params = mImplementation->getGPUDisjoint();
1608 break;
1609 case GL_MAX_FRAMEBUFFER_WIDTH:
1610 *params = mCaps.maxFramebufferWidth;
1611 break;
1612 case GL_MAX_FRAMEBUFFER_HEIGHT:
1613 *params = mCaps.maxFramebufferHeight;
1614 break;
1615 case GL_MAX_FRAMEBUFFER_SAMPLES:
1616 *params = mCaps.maxFramebufferSamples;
1617 break;
1618 case GL_MAX_SAMPLE_MASK_WORDS:
1619 *params = mCaps.maxSampleMaskWords;
1620 break;
1621 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1622 *params = mCaps.maxColorTextureSamples;
1623 break;
1624 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1625 *params = mCaps.maxDepthTextureSamples;
1626 break;
1627 case GL_MAX_INTEGER_SAMPLES:
1628 *params = mCaps.maxIntegerSamples;
1629 break;
1630 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1631 *params = mCaps.maxVertexAttribRelativeOffset;
1632 break;
1633 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1634 *params = mCaps.maxVertexAttribBindings;
1635 break;
1636 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1637 *params = mCaps.maxVertexAttribStride;
1638 break;
1639 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001643 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001649 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001652 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001655 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001658 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001661 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1664 *params = mCaps.minProgramTextureGatherOffset;
1665 break;
1666 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1667 *params = mCaps.maxProgramTextureGatherOffset;
1668 break;
1669 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1670 *params = mCaps.maxComputeWorkGroupInvocations;
1671 break;
1672 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001673 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 break;
1675 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001676 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001677 break;
1678 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1679 *params = mCaps.maxComputeSharedMemorySize;
1680 break;
1681 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001682 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 break;
1684 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001685 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001686 break;
1687 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001688 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001689 break;
1690 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001691 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 break;
1693 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001694 *params =
1695 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001698 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1701 *params = mCaps.maxCombinedShaderOutputResources;
1702 break;
1703 case GL_MAX_UNIFORM_LOCATIONS:
1704 *params = mCaps.maxUniformLocations;
1705 break;
1706 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1707 *params = mCaps.maxAtomicCounterBufferBindings;
1708 break;
1709 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1710 *params = mCaps.maxAtomicCounterBufferSize;
1711 break;
1712 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1713 *params = mCaps.maxCombinedAtomicCounterBuffers;
1714 break;
1715 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1716 *params = mCaps.maxCombinedAtomicCounters;
1717 break;
1718 case GL_MAX_IMAGE_UNITS:
1719 *params = mCaps.maxImageUnits;
1720 break;
1721 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1722 *params = mCaps.maxCombinedImageUniforms;
1723 break;
1724 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1725 *params = mCaps.maxShaderStorageBufferBindings;
1726 break;
1727 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1728 *params = mCaps.maxCombinedShaderStorageBlocks;
1729 break;
1730 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1731 *params = mCaps.shaderStorageBufferOffsetAlignment;
1732 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001733
1734 // GL_EXT_geometry_shader
1735 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1736 *params = mCaps.maxFramebufferLayers;
1737 break;
1738 case GL_LAYER_PROVOKING_VERTEX_EXT:
1739 *params = mCaps.layerProvokingVertex;
1740 break;
1741 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001742 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001743 break;
1744 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001745 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001746 break;
1747 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001748 *params =
1749 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
1751 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1752 *params = mCaps.maxGeometryInputComponents;
1753 break;
1754 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1755 *params = mCaps.maxGeometryOutputComponents;
1756 break;
1757 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1758 *params = mCaps.maxGeometryOutputVertices;
1759 break;
1760 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1761 *params = mCaps.maxGeometryTotalOutputComponents;
1762 break;
1763 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1764 *params = mCaps.maxGeometryShaderInvocations;
1765 break;
1766 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001767 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001768 break;
1769 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001770 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001771 break;
1772 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001773 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001774 break;
1775 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001776 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001777 break;
1778 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001779 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001780 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001781 // GLES1 emulation: Caps queries
1782 case GL_MAX_TEXTURE_UNITS:
1783 *params = mCaps.maxMultitextureUnits;
1784 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001785 case GL_MAX_MODELVIEW_STACK_DEPTH:
1786 *params = mCaps.maxModelviewMatrixStackDepth;
1787 break;
1788 case GL_MAX_PROJECTION_STACK_DEPTH:
1789 *params = mCaps.maxProjectionMatrixStackDepth;
1790 break;
1791 case GL_MAX_TEXTURE_STACK_DEPTH:
1792 *params = mCaps.maxTextureMatrixStackDepth;
1793 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001794 case GL_MAX_LIGHTS:
1795 *params = mCaps.maxLights;
1796 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001797 case GL_MAX_CLIP_PLANES:
1798 *params = mCaps.maxClipPlanes;
1799 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001800 // GLES1 emulation: Vertex attribute queries
1801 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1802 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1803 case GL_COLOR_ARRAY_BUFFER_BINDING:
1804 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1805 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1806 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1807 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1808 break;
1809 case GL_VERTEX_ARRAY_STRIDE:
1810 case GL_NORMAL_ARRAY_STRIDE:
1811 case GL_COLOR_ARRAY_STRIDE:
1812 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1813 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1814 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1815 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1816 break;
1817 case GL_VERTEX_ARRAY_SIZE:
1818 case GL_COLOR_ARRAY_SIZE:
1819 case GL_TEXTURE_COORD_ARRAY_SIZE:
1820 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1821 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1822 break;
1823 case GL_VERTEX_ARRAY_TYPE:
1824 case GL_COLOR_ARRAY_TYPE:
1825 case GL_NORMAL_ARRAY_TYPE:
1826 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1827 case GL_TEXTURE_COORD_ARRAY_TYPE:
1828 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1829 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1830 break;
1831
jchen1082af6202018-06-22 10:59:52 +08001832 // GL_KHR_parallel_shader_compile
1833 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1834 *params = mGLState.getMaxShaderCompilerThreads();
1835 break;
1836
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001837 // GL_EXT_blend_func_extended
1838 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1839 *params = mExtensions.maxDualSourceDrawBuffers;
1840 break;
1841
Jamie Madill231c7f52017-04-26 13:45:37 -04001842 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001843 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001844 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001845 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001846}
1847
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001848void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001849{
Shannon Woods53a94a82014-06-24 15:20:36 -04001850 // Queries about context capabilities and maximums are answered by Context.
1851 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001852 switch (pname)
1853 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001854 case GL_MAX_ELEMENT_INDEX:
1855 *params = mCaps.maxElementIndex;
1856 break;
1857 case GL_MAX_UNIFORM_BLOCK_SIZE:
1858 *params = mCaps.maxUniformBlockSize;
1859 break;
1860 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001861 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001862 break;
1863 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001864 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001865 break;
1866 case GL_MAX_SERVER_WAIT_TIMEOUT:
1867 *params = mCaps.maxServerWaitTimeout;
1868 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001869
Jamie Madill231c7f52017-04-26 13:45:37 -04001870 // GL_EXT_disjoint_timer_query
1871 case GL_TIMESTAMP_EXT:
1872 *params = mImplementation->getTimestamp();
1873 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001874
Jamie Madill231c7f52017-04-26 13:45:37 -04001875 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1876 *params = mCaps.maxShaderStorageBlockSize;
1877 break;
1878 default:
1879 UNREACHABLE();
1880 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001881 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001882}
1883
Geoff Lang70d0f492015-12-10 17:45:46 -05001884void Context::getPointerv(GLenum pname, void **params) const
1885{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001886 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001887}
1888
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001889void Context::getPointervRobustANGLERobust(GLenum pname,
1890 GLsizei bufSize,
1891 GLsizei *length,
1892 void **params)
1893{
1894 UNIMPLEMENTED();
1895}
1896
Martin Radev66fb8202016-07-28 11:45:20 +03001897void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001898{
Shannon Woods53a94a82014-06-24 15:20:36 -04001899 // Queries about context capabilities and maximums are answered by Context.
1900 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001901
1902 GLenum nativeType;
1903 unsigned int numParams;
1904 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1905 ASSERT(queryStatus);
1906
1907 if (nativeType == GL_INT)
1908 {
1909 switch (target)
1910 {
1911 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1912 ASSERT(index < 3u);
1913 *data = mCaps.maxComputeWorkGroupCount[index];
1914 break;
1915 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1916 ASSERT(index < 3u);
1917 *data = mCaps.maxComputeWorkGroupSize[index];
1918 break;
1919 default:
1920 mGLState.getIntegeri_v(target, index, data);
1921 }
1922 }
1923 else
1924 {
1925 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1926 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001927}
1928
Brandon Jones59770802018-04-02 13:18:42 -07001929void Context::getIntegeri_vRobust(GLenum target,
1930 GLuint index,
1931 GLsizei bufSize,
1932 GLsizei *length,
1933 GLint *data)
1934{
1935 getIntegeri_v(target, index, data);
1936}
1937
Martin Radev66fb8202016-07-28 11:45:20 +03001938void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001939{
Shannon Woods53a94a82014-06-24 15:20:36 -04001940 // Queries about context capabilities and maximums are answered by Context.
1941 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001942
1943 GLenum nativeType;
1944 unsigned int numParams;
1945 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1946 ASSERT(queryStatus);
1947
1948 if (nativeType == GL_INT_64_ANGLEX)
1949 {
1950 mGLState.getInteger64i_v(target, index, data);
1951 }
1952 else
1953 {
1954 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1955 }
1956}
1957
Brandon Jones59770802018-04-02 13:18:42 -07001958void Context::getInteger64i_vRobust(GLenum target,
1959 GLuint index,
1960 GLsizei bufSize,
1961 GLsizei *length,
1962 GLint64 *data)
1963{
1964 getInteger64i_v(target, index, data);
1965}
1966
Martin Radev66fb8202016-07-28 11:45:20 +03001967void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1968{
1969 // Queries about context capabilities and maximums are answered by Context.
1970 // Queries about current GL state values are answered by State.
1971
1972 GLenum nativeType;
1973 unsigned int numParams;
1974 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1975 ASSERT(queryStatus);
1976
1977 if (nativeType == GL_BOOL)
1978 {
1979 mGLState.getBooleani_v(target, index, data);
1980 }
1981 else
1982 {
1983 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1984 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001985}
1986
Brandon Jones59770802018-04-02 13:18:42 -07001987void Context::getBooleani_vRobust(GLenum target,
1988 GLuint index,
1989 GLsizei bufSize,
1990 GLsizei *length,
1991 GLboolean *data)
1992{
1993 getBooleani_v(target, index, data);
1994}
1995
Corentin Wallez336129f2017-10-17 15:55:40 -04001996void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001997{
1998 Buffer *buffer = mGLState.getTargetBuffer(target);
1999 QueryBufferParameteriv(buffer, pname, params);
2000}
2001
Brandon Jones59770802018-04-02 13:18:42 -07002002void Context::getBufferParameterivRobust(BufferBinding target,
2003 GLenum pname,
2004 GLsizei bufSize,
2005 GLsizei *length,
2006 GLint *params)
2007{
2008 getBufferParameteriv(target, pname, params);
2009}
2010
He Yunchao010e4db2017-03-03 14:22:06 +08002011void Context::getFramebufferAttachmentParameteriv(GLenum target,
2012 GLenum attachment,
2013 GLenum pname,
2014 GLint *params)
2015{
2016 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002017 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002018}
2019
Brandon Jones59770802018-04-02 13:18:42 -07002020void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2021 GLenum attachment,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 GLsizei *length,
2025 GLint *params)
2026{
2027 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2028}
2029
He Yunchao010e4db2017-03-03 14:22:06 +08002030void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2031{
2032 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2033 QueryRenderbufferiv(this, renderbuffer, pname, params);
2034}
2035
Brandon Jones59770802018-04-02 13:18:42 -07002036void Context::getRenderbufferParameterivRobust(GLenum target,
2037 GLenum pname,
2038 GLsizei bufSize,
2039 GLsizei *length,
2040 GLint *params)
2041{
2042 getRenderbufferParameteriv(target, pname, params);
2043}
2044
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002045void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002046{
Till Rathmannb8543632018-10-02 19:46:14 +02002047 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002048 QueryTexParameterfv(texture, pname, params);
2049}
2050
Brandon Jones59770802018-04-02 13:18:42 -07002051void Context::getTexParameterfvRobust(TextureType target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 GLsizei *length,
2055 GLfloat *params)
2056{
2057 getTexParameterfv(target, pname, params);
2058}
2059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002060void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002061{
Till Rathmannb8543632018-10-02 19:46:14 +02002062 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002063 QueryTexParameteriv(texture, pname, params);
2064}
Jiajia Qin5451d532017-11-16 17:16:34 +08002065
Till Rathmannb8543632018-10-02 19:46:14 +02002066void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2067{
2068 const Texture *const texture = getTargetTexture(target);
2069 QueryTexParameterIiv(texture, pname, params);
2070}
2071
2072void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2073{
2074 const Texture *const texture = getTargetTexture(target);
2075 QueryTexParameterIuiv(texture, pname, params);
2076}
2077
Brandon Jones59770802018-04-02 13:18:42 -07002078void Context::getTexParameterivRobust(TextureType target,
2079 GLenum pname,
2080 GLsizei bufSize,
2081 GLsizei *length,
2082 GLint *params)
2083{
2084 getTexParameteriv(target, pname, params);
2085}
2086
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002087void Context::getTexParameterIivRobust(TextureType target,
2088 GLenum pname,
2089 GLsizei bufSize,
2090 GLsizei *length,
2091 GLint *params)
2092{
2093 UNIMPLEMENTED();
2094}
2095
2096void Context::getTexParameterIuivRobust(TextureType target,
2097 GLenum pname,
2098 GLsizei bufSize,
2099 GLsizei *length,
2100 GLuint *params)
2101{
2102 UNIMPLEMENTED();
2103}
2104
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002105void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002106{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002107 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002108 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002109}
2110
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002111void Context::getTexLevelParameterivRobust(TextureTarget target,
2112 GLint level,
2113 GLenum pname,
2114 GLsizei bufSize,
2115 GLsizei *length,
2116 GLint *params)
2117{
2118 UNIMPLEMENTED();
2119}
2120
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002121void Context::getTexLevelParameterfv(TextureTarget target,
2122 GLint level,
2123 GLenum pname,
2124 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002125{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002126 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002127 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002128}
2129
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002130void Context::getTexLevelParameterfvRobust(TextureTarget target,
2131 GLint level,
2132 GLenum pname,
2133 GLsizei bufSize,
2134 GLsizei *length,
2135 GLfloat *params)
2136{
2137 UNIMPLEMENTED();
2138}
2139
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002140void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002141{
Till Rathmannb8543632018-10-02 19:46:14 +02002142 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002143 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002144 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002145}
2146
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002147void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
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 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002151 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002152}
2153
Brandon Jones59770802018-04-02 13:18:42 -07002154void Context::texParameterfvRobust(TextureType target,
2155 GLenum pname,
2156 GLsizei bufSize,
2157 const GLfloat *params)
2158{
2159 texParameterfv(target, pname, params);
2160}
2161
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002162void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002163{
Till Rathmannb8543632018-10-02 19:46:14 +02002164 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002165 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002166 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002167}
2168
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002169void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002170{
Till Rathmannb8543632018-10-02 19:46:14 +02002171 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002172 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002173 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002174}
2175
Till Rathmannb8543632018-10-02 19:46:14 +02002176void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2177{
2178 Texture *const texture = getTargetTexture(target);
2179 SetTexParameterIiv(this, texture, pname, params);
2180 onTextureChange(texture);
2181}
2182
2183void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2184{
2185 Texture *const texture = getTargetTexture(target);
2186 SetTexParameterIuiv(this, texture, pname, params);
2187 onTextureChange(texture);
2188}
2189
Brandon Jones59770802018-04-02 13:18:42 -07002190void Context::texParameterivRobust(TextureType target,
2191 GLenum pname,
2192 GLsizei bufSize,
2193 const GLint *params)
2194{
2195 texParameteriv(target, pname, params);
2196}
2197
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002198void Context::texParameterIivRobust(TextureType target,
2199 GLenum pname,
2200 GLsizei bufSize,
2201 const GLint *params)
2202{
2203 UNIMPLEMENTED();
2204}
2205
2206void Context::texParameterIuivRobust(TextureType target,
2207 GLenum pname,
2208 GLsizei bufSize,
2209 const GLuint *params)
2210{
2211 UNIMPLEMENTED();
2212}
2213
Jamie Madill493f9572018-05-24 19:52:15 -04002214void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002216 // No-op if count draws no primitives for given mode
2217 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002218 {
2219 return;
2220 }
2221
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002222 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002223 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002224 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225}
2226
Jamie Madill493f9572018-05-24 19:52:15 -04002227void Context::drawArraysInstanced(PrimitiveMode mode,
2228 GLint first,
2229 GLsizei count,
2230 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002231{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002232 // No-op if count draws no primitives for given mode
2233 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002234 {
2235 return;
2236 }
2237
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002238 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002239 ANGLE_CONTEXT_TRY(
2240 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002241 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2242 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002243}
2244
Jamie Madill493f9572018-05-24 19:52:15 -04002245void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002246{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002247 // No-op if count draws no primitives for given mode
2248 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002249 {
2250 return;
2251 }
2252
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002253 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002254 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002255}
2256
Jamie Madill493f9572018-05-24 19:52:15 -04002257void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002258 GLsizei count,
2259 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002260 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002261 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002262{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002263 // No-op if count draws no primitives for given mode
2264 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002265 {
2266 return;
2267 }
2268
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002269 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002270 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002271 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002272}
2273
Jamie Madill493f9572018-05-24 19:52:15 -04002274void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002275 GLuint start,
2276 GLuint end,
2277 GLsizei count,
2278 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002279 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002280{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002281 // No-op if count draws no primitives for given mode
2282 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002283 {
2284 return;
2285 }
2286
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002287 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002288 ANGLE_CONTEXT_TRY(
2289 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002290}
2291
Jamie Madill493f9572018-05-24 19:52:15 -04002292void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002293{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002294 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002295 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002296}
2297
Jamie Madill493f9572018-05-24 19:52:15 -04002298void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002299{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002300 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002301 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002302}
2303
Jamie Madill675fe712016-12-19 13:07:54 -05002304void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002305{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002306 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002307}
2308
Jamie Madill675fe712016-12-19 13:07:54 -05002309void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002310{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002311 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002312}
2313
Austin Kinross6ee1e782015-05-29 17:05:37 -07002314void Context::insertEventMarker(GLsizei length, const char *marker)
2315{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002316 ASSERT(mImplementation);
2317 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002318}
2319
2320void Context::pushGroupMarker(GLsizei length, const char *marker)
2321{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002322 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002323
2324 if (marker == nullptr)
2325 {
2326 // From the EXT_debug_marker spec,
2327 // "If <marker> is null then an empty string is pushed on the stack."
2328 mImplementation->pushGroupMarker(length, "");
2329 }
2330 else
2331 {
2332 mImplementation->pushGroupMarker(length, marker);
2333 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002334}
2335
2336void Context::popGroupMarker()
2337{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002338 ASSERT(mImplementation);
2339 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002340}
2341
Geoff Langd8605522016-04-13 10:19:12 -04002342void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2343{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002344 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002345 ASSERT(programObject);
2346
2347 programObject->bindUniformLocation(location, name);
2348}
2349
Brandon Jones59770802018-04-02 13:18:42 -07002350void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002351{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002352 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002353}
2354
Brandon Jones59770802018-04-02 13:18:42 -07002355void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002356{
2357 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2358}
2359
Brandon Jones59770802018-04-02 13:18:42 -07002360void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361{
2362 GLfloat I[16];
2363 angle::Matrix<GLfloat>::setToIdentity(I);
2364
2365 mGLState.loadPathRenderingMatrix(matrixMode, I);
2366}
2367
2368void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2369{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002370 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002371 if (!pathObj)
2372 return;
2373
Geoff Lang9bf86f02018-07-26 11:46:34 -04002374 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002375
2376 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2377}
2378
2379void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2380{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002381 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002382 if (!pathObj)
2383 return;
2384
Geoff Lang9bf86f02018-07-26 11:46:34 -04002385 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002386
2387 mImplementation->stencilStrokePath(pathObj, reference, mask);
2388}
2389
2390void Context::coverFillPath(GLuint path, GLenum coverMode)
2391{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002392 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002393 if (!pathObj)
2394 return;
2395
Geoff Lang9bf86f02018-07-26 11:46:34 -04002396 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002397
2398 mImplementation->coverFillPath(pathObj, coverMode);
2399}
2400
2401void Context::coverStrokePath(GLuint path, GLenum coverMode)
2402{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002403 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002404 if (!pathObj)
2405 return;
2406
Geoff Lang9bf86f02018-07-26 11:46:34 -04002407 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408
2409 mImplementation->coverStrokePath(pathObj, coverMode);
2410}
2411
2412void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2413{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002414 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002415 if (!pathObj)
2416 return;
2417
Geoff Lang9bf86f02018-07-26 11:46:34 -04002418 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002419
2420 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2421}
2422
2423void Context::stencilThenCoverStrokePath(GLuint path,
2424 GLint reference,
2425 GLuint mask,
2426 GLenum coverMode)
2427{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002428 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002429 if (!pathObj)
2430 return;
2431
Geoff Lang9bf86f02018-07-26 11:46:34 -04002432 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002433
2434 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2435}
2436
Sami Väisänend59ca052016-06-21 16:10:00 +03002437void Context::coverFillPathInstanced(GLsizei numPaths,
2438 GLenum pathNameType,
2439 const void *paths,
2440 GLuint pathBase,
2441 GLenum coverMode,
2442 GLenum transformType,
2443 const GLfloat *transformValues)
2444{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002446
Geoff Lang9bf86f02018-07-26 11:46:34 -04002447 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002448
2449 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2450}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002451
Sami Väisänend59ca052016-06-21 16:10:00 +03002452void Context::coverStrokePathInstanced(GLsizei numPaths,
2453 GLenum pathNameType,
2454 const void *paths,
2455 GLuint pathBase,
2456 GLenum coverMode,
2457 GLenum transformType,
2458 const GLfloat *transformValues)
2459{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002460 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002461
2462 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002463 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002464
2465 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2466 transformValues);
2467}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002468
Sami Väisänend59ca052016-06-21 16:10:00 +03002469void Context::stencilFillPathInstanced(GLsizei numPaths,
2470 GLenum pathNameType,
2471 const void *paths,
2472 GLuint pathBase,
2473 GLenum fillMode,
2474 GLuint mask,
2475 GLenum transformType,
2476 const GLfloat *transformValues)
2477{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002478 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002479
2480 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002481 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002482
2483 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2484 transformValues);
2485}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002486
Sami Väisänend59ca052016-06-21 16:10:00 +03002487void Context::stencilStrokePathInstanced(GLsizei numPaths,
2488 GLenum pathNameType,
2489 const void *paths,
2490 GLuint pathBase,
2491 GLint reference,
2492 GLuint mask,
2493 GLenum transformType,
2494 const GLfloat *transformValues)
2495{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002496 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002497
Geoff Lang9bf86f02018-07-26 11:46:34 -04002498 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002499
2500 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2501 transformValues);
2502}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002503
Sami Väisänend59ca052016-06-21 16:10:00 +03002504void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2505 GLenum pathNameType,
2506 const void *paths,
2507 GLuint pathBase,
2508 GLenum fillMode,
2509 GLuint mask,
2510 GLenum coverMode,
2511 GLenum transformType,
2512 const GLfloat *transformValues)
2513{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002514 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002515
Geoff Lang9bf86f02018-07-26 11:46:34 -04002516 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002517
2518 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2519 transformType, transformValues);
2520}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002521
Sami Väisänend59ca052016-06-21 16:10:00 +03002522void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2523 GLenum pathNameType,
2524 const void *paths,
2525 GLuint pathBase,
2526 GLint reference,
2527 GLuint mask,
2528 GLenum coverMode,
2529 GLenum transformType,
2530 const GLfloat *transformValues)
2531{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002532 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002533
Geoff Lang9bf86f02018-07-26 11:46:34 -04002534 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002535
2536 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2537 transformType, transformValues);
2538}
2539
Sami Väisänen46eaa942016-06-29 10:26:37 +03002540void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2541{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002542 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002543
2544 programObject->bindFragmentInputLocation(location, name);
2545}
2546
2547void Context::programPathFragmentInputGen(GLuint program,
2548 GLint location,
2549 GLenum genMode,
2550 GLint components,
2551 const GLfloat *coeffs)
2552{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002553 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002554
jchen103fd614d2018-08-13 12:21:58 +08002555 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002556}
2557
jchen1015015f72017-03-16 13:54:21 +08002558GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2559{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002560 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002561 return QueryProgramResourceIndex(programObject, programInterface, name);
2562}
2563
jchen10fd7c3b52017-03-21 15:36:03 +08002564void Context::getProgramResourceName(GLuint program,
2565 GLenum programInterface,
2566 GLuint index,
2567 GLsizei bufSize,
2568 GLsizei *length,
2569 GLchar *name)
2570{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002571 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002572 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2573}
2574
jchen10191381f2017-04-11 13:59:04 +08002575GLint Context::getProgramResourceLocation(GLuint program,
2576 GLenum programInterface,
2577 const GLchar *name)
2578{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002579 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002580 return QueryProgramResourceLocation(programObject, programInterface, name);
2581}
2582
jchen10880683b2017-04-12 16:21:55 +08002583void Context::getProgramResourceiv(GLuint program,
2584 GLenum programInterface,
2585 GLuint index,
2586 GLsizei propCount,
2587 const GLenum *props,
2588 GLsizei bufSize,
2589 GLsizei *length,
2590 GLint *params)
2591{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002592 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002593 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2594 length, params);
2595}
2596
jchen10d9cd7b72017-08-30 15:04:25 +08002597void Context::getProgramInterfaceiv(GLuint program,
2598 GLenum programInterface,
2599 GLenum pname,
2600 GLint *params)
2601{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002602 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002603 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2604}
2605
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002606void Context::getProgramInterfaceivRobust(GLuint program,
2607 GLenum programInterface,
2608 GLenum pname,
2609 GLsizei bufSize,
2610 GLsizei *length,
2611 GLint *params)
2612{
2613 UNIMPLEMENTED();
2614}
2615
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002616void Context::handleError(GLenum errorCode,
2617 const char *message,
2618 const char *file,
2619 const char *function,
2620 unsigned int line)
2621{
2622 mErrors.handleError(errorCode, message, file, function, line);
2623}
2624
Jamie Madilla139f012018-10-10 16:13:03 -04002625void Context::validationError(GLenum errorCode, const char *message)
2626{
2627 mErrors.validationError(errorCode, message);
2628}
2629
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002630// Get one of the recorded errors and clear its flag, if any.
2631// [OpenGL ES 2.0.24] section 2.5 page 13.
2632GLenum Context::getError()
2633{
Geoff Langda5777c2014-07-11 09:52:58 -04002634 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002635 {
Geoff Langda5777c2014-07-11 09:52:58 -04002636 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637 }
Geoff Langda5777c2014-07-11 09:52:58 -04002638 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002640 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642}
2643
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002644// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002645void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002646{
2647 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002648 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002649 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002650 mContextLostForced = true;
2651 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002652 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653}
2654
Jamie Madillfa920eb2018-01-04 11:45:50 -05002655GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657 // Even if the application doesn't want to know about resets, we want to know
2658 // as it will allow us to skip all the calls.
2659 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002661 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002662 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002663 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002664 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665
2666 // EXT_robustness, section 2.6: If the reset notification behavior is
2667 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2668 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2669 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670 }
2671
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002672 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2673 // status should be returned at least once, and GL_NO_ERROR should be returned
2674 // once the device has finished resetting.
2675 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002676 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002677 ASSERT(mResetStatus == GL_NO_ERROR);
2678 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002679
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002681 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002682 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002683 }
2684 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002685 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002686 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002687 // If markContextLost was used to mark the context lost then
2688 // assume that is not recoverable, and continue to report the
2689 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002690 mResetStatus = mImplementation->getResetStatus();
2691 }
Jamie Madill893ab082014-05-16 16:56:10 -04002692
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002693 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002694}
2695
2696bool Context::isResetNotificationEnabled()
2697{
2698 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2699}
2700
Corentin Walleze3b10e82015-05-20 11:06:25 -04002701const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002702{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002703 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002704}
2705
2706EGLenum Context::getClientType() const
2707{
2708 return mClientType;
2709}
2710
2711EGLenum Context::getRenderBuffer() const
2712{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002713 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2714 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002715 {
2716 return EGL_NONE;
2717 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002718
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002719 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002720 ASSERT(backAttachment != nullptr);
2721 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002722}
2723
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002724VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002725{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002726 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002727 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2728 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002729 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002730 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2731 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002732
Jamie Madill96a483b2017-06-27 16:49:21 -04002733 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002735
2736 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002737}
2738
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002739TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002740{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002741 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002742 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2743 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002744 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002745 transformFeedback =
2746 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002747 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002748 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002749 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002750
2751 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002752}
2753
2754bool Context::isVertexArrayGenerated(GLuint vertexArray)
2755{
Jamie Madill96a483b2017-06-27 16:49:21 -04002756 ASSERT(mVertexArrayMap.contains(0));
2757 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002758}
2759
2760bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2761{
Jamie Madill96a483b2017-06-27 16:49:21 -04002762 ASSERT(mTransformFeedbackMap.contains(0));
2763 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002764}
2765
Shannon Woods53a94a82014-06-24 15:20:36 -04002766void Context::detachTexture(GLuint texture)
2767{
2768 // Simple pass-through to State's detachTexture method, as textures do not require
2769 // allocation map management either here or in the resource manager at detach time.
2770 // Zero textures are held by the Context, and we don't attempt to request them from
2771 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002772 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002773}
2774
James Darpinian4d9d4832018-03-13 12:43:28 -07002775void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776{
Yuly Novikov5807a532015-12-03 13:01:22 -05002777 // Simple pass-through to State's detachBuffer method, since
2778 // only buffer attachments to container objects that are bound to the current context
2779 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002780
Yuly Novikov5807a532015-12-03 13:01:22 -05002781 // [OpenGL ES 3.2] section 5.1.2 page 45:
2782 // Attachments to unbound container objects, such as
2783 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2784 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002785 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786}
2787
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788void Context::detachFramebuffer(GLuint framebuffer)
2789{
Shannon Woods53a94a82014-06-24 15:20:36 -04002790 // Framebuffer detachment is handled by Context, because 0 is a valid
2791 // Framebuffer object, and a pointer to it must be passed from Context
2792 // to State at binding time.
2793
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002794 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002795 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2796 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2797 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002799 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800 {
2801 bindReadFramebuffer(0);
2802 }
2803
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002804 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002805 {
2806 bindDrawFramebuffer(0);
2807 }
2808}
2809
2810void Context::detachRenderbuffer(GLuint renderbuffer)
2811{
Jamie Madilla02315b2017-02-23 14:14:47 -05002812 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002813}
2814
Jamie Madill57a89722013-07-02 11:57:03 -04002815void Context::detachVertexArray(GLuint vertexArray)
2816{
Jamie Madill77a72f62015-04-14 11:18:32 -04002817 // Vertex array detachment is handled by Context, because 0 is a valid
2818 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002819 // binding time.
2820
Jamie Madill57a89722013-07-02 11:57:03 -04002821 // [OpenGL ES 3.0.2] section 2.10 page 43:
2822 // If a vertex array object that is currently bound is deleted, the binding
2823 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002824 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002825 {
2826 bindVertexArray(0);
2827 }
2828}
2829
Geoff Langc8058452014-02-03 12:04:11 -05002830void Context::detachTransformFeedback(GLuint transformFeedback)
2831{
Corentin Walleza2257da2016-04-19 16:43:12 -04002832 // Transform feedback detachment is handled by Context, because 0 is a valid
2833 // transform feedback, and a pointer to it must be passed from Context to State at
2834 // binding time.
2835
2836 // The OpenGL specification doesn't mention what should happen when the currently bound
2837 // transform feedback object is deleted. Since it is a container object, we treat it like
2838 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002839 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002840 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002841 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002842 }
Geoff Langc8058452014-02-03 12:04:11 -05002843}
2844
Jamie Madilldc356042013-07-19 16:36:57 -04002845void Context::detachSampler(GLuint sampler)
2846{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002847 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002848}
2849
Yunchao Hea336b902017-08-02 16:05:21 +08002850void Context::detachProgramPipeline(GLuint pipeline)
2851{
2852 mGLState.detachProgramPipeline(this, pipeline);
2853}
2854
Jamie Madill3ef140a2017-08-26 23:11:21 -04002855void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002856{
Shaodde78e82017-05-22 14:13:27 +08002857 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002858 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002859}
2860
Jamie Madille29d1672013-07-19 16:36:57 -04002861void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2862{
Till Rathmannb8543632018-10-02 19:46:14 +02002863 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002864 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002865 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002866}
Jamie Madille29d1672013-07-19 16:36:57 -04002867
Geoff Langc1984ed2016-10-07 12:41:00 -04002868void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2869{
Till Rathmannb8543632018-10-02 19:46:14 +02002870 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002871 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002872 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002873}
2874
Till Rathmannb8543632018-10-02 19:46:14 +02002875void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2876{
2877 Sampler *const samplerObject =
2878 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2879 SetSamplerParameterIiv(this, samplerObject, pname, param);
2880}
2881
2882void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2883{
2884 Sampler *const samplerObject =
2885 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2886 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2887}
2888
Brandon Jones59770802018-04-02 13:18:42 -07002889void Context::samplerParameterivRobust(GLuint sampler,
2890 GLenum pname,
2891 GLsizei bufSize,
2892 const GLint *param)
2893{
2894 samplerParameteriv(sampler, pname, param);
2895}
2896
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002897void Context::samplerParameterIivRobust(GLuint sampler,
2898 GLenum pname,
2899 GLsizei bufSize,
2900 const GLint *param)
2901{
2902 UNIMPLEMENTED();
2903}
2904
2905void Context::samplerParameterIuivRobust(GLuint sampler,
2906 GLenum pname,
2907 GLsizei bufSize,
2908 const GLuint *param)
2909{
2910 UNIMPLEMENTED();
2911}
2912
Jamie Madille29d1672013-07-19 16:36:57 -04002913void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2914{
Till Rathmannb8543632018-10-02 19:46:14 +02002915 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002916 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002917 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002918}
2919
Geoff Langc1984ed2016-10-07 12:41:00 -04002920void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002921{
Till Rathmannb8543632018-10-02 19:46:14 +02002922 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002923 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002924 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002925}
2926
Brandon Jones59770802018-04-02 13:18:42 -07002927void Context::samplerParameterfvRobust(GLuint sampler,
2928 GLenum pname,
2929 GLsizei bufSize,
2930 const GLfloat *param)
2931{
2932 samplerParameterfv(sampler, pname, param);
2933}
2934
Geoff Langc1984ed2016-10-07 12:41:00 -04002935void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002936{
Till Rathmannb8543632018-10-02 19:46:14 +02002937 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002938 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002939 QuerySamplerParameteriv(samplerObject, pname, params);
2940}
Jamie Madill9675b802013-07-19 16:36:59 -04002941
Till Rathmannb8543632018-10-02 19:46:14 +02002942void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2943{
2944 const Sampler *const samplerObject =
2945 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2946 QuerySamplerParameterIiv(samplerObject, pname, params);
2947}
2948
2949void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2950{
2951 const Sampler *const samplerObject =
2952 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2953 QuerySamplerParameterIuiv(samplerObject, pname, params);
2954}
2955
Brandon Jones59770802018-04-02 13:18:42 -07002956void Context::getSamplerParameterivRobust(GLuint sampler,
2957 GLenum pname,
2958 GLsizei bufSize,
2959 GLsizei *length,
2960 GLint *params)
2961{
2962 getSamplerParameteriv(sampler, pname, params);
2963}
2964
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002965void Context::getSamplerParameterIivRobust(GLuint sampler,
2966 GLenum pname,
2967 GLsizei bufSize,
2968 GLsizei *length,
2969 GLint *params)
2970{
2971 UNIMPLEMENTED();
2972}
2973
2974void Context::getSamplerParameterIuivRobust(GLuint sampler,
2975 GLenum pname,
2976 GLsizei bufSize,
2977 GLsizei *length,
2978 GLuint *params)
2979{
2980 UNIMPLEMENTED();
2981}
2982
Geoff Langc1984ed2016-10-07 12:41:00 -04002983void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2984{
Till Rathmannb8543632018-10-02 19:46:14 +02002985 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002986 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002987 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002988}
2989
Brandon Jones59770802018-04-02 13:18:42 -07002990void Context::getSamplerParameterfvRobust(GLuint sampler,
2991 GLenum pname,
2992 GLsizei bufSize,
2993 GLsizei *length,
2994 GLfloat *params)
2995{
2996 getSamplerParameterfv(sampler, pname, params);
2997}
2998
Olli Etuahof0fee072016-03-30 15:11:58 +03002999void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3000{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003001 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003002 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003003}
3004
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003005void Context::initRendererString()
3006{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003007 std::ostringstream rendererString;
3008 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003009 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003010 rendererString << ")";
3011
Geoff Langcec35902014-04-16 10:52:36 -04003012 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003013}
3014
Geoff Langc339c4e2016-11-29 10:37:36 -05003015void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003016{
Geoff Langc339c4e2016-11-29 10:37:36 -05003017 const Version &clientVersion = getClientVersion();
3018
3019 std::ostringstream versionString;
3020 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3021 << ANGLE_VERSION_STRING << ")";
3022 mVersionString = MakeStaticString(versionString.str());
3023
3024 std::ostringstream shadingLanguageVersionString;
3025 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3026 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3027 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3028 << ")";
3029 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003030}
3031
Geoff Langcec35902014-04-16 10:52:36 -04003032void Context::initExtensionStrings()
3033{
Geoff Langc339c4e2016-11-29 10:37:36 -05003034 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3035 std::ostringstream combinedStringStream;
3036 std::copy(strings.begin(), strings.end(),
3037 std::ostream_iterator<const char *>(combinedStringStream, " "));
3038 return MakeStaticString(combinedStringStream.str());
3039 };
3040
3041 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003042 for (const auto &extensionString : mExtensions.getStrings())
3043 {
3044 mExtensionStrings.push_back(MakeStaticString(extensionString));
3045 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003046 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003047
Geoff Langc339c4e2016-11-29 10:37:36 -05003048 mRequestableExtensionStrings.clear();
3049 for (const auto &extensionInfo : GetExtensionInfoMap())
3050 {
3051 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003052 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003053 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003054 {
3055 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3056 }
3057 }
3058 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003059}
3060
Geoff Langc339c4e2016-11-29 10:37:36 -05003061const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003062{
Geoff Langc339c4e2016-11-29 10:37:36 -05003063 switch (name)
3064 {
3065 case GL_VENDOR:
3066 return reinterpret_cast<const GLubyte *>("Google Inc.");
3067
3068 case GL_RENDERER:
3069 return reinterpret_cast<const GLubyte *>(mRendererString);
3070
3071 case GL_VERSION:
3072 return reinterpret_cast<const GLubyte *>(mVersionString);
3073
3074 case GL_SHADING_LANGUAGE_VERSION:
3075 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3076
3077 case GL_EXTENSIONS:
3078 return reinterpret_cast<const GLubyte *>(mExtensionString);
3079
3080 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3081 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3082
3083 default:
3084 UNREACHABLE();
3085 return nullptr;
3086 }
Geoff Langcec35902014-04-16 10:52:36 -04003087}
3088
Geoff Langc339c4e2016-11-29 10:37:36 -05003089const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003090{
Geoff Langc339c4e2016-11-29 10:37:36 -05003091 switch (name)
3092 {
3093 case GL_EXTENSIONS:
3094 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3095
3096 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3097 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3098
3099 default:
3100 UNREACHABLE();
3101 return nullptr;
3102 }
Geoff Langcec35902014-04-16 10:52:36 -04003103}
3104
3105size_t Context::getExtensionStringCount() const
3106{
3107 return mExtensionStrings.size();
3108}
3109
Geoff Lang111a99e2017-10-17 10:58:41 -04003110bool Context::isExtensionRequestable(const char *name)
3111{
3112 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3113 auto extension = extensionInfos.find(name);
3114
Geoff Lang111a99e2017-10-17 10:58:41 -04003115 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003116 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003117}
3118
Geoff Langc339c4e2016-11-29 10:37:36 -05003119void Context::requestExtension(const char *name)
3120{
3121 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3122 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3123 const auto &extension = extensionInfos.at(name);
3124 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003125 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003126
3127 if (mExtensions.*(extension.ExtensionsMember))
3128 {
3129 // Extension already enabled
3130 return;
3131 }
3132
3133 mExtensions.*(extension.ExtensionsMember) = true;
3134 updateCaps();
3135 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003136
Jamie Madill2f348d22017-06-05 10:50:59 -04003137 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3138 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003139
Jamie Madill81c2e252017-09-09 23:32:46 -04003140 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3141 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003142 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003143 for (auto &zeroTexture : mZeroTextures)
3144 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003145 if (zeroTexture.get() != nullptr)
3146 {
3147 zeroTexture->signalDirty(this, InitState::Initialized);
3148 }
Geoff Lang9aded172017-04-05 11:07:56 -04003149 }
3150
Jamie Madillb983a4b2018-08-01 11:34:51 -04003151 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003152}
3153
3154size_t Context::getRequestableExtensionStringCount() const
3155{
3156 return mRequestableExtensionStrings.size();
3157}
3158
Jamie Madill493f9572018-05-24 19:52:15 -04003159void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003160{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003161 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003162 ASSERT(transformFeedback != nullptr);
3163 ASSERT(!transformFeedback->isPaused());
3164
Jamie Madill6c1f6712017-02-14 19:08:04 -05003165 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003166 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003167}
3168
3169bool Context::hasActiveTransformFeedback(GLuint program) const
3170{
3171 for (auto pair : mTransformFeedbackMap)
3172 {
3173 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3174 {
3175 return true;
3176 }
3177 }
3178 return false;
3179}
3180
Geoff Lang33f11fb2018-05-07 13:42:47 -04003181Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003182{
3183 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3184
jchen1082af6202018-06-22 10:59:52 +08003185 // Explicitly enable GL_KHR_parallel_shader_compile
3186 supportedExtensions.parallelShaderCompile = true;
3187
Geoff Langb0f917f2017-12-05 13:41:54 -05003188 if (getClientVersion() < ES_2_0)
3189 {
3190 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003191 supportedExtensions.pointSizeArray = true;
3192 supportedExtensions.textureCubeMap = true;
3193 supportedExtensions.pointSprite = true;
3194 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003195 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003196 }
3197
3198 if (getClientVersion() < ES_3_0)
3199 {
3200 // Disable ES3+ extensions
3201 supportedExtensions.colorBufferFloat = false;
3202 supportedExtensions.eglImageExternalEssl3 = false;
3203 supportedExtensions.textureNorm16 = false;
3204 supportedExtensions.multiview = false;
3205 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003206 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003207 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003208
3209 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3210 if (!supportedExtensions.sRGB)
3211 {
3212 supportedExtensions.textureSRGBDecode = false;
3213 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003214 }
3215
3216 if (getClientVersion() < ES_3_1)
3217 {
3218 // Disable ES3.1+ extensions
3219 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003220
3221 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3222 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003223 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003224 }
3225
3226 if (getClientVersion() > ES_2_0)
3227 {
3228 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3229 // supportedExtensions.sRGB = false;
3230 }
3231
3232 // Some extensions are always available because they are implemented in the GL layer.
3233 supportedExtensions.bindUniformLocation = true;
3234 supportedExtensions.vertexArrayObject = true;
3235 supportedExtensions.bindGeneratesResource = true;
3236 supportedExtensions.clientArrays = true;
3237 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003238 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003239
3240 // Enable the no error extension if the context was created with the flag.
3241 supportedExtensions.noError = mSkipValidation;
3242
3243 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003244 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003245
3246 // Explicitly enable GL_KHR_debug
3247 supportedExtensions.debug = true;
3248 supportedExtensions.maxDebugMessageLength = 1024;
3249 supportedExtensions.maxDebugLoggedMessages = 1024;
3250 supportedExtensions.maxDebugGroupStackDepth = 1024;
3251 supportedExtensions.maxLabelLength = 1024;
3252
3253 // Explicitly enable GL_ANGLE_robust_client_memory
3254 supportedExtensions.robustClientMemory = true;
3255
3256 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003257 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003258
3259 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3260 // supports it.
3261 supportedExtensions.robustBufferAccessBehavior =
3262 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3263
3264 // Enable the cache control query unconditionally.
3265 supportedExtensions.programCacheControl = true;
3266
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003267 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003268 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003269 {
3270 // GL_ANGLE_explicit_context_gles1
3271 supportedExtensions.explicitContextGles1 = true;
3272 // GL_ANGLE_explicit_context
3273 supportedExtensions.explicitContext = true;
3274 }
3275
Geoff Lang79b91402018-10-04 15:11:30 -04003276 supportedExtensions.memorySize = true;
3277
Geoff Langb0f917f2017-12-05 13:41:54 -05003278 return supportedExtensions;
3279}
3280
Geoff Lang33f11fb2018-05-07 13:42:47 -04003281void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003282{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003283 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003284
Geoff Lang33f11fb2018-05-07 13:42:47 -04003285 mSupportedExtensions = generateSupportedExtensions();
3286 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003287
3288 mLimitations = mImplementation->getNativeLimitations();
3289
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003290 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3291 if (getClientVersion() < Version(2, 0))
3292 {
3293 mCaps.maxMultitextureUnits = 4;
3294 mCaps.maxClipPlanes = 6;
3295 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003296 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3297 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3298 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003299 mCaps.minSmoothPointSize = 1.0f;
3300 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003301 mCaps.minSmoothLineWidth = 1.0f;
3302 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003303 }
3304
Luc Ferronad2ae932018-06-11 15:31:17 -04003305 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003306 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003307
Luc Ferronad2ae932018-06-11 15:31:17 -04003308 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3309
Jamie Madill0f80ed82017-09-19 00:24:56 -04003310 if (getClientVersion() < ES_3_1)
3311 {
3312 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3313 }
3314 else
3315 {
3316 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3317 }
Geoff Lang301d1612014-07-09 10:34:37 -04003318
Jiawei Shao54aafe52018-04-27 14:54:57 +08003319 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3320 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003321 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3322
Jamie Madill0f80ed82017-09-19 00:24:56 -04003323 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3324 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3325
3326 // Limit textures as well, so we can use fast bitsets with texture bindings.
3327 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003328 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3329 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3330 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3331 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003332
Jiawei Shaodb342272017-09-27 10:21:45 +08003333 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3334
Geoff Langc287ea62016-09-16 14:46:51 -04003335 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003336 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003337 for (const auto &extensionInfo : GetExtensionInfoMap())
3338 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003339 // If the user has requested that extensions start disabled and they are requestable,
3340 // disable them.
3341 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003342 {
3343 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3344 }
3345 }
3346
3347 // Generate texture caps
3348 updateCaps();
3349}
3350
3351void Context::updateCaps()
3352{
Geoff Lang900013c2014-07-07 11:32:19 -04003353 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003354 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003355
Jamie Madill7b62cf92017-11-02 15:20:49 -04003356 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003357 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003358 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003359 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003360
Geoff Lang0d8b7242015-09-09 14:56:53 -04003361 // Update the format caps based on the client version and extensions.
3362 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3363 // ES3.
3364 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003365 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003366 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003367 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003368 formatCaps.textureAttachment =
3369 formatCaps.textureAttachment &&
3370 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3371 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3372 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003373
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003374 // OpenGL ES does not support multisampling with non-rendererable formats
3375 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003376 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003377 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003378 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003379 {
Geoff Langd87878e2014-09-19 15:42:59 -04003380 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003381 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003382 else
3383 {
3384 // We may have limited the max samples for some required renderbuffer formats due to
3385 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3386 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3387
3388 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3389 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3390 // exception of signed and unsigned integer formats."
3391 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3392 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3393 {
3394 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3395 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3396 }
3397
3398 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003399 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003400 {
3401 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3402 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3403 // the exception that the signed and unsigned integer formats are required only to
3404 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3405 // multisamples, which must be at least one."
3406 if (formatInfo.componentType == GL_INT ||
3407 formatInfo.componentType == GL_UNSIGNED_INT)
3408 {
3409 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3410 }
3411
3412 // GLES 3.1 section 19.3.1.
3413 if (formatCaps.texturable)
3414 {
3415 if (formatInfo.depthBits > 0)
3416 {
3417 mCaps.maxDepthTextureSamples =
3418 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3419 }
3420 else if (formatInfo.redBits > 0)
3421 {
3422 mCaps.maxColorTextureSamples =
3423 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3424 }
3425 }
3426 }
3427 }
Geoff Langd87878e2014-09-19 15:42:59 -04003428
3429 if (formatCaps.texturable && formatInfo.compressed)
3430 {
Geoff Langca271392017-04-05 12:30:00 -04003431 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003432 }
3433
Geoff Langca271392017-04-05 12:30:00 -04003434 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003435 }
Jamie Madill32447362017-06-28 14:53:52 -04003436
3437 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003438 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003439 {
3440 mMemoryProgramCache = nullptr;
3441 }
Corentin Walleze4477002017-12-01 14:39:58 -05003442
3443 // Compute which buffer types are allowed
3444 mValidBufferBindings.reset();
3445 mValidBufferBindings.set(BufferBinding::ElementArray);
3446 mValidBufferBindings.set(BufferBinding::Array);
3447
3448 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3449 {
3450 mValidBufferBindings.set(BufferBinding::PixelPack);
3451 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3452 }
3453
3454 if (getClientVersion() >= ES_3_0)
3455 {
3456 mValidBufferBindings.set(BufferBinding::CopyRead);
3457 mValidBufferBindings.set(BufferBinding::CopyWrite);
3458 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3459 mValidBufferBindings.set(BufferBinding::Uniform);
3460 }
3461
3462 if (getClientVersion() >= ES_3_1)
3463 {
3464 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3465 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3466 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3467 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3468 }
jchen107ae70d82018-07-06 13:47:01 +08003469
3470 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003471
3472 // Reinitialize state cache after extension changes.
3473 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003474}
3475
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003476void Context::initWorkarounds()
3477{
Jamie Madill761b02c2017-06-23 16:27:06 -04003478 // Apply back-end workarounds.
3479 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3480
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003481 // Lose the context upon out of memory error if the application is
3482 // expecting to watch for those events.
3483 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003484
3485 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3486 {
3487 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3488 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3489 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3490 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003491}
3492
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003493// Return true if the draw is a no-op, else return false.
3494// A no-op draw occurs if the count of vertices is less than the minimum required to
3495// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3496bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3497{
3498 return count < kMinimumPrimitiveCounts[mode];
3499}
3500
3501bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3502{
3503 return (instanceCount == 0) || noopDraw(mode, count);
3504}
3505
Jamie Madill6f755b22018-10-09 12:48:54 -04003506angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003507{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003508 if (mGLES1Renderer)
3509 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003510 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003511 }
3512
Geoff Lang9bf86f02018-07-26 11:46:34 -04003513 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003514
3515 if (isRobustResourceInitEnabled())
3516 {
3517 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3518 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3519 }
3520
Jamie Madill9e63a812018-11-16 12:30:04 +00003521 ANGLE_TRY(syncDirtyBits());
3522 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003523}
3524
Jamie Madill526392d2018-11-16 09:35:14 -05003525angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003526{
Geoff Langa8cb2872018-03-09 16:09:40 -05003527 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003528 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003529 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003530 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003531}
3532
Jamie Madill526392d2018-11-16 09:35:14 -05003533angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003534{
Geoff Langa8cb2872018-03-09 16:09:40 -05003535 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003536 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3537 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003538 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003539 return angle::Result::Continue();
Jamie Madill05b35b22017-10-03 09:01:44 -04003540}
3541
Jamie Madill526392d2018-11-16 09:35:14 -05003542angle::Result Context::syncState(const State::DirtyBits &bitMask,
3543 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003544{
Geoff Langa8cb2872018-03-09 16:09:40 -05003545 ANGLE_TRY(syncDirtyObjects(objectMask));
3546 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill526392d2018-11-16 09:35:14 -05003547 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003548}
3549
Jamie Madill9e63a812018-11-16 12:30:04 +00003550angle::Result Context::syncDirtyBits()
3551{
3552 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3553 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3554 mGLState.clearDirtyBits();
3555 return angle::Result::Continue();
3556}
3557
3558angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3559{
3560 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3561 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3562 mGLState.clearDirtyBits(dirtyBits);
3563 return angle::Result::Continue();
3564}
3565
3566angle::Result Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
3567{
3568 return mGLState.syncDirtyObjects(this, objectMask);
3569}
3570
Jamie Madillc29968b2016-01-20 11:17:23 -05003571void Context::blitFramebuffer(GLint srcX0,
3572 GLint srcY0,
3573 GLint srcX1,
3574 GLint srcY1,
3575 GLint dstX0,
3576 GLint dstY0,
3577 GLint dstX1,
3578 GLint dstY1,
3579 GLbitfield mask,
3580 GLenum filter)
3581{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003582 if (mask == 0)
3583 {
3584 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3585 // buffers are copied.
3586 return;
3587 }
3588
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003589 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 ASSERT(drawFramebuffer);
3591
3592 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3593 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3594
Jamie Madillbc918e72018-03-08 09:47:21 -05003595 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003596
Jamie Madill4f6592f2018-11-27 16:37:45 -05003597 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003598}
Jamie Madillc29968b2016-01-20 11:17:23 -05003599
3600void Context::clear(GLbitfield mask)
3601{
Geoff Langd4fff502017-09-22 11:28:28 -04003602 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3603 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003604}
3605
3606void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3607{
Olli Etuaho78df3362018-10-05 16:43:27 +03003608 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3609 const FramebufferAttachment *attachment = nullptr;
3610 if (buffer == GL_DEPTH)
3611 {
3612 attachment = framebufferObject->getDepthbuffer();
3613 }
3614 if (buffer == GL_COLOR &&
3615 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3616 {
3617 attachment = framebufferObject->getColorbuffer(drawbuffer);
3618 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003619 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3620 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003621 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003622 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003623 return;
3624 }
Geoff Langd4fff502017-09-22 11:28:28 -04003625 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003626 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003627}
3628
3629void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3630{
Olli Etuaho78df3362018-10-05 16:43:27 +03003631 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3632 const FramebufferAttachment *attachment = nullptr;
3633 if (buffer == GL_COLOR &&
3634 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3635 {
3636 attachment = framebufferObject->getColorbuffer(drawbuffer);
3637 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003638 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3639 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003640 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003641 {
3642 return;
3643 }
Geoff Langd4fff502017-09-22 11:28:28 -04003644 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003645 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003646}
3647
3648void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3649{
Olli Etuaho78df3362018-10-05 16:43:27 +03003650 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3651 const FramebufferAttachment *attachment = nullptr;
3652 if (buffer == GL_STENCIL)
3653 {
3654 attachment = framebufferObject->getStencilbuffer();
3655 }
3656 if (buffer == GL_COLOR &&
3657 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3658 {
3659 attachment = framebufferObject->getColorbuffer(drawbuffer);
3660 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003661 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3662 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003663 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003664 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003665 return;
3666 }
Geoff Langd4fff502017-09-22 11:28:28 -04003667 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003668 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003669}
3670
3671void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3672{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003673 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 ASSERT(framebufferObject);
3675
3676 // If a buffer is not present, the clear has no effect
3677 if (framebufferObject->getDepthbuffer() == nullptr &&
3678 framebufferObject->getStencilbuffer() == nullptr)
3679 {
3680 return;
3681 }
3682
Geoff Langd4fff502017-09-22 11:28:28 -04003683 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3684 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003685}
3686
3687void Context::readPixels(GLint x,
3688 GLint y,
3689 GLsizei width,
3690 GLsizei height,
3691 GLenum format,
3692 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003693 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003694{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003695 if (width == 0 || height == 0)
3696 {
3697 return;
3698 }
3699
Jamie Madillbc918e72018-03-08 09:47:21 -05003700 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003701
Jamie Madillb6664922017-07-25 12:55:04 -04003702 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3703 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003704
3705 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003706 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003707}
3708
Brandon Jones59770802018-04-02 13:18:42 -07003709void Context::readPixelsRobust(GLint x,
3710 GLint y,
3711 GLsizei width,
3712 GLsizei height,
3713 GLenum format,
3714 GLenum type,
3715 GLsizei bufSize,
3716 GLsizei *length,
3717 GLsizei *columns,
3718 GLsizei *rows,
3719 void *pixels)
3720{
3721 readPixels(x, y, width, height, format, type, pixels);
3722}
3723
3724void Context::readnPixelsRobust(GLint x,
3725 GLint y,
3726 GLsizei width,
3727 GLsizei height,
3728 GLenum format,
3729 GLenum type,
3730 GLsizei bufSize,
3731 GLsizei *length,
3732 GLsizei *columns,
3733 GLsizei *rows,
3734 void *data)
3735{
3736 readPixels(x, y, width, height, format, type, data);
3737}
3738
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003739void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 GLint level,
3741 GLenum internalformat,
3742 GLint x,
3743 GLint y,
3744 GLsizei width,
3745 GLsizei height,
3746 GLint border)
3747{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003748 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003749 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003750
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 Rectangle sourceArea(x, y, width, height);
3752
Jamie Madill05b35b22017-10-03 09:01:44 -04003753 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003754 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003755 ANGLE_CONTEXT_TRY(
3756 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003757}
3758
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003759void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003760 GLint level,
3761 GLint xoffset,
3762 GLint yoffset,
3763 GLint x,
3764 GLint y,
3765 GLsizei width,
3766 GLsizei height)
3767{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003768 if (width == 0 || height == 0)
3769 {
3770 return;
3771 }
3772
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003773 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003774 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003775
Jamie Madillc29968b2016-01-20 11:17:23 -05003776 Offset destOffset(xoffset, yoffset, 0);
3777 Rectangle sourceArea(x, y, width, height);
3778
Jamie Madill05b35b22017-10-03 09:01:44 -04003779 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003780 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003781 ANGLE_CONTEXT_TRY(
3782 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003783}
3784
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003785void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003786 GLint level,
3787 GLint xoffset,
3788 GLint yoffset,
3789 GLint zoffset,
3790 GLint x,
3791 GLint y,
3792 GLsizei width,
3793 GLsizei height)
3794{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003795 if (width == 0 || height == 0)
3796 {
3797 return;
3798 }
3799
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003800 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003801 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003802
Jamie Madillc29968b2016-01-20 11:17:23 -05003803 Offset destOffset(xoffset, yoffset, zoffset);
3804 Rectangle sourceArea(x, y, width, height);
3805
Jamie Madill05b35b22017-10-03 09:01:44 -04003806 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3807 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003808 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3809 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003810}
3811
3812void Context::framebufferTexture2D(GLenum target,
3813 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003814 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003815 GLuint texture,
3816 GLint level)
3817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003819 ASSERT(framebuffer);
3820
3821 if (texture != 0)
3822 {
3823 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003824 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003825 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003826 }
3827 else
3828 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003829 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003830 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003831
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003832 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003833}
3834
3835void Context::framebufferRenderbuffer(GLenum target,
3836 GLenum attachment,
3837 GLenum renderbuffertarget,
3838 GLuint renderbuffer)
3839{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003841 ASSERT(framebuffer);
3842
3843 if (renderbuffer != 0)
3844 {
3845 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003846
Jamie Madillcc129372018-04-12 09:13:18 -04003847 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003848 renderbufferObject);
3849 }
3850 else
3851 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003852 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003853 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003854
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003856}
3857
3858void Context::framebufferTextureLayer(GLenum target,
3859 GLenum attachment,
3860 GLuint texture,
3861 GLint level,
3862 GLint layer)
3863{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003865 ASSERT(framebuffer);
3866
3867 if (texture != 0)
3868 {
3869 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003870 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003871 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003872 }
3873 else
3874 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003875 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003876 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003877
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003878 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003879}
3880
Brandon Jones59770802018-04-02 13:18:42 -07003881void Context::framebufferTextureMultiviewLayered(GLenum target,
3882 GLenum attachment,
3883 GLuint texture,
3884 GLint level,
3885 GLint baseViewIndex,
3886 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003887{
Martin Radev82ef7742017-08-08 17:44:58 +03003888 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3889 ASSERT(framebuffer);
3890
3891 if (texture != 0)
3892 {
3893 Texture *textureObj = getTexture(texture);
3894
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003895 ImageIndex index;
3896 if (textureObj->getType() == TextureType::_2DArray)
3897 {
3898 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3899 }
3900 else
3901 {
3902 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3903 ASSERT(level == 0);
3904 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3905 }
Martin Radev82ef7742017-08-08 17:44:58 +03003906 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3907 numViews, baseViewIndex);
3908 }
3909 else
3910 {
3911 framebuffer->resetAttachment(this, attachment);
3912 }
3913
3914 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003915}
3916
Brandon Jones59770802018-04-02 13:18:42 -07003917void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3918 GLenum attachment,
3919 GLuint texture,
3920 GLint level,
3921 GLsizei numViews,
3922 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003923{
Martin Radev5dae57b2017-07-14 16:15:55 +03003924 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3925 ASSERT(framebuffer);
3926
3927 if (texture != 0)
3928 {
3929 Texture *textureObj = getTexture(texture);
3930
3931 ImageIndex index = ImageIndex::Make2D(level);
3932 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3933 textureObj, numViews, viewportOffsets);
3934 }
3935 else
3936 {
3937 framebuffer->resetAttachment(this, attachment);
3938 }
3939
3940 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003941}
3942
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003943void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3944{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003945 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3946 ASSERT(framebuffer);
3947
3948 if (texture != 0)
3949 {
3950 Texture *textureObj = getTexture(texture);
3951
3952 ImageIndex index = ImageIndex::MakeFromType(
3953 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3954 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3955 }
3956 else
3957 {
3958 framebuffer->resetAttachment(this, attachment);
3959 }
3960
3961 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003962}
3963
Jamie Madillc29968b2016-01-20 11:17:23 -05003964void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3965{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003966 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003967 ASSERT(framebuffer);
3968 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003969 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003970 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003971}
3972
3973void Context::readBuffer(GLenum mode)
3974{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003975 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003976 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003978}
3979
3980void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3981{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003982 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003983 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003984
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003986 ASSERT(framebuffer);
3987
3988 // The specification isn't clear what should be done when the framebuffer isn't complete.
3989 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003990 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003991}
3992
3993void Context::invalidateFramebuffer(GLenum target,
3994 GLsizei numAttachments,
3995 const GLenum *attachments)
3996{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003997 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003998 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003999
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004000 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004001 ASSERT(framebuffer);
4002
Jamie Madill427064d2018-04-13 16:20:34 -04004003 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004004 {
Jamie Madill437fa652016-05-03 15:13:24 -04004005 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004006 }
Jamie Madill437fa652016-05-03 15:13:24 -04004007
Jamie Madill4f6592f2018-11-27 16:37:45 -05004008 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004009}
4010
4011void Context::invalidateSubFramebuffer(GLenum target,
4012 GLsizei numAttachments,
4013 const GLenum *attachments,
4014 GLint x,
4015 GLint y,
4016 GLsizei width,
4017 GLsizei height)
4018{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004019 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004020 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004021
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004022 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004023 ASSERT(framebuffer);
4024
Jamie Madill427064d2018-04-13 16:20:34 -04004025 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004026 {
Jamie Madill437fa652016-05-03 15:13:24 -04004027 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004028 }
Jamie Madill437fa652016-05-03 15:13:24 -04004029
4030 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004031 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004032}
4033
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004034void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004035 GLint level,
4036 GLint internalformat,
4037 GLsizei width,
4038 GLsizei height,
4039 GLint border,
4040 GLenum format,
4041 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004042 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004043{
Jamie Madillbc918e72018-03-08 09:47:21 -05004044 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004045
4046 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004047 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004048 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4049 internalformat, size, format, type,
4050 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004051}
4052
Brandon Jones59770802018-04-02 13:18:42 -07004053void Context::texImage2DRobust(TextureTarget target,
4054 GLint level,
4055 GLint internalformat,
4056 GLsizei width,
4057 GLsizei height,
4058 GLint border,
4059 GLenum format,
4060 GLenum type,
4061 GLsizei bufSize,
4062 const void *pixels)
4063{
4064 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4065}
4066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004067void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004068 GLint level,
4069 GLint internalformat,
4070 GLsizei width,
4071 GLsizei height,
4072 GLsizei depth,
4073 GLint border,
4074 GLenum format,
4075 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004076 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004077{
Jamie Madillbc918e72018-03-08 09:47:21 -05004078 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004079
4080 Extents size(width, height, depth);
4081 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004082 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4083 NonCubeTextureTypeToTarget(target), level, internalformat,
4084 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004085}
4086
Brandon Jones59770802018-04-02 13:18:42 -07004087void Context::texImage3DRobust(TextureType target,
4088 GLint level,
4089 GLint internalformat,
4090 GLsizei width,
4091 GLsizei height,
4092 GLsizei depth,
4093 GLint border,
4094 GLenum format,
4095 GLenum type,
4096 GLsizei bufSize,
4097 const void *pixels)
4098{
4099 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4100}
4101
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004102void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004103 GLint level,
4104 GLint xoffset,
4105 GLint yoffset,
4106 GLsizei width,
4107 GLsizei height,
4108 GLenum format,
4109 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004110 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004111{
4112 // Zero sized uploads are valid but no-ops
4113 if (width == 0 || height == 0)
4114 {
4115 return;
4116 }
4117
Jamie Madillbc918e72018-03-08 09:47:21 -05004118 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004119
4120 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004121 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004122
4123 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4124
Jamie Madill4f6592f2018-11-27 16:37:45 -05004125 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4126 level, area, format, type,
4127 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004128}
4129
Brandon Jones59770802018-04-02 13:18:42 -07004130void Context::texSubImage2DRobust(TextureTarget target,
4131 GLint level,
4132 GLint xoffset,
4133 GLint yoffset,
4134 GLsizei width,
4135 GLsizei height,
4136 GLenum format,
4137 GLenum type,
4138 GLsizei bufSize,
4139 const void *pixels)
4140{
4141 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4142}
4143
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004144void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004145 GLint level,
4146 GLint xoffset,
4147 GLint yoffset,
4148 GLint zoffset,
4149 GLsizei width,
4150 GLsizei height,
4151 GLsizei depth,
4152 GLenum format,
4153 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004154 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004155{
4156 // Zero sized uploads are valid but no-ops
4157 if (width == 0 || height == 0 || depth == 0)
4158 {
4159 return;
4160 }
4161
Jamie Madillbc918e72018-03-08 09:47:21 -05004162 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004163
4164 Box area(xoffset, yoffset, zoffset, width, height, depth);
4165 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004166
4167 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4168
Jamie Madill4f6592f2018-11-27 16:37:45 -05004169 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4170 NonCubeTextureTypeToTarget(target), level, area, format,
4171 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004172}
4173
Brandon Jones59770802018-04-02 13:18:42 -07004174void Context::texSubImage3DRobust(TextureType target,
4175 GLint level,
4176 GLint xoffset,
4177 GLint yoffset,
4178 GLint zoffset,
4179 GLsizei width,
4180 GLsizei height,
4181 GLsizei depth,
4182 GLenum format,
4183 GLenum type,
4184 GLsizei bufSize,
4185 const void *pixels)
4186{
4187 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4188 pixels);
4189}
4190
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004191void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004192 GLint level,
4193 GLenum internalformat,
4194 GLsizei width,
4195 GLsizei height,
4196 GLint border,
4197 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004198 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004199{
Jamie Madillbc918e72018-03-08 09:47:21 -05004200 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004201
4202 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004203 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004204 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4205 internalformat, size, imageSize,
4206 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004207}
4208
Brandon Jones59770802018-04-02 13:18:42 -07004209void Context::compressedTexImage2DRobust(TextureTarget target,
4210 GLint level,
4211 GLenum internalformat,
4212 GLsizei width,
4213 GLsizei height,
4214 GLint border,
4215 GLsizei imageSize,
4216 GLsizei dataSize,
4217 const GLvoid *data)
4218{
4219 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4220}
4221
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004222void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004223 GLint level,
4224 GLenum internalformat,
4225 GLsizei width,
4226 GLsizei height,
4227 GLsizei depth,
4228 GLint border,
4229 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004230 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004231{
Jamie Madillbc918e72018-03-08 09:47:21 -05004232 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004233
4234 Extents size(width, height, depth);
4235 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004236 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004237 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004238 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004239}
4240
Brandon Jones59770802018-04-02 13:18:42 -07004241void Context::compressedTexImage3DRobust(TextureType target,
4242 GLint level,
4243 GLenum internalformat,
4244 GLsizei width,
4245 GLsizei height,
4246 GLsizei depth,
4247 GLint border,
4248 GLsizei imageSize,
4249 GLsizei dataSize,
4250 const GLvoid *data)
4251{
4252 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4253 data);
4254}
4255
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004256void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004257 GLint level,
4258 GLint xoffset,
4259 GLint yoffset,
4260 GLsizei width,
4261 GLsizei height,
4262 GLenum format,
4263 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004264 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004265{
Jamie Madillbc918e72018-03-08 09:47:21 -05004266 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004267
4268 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004269 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004270 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4271 area, format, imageSize,
4272 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004273}
4274
Brandon Jones59770802018-04-02 13:18:42 -07004275void Context::compressedTexSubImage2DRobust(TextureTarget target,
4276 GLint level,
4277 GLint xoffset,
4278 GLint yoffset,
4279 GLsizei width,
4280 GLsizei height,
4281 GLenum format,
4282 GLsizei imageSize,
4283 GLsizei dataSize,
4284 const GLvoid *data)
4285{
4286 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4287 data);
4288}
4289
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004290void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004291 GLint level,
4292 GLint xoffset,
4293 GLint yoffset,
4294 GLint zoffset,
4295 GLsizei width,
4296 GLsizei height,
4297 GLsizei depth,
4298 GLenum format,
4299 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004300 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004301{
4302 // Zero sized uploads are valid but no-ops
4303 if (width == 0 || height == 0)
4304 {
4305 return;
4306 }
4307
Jamie Madillbc918e72018-03-08 09:47:21 -05004308 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004309
4310 Box area(xoffset, yoffset, zoffset, width, height, depth);
4311 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004312 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004313 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004314 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004315}
4316
Brandon Jones59770802018-04-02 13:18:42 -07004317void Context::compressedTexSubImage3DRobust(TextureType target,
4318 GLint level,
4319 GLint xoffset,
4320 GLint yoffset,
4321 GLint zoffset,
4322 GLsizei width,
4323 GLsizei height,
4324 GLsizei depth,
4325 GLenum format,
4326 GLsizei imageSize,
4327 GLsizei dataSize,
4328 const GLvoid *data)
4329{
4330 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4331 imageSize, data);
4332}
4333
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004334void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004335{
4336 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004337 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004338}
4339
Jamie Madill007530e2017-12-28 14:27:04 -05004340void Context::copyTexture(GLuint sourceId,
4341 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004342 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004343 GLuint destId,
4344 GLint destLevel,
4345 GLint internalFormat,
4346 GLenum destType,
4347 GLboolean unpackFlipY,
4348 GLboolean unpackPremultiplyAlpha,
4349 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004350{
Jamie Madillbc918e72018-03-08 09:47:21 -05004351 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004352
4353 gl::Texture *sourceTexture = getTexture(sourceId);
4354 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004355 ANGLE_CONTEXT_TRY(
4356 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4357 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4358 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004359}
4360
Jamie Madill007530e2017-12-28 14:27:04 -05004361void Context::copySubTexture(GLuint sourceId,
4362 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004363 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004364 GLuint destId,
4365 GLint destLevel,
4366 GLint xoffset,
4367 GLint yoffset,
4368 GLint x,
4369 GLint y,
4370 GLsizei width,
4371 GLsizei height,
4372 GLboolean unpackFlipY,
4373 GLboolean unpackPremultiplyAlpha,
4374 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004375{
4376 // Zero sized copies are valid but no-ops
4377 if (width == 0 || height == 0)
4378 {
4379 return;
4380 }
4381
Jamie Madillbc918e72018-03-08 09:47:21 -05004382 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004383
4384 gl::Texture *sourceTexture = getTexture(sourceId);
4385 gl::Texture *destTexture = getTexture(destId);
4386 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004387 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004388 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4389 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4390 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4391 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004392}
4393
4394void Context::copyTexture3D(GLuint sourceId,
4395 GLint sourceLevel,
4396 TextureTarget destTarget,
4397 GLuint destId,
4398 GLint destLevel,
4399 GLint internalFormat,
4400 GLenum destType,
4401 GLboolean unpackFlipY,
4402 GLboolean unpackPremultiplyAlpha,
4403 GLboolean unpackUnmultiplyAlpha)
4404{
4405 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4406
4407 Texture *sourceTexture = getTexture(sourceId);
4408 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004409 ANGLE_CONTEXT_TRY(
4410 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4411 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4412 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004413}
4414
4415void Context::copySubTexture3D(GLuint sourceId,
4416 GLint sourceLevel,
4417 TextureTarget destTarget,
4418 GLuint destId,
4419 GLint destLevel,
4420 GLint xoffset,
4421 GLint yoffset,
4422 GLint zoffset,
4423 GLint x,
4424 GLint y,
4425 GLint z,
4426 GLsizei width,
4427 GLsizei height,
4428 GLsizei depth,
4429 GLboolean unpackFlipY,
4430 GLboolean unpackPremultiplyAlpha,
4431 GLboolean unpackUnmultiplyAlpha)
4432{
4433 // Zero sized copies are valid but no-ops
4434 if (width == 0 || height == 0 || depth == 0)
4435 {
4436 return;
4437 }
4438
4439 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4440
4441 Texture *sourceTexture = getTexture(sourceId);
4442 Texture *destTexture = getTexture(destId);
4443 Offset offset(xoffset, yoffset, zoffset);
4444 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004445 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4446 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4447 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4448 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004449}
4450
Jamie Madill007530e2017-12-28 14:27:04 -05004451void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004452{
Jamie Madillbc918e72018-03-08 09:47:21 -05004453 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004454
4455 gl::Texture *sourceTexture = getTexture(sourceId);
4456 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004457 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004458}
4459
Corentin Wallez336129f2017-10-17 15:55:40 -04004460void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004461{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004462 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004463 ASSERT(buffer);
4464
Geoff Lang496c02d2016-10-20 11:38:11 -07004465 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004466}
4467
Brandon Jones59770802018-04-02 13:18:42 -07004468void Context::getBufferPointervRobust(BufferBinding target,
4469 GLenum pname,
4470 GLsizei bufSize,
4471 GLsizei *length,
4472 void **params)
4473{
4474 getBufferPointerv(target, pname, params);
4475}
4476
Corentin Wallez336129f2017-10-17 15:55:40 -04004477void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004478{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004479 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004480 ASSERT(buffer);
4481
Jamie Madill4f6592f2018-11-27 16:37:45 -05004482 if (buffer->map(this, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004483 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004484 return nullptr;
4485 }
4486
4487 return buffer->getMapPointer();
4488}
4489
Corentin Wallez336129f2017-10-17 15:55:40 -04004490GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004493 ASSERT(buffer);
4494
4495 GLboolean result;
Jamie Madill4f6592f2018-11-27 16:37:45 -05004496 if (buffer->unmap(this, &result) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004497 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004498 return GL_FALSE;
4499 }
4500
4501 return result;
4502}
4503
Corentin Wallez336129f2017-10-17 15:55:40 -04004504void *Context::mapBufferRange(BufferBinding target,
4505 GLintptr offset,
4506 GLsizeiptr length,
4507 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004510 ASSERT(buffer);
4511
Jamie Madill4f6592f2018-11-27 16:37:45 -05004512 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004513 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004514 return nullptr;
4515 }
4516
4517 return buffer->getMapPointer();
4518}
4519
Corentin Wallez336129f2017-10-17 15:55:40 -04004520void Context::flushMappedBufferRange(BufferBinding /*target*/,
4521 GLintptr /*offset*/,
4522 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004523{
4524 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4525}
4526
Jamie Madill526392d2018-11-16 09:35:14 -05004527angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004528{
Geoff Langa8cb2872018-03-09 16:09:40 -05004529 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004530}
4531
Jamie Madill526392d2018-11-16 09:35:14 -05004532angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004533{
Geoff Langa8cb2872018-03-09 16:09:40 -05004534 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004535}
4536
Jamie Madill526392d2018-11-16 09:35:14 -05004537angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004538{
Geoff Langa8cb2872018-03-09 16:09:40 -05004539 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004540}
4541
Jamie Madill526392d2018-11-16 09:35:14 -05004542angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004543{
4544 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4545
4546 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4547 ANGLE_TRY(syncDirtyBits());
4548
Jamie Madill526392d2018-11-16 09:35:14 -05004549 return angle::Result::Continue();
Geoff Lang9bf86f02018-07-26 11:46:34 -04004550}
4551
Jiajia Qin5451d532017-11-16 17:16:34 +08004552void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4553{
4554 UNIMPLEMENTED();
4555}
4556
Jamie Madillc20ab272016-06-09 07:20:46 -07004557void Context::activeTexture(GLenum texture)
4558{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560}
4561
Jamie Madill876429b2017-04-20 15:46:24 -04004562void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004563{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004564 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004565}
4566
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004567void Context::blendEquation(GLenum mode)
4568{
4569 mGLState.setBlendEquation(mode, mode);
4570}
4571
Jamie Madillc20ab272016-06-09 07:20:46 -07004572void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004577void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4578{
4579 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4580}
4581
Jamie Madillc20ab272016-06-09 07:20:46 -07004582void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
Jamie Madill876429b2017-04-20 15:46:24 -04004587void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004588{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004589 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004590}
4591
Jamie Madill876429b2017-04-20 15:46:24 -04004592void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004593{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004594 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004595}
4596
4597void Context::clearStencil(GLint s)
4598{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004599 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
4602void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4603{
Geoff Lang92019432017-11-20 13:09:34 -05004604 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4605 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004606}
4607
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004608void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
4613void Context::depthFunc(GLenum func)
4614{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004615 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616}
4617
4618void Context::depthMask(GLboolean flag)
4619{
Geoff Lang92019432017-11-20 13:09:34 -05004620 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
Jamie Madill876429b2017-04-20 15:46:24 -04004623void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004624{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004625 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004626}
4627
4628void Context::disable(GLenum cap)
4629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004631 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004632}
4633
4634void Context::disableVertexAttribArray(GLuint index)
4635{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004636 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004637 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638}
4639
4640void Context::enable(GLenum cap)
4641{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004642 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004643 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004644}
4645
4646void Context::enableVertexAttribArray(GLuint index)
4647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004648 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004649 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::frontFace(GLenum mode)
4653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004654 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004655}
4656
4657void Context::hint(GLenum target, GLenum mode)
4658{
4659 switch (target)
4660 {
4661 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004662 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663 break;
4664
4665 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004666 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667 break;
4668
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004669 case GL_PERSPECTIVE_CORRECTION_HINT:
4670 case GL_POINT_SMOOTH_HINT:
4671 case GL_LINE_SMOOTH_HINT:
4672 case GL_FOG_HINT:
4673 mGLState.gles1().setHint(target, mode);
4674 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004675 default:
4676 UNREACHABLE();
4677 return;
4678 }
4679}
4680
4681void Context::lineWidth(GLfloat width)
4682{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004683 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004684}
4685
4686void Context::pixelStorei(GLenum pname, GLint param)
4687{
4688 switch (pname)
4689 {
4690 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004691 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004692 break;
4693
4694 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004695 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004696 break;
4697
4698 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004699 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004700 break;
4701
4702 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004703 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004704 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004705 break;
4706
4707 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004708 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004709 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710 break;
4711
4712 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004713 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004715 break;
4716
4717 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004718 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004720 break;
4721
4722 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004723 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004724 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004725 break;
4726
4727 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004728 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004729 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004730 break;
4731
4732 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004733 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004735 break;
4736
4737 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004738 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004739 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004740 break;
4741
4742 default:
4743 UNREACHABLE();
4744 return;
4745 }
4746}
4747
4748void Context::polygonOffset(GLfloat factor, GLfloat units)
4749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004750 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004751}
4752
Jamie Madill876429b2017-04-20 15:46:24 -04004753void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004754{
Geoff Lang92019432017-11-20 13:09:34 -05004755 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004756}
4757
Jiawei Shaodb342272017-09-27 10:21:45 +08004758void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4759{
4760 mGLState.setSampleMaskParams(maskNumber, mask);
4761}
4762
Jamie Madillc20ab272016-06-09 07:20:46 -07004763void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004765 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004766}
4767
4768void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4769{
4770 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4771 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004772 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004773 }
4774
4775 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4776 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004777 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004778 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004779
4780 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004781}
4782
4783void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4784{
4785 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4786 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004787 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004788 }
4789
4790 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4791 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004792 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004793 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004794
4795 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004796}
4797
4798void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4799{
4800 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4801 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004802 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803 }
4804
4805 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4806 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004807 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004808 }
4809}
4810
4811void Context::vertexAttrib1f(GLuint index, GLfloat x)
4812{
4813 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004815 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004816}
4817
4818void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4819{
4820 GLfloat vals[4] = {values[0], 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::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4826{
4827 GLfloat vals[4] = {x, y, 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::vertexAttrib2fv(GLuint index, const GLfloat *values)
4833{
4834 GLfloat vals[4] = {values[0], values[1], 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::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4840{
4841 GLfloat vals[4] = {x, y, z, 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::vertexAttrib3fv(GLuint index, const GLfloat *values)
4847{
4848 GLfloat vals[4] = {values[0], values[1], values[2], 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::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4854{
4855 GLfloat vals[4] = {x, y, z, w};
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::vertexAttrib4fv(GLuint index, const GLfloat *values)
4861{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004862 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004863 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004864}
4865
4866void Context::vertexAttribPointer(GLuint index,
4867 GLint size,
4868 GLenum type,
4869 GLboolean normalized,
4870 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004871 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004872{
Corentin Wallez336129f2017-10-17 15:55:40 -04004873 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004874 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004875 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004876}
4877
Shao80957d92017-02-20 21:25:59 +08004878void Context::vertexAttribFormat(GLuint attribIndex,
4879 GLint size,
4880 GLenum type,
4881 GLboolean normalized,
4882 GLuint relativeOffset)
4883{
Geoff Lang92019432017-11-20 13:09:34 -05004884 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004885 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004886 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004887}
4888
4889void Context::vertexAttribIFormat(GLuint attribIndex,
4890 GLint size,
4891 GLenum type,
4892 GLuint relativeOffset)
4893{
4894 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004895 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004896}
4897
4898void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4899{
Shaodde78e82017-05-22 14:13:27 +08004900 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004901 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004902}
4903
Jiajia Qin5451d532017-11-16 17:16:34 +08004904void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004905{
4906 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004907 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004908}
4909
Jamie Madillc20ab272016-06-09 07:20:46 -07004910void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4911{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004912 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004913}
4914
4915void Context::vertexAttribIPointer(GLuint index,
4916 GLint size,
4917 GLenum type,
4918 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004919 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004920{
Corentin Wallez336129f2017-10-17 15:55:40 -04004921 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4922 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004923 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004924}
4925
4926void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4927{
4928 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004929 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004930 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004931}
4932
4933void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4934{
4935 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004936 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004937 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004938}
4939
4940void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4941{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004942 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004943 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004944}
4945
4946void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4947{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004948 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004949 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004950}
4951
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004952void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4953{
4954 const VertexAttribCurrentValueData &currentValues =
4955 getGLState().getVertexAttribCurrentValue(index);
4956 const VertexArray *vao = getGLState().getVertexArray();
4957 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4958 currentValues, pname, params);
4959}
4960
Brandon Jones59770802018-04-02 13:18:42 -07004961void Context::getVertexAttribivRobust(GLuint index,
4962 GLenum pname,
4963 GLsizei bufSize,
4964 GLsizei *length,
4965 GLint *params)
4966{
4967 getVertexAttribiv(index, pname, params);
4968}
4969
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004970void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4971{
4972 const VertexAttribCurrentValueData &currentValues =
4973 getGLState().getVertexAttribCurrentValue(index);
4974 const VertexArray *vao = getGLState().getVertexArray();
4975 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4976 currentValues, pname, params);
4977}
4978
Brandon Jones59770802018-04-02 13:18:42 -07004979void Context::getVertexAttribfvRobust(GLuint index,
4980 GLenum pname,
4981 GLsizei bufSize,
4982 GLsizei *length,
4983 GLfloat *params)
4984{
4985 getVertexAttribfv(index, pname, params);
4986}
4987
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004988void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4989{
4990 const VertexAttribCurrentValueData &currentValues =
4991 getGLState().getVertexAttribCurrentValue(index);
4992 const VertexArray *vao = getGLState().getVertexArray();
4993 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4994 currentValues, pname, params);
4995}
4996
Brandon Jones59770802018-04-02 13:18:42 -07004997void Context::getVertexAttribIivRobust(GLuint index,
4998 GLenum pname,
4999 GLsizei bufSize,
5000 GLsizei *length,
5001 GLint *params)
5002{
5003 getVertexAttribIiv(index, pname, params);
5004}
5005
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005006void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5007{
5008 const VertexAttribCurrentValueData &currentValues =
5009 getGLState().getVertexAttribCurrentValue(index);
5010 const VertexArray *vao = getGLState().getVertexArray();
5011 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5012 currentValues, pname, params);
5013}
5014
Brandon Jones59770802018-04-02 13:18:42 -07005015void Context::getVertexAttribIuivRobust(GLuint index,
5016 GLenum pname,
5017 GLsizei bufSize,
5018 GLsizei *length,
5019 GLuint *params)
5020{
5021 getVertexAttribIuiv(index, pname, params);
5022}
5023
Jamie Madill876429b2017-04-20 15:46:24 -04005024void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005025{
5026 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5027 QueryVertexAttribPointerv(attrib, pname, pointer);
5028}
5029
Brandon Jones59770802018-04-02 13:18:42 -07005030void Context::getVertexAttribPointervRobust(GLuint index,
5031 GLenum pname,
5032 GLsizei bufSize,
5033 GLsizei *length,
5034 void **pointer)
5035{
5036 getVertexAttribPointerv(index, pname, pointer);
5037}
5038
Jamie Madillc20ab272016-06-09 07:20:46 -07005039void Context::debugMessageControl(GLenum source,
5040 GLenum type,
5041 GLenum severity,
5042 GLsizei count,
5043 const GLuint *ids,
5044 GLboolean enabled)
5045{
5046 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005047 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005048 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005049}
5050
5051void Context::debugMessageInsert(GLenum source,
5052 GLenum type,
5053 GLuint id,
5054 GLenum severity,
5055 GLsizei length,
5056 const GLchar *buf)
5057{
5058 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005059 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005060}
5061
5062void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5063{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005064 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005065}
5066
5067GLuint Context::getDebugMessageLog(GLuint count,
5068 GLsizei bufSize,
5069 GLenum *sources,
5070 GLenum *types,
5071 GLuint *ids,
5072 GLenum *severities,
5073 GLsizei *lengths,
5074 GLchar *messageLog)
5075{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005076 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5077 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005078}
5079
5080void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5081{
5082 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005083 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005084 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005085}
5086
5087void Context::popDebugGroup()
5088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005089 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005090 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005091}
5092
Corentin Wallez336129f2017-10-17 15:55:40 -04005093void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005094{
5095 Buffer *buffer = mGLState.getTargetBuffer(target);
5096 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005097 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005098}
5099
Corentin Wallez336129f2017-10-17 15:55:40 -04005100void Context::bufferSubData(BufferBinding target,
5101 GLintptr offset,
5102 GLsizeiptr size,
5103 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005104{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005105 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005106 {
5107 return;
5108 }
5109
5110 Buffer *buffer = mGLState.getTargetBuffer(target);
5111 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005112 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005113}
5114
Jamie Madillef300b12016-10-07 15:12:09 -04005115void Context::attachShader(GLuint program, GLuint shader)
5116{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005117 Program *programObject = mState.mShaderPrograms->getProgram(program);
5118 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005119 ASSERT(programObject && shaderObject);
5120 programObject->attachShader(shaderObject);
5121}
5122
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005123const Workarounds &Context::getWorkarounds() const
5124{
5125 return mWorkarounds;
5126}
5127
Corentin Wallez336129f2017-10-17 15:55:40 -04005128void Context::copyBufferSubData(BufferBinding readTarget,
5129 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005130 GLintptr readOffset,
5131 GLintptr writeOffset,
5132 GLsizeiptr size)
5133{
5134 // if size is zero, the copy is a successful no-op
5135 if (size == 0)
5136 {
5137 return;
5138 }
5139
5140 // TODO(jmadill): cache these.
5141 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5142 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5143
Jamie Madill4f6592f2018-11-27 16:37:45 -05005144 ANGLE_CONTEXT_TRY(
5145 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005146}
5147
Jamie Madill01a80ee2016-11-07 12:06:18 -05005148void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5149{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005150 // Ideally we could share the program query with the validation layer if possible.
5151 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005152 ASSERT(programObject);
5153 programObject->bindAttributeLocation(index, name);
5154}
5155
Corentin Wallez336129f2017-10-17 15:55:40 -04005156void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005157{
Corentin Wallez336129f2017-10-17 15:55:40 -04005158 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5159 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005160 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005161}
5162
Corentin Wallez336129f2017-10-17 15:55:40 -04005163void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005164{
5165 bindBufferRange(target, index, buffer, 0, 0);
5166}
5167
Corentin Wallez336129f2017-10-17 15:55:40 -04005168void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005169 GLuint index,
5170 GLuint buffer,
5171 GLintptr offset,
5172 GLsizeiptr size)
5173{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005174 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5175 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5176 if (target == BufferBinding::Uniform)
5177 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005178 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005179 mStateCache.onUniformBufferStateChange(this);
5180 }
5181 else
5182 {
5183 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005184 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005185}
5186
Jamie Madill01a80ee2016-11-07 12:06:18 -05005187void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5188{
5189 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5190 {
5191 bindReadFramebuffer(framebuffer);
5192 }
5193
5194 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5195 {
5196 bindDrawFramebuffer(framebuffer);
5197 }
5198}
5199
5200void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5201{
5202 ASSERT(target == GL_RENDERBUFFER);
5203 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005204 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005205 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005206}
5207
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005208void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005209 GLsizei samples,
5210 GLenum internalformat,
5211 GLsizei width,
5212 GLsizei height,
5213 GLboolean fixedsamplelocations)
5214{
5215 Extents size(width, height, 1);
5216 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005217 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5218 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005219}
5220
Olli Etuaho89664842018-08-24 14:45:36 +03005221void Context::texStorage3DMultisample(TextureType target,
5222 GLsizei samples,
5223 GLenum internalformat,
5224 GLsizei width,
5225 GLsizei height,
5226 GLsizei depth,
5227 GLboolean fixedsamplelocations)
5228{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005229 Extents size(width, height, depth);
5230 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005231 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5232 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005233}
5234
JiangYizhoubddc46b2016-12-09 09:50:51 +08005235void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5236{
JiangYizhou5b03f472017-01-09 10:22:53 +08005237 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5238 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005239 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005240 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005241
5242 switch (pname)
5243 {
5244 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005245 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005246 break;
5247 default:
5248 UNREACHABLE();
5249 }
5250}
5251
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005252void Context::getMultisamplefvRobust(GLenum pname,
5253 GLuint index,
5254 GLsizei bufSize,
5255 GLsizei *length,
5256 GLfloat *val)
5257{
5258 UNIMPLEMENTED();
5259}
5260
Jamie Madille8fb6402017-02-14 17:56:40 -05005261void Context::renderbufferStorage(GLenum target,
5262 GLenum internalformat,
5263 GLsizei width,
5264 GLsizei height)
5265{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005266 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5267 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5268
Jamie Madille8fb6402017-02-14 17:56:40 -05005269 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005270 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005271}
5272
5273void Context::renderbufferStorageMultisample(GLenum target,
5274 GLsizei samples,
5275 GLenum internalformat,
5276 GLsizei width,
5277 GLsizei height)
5278{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005279 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5280 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005281
5282 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005283 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005284 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005285}
5286
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005287void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5288{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005289 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005290 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005291}
5292
JiangYizhoue18e6392017-02-20 10:32:23 +08005293void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5294{
5295 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5296 QueryFramebufferParameteriv(framebuffer, pname, params);
5297}
5298
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005299void Context::getFramebufferParameterivRobust(GLenum target,
5300 GLenum pname,
5301 GLsizei bufSize,
5302 GLsizei *length,
5303 GLint *params)
5304{
5305 UNIMPLEMENTED();
5306}
5307
Jiajia Qin5451d532017-11-16 17:16:34 +08005308void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005309{
5310 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005311 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005312}
5313
Jamie Madilldec86232018-07-11 09:01:18 -04005314bool Context::getScratchBuffer(size_t requstedSizeBytes,
5315 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005316{
Jamie Madilldec86232018-07-11 09:01:18 -04005317 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005318}
5319
Jamie Madilldec86232018-07-11 09:01:18 -04005320bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5321 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005322{
Jamie Madilldec86232018-07-11 09:01:18 -04005323 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005324}
5325
Jamie Madill526392d2018-11-16 09:35:14 -05005326angle::Result Context::prepareForDispatch()
Xinghua Cao10a4d432017-11-28 14:46:26 +08005327{
Jamie Madill0cc11c62018-10-12 18:07:18 -04005328 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005329
5330 if (isRobustResourceInitEnabled())
5331 {
5332 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5333 }
5334
Jamie Madill0cc11c62018-10-12 18:07:18 -04005335 return syncDirtyBits(mComputeDirtyBits);
Xinghua Cao10a4d432017-11-28 14:46:26 +08005336}
5337
Xinghua Cao2b396592017-03-29 15:36:04 +08005338void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5339{
5340 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5341 {
5342 return;
5343 }
5344
Xinghua Cao10a4d432017-11-28 14:46:26 +08005345 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005346 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005347}
5348
Jiajia Qin5451d532017-11-16 17:16:34 +08005349void Context::dispatchComputeIndirect(GLintptr indirect)
5350{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005351 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005352 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005353}
5354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005355void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005356 GLsizei levels,
5357 GLenum internalFormat,
5358 GLsizei width,
5359 GLsizei height)
5360{
5361 Extents size(width, height, 1);
5362 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005363 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005364}
5365
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005366void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005367 GLsizei levels,
5368 GLenum internalFormat,
5369 GLsizei width,
5370 GLsizei height,
5371 GLsizei depth)
5372{
5373 Extents size(width, height, depth);
5374 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005375 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005376}
5377
Jiajia Qin5451d532017-11-16 17:16:34 +08005378void Context::memoryBarrier(GLbitfield barriers)
5379{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005380 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005381}
5382
5383void Context::memoryBarrierByRegion(GLbitfield barriers)
5384{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005385 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005386}
5387
Austin Eng1bf18ce2018-10-19 15:34:02 -07005388void Context::multiDrawArrays(PrimitiveMode mode,
5389 const GLint *firsts,
5390 const GLsizei *counts,
5391 GLsizei drawcount)
5392{
5393 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5394 Program *programObject = mGLState.getLinkedProgram(this);
5395 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5396 if (hasDrawID)
5397 {
5398 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5399 {
5400 if (noopDraw(mode, counts[drawID]))
5401 {
5402 continue;
5403 }
5404 programObject->setDrawIDUniform(drawID);
5405 ANGLE_CONTEXT_TRY(
5406 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5407 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5408 counts[drawID], 1);
5409 }
5410 }
5411 else
5412 {
5413 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5414 {
5415 if (noopDraw(mode, counts[drawID]))
5416 {
5417 continue;
5418 }
5419 ANGLE_CONTEXT_TRY(
5420 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5421 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5422 counts[drawID], 1);
5423 }
5424 }
5425}
5426
5427void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5428 const GLint *firsts,
5429 const GLsizei *counts,
5430 const GLsizei *instanceCounts,
5431 GLsizei drawcount)
5432{
5433 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5434 Program *programObject = mGLState.getLinkedProgram(this);
5435 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5436 if (hasDrawID)
5437 {
5438 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5439 {
5440 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5441 {
5442 continue;
5443 }
5444 programObject->setDrawIDUniform(drawID);
5445 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5446 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5447 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5448 counts[drawID], instanceCounts[drawID]);
5449 }
5450 }
5451 else
5452 {
5453 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5454 {
5455 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5456 {
5457 continue;
5458 }
5459 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5460 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5461 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5462 counts[drawID], instanceCounts[drawID]);
5463 }
5464 }
5465}
5466
5467void Context::multiDrawElements(PrimitiveMode mode,
5468 const GLsizei *counts,
5469 GLenum type,
5470 const GLsizei *offsets,
5471 GLsizei drawcount)
5472{
5473 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5474 Program *programObject = mGLState.getLinkedProgram(this);
5475 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5476 if (hasDrawID)
5477 {
5478 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5479 {
5480 if (noopDraw(mode, counts[drawID]))
5481 {
5482 continue;
5483 }
5484 programObject->setDrawIDUniform(drawID);
5485 const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID]));
5486 ANGLE_CONTEXT_TRY(
5487 mImplementation->drawElements(this, mode, counts[drawID], type, indices));
5488 }
5489 }
5490 else
5491 {
5492 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5493 {
5494 if (noopDraw(mode, counts[drawID]))
5495 {
5496 continue;
5497 }
5498 const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID]));
5499 ANGLE_CONTEXT_TRY(
5500 mImplementation->drawElements(this, mode, counts[drawID], type, indices));
5501 }
5502 }
5503}
5504
5505void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5506 const GLsizei *counts,
5507 GLenum type,
5508 const GLsizei *offsets,
5509 const GLsizei *instanceCounts,
5510 GLsizei drawcount)
5511{
5512 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5513 Program *programObject = mGLState.getLinkedProgram(this);
5514 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5515 if (hasDrawID)
5516 {
5517 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5518 {
5519 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5520 {
5521 continue;
5522 }
5523 programObject->setDrawIDUniform(drawID);
5524 const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID]));
5525 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
5526 this, mode, counts[drawID], type, indices, instanceCounts[drawID]));
5527 }
5528 }
5529 else
5530 {
5531 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5532 {
5533 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5534 {
5535 continue;
5536 }
5537 const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID]));
5538 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
5539 this, mode, counts[drawID], type, indices, instanceCounts[drawID]));
5540 }
5541 }
5542}
5543
Jamie Madillc1d770e2017-04-13 17:31:24 -04005544GLenum Context::checkFramebufferStatus(GLenum target)
5545{
5546 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5547 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005548 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005549}
5550
5551void Context::compileShader(GLuint shader)
5552{
5553 Shader *shaderObject = GetValidShader(this, shader);
5554 if (!shaderObject)
5555 {
5556 return;
5557 }
5558 shaderObject->compile(this);
5559}
5560
5561void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5562{
5563 for (int i = 0; i < n; i++)
5564 {
5565 deleteBuffer(buffers[i]);
5566 }
5567}
5568
5569void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5570{
5571 for (int i = 0; i < n; i++)
5572 {
5573 if (framebuffers[i] != 0)
5574 {
5575 deleteFramebuffer(framebuffers[i]);
5576 }
5577 }
5578}
5579
5580void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5581{
5582 for (int i = 0; i < n; i++)
5583 {
5584 deleteRenderbuffer(renderbuffers[i]);
5585 }
5586}
5587
5588void Context::deleteTextures(GLsizei n, const GLuint *textures)
5589{
5590 for (int i = 0; i < n; i++)
5591 {
5592 if (textures[i] != 0)
5593 {
5594 deleteTexture(textures[i]);
5595 }
5596 }
5597}
5598
5599void Context::detachShader(GLuint program, GLuint shader)
5600{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005601 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005602 ASSERT(programObject);
5603
5604 Shader *shaderObject = getShader(shader);
5605 ASSERT(shaderObject);
5606
5607 programObject->detachShader(this, shaderObject);
5608}
5609
5610void Context::genBuffers(GLsizei n, GLuint *buffers)
5611{
5612 for (int i = 0; i < n; i++)
5613 {
5614 buffers[i] = createBuffer();
5615 }
5616}
5617
5618void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5619{
5620 for (int i = 0; i < n; i++)
5621 {
5622 framebuffers[i] = createFramebuffer();
5623 }
5624}
5625
5626void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5627{
5628 for (int i = 0; i < n; i++)
5629 {
5630 renderbuffers[i] = createRenderbuffer();
5631 }
5632}
5633
5634void Context::genTextures(GLsizei n, GLuint *textures)
5635{
5636 for (int i = 0; i < n; i++)
5637 {
5638 textures[i] = createTexture();
5639 }
5640}
5641
5642void Context::getActiveAttrib(GLuint program,
5643 GLuint index,
5644 GLsizei bufsize,
5645 GLsizei *length,
5646 GLint *size,
5647 GLenum *type,
5648 GLchar *name)
5649{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005650 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005651 ASSERT(programObject);
5652 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5653}
5654
5655void Context::getActiveUniform(GLuint program,
5656 GLuint index,
5657 GLsizei bufsize,
5658 GLsizei *length,
5659 GLint *size,
5660 GLenum *type,
5661 GLchar *name)
5662{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005663 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664 ASSERT(programObject);
5665 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5666}
5667
5668void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5669{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005670 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005671 ASSERT(programObject);
5672 programObject->getAttachedShaders(maxcount, count, shaders);
5673}
5674
5675GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5676{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005677 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005678 ASSERT(programObject);
5679 return programObject->getAttributeLocation(name);
5680}
5681
5682void Context::getBooleanv(GLenum pname, GLboolean *params)
5683{
5684 GLenum nativeType;
5685 unsigned int numParams = 0;
5686 getQueryParameterInfo(pname, &nativeType, &numParams);
5687
5688 if (nativeType == GL_BOOL)
5689 {
5690 getBooleanvImpl(pname, params);
5691 }
5692 else
5693 {
5694 CastStateValues(this, nativeType, pname, numParams, params);
5695 }
5696}
5697
Brandon Jones59770802018-04-02 13:18:42 -07005698void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5699{
5700 getBooleanv(pname, params);
5701}
5702
Jamie Madillc1d770e2017-04-13 17:31:24 -04005703void Context::getFloatv(GLenum pname, GLfloat *params)
5704{
5705 GLenum nativeType;
5706 unsigned int numParams = 0;
5707 getQueryParameterInfo(pname, &nativeType, &numParams);
5708
5709 if (nativeType == GL_FLOAT)
5710 {
5711 getFloatvImpl(pname, params);
5712 }
5713 else
5714 {
5715 CastStateValues(this, nativeType, pname, numParams, params);
5716 }
5717}
5718
Brandon Jones59770802018-04-02 13:18:42 -07005719void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5720{
5721 getFloatv(pname, params);
5722}
5723
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724void Context::getIntegerv(GLenum pname, GLint *params)
5725{
5726 GLenum nativeType;
5727 unsigned int numParams = 0;
5728 getQueryParameterInfo(pname, &nativeType, &numParams);
5729
5730 if (nativeType == GL_INT)
5731 {
5732 getIntegervImpl(pname, params);
5733 }
5734 else
5735 {
5736 CastStateValues(this, nativeType, pname, numParams, params);
5737 }
5738}
5739
Brandon Jones59770802018-04-02 13:18:42 -07005740void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5741{
5742 getIntegerv(pname, data);
5743}
5744
Jamie Madillc1d770e2017-04-13 17:31:24 -04005745void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5746{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005747 // Don't resolve link if checking the link completion status.
5748 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5749 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005751 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005752}
5753
Brandon Jones59770802018-04-02 13:18:42 -07005754void Context::getProgramivRobust(GLuint program,
5755 GLenum pname,
5756 GLsizei bufSize,
5757 GLsizei *length,
5758 GLint *params)
5759{
5760 getProgramiv(program, pname, params);
5761}
5762
Jiajia Qin5451d532017-11-16 17:16:34 +08005763void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5764{
5765 UNIMPLEMENTED();
5766}
5767
Jamie Madillbe849e42017-05-02 15:49:00 -04005768void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005769{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005770 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005771 ASSERT(programObject);
5772 programObject->getInfoLog(bufsize, length, infolog);
5773}
5774
Jiajia Qin5451d532017-11-16 17:16:34 +08005775void Context::getProgramPipelineInfoLog(GLuint pipeline,
5776 GLsizei bufSize,
5777 GLsizei *length,
5778 GLchar *infoLog)
5779{
5780 UNIMPLEMENTED();
5781}
5782
Jamie Madillc1d770e2017-04-13 17:31:24 -04005783void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5784{
5785 Shader *shaderObject = getShader(shader);
5786 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005787 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005788}
5789
Brandon Jones59770802018-04-02 13:18:42 -07005790void Context::getShaderivRobust(GLuint shader,
5791 GLenum pname,
5792 GLsizei bufSize,
5793 GLsizei *length,
5794 GLint *params)
5795{
5796 getShaderiv(shader, pname, params);
5797}
5798
Jamie Madillc1d770e2017-04-13 17:31:24 -04005799void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5800{
5801 Shader *shaderObject = getShader(shader);
5802 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005803 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005804}
5805
5806void Context::getShaderPrecisionFormat(GLenum shadertype,
5807 GLenum precisiontype,
5808 GLint *range,
5809 GLint *precision)
5810{
5811 // TODO(jmadill): Compute shaders.
5812
5813 switch (shadertype)
5814 {
5815 case GL_VERTEX_SHADER:
5816 switch (precisiontype)
5817 {
5818 case GL_LOW_FLOAT:
5819 mCaps.vertexLowpFloat.get(range, precision);
5820 break;
5821 case GL_MEDIUM_FLOAT:
5822 mCaps.vertexMediumpFloat.get(range, precision);
5823 break;
5824 case GL_HIGH_FLOAT:
5825 mCaps.vertexHighpFloat.get(range, precision);
5826 break;
5827
5828 case GL_LOW_INT:
5829 mCaps.vertexLowpInt.get(range, precision);
5830 break;
5831 case GL_MEDIUM_INT:
5832 mCaps.vertexMediumpInt.get(range, precision);
5833 break;
5834 case GL_HIGH_INT:
5835 mCaps.vertexHighpInt.get(range, precision);
5836 break;
5837
5838 default:
5839 UNREACHABLE();
5840 return;
5841 }
5842 break;
5843
5844 case GL_FRAGMENT_SHADER:
5845 switch (precisiontype)
5846 {
5847 case GL_LOW_FLOAT:
5848 mCaps.fragmentLowpFloat.get(range, precision);
5849 break;
5850 case GL_MEDIUM_FLOAT:
5851 mCaps.fragmentMediumpFloat.get(range, precision);
5852 break;
5853 case GL_HIGH_FLOAT:
5854 mCaps.fragmentHighpFloat.get(range, precision);
5855 break;
5856
5857 case GL_LOW_INT:
5858 mCaps.fragmentLowpInt.get(range, precision);
5859 break;
5860 case GL_MEDIUM_INT:
5861 mCaps.fragmentMediumpInt.get(range, precision);
5862 break;
5863 case GL_HIGH_INT:
5864 mCaps.fragmentHighpInt.get(range, precision);
5865 break;
5866
5867 default:
5868 UNREACHABLE();
5869 return;
5870 }
5871 break;
5872
5873 default:
5874 UNREACHABLE();
5875 return;
5876 }
5877}
5878
5879void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5880{
5881 Shader *shaderObject = getShader(shader);
5882 ASSERT(shaderObject);
5883 shaderObject->getSource(bufsize, length, source);
5884}
5885
5886void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5887{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005888 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005889 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005890 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005891}
5892
Brandon Jones59770802018-04-02 13:18:42 -07005893void Context::getUniformfvRobust(GLuint program,
5894 GLint location,
5895 GLsizei bufSize,
5896 GLsizei *length,
5897 GLfloat *params)
5898{
5899 getUniformfv(program, location, params);
5900}
5901
Jamie Madillc1d770e2017-04-13 17:31:24 -04005902void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5903{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005904 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005905 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005906 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005907}
5908
Brandon Jones59770802018-04-02 13:18:42 -07005909void Context::getUniformivRobust(GLuint program,
5910 GLint location,
5911 GLsizei bufSize,
5912 GLsizei *length,
5913 GLint *params)
5914{
5915 getUniformiv(program, location, params);
5916}
5917
Jamie Madillc1d770e2017-04-13 17:31:24 -04005918GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5919{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005920 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005921 ASSERT(programObject);
5922 return programObject->getUniformLocation(name);
5923}
5924
5925GLboolean Context::isBuffer(GLuint buffer)
5926{
5927 if (buffer == 0)
5928 {
5929 return GL_FALSE;
5930 }
5931
5932 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5933}
5934
5935GLboolean Context::isEnabled(GLenum cap)
5936{
5937 return mGLState.getEnableFeature(cap);
5938}
5939
5940GLboolean Context::isFramebuffer(GLuint framebuffer)
5941{
5942 if (framebuffer == 0)
5943 {
5944 return GL_FALSE;
5945 }
5946
5947 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5948}
5949
5950GLboolean Context::isProgram(GLuint program)
5951{
5952 if (program == 0)
5953 {
5954 return GL_FALSE;
5955 }
5956
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005957 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005958}
5959
5960GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5961{
5962 if (renderbuffer == 0)
5963 {
5964 return GL_FALSE;
5965 }
5966
5967 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5968}
5969
5970GLboolean Context::isShader(GLuint shader)
5971{
5972 if (shader == 0)
5973 {
5974 return GL_FALSE;
5975 }
5976
5977 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5978}
5979
5980GLboolean Context::isTexture(GLuint texture)
5981{
5982 if (texture == 0)
5983 {
5984 return GL_FALSE;
5985 }
5986
5987 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5988}
5989
5990void Context::linkProgram(GLuint program)
5991{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005992 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005993 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005994 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005995
5996 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5997 // don't need to worry that:
5998 // 1. Draw calls after link use the new executable code or the old one depending on the link
5999 // result.
6000 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
6001 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
6002 // ProgramD3D.
6003 if (programObject->isInUse())
6004 {
Jamie Madill785e8a02018-10-04 17:42:00 -04006005 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006006 if (programObject->isLinked())
6007 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006008 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006009 }
jchen107ae70d82018-07-06 13:47:01 +08006010 mStateCache.onProgramExecutableChange(this);
6011 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006012}
6013
6014void Context::releaseShaderCompiler()
6015{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006016 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006017}
6018
6019void Context::shaderBinary(GLsizei n,
6020 const GLuint *shaders,
6021 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006022 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006023 GLsizei length)
6024{
6025 // No binary shader formats are supported.
6026 UNIMPLEMENTED();
6027}
6028
Olli Etuaho0ca09752018-09-24 11:00:50 +03006029void Context::bindFragDataLocationIndexed(GLuint program,
6030 GLuint colorNumber,
6031 GLuint index,
6032 const char *name)
6033{
6034 Program *programObject = getProgramNoResolveLink(program);
6035 programObject->bindFragmentOutputLocation(colorNumber, name);
6036 programObject->bindFragmentOutputIndex(index, name);
6037}
6038
6039void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6040{
6041 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6042}
6043
6044int Context::getFragDataIndex(GLuint program, const char *name)
6045{
6046 Program *programObject = getProgramResolveLink(program);
6047 return programObject->getFragDataIndex(name);
6048}
6049
6050int Context::getProgramResourceLocationIndex(GLuint program,
6051 GLenum programInterface,
6052 const char *name)
6053{
6054 Program *programObject = getProgramResolveLink(program);
6055 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6056 return programObject->getFragDataIndex(name);
6057}
6058
Jamie Madillc1d770e2017-04-13 17:31:24 -04006059void Context::shaderSource(GLuint shader,
6060 GLsizei count,
6061 const GLchar *const *string,
6062 const GLint *length)
6063{
6064 Shader *shaderObject = getShader(shader);
6065 ASSERT(shaderObject);
6066 shaderObject->setSource(count, string, length);
6067}
6068
6069void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6070{
6071 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6072}
6073
6074void Context::stencilMask(GLuint mask)
6075{
6076 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6077}
6078
6079void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6080{
6081 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6082}
6083
6084void Context::uniform1f(GLint location, GLfloat x)
6085{
6086 Program *program = mGLState.getProgram();
6087 program->setUniform1fv(location, 1, &x);
6088}
6089
6090void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6091{
6092 Program *program = mGLState.getProgram();
6093 program->setUniform1fv(location, count, v);
6094}
6095
Jamie Madill7e4eff12018-08-08 15:49:26 -04006096void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006097{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006098 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04006099 {
6100 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006101 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04006102 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006103}
6104
Jamie Madill7e4eff12018-08-08 15:49:26 -04006105void Context::uniform1i(GLint location, GLint x)
6106{
6107 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6108}
6109
Jamie Madillc1d770e2017-04-13 17:31:24 -04006110void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6111{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006112 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006113}
6114
6115void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6116{
6117 GLfloat xy[2] = {x, y};
6118 Program *program = mGLState.getProgram();
6119 program->setUniform2fv(location, 1, xy);
6120}
6121
6122void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6123{
6124 Program *program = mGLState.getProgram();
6125 program->setUniform2fv(location, count, v);
6126}
6127
6128void Context::uniform2i(GLint location, GLint x, GLint y)
6129{
6130 GLint xy[2] = {x, y};
6131 Program *program = mGLState.getProgram();
6132 program->setUniform2iv(location, 1, xy);
6133}
6134
6135void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6136{
6137 Program *program = mGLState.getProgram();
6138 program->setUniform2iv(location, count, v);
6139}
6140
6141void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6142{
6143 GLfloat xyz[3] = {x, y, z};
6144 Program *program = mGLState.getProgram();
6145 program->setUniform3fv(location, 1, xyz);
6146}
6147
6148void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6149{
6150 Program *program = mGLState.getProgram();
6151 program->setUniform3fv(location, count, v);
6152}
6153
6154void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6155{
6156 GLint xyz[3] = {x, y, z};
6157 Program *program = mGLState.getProgram();
6158 program->setUniform3iv(location, 1, xyz);
6159}
6160
6161void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6162{
6163 Program *program = mGLState.getProgram();
6164 program->setUniform3iv(location, count, v);
6165}
6166
6167void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6168{
6169 GLfloat xyzw[4] = {x, y, z, w};
6170 Program *program = mGLState.getProgram();
6171 program->setUniform4fv(location, 1, xyzw);
6172}
6173
6174void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6175{
6176 Program *program = mGLState.getProgram();
6177 program->setUniform4fv(location, count, v);
6178}
6179
6180void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6181{
6182 GLint xyzw[4] = {x, y, z, w};
6183 Program *program = mGLState.getProgram();
6184 program->setUniform4iv(location, 1, xyzw);
6185}
6186
6187void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6188{
6189 Program *program = mGLState.getProgram();
6190 program->setUniform4iv(location, count, v);
6191}
6192
6193void Context::uniformMatrix2fv(GLint location,
6194 GLsizei count,
6195 GLboolean transpose,
6196 const GLfloat *value)
6197{
6198 Program *program = mGLState.getProgram();
6199 program->setUniformMatrix2fv(location, count, transpose, value);
6200}
6201
6202void Context::uniformMatrix3fv(GLint location,
6203 GLsizei count,
6204 GLboolean transpose,
6205 const GLfloat *value)
6206{
6207 Program *program = mGLState.getProgram();
6208 program->setUniformMatrix3fv(location, count, transpose, value);
6209}
6210
6211void Context::uniformMatrix4fv(GLint location,
6212 GLsizei count,
6213 GLboolean transpose,
6214 const GLfloat *value)
6215{
6216 Program *program = mGLState.getProgram();
6217 program->setUniformMatrix4fv(location, count, transpose, value);
6218}
6219
6220void Context::validateProgram(GLuint program)
6221{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006222 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006223 ASSERT(programObject);
6224 programObject->validate(mCaps);
6225}
6226
Jiajia Qin5451d532017-11-16 17:16:34 +08006227void Context::validateProgramPipeline(GLuint pipeline)
6228{
6229 UNIMPLEMENTED();
6230}
6231
Jamie Madilld04908b2017-06-09 14:15:35 -04006232void Context::getProgramBinary(GLuint program,
6233 GLsizei bufSize,
6234 GLsizei *length,
6235 GLenum *binaryFormat,
6236 void *binary)
6237{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006238 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006239 ASSERT(programObject != nullptr);
6240
Jamie Madill4f6592f2018-11-27 16:37:45 -05006241 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006242}
6243
6244void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6245{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006246 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006247 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006248
Jamie Madill4f6592f2018-11-27 16:37:45 -05006249 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006250 if (programObject->isInUse())
6251 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006252 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006253 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006254 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006255}
6256
Jamie Madillff325f12017-08-26 15:06:05 -04006257void Context::uniform1ui(GLint location, GLuint v0)
6258{
6259 Program *program = mGLState.getProgram();
6260 program->setUniform1uiv(location, 1, &v0);
6261}
6262
6263void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6264{
6265 Program *program = mGLState.getProgram();
6266 const GLuint xy[] = {v0, v1};
6267 program->setUniform2uiv(location, 1, xy);
6268}
6269
6270void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6271{
6272 Program *program = mGLState.getProgram();
6273 const GLuint xyz[] = {v0, v1, v2};
6274 program->setUniform3uiv(location, 1, xyz);
6275}
6276
6277void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6278{
6279 Program *program = mGLState.getProgram();
6280 const GLuint xyzw[] = {v0, v1, v2, v3};
6281 program->setUniform4uiv(location, 1, xyzw);
6282}
6283
6284void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6285{
6286 Program *program = mGLState.getProgram();
6287 program->setUniform1uiv(location, count, value);
6288}
6289void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6290{
6291 Program *program = mGLState.getProgram();
6292 program->setUniform2uiv(location, count, value);
6293}
6294
6295void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6296{
6297 Program *program = mGLState.getProgram();
6298 program->setUniform3uiv(location, count, value);
6299}
6300
6301void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6302{
6303 Program *program = mGLState.getProgram();
6304 program->setUniform4uiv(location, count, value);
6305}
6306
Jamie Madillf0e04492017-08-26 15:28:42 -04006307void Context::genQueries(GLsizei n, GLuint *ids)
6308{
6309 for (GLsizei i = 0; i < n; i++)
6310 {
6311 GLuint handle = mQueryHandleAllocator.allocate();
6312 mQueryMap.assign(handle, nullptr);
6313 ids[i] = handle;
6314 }
6315}
6316
6317void Context::deleteQueries(GLsizei n, const GLuint *ids)
6318{
6319 for (int i = 0; i < n; i++)
6320 {
6321 GLuint query = ids[i];
6322
6323 Query *queryObject = nullptr;
6324 if (mQueryMap.erase(query, &queryObject))
6325 {
6326 mQueryHandleAllocator.release(query);
6327 if (queryObject)
6328 {
6329 queryObject->release(this);
6330 }
6331 }
6332 }
6333}
6334
6335GLboolean Context::isQuery(GLuint id)
6336{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006337 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006338}
6339
Jamie Madillc8c95812017-08-26 18:40:09 -04006340void Context::uniformMatrix2x3fv(GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *program = mGLState.getProgram();
6346 program->setUniformMatrix2x3fv(location, count, transpose, value);
6347}
6348
6349void Context::uniformMatrix3x2fv(GLint location,
6350 GLsizei count,
6351 GLboolean transpose,
6352 const GLfloat *value)
6353{
6354 Program *program = mGLState.getProgram();
6355 program->setUniformMatrix3x2fv(location, count, transpose, value);
6356}
6357
6358void Context::uniformMatrix2x4fv(GLint location,
6359 GLsizei count,
6360 GLboolean transpose,
6361 const GLfloat *value)
6362{
6363 Program *program = mGLState.getProgram();
6364 program->setUniformMatrix2x4fv(location, count, transpose, value);
6365}
6366
6367void Context::uniformMatrix4x2fv(GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *program = mGLState.getProgram();
6373 program->setUniformMatrix4x2fv(location, count, transpose, value);
6374}
6375
6376void Context::uniformMatrix3x4fv(GLint location,
6377 GLsizei count,
6378 GLboolean transpose,
6379 const GLfloat *value)
6380{
6381 Program *program = mGLState.getProgram();
6382 program->setUniformMatrix3x4fv(location, count, transpose, value);
6383}
6384
6385void Context::uniformMatrix4x3fv(GLint location,
6386 GLsizei count,
6387 GLboolean transpose,
6388 const GLfloat *value)
6389{
6390 Program *program = mGLState.getProgram();
6391 program->setUniformMatrix4x3fv(location, count, transpose, value);
6392}
6393
Jamie Madilld7576732017-08-26 18:49:50 -04006394void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6395{
6396 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6397 {
6398 GLuint vertexArray = arrays[arrayIndex];
6399
6400 if (arrays[arrayIndex] != 0)
6401 {
6402 VertexArray *vertexArrayObject = nullptr;
6403 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6404 {
6405 if (vertexArrayObject != nullptr)
6406 {
6407 detachVertexArray(vertexArray);
6408 vertexArrayObject->onDestroy(this);
6409 }
6410
6411 mVertexArrayHandleAllocator.release(vertexArray);
6412 }
6413 }
6414 }
6415}
6416
6417void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6418{
6419 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6420 {
6421 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6422 mVertexArrayMap.assign(vertexArray, nullptr);
6423 arrays[arrayIndex] = vertexArray;
6424 }
6425}
6426
6427bool Context::isVertexArray(GLuint array)
6428{
6429 if (array == 0)
6430 {
6431 return GL_FALSE;
6432 }
6433
6434 VertexArray *vao = getVertexArray(array);
6435 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6436}
6437
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006438void Context::endTransformFeedback()
6439{
6440 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6441 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006442 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006443}
6444
6445void Context::transformFeedbackVaryings(GLuint program,
6446 GLsizei count,
6447 const GLchar *const *varyings,
6448 GLenum bufferMode)
6449{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006450 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006451 ASSERT(programObject);
6452 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6453}
6454
6455void Context::getTransformFeedbackVarying(GLuint program,
6456 GLuint index,
6457 GLsizei bufSize,
6458 GLsizei *length,
6459 GLsizei *size,
6460 GLenum *type,
6461 GLchar *name)
6462{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006463 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006464 ASSERT(programObject);
6465 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6466}
6467
6468void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6469{
6470 for (int i = 0; i < n; i++)
6471 {
6472 GLuint transformFeedback = ids[i];
6473 if (transformFeedback == 0)
6474 {
6475 continue;
6476 }
6477
6478 TransformFeedback *transformFeedbackObject = nullptr;
6479 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6480 {
6481 if (transformFeedbackObject != nullptr)
6482 {
6483 detachTransformFeedback(transformFeedback);
6484 transformFeedbackObject->release(this);
6485 }
6486
6487 mTransformFeedbackHandleAllocator.release(transformFeedback);
6488 }
6489 }
6490}
6491
6492void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6493{
6494 for (int i = 0; i < n; i++)
6495 {
6496 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6497 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6498 ids[i] = transformFeedback;
6499 }
6500}
6501
6502bool Context::isTransformFeedback(GLuint id)
6503{
6504 if (id == 0)
6505 {
6506 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6507 // returns FALSE
6508 return GL_FALSE;
6509 }
6510
6511 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6512 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6513}
6514
6515void Context::pauseTransformFeedback()
6516{
6517 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6518 transformFeedback->pause();
6519}
6520
6521void Context::resumeTransformFeedback()
6522{
6523 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6524 transformFeedback->resume();
6525}
6526
Jamie Madill12e957f2017-08-26 21:42:26 -04006527void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6528{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006529 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006530 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006531}
6532
Brandon Jones59770802018-04-02 13:18:42 -07006533void Context::getUniformuivRobust(GLuint program,
6534 GLint location,
6535 GLsizei bufSize,
6536 GLsizei *length,
6537 GLuint *params)
6538{
6539 getUniformuiv(program, location, params);
6540}
6541
Jamie Madill12e957f2017-08-26 21:42:26 -04006542GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6543{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006544 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006545 return programObject->getFragDataLocation(name);
6546}
6547
6548void Context::getUniformIndices(GLuint program,
6549 GLsizei uniformCount,
6550 const GLchar *const *uniformNames,
6551 GLuint *uniformIndices)
6552{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006553 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006554 if (!programObject->isLinked())
6555 {
6556 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6557 {
6558 uniformIndices[uniformId] = GL_INVALID_INDEX;
6559 }
6560 }
6561 else
6562 {
6563 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6564 {
6565 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6566 }
6567 }
6568}
6569
6570void Context::getActiveUniformsiv(GLuint program,
6571 GLsizei uniformCount,
6572 const GLuint *uniformIndices,
6573 GLenum pname,
6574 GLint *params)
6575{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006576 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006577 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6578 {
6579 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006580 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006581 }
6582}
6583
6584GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6585{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006586 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006587 return programObject->getUniformBlockIndex(uniformBlockName);
6588}
6589
6590void Context::getActiveUniformBlockiv(GLuint program,
6591 GLuint uniformBlockIndex,
6592 GLenum pname,
6593 GLint *params)
6594{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006595 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006596 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6597}
6598
Brandon Jones59770802018-04-02 13:18:42 -07006599void Context::getActiveUniformBlockivRobust(GLuint program,
6600 GLuint uniformBlockIndex,
6601 GLenum pname,
6602 GLsizei bufSize,
6603 GLsizei *length,
6604 GLint *params)
6605{
6606 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6607}
6608
Jamie Madill12e957f2017-08-26 21:42:26 -04006609void Context::getActiveUniformBlockName(GLuint program,
6610 GLuint uniformBlockIndex,
6611 GLsizei bufSize,
6612 GLsizei *length,
6613 GLchar *uniformBlockName)
6614{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006615 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006616 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6617}
6618
6619void Context::uniformBlockBinding(GLuint program,
6620 GLuint uniformBlockIndex,
6621 GLuint uniformBlockBinding)
6622{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006623 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006624 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006625
Jamie Madill956ab4d2018-10-10 16:13:03 -04006626 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006627 if (programObject->isInUse())
6628 {
6629 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006630 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006631 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006632}
6633
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006634GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6635{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006636 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6637 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006638
Jamie Madill70b5bb02017-08-28 13:32:37 -04006639 Sync *syncObject = getSync(syncHandle);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006640 if (syncObject->set(this, condition, flags) == angle::Result::Stop())
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006641 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006642 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006643 return nullptr;
6644 }
6645
Jamie Madill70b5bb02017-08-28 13:32:37 -04006646 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006647}
6648
6649GLboolean Context::isSync(GLsync sync)
6650{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006651 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006652}
6653
6654GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6655{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006656 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006657
6658 GLenum result = GL_WAIT_FAILED;
Jamie Madill4f6592f2018-11-27 16:37:45 -05006659 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop())
6660 {
6661 return GL_WAIT_FAILED;
6662 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006663 return result;
6664}
6665
6666void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6667{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006668 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006669 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006670}
6671
6672void Context::getInteger64v(GLenum pname, GLint64 *params)
6673{
6674 GLenum nativeType = GL_NONE;
6675 unsigned int numParams = 0;
6676 getQueryParameterInfo(pname, &nativeType, &numParams);
6677
6678 if (nativeType == GL_INT_64_ANGLEX)
6679 {
6680 getInteger64vImpl(pname, params);
6681 }
6682 else
6683 {
6684 CastStateValues(this, nativeType, pname, numParams, params);
6685 }
6686}
6687
Brandon Jones59770802018-04-02 13:18:42 -07006688void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6689{
6690 getInteger64v(pname, data);
6691}
6692
Corentin Wallez336129f2017-10-17 15:55:40 -04006693void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006694{
6695 Buffer *buffer = mGLState.getTargetBuffer(target);
6696 QueryBufferParameteri64v(buffer, pname, params);
6697}
6698
Brandon Jones59770802018-04-02 13:18:42 -07006699void Context::getBufferParameteri64vRobust(BufferBinding target,
6700 GLenum pname,
6701 GLsizei bufSize,
6702 GLsizei *length,
6703 GLint64 *params)
6704{
6705 getBufferParameteri64v(target, pname, params);
6706}
6707
Jamie Madill3ef140a2017-08-26 23:11:21 -04006708void Context::genSamplers(GLsizei count, GLuint *samplers)
6709{
6710 for (int i = 0; i < count; i++)
6711 {
6712 samplers[i] = mState.mSamplers->createSampler();
6713 }
6714}
6715
6716void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6717{
6718 for (int i = 0; i < count; i++)
6719 {
6720 GLuint sampler = samplers[i];
6721
6722 if (mState.mSamplers->getSampler(sampler))
6723 {
6724 detachSampler(sampler);
6725 }
6726
6727 mState.mSamplers->deleteObject(this, sampler);
6728 }
6729}
6730
6731void Context::getInternalformativ(GLenum target,
6732 GLenum internalformat,
6733 GLenum pname,
6734 GLsizei bufSize,
6735 GLint *params)
6736{
6737 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6738 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6739}
6740
Brandon Jones59770802018-04-02 13:18:42 -07006741void Context::getInternalformativRobust(GLenum target,
6742 GLenum internalformat,
6743 GLenum pname,
6744 GLsizei bufSize,
6745 GLsizei *length,
6746 GLint *params)
6747{
6748 getInternalformativ(target, internalformat, pname, bufSize, params);
6749}
6750
Jiajia Qin5451d532017-11-16 17:16:34 +08006751void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6752{
6753 programUniform1iv(program, location, 1, &v0);
6754}
6755
6756void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6757{
6758 GLint xy[2] = {v0, v1};
6759 programUniform2iv(program, location, 1, xy);
6760}
6761
6762void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6763{
6764 GLint xyz[3] = {v0, v1, v2};
6765 programUniform3iv(program, location, 1, xyz);
6766}
6767
6768void Context::programUniform4i(GLuint program,
6769 GLint location,
6770 GLint v0,
6771 GLint v1,
6772 GLint v2,
6773 GLint v3)
6774{
6775 GLint xyzw[4] = {v0, v1, v2, v3};
6776 programUniform4iv(program, location, 1, xyzw);
6777}
6778
6779void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6780{
6781 programUniform1uiv(program, location, 1, &v0);
6782}
6783
6784void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6785{
6786 GLuint xy[2] = {v0, v1};
6787 programUniform2uiv(program, location, 1, xy);
6788}
6789
6790void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6791{
6792 GLuint xyz[3] = {v0, v1, v2};
6793 programUniform3uiv(program, location, 1, xyz);
6794}
6795
6796void Context::programUniform4ui(GLuint program,
6797 GLint location,
6798 GLuint v0,
6799 GLuint v1,
6800 GLuint v2,
6801 GLuint v3)
6802{
6803 GLuint xyzw[4] = {v0, v1, v2, v3};
6804 programUniform4uiv(program, location, 1, xyzw);
6805}
6806
6807void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6808{
6809 programUniform1fv(program, location, 1, &v0);
6810}
6811
6812void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6813{
6814 GLfloat xy[2] = {v0, v1};
6815 programUniform2fv(program, location, 1, xy);
6816}
6817
6818void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6819{
6820 GLfloat xyz[3] = {v0, v1, v2};
6821 programUniform3fv(program, location, 1, xyz);
6822}
6823
6824void Context::programUniform4f(GLuint program,
6825 GLint location,
6826 GLfloat v0,
6827 GLfloat v1,
6828 GLfloat v2,
6829 GLfloat v3)
6830{
6831 GLfloat xyzw[4] = {v0, v1, v2, v3};
6832 programUniform4fv(program, location, 1, xyzw);
6833}
6834
Jamie Madill81c2e252017-09-09 23:32:46 -04006835void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6836{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006837 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006838 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006839 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006840}
6841
Jiajia Qin5451d532017-11-16 17:16:34 +08006842void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6843{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006844 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006845 ASSERT(programObject);
6846 programObject->setUniform2iv(location, count, value);
6847}
6848
6849void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6850{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006851 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006852 ASSERT(programObject);
6853 programObject->setUniform3iv(location, count, value);
6854}
6855
6856void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6857{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006858 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006859 ASSERT(programObject);
6860 programObject->setUniform4iv(location, count, value);
6861}
6862
6863void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6864{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006865 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006866 ASSERT(programObject);
6867 programObject->setUniform1uiv(location, count, value);
6868}
6869
6870void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6871{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006872 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006873 ASSERT(programObject);
6874 programObject->setUniform2uiv(location, count, value);
6875}
6876
6877void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6878{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006879 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006880 ASSERT(programObject);
6881 programObject->setUniform3uiv(location, count, value);
6882}
6883
6884void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6885{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006886 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006887 ASSERT(programObject);
6888 programObject->setUniform4uiv(location, count, value);
6889}
6890
6891void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6892{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006893 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006894 ASSERT(programObject);
6895 programObject->setUniform1fv(location, count, value);
6896}
6897
6898void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6899{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006900 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006901 ASSERT(programObject);
6902 programObject->setUniform2fv(location, count, value);
6903}
6904
6905void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6906{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006907 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006908 ASSERT(programObject);
6909 programObject->setUniform3fv(location, count, value);
6910}
6911
6912void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6913{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006914 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006915 ASSERT(programObject);
6916 programObject->setUniform4fv(location, count, value);
6917}
6918
6919void Context::programUniformMatrix2fv(GLuint program,
6920 GLint location,
6921 GLsizei count,
6922 GLboolean transpose,
6923 const GLfloat *value)
6924{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006925 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006926 ASSERT(programObject);
6927 programObject->setUniformMatrix2fv(location, count, transpose, value);
6928}
6929
6930void Context::programUniformMatrix3fv(GLuint program,
6931 GLint location,
6932 GLsizei count,
6933 GLboolean transpose,
6934 const GLfloat *value)
6935{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006936 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006937 ASSERT(programObject);
6938 programObject->setUniformMatrix3fv(location, count, transpose, value);
6939}
6940
6941void Context::programUniformMatrix4fv(GLuint program,
6942 GLint location,
6943 GLsizei count,
6944 GLboolean transpose,
6945 const GLfloat *value)
6946{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006947 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006948 ASSERT(programObject);
6949 programObject->setUniformMatrix4fv(location, count, transpose, value);
6950}
6951
6952void Context::programUniformMatrix2x3fv(GLuint program,
6953 GLint location,
6954 GLsizei count,
6955 GLboolean transpose,
6956 const GLfloat *value)
6957{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006958 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006959 ASSERT(programObject);
6960 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6961}
6962
6963void Context::programUniformMatrix3x2fv(GLuint program,
6964 GLint location,
6965 GLsizei count,
6966 GLboolean transpose,
6967 const GLfloat *value)
6968{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006969 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006970 ASSERT(programObject);
6971 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6972}
6973
6974void Context::programUniformMatrix2x4fv(GLuint program,
6975 GLint location,
6976 GLsizei count,
6977 GLboolean transpose,
6978 const GLfloat *value)
6979{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006980 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006981 ASSERT(programObject);
6982 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6983}
6984
6985void Context::programUniformMatrix4x2fv(GLuint program,
6986 GLint location,
6987 GLsizei count,
6988 GLboolean transpose,
6989 const GLfloat *value)
6990{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006991 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006992 ASSERT(programObject);
6993 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6994}
6995
6996void Context::programUniformMatrix3x4fv(GLuint program,
6997 GLint location,
6998 GLsizei count,
6999 GLboolean transpose,
7000 const GLfloat *value)
7001{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007002 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007003 ASSERT(programObject);
7004 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7005}
7006
7007void Context::programUniformMatrix4x3fv(GLuint program,
7008 GLint location,
7009 GLsizei count,
7010 GLboolean transpose,
7011 const GLfloat *value)
7012{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007013 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007014 ASSERT(programObject);
7015 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7016}
7017
Jamie Madill81c2e252017-09-09 23:32:46 -04007018void Context::onTextureChange(const Texture *texture)
7019{
7020 // Conservatively assume all textures are dirty.
7021 // TODO(jmadill): More fine-grained update.
7022 mGLState.setObjectDirty(GL_TEXTURE);
7023}
7024
James Darpiniane8a93c62018-01-04 18:02:24 -08007025bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7026{
7027 return mGLState.isCurrentTransformFeedback(tf);
7028}
James Darpiniane8a93c62018-01-04 18:02:24 -08007029
Yunchao Hea336b902017-08-02 16:05:21 +08007030void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7031{
7032 for (int i = 0; i < count; i++)
7033 {
7034 pipelines[i] = createProgramPipeline();
7035 }
7036}
7037
7038void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7039{
7040 for (int i = 0; i < count; i++)
7041 {
7042 if (pipelines[i] != 0)
7043 {
7044 deleteProgramPipeline(pipelines[i]);
7045 }
7046 }
7047}
7048
7049GLboolean Context::isProgramPipeline(GLuint pipeline)
7050{
7051 if (pipeline == 0)
7052 {
7053 return GL_FALSE;
7054 }
7055
7056 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7057}
7058
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007059void Context::finishFenceNV(GLuint fence)
7060{
7061 FenceNV *fenceObject = getFenceNV(fence);
7062
7063 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007064 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007065}
7066
7067void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7068{
7069 FenceNV *fenceObject = getFenceNV(fence);
7070
7071 ASSERT(fenceObject && fenceObject->isSet());
7072
7073 switch (pname)
7074 {
7075 case GL_FENCE_STATUS_NV:
7076 {
7077 // GL_NV_fence spec:
7078 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7079 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7080 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7081 GLboolean status = GL_TRUE;
7082 if (fenceObject->getStatus() != GL_TRUE)
7083 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007084 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007085 }
7086 *params = status;
7087 break;
7088 }
7089
7090 case GL_FENCE_CONDITION_NV:
7091 {
7092 *params = static_cast<GLint>(fenceObject->getCondition());
7093 break;
7094 }
7095
7096 default:
7097 UNREACHABLE();
7098 }
7099}
7100
7101void Context::getTranslatedShaderSource(GLuint shader,
7102 GLsizei bufsize,
7103 GLsizei *length,
7104 GLchar *source)
7105{
7106 Shader *shaderObject = getShader(shader);
7107 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007108 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007109}
7110
7111void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7112{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007113 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007114 ASSERT(programObject);
7115
7116 programObject->getUniformfv(this, location, params);
7117}
7118
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007119void Context::getnUniformfvRobust(GLuint program,
7120 GLint location,
7121 GLsizei bufSize,
7122 GLsizei *length,
7123 GLfloat *params)
7124{
7125 UNIMPLEMENTED();
7126}
7127
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007128void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7129{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007130 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007131 ASSERT(programObject);
7132
7133 programObject->getUniformiv(this, location, params);
7134}
7135
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007136void Context::getnUniformivRobust(GLuint program,
7137 GLint location,
7138 GLsizei bufSize,
7139 GLsizei *length,
7140 GLint *params)
7141{
7142 UNIMPLEMENTED();
7143}
7144
7145void Context::getnUniformuivRobust(GLuint program,
7146 GLint location,
7147 GLsizei bufSize,
7148 GLsizei *length,
7149 GLuint *params)
7150{
7151 UNIMPLEMENTED();
7152}
7153
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007154GLboolean Context::isFenceNV(GLuint fence)
7155{
7156 FenceNV *fenceObject = getFenceNV(fence);
7157
7158 if (fenceObject == nullptr)
7159 {
7160 return GL_FALSE;
7161 }
7162
7163 // GL_NV_fence spec:
7164 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7165 // existing fence.
7166 return fenceObject->isSet();
7167}
7168
7169void Context::readnPixels(GLint x,
7170 GLint y,
7171 GLsizei width,
7172 GLsizei height,
7173 GLenum format,
7174 GLenum type,
7175 GLsizei bufSize,
7176 void *data)
7177{
7178 return readPixels(x, y, width, height, format, type, data);
7179}
7180
Jamie Madill007530e2017-12-28 14:27:04 -05007181void Context::setFenceNV(GLuint fence, GLenum condition)
7182{
7183 ASSERT(condition == GL_ALL_COMPLETED_NV);
7184
7185 FenceNV *fenceObject = getFenceNV(fence);
7186 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007187 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007188}
7189
7190GLboolean Context::testFenceNV(GLuint fence)
7191{
7192 FenceNV *fenceObject = getFenceNV(fence);
7193
7194 ASSERT(fenceObject != nullptr);
7195 ASSERT(fenceObject->isSet() == GL_TRUE);
7196
7197 GLboolean result = GL_TRUE;
Jamie Madill4f6592f2018-11-27 16:37:45 -05007198 if (fenceObject->test(this, &result) == angle::Result::Stop())
Jamie Madill007530e2017-12-28 14:27:04 -05007199 {
Jamie Madill007530e2017-12-28 14:27:04 -05007200 return GL_TRUE;
7201 }
7202
7203 return result;
7204}
7205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007206void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007207{
7208 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007209 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007210 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007211}
7212
Jamie Madillfa920eb2018-01-04 11:45:50 -05007213void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007214{
7215 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007216 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007217 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007218}
7219
Jamie Madillfa920eb2018-01-04 11:45:50 -05007220void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7221{
7222 UNIMPLEMENTED();
7223}
7224
Jamie Madill5b772312018-03-08 20:28:32 -05007225bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7226{
7227 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7228 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7229 // to the fact that it is stored internally as a float, and so would require conversion
7230 // if returned from Context::getIntegerv. Since this conversion is already implemented
7231 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7232 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7233 // application.
7234 switch (pname)
7235 {
7236 case GL_COMPRESSED_TEXTURE_FORMATS:
7237 {
7238 *type = GL_INT;
7239 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7240 return true;
7241 }
7242 case GL_SHADER_BINARY_FORMATS:
7243 {
7244 *type = GL_INT;
7245 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7246 return true;
7247 }
7248
7249 case GL_MAX_VERTEX_ATTRIBS:
7250 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7251 case GL_MAX_VARYING_VECTORS:
7252 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7253 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7254 case GL_MAX_TEXTURE_IMAGE_UNITS:
7255 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7256 case GL_MAX_RENDERBUFFER_SIZE:
7257 case GL_NUM_SHADER_BINARY_FORMATS:
7258 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7259 case GL_ARRAY_BUFFER_BINDING:
7260 case GL_FRAMEBUFFER_BINDING:
7261 case GL_RENDERBUFFER_BINDING:
7262 case GL_CURRENT_PROGRAM:
7263 case GL_PACK_ALIGNMENT:
7264 case GL_UNPACK_ALIGNMENT:
7265 case GL_GENERATE_MIPMAP_HINT:
7266 case GL_RED_BITS:
7267 case GL_GREEN_BITS:
7268 case GL_BLUE_BITS:
7269 case GL_ALPHA_BITS:
7270 case GL_DEPTH_BITS:
7271 case GL_STENCIL_BITS:
7272 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7273 case GL_CULL_FACE_MODE:
7274 case GL_FRONT_FACE:
7275 case GL_ACTIVE_TEXTURE:
7276 case GL_STENCIL_FUNC:
7277 case GL_STENCIL_VALUE_MASK:
7278 case GL_STENCIL_REF:
7279 case GL_STENCIL_FAIL:
7280 case GL_STENCIL_PASS_DEPTH_FAIL:
7281 case GL_STENCIL_PASS_DEPTH_PASS:
7282 case GL_STENCIL_BACK_FUNC:
7283 case GL_STENCIL_BACK_VALUE_MASK:
7284 case GL_STENCIL_BACK_REF:
7285 case GL_STENCIL_BACK_FAIL:
7286 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7287 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7288 case GL_DEPTH_FUNC:
7289 case GL_BLEND_SRC_RGB:
7290 case GL_BLEND_SRC_ALPHA:
7291 case GL_BLEND_DST_RGB:
7292 case GL_BLEND_DST_ALPHA:
7293 case GL_BLEND_EQUATION_RGB:
7294 case GL_BLEND_EQUATION_ALPHA:
7295 case GL_STENCIL_WRITEMASK:
7296 case GL_STENCIL_BACK_WRITEMASK:
7297 case GL_STENCIL_CLEAR_VALUE:
7298 case GL_SUBPIXEL_BITS:
7299 case GL_MAX_TEXTURE_SIZE:
7300 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7301 case GL_SAMPLE_BUFFERS:
7302 case GL_SAMPLES:
7303 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7304 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7305 case GL_TEXTURE_BINDING_2D:
7306 case GL_TEXTURE_BINDING_CUBE_MAP:
7307 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7308 {
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7314 {
7315 if (!getExtensions().packReverseRowOrder)
7316 {
7317 return false;
7318 }
7319 *type = GL_INT;
7320 *numParams = 1;
7321 return true;
7322 }
7323 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7324 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7325 {
7326 if (!getExtensions().textureRectangle)
7327 {
7328 return false;
7329 }
7330 *type = GL_INT;
7331 *numParams = 1;
7332 return true;
7333 }
7334 case GL_MAX_DRAW_BUFFERS_EXT:
7335 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7336 {
7337 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7338 {
7339 return false;
7340 }
7341 *type = GL_INT;
7342 *numParams = 1;
7343 return true;
7344 }
7345 case GL_MAX_VIEWPORT_DIMS:
7346 {
7347 *type = GL_INT;
7348 *numParams = 2;
7349 return true;
7350 }
7351 case GL_VIEWPORT:
7352 case GL_SCISSOR_BOX:
7353 {
7354 *type = GL_INT;
7355 *numParams = 4;
7356 return true;
7357 }
7358 case GL_SHADER_COMPILER:
7359 case GL_SAMPLE_COVERAGE_INVERT:
7360 case GL_DEPTH_WRITEMASK:
7361 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7362 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7363 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7364 // bool-natural
7365 case GL_SAMPLE_COVERAGE:
7366 case GL_SCISSOR_TEST:
7367 case GL_STENCIL_TEST:
7368 case GL_DEPTH_TEST:
7369 case GL_BLEND:
7370 case GL_DITHER:
7371 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7372 {
7373 *type = GL_BOOL;
7374 *numParams = 1;
7375 return true;
7376 }
7377 case GL_COLOR_WRITEMASK:
7378 {
7379 *type = GL_BOOL;
7380 *numParams = 4;
7381 return true;
7382 }
7383 case GL_POLYGON_OFFSET_FACTOR:
7384 case GL_POLYGON_OFFSET_UNITS:
7385 case GL_SAMPLE_COVERAGE_VALUE:
7386 case GL_DEPTH_CLEAR_VALUE:
7387 case GL_LINE_WIDTH:
7388 {
7389 *type = GL_FLOAT;
7390 *numParams = 1;
7391 return true;
7392 }
7393 case GL_ALIASED_LINE_WIDTH_RANGE:
7394 case GL_ALIASED_POINT_SIZE_RANGE:
7395 case GL_DEPTH_RANGE:
7396 {
7397 *type = GL_FLOAT;
7398 *numParams = 2;
7399 return true;
7400 }
7401 case GL_COLOR_CLEAR_VALUE:
7402 case GL_BLEND_COLOR:
7403 {
7404 *type = GL_FLOAT;
7405 *numParams = 4;
7406 return true;
7407 }
7408 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7409 if (!getExtensions().textureFilterAnisotropic)
7410 {
7411 return false;
7412 }
7413 *type = GL_FLOAT;
7414 *numParams = 1;
7415 return true;
7416 case GL_TIMESTAMP_EXT:
7417 if (!getExtensions().disjointTimerQuery)
7418 {
7419 return false;
7420 }
7421 *type = GL_INT_64_ANGLEX;
7422 *numParams = 1;
7423 return true;
7424 case GL_GPU_DISJOINT_EXT:
7425 if (!getExtensions().disjointTimerQuery)
7426 {
7427 return false;
7428 }
7429 *type = GL_INT;
7430 *numParams = 1;
7431 return true;
7432 case GL_COVERAGE_MODULATION_CHROMIUM:
7433 if (!getExtensions().framebufferMixedSamples)
7434 {
7435 return false;
7436 }
7437 *type = GL_INT;
7438 *numParams = 1;
7439 return true;
7440 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7441 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7442 {
7443 return false;
7444 }
7445 *type = GL_INT;
7446 *numParams = 1;
7447 return true;
7448 }
7449
7450 if (getExtensions().debug)
7451 {
7452 switch (pname)
7453 {
7454 case GL_DEBUG_LOGGED_MESSAGES:
7455 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7456 case GL_DEBUG_GROUP_STACK_DEPTH:
7457 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7458 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7459 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7460 case GL_MAX_LABEL_LENGTH:
7461 *type = GL_INT;
7462 *numParams = 1;
7463 return true;
7464
7465 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7466 case GL_DEBUG_OUTPUT:
7467 *type = GL_BOOL;
7468 *numParams = 1;
7469 return true;
7470 }
7471 }
7472
7473 if (getExtensions().multisampleCompatibility)
7474 {
7475 switch (pname)
7476 {
7477 case GL_MULTISAMPLE_EXT:
7478 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7479 *type = GL_BOOL;
7480 *numParams = 1;
7481 return true;
7482 }
7483 }
7484
7485 if (getExtensions().pathRendering)
7486 {
7487 switch (pname)
7488 {
7489 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7490 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7491 *type = GL_FLOAT;
7492 *numParams = 16;
7493 return true;
7494 }
7495 }
7496
7497 if (getExtensions().bindGeneratesResource)
7498 {
7499 switch (pname)
7500 {
7501 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7502 *type = GL_BOOL;
7503 *numParams = 1;
7504 return true;
7505 }
7506 }
7507
7508 if (getExtensions().clientArrays)
7509 {
7510 switch (pname)
7511 {
7512 case GL_CLIENT_ARRAYS_ANGLE:
7513 *type = GL_BOOL;
7514 *numParams = 1;
7515 return true;
7516 }
7517 }
7518
7519 if (getExtensions().sRGBWriteControl)
7520 {
7521 switch (pname)
7522 {
7523 case GL_FRAMEBUFFER_SRGB_EXT:
7524 *type = GL_BOOL;
7525 *numParams = 1;
7526 return true;
7527 }
7528 }
7529
7530 if (getExtensions().robustResourceInitialization &&
7531 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7532 {
7533 *type = GL_BOOL;
7534 *numParams = 1;
7535 return true;
7536 }
7537
7538 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7539 {
7540 *type = GL_BOOL;
7541 *numParams = 1;
7542 return true;
7543 }
7544
jchen1082af6202018-06-22 10:59:52 +08007545 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7546 {
7547 *type = GL_INT;
7548 *numParams = 1;
7549 return true;
7550 }
7551
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007552 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7553 {
7554 *type = GL_INT;
7555 *numParams = 1;
7556 return true;
7557 }
7558
Jamie Madill5b772312018-03-08 20:28:32 -05007559 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7560 switch (pname)
7561 {
7562 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7563 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7564 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7565 {
7566 return false;
7567 }
7568 *type = GL_INT;
7569 *numParams = 1;
7570 return true;
7571
7572 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7573 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7574 {
7575 return false;
7576 }
7577 *type = GL_INT;
7578 *numParams = 1;
7579 return true;
7580
7581 case GL_PROGRAM_BINARY_FORMATS_OES:
7582 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7583 {
7584 return false;
7585 }
7586 *type = GL_INT;
7587 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7588 return true;
7589
7590 case GL_PACK_ROW_LENGTH:
7591 case GL_PACK_SKIP_ROWS:
7592 case GL_PACK_SKIP_PIXELS:
7593 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7594 {
7595 return false;
7596 }
7597 *type = GL_INT;
7598 *numParams = 1;
7599 return true;
7600 case GL_UNPACK_ROW_LENGTH:
7601 case GL_UNPACK_SKIP_ROWS:
7602 case GL_UNPACK_SKIP_PIXELS:
7603 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7604 {
7605 return false;
7606 }
7607 *type = GL_INT;
7608 *numParams = 1;
7609 return true;
7610 case GL_VERTEX_ARRAY_BINDING:
7611 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7612 {
7613 return false;
7614 }
7615 *type = GL_INT;
7616 *numParams = 1;
7617 return true;
7618 case GL_PIXEL_PACK_BUFFER_BINDING:
7619 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7620 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7621 {
7622 return false;
7623 }
7624 *type = GL_INT;
7625 *numParams = 1;
7626 return true;
7627 case GL_MAX_SAMPLES:
7628 {
7629 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7630 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7631 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7632 {
7633 return false;
7634 }
7635 *type = GL_INT;
7636 *numParams = 1;
7637 return true;
7638
7639 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7640 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7641 {
7642 return false;
7643 }
7644 *type = GL_INT;
7645 *numParams = 1;
7646 return true;
7647 }
7648 }
7649
7650 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7651 {
7652 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7653 {
7654 return false;
7655 }
7656 *type = GL_INT;
7657 *numParams = 1;
7658 return true;
7659 }
7660
7661 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7662 {
7663 *type = GL_INT;
7664 *numParams = 1;
7665 return true;
7666 }
7667
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007668 if (getClientVersion() < Version(2, 0))
7669 {
7670 switch (pname)
7671 {
7672 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007673 case GL_CLIENT_ACTIVE_TEXTURE:
7674 case GL_MATRIX_MODE:
7675 case GL_MAX_TEXTURE_UNITS:
7676 case GL_MAX_MODELVIEW_STACK_DEPTH:
7677 case GL_MAX_PROJECTION_STACK_DEPTH:
7678 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007679 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007680 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007681 case GL_VERTEX_ARRAY_STRIDE:
7682 case GL_NORMAL_ARRAY_STRIDE:
7683 case GL_COLOR_ARRAY_STRIDE:
7684 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7685 case GL_VERTEX_ARRAY_SIZE:
7686 case GL_COLOR_ARRAY_SIZE:
7687 case GL_TEXTURE_COORD_ARRAY_SIZE:
7688 case GL_VERTEX_ARRAY_TYPE:
7689 case GL_NORMAL_ARRAY_TYPE:
7690 case GL_COLOR_ARRAY_TYPE:
7691 case GL_TEXTURE_COORD_ARRAY_TYPE:
7692 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7693 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7694 case GL_COLOR_ARRAY_BUFFER_BINDING:
7695 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7696 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7697 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7698 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007699 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007700 case GL_MODELVIEW_STACK_DEPTH:
7701 case GL_PROJECTION_STACK_DEPTH:
7702 case GL_TEXTURE_STACK_DEPTH:
7703 case GL_LOGIC_OP_MODE:
7704 case GL_BLEND_SRC:
7705 case GL_BLEND_DST:
7706 case GL_PERSPECTIVE_CORRECTION_HINT:
7707 case GL_POINT_SMOOTH_HINT:
7708 case GL_LINE_SMOOTH_HINT:
7709 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007710 *type = GL_INT;
7711 *numParams = 1;
7712 return true;
7713 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007714 case GL_FOG_DENSITY:
7715 case GL_FOG_START:
7716 case GL_FOG_END:
7717 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007718 case GL_POINT_SIZE:
7719 case GL_POINT_SIZE_MIN:
7720 case GL_POINT_SIZE_MAX:
7721 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007722 *type = GL_FLOAT;
7723 *numParams = 1;
7724 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007725 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007726 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007727 *type = GL_FLOAT;
7728 *numParams = 2;
7729 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007730 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007731 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007732 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007733 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007734 *type = GL_FLOAT;
7735 *numParams = 4;
7736 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007737 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007738 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007739 *type = GL_FLOAT;
7740 *numParams = 3;
7741 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007742 case GL_MODELVIEW_MATRIX:
7743 case GL_PROJECTION_MATRIX:
7744 case GL_TEXTURE_MATRIX:
7745 *type = GL_FLOAT;
7746 *numParams = 16;
7747 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007748 case GL_LIGHT_MODEL_TWO_SIDE:
7749 *type = GL_BOOL;
7750 *numParams = 1;
7751 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007752 }
7753 }
7754
Jamie Madill5b772312018-03-08 20:28:32 -05007755 if (getClientVersion() < Version(3, 0))
7756 {
7757 return false;
7758 }
7759
7760 // Check for ES3.0+ parameter names
7761 switch (pname)
7762 {
7763 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7764 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7765 case GL_UNIFORM_BUFFER_BINDING:
7766 case GL_TRANSFORM_FEEDBACK_BINDING:
7767 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7768 case GL_COPY_READ_BUFFER_BINDING:
7769 case GL_COPY_WRITE_BUFFER_BINDING:
7770 case GL_SAMPLER_BINDING:
7771 case GL_READ_BUFFER:
7772 case GL_TEXTURE_BINDING_3D:
7773 case GL_TEXTURE_BINDING_2D_ARRAY:
7774 case GL_MAX_3D_TEXTURE_SIZE:
7775 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7776 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7777 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7778 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7779 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7780 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7781 case GL_MAX_VARYING_COMPONENTS:
7782 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7783 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7784 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7785 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7786 case GL_NUM_EXTENSIONS:
7787 case GL_MAJOR_VERSION:
7788 case GL_MINOR_VERSION:
7789 case GL_MAX_ELEMENTS_INDICES:
7790 case GL_MAX_ELEMENTS_VERTICES:
7791 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7792 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7793 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7794 case GL_UNPACK_IMAGE_HEIGHT:
7795 case GL_UNPACK_SKIP_IMAGES:
7796 {
7797 *type = GL_INT;
7798 *numParams = 1;
7799 return true;
7800 }
7801
7802 case GL_MAX_ELEMENT_INDEX:
7803 case GL_MAX_UNIFORM_BLOCK_SIZE:
7804 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7805 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7806 case GL_MAX_SERVER_WAIT_TIMEOUT:
7807 {
7808 *type = GL_INT_64_ANGLEX;
7809 *numParams = 1;
7810 return true;
7811 }
7812
7813 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7814 case GL_TRANSFORM_FEEDBACK_PAUSED:
7815 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7816 case GL_RASTERIZER_DISCARD:
7817 {
7818 *type = GL_BOOL;
7819 *numParams = 1;
7820 return true;
7821 }
7822
7823 case GL_MAX_TEXTURE_LOD_BIAS:
7824 {
7825 *type = GL_FLOAT;
7826 *numParams = 1;
7827 return true;
7828 }
7829 }
7830
7831 if (getExtensions().requestExtension)
7832 {
7833 switch (pname)
7834 {
7835 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7836 *type = GL_INT;
7837 *numParams = 1;
7838 return true;
7839 }
7840 }
7841
Yizhou Jiang7818a852018-09-06 15:02:04 +08007842 if (getExtensions().textureMultisample)
7843 {
7844 switch (pname)
7845 {
7846 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7847 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7848 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7849 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
7850 *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 {
8112 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
8113 }
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 {
8120 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008121 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008122 }
Jamie Madille25b8002018-09-20 13:39:49 -04008123 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008124 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008125 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008126 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008127 }
Jamie Madille25b8002018-09-20 13:39:49 -04008128 else
8129 {
8130 ASSERT(index < kSamplerMaxSubjectIndex);
8131 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8132 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008133 break;
8134 }
8135}
8136
Jamie Madill6b873dd2018-07-12 23:56:30 -04008137// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008138ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008139
8140ErrorSet::~ErrorSet() = default;
8141
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008142void ErrorSet::handleError(GLenum errorCode,
8143 const char *message,
8144 const char *file,
8145 const char *function,
8146 unsigned int line)
8147{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008148 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8149 {
8150 mContext->markContextLost();
8151 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008152
Jamie Madill4f6592f2018-11-27 16:37:45 -05008153 std::stringstream errorStream;
8154 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8155 << line << ". " << message;
8156
8157 // validationError does the necessary work to process the error.
8158 validationError(errorCode, errorStream.str().c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008159}
8160
Jamie Madilla139f012018-10-10 16:13:03 -04008161void ErrorSet::validationError(GLenum errorCode, const char *message)
8162{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008163 ASSERT(errorCode != GL_NO_ERROR);
8164 mErrors.insert(errorCode);
8165
8166 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8167 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008168}
8169
Jamie Madill6b873dd2018-07-12 23:56:30 -04008170bool ErrorSet::empty() const
8171{
8172 return mErrors.empty();
8173}
8174
8175GLenum ErrorSet::popError()
8176{
8177 ASSERT(!empty());
8178 GLenum error = *mErrors.begin();
8179 mErrors.erase(mErrors.begin());
8180 return error;
8181}
Jamie Madilldc358af2018-07-31 11:22:13 -04008182
8183// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008184StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008185 : mCachedHasAnyEnabledClientAttrib(false),
8186 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008187 mCachedInstancedVertexElementLimit(0),
8188 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008189{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008190
8191StateCache::~StateCache() = default;
8192
Jamie Madillac66f982018-10-09 18:30:01 -04008193void StateCache::initialize(Context *context)
8194{
8195 updateValidDrawModes(context);
8196 updateValidBindTextureTypes(context);
8197}
8198
Jamie Madilldc358af2018-07-31 11:22:13 -04008199void StateCache::updateActiveAttribsMask(Context *context)
8200{
8201 bool isGLES1 = context->isGLES1();
8202 const State &glState = context->getGLState();
8203
8204 if (!isGLES1 && !glState.getProgram())
8205 {
8206 mCachedActiveBufferedAttribsMask = AttributesMask();
8207 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008208 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008209 return;
8210 }
8211
8212 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8213 : glState.getProgram()->getActiveAttribLocationsMask();
8214
8215 const VertexArray *vao = glState.getVertexArray();
8216 ASSERT(vao);
8217
8218 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8219 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008220 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008221
Jamie Madill0a17e482018-08-31 17:19:11 -04008222 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8223 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008224 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008225 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8226}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008227
8228void StateCache::updateVertexElementLimits(Context *context)
8229{
8230 const VertexArray *vao = context->getGLState().getVertexArray();
8231
8232 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8233 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8234
8235 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8236 // If there are no buffered attributes then we should not limit the draw call count.
8237 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8238 {
8239 return;
8240 }
8241
8242 const auto &vertexAttribs = vao->getVertexAttributes();
8243 const auto &vertexBindings = vao->getVertexBindings();
8244
8245 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8246 {
8247 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8248 ASSERT(attrib.enabled);
8249
8250 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8251 ASSERT(context->isGLES1() ||
8252 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8253
8254 GLint64 limit = attrib.getCachedElementLimit();
8255 if (binding.getDivisor() > 0)
8256 {
8257 mCachedInstancedVertexElementLimit =
8258 std::min(mCachedInstancedVertexElementLimit, limit);
8259 }
8260 else
8261 {
8262 mCachedNonInstancedVertexElementLimit =
8263 std::min(mCachedNonInstancedVertexElementLimit, limit);
8264 }
8265 }
8266}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008267
Jamie Madilld84b6732018-09-06 15:54:35 -04008268void StateCache::updateBasicDrawStatesError()
8269{
8270 mCachedBasicDrawStatesError = kInvalidPointer;
8271}
8272
8273intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8274{
8275 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8276 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8277 return mCachedBasicDrawStatesError;
8278}
8279
Jamie Madillc43cdad2018-08-08 15:49:25 -04008280void StateCache::onVertexArrayBindingChange(Context *context)
8281{
8282 updateActiveAttribsMask(context);
8283 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008284 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008285}
8286
8287void StateCache::onProgramExecutableChange(Context *context)
8288{
8289 updateActiveAttribsMask(context);
8290 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008291 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008292 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008293}
8294
Jamie Madilld84b6732018-09-06 15:54:35 -04008295void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008296{
8297 updateVertexElementLimits(context);
8298}
8299
Jamie Madilld84b6732018-09-06 15:54:35 -04008300void StateCache::onVertexArrayBufferContentsChange(Context *context)
8301{
8302 updateVertexElementLimits(context);
8303 updateBasicDrawStatesError();
8304}
8305
Jamie Madillc43cdad2018-08-08 15:49:25 -04008306void StateCache::onVertexArrayStateChange(Context *context)
8307{
8308 updateActiveAttribsMask(context);
8309 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008310 updateBasicDrawStatesError();
8311}
8312
8313void StateCache::onVertexArrayBufferStateChange(Context *context)
8314{
8315 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008316}
8317
8318void StateCache::onGLES1ClientStateChange(Context *context)
8319{
8320 updateActiveAttribsMask(context);
8321}
Jamie Madilld84b6732018-09-06 15:54:35 -04008322
8323void StateCache::onDrawFramebufferChange(Context *context)
8324{
8325 updateBasicDrawStatesError();
8326}
8327
8328void StateCache::onContextCapChange(Context *context)
8329{
8330 updateBasicDrawStatesError();
8331}
8332
8333void StateCache::onStencilStateChange(Context *context)
8334{
8335 updateBasicDrawStatesError();
8336}
8337
8338void StateCache::onDefaultVertexAttributeChange(Context *context)
8339{
8340 updateBasicDrawStatesError();
8341}
8342
8343void StateCache::onActiveTextureChange(Context *context)
8344{
8345 updateBasicDrawStatesError();
8346}
8347
8348void StateCache::onQueryChange(Context *context)
8349{
8350 updateBasicDrawStatesError();
8351}
8352
8353void StateCache::onTransformFeedbackChange(Context *context)
8354{
8355 updateBasicDrawStatesError();
8356}
8357
8358void StateCache::onUniformBufferStateChange(Context *context)
8359{
8360 updateBasicDrawStatesError();
8361}
8362
8363void StateCache::onBufferBindingChange(Context *context)
8364{
8365 updateBasicDrawStatesError();
8366}
Jamie Madill526a6f62018-09-12 11:03:05 -04008367
8368void StateCache::updateValidDrawModes(Context *context)
8369{
8370 Program *program = context->getGLState().getProgram();
8371 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8372 {
Jamie Madill752d2202018-11-27 13:29:48 -05008373 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008374 }
8375 else
8376 {
8377 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8378
8379 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8380
8381 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008382 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8383 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8384 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8385 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8386 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8387 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8388 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8389 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8390 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8391 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8392 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008393 }};
8394 }
8395}
Jamie Madillac66f982018-10-09 18:30:01 -04008396
8397void StateCache::updateValidBindTextureTypes(Context *context)
8398{
8399 const Extensions &exts = context->getExtensions();
8400 bool isGLES3 = context->getClientMajorVersion() >= 3;
8401 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8402
8403 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008404 {TextureType::_2D, true},
8405 {TextureType::_2DArray, isGLES3},
8406 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8407 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8408 {TextureType::_3D, isGLES3},
8409 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8410 {TextureType::Rectangle, exts.textureRectangle},
8411 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008412 }};
8413}
Jamie Madillc29968b2016-01-20 11:17:23 -05008414} // namespace gl