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