blob: 54b6f9a53355c44e8ef18d83acecbc9fec693b24 [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);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001033 object->setLabel(this, 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);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001046 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001047}
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;
Jamie Madill231c7f52017-04-26 13:45:37 -04001478 case GL_SUBPIXEL_BITS:
1479 *params = 4;
1480 break;
1481 case GL_MAX_TEXTURE_SIZE:
1482 *params = mCaps.max2DTextureSize;
1483 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001484 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1485 *params = mCaps.maxRectangleTextureSize;
1486 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1488 *params = mCaps.maxCubeMapTextureSize;
1489 break;
1490 case GL_MAX_3D_TEXTURE_SIZE:
1491 *params = mCaps.max3DTextureSize;
1492 break;
1493 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1494 *params = mCaps.maxArrayTextureLayers;
1495 break;
1496 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1497 *params = mCaps.uniformBufferOffsetAlignment;
1498 break;
1499 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1500 *params = mCaps.maxUniformBufferBindings;
1501 break;
1502 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001503 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 break;
1505 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001506 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001507 break;
1508 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1509 *params = mCaps.maxCombinedTextureImageUnits;
1510 break;
1511 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1512 *params = mCaps.maxVertexOutputComponents;
1513 break;
1514 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1515 *params = mCaps.maxFragmentInputComponents;
1516 break;
1517 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1518 *params = mCaps.minProgramTexelOffset;
1519 break;
1520 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1521 *params = mCaps.maxProgramTexelOffset;
1522 break;
1523 case GL_MAJOR_VERSION:
1524 *params = getClientVersion().major;
1525 break;
1526 case GL_MINOR_VERSION:
1527 *params = getClientVersion().minor;
1528 break;
1529 case GL_MAX_ELEMENTS_INDICES:
1530 *params = mCaps.maxElementsIndices;
1531 break;
1532 case GL_MAX_ELEMENTS_VERTICES:
1533 *params = mCaps.maxElementsVertices;
1534 break;
1535 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1536 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1537 break;
1538 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1539 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1540 break;
1541 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1542 *params = mCaps.maxTransformFeedbackSeparateComponents;
1543 break;
1544 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1545 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1546 break;
1547 case GL_MAX_SAMPLES_ANGLE:
1548 *params = mCaps.maxSamples;
1549 break;
1550 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001551 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001552 params[0] = mCaps.maxViewportWidth;
1553 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001554 }
1555 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001556 case GL_COMPRESSED_TEXTURE_FORMATS:
1557 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1558 params);
1559 break;
1560 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1561 *params = mResetStrategy;
1562 break;
1563 case GL_NUM_SHADER_BINARY_FORMATS:
1564 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1565 break;
1566 case GL_SHADER_BINARY_FORMATS:
1567 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1568 break;
1569 case GL_NUM_PROGRAM_BINARY_FORMATS:
1570 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1571 break;
1572 case GL_PROGRAM_BINARY_FORMATS:
1573 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1574 break;
1575 case GL_NUM_EXTENSIONS:
1576 *params = static_cast<GLint>(mExtensionStrings.size());
1577 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001578
Geoff Lang38f24ee2018-10-01 13:04:59 -04001579 // GL_ANGLE_request_extension
1580 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1581 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1582 break;
1583
Jamie Madill231c7f52017-04-26 13:45:37 -04001584 // GL_KHR_debug
1585 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1586 *params = mExtensions.maxDebugMessageLength;
1587 break;
1588 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1589 *params = mExtensions.maxDebugLoggedMessages;
1590 break;
1591 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1592 *params = mExtensions.maxDebugGroupStackDepth;
1593 break;
1594 case GL_MAX_LABEL_LENGTH:
1595 *params = mExtensions.maxLabelLength;
1596 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001597
Martin Radeve5285d22017-07-14 16:23:53 +03001598 // GL_ANGLE_multiview
1599 case GL_MAX_VIEWS_ANGLE:
1600 *params = mExtensions.maxViews;
1601 break;
1602
Jamie Madill231c7f52017-04-26 13:45:37 -04001603 // GL_EXT_disjoint_timer_query
1604 case GL_GPU_DISJOINT_EXT:
1605 *params = mImplementation->getGPUDisjoint();
1606 break;
1607 case GL_MAX_FRAMEBUFFER_WIDTH:
1608 *params = mCaps.maxFramebufferWidth;
1609 break;
1610 case GL_MAX_FRAMEBUFFER_HEIGHT:
1611 *params = mCaps.maxFramebufferHeight;
1612 break;
1613 case GL_MAX_FRAMEBUFFER_SAMPLES:
1614 *params = mCaps.maxFramebufferSamples;
1615 break;
1616 case GL_MAX_SAMPLE_MASK_WORDS:
1617 *params = mCaps.maxSampleMaskWords;
1618 break;
1619 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1620 *params = mCaps.maxColorTextureSamples;
1621 break;
1622 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1623 *params = mCaps.maxDepthTextureSamples;
1624 break;
1625 case GL_MAX_INTEGER_SAMPLES:
1626 *params = mCaps.maxIntegerSamples;
1627 break;
1628 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1629 *params = mCaps.maxVertexAttribRelativeOffset;
1630 break;
1631 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1632 *params = mCaps.maxVertexAttribBindings;
1633 break;
1634 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1635 *params = mCaps.maxVertexAttribStride;
1636 break;
1637 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001638 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001639 break;
1640 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001641 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 break;
1643 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001644 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001645 break;
1646 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001647 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001653 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001656 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001657 break;
1658 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001659 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1662 *params = mCaps.minProgramTextureGatherOffset;
1663 break;
1664 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1665 *params = mCaps.maxProgramTextureGatherOffset;
1666 break;
1667 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1668 *params = mCaps.maxComputeWorkGroupInvocations;
1669 break;
1670 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001671 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001674 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1677 *params = mCaps.maxComputeSharedMemorySize;
1678 break;
1679 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001683 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001686 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001689 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001692 *params =
1693 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001696 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1699 *params = mCaps.maxCombinedShaderOutputResources;
1700 break;
1701 case GL_MAX_UNIFORM_LOCATIONS:
1702 *params = mCaps.maxUniformLocations;
1703 break;
1704 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1705 *params = mCaps.maxAtomicCounterBufferBindings;
1706 break;
1707 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1708 *params = mCaps.maxAtomicCounterBufferSize;
1709 break;
1710 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1711 *params = mCaps.maxCombinedAtomicCounterBuffers;
1712 break;
1713 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1714 *params = mCaps.maxCombinedAtomicCounters;
1715 break;
1716 case GL_MAX_IMAGE_UNITS:
1717 *params = mCaps.maxImageUnits;
1718 break;
1719 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1720 *params = mCaps.maxCombinedImageUniforms;
1721 break;
1722 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1723 *params = mCaps.maxShaderStorageBufferBindings;
1724 break;
1725 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1726 *params = mCaps.maxCombinedShaderStorageBlocks;
1727 break;
1728 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1729 *params = mCaps.shaderStorageBufferOffsetAlignment;
1730 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001731
1732 // GL_EXT_geometry_shader
1733 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1734 *params = mCaps.maxFramebufferLayers;
1735 break;
1736 case GL_LAYER_PROVOKING_VERTEX_EXT:
1737 *params = mCaps.layerProvokingVertex;
1738 break;
1739 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001740 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001741 break;
1742 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001743 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001744 break;
1745 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001746 *params =
1747 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001748 break;
1749 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1750 *params = mCaps.maxGeometryInputComponents;
1751 break;
1752 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1753 *params = mCaps.maxGeometryOutputComponents;
1754 break;
1755 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1756 *params = mCaps.maxGeometryOutputVertices;
1757 break;
1758 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1759 *params = mCaps.maxGeometryTotalOutputComponents;
1760 break;
1761 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1762 *params = mCaps.maxGeometryShaderInvocations;
1763 break;
1764 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001765 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001766 break;
1767 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001768 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001769 break;
1770 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001771 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001772 break;
1773 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001774 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001775 break;
1776 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001777 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001778 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001779 // GLES1 emulation: Caps queries
1780 case GL_MAX_TEXTURE_UNITS:
1781 *params = mCaps.maxMultitextureUnits;
1782 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001783 case GL_MAX_MODELVIEW_STACK_DEPTH:
1784 *params = mCaps.maxModelviewMatrixStackDepth;
1785 break;
1786 case GL_MAX_PROJECTION_STACK_DEPTH:
1787 *params = mCaps.maxProjectionMatrixStackDepth;
1788 break;
1789 case GL_MAX_TEXTURE_STACK_DEPTH:
1790 *params = mCaps.maxTextureMatrixStackDepth;
1791 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001792 case GL_MAX_LIGHTS:
1793 *params = mCaps.maxLights;
1794 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001795 case GL_MAX_CLIP_PLANES:
1796 *params = mCaps.maxClipPlanes;
1797 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001798 // GLES1 emulation: Vertex attribute queries
1799 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1800 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1801 case GL_COLOR_ARRAY_BUFFER_BINDING:
1802 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1803 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1804 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1805 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1806 break;
1807 case GL_VERTEX_ARRAY_STRIDE:
1808 case GL_NORMAL_ARRAY_STRIDE:
1809 case GL_COLOR_ARRAY_STRIDE:
1810 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1811 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1812 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1813 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1814 break;
1815 case GL_VERTEX_ARRAY_SIZE:
1816 case GL_COLOR_ARRAY_SIZE:
1817 case GL_TEXTURE_COORD_ARRAY_SIZE:
1818 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1819 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1820 break;
1821 case GL_VERTEX_ARRAY_TYPE:
1822 case GL_COLOR_ARRAY_TYPE:
1823 case GL_NORMAL_ARRAY_TYPE:
1824 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1825 case GL_TEXTURE_COORD_ARRAY_TYPE:
1826 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1827 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1828 break;
1829
jchen1082af6202018-06-22 10:59:52 +08001830 // GL_KHR_parallel_shader_compile
1831 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1832 *params = mGLState.getMaxShaderCompilerThreads();
1833 break;
1834
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001835 // GL_EXT_blend_func_extended
1836 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1837 *params = mExtensions.maxDualSourceDrawBuffers;
1838 break;
1839
Jamie Madill231c7f52017-04-26 13:45:37 -04001840 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001841 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001842 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001843 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001844}
1845
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001846void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001847{
Shannon Woods53a94a82014-06-24 15:20:36 -04001848 // Queries about context capabilities and maximums are answered by Context.
1849 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001850 switch (pname)
1851 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001852 case GL_MAX_ELEMENT_INDEX:
1853 *params = mCaps.maxElementIndex;
1854 break;
1855 case GL_MAX_UNIFORM_BLOCK_SIZE:
1856 *params = mCaps.maxUniformBlockSize;
1857 break;
1858 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001859 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001860 break;
1861 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001862 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001863 break;
1864 case GL_MAX_SERVER_WAIT_TIMEOUT:
1865 *params = mCaps.maxServerWaitTimeout;
1866 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001867
Jamie Madill231c7f52017-04-26 13:45:37 -04001868 // GL_EXT_disjoint_timer_query
1869 case GL_TIMESTAMP_EXT:
1870 *params = mImplementation->getTimestamp();
1871 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001872
Jamie Madill231c7f52017-04-26 13:45:37 -04001873 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1874 *params = mCaps.maxShaderStorageBlockSize;
1875 break;
1876 default:
1877 UNREACHABLE();
1878 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001879 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001880}
1881
Geoff Lang70d0f492015-12-10 17:45:46 -05001882void Context::getPointerv(GLenum pname, void **params) const
1883{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001884 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001885}
1886
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001887void Context::getPointervRobustANGLERobust(GLenum pname,
1888 GLsizei bufSize,
1889 GLsizei *length,
1890 void **params)
1891{
1892 UNIMPLEMENTED();
1893}
1894
Martin Radev66fb8202016-07-28 11:45:20 +03001895void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001896{
Shannon Woods53a94a82014-06-24 15:20:36 -04001897 // Queries about context capabilities and maximums are answered by Context.
1898 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001899
1900 GLenum nativeType;
1901 unsigned int numParams;
1902 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1903 ASSERT(queryStatus);
1904
1905 if (nativeType == GL_INT)
1906 {
1907 switch (target)
1908 {
1909 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1910 ASSERT(index < 3u);
1911 *data = mCaps.maxComputeWorkGroupCount[index];
1912 break;
1913 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1914 ASSERT(index < 3u);
1915 *data = mCaps.maxComputeWorkGroupSize[index];
1916 break;
1917 default:
1918 mGLState.getIntegeri_v(target, index, data);
1919 }
1920 }
1921 else
1922 {
1923 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1924 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001925}
1926
Brandon Jones59770802018-04-02 13:18:42 -07001927void Context::getIntegeri_vRobust(GLenum target,
1928 GLuint index,
1929 GLsizei bufSize,
1930 GLsizei *length,
1931 GLint *data)
1932{
1933 getIntegeri_v(target, index, data);
1934}
1935
Martin Radev66fb8202016-07-28 11:45:20 +03001936void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001937{
Shannon Woods53a94a82014-06-24 15:20:36 -04001938 // Queries about context capabilities and maximums are answered by Context.
1939 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001940
1941 GLenum nativeType;
1942 unsigned int numParams;
1943 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1944 ASSERT(queryStatus);
1945
1946 if (nativeType == GL_INT_64_ANGLEX)
1947 {
1948 mGLState.getInteger64i_v(target, index, data);
1949 }
1950 else
1951 {
1952 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1953 }
1954}
1955
Brandon Jones59770802018-04-02 13:18:42 -07001956void Context::getInteger64i_vRobust(GLenum target,
1957 GLuint index,
1958 GLsizei bufSize,
1959 GLsizei *length,
1960 GLint64 *data)
1961{
1962 getInteger64i_v(target, index, data);
1963}
1964
Martin Radev66fb8202016-07-28 11:45:20 +03001965void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1966{
1967 // Queries about context capabilities and maximums are answered by Context.
1968 // Queries about current GL state values are answered by State.
1969
1970 GLenum nativeType;
1971 unsigned int numParams;
1972 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1973 ASSERT(queryStatus);
1974
1975 if (nativeType == GL_BOOL)
1976 {
1977 mGLState.getBooleani_v(target, index, data);
1978 }
1979 else
1980 {
1981 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1982 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001983}
1984
Brandon Jones59770802018-04-02 13:18:42 -07001985void Context::getBooleani_vRobust(GLenum target,
1986 GLuint index,
1987 GLsizei bufSize,
1988 GLsizei *length,
1989 GLboolean *data)
1990{
1991 getBooleani_v(target, index, data);
1992}
1993
Corentin Wallez336129f2017-10-17 15:55:40 -04001994void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001995{
1996 Buffer *buffer = mGLState.getTargetBuffer(target);
1997 QueryBufferParameteriv(buffer, pname, params);
1998}
1999
Brandon Jones59770802018-04-02 13:18:42 -07002000void Context::getBufferParameterivRobust(BufferBinding target,
2001 GLenum pname,
2002 GLsizei bufSize,
2003 GLsizei *length,
2004 GLint *params)
2005{
2006 getBufferParameteriv(target, pname, params);
2007}
2008
He Yunchao010e4db2017-03-03 14:22:06 +08002009void Context::getFramebufferAttachmentParameteriv(GLenum target,
2010 GLenum attachment,
2011 GLenum pname,
2012 GLint *params)
2013{
2014 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002015 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002016}
2017
Brandon Jones59770802018-04-02 13:18:42 -07002018void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2019 GLenum attachment,
2020 GLenum pname,
2021 GLsizei bufSize,
2022 GLsizei *length,
2023 GLint *params)
2024{
2025 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2026}
2027
He Yunchao010e4db2017-03-03 14:22:06 +08002028void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2029{
2030 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2031 QueryRenderbufferiv(this, renderbuffer, pname, params);
2032}
2033
Brandon Jones59770802018-04-02 13:18:42 -07002034void Context::getRenderbufferParameterivRobust(GLenum target,
2035 GLenum pname,
2036 GLsizei bufSize,
2037 GLsizei *length,
2038 GLint *params)
2039{
2040 getRenderbufferParameteriv(target, pname, params);
2041}
2042
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002043void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002044{
Till Rathmannb8543632018-10-02 19:46:14 +02002045 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002046 QueryTexParameterfv(texture, pname, params);
2047}
2048
Brandon Jones59770802018-04-02 13:18:42 -07002049void Context::getTexParameterfvRobust(TextureType target,
2050 GLenum pname,
2051 GLsizei bufSize,
2052 GLsizei *length,
2053 GLfloat *params)
2054{
2055 getTexParameterfv(target, pname, params);
2056}
2057
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002058void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002059{
Till Rathmannb8543632018-10-02 19:46:14 +02002060 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002061 QueryTexParameteriv(texture, pname, params);
2062}
Jiajia Qin5451d532017-11-16 17:16:34 +08002063
Till Rathmannb8543632018-10-02 19:46:14 +02002064void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2065{
2066 const Texture *const texture = getTargetTexture(target);
2067 QueryTexParameterIiv(texture, pname, params);
2068}
2069
2070void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2071{
2072 const Texture *const texture = getTargetTexture(target);
2073 QueryTexParameterIuiv(texture, pname, params);
2074}
2075
Brandon Jones59770802018-04-02 13:18:42 -07002076void Context::getTexParameterivRobust(TextureType target,
2077 GLenum pname,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLint *params)
2081{
2082 getTexParameteriv(target, pname, params);
2083}
2084
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002085void Context::getTexParameterIivRobust(TextureType target,
2086 GLenum pname,
2087 GLsizei bufSize,
2088 GLsizei *length,
2089 GLint *params)
2090{
2091 UNIMPLEMENTED();
2092}
2093
2094void Context::getTexParameterIuivRobust(TextureType target,
2095 GLenum pname,
2096 GLsizei bufSize,
2097 GLsizei *length,
2098 GLuint *params)
2099{
2100 UNIMPLEMENTED();
2101}
2102
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002103void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002104{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002105 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002106 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002107}
2108
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002109void Context::getTexLevelParameterivRobust(TextureTarget target,
2110 GLint level,
2111 GLenum pname,
2112 GLsizei bufSize,
2113 GLsizei *length,
2114 GLint *params)
2115{
2116 UNIMPLEMENTED();
2117}
2118
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002119void Context::getTexLevelParameterfv(TextureTarget target,
2120 GLint level,
2121 GLenum pname,
2122 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002123{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002124 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002125 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002126}
2127
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002128void Context::getTexLevelParameterfvRobust(TextureTarget target,
2129 GLint level,
2130 GLenum pname,
2131 GLsizei bufSize,
2132 GLsizei *length,
2133 GLfloat *params)
2134{
2135 UNIMPLEMENTED();
2136}
2137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002138void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002139{
Till Rathmannb8543632018-10-02 19:46:14 +02002140 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002141 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002142 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002143}
2144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002145void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002146{
Till Rathmannb8543632018-10-02 19:46:14 +02002147 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002148 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002149 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002150}
2151
Brandon Jones59770802018-04-02 13:18:42 -07002152void Context::texParameterfvRobust(TextureType target,
2153 GLenum pname,
2154 GLsizei bufSize,
2155 const GLfloat *params)
2156{
2157 texParameterfv(target, pname, params);
2158}
2159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002160void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002161{
Till Rathmannb8543632018-10-02 19:46:14 +02002162 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002163 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002164 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002165}
2166
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002167void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002168{
Till Rathmannb8543632018-10-02 19:46:14 +02002169 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002170 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002171 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002172}
2173
Till Rathmannb8543632018-10-02 19:46:14 +02002174void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2175{
2176 Texture *const texture = getTargetTexture(target);
2177 SetTexParameterIiv(this, texture, pname, params);
2178 onTextureChange(texture);
2179}
2180
2181void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2182{
2183 Texture *const texture = getTargetTexture(target);
2184 SetTexParameterIuiv(this, texture, pname, params);
2185 onTextureChange(texture);
2186}
2187
Brandon Jones59770802018-04-02 13:18:42 -07002188void Context::texParameterivRobust(TextureType target,
2189 GLenum pname,
2190 GLsizei bufSize,
2191 const GLint *params)
2192{
2193 texParameteriv(target, pname, params);
2194}
2195
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002196void Context::texParameterIivRobust(TextureType target,
2197 GLenum pname,
2198 GLsizei bufSize,
2199 const GLint *params)
2200{
2201 UNIMPLEMENTED();
2202}
2203
2204void Context::texParameterIuivRobust(TextureType target,
2205 GLenum pname,
2206 GLsizei bufSize,
2207 const GLuint *params)
2208{
2209 UNIMPLEMENTED();
2210}
2211
Jamie Madill493f9572018-05-24 19:52:15 -04002212void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002213{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002214 // No-op if count draws no primitives for given mode
2215 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002216 {
2217 return;
2218 }
2219
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002220 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002221 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002222 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223}
2224
Jamie Madill493f9572018-05-24 19:52:15 -04002225void Context::drawArraysInstanced(PrimitiveMode mode,
2226 GLint first,
2227 GLsizei count,
2228 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002229{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002230 // No-op if count draws no primitives for given mode
2231 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002232 {
2233 return;
2234 }
2235
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002236 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002237 ANGLE_CONTEXT_TRY(
2238 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002239 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2240 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002241}
2242
Jamie Madill8dc27f92018-11-29 11:45:44 -05002243void Context::drawElements(PrimitiveMode mode,
2244 GLsizei count,
2245 DrawElementsType type,
2246 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002247{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002248 // No-op if count draws no primitives for given mode
2249 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002250 {
2251 return;
2252 }
2253
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002254 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002255 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002256}
2257
Jamie Madill493f9572018-05-24 19:52:15 -04002258void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002259 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002260 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002261 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002262 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002263{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002264 // No-op if count draws no primitives for given mode
2265 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002266 {
2267 return;
2268 }
2269
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002270 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002271 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002272 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002273}
2274
Jamie Madill493f9572018-05-24 19:52:15 -04002275void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002276 GLuint start,
2277 GLuint end,
2278 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002279 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002280 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002281{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002282 // No-op if count draws no primitives for given mode
2283 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002284 {
2285 return;
2286 }
2287
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002288 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002289 ANGLE_CONTEXT_TRY(
2290 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002291}
2292
Jamie Madill493f9572018-05-24 19:52:15 -04002293void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002294{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002295 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002296 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002297}
2298
Jamie Madill8dc27f92018-11-29 11:45:44 -05002299void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002300{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002301 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002302 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002303}
2304
Jamie Madill675fe712016-12-19 13:07:54 -05002305void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002306{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002307 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002308}
2309
Jamie Madill675fe712016-12-19 13:07:54 -05002310void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002311{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002312 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002313}
2314
Austin Kinross6ee1e782015-05-29 17:05:37 -07002315void Context::insertEventMarker(GLsizei length, const char *marker)
2316{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002317 ASSERT(mImplementation);
2318 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002319}
2320
2321void Context::pushGroupMarker(GLsizei length, const char *marker)
2322{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002323 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002324
2325 if (marker == nullptr)
2326 {
2327 // From the EXT_debug_marker spec,
2328 // "If <marker> is null then an empty string is pushed on the stack."
2329 mImplementation->pushGroupMarker(length, "");
2330 }
2331 else
2332 {
2333 mImplementation->pushGroupMarker(length, marker);
2334 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002335}
2336
2337void Context::popGroupMarker()
2338{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002339 ASSERT(mImplementation);
2340 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002341}
2342
Geoff Langd8605522016-04-13 10:19:12 -04002343void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2344{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002345 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002346 ASSERT(programObject);
2347
2348 programObject->bindUniformLocation(location, name);
2349}
2350
Brandon Jones59770802018-04-02 13:18:42 -07002351void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002352{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002353 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002354}
2355
Brandon Jones59770802018-04-02 13:18:42 -07002356void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357{
2358 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2359}
2360
Brandon Jones59770802018-04-02 13:18:42 -07002361void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002362{
2363 GLfloat I[16];
2364 angle::Matrix<GLfloat>::setToIdentity(I);
2365
2366 mGLState.loadPathRenderingMatrix(matrixMode, I);
2367}
2368
2369void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2370{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002371 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002372 if (!pathObj)
2373 return;
2374
Geoff Lang9bf86f02018-07-26 11:46:34 -04002375 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002376
2377 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2378}
2379
2380void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2381{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002382 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002383 if (!pathObj)
2384 return;
2385
Geoff Lang9bf86f02018-07-26 11:46:34 -04002386 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002387
2388 mImplementation->stencilStrokePath(pathObj, reference, mask);
2389}
2390
2391void Context::coverFillPath(GLuint path, GLenum coverMode)
2392{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002393 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002394 if (!pathObj)
2395 return;
2396
Geoff Lang9bf86f02018-07-26 11:46:34 -04002397 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002398
2399 mImplementation->coverFillPath(pathObj, coverMode);
2400}
2401
2402void Context::coverStrokePath(GLuint path, GLenum coverMode)
2403{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002404 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002405 if (!pathObj)
2406 return;
2407
Geoff Lang9bf86f02018-07-26 11:46:34 -04002408 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002409
2410 mImplementation->coverStrokePath(pathObj, coverMode);
2411}
2412
2413void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2414{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002415 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002416 if (!pathObj)
2417 return;
2418
Geoff Lang9bf86f02018-07-26 11:46:34 -04002419 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002420
2421 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2422}
2423
2424void Context::stencilThenCoverStrokePath(GLuint path,
2425 GLint reference,
2426 GLuint mask,
2427 GLenum coverMode)
2428{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002429 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002430 if (!pathObj)
2431 return;
2432
Geoff Lang9bf86f02018-07-26 11:46:34 -04002433 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002434
2435 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2436}
2437
Sami Väisänend59ca052016-06-21 16:10:00 +03002438void Context::coverFillPathInstanced(GLsizei numPaths,
2439 GLenum pathNameType,
2440 const void *paths,
2441 GLuint pathBase,
2442 GLenum coverMode,
2443 GLenum transformType,
2444 const GLfloat *transformValues)
2445{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002446 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
Geoff Lang9bf86f02018-07-26 11:46:34 -04002448 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002449
2450 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2451}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002452
Sami Väisänend59ca052016-06-21 16:10:00 +03002453void Context::coverStrokePathInstanced(GLsizei numPaths,
2454 GLenum pathNameType,
2455 const void *paths,
2456 GLuint pathBase,
2457 GLenum coverMode,
2458 GLenum transformType,
2459 const GLfloat *transformValues)
2460{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002462
2463 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002464 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
2466 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2467 transformValues);
2468}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002469
Sami Väisänend59ca052016-06-21 16:10:00 +03002470void Context::stencilFillPathInstanced(GLsizei numPaths,
2471 GLenum pathNameType,
2472 const void *paths,
2473 GLuint pathBase,
2474 GLenum fillMode,
2475 GLuint mask,
2476 GLenum transformType,
2477 const GLfloat *transformValues)
2478{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002479 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002480
2481 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002482 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002483
2484 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2485 transformValues);
2486}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002487
Sami Väisänend59ca052016-06-21 16:10:00 +03002488void Context::stencilStrokePathInstanced(GLsizei numPaths,
2489 GLenum pathNameType,
2490 const void *paths,
2491 GLuint pathBase,
2492 GLint reference,
2493 GLuint mask,
2494 GLenum transformType,
2495 const GLfloat *transformValues)
2496{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002497 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002498
Geoff Lang9bf86f02018-07-26 11:46:34 -04002499 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002500
2501 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2502 transformValues);
2503}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002504
Sami Väisänend59ca052016-06-21 16:10:00 +03002505void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2506 GLenum pathNameType,
2507 const void *paths,
2508 GLuint pathBase,
2509 GLenum fillMode,
2510 GLuint mask,
2511 GLenum coverMode,
2512 GLenum transformType,
2513 const GLfloat *transformValues)
2514{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002515 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002516
Geoff Lang9bf86f02018-07-26 11:46:34 -04002517 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002518
2519 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2520 transformType, transformValues);
2521}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002522
Sami Väisänend59ca052016-06-21 16:10:00 +03002523void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2524 GLenum pathNameType,
2525 const void *paths,
2526 GLuint pathBase,
2527 GLint reference,
2528 GLuint mask,
2529 GLenum coverMode,
2530 GLenum transformType,
2531 const GLfloat *transformValues)
2532{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002533 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002534
Geoff Lang9bf86f02018-07-26 11:46:34 -04002535 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002536
2537 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2538 transformType, transformValues);
2539}
2540
Sami Väisänen46eaa942016-06-29 10:26:37 +03002541void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2542{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002543 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002544
2545 programObject->bindFragmentInputLocation(location, name);
2546}
2547
2548void Context::programPathFragmentInputGen(GLuint program,
2549 GLint location,
2550 GLenum genMode,
2551 GLint components,
2552 const GLfloat *coeffs)
2553{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002554 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002555
jchen103fd614d2018-08-13 12:21:58 +08002556 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002557}
2558
jchen1015015f72017-03-16 13:54:21 +08002559GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2560{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002561 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002562 return QueryProgramResourceIndex(programObject, programInterface, name);
2563}
2564
jchen10fd7c3b52017-03-21 15:36:03 +08002565void Context::getProgramResourceName(GLuint program,
2566 GLenum programInterface,
2567 GLuint index,
2568 GLsizei bufSize,
2569 GLsizei *length,
2570 GLchar *name)
2571{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002572 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002573 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2574}
2575
jchen10191381f2017-04-11 13:59:04 +08002576GLint Context::getProgramResourceLocation(GLuint program,
2577 GLenum programInterface,
2578 const GLchar *name)
2579{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002580 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002581 return QueryProgramResourceLocation(programObject, programInterface, name);
2582}
2583
jchen10880683b2017-04-12 16:21:55 +08002584void Context::getProgramResourceiv(GLuint program,
2585 GLenum programInterface,
2586 GLuint index,
2587 GLsizei propCount,
2588 const GLenum *props,
2589 GLsizei bufSize,
2590 GLsizei *length,
2591 GLint *params)
2592{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002593 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002594 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2595 length, params);
2596}
2597
jchen10d9cd7b72017-08-30 15:04:25 +08002598void Context::getProgramInterfaceiv(GLuint program,
2599 GLenum programInterface,
2600 GLenum pname,
2601 GLint *params)
2602{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002603 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002604 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2605}
2606
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002607void Context::getProgramInterfaceivRobust(GLuint program,
2608 GLenum programInterface,
2609 GLenum pname,
2610 GLsizei bufSize,
2611 GLsizei *length,
2612 GLint *params)
2613{
2614 UNIMPLEMENTED();
2615}
2616
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002617void Context::handleError(GLenum errorCode,
2618 const char *message,
2619 const char *file,
2620 const char *function,
2621 unsigned int line)
2622{
2623 mErrors.handleError(errorCode, message, file, function, line);
2624}
2625
Jamie Madilla139f012018-10-10 16:13:03 -04002626void Context::validationError(GLenum errorCode, const char *message)
2627{
2628 mErrors.validationError(errorCode, message);
2629}
2630
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002631// Get one of the recorded errors and clear its flag, if any.
2632// [OpenGL ES 2.0.24] section 2.5 page 13.
2633GLenum Context::getError()
2634{
Geoff Langda5777c2014-07-11 09:52:58 -04002635 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002636 {
Geoff Langda5777c2014-07-11 09:52:58 -04002637 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638 }
Geoff Langda5777c2014-07-11 09:52:58 -04002639 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002640 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002641 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643}
2644
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002645// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002646void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647{
2648 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002649 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002650 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002651 mContextLostForced = true;
2652 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002653 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002654}
2655
Jamie Madillfa920eb2018-01-04 11:45:50 -05002656GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002657{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002658 // Even if the application doesn't want to know about resets, we want to know
2659 // as it will allow us to skip all the calls.
2660 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002663 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002664 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002665 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666
2667 // EXT_robustness, section 2.6: If the reset notification behavior is
2668 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2669 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2670 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671 }
2672
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002673 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2674 // status should be returned at least once, and GL_NO_ERROR should be returned
2675 // once the device has finished resetting.
2676 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002677 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002678 ASSERT(mResetStatus == GL_NO_ERROR);
2679 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002680
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002681 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002682 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684 }
2685 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002686 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002687 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002688 // If markContextLost was used to mark the context lost then
2689 // assume that is not recoverable, and continue to report the
2690 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002691 mResetStatus = mImplementation->getResetStatus();
2692 }
Jamie Madill893ab082014-05-16 16:56:10 -04002693
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002694 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002695}
2696
2697bool Context::isResetNotificationEnabled()
2698{
2699 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2700}
2701
Corentin Walleze3b10e82015-05-20 11:06:25 -04002702const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002703{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002704 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002705}
2706
2707EGLenum Context::getClientType() const
2708{
2709 return mClientType;
2710}
2711
2712EGLenum Context::getRenderBuffer() const
2713{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002714 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2715 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002716 {
2717 return EGL_NONE;
2718 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002719
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002720 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002721 ASSERT(backAttachment != nullptr);
2722 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002723}
2724
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002726{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002727 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002728 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2729 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002730 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002731 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2732 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002733
Jamie Madill96a483b2017-06-27 16:49:21 -04002734 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002735 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002736
2737 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002738}
2739
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002740TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002741{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002742 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002743 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2744 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002745 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002746 transformFeedback =
2747 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002748 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002749 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002750 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002751
2752 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002753}
2754
2755bool Context::isVertexArrayGenerated(GLuint vertexArray)
2756{
Jamie Madill96a483b2017-06-27 16:49:21 -04002757 ASSERT(mVertexArrayMap.contains(0));
2758 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002759}
2760
2761bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2762{
Jamie Madill96a483b2017-06-27 16:49:21 -04002763 ASSERT(mTransformFeedbackMap.contains(0));
2764 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002765}
2766
Shannon Woods53a94a82014-06-24 15:20:36 -04002767void Context::detachTexture(GLuint texture)
2768{
2769 // Simple pass-through to State's detachTexture method, as textures do not require
2770 // allocation map management either here or in the resource manager at detach time.
2771 // Zero textures are held by the Context, and we don't attempt to request them from
2772 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002773 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002774}
2775
James Darpinian4d9d4832018-03-13 12:43:28 -07002776void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002777{
Yuly Novikov5807a532015-12-03 13:01:22 -05002778 // Simple pass-through to State's detachBuffer method, since
2779 // only buffer attachments to container objects that are bound to the current context
2780 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002781
Yuly Novikov5807a532015-12-03 13:01:22 -05002782 // [OpenGL ES 3.2] section 5.1.2 page 45:
2783 // Attachments to unbound container objects, such as
2784 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2785 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002786 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002787}
2788
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002789void Context::detachFramebuffer(GLuint framebuffer)
2790{
Shannon Woods53a94a82014-06-24 15:20:36 -04002791 // Framebuffer detachment is handled by Context, because 0 is a valid
2792 // Framebuffer object, and a pointer to it must be passed from Context
2793 // to State at binding time.
2794
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002795 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002796 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2797 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2798 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002799
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002800 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801 {
2802 bindReadFramebuffer(0);
2803 }
2804
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002805 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002806 {
2807 bindDrawFramebuffer(0);
2808 }
2809}
2810
2811void Context::detachRenderbuffer(GLuint renderbuffer)
2812{
Jamie Madilla02315b2017-02-23 14:14:47 -05002813 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002814}
2815
Jamie Madill57a89722013-07-02 11:57:03 -04002816void Context::detachVertexArray(GLuint vertexArray)
2817{
Jamie Madill77a72f62015-04-14 11:18:32 -04002818 // Vertex array detachment is handled by Context, because 0 is a valid
2819 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002820 // binding time.
2821
Jamie Madill57a89722013-07-02 11:57:03 -04002822 // [OpenGL ES 3.0.2] section 2.10 page 43:
2823 // If a vertex array object that is currently bound is deleted, the binding
2824 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002825 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002826 {
2827 bindVertexArray(0);
2828 }
2829}
2830
Geoff Langc8058452014-02-03 12:04:11 -05002831void Context::detachTransformFeedback(GLuint transformFeedback)
2832{
Corentin Walleza2257da2016-04-19 16:43:12 -04002833 // Transform feedback detachment is handled by Context, because 0 is a valid
2834 // transform feedback, and a pointer to it must be passed from Context to State at
2835 // binding time.
2836
2837 // The OpenGL specification doesn't mention what should happen when the currently bound
2838 // transform feedback object is deleted. Since it is a container object, we treat it like
2839 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002840 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002841 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002842 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002843 }
Geoff Langc8058452014-02-03 12:04:11 -05002844}
2845
Jamie Madilldc356042013-07-19 16:36:57 -04002846void Context::detachSampler(GLuint sampler)
2847{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002848 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002849}
2850
Yunchao Hea336b902017-08-02 16:05:21 +08002851void Context::detachProgramPipeline(GLuint pipeline)
2852{
2853 mGLState.detachProgramPipeline(this, pipeline);
2854}
2855
Jamie Madill3ef140a2017-08-26 23:11:21 -04002856void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002857{
Shaodde78e82017-05-22 14:13:27 +08002858 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002859 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002860}
2861
Jamie Madille29d1672013-07-19 16:36:57 -04002862void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2863{
Till Rathmannb8543632018-10-02 19:46:14 +02002864 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002865 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002866 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002867}
Jamie Madille29d1672013-07-19 16:36:57 -04002868
Geoff Langc1984ed2016-10-07 12:41:00 -04002869void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2870{
Till Rathmannb8543632018-10-02 19:46:14 +02002871 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002872 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002873 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002874}
2875
Till Rathmannb8543632018-10-02 19:46:14 +02002876void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2877{
2878 Sampler *const samplerObject =
2879 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2880 SetSamplerParameterIiv(this, samplerObject, pname, param);
2881}
2882
2883void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2884{
2885 Sampler *const samplerObject =
2886 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2887 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2888}
2889
Brandon Jones59770802018-04-02 13:18:42 -07002890void Context::samplerParameterivRobust(GLuint sampler,
2891 GLenum pname,
2892 GLsizei bufSize,
2893 const GLint *param)
2894{
2895 samplerParameteriv(sampler, pname, param);
2896}
2897
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002898void Context::samplerParameterIivRobust(GLuint sampler,
2899 GLenum pname,
2900 GLsizei bufSize,
2901 const GLint *param)
2902{
2903 UNIMPLEMENTED();
2904}
2905
2906void Context::samplerParameterIuivRobust(GLuint sampler,
2907 GLenum pname,
2908 GLsizei bufSize,
2909 const GLuint *param)
2910{
2911 UNIMPLEMENTED();
2912}
2913
Jamie Madille29d1672013-07-19 16:36:57 -04002914void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2915{
Till Rathmannb8543632018-10-02 19:46:14 +02002916 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002917 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002918 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002919}
2920
Geoff Langc1984ed2016-10-07 12:41:00 -04002921void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002922{
Till Rathmannb8543632018-10-02 19:46:14 +02002923 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002924 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002925 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002926}
2927
Brandon Jones59770802018-04-02 13:18:42 -07002928void Context::samplerParameterfvRobust(GLuint sampler,
2929 GLenum pname,
2930 GLsizei bufSize,
2931 const GLfloat *param)
2932{
2933 samplerParameterfv(sampler, pname, param);
2934}
2935
Geoff Langc1984ed2016-10-07 12:41:00 -04002936void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002937{
Till Rathmannb8543632018-10-02 19:46:14 +02002938 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002939 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002940 QuerySamplerParameteriv(samplerObject, pname, params);
2941}
Jamie Madill9675b802013-07-19 16:36:59 -04002942
Till Rathmannb8543632018-10-02 19:46:14 +02002943void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2944{
2945 const Sampler *const samplerObject =
2946 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2947 QuerySamplerParameterIiv(samplerObject, pname, params);
2948}
2949
2950void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2951{
2952 const Sampler *const samplerObject =
2953 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2954 QuerySamplerParameterIuiv(samplerObject, pname, params);
2955}
2956
Brandon Jones59770802018-04-02 13:18:42 -07002957void Context::getSamplerParameterivRobust(GLuint sampler,
2958 GLenum pname,
2959 GLsizei bufSize,
2960 GLsizei *length,
2961 GLint *params)
2962{
2963 getSamplerParameteriv(sampler, pname, params);
2964}
2965
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002966void Context::getSamplerParameterIivRobust(GLuint sampler,
2967 GLenum pname,
2968 GLsizei bufSize,
2969 GLsizei *length,
2970 GLint *params)
2971{
2972 UNIMPLEMENTED();
2973}
2974
2975void Context::getSamplerParameterIuivRobust(GLuint sampler,
2976 GLenum pname,
2977 GLsizei bufSize,
2978 GLsizei *length,
2979 GLuint *params)
2980{
2981 UNIMPLEMENTED();
2982}
2983
Geoff Langc1984ed2016-10-07 12:41:00 -04002984void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2985{
Till Rathmannb8543632018-10-02 19:46:14 +02002986 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002987 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002988 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002989}
2990
Brandon Jones59770802018-04-02 13:18:42 -07002991void Context::getSamplerParameterfvRobust(GLuint sampler,
2992 GLenum pname,
2993 GLsizei bufSize,
2994 GLsizei *length,
2995 GLfloat *params)
2996{
2997 getSamplerParameterfv(sampler, pname, params);
2998}
2999
Olli Etuahof0fee072016-03-30 15:11:58 +03003000void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3001{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003002 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003003 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003004}
3005
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003006void Context::initRendererString()
3007{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003008 std::ostringstream rendererString;
3009 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003010 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003011 rendererString << ")";
3012
Geoff Langcec35902014-04-16 10:52:36 -04003013 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003014}
3015
Geoff Langc339c4e2016-11-29 10:37:36 -05003016void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003017{
Geoff Langc339c4e2016-11-29 10:37:36 -05003018 const Version &clientVersion = getClientVersion();
3019
3020 std::ostringstream versionString;
3021 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3022 << ANGLE_VERSION_STRING << ")";
3023 mVersionString = MakeStaticString(versionString.str());
3024
3025 std::ostringstream shadingLanguageVersionString;
3026 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3027 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3028 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3029 << ")";
3030 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003031}
3032
Geoff Langcec35902014-04-16 10:52:36 -04003033void Context::initExtensionStrings()
3034{
Geoff Langc339c4e2016-11-29 10:37:36 -05003035 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3036 std::ostringstream combinedStringStream;
3037 std::copy(strings.begin(), strings.end(),
3038 std::ostream_iterator<const char *>(combinedStringStream, " "));
3039 return MakeStaticString(combinedStringStream.str());
3040 };
3041
3042 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003043 for (const auto &extensionString : mExtensions.getStrings())
3044 {
3045 mExtensionStrings.push_back(MakeStaticString(extensionString));
3046 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003047 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003048
Geoff Langc339c4e2016-11-29 10:37:36 -05003049 mRequestableExtensionStrings.clear();
3050 for (const auto &extensionInfo : GetExtensionInfoMap())
3051 {
3052 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003053 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003054 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003055 {
3056 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3057 }
3058 }
3059 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003060}
3061
Geoff Langc339c4e2016-11-29 10:37:36 -05003062const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003063{
Geoff Langc339c4e2016-11-29 10:37:36 -05003064 switch (name)
3065 {
3066 case GL_VENDOR:
3067 return reinterpret_cast<const GLubyte *>("Google Inc.");
3068
3069 case GL_RENDERER:
3070 return reinterpret_cast<const GLubyte *>(mRendererString);
3071
3072 case GL_VERSION:
3073 return reinterpret_cast<const GLubyte *>(mVersionString);
3074
3075 case GL_SHADING_LANGUAGE_VERSION:
3076 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3077
3078 case GL_EXTENSIONS:
3079 return reinterpret_cast<const GLubyte *>(mExtensionString);
3080
3081 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3082 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3083
3084 default:
3085 UNREACHABLE();
3086 return nullptr;
3087 }
Geoff Langcec35902014-04-16 10:52:36 -04003088}
3089
Geoff Langc339c4e2016-11-29 10:37:36 -05003090const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003091{
Geoff Langc339c4e2016-11-29 10:37:36 -05003092 switch (name)
3093 {
3094 case GL_EXTENSIONS:
3095 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3096
3097 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3098 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3099
3100 default:
3101 UNREACHABLE();
3102 return nullptr;
3103 }
Geoff Langcec35902014-04-16 10:52:36 -04003104}
3105
3106size_t Context::getExtensionStringCount() const
3107{
3108 return mExtensionStrings.size();
3109}
3110
Geoff Lang111a99e2017-10-17 10:58:41 -04003111bool Context::isExtensionRequestable(const char *name)
3112{
3113 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3114 auto extension = extensionInfos.find(name);
3115
Geoff Lang111a99e2017-10-17 10:58:41 -04003116 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003117 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003118}
3119
Geoff Langc339c4e2016-11-29 10:37:36 -05003120void Context::requestExtension(const char *name)
3121{
3122 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3123 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3124 const auto &extension = extensionInfos.at(name);
3125 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003126 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003127
3128 if (mExtensions.*(extension.ExtensionsMember))
3129 {
3130 // Extension already enabled
3131 return;
3132 }
3133
3134 mExtensions.*(extension.ExtensionsMember) = true;
3135 updateCaps();
3136 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003137
Jamie Madill2f348d22017-06-05 10:50:59 -04003138 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3139 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003140
Jamie Madill81c2e252017-09-09 23:32:46 -04003141 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3142 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003143 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003144 for (auto &zeroTexture : mZeroTextures)
3145 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003146 if (zeroTexture.get() != nullptr)
3147 {
3148 zeroTexture->signalDirty(this, InitState::Initialized);
3149 }
Geoff Lang9aded172017-04-05 11:07:56 -04003150 }
3151
Jamie Madillb983a4b2018-08-01 11:34:51 -04003152 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003153}
3154
3155size_t Context::getRequestableExtensionStringCount() const
3156{
3157 return mRequestableExtensionStrings.size();
3158}
3159
Jamie Madill493f9572018-05-24 19:52:15 -04003160void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003161{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003162 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003163 ASSERT(transformFeedback != nullptr);
3164 ASSERT(!transformFeedback->isPaused());
3165
Jamie Madill6c1f6712017-02-14 19:08:04 -05003166 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003167 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003168}
3169
3170bool Context::hasActiveTransformFeedback(GLuint program) const
3171{
3172 for (auto pair : mTransformFeedbackMap)
3173 {
3174 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3175 {
3176 return true;
3177 }
3178 }
3179 return false;
3180}
3181
Geoff Lang33f11fb2018-05-07 13:42:47 -04003182Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003183{
3184 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3185
jchen1082af6202018-06-22 10:59:52 +08003186 // Explicitly enable GL_KHR_parallel_shader_compile
3187 supportedExtensions.parallelShaderCompile = true;
3188
Geoff Langb0f917f2017-12-05 13:41:54 -05003189 if (getClientVersion() < ES_2_0)
3190 {
3191 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003192 supportedExtensions.pointSizeArray = true;
3193 supportedExtensions.textureCubeMap = true;
3194 supportedExtensions.pointSprite = true;
3195 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003196 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003197 }
3198
3199 if (getClientVersion() < ES_3_0)
3200 {
3201 // Disable ES3+ extensions
3202 supportedExtensions.colorBufferFloat = false;
3203 supportedExtensions.eglImageExternalEssl3 = false;
3204 supportedExtensions.textureNorm16 = false;
3205 supportedExtensions.multiview = false;
3206 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003207 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003208 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003209
3210 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3211 if (!supportedExtensions.sRGB)
3212 {
3213 supportedExtensions.textureSRGBDecode = false;
3214 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003215 }
3216
3217 if (getClientVersion() < ES_3_1)
3218 {
3219 // Disable ES3.1+ extensions
3220 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003221
3222 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3223 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003224 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003225 }
3226
3227 if (getClientVersion() > ES_2_0)
3228 {
3229 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3230 // supportedExtensions.sRGB = false;
3231 }
3232
3233 // Some extensions are always available because they are implemented in the GL layer.
3234 supportedExtensions.bindUniformLocation = true;
3235 supportedExtensions.vertexArrayObject = true;
3236 supportedExtensions.bindGeneratesResource = true;
3237 supportedExtensions.clientArrays = true;
3238 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003239 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003240
3241 // Enable the no error extension if the context was created with the flag.
3242 supportedExtensions.noError = mSkipValidation;
3243
3244 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003245 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003246
3247 // Explicitly enable GL_KHR_debug
3248 supportedExtensions.debug = true;
3249 supportedExtensions.maxDebugMessageLength = 1024;
3250 supportedExtensions.maxDebugLoggedMessages = 1024;
3251 supportedExtensions.maxDebugGroupStackDepth = 1024;
3252 supportedExtensions.maxLabelLength = 1024;
3253
3254 // Explicitly enable GL_ANGLE_robust_client_memory
3255 supportedExtensions.robustClientMemory = true;
3256
3257 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003258 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003259
3260 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3261 // supports it.
3262 supportedExtensions.robustBufferAccessBehavior =
3263 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3264
3265 // Enable the cache control query unconditionally.
3266 supportedExtensions.programCacheControl = true;
3267
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003268 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003269 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003270 {
3271 // GL_ANGLE_explicit_context_gles1
3272 supportedExtensions.explicitContextGles1 = true;
3273 // GL_ANGLE_explicit_context
3274 supportedExtensions.explicitContext = true;
3275 }
3276
Geoff Lang79b91402018-10-04 15:11:30 -04003277 supportedExtensions.memorySize = true;
3278
Geoff Langb0f917f2017-12-05 13:41:54 -05003279 return supportedExtensions;
3280}
3281
Geoff Lang33f11fb2018-05-07 13:42:47 -04003282void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003283{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003284 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003285
Geoff Lang33f11fb2018-05-07 13:42:47 -04003286 mSupportedExtensions = generateSupportedExtensions();
3287 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003288
3289 mLimitations = mImplementation->getNativeLimitations();
3290
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003291 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3292 if (getClientVersion() < Version(2, 0))
3293 {
3294 mCaps.maxMultitextureUnits = 4;
3295 mCaps.maxClipPlanes = 6;
3296 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003297 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3298 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3299 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003300 mCaps.minSmoothPointSize = 1.0f;
3301 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003302 mCaps.minSmoothLineWidth = 1.0f;
3303 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003304 }
3305
Luc Ferronad2ae932018-06-11 15:31:17 -04003306 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003307 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003308
Luc Ferronad2ae932018-06-11 15:31:17 -04003309 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3310
Jamie Madill0f80ed82017-09-19 00:24:56 -04003311 if (getClientVersion() < ES_3_1)
3312 {
3313 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3314 }
3315 else
3316 {
3317 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3318 }
Geoff Lang301d1612014-07-09 10:34:37 -04003319
Jiawei Shao54aafe52018-04-27 14:54:57 +08003320 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3321 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003322 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3323
Jamie Madill0f80ed82017-09-19 00:24:56 -04003324 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3325 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3326
3327 // Limit textures as well, so we can use fast bitsets with texture bindings.
3328 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003329 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3330 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3331 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3332 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003333
Jiawei Shaodb342272017-09-27 10:21:45 +08003334 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3335
Geoff Langc287ea62016-09-16 14:46:51 -04003336 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003337 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003338 for (const auto &extensionInfo : GetExtensionInfoMap())
3339 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003340 // If the user has requested that extensions start disabled and they are requestable,
3341 // disable them.
3342 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003343 {
3344 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3345 }
3346 }
3347
3348 // Generate texture caps
3349 updateCaps();
3350}
3351
3352void Context::updateCaps()
3353{
Geoff Lang900013c2014-07-07 11:32:19 -04003354 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003355 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003356
Jamie Madill7b62cf92017-11-02 15:20:49 -04003357 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003358 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003359 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003360 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003361
Geoff Lang0d8b7242015-09-09 14:56:53 -04003362 // Update the format caps based on the client version and extensions.
3363 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3364 // ES3.
3365 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003366 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003367 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003368 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003369 formatCaps.textureAttachment =
3370 formatCaps.textureAttachment &&
3371 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3372 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3373 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003374
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003375 // OpenGL ES does not support multisampling with non-rendererable formats
3376 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003377 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003378 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003379 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003380 {
Geoff Langd87878e2014-09-19 15:42:59 -04003381 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003382 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003383 else
3384 {
3385 // We may have limited the max samples for some required renderbuffer formats due to
3386 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3387 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3388
3389 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3390 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3391 // exception of signed and unsigned integer formats."
3392 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3393 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3394 {
3395 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3396 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3397 }
3398
3399 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003400 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003401 {
3402 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3403 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3404 // the exception that the signed and unsigned integer formats are required only to
3405 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3406 // multisamples, which must be at least one."
3407 if (formatInfo.componentType == GL_INT ||
3408 formatInfo.componentType == GL_UNSIGNED_INT)
3409 {
3410 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3411 }
3412
3413 // GLES 3.1 section 19.3.1.
3414 if (formatCaps.texturable)
3415 {
3416 if (formatInfo.depthBits > 0)
3417 {
3418 mCaps.maxDepthTextureSamples =
3419 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3420 }
3421 else if (formatInfo.redBits > 0)
3422 {
3423 mCaps.maxColorTextureSamples =
3424 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3425 }
3426 }
3427 }
3428 }
Geoff Langd87878e2014-09-19 15:42:59 -04003429
3430 if (formatCaps.texturable && formatInfo.compressed)
3431 {
Geoff Langca271392017-04-05 12:30:00 -04003432 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003433 }
3434
Geoff Langca271392017-04-05 12:30:00 -04003435 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003436 }
Jamie Madill32447362017-06-28 14:53:52 -04003437
3438 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003439 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003440 {
3441 mMemoryProgramCache = nullptr;
3442 }
Corentin Walleze4477002017-12-01 14:39:58 -05003443
3444 // Compute which buffer types are allowed
3445 mValidBufferBindings.reset();
3446 mValidBufferBindings.set(BufferBinding::ElementArray);
3447 mValidBufferBindings.set(BufferBinding::Array);
3448
3449 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3450 {
3451 mValidBufferBindings.set(BufferBinding::PixelPack);
3452 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3453 }
3454
3455 if (getClientVersion() >= ES_3_0)
3456 {
3457 mValidBufferBindings.set(BufferBinding::CopyRead);
3458 mValidBufferBindings.set(BufferBinding::CopyWrite);
3459 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3460 mValidBufferBindings.set(BufferBinding::Uniform);
3461 }
3462
3463 if (getClientVersion() >= ES_3_1)
3464 {
3465 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3466 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3467 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3468 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3469 }
jchen107ae70d82018-07-06 13:47:01 +08003470
3471 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003472
Jamie Madillef9fcd92018-11-28 14:03:59 -05003473 // Reinitialize some dirty bits that depend on extensions.
3474 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS,
3475 mGLState.isRobustResourceInitEnabled());
3476 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS,
3477 mGLState.isRobustResourceInitEnabled());
3478
Jamie Madillac66f982018-10-09 18:30:01 -04003479 // Reinitialize state cache after extension changes.
3480 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003481}
3482
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003483void Context::initWorkarounds()
3484{
Jamie Madill761b02c2017-06-23 16:27:06 -04003485 // Apply back-end workarounds.
3486 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3487
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003488 // Lose the context upon out of memory error if the application is
3489 // expecting to watch for those events.
3490 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003491
3492 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3493 {
3494 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3495 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3496 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3497 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003498}
3499
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003500// Return true if the draw is a no-op, else return false.
3501// A no-op draw occurs if the count of vertices is less than the minimum required to
3502// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3503bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3504{
3505 return count < kMinimumPrimitiveCounts[mode];
3506}
3507
3508bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3509{
3510 return (instanceCount == 0) || noopDraw(mode, count);
3511}
3512
Jamie Madill6f755b22018-10-09 12:48:54 -04003513angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003514{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003515 if (mGLES1Renderer)
3516 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003517 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003518 }
3519
Geoff Lang9bf86f02018-07-26 11:46:34 -04003520 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003521
3522 if (isRobustResourceInitEnabled())
3523 {
3524 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
Jamie Madillef9fcd92018-11-28 14:03:59 -05003525 ASSERT(!mGLState.getDrawFramebuffer()->hasResourceThatNeedsInit());
Jamie Madilla59fc192017-11-02 12:57:58 -04003526 }
3527
Jamie Madill9e63a812018-11-16 12:30:04 +00003528 ANGLE_TRY(syncDirtyBits());
3529 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003530}
3531
Jamie Madill526392d2018-11-16 09:35:14 -05003532angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003533{
Geoff Langa8cb2872018-03-09 16:09:40 -05003534 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003535 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003536 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003537 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003538}
3539
Jamie Madill526392d2018-11-16 09:35:14 -05003540angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003541{
Geoff Langa8cb2872018-03-09 16:09:40 -05003542 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003543 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3544 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003545 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003546 return angle::Result::Continue();
Jamie Madill05b35b22017-10-03 09:01:44 -04003547}
3548
Jamie Madill526392d2018-11-16 09:35:14 -05003549angle::Result Context::syncState(const State::DirtyBits &bitMask,
3550 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003551{
Geoff Langa8cb2872018-03-09 16:09:40 -05003552 ANGLE_TRY(syncDirtyObjects(objectMask));
3553 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill526392d2018-11-16 09:35:14 -05003554 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003555}
3556
Jamie Madill9e63a812018-11-16 12:30:04 +00003557angle::Result Context::syncDirtyBits()
3558{
3559 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3560 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3561 mGLState.clearDirtyBits();
3562 return angle::Result::Continue();
3563}
3564
3565angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3566{
3567 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3568 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3569 mGLState.clearDirtyBits(dirtyBits);
3570 return angle::Result::Continue();
3571}
3572
Jamie Madillc29968b2016-01-20 11:17:23 -05003573void Context::blitFramebuffer(GLint srcX0,
3574 GLint srcY0,
3575 GLint srcX1,
3576 GLint srcY1,
3577 GLint dstX0,
3578 GLint dstY0,
3579 GLint dstX1,
3580 GLint dstY1,
3581 GLbitfield mask,
3582 GLenum filter)
3583{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003584 if (mask == 0)
3585 {
3586 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3587 // buffers are copied.
3588 return;
3589 }
3590
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 ASSERT(drawFramebuffer);
3593
3594 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3595 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3596
Jamie Madillbc918e72018-03-08 09:47:21 -05003597 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003598
Jamie Madill4f6592f2018-11-27 16:37:45 -05003599 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003600}
Jamie Madillc29968b2016-01-20 11:17:23 -05003601
3602void Context::clear(GLbitfield mask)
3603{
Geoff Langd4fff502017-09-22 11:28:28 -04003604 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3605 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003606}
3607
3608void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3609{
Olli Etuaho78df3362018-10-05 16:43:27 +03003610 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3611 const FramebufferAttachment *attachment = nullptr;
3612 if (buffer == GL_DEPTH)
3613 {
3614 attachment = framebufferObject->getDepthbuffer();
3615 }
3616 if (buffer == GL_COLOR &&
3617 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3618 {
3619 attachment = framebufferObject->getColorbuffer(drawbuffer);
3620 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003621 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3622 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003623 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003624 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003625 return;
3626 }
Geoff Langd4fff502017-09-22 11:28:28 -04003627 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003628 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003629}
3630
3631void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3632{
Olli Etuaho78df3362018-10-05 16:43:27 +03003633 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3634 const FramebufferAttachment *attachment = nullptr;
3635 if (buffer == GL_COLOR &&
3636 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3637 {
3638 attachment = framebufferObject->getColorbuffer(drawbuffer);
3639 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003640 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3641 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003642 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003643 {
3644 return;
3645 }
Geoff Langd4fff502017-09-22 11:28:28 -04003646 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003647 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003648}
3649
3650void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3651{
Olli Etuaho78df3362018-10-05 16:43:27 +03003652 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3653 const FramebufferAttachment *attachment = nullptr;
3654 if (buffer == GL_STENCIL)
3655 {
3656 attachment = framebufferObject->getStencilbuffer();
3657 }
3658 if (buffer == GL_COLOR &&
3659 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3660 {
3661 attachment = framebufferObject->getColorbuffer(drawbuffer);
3662 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003663 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3664 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003665 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003666 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003667 return;
3668 }
Geoff Langd4fff502017-09-22 11:28:28 -04003669 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003670 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003671}
3672
3673void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3674{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003675 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 ASSERT(framebufferObject);
3677
3678 // If a buffer is not present, the clear has no effect
3679 if (framebufferObject->getDepthbuffer() == nullptr &&
3680 framebufferObject->getStencilbuffer() == nullptr)
3681 {
3682 return;
3683 }
3684
Geoff Langd4fff502017-09-22 11:28:28 -04003685 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3686 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003687}
3688
3689void Context::readPixels(GLint x,
3690 GLint y,
3691 GLsizei width,
3692 GLsizei height,
3693 GLenum format,
3694 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003695 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003696{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003697 if (width == 0 || height == 0)
3698 {
3699 return;
3700 }
3701
Jamie Madillbc918e72018-03-08 09:47:21 -05003702 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003703
Jamie Madillb6664922017-07-25 12:55:04 -04003704 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3705 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706
3707 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003708 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003709}
3710
Brandon Jones59770802018-04-02 13:18:42 -07003711void Context::readPixelsRobust(GLint x,
3712 GLint y,
3713 GLsizei width,
3714 GLsizei height,
3715 GLenum format,
3716 GLenum type,
3717 GLsizei bufSize,
3718 GLsizei *length,
3719 GLsizei *columns,
3720 GLsizei *rows,
3721 void *pixels)
3722{
3723 readPixels(x, y, width, height, format, type, pixels);
3724}
3725
3726void Context::readnPixelsRobust(GLint x,
3727 GLint y,
3728 GLsizei width,
3729 GLsizei height,
3730 GLenum format,
3731 GLenum type,
3732 GLsizei bufSize,
3733 GLsizei *length,
3734 GLsizei *columns,
3735 GLsizei *rows,
3736 void *data)
3737{
3738 readPixels(x, y, width, height, format, type, data);
3739}
3740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003741void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003742 GLint level,
3743 GLenum internalformat,
3744 GLint x,
3745 GLint y,
3746 GLsizei width,
3747 GLsizei height,
3748 GLint border)
3749{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003750 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003751 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003752
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 Rectangle sourceArea(x, y, width, height);
3754
Jamie Madill05b35b22017-10-03 09:01:44 -04003755 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003756 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003757 ANGLE_CONTEXT_TRY(
3758 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003759}
3760
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003761void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003762 GLint level,
3763 GLint xoffset,
3764 GLint yoffset,
3765 GLint x,
3766 GLint y,
3767 GLsizei width,
3768 GLsizei height)
3769{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003770 if (width == 0 || height == 0)
3771 {
3772 return;
3773 }
3774
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003775 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003776 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003777
Jamie Madillc29968b2016-01-20 11:17:23 -05003778 Offset destOffset(xoffset, yoffset, 0);
3779 Rectangle sourceArea(x, y, width, height);
3780
Jamie Madill05b35b22017-10-03 09:01:44 -04003781 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003782 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003783 ANGLE_CONTEXT_TRY(
3784 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003785}
3786
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003787void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 GLint level,
3789 GLint xoffset,
3790 GLint yoffset,
3791 GLint zoffset,
3792 GLint x,
3793 GLint y,
3794 GLsizei width,
3795 GLsizei height)
3796{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003797 if (width == 0 || height == 0)
3798 {
3799 return;
3800 }
3801
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003802 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003803 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003804
Jamie Madillc29968b2016-01-20 11:17:23 -05003805 Offset destOffset(xoffset, yoffset, zoffset);
3806 Rectangle sourceArea(x, y, width, height);
3807
Jamie Madill05b35b22017-10-03 09:01:44 -04003808 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3809 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003810 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3811 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003812}
3813
3814void Context::framebufferTexture2D(GLenum target,
3815 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003816 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003817 GLuint texture,
3818 GLint level)
3819{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003821 ASSERT(framebuffer);
3822
3823 if (texture != 0)
3824 {
3825 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003826 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003827 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003828 }
3829 else
3830 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003831 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003832 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003833
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003834 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003835}
3836
3837void Context::framebufferRenderbuffer(GLenum target,
3838 GLenum attachment,
3839 GLenum renderbuffertarget,
3840 GLuint renderbuffer)
3841{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003842 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 ASSERT(framebuffer);
3844
3845 if (renderbuffer != 0)
3846 {
3847 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003848
Jamie Madillcc129372018-04-12 09:13:18 -04003849 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003850 renderbufferObject);
3851 }
3852 else
3853 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003854 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003855 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003856
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003857 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003858}
3859
3860void Context::framebufferTextureLayer(GLenum target,
3861 GLenum attachment,
3862 GLuint texture,
3863 GLint level,
3864 GLint layer)
3865{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003866 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003867 ASSERT(framebuffer);
3868
3869 if (texture != 0)
3870 {
3871 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003872 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003873 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003874 }
3875 else
3876 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003877 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003878 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003879
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003880 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003881}
3882
Brandon Jones59770802018-04-02 13:18:42 -07003883void Context::framebufferTextureMultiviewLayered(GLenum target,
3884 GLenum attachment,
3885 GLuint texture,
3886 GLint level,
3887 GLint baseViewIndex,
3888 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003889{
Martin Radev82ef7742017-08-08 17:44:58 +03003890 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3891 ASSERT(framebuffer);
3892
3893 if (texture != 0)
3894 {
3895 Texture *textureObj = getTexture(texture);
3896
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003897 ImageIndex index;
3898 if (textureObj->getType() == TextureType::_2DArray)
3899 {
3900 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3901 }
3902 else
3903 {
3904 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3905 ASSERT(level == 0);
3906 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3907 }
Martin Radev82ef7742017-08-08 17:44:58 +03003908 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3909 numViews, baseViewIndex);
3910 }
3911 else
3912 {
3913 framebuffer->resetAttachment(this, attachment);
3914 }
3915
3916 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003917}
3918
Brandon Jones59770802018-04-02 13:18:42 -07003919void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3920 GLenum attachment,
3921 GLuint texture,
3922 GLint level,
3923 GLsizei numViews,
3924 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003925{
Martin Radev5dae57b2017-07-14 16:15:55 +03003926 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3927 ASSERT(framebuffer);
3928
3929 if (texture != 0)
3930 {
3931 Texture *textureObj = getTexture(texture);
3932
3933 ImageIndex index = ImageIndex::Make2D(level);
3934 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3935 textureObj, numViews, viewportOffsets);
3936 }
3937 else
3938 {
3939 framebuffer->resetAttachment(this, attachment);
3940 }
3941
3942 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003943}
3944
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003945void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3946{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003947 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3948 ASSERT(framebuffer);
3949
3950 if (texture != 0)
3951 {
3952 Texture *textureObj = getTexture(texture);
3953
3954 ImageIndex index = ImageIndex::MakeFromType(
3955 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3956 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3957 }
3958 else
3959 {
3960 framebuffer->resetAttachment(this, attachment);
3961 }
3962
3963 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003964}
3965
Jamie Madillc29968b2016-01-20 11:17:23 -05003966void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3967{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003969 ASSERT(framebuffer);
3970 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003971 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003972 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003973}
3974
3975void Context::readBuffer(GLenum mode)
3976{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003978 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003979 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003980}
3981
3982void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3983{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003984 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003985 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003986
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003987 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003988 ASSERT(framebuffer);
3989
3990 // The specification isn't clear what should be done when the framebuffer isn't complete.
3991 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003992 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003993}
3994
3995void Context::invalidateFramebuffer(GLenum target,
3996 GLsizei numAttachments,
3997 const GLenum *attachments)
3998{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003999 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004000 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004001
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004002 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004003 ASSERT(framebuffer);
4004
Jamie Madill427064d2018-04-13 16:20:34 -04004005 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004006 {
Jamie Madill437fa652016-05-03 15:13:24 -04004007 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004008 }
Jamie Madill437fa652016-05-03 15:13:24 -04004009
Jamie Madill4f6592f2018-11-27 16:37:45 -05004010 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004011}
4012
4013void Context::invalidateSubFramebuffer(GLenum target,
4014 GLsizei numAttachments,
4015 const GLenum *attachments,
4016 GLint x,
4017 GLint y,
4018 GLsizei width,
4019 GLsizei height)
4020{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004021 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004022 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004023
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004024 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004025 ASSERT(framebuffer);
4026
Jamie Madill427064d2018-04-13 16:20:34 -04004027 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004028 {
Jamie Madill437fa652016-05-03 15:13:24 -04004029 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004030 }
Jamie Madill437fa652016-05-03 15:13:24 -04004031
4032 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004033 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004034}
4035
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004036void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004037 GLint level,
4038 GLint internalformat,
4039 GLsizei width,
4040 GLsizei height,
4041 GLint border,
4042 GLenum format,
4043 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004044 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004045{
Jamie Madillbc918e72018-03-08 09:47:21 -05004046 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004047
4048 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004049 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004050 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4051 internalformat, size, format, type,
4052 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004053}
4054
Brandon Jones59770802018-04-02 13:18:42 -07004055void Context::texImage2DRobust(TextureTarget target,
4056 GLint level,
4057 GLint internalformat,
4058 GLsizei width,
4059 GLsizei height,
4060 GLint border,
4061 GLenum format,
4062 GLenum type,
4063 GLsizei bufSize,
4064 const void *pixels)
4065{
4066 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4067}
4068
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004069void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004070 GLint level,
4071 GLint internalformat,
4072 GLsizei width,
4073 GLsizei height,
4074 GLsizei depth,
4075 GLint border,
4076 GLenum format,
4077 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004078 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004079{
Jamie Madillbc918e72018-03-08 09:47:21 -05004080 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004081
4082 Extents size(width, height, depth);
4083 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004084 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4085 NonCubeTextureTypeToTarget(target), level, internalformat,
4086 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004087}
4088
Brandon Jones59770802018-04-02 13:18:42 -07004089void Context::texImage3DRobust(TextureType target,
4090 GLint level,
4091 GLint internalformat,
4092 GLsizei width,
4093 GLsizei height,
4094 GLsizei depth,
4095 GLint border,
4096 GLenum format,
4097 GLenum type,
4098 GLsizei bufSize,
4099 const void *pixels)
4100{
4101 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4102}
4103
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004104void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004105 GLint level,
4106 GLint xoffset,
4107 GLint yoffset,
4108 GLsizei width,
4109 GLsizei height,
4110 GLenum format,
4111 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004112 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004113{
4114 // Zero sized uploads are valid but no-ops
4115 if (width == 0 || height == 0)
4116 {
4117 return;
4118 }
4119
Jamie Madillbc918e72018-03-08 09:47:21 -05004120 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004121
4122 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004123 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004124
4125 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4126
Jamie Madill4f6592f2018-11-27 16:37:45 -05004127 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4128 level, area, format, type,
4129 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::texSubImage2DRobust(TextureTarget target,
4133 GLint level,
4134 GLint xoffset,
4135 GLint yoffset,
4136 GLsizei width,
4137 GLsizei height,
4138 GLenum format,
4139 GLenum type,
4140 GLsizei bufSize,
4141 const void *pixels)
4142{
4143 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4144}
4145
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004146void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004147 GLint level,
4148 GLint xoffset,
4149 GLint yoffset,
4150 GLint zoffset,
4151 GLsizei width,
4152 GLsizei height,
4153 GLsizei depth,
4154 GLenum format,
4155 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004156 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004157{
4158 // Zero sized uploads are valid but no-ops
4159 if (width == 0 || height == 0 || depth == 0)
4160 {
4161 return;
4162 }
4163
Jamie Madillbc918e72018-03-08 09:47:21 -05004164 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004165
4166 Box area(xoffset, yoffset, zoffset, width, height, depth);
4167 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004168
4169 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4170
Jamie Madill4f6592f2018-11-27 16:37:45 -05004171 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4172 NonCubeTextureTypeToTarget(target), level, area, format,
4173 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004174}
4175
Brandon Jones59770802018-04-02 13:18:42 -07004176void Context::texSubImage3DRobust(TextureType target,
4177 GLint level,
4178 GLint xoffset,
4179 GLint yoffset,
4180 GLint zoffset,
4181 GLsizei width,
4182 GLsizei height,
4183 GLsizei depth,
4184 GLenum format,
4185 GLenum type,
4186 GLsizei bufSize,
4187 const void *pixels)
4188{
4189 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4190 pixels);
4191}
4192
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004193void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004194 GLint level,
4195 GLenum internalformat,
4196 GLsizei width,
4197 GLsizei height,
4198 GLint border,
4199 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004200 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004201{
Jamie Madillbc918e72018-03-08 09:47:21 -05004202 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004203
4204 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004205 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004206 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4207 internalformat, size, imageSize,
4208 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004209}
4210
Brandon Jones59770802018-04-02 13:18:42 -07004211void Context::compressedTexImage2DRobust(TextureTarget target,
4212 GLint level,
4213 GLenum internalformat,
4214 GLsizei width,
4215 GLsizei height,
4216 GLint border,
4217 GLsizei imageSize,
4218 GLsizei dataSize,
4219 const GLvoid *data)
4220{
4221 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4222}
4223
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004224void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004225 GLint level,
4226 GLenum internalformat,
4227 GLsizei width,
4228 GLsizei height,
4229 GLsizei depth,
4230 GLint border,
4231 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004232 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004233{
Jamie Madillbc918e72018-03-08 09:47:21 -05004234 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004235
4236 Extents size(width, height, depth);
4237 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004238 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004239 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004240 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004241}
4242
Brandon Jones59770802018-04-02 13:18:42 -07004243void Context::compressedTexImage3DRobust(TextureType target,
4244 GLint level,
4245 GLenum internalformat,
4246 GLsizei width,
4247 GLsizei height,
4248 GLsizei depth,
4249 GLint border,
4250 GLsizei imageSize,
4251 GLsizei dataSize,
4252 const GLvoid *data)
4253{
4254 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4255 data);
4256}
4257
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004258void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004259 GLint level,
4260 GLint xoffset,
4261 GLint yoffset,
4262 GLsizei width,
4263 GLsizei height,
4264 GLenum format,
4265 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004266 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004267{
Jamie Madillbc918e72018-03-08 09:47:21 -05004268 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004269
4270 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004271 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004272 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4273 area, format, imageSize,
4274 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004275}
4276
Brandon Jones59770802018-04-02 13:18:42 -07004277void Context::compressedTexSubImage2DRobust(TextureTarget target,
4278 GLint level,
4279 GLint xoffset,
4280 GLint yoffset,
4281 GLsizei width,
4282 GLsizei height,
4283 GLenum format,
4284 GLsizei imageSize,
4285 GLsizei dataSize,
4286 const GLvoid *data)
4287{
4288 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4289 data);
4290}
4291
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004292void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004293 GLint level,
4294 GLint xoffset,
4295 GLint yoffset,
4296 GLint zoffset,
4297 GLsizei width,
4298 GLsizei height,
4299 GLsizei depth,
4300 GLenum format,
4301 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004302 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004303{
4304 // Zero sized uploads are valid but no-ops
4305 if (width == 0 || height == 0)
4306 {
4307 return;
4308 }
4309
Jamie Madillbc918e72018-03-08 09:47:21 -05004310 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004311
4312 Box area(xoffset, yoffset, zoffset, width, height, depth);
4313 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004314 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004315 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004316 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004317}
4318
Brandon Jones59770802018-04-02 13:18:42 -07004319void Context::compressedTexSubImage3DRobust(TextureType target,
4320 GLint level,
4321 GLint xoffset,
4322 GLint yoffset,
4323 GLint zoffset,
4324 GLsizei width,
4325 GLsizei height,
4326 GLsizei depth,
4327 GLenum format,
4328 GLsizei imageSize,
4329 GLsizei dataSize,
4330 const GLvoid *data)
4331{
4332 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4333 imageSize, data);
4334}
4335
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004336void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004337{
4338 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004339 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004340}
4341
Jamie Madill007530e2017-12-28 14:27:04 -05004342void Context::copyTexture(GLuint sourceId,
4343 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004344 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004345 GLuint destId,
4346 GLint destLevel,
4347 GLint internalFormat,
4348 GLenum destType,
4349 GLboolean unpackFlipY,
4350 GLboolean unpackPremultiplyAlpha,
4351 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004352{
Jamie Madillbc918e72018-03-08 09:47:21 -05004353 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004354
4355 gl::Texture *sourceTexture = getTexture(sourceId);
4356 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004357 ANGLE_CONTEXT_TRY(
4358 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4359 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4360 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004361}
4362
Jamie Madill007530e2017-12-28 14:27:04 -05004363void Context::copySubTexture(GLuint sourceId,
4364 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004365 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004366 GLuint destId,
4367 GLint destLevel,
4368 GLint xoffset,
4369 GLint yoffset,
4370 GLint x,
4371 GLint y,
4372 GLsizei width,
4373 GLsizei height,
4374 GLboolean unpackFlipY,
4375 GLboolean unpackPremultiplyAlpha,
4376 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004377{
4378 // Zero sized copies are valid but no-ops
4379 if (width == 0 || height == 0)
4380 {
4381 return;
4382 }
4383
Jamie Madillbc918e72018-03-08 09:47:21 -05004384 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004385
4386 gl::Texture *sourceTexture = getTexture(sourceId);
4387 gl::Texture *destTexture = getTexture(destId);
4388 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004389 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004390 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4391 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4392 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4393 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004394}
4395
4396void Context::copyTexture3D(GLuint sourceId,
4397 GLint sourceLevel,
4398 TextureTarget destTarget,
4399 GLuint destId,
4400 GLint destLevel,
4401 GLint internalFormat,
4402 GLenum destType,
4403 GLboolean unpackFlipY,
4404 GLboolean unpackPremultiplyAlpha,
4405 GLboolean unpackUnmultiplyAlpha)
4406{
4407 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4408
4409 Texture *sourceTexture = getTexture(sourceId);
4410 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004411 ANGLE_CONTEXT_TRY(
4412 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4413 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4414 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004415}
4416
4417void Context::copySubTexture3D(GLuint sourceId,
4418 GLint sourceLevel,
4419 TextureTarget destTarget,
4420 GLuint destId,
4421 GLint destLevel,
4422 GLint xoffset,
4423 GLint yoffset,
4424 GLint zoffset,
4425 GLint x,
4426 GLint y,
4427 GLint z,
4428 GLsizei width,
4429 GLsizei height,
4430 GLsizei depth,
4431 GLboolean unpackFlipY,
4432 GLboolean unpackPremultiplyAlpha,
4433 GLboolean unpackUnmultiplyAlpha)
4434{
4435 // Zero sized copies are valid but no-ops
4436 if (width == 0 || height == 0 || depth == 0)
4437 {
4438 return;
4439 }
4440
4441 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4442
4443 Texture *sourceTexture = getTexture(sourceId);
4444 Texture *destTexture = getTexture(destId);
4445 Offset offset(xoffset, yoffset, zoffset);
4446 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004447 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4448 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4449 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4450 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004451}
4452
Jamie Madill007530e2017-12-28 14:27:04 -05004453void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004454{
Jamie Madillbc918e72018-03-08 09:47:21 -05004455 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004456
4457 gl::Texture *sourceTexture = getTexture(sourceId);
4458 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004459 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004460}
4461
Corentin Wallez336129f2017-10-17 15:55:40 -04004462void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004463{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004465 ASSERT(buffer);
4466
Geoff Lang496c02d2016-10-20 11:38:11 -07004467 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004468}
4469
Brandon Jones59770802018-04-02 13:18:42 -07004470void Context::getBufferPointervRobust(BufferBinding target,
4471 GLenum pname,
4472 GLsizei bufSize,
4473 GLsizei *length,
4474 void **params)
4475{
4476 getBufferPointerv(target, pname, params);
4477}
4478
Corentin Wallez336129f2017-10-17 15:55:40 -04004479void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004482 ASSERT(buffer);
4483
Jamie Madill4f6592f2018-11-27 16:37:45 -05004484 if (buffer->map(this, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004485 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004486 return nullptr;
4487 }
4488
4489 return buffer->getMapPointer();
4490}
4491
Corentin Wallez336129f2017-10-17 15:55:40 -04004492GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004495 ASSERT(buffer);
4496
4497 GLboolean result;
Jamie Madill4f6592f2018-11-27 16:37:45 -05004498 if (buffer->unmap(this, &result) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004499 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004500 return GL_FALSE;
4501 }
4502
4503 return result;
4504}
4505
Corentin Wallez336129f2017-10-17 15:55:40 -04004506void *Context::mapBufferRange(BufferBinding target,
4507 GLintptr offset,
4508 GLsizeiptr length,
4509 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004512 ASSERT(buffer);
4513
Jamie Madill4f6592f2018-11-27 16:37:45 -05004514 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004515 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004516 return nullptr;
4517 }
4518
4519 return buffer->getMapPointer();
4520}
4521
Corentin Wallez336129f2017-10-17 15:55:40 -04004522void Context::flushMappedBufferRange(BufferBinding /*target*/,
4523 GLintptr /*offset*/,
4524 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004525{
4526 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4527}
4528
Jamie Madill526392d2018-11-16 09:35:14 -05004529angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004530{
Geoff Langa8cb2872018-03-09 16:09:40 -05004531 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004532}
4533
Jamie Madill526392d2018-11-16 09:35:14 -05004534angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004535{
Geoff Langa8cb2872018-03-09 16:09:40 -05004536 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004537}
4538
Jamie Madill526392d2018-11-16 09:35:14 -05004539angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004540{
Geoff Langa8cb2872018-03-09 16:09:40 -05004541 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004542}
4543
Jamie Madill526392d2018-11-16 09:35:14 -05004544angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004545{
4546 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4547
4548 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4549 ANGLE_TRY(syncDirtyBits());
4550
Jamie Madill526392d2018-11-16 09:35:14 -05004551 return angle::Result::Continue();
Geoff Lang9bf86f02018-07-26 11:46:34 -04004552}
4553
Jiajia Qin5451d532017-11-16 17:16:34 +08004554void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4555{
4556 UNIMPLEMENTED();
4557}
4558
Jamie Madillc20ab272016-06-09 07:20:46 -07004559void Context::activeTexture(GLenum texture)
4560{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004561 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562}
4563
Jamie Madill876429b2017-04-20 15:46:24 -04004564void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004569void Context::blendEquation(GLenum mode)
4570{
4571 mGLState.setBlendEquation(mode, mode);
4572}
4573
Jamie Madillc20ab272016-06-09 07:20:46 -07004574void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577}
4578
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004579void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4580{
4581 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4582}
4583
Jamie Madillc20ab272016-06-09 07:20:46 -07004584void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4585{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587}
4588
Jamie Madill876429b2017-04-20 15:46:24 -04004589void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592}
4593
Jamie Madill876429b2017-04-20 15:46:24 -04004594void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004595{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004596 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004597}
4598
4599void Context::clearStencil(GLint s)
4600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
4604void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4605{
Geoff Lang92019432017-11-20 13:09:34 -05004606 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4607 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004608}
4609
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004610void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
4615void Context::depthFunc(GLenum func)
4616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
4620void Context::depthMask(GLboolean flag)
4621{
Geoff Lang92019432017-11-20 13:09:34 -05004622 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
Jamie Madill876429b2017-04-20 15:46:24 -04004625void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004626{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004627 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004628}
4629
4630void Context::disable(GLenum cap)
4631{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004633 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
4636void Context::disableVertexAttribArray(GLuint index)
4637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004638 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004639 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004640}
4641
4642void Context::enable(GLenum cap)
4643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004645 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
4648void Context::enableVertexAttribArray(GLuint index)
4649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004651 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::frontFace(GLenum mode)
4655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004656 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::hint(GLenum target, GLenum mode)
4660{
4661 switch (target)
4662 {
4663 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665 break;
4666
4667 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669 break;
4670
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004671 case GL_PERSPECTIVE_CORRECTION_HINT:
4672 case GL_POINT_SMOOTH_HINT:
4673 case GL_LINE_SMOOTH_HINT:
4674 case GL_FOG_HINT:
4675 mGLState.gles1().setHint(target, mode);
4676 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004677 default:
4678 UNREACHABLE();
4679 return;
4680 }
4681}
4682
4683void Context::lineWidth(GLfloat width)
4684{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004685 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004686}
4687
4688void Context::pixelStorei(GLenum pname, GLint param)
4689{
4690 switch (pname)
4691 {
4692 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694 break;
4695
4696 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698 break;
4699
4700 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004701 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004702 break;
4703
4704 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004705 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004706 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004707 break;
4708
4709 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004710 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004711 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712 break;
4713
4714 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004715 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004717 break;
4718
4719 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004720 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004721 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004722 break;
4723
4724 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004725 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004726 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004727 break;
4728
4729 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004730 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004731 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004732 break;
4733
4734 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004735 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004736 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004737 break;
4738
4739 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004740 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004741 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004742 break;
4743
4744 default:
4745 UNREACHABLE();
4746 return;
4747 }
4748}
4749
4750void Context::polygonOffset(GLfloat factor, GLfloat units)
4751{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004752 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
Jamie Madill876429b2017-04-20 15:46:24 -04004755void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004756{
Geoff Lang92019432017-11-20 13:09:34 -05004757 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004758}
4759
Jiawei Shaodb342272017-09-27 10:21:45 +08004760void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4761{
4762 mGLState.setSampleMaskParams(maskNumber, mask);
4763}
4764
Jamie Madillc20ab272016-06-09 07:20:46 -07004765void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4766{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004767 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768}
4769
4770void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4771{
4772 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4773 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004774 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004775 }
4776
4777 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4778 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004779 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004781
4782 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004783}
4784
4785void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4786{
4787 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4788 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004789 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004790 }
4791
4792 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4793 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004794 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004795 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004796
4797 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004798}
4799
4800void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4801{
4802 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4803 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004804 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004805 }
4806
4807 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4808 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004809 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810 }
4811}
4812
4813void Context::vertexAttrib1f(GLuint index, GLfloat x)
4814{
4815 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004816 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004817 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004818}
4819
4820void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4821{
4822 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004823 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004824 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004825}
4826
4827void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4828{
4829 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004830 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004831 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004832}
4833
4834void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4835{
4836 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004837 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004838 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004839}
4840
4841void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4842{
4843 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004844 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004845 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004846}
4847
4848void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4849{
4850 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004851 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004852 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004853}
4854
4855void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4856{
4857 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004858 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004859 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004860}
4861
4862void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4863{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004864 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004865 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004866}
4867
4868void Context::vertexAttribPointer(GLuint index,
4869 GLint size,
4870 GLenum type,
4871 GLboolean normalized,
4872 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004873 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004874{
Corentin Wallez336129f2017-10-17 15:55:40 -04004875 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004876 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004877 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004878}
4879
Shao80957d92017-02-20 21:25:59 +08004880void Context::vertexAttribFormat(GLuint attribIndex,
4881 GLint size,
4882 GLenum type,
4883 GLboolean normalized,
4884 GLuint relativeOffset)
4885{
Geoff Lang92019432017-11-20 13:09:34 -05004886 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004887 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004888 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004889}
4890
4891void Context::vertexAttribIFormat(GLuint attribIndex,
4892 GLint size,
4893 GLenum type,
4894 GLuint relativeOffset)
4895{
4896 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004897 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004898}
4899
4900void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4901{
Shaodde78e82017-05-22 14:13:27 +08004902 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004903 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004904}
4905
Jiajia Qin5451d532017-11-16 17:16:34 +08004906void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004907{
4908 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004909 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004910}
4911
Jamie Madillc20ab272016-06-09 07:20:46 -07004912void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4913{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004914 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004915}
4916
4917void Context::vertexAttribIPointer(GLuint index,
4918 GLint size,
4919 GLenum type,
4920 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004921 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004922{
Corentin Wallez336129f2017-10-17 15:55:40 -04004923 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4924 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004925 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004926}
4927
4928void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4929{
4930 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004931 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004932 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004933}
4934
4935void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4936{
4937 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004938 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004939 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004940}
4941
4942void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4943{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004944 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004945 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004946}
4947
4948void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4949{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004950 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004951 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004952}
4953
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004954void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4955{
4956 const VertexAttribCurrentValueData &currentValues =
4957 getGLState().getVertexAttribCurrentValue(index);
4958 const VertexArray *vao = getGLState().getVertexArray();
4959 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4960 currentValues, pname, params);
4961}
4962
Brandon Jones59770802018-04-02 13:18:42 -07004963void Context::getVertexAttribivRobust(GLuint index,
4964 GLenum pname,
4965 GLsizei bufSize,
4966 GLsizei *length,
4967 GLint *params)
4968{
4969 getVertexAttribiv(index, pname, params);
4970}
4971
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004972void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4973{
4974 const VertexAttribCurrentValueData &currentValues =
4975 getGLState().getVertexAttribCurrentValue(index);
4976 const VertexArray *vao = getGLState().getVertexArray();
4977 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4978 currentValues, pname, params);
4979}
4980
Brandon Jones59770802018-04-02 13:18:42 -07004981void Context::getVertexAttribfvRobust(GLuint index,
4982 GLenum pname,
4983 GLsizei bufSize,
4984 GLsizei *length,
4985 GLfloat *params)
4986{
4987 getVertexAttribfv(index, pname, params);
4988}
4989
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004990void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4991{
4992 const VertexAttribCurrentValueData &currentValues =
4993 getGLState().getVertexAttribCurrentValue(index);
4994 const VertexArray *vao = getGLState().getVertexArray();
4995 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4996 currentValues, pname, params);
4997}
4998
Brandon Jones59770802018-04-02 13:18:42 -07004999void Context::getVertexAttribIivRobust(GLuint index,
5000 GLenum pname,
5001 GLsizei bufSize,
5002 GLsizei *length,
5003 GLint *params)
5004{
5005 getVertexAttribIiv(index, pname, params);
5006}
5007
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005008void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5009{
5010 const VertexAttribCurrentValueData &currentValues =
5011 getGLState().getVertexAttribCurrentValue(index);
5012 const VertexArray *vao = getGLState().getVertexArray();
5013 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5014 currentValues, pname, params);
5015}
5016
Brandon Jones59770802018-04-02 13:18:42 -07005017void Context::getVertexAttribIuivRobust(GLuint index,
5018 GLenum pname,
5019 GLsizei bufSize,
5020 GLsizei *length,
5021 GLuint *params)
5022{
5023 getVertexAttribIuiv(index, pname, params);
5024}
5025
Jamie Madill876429b2017-04-20 15:46:24 -04005026void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005027{
5028 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5029 QueryVertexAttribPointerv(attrib, pname, pointer);
5030}
5031
Brandon Jones59770802018-04-02 13:18:42 -07005032void Context::getVertexAttribPointervRobust(GLuint index,
5033 GLenum pname,
5034 GLsizei bufSize,
5035 GLsizei *length,
5036 void **pointer)
5037{
5038 getVertexAttribPointerv(index, pname, pointer);
5039}
5040
Jamie Madillc20ab272016-06-09 07:20:46 -07005041void Context::debugMessageControl(GLenum source,
5042 GLenum type,
5043 GLenum severity,
5044 GLsizei count,
5045 const GLuint *ids,
5046 GLboolean enabled)
5047{
5048 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005049 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005050 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005051}
5052
5053void Context::debugMessageInsert(GLenum source,
5054 GLenum type,
5055 GLuint id,
5056 GLenum severity,
5057 GLsizei length,
5058 const GLchar *buf)
5059{
5060 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005061 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005062}
5063
5064void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5065{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005066 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005067}
5068
5069GLuint Context::getDebugMessageLog(GLuint count,
5070 GLsizei bufSize,
5071 GLenum *sources,
5072 GLenum *types,
5073 GLuint *ids,
5074 GLenum *severities,
5075 GLsizei *lengths,
5076 GLchar *messageLog)
5077{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005078 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5079 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005080}
5081
5082void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5083{
5084 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005085 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005086 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005087}
5088
5089void Context::popDebugGroup()
5090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005091 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005092 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005093}
5094
Corentin Wallez336129f2017-10-17 15:55:40 -04005095void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005096{
5097 Buffer *buffer = mGLState.getTargetBuffer(target);
5098 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005099 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005100}
5101
Corentin Wallez336129f2017-10-17 15:55:40 -04005102void Context::bufferSubData(BufferBinding target,
5103 GLintptr offset,
5104 GLsizeiptr size,
5105 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005106{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005107 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005108 {
5109 return;
5110 }
5111
5112 Buffer *buffer = mGLState.getTargetBuffer(target);
5113 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005114 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005115}
5116
Jamie Madillef300b12016-10-07 15:12:09 -04005117void Context::attachShader(GLuint program, GLuint shader)
5118{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005119 Program *programObject = mState.mShaderPrograms->getProgram(program);
5120 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005121 ASSERT(programObject && shaderObject);
5122 programObject->attachShader(shaderObject);
5123}
5124
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005125const Workarounds &Context::getWorkarounds() const
5126{
5127 return mWorkarounds;
5128}
5129
Corentin Wallez336129f2017-10-17 15:55:40 -04005130void Context::copyBufferSubData(BufferBinding readTarget,
5131 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005132 GLintptr readOffset,
5133 GLintptr writeOffset,
5134 GLsizeiptr size)
5135{
5136 // if size is zero, the copy is a successful no-op
5137 if (size == 0)
5138 {
5139 return;
5140 }
5141
5142 // TODO(jmadill): cache these.
5143 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5144 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5145
Jamie Madill4f6592f2018-11-27 16:37:45 -05005146 ANGLE_CONTEXT_TRY(
5147 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005148}
5149
Jamie Madill01a80ee2016-11-07 12:06:18 -05005150void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5151{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005152 // Ideally we could share the program query with the validation layer if possible.
5153 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005154 ASSERT(programObject);
5155 programObject->bindAttributeLocation(index, name);
5156}
5157
Corentin Wallez336129f2017-10-17 15:55:40 -04005158void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005159{
Corentin Wallez336129f2017-10-17 15:55:40 -04005160 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5161 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005162 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005163}
5164
Corentin Wallez336129f2017-10-17 15:55:40 -04005165void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005166{
5167 bindBufferRange(target, index, buffer, 0, 0);
5168}
5169
Corentin Wallez336129f2017-10-17 15:55:40 -04005170void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005171 GLuint index,
5172 GLuint buffer,
5173 GLintptr offset,
5174 GLsizeiptr size)
5175{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005176 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5177 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5178 if (target == BufferBinding::Uniform)
5179 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005180 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005181 mStateCache.onUniformBufferStateChange(this);
5182 }
5183 else
5184 {
5185 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005186 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005187}
5188
Jamie Madill01a80ee2016-11-07 12:06:18 -05005189void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5190{
5191 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5192 {
5193 bindReadFramebuffer(framebuffer);
5194 }
5195
5196 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5197 {
5198 bindDrawFramebuffer(framebuffer);
5199 }
5200}
5201
5202void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5203{
5204 ASSERT(target == GL_RENDERBUFFER);
5205 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005206 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005207 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005208}
5209
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005210void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005211 GLsizei samples,
5212 GLenum internalformat,
5213 GLsizei width,
5214 GLsizei height,
5215 GLboolean fixedsamplelocations)
5216{
5217 Extents size(width, height, 1);
5218 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005219 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5220 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005221}
5222
Olli Etuaho89664842018-08-24 14:45:36 +03005223void Context::texStorage3DMultisample(TextureType target,
5224 GLsizei samples,
5225 GLenum internalformat,
5226 GLsizei width,
5227 GLsizei height,
5228 GLsizei depth,
5229 GLboolean fixedsamplelocations)
5230{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005231 Extents size(width, height, depth);
5232 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005233 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5234 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005235}
5236
JiangYizhoubddc46b2016-12-09 09:50:51 +08005237void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5238{
JiangYizhou5b03f472017-01-09 10:22:53 +08005239 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5240 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005241 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005242 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005243
5244 switch (pname)
5245 {
5246 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005247 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005248 break;
5249 default:
5250 UNREACHABLE();
5251 }
5252}
5253
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005254void Context::getMultisamplefvRobust(GLenum pname,
5255 GLuint index,
5256 GLsizei bufSize,
5257 GLsizei *length,
5258 GLfloat *val)
5259{
5260 UNIMPLEMENTED();
5261}
5262
Jamie Madille8fb6402017-02-14 17:56:40 -05005263void Context::renderbufferStorage(GLenum target,
5264 GLenum internalformat,
5265 GLsizei width,
5266 GLsizei height)
5267{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005268 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5269 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5270
Jamie Madille8fb6402017-02-14 17:56:40 -05005271 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005272 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005273}
5274
5275void Context::renderbufferStorageMultisample(GLenum target,
5276 GLsizei samples,
5277 GLenum internalformat,
5278 GLsizei width,
5279 GLsizei height)
5280{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005281 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5282 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005283
5284 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005285 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005286 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005287}
5288
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005289void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5290{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005291 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005292 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005293}
5294
JiangYizhoue18e6392017-02-20 10:32:23 +08005295void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5296{
5297 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5298 QueryFramebufferParameteriv(framebuffer, pname, params);
5299}
5300
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005301void Context::getFramebufferParameterivRobust(GLenum target,
5302 GLenum pname,
5303 GLsizei bufSize,
5304 GLsizei *length,
5305 GLint *params)
5306{
5307 UNIMPLEMENTED();
5308}
5309
Jiajia Qin5451d532017-11-16 17:16:34 +08005310void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005311{
5312 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005313 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005314}
5315
Jamie Madilldec86232018-07-11 09:01:18 -04005316bool Context::getScratchBuffer(size_t requstedSizeBytes,
5317 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005318{
Jamie Madilldec86232018-07-11 09:01:18 -04005319 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005320}
5321
Jamie Madilldec86232018-07-11 09:01:18 -04005322bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5323 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005324{
Jamie Madilldec86232018-07-11 09:01:18 -04005325 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005326}
5327
Jamie Madill526392d2018-11-16 09:35:14 -05005328angle::Result Context::prepareForDispatch()
Xinghua Cao10a4d432017-11-28 14:46:26 +08005329{
Jamie Madill0cc11c62018-10-12 18:07:18 -04005330 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005331
5332 if (isRobustResourceInitEnabled())
5333 {
5334 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5335 }
5336
Jamie Madill0cc11c62018-10-12 18:07:18 -04005337 return syncDirtyBits(mComputeDirtyBits);
Xinghua Cao10a4d432017-11-28 14:46:26 +08005338}
5339
Xinghua Cao2b396592017-03-29 15:36:04 +08005340void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5341{
5342 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5343 {
5344 return;
5345 }
5346
Xinghua Cao10a4d432017-11-28 14:46:26 +08005347 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005348 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005349}
5350
Jiajia Qin5451d532017-11-16 17:16:34 +08005351void Context::dispatchComputeIndirect(GLintptr indirect)
5352{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005353 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005354 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005355}
5356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005357void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005358 GLsizei levels,
5359 GLenum internalFormat,
5360 GLsizei width,
5361 GLsizei height)
5362{
5363 Extents size(width, height, 1);
5364 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005365 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005366}
5367
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005368void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005369 GLsizei levels,
5370 GLenum internalFormat,
5371 GLsizei width,
5372 GLsizei height,
5373 GLsizei depth)
5374{
5375 Extents size(width, height, depth);
5376 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005377 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005378}
5379
Jiajia Qin5451d532017-11-16 17:16:34 +08005380void Context::memoryBarrier(GLbitfield barriers)
5381{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005382 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005383}
5384
5385void Context::memoryBarrierByRegion(GLbitfield barriers)
5386{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005387 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005388}
5389
Austin Eng1bf18ce2018-10-19 15:34:02 -07005390void Context::multiDrawArrays(PrimitiveMode mode,
5391 const GLint *firsts,
5392 const GLsizei *counts,
5393 GLsizei drawcount)
5394{
5395 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5396 Program *programObject = mGLState.getLinkedProgram(this);
5397 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5398 if (hasDrawID)
5399 {
5400 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5401 {
5402 if (noopDraw(mode, counts[drawID]))
5403 {
5404 continue;
5405 }
5406 programObject->setDrawIDUniform(drawID);
5407 ANGLE_CONTEXT_TRY(
5408 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5409 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5410 counts[drawID], 1);
5411 }
5412 }
5413 else
5414 {
5415 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5416 {
5417 if (noopDraw(mode, counts[drawID]))
5418 {
5419 continue;
5420 }
5421 ANGLE_CONTEXT_TRY(
5422 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5423 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5424 counts[drawID], 1);
5425 }
5426 }
5427}
5428
5429void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5430 const GLint *firsts,
5431 const GLsizei *counts,
5432 const GLsizei *instanceCounts,
5433 GLsizei drawcount)
5434{
5435 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5436 Program *programObject = mGLState.getLinkedProgram(this);
5437 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5438 if (hasDrawID)
5439 {
5440 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5441 {
5442 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5443 {
5444 continue;
5445 }
5446 programObject->setDrawIDUniform(drawID);
5447 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5448 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5449 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5450 counts[drawID], instanceCounts[drawID]);
5451 }
5452 }
5453 else
5454 {
5455 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5456 {
5457 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5458 {
5459 continue;
5460 }
5461 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5462 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5463 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5464 counts[drawID], instanceCounts[drawID]);
5465 }
5466 }
5467}
5468
5469void Context::multiDrawElements(PrimitiveMode mode,
5470 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005471 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005472 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005473 GLsizei drawcount)
5474{
5475 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5476 Program *programObject = mGLState.getLinkedProgram(this);
5477 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5478 if (hasDrawID)
5479 {
5480 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5481 {
5482 if (noopDraw(mode, counts[drawID]))
5483 {
5484 continue;
5485 }
5486 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005487 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005488 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005489 }
5490 }
5491 else
5492 {
5493 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5494 {
5495 if (noopDraw(mode, counts[drawID]))
5496 {
5497 continue;
5498 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005499 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005500 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005501 }
5502 }
5503}
5504
5505void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5506 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005507 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005508 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005509 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);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005524 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005525 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005526 }
5527 }
5528 else
5529 {
5530 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5531 {
5532 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5533 {
5534 continue;
5535 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005536 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005537 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005538 }
5539 }
5540}
5541
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542GLenum Context::checkFramebufferStatus(GLenum target)
5543{
5544 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5545 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005546 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005547}
5548
5549void Context::compileShader(GLuint shader)
5550{
5551 Shader *shaderObject = GetValidShader(this, shader);
5552 if (!shaderObject)
5553 {
5554 return;
5555 }
5556 shaderObject->compile(this);
5557}
5558
5559void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5560{
5561 for (int i = 0; i < n; i++)
5562 {
5563 deleteBuffer(buffers[i]);
5564 }
5565}
5566
5567void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5568{
5569 for (int i = 0; i < n; i++)
5570 {
5571 if (framebuffers[i] != 0)
5572 {
5573 deleteFramebuffer(framebuffers[i]);
5574 }
5575 }
5576}
5577
5578void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5579{
5580 for (int i = 0; i < n; i++)
5581 {
5582 deleteRenderbuffer(renderbuffers[i]);
5583 }
5584}
5585
5586void Context::deleteTextures(GLsizei n, const GLuint *textures)
5587{
5588 for (int i = 0; i < n; i++)
5589 {
5590 if (textures[i] != 0)
5591 {
5592 deleteTexture(textures[i]);
5593 }
5594 }
5595}
5596
5597void Context::detachShader(GLuint program, GLuint shader)
5598{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005599 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005600 ASSERT(programObject);
5601
5602 Shader *shaderObject = getShader(shader);
5603 ASSERT(shaderObject);
5604
5605 programObject->detachShader(this, shaderObject);
5606}
5607
5608void Context::genBuffers(GLsizei n, GLuint *buffers)
5609{
5610 for (int i = 0; i < n; i++)
5611 {
5612 buffers[i] = createBuffer();
5613 }
5614}
5615
5616void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5617{
5618 for (int i = 0; i < n; i++)
5619 {
5620 framebuffers[i] = createFramebuffer();
5621 }
5622}
5623
5624void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5625{
5626 for (int i = 0; i < n; i++)
5627 {
5628 renderbuffers[i] = createRenderbuffer();
5629 }
5630}
5631
5632void Context::genTextures(GLsizei n, GLuint *textures)
5633{
5634 for (int i = 0; i < n; i++)
5635 {
5636 textures[i] = createTexture();
5637 }
5638}
5639
5640void Context::getActiveAttrib(GLuint program,
5641 GLuint index,
5642 GLsizei bufsize,
5643 GLsizei *length,
5644 GLint *size,
5645 GLenum *type,
5646 GLchar *name)
5647{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005648 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005649 ASSERT(programObject);
5650 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5651}
5652
5653void Context::getActiveUniform(GLuint program,
5654 GLuint index,
5655 GLsizei bufsize,
5656 GLsizei *length,
5657 GLint *size,
5658 GLenum *type,
5659 GLchar *name)
5660{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005661 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005662 ASSERT(programObject);
5663 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5664}
5665
5666void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5667{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005668 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005669 ASSERT(programObject);
5670 programObject->getAttachedShaders(maxcount, count, shaders);
5671}
5672
5673GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5674{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005675 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005676 ASSERT(programObject);
5677 return programObject->getAttributeLocation(name);
5678}
5679
5680void Context::getBooleanv(GLenum pname, GLboolean *params)
5681{
5682 GLenum nativeType;
5683 unsigned int numParams = 0;
5684 getQueryParameterInfo(pname, &nativeType, &numParams);
5685
5686 if (nativeType == GL_BOOL)
5687 {
5688 getBooleanvImpl(pname, params);
5689 }
5690 else
5691 {
5692 CastStateValues(this, nativeType, pname, numParams, params);
5693 }
5694}
5695
Brandon Jones59770802018-04-02 13:18:42 -07005696void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5697{
5698 getBooleanv(pname, params);
5699}
5700
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701void Context::getFloatv(GLenum pname, GLfloat *params)
5702{
5703 GLenum nativeType;
5704 unsigned int numParams = 0;
5705 getQueryParameterInfo(pname, &nativeType, &numParams);
5706
5707 if (nativeType == GL_FLOAT)
5708 {
5709 getFloatvImpl(pname, params);
5710 }
5711 else
5712 {
5713 CastStateValues(this, nativeType, pname, numParams, params);
5714 }
5715}
5716
Brandon Jones59770802018-04-02 13:18:42 -07005717void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5718{
5719 getFloatv(pname, params);
5720}
5721
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722void Context::getIntegerv(GLenum pname, GLint *params)
5723{
5724 GLenum nativeType;
5725 unsigned int numParams = 0;
5726 getQueryParameterInfo(pname, &nativeType, &numParams);
5727
5728 if (nativeType == GL_INT)
5729 {
5730 getIntegervImpl(pname, params);
5731 }
5732 else
5733 {
5734 CastStateValues(this, nativeType, pname, numParams, params);
5735 }
5736}
5737
Brandon Jones59770802018-04-02 13:18:42 -07005738void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5739{
5740 getIntegerv(pname, data);
5741}
5742
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5744{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005745 // Don't resolve link if checking the link completion status.
5746 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5747 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005749 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750}
5751
Brandon Jones59770802018-04-02 13:18:42 -07005752void Context::getProgramivRobust(GLuint program,
5753 GLenum pname,
5754 GLsizei bufSize,
5755 GLsizei *length,
5756 GLint *params)
5757{
5758 getProgramiv(program, pname, params);
5759}
5760
Jiajia Qin5451d532017-11-16 17:16:34 +08005761void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5762{
5763 UNIMPLEMENTED();
5764}
5765
Jamie Madillbe849e42017-05-02 15:49:00 -04005766void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005767{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005768 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005769 ASSERT(programObject);
5770 programObject->getInfoLog(bufsize, length, infolog);
5771}
5772
Jiajia Qin5451d532017-11-16 17:16:34 +08005773void Context::getProgramPipelineInfoLog(GLuint pipeline,
5774 GLsizei bufSize,
5775 GLsizei *length,
5776 GLchar *infoLog)
5777{
5778 UNIMPLEMENTED();
5779}
5780
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5782{
5783 Shader *shaderObject = getShader(shader);
5784 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005785 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005786}
5787
Brandon Jones59770802018-04-02 13:18:42 -07005788void Context::getShaderivRobust(GLuint shader,
5789 GLenum pname,
5790 GLsizei bufSize,
5791 GLsizei *length,
5792 GLint *params)
5793{
5794 getShaderiv(shader, pname, params);
5795}
5796
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5798{
5799 Shader *shaderObject = getShader(shader);
5800 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005801 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005802}
5803
5804void Context::getShaderPrecisionFormat(GLenum shadertype,
5805 GLenum precisiontype,
5806 GLint *range,
5807 GLint *precision)
5808{
5809 // TODO(jmadill): Compute shaders.
5810
5811 switch (shadertype)
5812 {
5813 case GL_VERTEX_SHADER:
5814 switch (precisiontype)
5815 {
5816 case GL_LOW_FLOAT:
5817 mCaps.vertexLowpFloat.get(range, precision);
5818 break;
5819 case GL_MEDIUM_FLOAT:
5820 mCaps.vertexMediumpFloat.get(range, precision);
5821 break;
5822 case GL_HIGH_FLOAT:
5823 mCaps.vertexHighpFloat.get(range, precision);
5824 break;
5825
5826 case GL_LOW_INT:
5827 mCaps.vertexLowpInt.get(range, precision);
5828 break;
5829 case GL_MEDIUM_INT:
5830 mCaps.vertexMediumpInt.get(range, precision);
5831 break;
5832 case GL_HIGH_INT:
5833 mCaps.vertexHighpInt.get(range, precision);
5834 break;
5835
5836 default:
5837 UNREACHABLE();
5838 return;
5839 }
5840 break;
5841
5842 case GL_FRAGMENT_SHADER:
5843 switch (precisiontype)
5844 {
5845 case GL_LOW_FLOAT:
5846 mCaps.fragmentLowpFloat.get(range, precision);
5847 break;
5848 case GL_MEDIUM_FLOAT:
5849 mCaps.fragmentMediumpFloat.get(range, precision);
5850 break;
5851 case GL_HIGH_FLOAT:
5852 mCaps.fragmentHighpFloat.get(range, precision);
5853 break;
5854
5855 case GL_LOW_INT:
5856 mCaps.fragmentLowpInt.get(range, precision);
5857 break;
5858 case GL_MEDIUM_INT:
5859 mCaps.fragmentMediumpInt.get(range, precision);
5860 break;
5861 case GL_HIGH_INT:
5862 mCaps.fragmentHighpInt.get(range, precision);
5863 break;
5864
5865 default:
5866 UNREACHABLE();
5867 return;
5868 }
5869 break;
5870
5871 default:
5872 UNREACHABLE();
5873 return;
5874 }
5875}
5876
5877void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5878{
5879 Shader *shaderObject = getShader(shader);
5880 ASSERT(shaderObject);
5881 shaderObject->getSource(bufsize, length, source);
5882}
5883
5884void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5885{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005886 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005887 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005888 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005889}
5890
Brandon Jones59770802018-04-02 13:18:42 -07005891void Context::getUniformfvRobust(GLuint program,
5892 GLint location,
5893 GLsizei bufSize,
5894 GLsizei *length,
5895 GLfloat *params)
5896{
5897 getUniformfv(program, location, params);
5898}
5899
Jamie Madillc1d770e2017-04-13 17:31:24 -04005900void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5901{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005902 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005903 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005904 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005905}
5906
Brandon Jones59770802018-04-02 13:18:42 -07005907void Context::getUniformivRobust(GLuint program,
5908 GLint location,
5909 GLsizei bufSize,
5910 GLsizei *length,
5911 GLint *params)
5912{
5913 getUniformiv(program, location, params);
5914}
5915
Jamie Madillc1d770e2017-04-13 17:31:24 -04005916GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5917{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005918 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005919 ASSERT(programObject);
5920 return programObject->getUniformLocation(name);
5921}
5922
5923GLboolean Context::isBuffer(GLuint buffer)
5924{
5925 if (buffer == 0)
5926 {
5927 return GL_FALSE;
5928 }
5929
5930 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5931}
5932
5933GLboolean Context::isEnabled(GLenum cap)
5934{
5935 return mGLState.getEnableFeature(cap);
5936}
5937
5938GLboolean Context::isFramebuffer(GLuint framebuffer)
5939{
5940 if (framebuffer == 0)
5941 {
5942 return GL_FALSE;
5943 }
5944
5945 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5946}
5947
5948GLboolean Context::isProgram(GLuint program)
5949{
5950 if (program == 0)
5951 {
5952 return GL_FALSE;
5953 }
5954
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005955 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005956}
5957
5958GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5959{
5960 if (renderbuffer == 0)
5961 {
5962 return GL_FALSE;
5963 }
5964
5965 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5966}
5967
5968GLboolean Context::isShader(GLuint shader)
5969{
5970 if (shader == 0)
5971 {
5972 return GL_FALSE;
5973 }
5974
5975 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5976}
5977
5978GLboolean Context::isTexture(GLuint texture)
5979{
5980 if (texture == 0)
5981 {
5982 return GL_FALSE;
5983 }
5984
5985 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5986}
5987
5988void Context::linkProgram(GLuint program)
5989{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005990 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005991 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005992 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005993
5994 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5995 // don't need to worry that:
5996 // 1. Draw calls after link use the new executable code or the old one depending on the link
5997 // result.
5998 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5999 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
6000 // ProgramD3D.
6001 if (programObject->isInUse())
6002 {
Jamie Madill785e8a02018-10-04 17:42:00 -04006003 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006004 if (programObject->isLinked())
6005 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006006 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006007 }
jchen107ae70d82018-07-06 13:47:01 +08006008 mStateCache.onProgramExecutableChange(this);
6009 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006010}
6011
6012void Context::releaseShaderCompiler()
6013{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006014 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006015}
6016
6017void Context::shaderBinary(GLsizei n,
6018 const GLuint *shaders,
6019 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006020 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006021 GLsizei length)
6022{
6023 // No binary shader formats are supported.
6024 UNIMPLEMENTED();
6025}
6026
Olli Etuaho0ca09752018-09-24 11:00:50 +03006027void Context::bindFragDataLocationIndexed(GLuint program,
6028 GLuint colorNumber,
6029 GLuint index,
6030 const char *name)
6031{
6032 Program *programObject = getProgramNoResolveLink(program);
6033 programObject->bindFragmentOutputLocation(colorNumber, name);
6034 programObject->bindFragmentOutputIndex(index, name);
6035}
6036
6037void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6038{
6039 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6040}
6041
6042int Context::getFragDataIndex(GLuint program, const char *name)
6043{
6044 Program *programObject = getProgramResolveLink(program);
6045 return programObject->getFragDataIndex(name);
6046}
6047
6048int Context::getProgramResourceLocationIndex(GLuint program,
6049 GLenum programInterface,
6050 const char *name)
6051{
6052 Program *programObject = getProgramResolveLink(program);
6053 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6054 return programObject->getFragDataIndex(name);
6055}
6056
Jamie Madillc1d770e2017-04-13 17:31:24 -04006057void Context::shaderSource(GLuint shader,
6058 GLsizei count,
6059 const GLchar *const *string,
6060 const GLint *length)
6061{
6062 Shader *shaderObject = getShader(shader);
6063 ASSERT(shaderObject);
6064 shaderObject->setSource(count, string, length);
6065}
6066
6067void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6068{
6069 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6070}
6071
6072void Context::stencilMask(GLuint mask)
6073{
6074 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6075}
6076
6077void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6078{
6079 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6080}
6081
6082void Context::uniform1f(GLint location, GLfloat x)
6083{
6084 Program *program = mGLState.getProgram();
6085 program->setUniform1fv(location, 1, &x);
6086}
6087
6088void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6089{
6090 Program *program = mGLState.getProgram();
6091 program->setUniform1fv(location, count, v);
6092}
6093
Jamie Madill7e4eff12018-08-08 15:49:26 -04006094void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006095{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006096 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04006097 {
6098 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006099 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04006100 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006101}
6102
Jamie Madill7e4eff12018-08-08 15:49:26 -04006103void Context::uniform1i(GLint location, GLint x)
6104{
6105 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6106}
6107
Jamie Madillc1d770e2017-04-13 17:31:24 -04006108void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6109{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006110 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006111}
6112
6113void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6114{
6115 GLfloat xy[2] = {x, y};
6116 Program *program = mGLState.getProgram();
6117 program->setUniform2fv(location, 1, xy);
6118}
6119
6120void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6121{
6122 Program *program = mGLState.getProgram();
6123 program->setUniform2fv(location, count, v);
6124}
6125
6126void Context::uniform2i(GLint location, GLint x, GLint y)
6127{
6128 GLint xy[2] = {x, y};
6129 Program *program = mGLState.getProgram();
6130 program->setUniform2iv(location, 1, xy);
6131}
6132
6133void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6134{
6135 Program *program = mGLState.getProgram();
6136 program->setUniform2iv(location, count, v);
6137}
6138
6139void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6140{
6141 GLfloat xyz[3] = {x, y, z};
6142 Program *program = mGLState.getProgram();
6143 program->setUniform3fv(location, 1, xyz);
6144}
6145
6146void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6147{
6148 Program *program = mGLState.getProgram();
6149 program->setUniform3fv(location, count, v);
6150}
6151
6152void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6153{
6154 GLint xyz[3] = {x, y, z};
6155 Program *program = mGLState.getProgram();
6156 program->setUniform3iv(location, 1, xyz);
6157}
6158
6159void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6160{
6161 Program *program = mGLState.getProgram();
6162 program->setUniform3iv(location, count, v);
6163}
6164
6165void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6166{
6167 GLfloat xyzw[4] = {x, y, z, w};
6168 Program *program = mGLState.getProgram();
6169 program->setUniform4fv(location, 1, xyzw);
6170}
6171
6172void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6173{
6174 Program *program = mGLState.getProgram();
6175 program->setUniform4fv(location, count, v);
6176}
6177
6178void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6179{
6180 GLint xyzw[4] = {x, y, z, w};
6181 Program *program = mGLState.getProgram();
6182 program->setUniform4iv(location, 1, xyzw);
6183}
6184
6185void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6186{
6187 Program *program = mGLState.getProgram();
6188 program->setUniform4iv(location, count, v);
6189}
6190
6191void Context::uniformMatrix2fv(GLint location,
6192 GLsizei count,
6193 GLboolean transpose,
6194 const GLfloat *value)
6195{
6196 Program *program = mGLState.getProgram();
6197 program->setUniformMatrix2fv(location, count, transpose, value);
6198}
6199
6200void Context::uniformMatrix3fv(GLint location,
6201 GLsizei count,
6202 GLboolean transpose,
6203 const GLfloat *value)
6204{
6205 Program *program = mGLState.getProgram();
6206 program->setUniformMatrix3fv(location, count, transpose, value);
6207}
6208
6209void Context::uniformMatrix4fv(GLint location,
6210 GLsizei count,
6211 GLboolean transpose,
6212 const GLfloat *value)
6213{
6214 Program *program = mGLState.getProgram();
6215 program->setUniformMatrix4fv(location, count, transpose, value);
6216}
6217
6218void Context::validateProgram(GLuint program)
6219{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006220 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006221 ASSERT(programObject);
6222 programObject->validate(mCaps);
6223}
6224
Jiajia Qin5451d532017-11-16 17:16:34 +08006225void Context::validateProgramPipeline(GLuint pipeline)
6226{
6227 UNIMPLEMENTED();
6228}
6229
Jamie Madilld04908b2017-06-09 14:15:35 -04006230void Context::getProgramBinary(GLuint program,
6231 GLsizei bufSize,
6232 GLsizei *length,
6233 GLenum *binaryFormat,
6234 void *binary)
6235{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006236 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006237 ASSERT(programObject != nullptr);
6238
Jamie Madill4f6592f2018-11-27 16:37:45 -05006239 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006240}
6241
6242void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6243{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006244 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006245 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006246
Jamie Madill4f6592f2018-11-27 16:37:45 -05006247 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006248 if (programObject->isInUse())
6249 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006250 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006251 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006252 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006253}
6254
Jamie Madillff325f12017-08-26 15:06:05 -04006255void Context::uniform1ui(GLint location, GLuint v0)
6256{
6257 Program *program = mGLState.getProgram();
6258 program->setUniform1uiv(location, 1, &v0);
6259}
6260
6261void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6262{
6263 Program *program = mGLState.getProgram();
6264 const GLuint xy[] = {v0, v1};
6265 program->setUniform2uiv(location, 1, xy);
6266}
6267
6268void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6269{
6270 Program *program = mGLState.getProgram();
6271 const GLuint xyz[] = {v0, v1, v2};
6272 program->setUniform3uiv(location, 1, xyz);
6273}
6274
6275void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6276{
6277 Program *program = mGLState.getProgram();
6278 const GLuint xyzw[] = {v0, v1, v2, v3};
6279 program->setUniform4uiv(location, 1, xyzw);
6280}
6281
6282void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6283{
6284 Program *program = mGLState.getProgram();
6285 program->setUniform1uiv(location, count, value);
6286}
6287void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6288{
6289 Program *program = mGLState.getProgram();
6290 program->setUniform2uiv(location, count, value);
6291}
6292
6293void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6294{
6295 Program *program = mGLState.getProgram();
6296 program->setUniform3uiv(location, count, value);
6297}
6298
6299void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6300{
6301 Program *program = mGLState.getProgram();
6302 program->setUniform4uiv(location, count, value);
6303}
6304
Jamie Madillf0e04492017-08-26 15:28:42 -04006305void Context::genQueries(GLsizei n, GLuint *ids)
6306{
6307 for (GLsizei i = 0; i < n; i++)
6308 {
6309 GLuint handle = mQueryHandleAllocator.allocate();
6310 mQueryMap.assign(handle, nullptr);
6311 ids[i] = handle;
6312 }
6313}
6314
6315void Context::deleteQueries(GLsizei n, const GLuint *ids)
6316{
6317 for (int i = 0; i < n; i++)
6318 {
6319 GLuint query = ids[i];
6320
6321 Query *queryObject = nullptr;
6322 if (mQueryMap.erase(query, &queryObject))
6323 {
6324 mQueryHandleAllocator.release(query);
6325 if (queryObject)
6326 {
6327 queryObject->release(this);
6328 }
6329 }
6330 }
6331}
6332
6333GLboolean Context::isQuery(GLuint id)
6334{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006335 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006336}
6337
Jamie Madillc8c95812017-08-26 18:40:09 -04006338void Context::uniformMatrix2x3fv(GLint location,
6339 GLsizei count,
6340 GLboolean transpose,
6341 const GLfloat *value)
6342{
6343 Program *program = mGLState.getProgram();
6344 program->setUniformMatrix2x3fv(location, count, transpose, value);
6345}
6346
6347void Context::uniformMatrix3x2fv(GLint location,
6348 GLsizei count,
6349 GLboolean transpose,
6350 const GLfloat *value)
6351{
6352 Program *program = mGLState.getProgram();
6353 program->setUniformMatrix3x2fv(location, count, transpose, value);
6354}
6355
6356void Context::uniformMatrix2x4fv(GLint location,
6357 GLsizei count,
6358 GLboolean transpose,
6359 const GLfloat *value)
6360{
6361 Program *program = mGLState.getProgram();
6362 program->setUniformMatrix2x4fv(location, count, transpose, value);
6363}
6364
6365void Context::uniformMatrix4x2fv(GLint location,
6366 GLsizei count,
6367 GLboolean transpose,
6368 const GLfloat *value)
6369{
6370 Program *program = mGLState.getProgram();
6371 program->setUniformMatrix4x2fv(location, count, transpose, value);
6372}
6373
6374void Context::uniformMatrix3x4fv(GLint location,
6375 GLsizei count,
6376 GLboolean transpose,
6377 const GLfloat *value)
6378{
6379 Program *program = mGLState.getProgram();
6380 program->setUniformMatrix3x4fv(location, count, transpose, value);
6381}
6382
6383void Context::uniformMatrix4x3fv(GLint location,
6384 GLsizei count,
6385 GLboolean transpose,
6386 const GLfloat *value)
6387{
6388 Program *program = mGLState.getProgram();
6389 program->setUniformMatrix4x3fv(location, count, transpose, value);
6390}
6391
Jamie Madilld7576732017-08-26 18:49:50 -04006392void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6393{
6394 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6395 {
6396 GLuint vertexArray = arrays[arrayIndex];
6397
6398 if (arrays[arrayIndex] != 0)
6399 {
6400 VertexArray *vertexArrayObject = nullptr;
6401 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6402 {
6403 if (vertexArrayObject != nullptr)
6404 {
6405 detachVertexArray(vertexArray);
6406 vertexArrayObject->onDestroy(this);
6407 }
6408
6409 mVertexArrayHandleAllocator.release(vertexArray);
6410 }
6411 }
6412 }
6413}
6414
6415void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6416{
6417 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6418 {
6419 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6420 mVertexArrayMap.assign(vertexArray, nullptr);
6421 arrays[arrayIndex] = vertexArray;
6422 }
6423}
6424
6425bool Context::isVertexArray(GLuint array)
6426{
6427 if (array == 0)
6428 {
6429 return GL_FALSE;
6430 }
6431
6432 VertexArray *vao = getVertexArray(array);
6433 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6434}
6435
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006436void Context::endTransformFeedback()
6437{
6438 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6439 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006440 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006441}
6442
6443void Context::transformFeedbackVaryings(GLuint program,
6444 GLsizei count,
6445 const GLchar *const *varyings,
6446 GLenum bufferMode)
6447{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006448 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006449 ASSERT(programObject);
6450 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6451}
6452
6453void Context::getTransformFeedbackVarying(GLuint program,
6454 GLuint index,
6455 GLsizei bufSize,
6456 GLsizei *length,
6457 GLsizei *size,
6458 GLenum *type,
6459 GLchar *name)
6460{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006461 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006462 ASSERT(programObject);
6463 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6464}
6465
6466void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6467{
6468 for (int i = 0; i < n; i++)
6469 {
6470 GLuint transformFeedback = ids[i];
6471 if (transformFeedback == 0)
6472 {
6473 continue;
6474 }
6475
6476 TransformFeedback *transformFeedbackObject = nullptr;
6477 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6478 {
6479 if (transformFeedbackObject != nullptr)
6480 {
6481 detachTransformFeedback(transformFeedback);
6482 transformFeedbackObject->release(this);
6483 }
6484
6485 mTransformFeedbackHandleAllocator.release(transformFeedback);
6486 }
6487 }
6488}
6489
6490void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6491{
6492 for (int i = 0; i < n; i++)
6493 {
6494 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6495 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6496 ids[i] = transformFeedback;
6497 }
6498}
6499
6500bool Context::isTransformFeedback(GLuint id)
6501{
6502 if (id == 0)
6503 {
6504 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6505 // returns FALSE
6506 return GL_FALSE;
6507 }
6508
6509 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6510 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6511}
6512
6513void Context::pauseTransformFeedback()
6514{
6515 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6516 transformFeedback->pause();
6517}
6518
6519void Context::resumeTransformFeedback()
6520{
6521 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6522 transformFeedback->resume();
6523}
6524
Jamie Madill12e957f2017-08-26 21:42:26 -04006525void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6526{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006527 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006528 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006529}
6530
Brandon Jones59770802018-04-02 13:18:42 -07006531void Context::getUniformuivRobust(GLuint program,
6532 GLint location,
6533 GLsizei bufSize,
6534 GLsizei *length,
6535 GLuint *params)
6536{
6537 getUniformuiv(program, location, params);
6538}
6539
Jamie Madill12e957f2017-08-26 21:42:26 -04006540GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6541{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006542 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006543 return programObject->getFragDataLocation(name);
6544}
6545
6546void Context::getUniformIndices(GLuint program,
6547 GLsizei uniformCount,
6548 const GLchar *const *uniformNames,
6549 GLuint *uniformIndices)
6550{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006551 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006552 if (!programObject->isLinked())
6553 {
6554 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6555 {
6556 uniformIndices[uniformId] = GL_INVALID_INDEX;
6557 }
6558 }
6559 else
6560 {
6561 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6562 {
6563 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6564 }
6565 }
6566}
6567
6568void Context::getActiveUniformsiv(GLuint program,
6569 GLsizei uniformCount,
6570 const GLuint *uniformIndices,
6571 GLenum pname,
6572 GLint *params)
6573{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006574 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006575 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6576 {
6577 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006578 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006579 }
6580}
6581
6582GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6583{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006584 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006585 return programObject->getUniformBlockIndex(uniformBlockName);
6586}
6587
6588void Context::getActiveUniformBlockiv(GLuint program,
6589 GLuint uniformBlockIndex,
6590 GLenum pname,
6591 GLint *params)
6592{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006593 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006594 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6595}
6596
Brandon Jones59770802018-04-02 13:18:42 -07006597void Context::getActiveUniformBlockivRobust(GLuint program,
6598 GLuint uniformBlockIndex,
6599 GLenum pname,
6600 GLsizei bufSize,
6601 GLsizei *length,
6602 GLint *params)
6603{
6604 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6605}
6606
Jamie Madill12e957f2017-08-26 21:42:26 -04006607void Context::getActiveUniformBlockName(GLuint program,
6608 GLuint uniformBlockIndex,
6609 GLsizei bufSize,
6610 GLsizei *length,
6611 GLchar *uniformBlockName)
6612{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006613 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006614 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6615}
6616
6617void Context::uniformBlockBinding(GLuint program,
6618 GLuint uniformBlockIndex,
6619 GLuint uniformBlockBinding)
6620{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006621 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006622 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006623
Jamie Madill956ab4d2018-10-10 16:13:03 -04006624 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006625 if (programObject->isInUse())
6626 {
6627 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006628 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006629 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006630}
6631
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006632GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6633{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006634 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6635 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006636
Jamie Madill70b5bb02017-08-28 13:32:37 -04006637 Sync *syncObject = getSync(syncHandle);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006638 if (syncObject->set(this, condition, flags) == angle::Result::Stop())
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006639 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006640 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006641 return nullptr;
6642 }
6643
Jamie Madill70b5bb02017-08-28 13:32:37 -04006644 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006645}
6646
6647GLboolean Context::isSync(GLsync sync)
6648{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006649 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006650}
6651
6652GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6653{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006654 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006655
6656 GLenum result = GL_WAIT_FAILED;
Jamie Madill4f6592f2018-11-27 16:37:45 -05006657 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop())
6658 {
6659 return GL_WAIT_FAILED;
6660 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006661 return result;
6662}
6663
6664void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6665{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006666 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006667 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006668}
6669
6670void Context::getInteger64v(GLenum pname, GLint64 *params)
6671{
6672 GLenum nativeType = GL_NONE;
6673 unsigned int numParams = 0;
6674 getQueryParameterInfo(pname, &nativeType, &numParams);
6675
6676 if (nativeType == GL_INT_64_ANGLEX)
6677 {
6678 getInteger64vImpl(pname, params);
6679 }
6680 else
6681 {
6682 CastStateValues(this, nativeType, pname, numParams, params);
6683 }
6684}
6685
Brandon Jones59770802018-04-02 13:18:42 -07006686void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6687{
6688 getInteger64v(pname, data);
6689}
6690
Corentin Wallez336129f2017-10-17 15:55:40 -04006691void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006692{
6693 Buffer *buffer = mGLState.getTargetBuffer(target);
6694 QueryBufferParameteri64v(buffer, pname, params);
6695}
6696
Brandon Jones59770802018-04-02 13:18:42 -07006697void Context::getBufferParameteri64vRobust(BufferBinding target,
6698 GLenum pname,
6699 GLsizei bufSize,
6700 GLsizei *length,
6701 GLint64 *params)
6702{
6703 getBufferParameteri64v(target, pname, params);
6704}
6705
Jamie Madill3ef140a2017-08-26 23:11:21 -04006706void Context::genSamplers(GLsizei count, GLuint *samplers)
6707{
6708 for (int i = 0; i < count; i++)
6709 {
6710 samplers[i] = mState.mSamplers->createSampler();
6711 }
6712}
6713
6714void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6715{
6716 for (int i = 0; i < count; i++)
6717 {
6718 GLuint sampler = samplers[i];
6719
6720 if (mState.mSamplers->getSampler(sampler))
6721 {
6722 detachSampler(sampler);
6723 }
6724
6725 mState.mSamplers->deleteObject(this, sampler);
6726 }
6727}
6728
6729void Context::getInternalformativ(GLenum target,
6730 GLenum internalformat,
6731 GLenum pname,
6732 GLsizei bufSize,
6733 GLint *params)
6734{
6735 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6736 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6737}
6738
Brandon Jones59770802018-04-02 13:18:42 -07006739void Context::getInternalformativRobust(GLenum target,
6740 GLenum internalformat,
6741 GLenum pname,
6742 GLsizei bufSize,
6743 GLsizei *length,
6744 GLint *params)
6745{
6746 getInternalformativ(target, internalformat, pname, bufSize, params);
6747}
6748
Jiajia Qin5451d532017-11-16 17:16:34 +08006749void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6750{
6751 programUniform1iv(program, location, 1, &v0);
6752}
6753
6754void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6755{
6756 GLint xy[2] = {v0, v1};
6757 programUniform2iv(program, location, 1, xy);
6758}
6759
6760void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6761{
6762 GLint xyz[3] = {v0, v1, v2};
6763 programUniform3iv(program, location, 1, xyz);
6764}
6765
6766void Context::programUniform4i(GLuint program,
6767 GLint location,
6768 GLint v0,
6769 GLint v1,
6770 GLint v2,
6771 GLint v3)
6772{
6773 GLint xyzw[4] = {v0, v1, v2, v3};
6774 programUniform4iv(program, location, 1, xyzw);
6775}
6776
6777void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6778{
6779 programUniform1uiv(program, location, 1, &v0);
6780}
6781
6782void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6783{
6784 GLuint xy[2] = {v0, v1};
6785 programUniform2uiv(program, location, 1, xy);
6786}
6787
6788void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6789{
6790 GLuint xyz[3] = {v0, v1, v2};
6791 programUniform3uiv(program, location, 1, xyz);
6792}
6793
6794void Context::programUniform4ui(GLuint program,
6795 GLint location,
6796 GLuint v0,
6797 GLuint v1,
6798 GLuint v2,
6799 GLuint v3)
6800{
6801 GLuint xyzw[4] = {v0, v1, v2, v3};
6802 programUniform4uiv(program, location, 1, xyzw);
6803}
6804
6805void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6806{
6807 programUniform1fv(program, location, 1, &v0);
6808}
6809
6810void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6811{
6812 GLfloat xy[2] = {v0, v1};
6813 programUniform2fv(program, location, 1, xy);
6814}
6815
6816void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6817{
6818 GLfloat xyz[3] = {v0, v1, v2};
6819 programUniform3fv(program, location, 1, xyz);
6820}
6821
6822void Context::programUniform4f(GLuint program,
6823 GLint location,
6824 GLfloat v0,
6825 GLfloat v1,
6826 GLfloat v2,
6827 GLfloat v3)
6828{
6829 GLfloat xyzw[4] = {v0, v1, v2, v3};
6830 programUniform4fv(program, location, 1, xyzw);
6831}
6832
Jamie Madill81c2e252017-09-09 23:32:46 -04006833void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6834{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006835 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006836 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006837 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006838}
6839
Jiajia Qin5451d532017-11-16 17:16:34 +08006840void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6841{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006842 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006843 ASSERT(programObject);
6844 programObject->setUniform2iv(location, count, value);
6845}
6846
6847void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6848{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006849 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006850 ASSERT(programObject);
6851 programObject->setUniform3iv(location, count, value);
6852}
6853
6854void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6855{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006856 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006857 ASSERT(programObject);
6858 programObject->setUniform4iv(location, count, value);
6859}
6860
6861void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6862{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006863 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006864 ASSERT(programObject);
6865 programObject->setUniform1uiv(location, count, value);
6866}
6867
6868void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6869{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006870 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006871 ASSERT(programObject);
6872 programObject->setUniform2uiv(location, count, value);
6873}
6874
6875void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6876{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006877 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006878 ASSERT(programObject);
6879 programObject->setUniform3uiv(location, count, value);
6880}
6881
6882void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6883{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006884 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006885 ASSERT(programObject);
6886 programObject->setUniform4uiv(location, count, value);
6887}
6888
6889void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6890{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006891 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006892 ASSERT(programObject);
6893 programObject->setUniform1fv(location, count, value);
6894}
6895
6896void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6897{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006898 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006899 ASSERT(programObject);
6900 programObject->setUniform2fv(location, count, value);
6901}
6902
6903void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6904{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006905 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006906 ASSERT(programObject);
6907 programObject->setUniform3fv(location, count, value);
6908}
6909
6910void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6911{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006912 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006913 ASSERT(programObject);
6914 programObject->setUniform4fv(location, count, value);
6915}
6916
6917void Context::programUniformMatrix2fv(GLuint program,
6918 GLint location,
6919 GLsizei count,
6920 GLboolean transpose,
6921 const GLfloat *value)
6922{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006923 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006924 ASSERT(programObject);
6925 programObject->setUniformMatrix2fv(location, count, transpose, value);
6926}
6927
6928void Context::programUniformMatrix3fv(GLuint program,
6929 GLint location,
6930 GLsizei count,
6931 GLboolean transpose,
6932 const GLfloat *value)
6933{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006934 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006935 ASSERT(programObject);
6936 programObject->setUniformMatrix3fv(location, count, transpose, value);
6937}
6938
6939void Context::programUniformMatrix4fv(GLuint program,
6940 GLint location,
6941 GLsizei count,
6942 GLboolean transpose,
6943 const GLfloat *value)
6944{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006945 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006946 ASSERT(programObject);
6947 programObject->setUniformMatrix4fv(location, count, transpose, value);
6948}
6949
6950void Context::programUniformMatrix2x3fv(GLuint program,
6951 GLint location,
6952 GLsizei count,
6953 GLboolean transpose,
6954 const GLfloat *value)
6955{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006956 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006957 ASSERT(programObject);
6958 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6959}
6960
6961void Context::programUniformMatrix3x2fv(GLuint program,
6962 GLint location,
6963 GLsizei count,
6964 GLboolean transpose,
6965 const GLfloat *value)
6966{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006967 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006968 ASSERT(programObject);
6969 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6970}
6971
6972void Context::programUniformMatrix2x4fv(GLuint program,
6973 GLint location,
6974 GLsizei count,
6975 GLboolean transpose,
6976 const GLfloat *value)
6977{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006978 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006979 ASSERT(programObject);
6980 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6981}
6982
6983void Context::programUniformMatrix4x2fv(GLuint program,
6984 GLint location,
6985 GLsizei count,
6986 GLboolean transpose,
6987 const GLfloat *value)
6988{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006989 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006990 ASSERT(programObject);
6991 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6992}
6993
6994void Context::programUniformMatrix3x4fv(GLuint program,
6995 GLint location,
6996 GLsizei count,
6997 GLboolean transpose,
6998 const GLfloat *value)
6999{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007000 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007001 ASSERT(programObject);
7002 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7003}
7004
7005void Context::programUniformMatrix4x3fv(GLuint program,
7006 GLint location,
7007 GLsizei count,
7008 GLboolean transpose,
7009 const GLfloat *value)
7010{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007011 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007012 ASSERT(programObject);
7013 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7014}
7015
Jamie Madill81c2e252017-09-09 23:32:46 -04007016void Context::onTextureChange(const Texture *texture)
7017{
7018 // Conservatively assume all textures are dirty.
7019 // TODO(jmadill): More fine-grained update.
7020 mGLState.setObjectDirty(GL_TEXTURE);
7021}
7022
James Darpiniane8a93c62018-01-04 18:02:24 -08007023bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7024{
7025 return mGLState.isCurrentTransformFeedback(tf);
7026}
James Darpiniane8a93c62018-01-04 18:02:24 -08007027
Yunchao Hea336b902017-08-02 16:05:21 +08007028void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7029{
7030 for (int i = 0; i < count; i++)
7031 {
7032 pipelines[i] = createProgramPipeline();
7033 }
7034}
7035
7036void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7037{
7038 for (int i = 0; i < count; i++)
7039 {
7040 if (pipelines[i] != 0)
7041 {
7042 deleteProgramPipeline(pipelines[i]);
7043 }
7044 }
7045}
7046
7047GLboolean Context::isProgramPipeline(GLuint pipeline)
7048{
7049 if (pipeline == 0)
7050 {
7051 return GL_FALSE;
7052 }
7053
7054 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7055}
7056
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007057void Context::finishFenceNV(GLuint fence)
7058{
7059 FenceNV *fenceObject = getFenceNV(fence);
7060
7061 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007062 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007063}
7064
7065void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7066{
7067 FenceNV *fenceObject = getFenceNV(fence);
7068
7069 ASSERT(fenceObject && fenceObject->isSet());
7070
7071 switch (pname)
7072 {
7073 case GL_FENCE_STATUS_NV:
7074 {
7075 // GL_NV_fence spec:
7076 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7077 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7078 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7079 GLboolean status = GL_TRUE;
7080 if (fenceObject->getStatus() != GL_TRUE)
7081 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007082 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007083 }
7084 *params = status;
7085 break;
7086 }
7087
7088 case GL_FENCE_CONDITION_NV:
7089 {
7090 *params = static_cast<GLint>(fenceObject->getCondition());
7091 break;
7092 }
7093
7094 default:
7095 UNREACHABLE();
7096 }
7097}
7098
7099void Context::getTranslatedShaderSource(GLuint shader,
7100 GLsizei bufsize,
7101 GLsizei *length,
7102 GLchar *source)
7103{
7104 Shader *shaderObject = getShader(shader);
7105 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007106 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007107}
7108
7109void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7110{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007111 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007112 ASSERT(programObject);
7113
7114 programObject->getUniformfv(this, location, params);
7115}
7116
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007117void Context::getnUniformfvRobust(GLuint program,
7118 GLint location,
7119 GLsizei bufSize,
7120 GLsizei *length,
7121 GLfloat *params)
7122{
7123 UNIMPLEMENTED();
7124}
7125
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007126void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7127{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007128 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007129 ASSERT(programObject);
7130
7131 programObject->getUniformiv(this, location, params);
7132}
7133
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007134void Context::getnUniformivRobust(GLuint program,
7135 GLint location,
7136 GLsizei bufSize,
7137 GLsizei *length,
7138 GLint *params)
7139{
7140 UNIMPLEMENTED();
7141}
7142
7143void Context::getnUniformuivRobust(GLuint program,
7144 GLint location,
7145 GLsizei bufSize,
7146 GLsizei *length,
7147 GLuint *params)
7148{
7149 UNIMPLEMENTED();
7150}
7151
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007152GLboolean Context::isFenceNV(GLuint fence)
7153{
7154 FenceNV *fenceObject = getFenceNV(fence);
7155
7156 if (fenceObject == nullptr)
7157 {
7158 return GL_FALSE;
7159 }
7160
7161 // GL_NV_fence spec:
7162 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7163 // existing fence.
7164 return fenceObject->isSet();
7165}
7166
7167void Context::readnPixels(GLint x,
7168 GLint y,
7169 GLsizei width,
7170 GLsizei height,
7171 GLenum format,
7172 GLenum type,
7173 GLsizei bufSize,
7174 void *data)
7175{
7176 return readPixels(x, y, width, height, format, type, data);
7177}
7178
Jamie Madill007530e2017-12-28 14:27:04 -05007179void Context::setFenceNV(GLuint fence, GLenum condition)
7180{
7181 ASSERT(condition == GL_ALL_COMPLETED_NV);
7182
7183 FenceNV *fenceObject = getFenceNV(fence);
7184 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007185 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007186}
7187
7188GLboolean Context::testFenceNV(GLuint fence)
7189{
7190 FenceNV *fenceObject = getFenceNV(fence);
7191
7192 ASSERT(fenceObject != nullptr);
7193 ASSERT(fenceObject->isSet() == GL_TRUE);
7194
7195 GLboolean result = GL_TRUE;
Jamie Madill4f6592f2018-11-27 16:37:45 -05007196 if (fenceObject->test(this, &result) == angle::Result::Stop())
Jamie Madill007530e2017-12-28 14:27:04 -05007197 {
Jamie Madill007530e2017-12-28 14:27:04 -05007198 return GL_TRUE;
7199 }
7200
7201 return result;
7202}
7203
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007204void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007205{
7206 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007207 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007208 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007209}
7210
Jamie Madillfa920eb2018-01-04 11:45:50 -05007211void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007212{
7213 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007214 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007215 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007216}
7217
Jamie Madillfa920eb2018-01-04 11:45:50 -05007218void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7219{
7220 UNIMPLEMENTED();
7221}
7222
Jamie Madill5b772312018-03-08 20:28:32 -05007223bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7224{
7225 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7226 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7227 // to the fact that it is stored internally as a float, and so would require conversion
7228 // if returned from Context::getIntegerv. Since this conversion is already implemented
7229 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7230 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7231 // application.
7232 switch (pname)
7233 {
7234 case GL_COMPRESSED_TEXTURE_FORMATS:
7235 {
7236 *type = GL_INT;
7237 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7238 return true;
7239 }
7240 case GL_SHADER_BINARY_FORMATS:
7241 {
7242 *type = GL_INT;
7243 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7244 return true;
7245 }
7246
7247 case GL_MAX_VERTEX_ATTRIBS:
7248 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7249 case GL_MAX_VARYING_VECTORS:
7250 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7251 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7252 case GL_MAX_TEXTURE_IMAGE_UNITS:
7253 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7254 case GL_MAX_RENDERBUFFER_SIZE:
7255 case GL_NUM_SHADER_BINARY_FORMATS:
7256 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7257 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007258 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7259 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007260 case GL_RENDERBUFFER_BINDING:
7261 case GL_CURRENT_PROGRAM:
7262 case GL_PACK_ALIGNMENT:
7263 case GL_UNPACK_ALIGNMENT:
7264 case GL_GENERATE_MIPMAP_HINT:
7265 case GL_RED_BITS:
7266 case GL_GREEN_BITS:
7267 case GL_BLUE_BITS:
7268 case GL_ALPHA_BITS:
7269 case GL_DEPTH_BITS:
7270 case GL_STENCIL_BITS:
7271 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7272 case GL_CULL_FACE_MODE:
7273 case GL_FRONT_FACE:
7274 case GL_ACTIVE_TEXTURE:
7275 case GL_STENCIL_FUNC:
7276 case GL_STENCIL_VALUE_MASK:
7277 case GL_STENCIL_REF:
7278 case GL_STENCIL_FAIL:
7279 case GL_STENCIL_PASS_DEPTH_FAIL:
7280 case GL_STENCIL_PASS_DEPTH_PASS:
7281 case GL_STENCIL_BACK_FUNC:
7282 case GL_STENCIL_BACK_VALUE_MASK:
7283 case GL_STENCIL_BACK_REF:
7284 case GL_STENCIL_BACK_FAIL:
7285 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7286 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7287 case GL_DEPTH_FUNC:
7288 case GL_BLEND_SRC_RGB:
7289 case GL_BLEND_SRC_ALPHA:
7290 case GL_BLEND_DST_RGB:
7291 case GL_BLEND_DST_ALPHA:
7292 case GL_BLEND_EQUATION_RGB:
7293 case GL_BLEND_EQUATION_ALPHA:
7294 case GL_STENCIL_WRITEMASK:
7295 case GL_STENCIL_BACK_WRITEMASK:
7296 case GL_STENCIL_CLEAR_VALUE:
7297 case GL_SUBPIXEL_BITS:
7298 case GL_MAX_TEXTURE_SIZE:
7299 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7300 case GL_SAMPLE_BUFFERS:
7301 case GL_SAMPLES:
7302 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7303 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7304 case GL_TEXTURE_BINDING_2D:
7305 case GL_TEXTURE_BINDING_CUBE_MAP:
7306 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7307 {
7308 *type = GL_INT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7313 {
7314 if (!getExtensions().packReverseRowOrder)
7315 {
7316 return false;
7317 }
7318 *type = GL_INT;
7319 *numParams = 1;
7320 return true;
7321 }
7322 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7323 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7324 {
7325 if (!getExtensions().textureRectangle)
7326 {
7327 return false;
7328 }
7329 *type = GL_INT;
7330 *numParams = 1;
7331 return true;
7332 }
7333 case GL_MAX_DRAW_BUFFERS_EXT:
7334 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7335 {
7336 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7337 {
7338 return false;
7339 }
7340 *type = GL_INT;
7341 *numParams = 1;
7342 return true;
7343 }
7344 case GL_MAX_VIEWPORT_DIMS:
7345 {
7346 *type = GL_INT;
7347 *numParams = 2;
7348 return true;
7349 }
7350 case GL_VIEWPORT:
7351 case GL_SCISSOR_BOX:
7352 {
7353 *type = GL_INT;
7354 *numParams = 4;
7355 return true;
7356 }
7357 case GL_SHADER_COMPILER:
7358 case GL_SAMPLE_COVERAGE_INVERT:
7359 case GL_DEPTH_WRITEMASK:
7360 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7361 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7362 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7363 // bool-natural
7364 case GL_SAMPLE_COVERAGE:
7365 case GL_SCISSOR_TEST:
7366 case GL_STENCIL_TEST:
7367 case GL_DEPTH_TEST:
7368 case GL_BLEND:
7369 case GL_DITHER:
7370 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7371 {
7372 *type = GL_BOOL;
7373 *numParams = 1;
7374 return true;
7375 }
7376 case GL_COLOR_WRITEMASK:
7377 {
7378 *type = GL_BOOL;
7379 *numParams = 4;
7380 return true;
7381 }
7382 case GL_POLYGON_OFFSET_FACTOR:
7383 case GL_POLYGON_OFFSET_UNITS:
7384 case GL_SAMPLE_COVERAGE_VALUE:
7385 case GL_DEPTH_CLEAR_VALUE:
7386 case GL_LINE_WIDTH:
7387 {
7388 *type = GL_FLOAT;
7389 *numParams = 1;
7390 return true;
7391 }
7392 case GL_ALIASED_LINE_WIDTH_RANGE:
7393 case GL_ALIASED_POINT_SIZE_RANGE:
7394 case GL_DEPTH_RANGE:
7395 {
7396 *type = GL_FLOAT;
7397 *numParams = 2;
7398 return true;
7399 }
7400 case GL_COLOR_CLEAR_VALUE:
7401 case GL_BLEND_COLOR:
7402 {
7403 *type = GL_FLOAT;
7404 *numParams = 4;
7405 return true;
7406 }
7407 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7408 if (!getExtensions().textureFilterAnisotropic)
7409 {
7410 return false;
7411 }
7412 *type = GL_FLOAT;
7413 *numParams = 1;
7414 return true;
7415 case GL_TIMESTAMP_EXT:
7416 if (!getExtensions().disjointTimerQuery)
7417 {
7418 return false;
7419 }
7420 *type = GL_INT_64_ANGLEX;
7421 *numParams = 1;
7422 return true;
7423 case GL_GPU_DISJOINT_EXT:
7424 if (!getExtensions().disjointTimerQuery)
7425 {
7426 return false;
7427 }
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 case GL_COVERAGE_MODULATION_CHROMIUM:
7432 if (!getExtensions().framebufferMixedSamples)
7433 {
7434 return false;
7435 }
7436 *type = GL_INT;
7437 *numParams = 1;
7438 return true;
7439 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7440 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7441 {
7442 return false;
7443 }
7444 *type = GL_INT;
7445 *numParams = 1;
7446 return true;
7447 }
7448
7449 if (getExtensions().debug)
7450 {
7451 switch (pname)
7452 {
7453 case GL_DEBUG_LOGGED_MESSAGES:
7454 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7455 case GL_DEBUG_GROUP_STACK_DEPTH:
7456 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7457 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7458 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7459 case GL_MAX_LABEL_LENGTH:
7460 *type = GL_INT;
7461 *numParams = 1;
7462 return true;
7463
7464 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7465 case GL_DEBUG_OUTPUT:
7466 *type = GL_BOOL;
7467 *numParams = 1;
7468 return true;
7469 }
7470 }
7471
7472 if (getExtensions().multisampleCompatibility)
7473 {
7474 switch (pname)
7475 {
7476 case GL_MULTISAMPLE_EXT:
7477 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7478 *type = GL_BOOL;
7479 *numParams = 1;
7480 return true;
7481 }
7482 }
7483
7484 if (getExtensions().pathRendering)
7485 {
7486 switch (pname)
7487 {
7488 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7489 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7490 *type = GL_FLOAT;
7491 *numParams = 16;
7492 return true;
7493 }
7494 }
7495
7496 if (getExtensions().bindGeneratesResource)
7497 {
7498 switch (pname)
7499 {
7500 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7501 *type = GL_BOOL;
7502 *numParams = 1;
7503 return true;
7504 }
7505 }
7506
7507 if (getExtensions().clientArrays)
7508 {
7509 switch (pname)
7510 {
7511 case GL_CLIENT_ARRAYS_ANGLE:
7512 *type = GL_BOOL;
7513 *numParams = 1;
7514 return true;
7515 }
7516 }
7517
7518 if (getExtensions().sRGBWriteControl)
7519 {
7520 switch (pname)
7521 {
7522 case GL_FRAMEBUFFER_SRGB_EXT:
7523 *type = GL_BOOL;
7524 *numParams = 1;
7525 return true;
7526 }
7527 }
7528
7529 if (getExtensions().robustResourceInitialization &&
7530 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7531 {
7532 *type = GL_BOOL;
7533 *numParams = 1;
7534 return true;
7535 }
7536
7537 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7538 {
7539 *type = GL_BOOL;
7540 *numParams = 1;
7541 return true;
7542 }
7543
jchen1082af6202018-06-22 10:59:52 +08007544 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7545 {
7546 *type = GL_INT;
7547 *numParams = 1;
7548 return true;
7549 }
7550
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007551 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7552 {
7553 *type = GL_INT;
7554 *numParams = 1;
7555 return true;
7556 }
7557
Jamie Madill5b772312018-03-08 20:28:32 -05007558 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7559 switch (pname)
7560 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007561 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007562 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7563 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7564 {
7565 return false;
7566 }
7567 *type = GL_INT;
7568 *numParams = 1;
7569 return true;
7570
7571 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7572 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7573 {
7574 return false;
7575 }
7576 *type = GL_INT;
7577 *numParams = 1;
7578 return true;
7579
7580 case GL_PROGRAM_BINARY_FORMATS_OES:
7581 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7582 {
7583 return false;
7584 }
7585 *type = GL_INT;
7586 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7587 return true;
7588
7589 case GL_PACK_ROW_LENGTH:
7590 case GL_PACK_SKIP_ROWS:
7591 case GL_PACK_SKIP_PIXELS:
7592 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7593 {
7594 return false;
7595 }
7596 *type = GL_INT;
7597 *numParams = 1;
7598 return true;
7599 case GL_UNPACK_ROW_LENGTH:
7600 case GL_UNPACK_SKIP_ROWS:
7601 case GL_UNPACK_SKIP_PIXELS:
7602 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7603 {
7604 return false;
7605 }
7606 *type = GL_INT;
7607 *numParams = 1;
7608 return true;
7609 case GL_VERTEX_ARRAY_BINDING:
7610 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7611 {
7612 return false;
7613 }
7614 *type = GL_INT;
7615 *numParams = 1;
7616 return true;
7617 case GL_PIXEL_PACK_BUFFER_BINDING:
7618 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7619 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7620 {
7621 return false;
7622 }
7623 *type = GL_INT;
7624 *numParams = 1;
7625 return true;
7626 case GL_MAX_SAMPLES:
7627 {
7628 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7629 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7630 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7631 {
7632 return false;
7633 }
7634 *type = GL_INT;
7635 *numParams = 1;
7636 return true;
7637
7638 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7639 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7640 {
7641 return false;
7642 }
7643 *type = GL_INT;
7644 *numParams = 1;
7645 return true;
7646 }
7647 }
7648
7649 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7650 {
7651 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7652 {
7653 return false;
7654 }
7655 *type = GL_INT;
7656 *numParams = 1;
7657 return true;
7658 }
7659
7660 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7661 {
7662 *type = GL_INT;
7663 *numParams = 1;
7664 return true;
7665 }
7666
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007667 if (getClientVersion() < Version(2, 0))
7668 {
7669 switch (pname)
7670 {
7671 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007672 case GL_CLIENT_ACTIVE_TEXTURE:
7673 case GL_MATRIX_MODE:
7674 case GL_MAX_TEXTURE_UNITS:
7675 case GL_MAX_MODELVIEW_STACK_DEPTH:
7676 case GL_MAX_PROJECTION_STACK_DEPTH:
7677 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007678 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007679 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007680 case GL_VERTEX_ARRAY_STRIDE:
7681 case GL_NORMAL_ARRAY_STRIDE:
7682 case GL_COLOR_ARRAY_STRIDE:
7683 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7684 case GL_VERTEX_ARRAY_SIZE:
7685 case GL_COLOR_ARRAY_SIZE:
7686 case GL_TEXTURE_COORD_ARRAY_SIZE:
7687 case GL_VERTEX_ARRAY_TYPE:
7688 case GL_NORMAL_ARRAY_TYPE:
7689 case GL_COLOR_ARRAY_TYPE:
7690 case GL_TEXTURE_COORD_ARRAY_TYPE:
7691 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7692 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7693 case GL_COLOR_ARRAY_BUFFER_BINDING:
7694 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7695 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7696 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7697 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007698 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007699 case GL_MODELVIEW_STACK_DEPTH:
7700 case GL_PROJECTION_STACK_DEPTH:
7701 case GL_TEXTURE_STACK_DEPTH:
7702 case GL_LOGIC_OP_MODE:
7703 case GL_BLEND_SRC:
7704 case GL_BLEND_DST:
7705 case GL_PERSPECTIVE_CORRECTION_HINT:
7706 case GL_POINT_SMOOTH_HINT:
7707 case GL_LINE_SMOOTH_HINT:
7708 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007709 *type = GL_INT;
7710 *numParams = 1;
7711 return true;
7712 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007713 case GL_FOG_DENSITY:
7714 case GL_FOG_START:
7715 case GL_FOG_END:
7716 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007717 case GL_POINT_SIZE:
7718 case GL_POINT_SIZE_MIN:
7719 case GL_POINT_SIZE_MAX:
7720 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007721 *type = GL_FLOAT;
7722 *numParams = 1;
7723 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007724 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007725 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007726 *type = GL_FLOAT;
7727 *numParams = 2;
7728 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007729 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007730 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007731 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007732 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007733 *type = GL_FLOAT;
7734 *numParams = 4;
7735 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007736 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007737 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007738 *type = GL_FLOAT;
7739 *numParams = 3;
7740 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007741 case GL_MODELVIEW_MATRIX:
7742 case GL_PROJECTION_MATRIX:
7743 case GL_TEXTURE_MATRIX:
7744 *type = GL_FLOAT;
7745 *numParams = 16;
7746 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007747 case GL_LIGHT_MODEL_TWO_SIDE:
7748 *type = GL_BOOL;
7749 *numParams = 1;
7750 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007751 }
7752 }
7753
Jamie Madill5b772312018-03-08 20:28:32 -05007754 if (getClientVersion() < Version(3, 0))
7755 {
7756 return false;
7757 }
7758
7759 // Check for ES3.0+ parameter names
7760 switch (pname)
7761 {
7762 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7763 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7764 case GL_UNIFORM_BUFFER_BINDING:
7765 case GL_TRANSFORM_FEEDBACK_BINDING:
7766 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7767 case GL_COPY_READ_BUFFER_BINDING:
7768 case GL_COPY_WRITE_BUFFER_BINDING:
7769 case GL_SAMPLER_BINDING:
7770 case GL_READ_BUFFER:
7771 case GL_TEXTURE_BINDING_3D:
7772 case GL_TEXTURE_BINDING_2D_ARRAY:
7773 case GL_MAX_3D_TEXTURE_SIZE:
7774 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7775 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7776 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7777 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7778 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7779 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7780 case GL_MAX_VARYING_COMPONENTS:
7781 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7782 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7783 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7784 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7785 case GL_NUM_EXTENSIONS:
7786 case GL_MAJOR_VERSION:
7787 case GL_MINOR_VERSION:
7788 case GL_MAX_ELEMENTS_INDICES:
7789 case GL_MAX_ELEMENTS_VERTICES:
7790 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7791 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7792 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7793 case GL_UNPACK_IMAGE_HEIGHT:
7794 case GL_UNPACK_SKIP_IMAGES:
7795 {
7796 *type = GL_INT;
7797 *numParams = 1;
7798 return true;
7799 }
7800
7801 case GL_MAX_ELEMENT_INDEX:
7802 case GL_MAX_UNIFORM_BLOCK_SIZE:
7803 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7804 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7805 case GL_MAX_SERVER_WAIT_TIMEOUT:
7806 {
7807 *type = GL_INT_64_ANGLEX;
7808 *numParams = 1;
7809 return true;
7810 }
7811
7812 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7813 case GL_TRANSFORM_FEEDBACK_PAUSED:
7814 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7815 case GL_RASTERIZER_DISCARD:
7816 {
7817 *type = GL_BOOL;
7818 *numParams = 1;
7819 return true;
7820 }
7821
7822 case GL_MAX_TEXTURE_LOD_BIAS:
7823 {
7824 *type = GL_FLOAT;
7825 *numParams = 1;
7826 return true;
7827 }
7828 }
7829
7830 if (getExtensions().requestExtension)
7831 {
7832 switch (pname)
7833 {
7834 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7835 *type = GL_INT;
7836 *numParams = 1;
7837 return true;
7838 }
7839 }
7840
Yizhou Jiang7818a852018-09-06 15:02:04 +08007841 if (getExtensions().textureMultisample)
7842 {
7843 switch (pname)
7844 {
7845 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7846 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7847 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7848 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007849 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007850 *type = GL_INT;
7851 *numParams = 1;
7852 return true;
7853 }
7854 }
7855
Jamie Madill5b772312018-03-08 20:28:32 -05007856 if (getClientVersion() < Version(3, 1))
7857 {
7858 return false;
7859 }
7860
7861 switch (pname)
7862 {
7863 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7864 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7865 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7866 case GL_MAX_FRAMEBUFFER_WIDTH:
7867 case GL_MAX_FRAMEBUFFER_HEIGHT:
7868 case GL_MAX_FRAMEBUFFER_SAMPLES:
7869 case GL_MAX_SAMPLE_MASK_WORDS:
7870 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7871 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7872 case GL_MAX_INTEGER_SAMPLES:
7873 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7874 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7875 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7876 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7877 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7878 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7879 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7880 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7881 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7882 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7883 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7884 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7885 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7886 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7887 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7888 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7889 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7890 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7891 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7892 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7893 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7894 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7895 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7896 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7897 case GL_MAX_UNIFORM_LOCATIONS:
7898 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7899 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7900 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7901 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7902 case GL_MAX_IMAGE_UNITS:
7903 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7904 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7905 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7906 case GL_SHADER_STORAGE_BUFFER_BINDING:
7907 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7908 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007909 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007910 *type = GL_INT;
7911 *numParams = 1;
7912 return true;
7913 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7914 *type = GL_INT_64_ANGLEX;
7915 *numParams = 1;
7916 return true;
7917 case GL_SAMPLE_MASK:
7918 *type = GL_BOOL;
7919 *numParams = 1;
7920 return true;
7921 }
7922
7923 if (getExtensions().geometryShader)
7924 {
7925 switch (pname)
7926 {
7927 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7928 case GL_LAYER_PROVOKING_VERTEX_EXT:
7929 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7930 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7931 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7932 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7933 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7934 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7935 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7936 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7937 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7938 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7939 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7940 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7941 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7942 *type = GL_INT;
7943 *numParams = 1;
7944 return true;
7945 }
7946 }
7947
7948 return false;
7949}
7950
7951bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7952{
7953 if (getClientVersion() < Version(3, 0))
7954 {
7955 return false;
7956 }
7957
7958 switch (target)
7959 {
7960 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7961 case GL_UNIFORM_BUFFER_BINDING:
7962 {
7963 *type = GL_INT;
7964 *numParams = 1;
7965 return true;
7966 }
7967 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7968 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7969 case GL_UNIFORM_BUFFER_START:
7970 case GL_UNIFORM_BUFFER_SIZE:
7971 {
7972 *type = GL_INT_64_ANGLEX;
7973 *numParams = 1;
7974 return true;
7975 }
7976 }
7977
7978 if (getClientVersion() < Version(3, 1))
7979 {
7980 return false;
7981 }
7982
7983 switch (target)
7984 {
7985 case GL_IMAGE_BINDING_LAYERED:
7986 {
7987 *type = GL_BOOL;
7988 *numParams = 1;
7989 return true;
7990 }
7991 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7992 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7993 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7994 case GL_SHADER_STORAGE_BUFFER_BINDING:
7995 case GL_VERTEX_BINDING_BUFFER:
7996 case GL_VERTEX_BINDING_DIVISOR:
7997 case GL_VERTEX_BINDING_OFFSET:
7998 case GL_VERTEX_BINDING_STRIDE:
7999 case GL_SAMPLE_MASK_VALUE:
8000 case GL_IMAGE_BINDING_NAME:
8001 case GL_IMAGE_BINDING_LEVEL:
8002 case GL_IMAGE_BINDING_LAYER:
8003 case GL_IMAGE_BINDING_ACCESS:
8004 case GL_IMAGE_BINDING_FORMAT:
8005 {
8006 *type = GL_INT;
8007 *numParams = 1;
8008 return true;
8009 }
8010 case GL_ATOMIC_COUNTER_BUFFER_START:
8011 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8012 case GL_SHADER_STORAGE_BUFFER_START:
8013 case GL_SHADER_STORAGE_BUFFER_SIZE:
8014 {
8015 *type = GL_INT_64_ANGLEX;
8016 *numParams = 1;
8017 return true;
8018 }
8019 }
8020
8021 return false;
8022}
8023
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008024Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008025{
8026 return mState.mShaderPrograms->getProgram(handle);
8027}
8028
8029Shader *Context::getShader(GLuint handle) const
8030{
8031 return mState.mShaderPrograms->getShader(handle);
8032}
8033
Jamie Madill5b772312018-03-08 20:28:32 -05008034bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8035{
8036 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8037}
8038
8039bool Context::isFramebufferGenerated(GLuint framebuffer) const
8040{
8041 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8042}
8043
8044bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8045{
8046 return mState.mPipelines->isHandleGenerated(pipeline);
8047}
8048
8049bool Context::usingDisplayTextureShareGroup() const
8050{
8051 return mDisplayTextureShareGroup;
8052}
8053
8054GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8055{
8056 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8057 internalformat == GL_DEPTH_STENCIL
8058 ? GL_DEPTH24_STENCIL8
8059 : internalformat;
8060}
8061
jchen1082af6202018-06-22 10:59:52 +08008062void Context::maxShaderCompilerThreads(GLuint count)
8063{
jchen107ae70d82018-07-06 13:47:01 +08008064 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008065 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008066 // A count of zero specifies a request for no parallel compiling or linking.
8067 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8068 {
8069 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8070 }
8071 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008072}
8073
Jamie Madill2eb65032018-07-30 10:25:57 -04008074bool Context::isGLES1() const
8075{
8076 return mState.getClientVersion() < Version(2, 0);
8077}
8078
Jamie Madilla11819d2018-07-30 10:26:01 -04008079void Context::onSubjectStateChange(const Context *context,
8080 angle::SubjectIndex index,
8081 angle::SubjectMessage message)
8082{
Jamie Madilla11819d2018-07-30 10:26:01 -04008083 switch (index)
8084 {
8085 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008086 switch (message)
8087 {
8088 case angle::SubjectMessage::CONTENTS_CHANGED:
8089 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8090 mStateCache.onVertexArrayBufferContentsChange(this);
8091 break;
8092 case angle::SubjectMessage::RESOURCE_MAPPED:
8093 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8094 case angle::SubjectMessage::BINDING_CHANGED:
8095 mStateCache.onVertexArrayBufferStateChange(this);
8096 break;
8097 default:
8098 break;
8099 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008100 break;
8101
8102 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008103 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8104 {
8105 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8106 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008107 break;
8108
8109 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008110 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8111 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008112 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008113 }
8114 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008115 break;
8116
8117 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008118 if (index < kTextureMaxSubjectIndex)
8119 {
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);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008197 updateValidDrawElementsTypes(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008198}
8199
Jamie Madilldc358af2018-07-31 11:22:13 -04008200void StateCache::updateActiveAttribsMask(Context *context)
8201{
8202 bool isGLES1 = context->isGLES1();
8203 const State &glState = context->getGLState();
8204
8205 if (!isGLES1 && !glState.getProgram())
8206 {
8207 mCachedActiveBufferedAttribsMask = AttributesMask();
8208 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008209 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008210 return;
8211 }
8212
8213 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8214 : glState.getProgram()->getActiveAttribLocationsMask();
8215
8216 const VertexArray *vao = glState.getVertexArray();
8217 ASSERT(vao);
8218
8219 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8220 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008221 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008222
Jamie Madill0a17e482018-08-31 17:19:11 -04008223 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8224 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008225 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008226 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8227}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008228
8229void StateCache::updateVertexElementLimits(Context *context)
8230{
8231 const VertexArray *vao = context->getGLState().getVertexArray();
8232
8233 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8234 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8235
8236 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8237 // If there are no buffered attributes then we should not limit the draw call count.
8238 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8239 {
8240 return;
8241 }
8242
8243 const auto &vertexAttribs = vao->getVertexAttributes();
8244 const auto &vertexBindings = vao->getVertexBindings();
8245
8246 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8247 {
8248 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8249 ASSERT(attrib.enabled);
8250
8251 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8252 ASSERT(context->isGLES1() ||
8253 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8254
8255 GLint64 limit = attrib.getCachedElementLimit();
8256 if (binding.getDivisor() > 0)
8257 {
8258 mCachedInstancedVertexElementLimit =
8259 std::min(mCachedInstancedVertexElementLimit, limit);
8260 }
8261 else
8262 {
8263 mCachedNonInstancedVertexElementLimit =
8264 std::min(mCachedNonInstancedVertexElementLimit, limit);
8265 }
8266 }
8267}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008268
Jamie Madilld84b6732018-09-06 15:54:35 -04008269void StateCache::updateBasicDrawStatesError()
8270{
8271 mCachedBasicDrawStatesError = kInvalidPointer;
8272}
8273
8274intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8275{
8276 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8277 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8278 return mCachedBasicDrawStatesError;
8279}
8280
Jamie Madillc43cdad2018-08-08 15:49:25 -04008281void StateCache::onVertexArrayBindingChange(Context *context)
8282{
8283 updateActiveAttribsMask(context);
8284 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008285 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008286}
8287
8288void StateCache::onProgramExecutableChange(Context *context)
8289{
8290 updateActiveAttribsMask(context);
8291 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008292 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008293 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008294}
8295
Jamie Madilld84b6732018-09-06 15:54:35 -04008296void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008297{
8298 updateVertexElementLimits(context);
8299}
8300
Jamie Madilld84b6732018-09-06 15:54:35 -04008301void StateCache::onVertexArrayBufferContentsChange(Context *context)
8302{
8303 updateVertexElementLimits(context);
8304 updateBasicDrawStatesError();
8305}
8306
Jamie Madillc43cdad2018-08-08 15:49:25 -04008307void StateCache::onVertexArrayStateChange(Context *context)
8308{
8309 updateActiveAttribsMask(context);
8310 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008311 updateBasicDrawStatesError();
8312}
8313
8314void StateCache::onVertexArrayBufferStateChange(Context *context)
8315{
8316 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008317}
8318
8319void StateCache::onGLES1ClientStateChange(Context *context)
8320{
8321 updateActiveAttribsMask(context);
8322}
Jamie Madilld84b6732018-09-06 15:54:35 -04008323
8324void StateCache::onDrawFramebufferChange(Context *context)
8325{
8326 updateBasicDrawStatesError();
8327}
8328
8329void StateCache::onContextCapChange(Context *context)
8330{
8331 updateBasicDrawStatesError();
8332}
8333
8334void StateCache::onStencilStateChange(Context *context)
8335{
8336 updateBasicDrawStatesError();
8337}
8338
8339void StateCache::onDefaultVertexAttributeChange(Context *context)
8340{
8341 updateBasicDrawStatesError();
8342}
8343
8344void StateCache::onActiveTextureChange(Context *context)
8345{
8346 updateBasicDrawStatesError();
8347}
8348
8349void StateCache::onQueryChange(Context *context)
8350{
8351 updateBasicDrawStatesError();
8352}
8353
8354void StateCache::onTransformFeedbackChange(Context *context)
8355{
8356 updateBasicDrawStatesError();
8357}
8358
8359void StateCache::onUniformBufferStateChange(Context *context)
8360{
8361 updateBasicDrawStatesError();
8362}
8363
8364void StateCache::onBufferBindingChange(Context *context)
8365{
8366 updateBasicDrawStatesError();
8367}
Jamie Madill526a6f62018-09-12 11:03:05 -04008368
8369void StateCache::updateValidDrawModes(Context *context)
8370{
8371 Program *program = context->getGLState().getProgram();
8372 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8373 {
Jamie Madill752d2202018-11-27 13:29:48 -05008374 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008375 }
8376 else
8377 {
8378 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8379
8380 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8381
8382 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008383 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8384 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8385 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8386 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8387 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8388 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8389 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8390 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8391 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8392 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8393 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008394 }};
8395 }
8396}
Jamie Madillac66f982018-10-09 18:30:01 -04008397
8398void StateCache::updateValidBindTextureTypes(Context *context)
8399{
8400 const Extensions &exts = context->getExtensions();
8401 bool isGLES3 = context->getClientMajorVersion() >= 3;
8402 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8403
8404 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008405 {TextureType::_2D, true},
8406 {TextureType::_2DArray, isGLES3},
8407 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8408 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8409 {TextureType::_3D, isGLES3},
8410 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8411 {TextureType::Rectangle, exts.textureRectangle},
8412 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008413 }};
8414}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008415
8416void StateCache::updateValidDrawElementsTypes(Context *context)
8417{
8418 bool supportsUint =
8419 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8420
8421 mCachedValidDrawElementsTypes = {{
8422 {DrawElementsType::UnsignedByte, true},
8423 {DrawElementsType::UnsignedShort, true},
8424 {DrawElementsType::UnsignedInt, supportsUint},
8425 }};
8426}
Jamie Madillc29968b2016-01-20 11:17:23 -05008427} // namespace gl