blob: 132563a358250d14e0778efd2d58e5e138dced2b [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
Jamie Madillc29968b2016-01-20 11:17:23 -05003566void Context::blitFramebuffer(GLint srcX0,
3567 GLint srcY0,
3568 GLint srcX1,
3569 GLint srcY1,
3570 GLint dstX0,
3571 GLint dstY0,
3572 GLint dstX1,
3573 GLint dstY1,
3574 GLbitfield mask,
3575 GLenum filter)
3576{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003577 if (mask == 0)
3578 {
3579 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3580 // buffers are copied.
3581 return;
3582 }
3583
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003584 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003585 ASSERT(drawFramebuffer);
3586
3587 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3588 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3589
Jamie Madillbc918e72018-03-08 09:47:21 -05003590 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003591
Jamie Madill4f6592f2018-11-27 16:37:45 -05003592 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003593}
Jamie Madillc29968b2016-01-20 11:17:23 -05003594
3595void Context::clear(GLbitfield mask)
3596{
Geoff Langd4fff502017-09-22 11:28:28 -04003597 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3598 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003599}
3600
3601void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3602{
Olli Etuaho78df3362018-10-05 16:43:27 +03003603 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3604 const FramebufferAttachment *attachment = nullptr;
3605 if (buffer == GL_DEPTH)
3606 {
3607 attachment = framebufferObject->getDepthbuffer();
3608 }
3609 if (buffer == GL_COLOR &&
3610 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3611 {
3612 attachment = framebufferObject->getColorbuffer(drawbuffer);
3613 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003614 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3615 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003616 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003617 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003618 return;
3619 }
Geoff Langd4fff502017-09-22 11:28:28 -04003620 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003621 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003622}
3623
3624void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3625{
Olli Etuaho78df3362018-10-05 16:43:27 +03003626 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3627 const FramebufferAttachment *attachment = nullptr;
3628 if (buffer == GL_COLOR &&
3629 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3630 {
3631 attachment = framebufferObject->getColorbuffer(drawbuffer);
3632 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003633 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3634 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003635 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003636 {
3637 return;
3638 }
Geoff Langd4fff502017-09-22 11:28:28 -04003639 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003640 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003641}
3642
3643void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3644{
Olli Etuaho78df3362018-10-05 16:43:27 +03003645 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3646 const FramebufferAttachment *attachment = nullptr;
3647 if (buffer == GL_STENCIL)
3648 {
3649 attachment = framebufferObject->getStencilbuffer();
3650 }
3651 if (buffer == GL_COLOR &&
3652 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3653 {
3654 attachment = framebufferObject->getColorbuffer(drawbuffer);
3655 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003656 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3657 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003658 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003659 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003660 return;
3661 }
Geoff Langd4fff502017-09-22 11:28:28 -04003662 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003663 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003664}
3665
3666void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 ASSERT(framebufferObject);
3670
3671 // If a buffer is not present, the clear has no effect
3672 if (framebufferObject->getDepthbuffer() == nullptr &&
3673 framebufferObject->getStencilbuffer() == nullptr)
3674 {
3675 return;
3676 }
3677
Geoff Langd4fff502017-09-22 11:28:28 -04003678 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3679 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003680}
3681
3682void Context::readPixels(GLint x,
3683 GLint y,
3684 GLsizei width,
3685 GLsizei height,
3686 GLenum format,
3687 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003688 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003689{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003690 if (width == 0 || height == 0)
3691 {
3692 return;
3693 }
3694
Jamie Madillbc918e72018-03-08 09:47:21 -05003695 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003696
Jamie Madillb6664922017-07-25 12:55:04 -04003697 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3698 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003699
3700 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003701 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003702}
3703
Brandon Jones59770802018-04-02 13:18:42 -07003704void Context::readPixelsRobust(GLint x,
3705 GLint y,
3706 GLsizei width,
3707 GLsizei height,
3708 GLenum format,
3709 GLenum type,
3710 GLsizei bufSize,
3711 GLsizei *length,
3712 GLsizei *columns,
3713 GLsizei *rows,
3714 void *pixels)
3715{
3716 readPixels(x, y, width, height, format, type, pixels);
3717}
3718
3719void Context::readnPixelsRobust(GLint x,
3720 GLint y,
3721 GLsizei width,
3722 GLsizei height,
3723 GLenum format,
3724 GLenum type,
3725 GLsizei bufSize,
3726 GLsizei *length,
3727 GLsizei *columns,
3728 GLsizei *rows,
3729 void *data)
3730{
3731 readPixels(x, y, width, height, format, type, data);
3732}
3733
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003734void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 GLint level,
3736 GLenum internalformat,
3737 GLint x,
3738 GLint y,
3739 GLsizei width,
3740 GLsizei height,
3741 GLint border)
3742{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003743 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003744 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003745
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 Rectangle sourceArea(x, y, width, height);
3747
Jamie Madill05b35b22017-10-03 09:01:44 -04003748 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003749 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003750 ANGLE_CONTEXT_TRY(
3751 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003752}
3753
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003754void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 GLint level,
3756 GLint xoffset,
3757 GLint yoffset,
3758 GLint x,
3759 GLint y,
3760 GLsizei width,
3761 GLsizei height)
3762{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003763 if (width == 0 || height == 0)
3764 {
3765 return;
3766 }
3767
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003768 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003769 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770
Jamie Madillc29968b2016-01-20 11:17:23 -05003771 Offset destOffset(xoffset, yoffset, 0);
3772 Rectangle sourceArea(x, y, width, height);
3773
Jamie Madill05b35b22017-10-03 09:01:44 -04003774 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003775 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003776 ANGLE_CONTEXT_TRY(
3777 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003778}
3779
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003780void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003781 GLint level,
3782 GLint xoffset,
3783 GLint yoffset,
3784 GLint zoffset,
3785 GLint x,
3786 GLint y,
3787 GLsizei width,
3788 GLsizei height)
3789{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003790 if (width == 0 || height == 0)
3791 {
3792 return;
3793 }
3794
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003795 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003796 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003797
Jamie Madillc29968b2016-01-20 11:17:23 -05003798 Offset destOffset(xoffset, yoffset, zoffset);
3799 Rectangle sourceArea(x, y, width, height);
3800
Jamie Madill05b35b22017-10-03 09:01:44 -04003801 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3802 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003803 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3804 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003805}
3806
3807void Context::framebufferTexture2D(GLenum target,
3808 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003809 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003810 GLuint texture,
3811 GLint level)
3812{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003814 ASSERT(framebuffer);
3815
3816 if (texture != 0)
3817 {
3818 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003819 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003820 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003821 }
3822 else
3823 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003824 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003825 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003826
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003828}
3829
3830void Context::framebufferRenderbuffer(GLenum target,
3831 GLenum attachment,
3832 GLenum renderbuffertarget,
3833 GLuint renderbuffer)
3834{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003835 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003836 ASSERT(framebuffer);
3837
3838 if (renderbuffer != 0)
3839 {
3840 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003841
Jamie Madillcc129372018-04-12 09:13:18 -04003842 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 renderbufferObject);
3844 }
3845 else
3846 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003847 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003848 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003849
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003851}
3852
3853void Context::framebufferTextureLayer(GLenum target,
3854 GLenum attachment,
3855 GLuint texture,
3856 GLint level,
3857 GLint layer)
3858{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003860 ASSERT(framebuffer);
3861
3862 if (texture != 0)
3863 {
3864 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003865 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003866 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003867 }
3868 else
3869 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003870 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003871 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003872
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003873 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003874}
3875
Brandon Jones59770802018-04-02 13:18:42 -07003876void Context::framebufferTextureMultiviewLayered(GLenum target,
3877 GLenum attachment,
3878 GLuint texture,
3879 GLint level,
3880 GLint baseViewIndex,
3881 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003882{
Martin Radev82ef7742017-08-08 17:44:58 +03003883 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3884 ASSERT(framebuffer);
3885
3886 if (texture != 0)
3887 {
3888 Texture *textureObj = getTexture(texture);
3889
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003890 ImageIndex index;
3891 if (textureObj->getType() == TextureType::_2DArray)
3892 {
3893 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3894 }
3895 else
3896 {
3897 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3898 ASSERT(level == 0);
3899 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3900 }
Martin Radev82ef7742017-08-08 17:44:58 +03003901 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3902 numViews, baseViewIndex);
3903 }
3904 else
3905 {
3906 framebuffer->resetAttachment(this, attachment);
3907 }
3908
3909 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003910}
3911
Brandon Jones59770802018-04-02 13:18:42 -07003912void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3913 GLenum attachment,
3914 GLuint texture,
3915 GLint level,
3916 GLsizei numViews,
3917 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003918{
Martin Radev5dae57b2017-07-14 16:15:55 +03003919 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3920 ASSERT(framebuffer);
3921
3922 if (texture != 0)
3923 {
3924 Texture *textureObj = getTexture(texture);
3925
3926 ImageIndex index = ImageIndex::Make2D(level);
3927 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3928 textureObj, numViews, viewportOffsets);
3929 }
3930 else
3931 {
3932 framebuffer->resetAttachment(this, attachment);
3933 }
3934
3935 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003936}
3937
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003938void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3939{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003940 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3941 ASSERT(framebuffer);
3942
3943 if (texture != 0)
3944 {
3945 Texture *textureObj = getTexture(texture);
3946
3947 ImageIndex index = ImageIndex::MakeFromType(
3948 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3949 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3950 }
3951 else
3952 {
3953 framebuffer->resetAttachment(this, attachment);
3954 }
3955
3956 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003957}
3958
Jamie Madillc29968b2016-01-20 11:17:23 -05003959void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003961 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003962 ASSERT(framebuffer);
3963 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003964 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003965 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003966}
3967
3968void Context::readBuffer(GLenum mode)
3969{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003970 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003971 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003972 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003973}
3974
3975void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3976{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003977 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003978 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003979
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003980 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003981 ASSERT(framebuffer);
3982
3983 // The specification isn't clear what should be done when the framebuffer isn't complete.
3984 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003985 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003986}
3987
3988void Context::invalidateFramebuffer(GLenum target,
3989 GLsizei numAttachments,
3990 const GLenum *attachments)
3991{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003992 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003993 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003994
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003996 ASSERT(framebuffer);
3997
Jamie Madill427064d2018-04-13 16:20:34 -04003998 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003999 {
Jamie Madill437fa652016-05-03 15:13:24 -04004000 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004001 }
Jamie Madill437fa652016-05-03 15:13:24 -04004002
Jamie Madill4f6592f2018-11-27 16:37:45 -05004003 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004004}
4005
4006void Context::invalidateSubFramebuffer(GLenum target,
4007 GLsizei numAttachments,
4008 const GLenum *attachments,
4009 GLint x,
4010 GLint y,
4011 GLsizei width,
4012 GLsizei height)
4013{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004014 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004015 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004016
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004017 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004018 ASSERT(framebuffer);
4019
Jamie Madill427064d2018-04-13 16:20:34 -04004020 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004021 {
Jamie Madill437fa652016-05-03 15:13:24 -04004022 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004023 }
Jamie Madill437fa652016-05-03 15:13:24 -04004024
4025 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004026 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004027}
4028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004029void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004030 GLint level,
4031 GLint internalformat,
4032 GLsizei width,
4033 GLsizei height,
4034 GLint border,
4035 GLenum format,
4036 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004037 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004038{
Jamie Madillbc918e72018-03-08 09:47:21 -05004039 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004040
4041 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004042 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004043 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4044 internalformat, size, format, type,
4045 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004046}
4047
Brandon Jones59770802018-04-02 13:18:42 -07004048void Context::texImage2DRobust(TextureTarget target,
4049 GLint level,
4050 GLint internalformat,
4051 GLsizei width,
4052 GLsizei height,
4053 GLint border,
4054 GLenum format,
4055 GLenum type,
4056 GLsizei bufSize,
4057 const void *pixels)
4058{
4059 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4060}
4061
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004062void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004063 GLint level,
4064 GLint internalformat,
4065 GLsizei width,
4066 GLsizei height,
4067 GLsizei depth,
4068 GLint border,
4069 GLenum format,
4070 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004071 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004072{
Jamie Madillbc918e72018-03-08 09:47:21 -05004073 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004074
4075 Extents size(width, height, depth);
4076 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004077 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4078 NonCubeTextureTypeToTarget(target), level, internalformat,
4079 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004080}
4081
Brandon Jones59770802018-04-02 13:18:42 -07004082void Context::texImage3DRobust(TextureType target,
4083 GLint level,
4084 GLint internalformat,
4085 GLsizei width,
4086 GLsizei height,
4087 GLsizei depth,
4088 GLint border,
4089 GLenum format,
4090 GLenum type,
4091 GLsizei bufSize,
4092 const void *pixels)
4093{
4094 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4095}
4096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004097void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004098 GLint level,
4099 GLint xoffset,
4100 GLint yoffset,
4101 GLsizei width,
4102 GLsizei height,
4103 GLenum format,
4104 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004105 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004106{
4107 // Zero sized uploads are valid but no-ops
4108 if (width == 0 || height == 0)
4109 {
4110 return;
4111 }
4112
Jamie Madillbc918e72018-03-08 09:47:21 -05004113 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004114
4115 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004116 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004117
4118 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4119
Jamie Madill4f6592f2018-11-27 16:37:45 -05004120 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4121 level, area, format, type,
4122 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004123}
4124
Brandon Jones59770802018-04-02 13:18:42 -07004125void Context::texSubImage2DRobust(TextureTarget target,
4126 GLint level,
4127 GLint xoffset,
4128 GLint yoffset,
4129 GLsizei width,
4130 GLsizei height,
4131 GLenum format,
4132 GLenum type,
4133 GLsizei bufSize,
4134 const void *pixels)
4135{
4136 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4137}
4138
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004139void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004140 GLint level,
4141 GLint xoffset,
4142 GLint yoffset,
4143 GLint zoffset,
4144 GLsizei width,
4145 GLsizei height,
4146 GLsizei depth,
4147 GLenum format,
4148 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004149 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004150{
4151 // Zero sized uploads are valid but no-ops
4152 if (width == 0 || height == 0 || depth == 0)
4153 {
4154 return;
4155 }
4156
Jamie Madillbc918e72018-03-08 09:47:21 -05004157 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004158
4159 Box area(xoffset, yoffset, zoffset, width, height, depth);
4160 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004161
4162 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4163
Jamie Madill4f6592f2018-11-27 16:37:45 -05004164 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4165 NonCubeTextureTypeToTarget(target), level, area, format,
4166 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004167}
4168
Brandon Jones59770802018-04-02 13:18:42 -07004169void Context::texSubImage3DRobust(TextureType target,
4170 GLint level,
4171 GLint xoffset,
4172 GLint yoffset,
4173 GLint zoffset,
4174 GLsizei width,
4175 GLsizei height,
4176 GLsizei depth,
4177 GLenum format,
4178 GLenum type,
4179 GLsizei bufSize,
4180 const void *pixels)
4181{
4182 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4183 pixels);
4184}
4185
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004186void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004187 GLint level,
4188 GLenum internalformat,
4189 GLsizei width,
4190 GLsizei height,
4191 GLint border,
4192 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004193 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004194{
Jamie Madillbc918e72018-03-08 09:47:21 -05004195 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004196
4197 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004198 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004199 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4200 internalformat, size, imageSize,
4201 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004202}
4203
Brandon Jones59770802018-04-02 13:18:42 -07004204void Context::compressedTexImage2DRobust(TextureTarget target,
4205 GLint level,
4206 GLenum internalformat,
4207 GLsizei width,
4208 GLsizei height,
4209 GLint border,
4210 GLsizei imageSize,
4211 GLsizei dataSize,
4212 const GLvoid *data)
4213{
4214 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4215}
4216
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004217void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004218 GLint level,
4219 GLenum internalformat,
4220 GLsizei width,
4221 GLsizei height,
4222 GLsizei depth,
4223 GLint border,
4224 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004225 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004226{
Jamie Madillbc918e72018-03-08 09:47:21 -05004227 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004228
4229 Extents size(width, height, depth);
4230 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004231 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004232 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004233 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004234}
4235
Brandon Jones59770802018-04-02 13:18:42 -07004236void Context::compressedTexImage3DRobust(TextureType target,
4237 GLint level,
4238 GLenum internalformat,
4239 GLsizei width,
4240 GLsizei height,
4241 GLsizei depth,
4242 GLint border,
4243 GLsizei imageSize,
4244 GLsizei dataSize,
4245 const GLvoid *data)
4246{
4247 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4248 data);
4249}
4250
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004251void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004252 GLint level,
4253 GLint xoffset,
4254 GLint yoffset,
4255 GLsizei width,
4256 GLsizei height,
4257 GLenum format,
4258 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004259 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004260{
Jamie Madillbc918e72018-03-08 09:47:21 -05004261 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004262
4263 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004264 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004265 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4266 area, format, imageSize,
4267 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004268}
4269
Brandon Jones59770802018-04-02 13:18:42 -07004270void Context::compressedTexSubImage2DRobust(TextureTarget target,
4271 GLint level,
4272 GLint xoffset,
4273 GLint yoffset,
4274 GLsizei width,
4275 GLsizei height,
4276 GLenum format,
4277 GLsizei imageSize,
4278 GLsizei dataSize,
4279 const GLvoid *data)
4280{
4281 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4282 data);
4283}
4284
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004285void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004286 GLint level,
4287 GLint xoffset,
4288 GLint yoffset,
4289 GLint zoffset,
4290 GLsizei width,
4291 GLsizei height,
4292 GLsizei depth,
4293 GLenum format,
4294 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004295 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004296{
4297 // Zero sized uploads are valid but no-ops
4298 if (width == 0 || height == 0)
4299 {
4300 return;
4301 }
4302
Jamie Madillbc918e72018-03-08 09:47:21 -05004303 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004304
4305 Box area(xoffset, yoffset, zoffset, width, height, depth);
4306 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004307 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004308 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004309 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004310}
4311
Brandon Jones59770802018-04-02 13:18:42 -07004312void Context::compressedTexSubImage3DRobust(TextureType target,
4313 GLint level,
4314 GLint xoffset,
4315 GLint yoffset,
4316 GLint zoffset,
4317 GLsizei width,
4318 GLsizei height,
4319 GLsizei depth,
4320 GLenum format,
4321 GLsizei imageSize,
4322 GLsizei dataSize,
4323 const GLvoid *data)
4324{
4325 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4326 imageSize, data);
4327}
4328
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004329void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004330{
4331 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004332 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004333}
4334
Jamie Madill007530e2017-12-28 14:27:04 -05004335void Context::copyTexture(GLuint sourceId,
4336 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004337 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004338 GLuint destId,
4339 GLint destLevel,
4340 GLint internalFormat,
4341 GLenum destType,
4342 GLboolean unpackFlipY,
4343 GLboolean unpackPremultiplyAlpha,
4344 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004345{
Jamie Madillbc918e72018-03-08 09:47:21 -05004346 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004347
4348 gl::Texture *sourceTexture = getTexture(sourceId);
4349 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004350 ANGLE_CONTEXT_TRY(
4351 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4352 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4353 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004354}
4355
Jamie Madill007530e2017-12-28 14:27:04 -05004356void Context::copySubTexture(GLuint sourceId,
4357 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004358 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004359 GLuint destId,
4360 GLint destLevel,
4361 GLint xoffset,
4362 GLint yoffset,
4363 GLint x,
4364 GLint y,
4365 GLsizei width,
4366 GLsizei height,
4367 GLboolean unpackFlipY,
4368 GLboolean unpackPremultiplyAlpha,
4369 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004370{
4371 // Zero sized copies are valid but no-ops
4372 if (width == 0 || height == 0)
4373 {
4374 return;
4375 }
4376
Jamie Madillbc918e72018-03-08 09:47:21 -05004377 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004378
4379 gl::Texture *sourceTexture = getTexture(sourceId);
4380 gl::Texture *destTexture = getTexture(destId);
4381 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004382 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004383 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4384 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4385 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4386 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004387}
4388
4389void Context::copyTexture3D(GLuint sourceId,
4390 GLint sourceLevel,
4391 TextureTarget destTarget,
4392 GLuint destId,
4393 GLint destLevel,
4394 GLint internalFormat,
4395 GLenum destType,
4396 GLboolean unpackFlipY,
4397 GLboolean unpackPremultiplyAlpha,
4398 GLboolean unpackUnmultiplyAlpha)
4399{
4400 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4401
4402 Texture *sourceTexture = getTexture(sourceId);
4403 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004404 ANGLE_CONTEXT_TRY(
4405 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4406 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4407 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004408}
4409
4410void Context::copySubTexture3D(GLuint sourceId,
4411 GLint sourceLevel,
4412 TextureTarget destTarget,
4413 GLuint destId,
4414 GLint destLevel,
4415 GLint xoffset,
4416 GLint yoffset,
4417 GLint zoffset,
4418 GLint x,
4419 GLint y,
4420 GLint z,
4421 GLsizei width,
4422 GLsizei height,
4423 GLsizei depth,
4424 GLboolean unpackFlipY,
4425 GLboolean unpackPremultiplyAlpha,
4426 GLboolean unpackUnmultiplyAlpha)
4427{
4428 // Zero sized copies are valid but no-ops
4429 if (width == 0 || height == 0 || depth == 0)
4430 {
4431 return;
4432 }
4433
4434 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4435
4436 Texture *sourceTexture = getTexture(sourceId);
4437 Texture *destTexture = getTexture(destId);
4438 Offset offset(xoffset, yoffset, zoffset);
4439 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004440 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4441 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4442 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4443 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004444}
4445
Jamie Madill007530e2017-12-28 14:27:04 -05004446void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004447{
Jamie Madillbc918e72018-03-08 09:47:21 -05004448 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004449
4450 gl::Texture *sourceTexture = getTexture(sourceId);
4451 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004452 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004453}
4454
Corentin Wallez336129f2017-10-17 15:55:40 -04004455void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004456{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004457 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004458 ASSERT(buffer);
4459
Geoff Lang496c02d2016-10-20 11:38:11 -07004460 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004461}
4462
Brandon Jones59770802018-04-02 13:18:42 -07004463void Context::getBufferPointervRobust(BufferBinding target,
4464 GLenum pname,
4465 GLsizei bufSize,
4466 GLsizei *length,
4467 void **params)
4468{
4469 getBufferPointerv(target, pname, params);
4470}
4471
Corentin Wallez336129f2017-10-17 15:55:40 -04004472void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004473{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004475 ASSERT(buffer);
4476
Jamie Madill4f6592f2018-11-27 16:37:45 -05004477 if (buffer->map(this, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004478 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004479 return nullptr;
4480 }
4481
4482 return buffer->getMapPointer();
4483}
4484
Corentin Wallez336129f2017-10-17 15:55:40 -04004485GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004488 ASSERT(buffer);
4489
4490 GLboolean result;
Jamie Madill4f6592f2018-11-27 16:37:45 -05004491 if (buffer->unmap(this, &result) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004492 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004493 return GL_FALSE;
4494 }
4495
4496 return result;
4497}
4498
Corentin Wallez336129f2017-10-17 15:55:40 -04004499void *Context::mapBufferRange(BufferBinding target,
4500 GLintptr offset,
4501 GLsizeiptr length,
4502 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004503{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004505 ASSERT(buffer);
4506
Jamie Madill4f6592f2018-11-27 16:37:45 -05004507 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004508 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004509 return nullptr;
4510 }
4511
4512 return buffer->getMapPointer();
4513}
4514
Corentin Wallez336129f2017-10-17 15:55:40 -04004515void Context::flushMappedBufferRange(BufferBinding /*target*/,
4516 GLintptr /*offset*/,
4517 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004518{
4519 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4520}
4521
Jamie Madill526392d2018-11-16 09:35:14 -05004522angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004523{
Geoff Langa8cb2872018-03-09 16:09:40 -05004524 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004525}
4526
Jamie Madill526392d2018-11-16 09:35:14 -05004527angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004528{
Geoff Langa8cb2872018-03-09 16:09:40 -05004529 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004530}
4531
Jamie Madill526392d2018-11-16 09:35:14 -05004532angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004533{
Geoff Langa8cb2872018-03-09 16:09:40 -05004534 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004535}
4536
Jamie Madill526392d2018-11-16 09:35:14 -05004537angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004538{
4539 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4540
4541 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4542 ANGLE_TRY(syncDirtyBits());
4543
Jamie Madill526392d2018-11-16 09:35:14 -05004544 return angle::Result::Continue();
Geoff Lang9bf86f02018-07-26 11:46:34 -04004545}
4546
Jiajia Qin5451d532017-11-16 17:16:34 +08004547void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4548{
4549 UNIMPLEMENTED();
4550}
4551
Jamie Madillc20ab272016-06-09 07:20:46 -07004552void Context::activeTexture(GLenum texture)
4553{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
Jamie Madill876429b2017-04-20 15:46:24 -04004557void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004558{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004560}
4561
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004562void Context::blendEquation(GLenum mode)
4563{
4564 mGLState.setBlendEquation(mode, mode);
4565}
4566
Jamie Madillc20ab272016-06-09 07:20:46 -07004567void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4568{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570}
4571
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004572void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4573{
4574 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4575}
4576
Jamie Madillc20ab272016-06-09 07:20:46 -07004577void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4578{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004579 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580}
4581
Jamie Madill876429b2017-04-20 15:46:24 -04004582void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
Jamie Madill876429b2017-04-20 15:46:24 -04004587void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004588{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004589 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004590}
4591
4592void Context::clearStencil(GLint s)
4593{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004594 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004595}
4596
4597void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4598{
Geoff Lang92019432017-11-20 13:09:34 -05004599 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4600 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004603void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004606}
4607
4608void Context::depthFunc(GLenum func)
4609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
4613void Context::depthMask(GLboolean flag)
4614{
Geoff Lang92019432017-11-20 13:09:34 -05004615 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004616}
4617
Jamie Madill876429b2017-04-20 15:46:24 -04004618void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004619{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004620 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
4623void Context::disable(GLenum cap)
4624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004626 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004627}
4628
4629void Context::disableVertexAttribArray(GLuint index)
4630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004631 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004632 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633}
4634
4635void Context::enable(GLenum cap)
4636{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004638 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639}
4640
4641void Context::enableVertexAttribArray(GLuint index)
4642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004644 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645}
4646
4647void Context::frontFace(GLenum mode)
4648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::hint(GLenum target, GLenum mode)
4653{
4654 switch (target)
4655 {
4656 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658 break;
4659
4660 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662 break;
4663
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004664 case GL_PERSPECTIVE_CORRECTION_HINT:
4665 case GL_POINT_SMOOTH_HINT:
4666 case GL_LINE_SMOOTH_HINT:
4667 case GL_FOG_HINT:
4668 mGLState.gles1().setHint(target, mode);
4669 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004670 default:
4671 UNREACHABLE();
4672 return;
4673 }
4674}
4675
4676void Context::lineWidth(GLfloat width)
4677{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004678 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004679}
4680
4681void Context::pixelStorei(GLenum pname, GLint param)
4682{
4683 switch (pname)
4684 {
4685 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004687 break;
4688
4689 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004690 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004691 break;
4692
4693 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004694 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695 break;
4696
4697 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004698 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004699 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004700 break;
4701
4702 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004703 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004704 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004705 break;
4706
4707 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004708 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004709 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710 break;
4711
4712 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004713 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004715 break;
4716
4717 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004718 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004720 break;
4721
4722 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004723 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004724 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004725 break;
4726
4727 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004728 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004729 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004730 break;
4731
4732 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004733 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004735 break;
4736
4737 default:
4738 UNREACHABLE();
4739 return;
4740 }
4741}
4742
4743void Context::polygonOffset(GLfloat factor, GLfloat units)
4744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004745 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
Jamie Madill876429b2017-04-20 15:46:24 -04004748void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004749{
Geoff Lang92019432017-11-20 13:09:34 -05004750 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004751}
4752
Jiawei Shaodb342272017-09-27 10:21:45 +08004753void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4754{
4755 mGLState.setSampleMaskParams(maskNumber, mask);
4756}
4757
Jamie Madillc20ab272016-06-09 07:20:46 -07004758void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4759{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004760 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004761}
4762
4763void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4764{
4765 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4766 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004767 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768 }
4769
4770 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4771 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004772 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004773 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004774
4775 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004776}
4777
4778void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4779{
4780 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4781 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004782 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004783 }
4784
4785 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4786 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004787 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004788 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004789
4790 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004791}
4792
4793void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4794{
4795 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4796 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004797 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004798 }
4799
4800 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4801 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004802 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803 }
4804}
4805
4806void Context::vertexAttrib1f(GLuint index, GLfloat x)
4807{
4808 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004809 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004810 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004811}
4812
4813void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4814{
4815 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004816 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004817 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004818}
4819
4820void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4821{
4822 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004823 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004824 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004825}
4826
4827void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4828{
4829 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004830 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004831 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004832}
4833
4834void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4835{
4836 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004837 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004838 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004839}
4840
4841void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4842{
4843 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004844 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004845 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004846}
4847
4848void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4849{
4850 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004851 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004852 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004853}
4854
4855void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004857 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004858 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004859}
4860
4861void Context::vertexAttribPointer(GLuint index,
4862 GLint size,
4863 GLenum type,
4864 GLboolean normalized,
4865 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004866 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004867{
Corentin Wallez336129f2017-10-17 15:55:40 -04004868 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004869 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004870 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004871}
4872
Shao80957d92017-02-20 21:25:59 +08004873void Context::vertexAttribFormat(GLuint attribIndex,
4874 GLint size,
4875 GLenum type,
4876 GLboolean normalized,
4877 GLuint relativeOffset)
4878{
Geoff Lang92019432017-11-20 13:09:34 -05004879 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004880 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004881 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004882}
4883
4884void Context::vertexAttribIFormat(GLuint attribIndex,
4885 GLint size,
4886 GLenum type,
4887 GLuint relativeOffset)
4888{
4889 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004890 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004891}
4892
4893void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4894{
Shaodde78e82017-05-22 14:13:27 +08004895 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004896 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004897}
4898
Jiajia Qin5451d532017-11-16 17:16:34 +08004899void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004900{
4901 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004902 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004903}
4904
Jamie Madillc20ab272016-06-09 07:20:46 -07004905void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4906{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004907 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004908}
4909
4910void Context::vertexAttribIPointer(GLuint index,
4911 GLint size,
4912 GLenum type,
4913 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004914 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004915{
Corentin Wallez336129f2017-10-17 15:55:40 -04004916 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4917 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004918 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004919}
4920
4921void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4922{
4923 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004924 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004925 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004926}
4927
4928void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4929{
4930 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004931 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004932 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004933}
4934
4935void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4936{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004937 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004938 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004939}
4940
4941void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4942{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004943 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004944 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004945}
4946
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004947void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4948{
4949 const VertexAttribCurrentValueData &currentValues =
4950 getGLState().getVertexAttribCurrentValue(index);
4951 const VertexArray *vao = getGLState().getVertexArray();
4952 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4953 currentValues, pname, params);
4954}
4955
Brandon Jones59770802018-04-02 13:18:42 -07004956void Context::getVertexAttribivRobust(GLuint index,
4957 GLenum pname,
4958 GLsizei bufSize,
4959 GLsizei *length,
4960 GLint *params)
4961{
4962 getVertexAttribiv(index, pname, params);
4963}
4964
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004965void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4966{
4967 const VertexAttribCurrentValueData &currentValues =
4968 getGLState().getVertexAttribCurrentValue(index);
4969 const VertexArray *vao = getGLState().getVertexArray();
4970 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4971 currentValues, pname, params);
4972}
4973
Brandon Jones59770802018-04-02 13:18:42 -07004974void Context::getVertexAttribfvRobust(GLuint index,
4975 GLenum pname,
4976 GLsizei bufSize,
4977 GLsizei *length,
4978 GLfloat *params)
4979{
4980 getVertexAttribfv(index, pname, params);
4981}
4982
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004983void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4984{
4985 const VertexAttribCurrentValueData &currentValues =
4986 getGLState().getVertexAttribCurrentValue(index);
4987 const VertexArray *vao = getGLState().getVertexArray();
4988 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4989 currentValues, pname, params);
4990}
4991
Brandon Jones59770802018-04-02 13:18:42 -07004992void Context::getVertexAttribIivRobust(GLuint index,
4993 GLenum pname,
4994 GLsizei bufSize,
4995 GLsizei *length,
4996 GLint *params)
4997{
4998 getVertexAttribIiv(index, pname, params);
4999}
5000
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005001void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5002{
5003 const VertexAttribCurrentValueData &currentValues =
5004 getGLState().getVertexAttribCurrentValue(index);
5005 const VertexArray *vao = getGLState().getVertexArray();
5006 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5007 currentValues, pname, params);
5008}
5009
Brandon Jones59770802018-04-02 13:18:42 -07005010void Context::getVertexAttribIuivRobust(GLuint index,
5011 GLenum pname,
5012 GLsizei bufSize,
5013 GLsizei *length,
5014 GLuint *params)
5015{
5016 getVertexAttribIuiv(index, pname, params);
5017}
5018
Jamie Madill876429b2017-04-20 15:46:24 -04005019void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005020{
5021 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5022 QueryVertexAttribPointerv(attrib, pname, pointer);
5023}
5024
Brandon Jones59770802018-04-02 13:18:42 -07005025void Context::getVertexAttribPointervRobust(GLuint index,
5026 GLenum pname,
5027 GLsizei bufSize,
5028 GLsizei *length,
5029 void **pointer)
5030{
5031 getVertexAttribPointerv(index, pname, pointer);
5032}
5033
Jamie Madillc20ab272016-06-09 07:20:46 -07005034void Context::debugMessageControl(GLenum source,
5035 GLenum type,
5036 GLenum severity,
5037 GLsizei count,
5038 const GLuint *ids,
5039 GLboolean enabled)
5040{
5041 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005042 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005043 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005044}
5045
5046void Context::debugMessageInsert(GLenum source,
5047 GLenum type,
5048 GLuint id,
5049 GLenum severity,
5050 GLsizei length,
5051 const GLchar *buf)
5052{
5053 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005054 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005055}
5056
5057void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5058{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005059 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005060}
5061
5062GLuint Context::getDebugMessageLog(GLuint count,
5063 GLsizei bufSize,
5064 GLenum *sources,
5065 GLenum *types,
5066 GLuint *ids,
5067 GLenum *severities,
5068 GLsizei *lengths,
5069 GLchar *messageLog)
5070{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005071 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5072 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005073}
5074
5075void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5076{
5077 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005078 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005079 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005080}
5081
5082void Context::popDebugGroup()
5083{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005084 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005085 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005086}
5087
Corentin Wallez336129f2017-10-17 15:55:40 -04005088void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005089{
5090 Buffer *buffer = mGLState.getTargetBuffer(target);
5091 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005092 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005093}
5094
Corentin Wallez336129f2017-10-17 15:55:40 -04005095void Context::bufferSubData(BufferBinding target,
5096 GLintptr offset,
5097 GLsizeiptr size,
5098 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005099{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005100 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005101 {
5102 return;
5103 }
5104
5105 Buffer *buffer = mGLState.getTargetBuffer(target);
5106 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005107 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005108}
5109
Jamie Madillef300b12016-10-07 15:12:09 -04005110void Context::attachShader(GLuint program, GLuint shader)
5111{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005112 Program *programObject = mState.mShaderPrograms->getProgram(program);
5113 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005114 ASSERT(programObject && shaderObject);
5115 programObject->attachShader(shaderObject);
5116}
5117
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005118const Workarounds &Context::getWorkarounds() const
5119{
5120 return mWorkarounds;
5121}
5122
Corentin Wallez336129f2017-10-17 15:55:40 -04005123void Context::copyBufferSubData(BufferBinding readTarget,
5124 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005125 GLintptr readOffset,
5126 GLintptr writeOffset,
5127 GLsizeiptr size)
5128{
5129 // if size is zero, the copy is a successful no-op
5130 if (size == 0)
5131 {
5132 return;
5133 }
5134
5135 // TODO(jmadill): cache these.
5136 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5137 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5138
Jamie Madill4f6592f2018-11-27 16:37:45 -05005139 ANGLE_CONTEXT_TRY(
5140 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005141}
5142
Jamie Madill01a80ee2016-11-07 12:06:18 -05005143void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5144{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005145 // Ideally we could share the program query with the validation layer if possible.
5146 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005147 ASSERT(programObject);
5148 programObject->bindAttributeLocation(index, name);
5149}
5150
Corentin Wallez336129f2017-10-17 15:55:40 -04005151void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005152{
Corentin Wallez336129f2017-10-17 15:55:40 -04005153 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5154 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005155 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005156}
5157
Corentin Wallez336129f2017-10-17 15:55:40 -04005158void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005159{
5160 bindBufferRange(target, index, buffer, 0, 0);
5161}
5162
Corentin Wallez336129f2017-10-17 15:55:40 -04005163void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005164 GLuint index,
5165 GLuint buffer,
5166 GLintptr offset,
5167 GLsizeiptr size)
5168{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005169 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5170 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5171 if (target == BufferBinding::Uniform)
5172 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005173 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005174 mStateCache.onUniformBufferStateChange(this);
5175 }
5176 else
5177 {
5178 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005179 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005180}
5181
Jamie Madill01a80ee2016-11-07 12:06:18 -05005182void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5183{
5184 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5185 {
5186 bindReadFramebuffer(framebuffer);
5187 }
5188
5189 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5190 {
5191 bindDrawFramebuffer(framebuffer);
5192 }
5193}
5194
5195void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5196{
5197 ASSERT(target == GL_RENDERBUFFER);
5198 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005199 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005200 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005201}
5202
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005203void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005204 GLsizei samples,
5205 GLenum internalformat,
5206 GLsizei width,
5207 GLsizei height,
5208 GLboolean fixedsamplelocations)
5209{
5210 Extents size(width, height, 1);
5211 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005212 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5213 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005214}
5215
Olli Etuaho89664842018-08-24 14:45:36 +03005216void Context::texStorage3DMultisample(TextureType target,
5217 GLsizei samples,
5218 GLenum internalformat,
5219 GLsizei width,
5220 GLsizei height,
5221 GLsizei depth,
5222 GLboolean fixedsamplelocations)
5223{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005224 Extents size(width, height, depth);
5225 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005226 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5227 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005228}
5229
JiangYizhoubddc46b2016-12-09 09:50:51 +08005230void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5231{
JiangYizhou5b03f472017-01-09 10:22:53 +08005232 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5233 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005234 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005235 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005236
5237 switch (pname)
5238 {
5239 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005240 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005241 break;
5242 default:
5243 UNREACHABLE();
5244 }
5245}
5246
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005247void Context::getMultisamplefvRobust(GLenum pname,
5248 GLuint index,
5249 GLsizei bufSize,
5250 GLsizei *length,
5251 GLfloat *val)
5252{
5253 UNIMPLEMENTED();
5254}
5255
Jamie Madille8fb6402017-02-14 17:56:40 -05005256void Context::renderbufferStorage(GLenum target,
5257 GLenum internalformat,
5258 GLsizei width,
5259 GLsizei height)
5260{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005261 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5262 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5263
Jamie Madille8fb6402017-02-14 17:56:40 -05005264 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005265 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005266}
5267
5268void Context::renderbufferStorageMultisample(GLenum target,
5269 GLsizei samples,
5270 GLenum internalformat,
5271 GLsizei width,
5272 GLsizei height)
5273{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005274 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5275 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005276
5277 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005278 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005279 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005280}
5281
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005282void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5283{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005284 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005285 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005286}
5287
JiangYizhoue18e6392017-02-20 10:32:23 +08005288void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5289{
5290 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5291 QueryFramebufferParameteriv(framebuffer, pname, params);
5292}
5293
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005294void Context::getFramebufferParameterivRobust(GLenum target,
5295 GLenum pname,
5296 GLsizei bufSize,
5297 GLsizei *length,
5298 GLint *params)
5299{
5300 UNIMPLEMENTED();
5301}
5302
Jiajia Qin5451d532017-11-16 17:16:34 +08005303void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005304{
5305 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005306 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005307}
5308
Jamie Madilldec86232018-07-11 09:01:18 -04005309bool Context::getScratchBuffer(size_t requstedSizeBytes,
5310 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005311{
Jamie Madilldec86232018-07-11 09:01:18 -04005312 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005313}
5314
Jamie Madilldec86232018-07-11 09:01:18 -04005315bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5316 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005317{
Jamie Madilldec86232018-07-11 09:01:18 -04005318 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005319}
5320
Jamie Madill526392d2018-11-16 09:35:14 -05005321angle::Result Context::prepareForDispatch()
Xinghua Cao10a4d432017-11-28 14:46:26 +08005322{
Jamie Madill0cc11c62018-10-12 18:07:18 -04005323 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005324
5325 if (isRobustResourceInitEnabled())
5326 {
5327 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5328 }
5329
Jamie Madill0cc11c62018-10-12 18:07:18 -04005330 return syncDirtyBits(mComputeDirtyBits);
Xinghua Cao10a4d432017-11-28 14:46:26 +08005331}
5332
Xinghua Cao2b396592017-03-29 15:36:04 +08005333void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5334{
5335 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5336 {
5337 return;
5338 }
5339
Xinghua Cao10a4d432017-11-28 14:46:26 +08005340 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005341 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005342}
5343
Jiajia Qin5451d532017-11-16 17:16:34 +08005344void Context::dispatchComputeIndirect(GLintptr indirect)
5345{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005346 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005347 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005348}
5349
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005350void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005351 GLsizei levels,
5352 GLenum internalFormat,
5353 GLsizei width,
5354 GLsizei height)
5355{
5356 Extents size(width, height, 1);
5357 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005358 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005359}
5360
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005361void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005362 GLsizei levels,
5363 GLenum internalFormat,
5364 GLsizei width,
5365 GLsizei height,
5366 GLsizei depth)
5367{
5368 Extents size(width, height, depth);
5369 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005370 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005371}
5372
Jiajia Qin5451d532017-11-16 17:16:34 +08005373void Context::memoryBarrier(GLbitfield barriers)
5374{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005375 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005376}
5377
5378void Context::memoryBarrierByRegion(GLbitfield barriers)
5379{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005380 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005381}
5382
Austin Eng1bf18ce2018-10-19 15:34:02 -07005383void Context::multiDrawArrays(PrimitiveMode mode,
5384 const GLint *firsts,
5385 const GLsizei *counts,
5386 GLsizei drawcount)
5387{
5388 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5389 Program *programObject = mGLState.getLinkedProgram(this);
5390 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5391 if (hasDrawID)
5392 {
5393 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5394 {
5395 if (noopDraw(mode, counts[drawID]))
5396 {
5397 continue;
5398 }
5399 programObject->setDrawIDUniform(drawID);
5400 ANGLE_CONTEXT_TRY(
5401 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5402 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5403 counts[drawID], 1);
5404 }
5405 }
5406 else
5407 {
5408 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5409 {
5410 if (noopDraw(mode, counts[drawID]))
5411 {
5412 continue;
5413 }
5414 ANGLE_CONTEXT_TRY(
5415 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5416 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5417 counts[drawID], 1);
5418 }
5419 }
5420}
5421
5422void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5423 const GLint *firsts,
5424 const GLsizei *counts,
5425 const GLsizei *instanceCounts,
5426 GLsizei drawcount)
5427{
5428 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5429 Program *programObject = mGLState.getLinkedProgram(this);
5430 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5431 if (hasDrawID)
5432 {
5433 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5434 {
5435 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5436 {
5437 continue;
5438 }
5439 programObject->setDrawIDUniform(drawID);
5440 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5441 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5442 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5443 counts[drawID], instanceCounts[drawID]);
5444 }
5445 }
5446 else
5447 {
5448 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5449 {
5450 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5451 {
5452 continue;
5453 }
5454 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5455 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5456 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5457 counts[drawID], instanceCounts[drawID]);
5458 }
5459 }
5460}
5461
5462void Context::multiDrawElements(PrimitiveMode mode,
5463 const GLsizei *counts,
5464 GLenum type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005465 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005466 GLsizei drawcount)
5467{
5468 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5469 Program *programObject = mGLState.getLinkedProgram(this);
5470 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5471 if (hasDrawID)
5472 {
5473 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5474 {
5475 if (noopDraw(mode, counts[drawID]))
5476 {
5477 continue;
5478 }
5479 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005480 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005481 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005482 }
5483 }
5484 else
5485 {
5486 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5487 {
5488 if (noopDraw(mode, counts[drawID]))
5489 {
5490 continue;
5491 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005492 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005493 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005494 }
5495 }
5496}
5497
5498void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5499 const GLsizei *counts,
5500 GLenum type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005501 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005502 const GLsizei *instanceCounts,
5503 GLsizei drawcount)
5504{
5505 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5506 Program *programObject = mGLState.getLinkedProgram(this);
5507 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5508 if (hasDrawID)
5509 {
5510 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5511 {
5512 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5513 {
5514 continue;
5515 }
5516 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005517 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005518 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005519 }
5520 }
5521 else
5522 {
5523 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5524 {
5525 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5526 {
5527 continue;
5528 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005529 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005530 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005531 }
5532 }
5533}
5534
Jamie Madillc1d770e2017-04-13 17:31:24 -04005535GLenum Context::checkFramebufferStatus(GLenum target)
5536{
5537 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5538 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005539 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005540}
5541
5542void Context::compileShader(GLuint shader)
5543{
5544 Shader *shaderObject = GetValidShader(this, shader);
5545 if (!shaderObject)
5546 {
5547 return;
5548 }
5549 shaderObject->compile(this);
5550}
5551
5552void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5553{
5554 for (int i = 0; i < n; i++)
5555 {
5556 deleteBuffer(buffers[i]);
5557 }
5558}
5559
5560void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5561{
5562 for (int i = 0; i < n; i++)
5563 {
5564 if (framebuffers[i] != 0)
5565 {
5566 deleteFramebuffer(framebuffers[i]);
5567 }
5568 }
5569}
5570
5571void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5572{
5573 for (int i = 0; i < n; i++)
5574 {
5575 deleteRenderbuffer(renderbuffers[i]);
5576 }
5577}
5578
5579void Context::deleteTextures(GLsizei n, const GLuint *textures)
5580{
5581 for (int i = 0; i < n; i++)
5582 {
5583 if (textures[i] != 0)
5584 {
5585 deleteTexture(textures[i]);
5586 }
5587 }
5588}
5589
5590void Context::detachShader(GLuint program, GLuint shader)
5591{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005592 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005593 ASSERT(programObject);
5594
5595 Shader *shaderObject = getShader(shader);
5596 ASSERT(shaderObject);
5597
5598 programObject->detachShader(this, shaderObject);
5599}
5600
5601void Context::genBuffers(GLsizei n, GLuint *buffers)
5602{
5603 for (int i = 0; i < n; i++)
5604 {
5605 buffers[i] = createBuffer();
5606 }
5607}
5608
5609void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5610{
5611 for (int i = 0; i < n; i++)
5612 {
5613 framebuffers[i] = createFramebuffer();
5614 }
5615}
5616
5617void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5618{
5619 for (int i = 0; i < n; i++)
5620 {
5621 renderbuffers[i] = createRenderbuffer();
5622 }
5623}
5624
5625void Context::genTextures(GLsizei n, GLuint *textures)
5626{
5627 for (int i = 0; i < n; i++)
5628 {
5629 textures[i] = createTexture();
5630 }
5631}
5632
5633void Context::getActiveAttrib(GLuint program,
5634 GLuint index,
5635 GLsizei bufsize,
5636 GLsizei *length,
5637 GLint *size,
5638 GLenum *type,
5639 GLchar *name)
5640{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005641 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005642 ASSERT(programObject);
5643 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5644}
5645
5646void Context::getActiveUniform(GLuint program,
5647 GLuint index,
5648 GLsizei bufsize,
5649 GLsizei *length,
5650 GLint *size,
5651 GLenum *type,
5652 GLchar *name)
5653{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005654 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005655 ASSERT(programObject);
5656 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5657}
5658
5659void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5660{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005661 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005662 ASSERT(programObject);
5663 programObject->getAttachedShaders(maxcount, count, shaders);
5664}
5665
5666GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5667{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005668 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005669 ASSERT(programObject);
5670 return programObject->getAttributeLocation(name);
5671}
5672
5673void Context::getBooleanv(GLenum pname, GLboolean *params)
5674{
5675 GLenum nativeType;
5676 unsigned int numParams = 0;
5677 getQueryParameterInfo(pname, &nativeType, &numParams);
5678
5679 if (nativeType == GL_BOOL)
5680 {
5681 getBooleanvImpl(pname, params);
5682 }
5683 else
5684 {
5685 CastStateValues(this, nativeType, pname, numParams, params);
5686 }
5687}
5688
Brandon Jones59770802018-04-02 13:18:42 -07005689void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5690{
5691 getBooleanv(pname, params);
5692}
5693
Jamie Madillc1d770e2017-04-13 17:31:24 -04005694void Context::getFloatv(GLenum pname, GLfloat *params)
5695{
5696 GLenum nativeType;
5697 unsigned int numParams = 0;
5698 getQueryParameterInfo(pname, &nativeType, &numParams);
5699
5700 if (nativeType == GL_FLOAT)
5701 {
5702 getFloatvImpl(pname, params);
5703 }
5704 else
5705 {
5706 CastStateValues(this, nativeType, pname, numParams, params);
5707 }
5708}
5709
Brandon Jones59770802018-04-02 13:18:42 -07005710void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5711{
5712 getFloatv(pname, params);
5713}
5714
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715void Context::getIntegerv(GLenum pname, GLint *params)
5716{
5717 GLenum nativeType;
5718 unsigned int numParams = 0;
5719 getQueryParameterInfo(pname, &nativeType, &numParams);
5720
5721 if (nativeType == GL_INT)
5722 {
5723 getIntegervImpl(pname, params);
5724 }
5725 else
5726 {
5727 CastStateValues(this, nativeType, pname, numParams, params);
5728 }
5729}
5730
Brandon Jones59770802018-04-02 13:18:42 -07005731void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5732{
5733 getIntegerv(pname, data);
5734}
5735
Jamie Madillc1d770e2017-04-13 17:31:24 -04005736void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5737{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005738 // Don't resolve link if checking the link completion status.
5739 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5740 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005742 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743}
5744
Brandon Jones59770802018-04-02 13:18:42 -07005745void Context::getProgramivRobust(GLuint program,
5746 GLenum pname,
5747 GLsizei bufSize,
5748 GLsizei *length,
5749 GLint *params)
5750{
5751 getProgramiv(program, pname, params);
5752}
5753
Jiajia Qin5451d532017-11-16 17:16:34 +08005754void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5755{
5756 UNIMPLEMENTED();
5757}
5758
Jamie Madillbe849e42017-05-02 15:49:00 -04005759void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005760{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005761 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005762 ASSERT(programObject);
5763 programObject->getInfoLog(bufsize, length, infolog);
5764}
5765
Jiajia Qin5451d532017-11-16 17:16:34 +08005766void Context::getProgramPipelineInfoLog(GLuint pipeline,
5767 GLsizei bufSize,
5768 GLsizei *length,
5769 GLchar *infoLog)
5770{
5771 UNIMPLEMENTED();
5772}
5773
Jamie Madillc1d770e2017-04-13 17:31:24 -04005774void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5775{
5776 Shader *shaderObject = getShader(shader);
5777 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005778 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005779}
5780
Brandon Jones59770802018-04-02 13:18:42 -07005781void Context::getShaderivRobust(GLuint shader,
5782 GLenum pname,
5783 GLsizei bufSize,
5784 GLsizei *length,
5785 GLint *params)
5786{
5787 getShaderiv(shader, pname, params);
5788}
5789
Jamie Madillc1d770e2017-04-13 17:31:24 -04005790void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5791{
5792 Shader *shaderObject = getShader(shader);
5793 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005794 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005795}
5796
5797void Context::getShaderPrecisionFormat(GLenum shadertype,
5798 GLenum precisiontype,
5799 GLint *range,
5800 GLint *precision)
5801{
5802 // TODO(jmadill): Compute shaders.
5803
5804 switch (shadertype)
5805 {
5806 case GL_VERTEX_SHADER:
5807 switch (precisiontype)
5808 {
5809 case GL_LOW_FLOAT:
5810 mCaps.vertexLowpFloat.get(range, precision);
5811 break;
5812 case GL_MEDIUM_FLOAT:
5813 mCaps.vertexMediumpFloat.get(range, precision);
5814 break;
5815 case GL_HIGH_FLOAT:
5816 mCaps.vertexHighpFloat.get(range, precision);
5817 break;
5818
5819 case GL_LOW_INT:
5820 mCaps.vertexLowpInt.get(range, precision);
5821 break;
5822 case GL_MEDIUM_INT:
5823 mCaps.vertexMediumpInt.get(range, precision);
5824 break;
5825 case GL_HIGH_INT:
5826 mCaps.vertexHighpInt.get(range, precision);
5827 break;
5828
5829 default:
5830 UNREACHABLE();
5831 return;
5832 }
5833 break;
5834
5835 case GL_FRAGMENT_SHADER:
5836 switch (precisiontype)
5837 {
5838 case GL_LOW_FLOAT:
5839 mCaps.fragmentLowpFloat.get(range, precision);
5840 break;
5841 case GL_MEDIUM_FLOAT:
5842 mCaps.fragmentMediumpFloat.get(range, precision);
5843 break;
5844 case GL_HIGH_FLOAT:
5845 mCaps.fragmentHighpFloat.get(range, precision);
5846 break;
5847
5848 case GL_LOW_INT:
5849 mCaps.fragmentLowpInt.get(range, precision);
5850 break;
5851 case GL_MEDIUM_INT:
5852 mCaps.fragmentMediumpInt.get(range, precision);
5853 break;
5854 case GL_HIGH_INT:
5855 mCaps.fragmentHighpInt.get(range, precision);
5856 break;
5857
5858 default:
5859 UNREACHABLE();
5860 return;
5861 }
5862 break;
5863
5864 default:
5865 UNREACHABLE();
5866 return;
5867 }
5868}
5869
5870void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5871{
5872 Shader *shaderObject = getShader(shader);
5873 ASSERT(shaderObject);
5874 shaderObject->getSource(bufsize, length, source);
5875}
5876
5877void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5878{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005879 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005880 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005881 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005882}
5883
Brandon Jones59770802018-04-02 13:18:42 -07005884void Context::getUniformfvRobust(GLuint program,
5885 GLint location,
5886 GLsizei bufSize,
5887 GLsizei *length,
5888 GLfloat *params)
5889{
5890 getUniformfv(program, location, params);
5891}
5892
Jamie Madillc1d770e2017-04-13 17:31:24 -04005893void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5894{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005895 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005896 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005897 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005898}
5899
Brandon Jones59770802018-04-02 13:18:42 -07005900void Context::getUniformivRobust(GLuint program,
5901 GLint location,
5902 GLsizei bufSize,
5903 GLsizei *length,
5904 GLint *params)
5905{
5906 getUniformiv(program, location, params);
5907}
5908
Jamie Madillc1d770e2017-04-13 17:31:24 -04005909GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5910{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005911 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912 ASSERT(programObject);
5913 return programObject->getUniformLocation(name);
5914}
5915
5916GLboolean Context::isBuffer(GLuint buffer)
5917{
5918 if (buffer == 0)
5919 {
5920 return GL_FALSE;
5921 }
5922
5923 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5924}
5925
5926GLboolean Context::isEnabled(GLenum cap)
5927{
5928 return mGLState.getEnableFeature(cap);
5929}
5930
5931GLboolean Context::isFramebuffer(GLuint framebuffer)
5932{
5933 if (framebuffer == 0)
5934 {
5935 return GL_FALSE;
5936 }
5937
5938 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5939}
5940
5941GLboolean Context::isProgram(GLuint program)
5942{
5943 if (program == 0)
5944 {
5945 return GL_FALSE;
5946 }
5947
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005948 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005949}
5950
5951GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5952{
5953 if (renderbuffer == 0)
5954 {
5955 return GL_FALSE;
5956 }
5957
5958 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5959}
5960
5961GLboolean Context::isShader(GLuint shader)
5962{
5963 if (shader == 0)
5964 {
5965 return GL_FALSE;
5966 }
5967
5968 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5969}
5970
5971GLboolean Context::isTexture(GLuint texture)
5972{
5973 if (texture == 0)
5974 {
5975 return GL_FALSE;
5976 }
5977
5978 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5979}
5980
5981void Context::linkProgram(GLuint program)
5982{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005983 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005984 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005985 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005986
5987 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5988 // don't need to worry that:
5989 // 1. Draw calls after link use the new executable code or the old one depending on the link
5990 // result.
5991 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5992 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5993 // ProgramD3D.
5994 if (programObject->isInUse())
5995 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005996 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005997 if (programObject->isLinked())
5998 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04005999 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006000 }
jchen107ae70d82018-07-06 13:47:01 +08006001 mStateCache.onProgramExecutableChange(this);
6002 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006003}
6004
6005void Context::releaseShaderCompiler()
6006{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006007 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006008}
6009
6010void Context::shaderBinary(GLsizei n,
6011 const GLuint *shaders,
6012 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006013 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006014 GLsizei length)
6015{
6016 // No binary shader formats are supported.
6017 UNIMPLEMENTED();
6018}
6019
Olli Etuaho0ca09752018-09-24 11:00:50 +03006020void Context::bindFragDataLocationIndexed(GLuint program,
6021 GLuint colorNumber,
6022 GLuint index,
6023 const char *name)
6024{
6025 Program *programObject = getProgramNoResolveLink(program);
6026 programObject->bindFragmentOutputLocation(colorNumber, name);
6027 programObject->bindFragmentOutputIndex(index, name);
6028}
6029
6030void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6031{
6032 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6033}
6034
6035int Context::getFragDataIndex(GLuint program, const char *name)
6036{
6037 Program *programObject = getProgramResolveLink(program);
6038 return programObject->getFragDataIndex(name);
6039}
6040
6041int Context::getProgramResourceLocationIndex(GLuint program,
6042 GLenum programInterface,
6043 const char *name)
6044{
6045 Program *programObject = getProgramResolveLink(program);
6046 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6047 return programObject->getFragDataIndex(name);
6048}
6049
Jamie Madillc1d770e2017-04-13 17:31:24 -04006050void Context::shaderSource(GLuint shader,
6051 GLsizei count,
6052 const GLchar *const *string,
6053 const GLint *length)
6054{
6055 Shader *shaderObject = getShader(shader);
6056 ASSERT(shaderObject);
6057 shaderObject->setSource(count, string, length);
6058}
6059
6060void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6061{
6062 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6063}
6064
6065void Context::stencilMask(GLuint mask)
6066{
6067 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6068}
6069
6070void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6071{
6072 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6073}
6074
6075void Context::uniform1f(GLint location, GLfloat x)
6076{
6077 Program *program = mGLState.getProgram();
6078 program->setUniform1fv(location, 1, &x);
6079}
6080
6081void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6082{
6083 Program *program = mGLState.getProgram();
6084 program->setUniform1fv(location, count, v);
6085}
6086
Jamie Madill7e4eff12018-08-08 15:49:26 -04006087void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006088{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006089 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04006090 {
6091 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006092 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04006093 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006094}
6095
Jamie Madill7e4eff12018-08-08 15:49:26 -04006096void Context::uniform1i(GLint location, GLint x)
6097{
6098 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6099}
6100
Jamie Madillc1d770e2017-04-13 17:31:24 -04006101void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6102{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006103 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104}
6105
6106void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6107{
6108 GLfloat xy[2] = {x, y};
6109 Program *program = mGLState.getProgram();
6110 program->setUniform2fv(location, 1, xy);
6111}
6112
6113void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6114{
6115 Program *program = mGLState.getProgram();
6116 program->setUniform2fv(location, count, v);
6117}
6118
6119void Context::uniform2i(GLint location, GLint x, GLint y)
6120{
6121 GLint xy[2] = {x, y};
6122 Program *program = mGLState.getProgram();
6123 program->setUniform2iv(location, 1, xy);
6124}
6125
6126void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6127{
6128 Program *program = mGLState.getProgram();
6129 program->setUniform2iv(location, count, v);
6130}
6131
6132void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6133{
6134 GLfloat xyz[3] = {x, y, z};
6135 Program *program = mGLState.getProgram();
6136 program->setUniform3fv(location, 1, xyz);
6137}
6138
6139void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6140{
6141 Program *program = mGLState.getProgram();
6142 program->setUniform3fv(location, count, v);
6143}
6144
6145void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6146{
6147 GLint xyz[3] = {x, y, z};
6148 Program *program = mGLState.getProgram();
6149 program->setUniform3iv(location, 1, xyz);
6150}
6151
6152void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6153{
6154 Program *program = mGLState.getProgram();
6155 program->setUniform3iv(location, count, v);
6156}
6157
6158void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6159{
6160 GLfloat xyzw[4] = {x, y, z, w};
6161 Program *program = mGLState.getProgram();
6162 program->setUniform4fv(location, 1, xyzw);
6163}
6164
6165void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6166{
6167 Program *program = mGLState.getProgram();
6168 program->setUniform4fv(location, count, v);
6169}
6170
6171void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6172{
6173 GLint xyzw[4] = {x, y, z, w};
6174 Program *program = mGLState.getProgram();
6175 program->setUniform4iv(location, 1, xyzw);
6176}
6177
6178void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6179{
6180 Program *program = mGLState.getProgram();
6181 program->setUniform4iv(location, count, v);
6182}
6183
6184void Context::uniformMatrix2fv(GLint location,
6185 GLsizei count,
6186 GLboolean transpose,
6187 const GLfloat *value)
6188{
6189 Program *program = mGLState.getProgram();
6190 program->setUniformMatrix2fv(location, count, transpose, value);
6191}
6192
6193void Context::uniformMatrix3fv(GLint location,
6194 GLsizei count,
6195 GLboolean transpose,
6196 const GLfloat *value)
6197{
6198 Program *program = mGLState.getProgram();
6199 program->setUniformMatrix3fv(location, count, transpose, value);
6200}
6201
6202void Context::uniformMatrix4fv(GLint location,
6203 GLsizei count,
6204 GLboolean transpose,
6205 const GLfloat *value)
6206{
6207 Program *program = mGLState.getProgram();
6208 program->setUniformMatrix4fv(location, count, transpose, value);
6209}
6210
6211void Context::validateProgram(GLuint program)
6212{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006213 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006214 ASSERT(programObject);
6215 programObject->validate(mCaps);
6216}
6217
Jiajia Qin5451d532017-11-16 17:16:34 +08006218void Context::validateProgramPipeline(GLuint pipeline)
6219{
6220 UNIMPLEMENTED();
6221}
6222
Jamie Madilld04908b2017-06-09 14:15:35 -04006223void Context::getProgramBinary(GLuint program,
6224 GLsizei bufSize,
6225 GLsizei *length,
6226 GLenum *binaryFormat,
6227 void *binary)
6228{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006229 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006230 ASSERT(programObject != nullptr);
6231
Jamie Madill4f6592f2018-11-27 16:37:45 -05006232 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006233}
6234
6235void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6236{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006237 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006238 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006239
Jamie Madill4f6592f2018-11-27 16:37:45 -05006240 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006241 if (programObject->isInUse())
6242 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006243 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006244 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006245 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006246}
6247
Jamie Madillff325f12017-08-26 15:06:05 -04006248void Context::uniform1ui(GLint location, GLuint v0)
6249{
6250 Program *program = mGLState.getProgram();
6251 program->setUniform1uiv(location, 1, &v0);
6252}
6253
6254void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6255{
6256 Program *program = mGLState.getProgram();
6257 const GLuint xy[] = {v0, v1};
6258 program->setUniform2uiv(location, 1, xy);
6259}
6260
6261void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6262{
6263 Program *program = mGLState.getProgram();
6264 const GLuint xyz[] = {v0, v1, v2};
6265 program->setUniform3uiv(location, 1, xyz);
6266}
6267
6268void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6269{
6270 Program *program = mGLState.getProgram();
6271 const GLuint xyzw[] = {v0, v1, v2, v3};
6272 program->setUniform4uiv(location, 1, xyzw);
6273}
6274
6275void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6276{
6277 Program *program = mGLState.getProgram();
6278 program->setUniform1uiv(location, count, value);
6279}
6280void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6281{
6282 Program *program = mGLState.getProgram();
6283 program->setUniform2uiv(location, count, value);
6284}
6285
6286void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6287{
6288 Program *program = mGLState.getProgram();
6289 program->setUniform3uiv(location, count, value);
6290}
6291
6292void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6293{
6294 Program *program = mGLState.getProgram();
6295 program->setUniform4uiv(location, count, value);
6296}
6297
Jamie Madillf0e04492017-08-26 15:28:42 -04006298void Context::genQueries(GLsizei n, GLuint *ids)
6299{
6300 for (GLsizei i = 0; i < n; i++)
6301 {
6302 GLuint handle = mQueryHandleAllocator.allocate();
6303 mQueryMap.assign(handle, nullptr);
6304 ids[i] = handle;
6305 }
6306}
6307
6308void Context::deleteQueries(GLsizei n, const GLuint *ids)
6309{
6310 for (int i = 0; i < n; i++)
6311 {
6312 GLuint query = ids[i];
6313
6314 Query *queryObject = nullptr;
6315 if (mQueryMap.erase(query, &queryObject))
6316 {
6317 mQueryHandleAllocator.release(query);
6318 if (queryObject)
6319 {
6320 queryObject->release(this);
6321 }
6322 }
6323 }
6324}
6325
6326GLboolean Context::isQuery(GLuint id)
6327{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006328 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006329}
6330
Jamie Madillc8c95812017-08-26 18:40:09 -04006331void Context::uniformMatrix2x3fv(GLint location,
6332 GLsizei count,
6333 GLboolean transpose,
6334 const GLfloat *value)
6335{
6336 Program *program = mGLState.getProgram();
6337 program->setUniformMatrix2x3fv(location, count, transpose, value);
6338}
6339
6340void Context::uniformMatrix3x2fv(GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *program = mGLState.getProgram();
6346 program->setUniformMatrix3x2fv(location, count, transpose, value);
6347}
6348
6349void Context::uniformMatrix2x4fv(GLint location,
6350 GLsizei count,
6351 GLboolean transpose,
6352 const GLfloat *value)
6353{
6354 Program *program = mGLState.getProgram();
6355 program->setUniformMatrix2x4fv(location, count, transpose, value);
6356}
6357
6358void Context::uniformMatrix4x2fv(GLint location,
6359 GLsizei count,
6360 GLboolean transpose,
6361 const GLfloat *value)
6362{
6363 Program *program = mGLState.getProgram();
6364 program->setUniformMatrix4x2fv(location, count, transpose, value);
6365}
6366
6367void Context::uniformMatrix3x4fv(GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *program = mGLState.getProgram();
6373 program->setUniformMatrix3x4fv(location, count, transpose, value);
6374}
6375
6376void Context::uniformMatrix4x3fv(GLint location,
6377 GLsizei count,
6378 GLboolean transpose,
6379 const GLfloat *value)
6380{
6381 Program *program = mGLState.getProgram();
6382 program->setUniformMatrix4x3fv(location, count, transpose, value);
6383}
6384
Jamie Madilld7576732017-08-26 18:49:50 -04006385void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6386{
6387 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6388 {
6389 GLuint vertexArray = arrays[arrayIndex];
6390
6391 if (arrays[arrayIndex] != 0)
6392 {
6393 VertexArray *vertexArrayObject = nullptr;
6394 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6395 {
6396 if (vertexArrayObject != nullptr)
6397 {
6398 detachVertexArray(vertexArray);
6399 vertexArrayObject->onDestroy(this);
6400 }
6401
6402 mVertexArrayHandleAllocator.release(vertexArray);
6403 }
6404 }
6405 }
6406}
6407
6408void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6409{
6410 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6411 {
6412 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6413 mVertexArrayMap.assign(vertexArray, nullptr);
6414 arrays[arrayIndex] = vertexArray;
6415 }
6416}
6417
6418bool Context::isVertexArray(GLuint array)
6419{
6420 if (array == 0)
6421 {
6422 return GL_FALSE;
6423 }
6424
6425 VertexArray *vao = getVertexArray(array);
6426 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6427}
6428
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006429void Context::endTransformFeedback()
6430{
6431 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6432 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006433 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006434}
6435
6436void Context::transformFeedbackVaryings(GLuint program,
6437 GLsizei count,
6438 const GLchar *const *varyings,
6439 GLenum bufferMode)
6440{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006441 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006442 ASSERT(programObject);
6443 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6444}
6445
6446void Context::getTransformFeedbackVarying(GLuint program,
6447 GLuint index,
6448 GLsizei bufSize,
6449 GLsizei *length,
6450 GLsizei *size,
6451 GLenum *type,
6452 GLchar *name)
6453{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006454 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006455 ASSERT(programObject);
6456 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6457}
6458
6459void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6460{
6461 for (int i = 0; i < n; i++)
6462 {
6463 GLuint transformFeedback = ids[i];
6464 if (transformFeedback == 0)
6465 {
6466 continue;
6467 }
6468
6469 TransformFeedback *transformFeedbackObject = nullptr;
6470 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6471 {
6472 if (transformFeedbackObject != nullptr)
6473 {
6474 detachTransformFeedback(transformFeedback);
6475 transformFeedbackObject->release(this);
6476 }
6477
6478 mTransformFeedbackHandleAllocator.release(transformFeedback);
6479 }
6480 }
6481}
6482
6483void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6484{
6485 for (int i = 0; i < n; i++)
6486 {
6487 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6488 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6489 ids[i] = transformFeedback;
6490 }
6491}
6492
6493bool Context::isTransformFeedback(GLuint id)
6494{
6495 if (id == 0)
6496 {
6497 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6498 // returns FALSE
6499 return GL_FALSE;
6500 }
6501
6502 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6503 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6504}
6505
6506void Context::pauseTransformFeedback()
6507{
6508 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6509 transformFeedback->pause();
6510}
6511
6512void Context::resumeTransformFeedback()
6513{
6514 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6515 transformFeedback->resume();
6516}
6517
Jamie Madill12e957f2017-08-26 21:42:26 -04006518void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6519{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006520 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006521 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006522}
6523
Brandon Jones59770802018-04-02 13:18:42 -07006524void Context::getUniformuivRobust(GLuint program,
6525 GLint location,
6526 GLsizei bufSize,
6527 GLsizei *length,
6528 GLuint *params)
6529{
6530 getUniformuiv(program, location, params);
6531}
6532
Jamie Madill12e957f2017-08-26 21:42:26 -04006533GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6534{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006535 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006536 return programObject->getFragDataLocation(name);
6537}
6538
6539void Context::getUniformIndices(GLuint program,
6540 GLsizei uniformCount,
6541 const GLchar *const *uniformNames,
6542 GLuint *uniformIndices)
6543{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006544 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006545 if (!programObject->isLinked())
6546 {
6547 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6548 {
6549 uniformIndices[uniformId] = GL_INVALID_INDEX;
6550 }
6551 }
6552 else
6553 {
6554 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6555 {
6556 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6557 }
6558 }
6559}
6560
6561void Context::getActiveUniformsiv(GLuint program,
6562 GLsizei uniformCount,
6563 const GLuint *uniformIndices,
6564 GLenum pname,
6565 GLint *params)
6566{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006567 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006568 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6569 {
6570 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006571 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006572 }
6573}
6574
6575GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6576{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006577 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006578 return programObject->getUniformBlockIndex(uniformBlockName);
6579}
6580
6581void Context::getActiveUniformBlockiv(GLuint program,
6582 GLuint uniformBlockIndex,
6583 GLenum pname,
6584 GLint *params)
6585{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006586 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006587 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6588}
6589
Brandon Jones59770802018-04-02 13:18:42 -07006590void Context::getActiveUniformBlockivRobust(GLuint program,
6591 GLuint uniformBlockIndex,
6592 GLenum pname,
6593 GLsizei bufSize,
6594 GLsizei *length,
6595 GLint *params)
6596{
6597 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6598}
6599
Jamie Madill12e957f2017-08-26 21:42:26 -04006600void Context::getActiveUniformBlockName(GLuint program,
6601 GLuint uniformBlockIndex,
6602 GLsizei bufSize,
6603 GLsizei *length,
6604 GLchar *uniformBlockName)
6605{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006606 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006607 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6608}
6609
6610void Context::uniformBlockBinding(GLuint program,
6611 GLuint uniformBlockIndex,
6612 GLuint uniformBlockBinding)
6613{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006614 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006615 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006616
Jamie Madill956ab4d2018-10-10 16:13:03 -04006617 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006618 if (programObject->isInUse())
6619 {
6620 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006621 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006622 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006623}
6624
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006625GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6626{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006627 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6628 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006629
Jamie Madill70b5bb02017-08-28 13:32:37 -04006630 Sync *syncObject = getSync(syncHandle);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006631 if (syncObject->set(this, condition, flags) == angle::Result::Stop())
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006632 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006633 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006634 return nullptr;
6635 }
6636
Jamie Madill70b5bb02017-08-28 13:32:37 -04006637 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006638}
6639
6640GLboolean Context::isSync(GLsync sync)
6641{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006642 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006643}
6644
6645GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6646{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006647 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006648
6649 GLenum result = GL_WAIT_FAILED;
Jamie Madill4f6592f2018-11-27 16:37:45 -05006650 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop())
6651 {
6652 return GL_WAIT_FAILED;
6653 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006654 return result;
6655}
6656
6657void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6658{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006659 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006660 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006661}
6662
6663void Context::getInteger64v(GLenum pname, GLint64 *params)
6664{
6665 GLenum nativeType = GL_NONE;
6666 unsigned int numParams = 0;
6667 getQueryParameterInfo(pname, &nativeType, &numParams);
6668
6669 if (nativeType == GL_INT_64_ANGLEX)
6670 {
6671 getInteger64vImpl(pname, params);
6672 }
6673 else
6674 {
6675 CastStateValues(this, nativeType, pname, numParams, params);
6676 }
6677}
6678
Brandon Jones59770802018-04-02 13:18:42 -07006679void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6680{
6681 getInteger64v(pname, data);
6682}
6683
Corentin Wallez336129f2017-10-17 15:55:40 -04006684void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006685{
6686 Buffer *buffer = mGLState.getTargetBuffer(target);
6687 QueryBufferParameteri64v(buffer, pname, params);
6688}
6689
Brandon Jones59770802018-04-02 13:18:42 -07006690void Context::getBufferParameteri64vRobust(BufferBinding target,
6691 GLenum pname,
6692 GLsizei bufSize,
6693 GLsizei *length,
6694 GLint64 *params)
6695{
6696 getBufferParameteri64v(target, pname, params);
6697}
6698
Jamie Madill3ef140a2017-08-26 23:11:21 -04006699void Context::genSamplers(GLsizei count, GLuint *samplers)
6700{
6701 for (int i = 0; i < count; i++)
6702 {
6703 samplers[i] = mState.mSamplers->createSampler();
6704 }
6705}
6706
6707void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6708{
6709 for (int i = 0; i < count; i++)
6710 {
6711 GLuint sampler = samplers[i];
6712
6713 if (mState.mSamplers->getSampler(sampler))
6714 {
6715 detachSampler(sampler);
6716 }
6717
6718 mState.mSamplers->deleteObject(this, sampler);
6719 }
6720}
6721
6722void Context::getInternalformativ(GLenum target,
6723 GLenum internalformat,
6724 GLenum pname,
6725 GLsizei bufSize,
6726 GLint *params)
6727{
6728 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6729 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6730}
6731
Brandon Jones59770802018-04-02 13:18:42 -07006732void Context::getInternalformativRobust(GLenum target,
6733 GLenum internalformat,
6734 GLenum pname,
6735 GLsizei bufSize,
6736 GLsizei *length,
6737 GLint *params)
6738{
6739 getInternalformativ(target, internalformat, pname, bufSize, params);
6740}
6741
Jiajia Qin5451d532017-11-16 17:16:34 +08006742void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6743{
6744 programUniform1iv(program, location, 1, &v0);
6745}
6746
6747void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6748{
6749 GLint xy[2] = {v0, v1};
6750 programUniform2iv(program, location, 1, xy);
6751}
6752
6753void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6754{
6755 GLint xyz[3] = {v0, v1, v2};
6756 programUniform3iv(program, location, 1, xyz);
6757}
6758
6759void Context::programUniform4i(GLuint program,
6760 GLint location,
6761 GLint v0,
6762 GLint v1,
6763 GLint v2,
6764 GLint v3)
6765{
6766 GLint xyzw[4] = {v0, v1, v2, v3};
6767 programUniform4iv(program, location, 1, xyzw);
6768}
6769
6770void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6771{
6772 programUniform1uiv(program, location, 1, &v0);
6773}
6774
6775void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6776{
6777 GLuint xy[2] = {v0, v1};
6778 programUniform2uiv(program, location, 1, xy);
6779}
6780
6781void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6782{
6783 GLuint xyz[3] = {v0, v1, v2};
6784 programUniform3uiv(program, location, 1, xyz);
6785}
6786
6787void Context::programUniform4ui(GLuint program,
6788 GLint location,
6789 GLuint v0,
6790 GLuint v1,
6791 GLuint v2,
6792 GLuint v3)
6793{
6794 GLuint xyzw[4] = {v0, v1, v2, v3};
6795 programUniform4uiv(program, location, 1, xyzw);
6796}
6797
6798void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6799{
6800 programUniform1fv(program, location, 1, &v0);
6801}
6802
6803void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6804{
6805 GLfloat xy[2] = {v0, v1};
6806 programUniform2fv(program, location, 1, xy);
6807}
6808
6809void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6810{
6811 GLfloat xyz[3] = {v0, v1, v2};
6812 programUniform3fv(program, location, 1, xyz);
6813}
6814
6815void Context::programUniform4f(GLuint program,
6816 GLint location,
6817 GLfloat v0,
6818 GLfloat v1,
6819 GLfloat v2,
6820 GLfloat v3)
6821{
6822 GLfloat xyzw[4] = {v0, v1, v2, v3};
6823 programUniform4fv(program, location, 1, xyzw);
6824}
6825
Jamie Madill81c2e252017-09-09 23:32:46 -04006826void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6827{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006828 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006829 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006830 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006831}
6832
Jiajia Qin5451d532017-11-16 17:16:34 +08006833void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6834{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006835 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006836 ASSERT(programObject);
6837 programObject->setUniform2iv(location, count, value);
6838}
6839
6840void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6841{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006842 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006843 ASSERT(programObject);
6844 programObject->setUniform3iv(location, count, value);
6845}
6846
6847void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6848{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006849 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006850 ASSERT(programObject);
6851 programObject->setUniform4iv(location, count, value);
6852}
6853
6854void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6855{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006856 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006857 ASSERT(programObject);
6858 programObject->setUniform1uiv(location, count, value);
6859}
6860
6861void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6862{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006863 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006864 ASSERT(programObject);
6865 programObject->setUniform2uiv(location, count, value);
6866}
6867
6868void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6869{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006870 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006871 ASSERT(programObject);
6872 programObject->setUniform3uiv(location, count, value);
6873}
6874
6875void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6876{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006877 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006878 ASSERT(programObject);
6879 programObject->setUniform4uiv(location, count, value);
6880}
6881
6882void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6883{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006884 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006885 ASSERT(programObject);
6886 programObject->setUniform1fv(location, count, value);
6887}
6888
6889void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6890{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006891 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006892 ASSERT(programObject);
6893 programObject->setUniform2fv(location, count, value);
6894}
6895
6896void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6897{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006898 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006899 ASSERT(programObject);
6900 programObject->setUniform3fv(location, count, value);
6901}
6902
6903void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6904{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006905 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006906 ASSERT(programObject);
6907 programObject->setUniform4fv(location, count, value);
6908}
6909
6910void Context::programUniformMatrix2fv(GLuint program,
6911 GLint location,
6912 GLsizei count,
6913 GLboolean transpose,
6914 const GLfloat *value)
6915{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006916 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006917 ASSERT(programObject);
6918 programObject->setUniformMatrix2fv(location, count, transpose, value);
6919}
6920
6921void Context::programUniformMatrix3fv(GLuint program,
6922 GLint location,
6923 GLsizei count,
6924 GLboolean transpose,
6925 const GLfloat *value)
6926{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006927 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006928 ASSERT(programObject);
6929 programObject->setUniformMatrix3fv(location, count, transpose, value);
6930}
6931
6932void Context::programUniformMatrix4fv(GLuint program,
6933 GLint location,
6934 GLsizei count,
6935 GLboolean transpose,
6936 const GLfloat *value)
6937{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006938 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006939 ASSERT(programObject);
6940 programObject->setUniformMatrix4fv(location, count, transpose, value);
6941}
6942
6943void Context::programUniformMatrix2x3fv(GLuint program,
6944 GLint location,
6945 GLsizei count,
6946 GLboolean transpose,
6947 const GLfloat *value)
6948{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006949 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006950 ASSERT(programObject);
6951 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6952}
6953
6954void Context::programUniformMatrix3x2fv(GLuint program,
6955 GLint location,
6956 GLsizei count,
6957 GLboolean transpose,
6958 const GLfloat *value)
6959{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006960 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006961 ASSERT(programObject);
6962 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6963}
6964
6965void Context::programUniformMatrix2x4fv(GLuint program,
6966 GLint location,
6967 GLsizei count,
6968 GLboolean transpose,
6969 const GLfloat *value)
6970{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006971 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006972 ASSERT(programObject);
6973 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6974}
6975
6976void Context::programUniformMatrix4x2fv(GLuint program,
6977 GLint location,
6978 GLsizei count,
6979 GLboolean transpose,
6980 const GLfloat *value)
6981{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006982 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006983 ASSERT(programObject);
6984 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6985}
6986
6987void Context::programUniformMatrix3x4fv(GLuint program,
6988 GLint location,
6989 GLsizei count,
6990 GLboolean transpose,
6991 const GLfloat *value)
6992{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006993 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006994 ASSERT(programObject);
6995 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6996}
6997
6998void Context::programUniformMatrix4x3fv(GLuint program,
6999 GLint location,
7000 GLsizei count,
7001 GLboolean transpose,
7002 const GLfloat *value)
7003{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007004 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007005 ASSERT(programObject);
7006 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7007}
7008
Jamie Madill81c2e252017-09-09 23:32:46 -04007009void Context::onTextureChange(const Texture *texture)
7010{
7011 // Conservatively assume all textures are dirty.
7012 // TODO(jmadill): More fine-grained update.
7013 mGLState.setObjectDirty(GL_TEXTURE);
7014}
7015
James Darpiniane8a93c62018-01-04 18:02:24 -08007016bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7017{
7018 return mGLState.isCurrentTransformFeedback(tf);
7019}
James Darpiniane8a93c62018-01-04 18:02:24 -08007020
Yunchao Hea336b902017-08-02 16:05:21 +08007021void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7022{
7023 for (int i = 0; i < count; i++)
7024 {
7025 pipelines[i] = createProgramPipeline();
7026 }
7027}
7028
7029void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7030{
7031 for (int i = 0; i < count; i++)
7032 {
7033 if (pipelines[i] != 0)
7034 {
7035 deleteProgramPipeline(pipelines[i]);
7036 }
7037 }
7038}
7039
7040GLboolean Context::isProgramPipeline(GLuint pipeline)
7041{
7042 if (pipeline == 0)
7043 {
7044 return GL_FALSE;
7045 }
7046
7047 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7048}
7049
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007050void Context::finishFenceNV(GLuint fence)
7051{
7052 FenceNV *fenceObject = getFenceNV(fence);
7053
7054 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007055 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007056}
7057
7058void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7059{
7060 FenceNV *fenceObject = getFenceNV(fence);
7061
7062 ASSERT(fenceObject && fenceObject->isSet());
7063
7064 switch (pname)
7065 {
7066 case GL_FENCE_STATUS_NV:
7067 {
7068 // GL_NV_fence spec:
7069 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7070 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7071 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7072 GLboolean status = GL_TRUE;
7073 if (fenceObject->getStatus() != GL_TRUE)
7074 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007075 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007076 }
7077 *params = status;
7078 break;
7079 }
7080
7081 case GL_FENCE_CONDITION_NV:
7082 {
7083 *params = static_cast<GLint>(fenceObject->getCondition());
7084 break;
7085 }
7086
7087 default:
7088 UNREACHABLE();
7089 }
7090}
7091
7092void Context::getTranslatedShaderSource(GLuint shader,
7093 GLsizei bufsize,
7094 GLsizei *length,
7095 GLchar *source)
7096{
7097 Shader *shaderObject = getShader(shader);
7098 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007099 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007100}
7101
7102void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7103{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007104 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007105 ASSERT(programObject);
7106
7107 programObject->getUniformfv(this, location, params);
7108}
7109
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007110void Context::getnUniformfvRobust(GLuint program,
7111 GLint location,
7112 GLsizei bufSize,
7113 GLsizei *length,
7114 GLfloat *params)
7115{
7116 UNIMPLEMENTED();
7117}
7118
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007119void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7120{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007121 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007122 ASSERT(programObject);
7123
7124 programObject->getUniformiv(this, location, params);
7125}
7126
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007127void Context::getnUniformivRobust(GLuint program,
7128 GLint location,
7129 GLsizei bufSize,
7130 GLsizei *length,
7131 GLint *params)
7132{
7133 UNIMPLEMENTED();
7134}
7135
7136void Context::getnUniformuivRobust(GLuint program,
7137 GLint location,
7138 GLsizei bufSize,
7139 GLsizei *length,
7140 GLuint *params)
7141{
7142 UNIMPLEMENTED();
7143}
7144
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007145GLboolean Context::isFenceNV(GLuint fence)
7146{
7147 FenceNV *fenceObject = getFenceNV(fence);
7148
7149 if (fenceObject == nullptr)
7150 {
7151 return GL_FALSE;
7152 }
7153
7154 // GL_NV_fence spec:
7155 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7156 // existing fence.
7157 return fenceObject->isSet();
7158}
7159
7160void Context::readnPixels(GLint x,
7161 GLint y,
7162 GLsizei width,
7163 GLsizei height,
7164 GLenum format,
7165 GLenum type,
7166 GLsizei bufSize,
7167 void *data)
7168{
7169 return readPixels(x, y, width, height, format, type, data);
7170}
7171
Jamie Madill007530e2017-12-28 14:27:04 -05007172void Context::setFenceNV(GLuint fence, GLenum condition)
7173{
7174 ASSERT(condition == GL_ALL_COMPLETED_NV);
7175
7176 FenceNV *fenceObject = getFenceNV(fence);
7177 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007178 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007179}
7180
7181GLboolean Context::testFenceNV(GLuint fence)
7182{
7183 FenceNV *fenceObject = getFenceNV(fence);
7184
7185 ASSERT(fenceObject != nullptr);
7186 ASSERT(fenceObject->isSet() == GL_TRUE);
7187
7188 GLboolean result = GL_TRUE;
Jamie Madill4f6592f2018-11-27 16:37:45 -05007189 if (fenceObject->test(this, &result) == angle::Result::Stop())
Jamie Madill007530e2017-12-28 14:27:04 -05007190 {
Jamie Madill007530e2017-12-28 14:27:04 -05007191 return GL_TRUE;
7192 }
7193
7194 return result;
7195}
7196
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007197void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007198{
7199 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007200 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007201 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007202}
7203
Jamie Madillfa920eb2018-01-04 11:45:50 -05007204void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007205{
7206 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007207 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007208 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007209}
7210
Jamie Madillfa920eb2018-01-04 11:45:50 -05007211void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7212{
7213 UNIMPLEMENTED();
7214}
7215
Jamie Madill5b772312018-03-08 20:28:32 -05007216bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7217{
7218 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7219 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7220 // to the fact that it is stored internally as a float, and so would require conversion
7221 // if returned from Context::getIntegerv. Since this conversion is already implemented
7222 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7223 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7224 // application.
7225 switch (pname)
7226 {
7227 case GL_COMPRESSED_TEXTURE_FORMATS:
7228 {
7229 *type = GL_INT;
7230 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7231 return true;
7232 }
7233 case GL_SHADER_BINARY_FORMATS:
7234 {
7235 *type = GL_INT;
7236 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7237 return true;
7238 }
7239
7240 case GL_MAX_VERTEX_ATTRIBS:
7241 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7242 case GL_MAX_VARYING_VECTORS:
7243 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7244 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7245 case GL_MAX_TEXTURE_IMAGE_UNITS:
7246 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7247 case GL_MAX_RENDERBUFFER_SIZE:
7248 case GL_NUM_SHADER_BINARY_FORMATS:
7249 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7250 case GL_ARRAY_BUFFER_BINDING:
7251 case GL_FRAMEBUFFER_BINDING:
7252 case GL_RENDERBUFFER_BINDING:
7253 case GL_CURRENT_PROGRAM:
7254 case GL_PACK_ALIGNMENT:
7255 case GL_UNPACK_ALIGNMENT:
7256 case GL_GENERATE_MIPMAP_HINT:
7257 case GL_RED_BITS:
7258 case GL_GREEN_BITS:
7259 case GL_BLUE_BITS:
7260 case GL_ALPHA_BITS:
7261 case GL_DEPTH_BITS:
7262 case GL_STENCIL_BITS:
7263 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7264 case GL_CULL_FACE_MODE:
7265 case GL_FRONT_FACE:
7266 case GL_ACTIVE_TEXTURE:
7267 case GL_STENCIL_FUNC:
7268 case GL_STENCIL_VALUE_MASK:
7269 case GL_STENCIL_REF:
7270 case GL_STENCIL_FAIL:
7271 case GL_STENCIL_PASS_DEPTH_FAIL:
7272 case GL_STENCIL_PASS_DEPTH_PASS:
7273 case GL_STENCIL_BACK_FUNC:
7274 case GL_STENCIL_BACK_VALUE_MASK:
7275 case GL_STENCIL_BACK_REF:
7276 case GL_STENCIL_BACK_FAIL:
7277 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7278 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7279 case GL_DEPTH_FUNC:
7280 case GL_BLEND_SRC_RGB:
7281 case GL_BLEND_SRC_ALPHA:
7282 case GL_BLEND_DST_RGB:
7283 case GL_BLEND_DST_ALPHA:
7284 case GL_BLEND_EQUATION_RGB:
7285 case GL_BLEND_EQUATION_ALPHA:
7286 case GL_STENCIL_WRITEMASK:
7287 case GL_STENCIL_BACK_WRITEMASK:
7288 case GL_STENCIL_CLEAR_VALUE:
7289 case GL_SUBPIXEL_BITS:
7290 case GL_MAX_TEXTURE_SIZE:
7291 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7292 case GL_SAMPLE_BUFFERS:
7293 case GL_SAMPLES:
7294 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7295 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7296 case GL_TEXTURE_BINDING_2D:
7297 case GL_TEXTURE_BINDING_CUBE_MAP:
7298 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7299 {
7300 *type = GL_INT;
7301 *numParams = 1;
7302 return true;
7303 }
7304 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7305 {
7306 if (!getExtensions().packReverseRowOrder)
7307 {
7308 return false;
7309 }
7310 *type = GL_INT;
7311 *numParams = 1;
7312 return true;
7313 }
7314 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7315 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7316 {
7317 if (!getExtensions().textureRectangle)
7318 {
7319 return false;
7320 }
7321 *type = GL_INT;
7322 *numParams = 1;
7323 return true;
7324 }
7325 case GL_MAX_DRAW_BUFFERS_EXT:
7326 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7327 {
7328 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7329 {
7330 return false;
7331 }
7332 *type = GL_INT;
7333 *numParams = 1;
7334 return true;
7335 }
7336 case GL_MAX_VIEWPORT_DIMS:
7337 {
7338 *type = GL_INT;
7339 *numParams = 2;
7340 return true;
7341 }
7342 case GL_VIEWPORT:
7343 case GL_SCISSOR_BOX:
7344 {
7345 *type = GL_INT;
7346 *numParams = 4;
7347 return true;
7348 }
7349 case GL_SHADER_COMPILER:
7350 case GL_SAMPLE_COVERAGE_INVERT:
7351 case GL_DEPTH_WRITEMASK:
7352 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7353 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7354 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7355 // bool-natural
7356 case GL_SAMPLE_COVERAGE:
7357 case GL_SCISSOR_TEST:
7358 case GL_STENCIL_TEST:
7359 case GL_DEPTH_TEST:
7360 case GL_BLEND:
7361 case GL_DITHER:
7362 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7363 {
7364 *type = GL_BOOL;
7365 *numParams = 1;
7366 return true;
7367 }
7368 case GL_COLOR_WRITEMASK:
7369 {
7370 *type = GL_BOOL;
7371 *numParams = 4;
7372 return true;
7373 }
7374 case GL_POLYGON_OFFSET_FACTOR:
7375 case GL_POLYGON_OFFSET_UNITS:
7376 case GL_SAMPLE_COVERAGE_VALUE:
7377 case GL_DEPTH_CLEAR_VALUE:
7378 case GL_LINE_WIDTH:
7379 {
7380 *type = GL_FLOAT;
7381 *numParams = 1;
7382 return true;
7383 }
7384 case GL_ALIASED_LINE_WIDTH_RANGE:
7385 case GL_ALIASED_POINT_SIZE_RANGE:
7386 case GL_DEPTH_RANGE:
7387 {
7388 *type = GL_FLOAT;
7389 *numParams = 2;
7390 return true;
7391 }
7392 case GL_COLOR_CLEAR_VALUE:
7393 case GL_BLEND_COLOR:
7394 {
7395 *type = GL_FLOAT;
7396 *numParams = 4;
7397 return true;
7398 }
7399 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7400 if (!getExtensions().textureFilterAnisotropic)
7401 {
7402 return false;
7403 }
7404 *type = GL_FLOAT;
7405 *numParams = 1;
7406 return true;
7407 case GL_TIMESTAMP_EXT:
7408 if (!getExtensions().disjointTimerQuery)
7409 {
7410 return false;
7411 }
7412 *type = GL_INT_64_ANGLEX;
7413 *numParams = 1;
7414 return true;
7415 case GL_GPU_DISJOINT_EXT:
7416 if (!getExtensions().disjointTimerQuery)
7417 {
7418 return false;
7419 }
7420 *type = GL_INT;
7421 *numParams = 1;
7422 return true;
7423 case GL_COVERAGE_MODULATION_CHROMIUM:
7424 if (!getExtensions().framebufferMixedSamples)
7425 {
7426 return false;
7427 }
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7432 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7433 {
7434 return false;
7435 }
7436 *type = GL_INT;
7437 *numParams = 1;
7438 return true;
7439 }
7440
7441 if (getExtensions().debug)
7442 {
7443 switch (pname)
7444 {
7445 case GL_DEBUG_LOGGED_MESSAGES:
7446 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7447 case GL_DEBUG_GROUP_STACK_DEPTH:
7448 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7449 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7450 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7451 case GL_MAX_LABEL_LENGTH:
7452 *type = GL_INT;
7453 *numParams = 1;
7454 return true;
7455
7456 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7457 case GL_DEBUG_OUTPUT:
7458 *type = GL_BOOL;
7459 *numParams = 1;
7460 return true;
7461 }
7462 }
7463
7464 if (getExtensions().multisampleCompatibility)
7465 {
7466 switch (pname)
7467 {
7468 case GL_MULTISAMPLE_EXT:
7469 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7470 *type = GL_BOOL;
7471 *numParams = 1;
7472 return true;
7473 }
7474 }
7475
7476 if (getExtensions().pathRendering)
7477 {
7478 switch (pname)
7479 {
7480 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7481 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7482 *type = GL_FLOAT;
7483 *numParams = 16;
7484 return true;
7485 }
7486 }
7487
7488 if (getExtensions().bindGeneratesResource)
7489 {
7490 switch (pname)
7491 {
7492 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7493 *type = GL_BOOL;
7494 *numParams = 1;
7495 return true;
7496 }
7497 }
7498
7499 if (getExtensions().clientArrays)
7500 {
7501 switch (pname)
7502 {
7503 case GL_CLIENT_ARRAYS_ANGLE:
7504 *type = GL_BOOL;
7505 *numParams = 1;
7506 return true;
7507 }
7508 }
7509
7510 if (getExtensions().sRGBWriteControl)
7511 {
7512 switch (pname)
7513 {
7514 case GL_FRAMEBUFFER_SRGB_EXT:
7515 *type = GL_BOOL;
7516 *numParams = 1;
7517 return true;
7518 }
7519 }
7520
7521 if (getExtensions().robustResourceInitialization &&
7522 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7523 {
7524 *type = GL_BOOL;
7525 *numParams = 1;
7526 return true;
7527 }
7528
7529 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7530 {
7531 *type = GL_BOOL;
7532 *numParams = 1;
7533 return true;
7534 }
7535
jchen1082af6202018-06-22 10:59:52 +08007536 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7537 {
7538 *type = GL_INT;
7539 *numParams = 1;
7540 return true;
7541 }
7542
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007543 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7544 {
7545 *type = GL_INT;
7546 *numParams = 1;
7547 return true;
7548 }
7549
Jamie Madill5b772312018-03-08 20:28:32 -05007550 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7551 switch (pname)
7552 {
7553 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7554 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7555 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7556 {
7557 return false;
7558 }
7559 *type = GL_INT;
7560 *numParams = 1;
7561 return true;
7562
7563 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7564 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7565 {
7566 return false;
7567 }
7568 *type = GL_INT;
7569 *numParams = 1;
7570 return true;
7571
7572 case GL_PROGRAM_BINARY_FORMATS_OES:
7573 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7574 {
7575 return false;
7576 }
7577 *type = GL_INT;
7578 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7579 return true;
7580
7581 case GL_PACK_ROW_LENGTH:
7582 case GL_PACK_SKIP_ROWS:
7583 case GL_PACK_SKIP_PIXELS:
7584 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7585 {
7586 return false;
7587 }
7588 *type = GL_INT;
7589 *numParams = 1;
7590 return true;
7591 case GL_UNPACK_ROW_LENGTH:
7592 case GL_UNPACK_SKIP_ROWS:
7593 case GL_UNPACK_SKIP_PIXELS:
7594 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7595 {
7596 return false;
7597 }
7598 *type = GL_INT;
7599 *numParams = 1;
7600 return true;
7601 case GL_VERTEX_ARRAY_BINDING:
7602 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7603 {
7604 return false;
7605 }
7606 *type = GL_INT;
7607 *numParams = 1;
7608 return true;
7609 case GL_PIXEL_PACK_BUFFER_BINDING:
7610 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7611 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7612 {
7613 return false;
7614 }
7615 *type = GL_INT;
7616 *numParams = 1;
7617 return true;
7618 case GL_MAX_SAMPLES:
7619 {
7620 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7621 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7622 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7623 {
7624 return false;
7625 }
7626 *type = GL_INT;
7627 *numParams = 1;
7628 return true;
7629
7630 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7631 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7632 {
7633 return false;
7634 }
7635 *type = GL_INT;
7636 *numParams = 1;
7637 return true;
7638 }
7639 }
7640
7641 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7642 {
7643 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7644 {
7645 return false;
7646 }
7647 *type = GL_INT;
7648 *numParams = 1;
7649 return true;
7650 }
7651
7652 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7653 {
7654 *type = GL_INT;
7655 *numParams = 1;
7656 return true;
7657 }
7658
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007659 if (getClientVersion() < Version(2, 0))
7660 {
7661 switch (pname)
7662 {
7663 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007664 case GL_CLIENT_ACTIVE_TEXTURE:
7665 case GL_MATRIX_MODE:
7666 case GL_MAX_TEXTURE_UNITS:
7667 case GL_MAX_MODELVIEW_STACK_DEPTH:
7668 case GL_MAX_PROJECTION_STACK_DEPTH:
7669 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007670 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007671 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007672 case GL_VERTEX_ARRAY_STRIDE:
7673 case GL_NORMAL_ARRAY_STRIDE:
7674 case GL_COLOR_ARRAY_STRIDE:
7675 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7676 case GL_VERTEX_ARRAY_SIZE:
7677 case GL_COLOR_ARRAY_SIZE:
7678 case GL_TEXTURE_COORD_ARRAY_SIZE:
7679 case GL_VERTEX_ARRAY_TYPE:
7680 case GL_NORMAL_ARRAY_TYPE:
7681 case GL_COLOR_ARRAY_TYPE:
7682 case GL_TEXTURE_COORD_ARRAY_TYPE:
7683 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7684 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7685 case GL_COLOR_ARRAY_BUFFER_BINDING:
7686 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7687 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7688 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7689 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007690 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007691 case GL_MODELVIEW_STACK_DEPTH:
7692 case GL_PROJECTION_STACK_DEPTH:
7693 case GL_TEXTURE_STACK_DEPTH:
7694 case GL_LOGIC_OP_MODE:
7695 case GL_BLEND_SRC:
7696 case GL_BLEND_DST:
7697 case GL_PERSPECTIVE_CORRECTION_HINT:
7698 case GL_POINT_SMOOTH_HINT:
7699 case GL_LINE_SMOOTH_HINT:
7700 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007701 *type = GL_INT;
7702 *numParams = 1;
7703 return true;
7704 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007705 case GL_FOG_DENSITY:
7706 case GL_FOG_START:
7707 case GL_FOG_END:
7708 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007709 case GL_POINT_SIZE:
7710 case GL_POINT_SIZE_MIN:
7711 case GL_POINT_SIZE_MAX:
7712 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007713 *type = GL_FLOAT;
7714 *numParams = 1;
7715 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007716 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007717 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007718 *type = GL_FLOAT;
7719 *numParams = 2;
7720 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007721 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007722 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007723 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007724 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007725 *type = GL_FLOAT;
7726 *numParams = 4;
7727 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007728 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007729 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007730 *type = GL_FLOAT;
7731 *numParams = 3;
7732 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007733 case GL_MODELVIEW_MATRIX:
7734 case GL_PROJECTION_MATRIX:
7735 case GL_TEXTURE_MATRIX:
7736 *type = GL_FLOAT;
7737 *numParams = 16;
7738 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007739 case GL_LIGHT_MODEL_TWO_SIDE:
7740 *type = GL_BOOL;
7741 *numParams = 1;
7742 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007743 }
7744 }
7745
Jamie Madill5b772312018-03-08 20:28:32 -05007746 if (getClientVersion() < Version(3, 0))
7747 {
7748 return false;
7749 }
7750
7751 // Check for ES3.0+ parameter names
7752 switch (pname)
7753 {
7754 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7755 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7756 case GL_UNIFORM_BUFFER_BINDING:
7757 case GL_TRANSFORM_FEEDBACK_BINDING:
7758 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7759 case GL_COPY_READ_BUFFER_BINDING:
7760 case GL_COPY_WRITE_BUFFER_BINDING:
7761 case GL_SAMPLER_BINDING:
7762 case GL_READ_BUFFER:
7763 case GL_TEXTURE_BINDING_3D:
7764 case GL_TEXTURE_BINDING_2D_ARRAY:
7765 case GL_MAX_3D_TEXTURE_SIZE:
7766 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7767 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7768 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7769 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7770 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7771 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7772 case GL_MAX_VARYING_COMPONENTS:
7773 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7774 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7775 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7776 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7777 case GL_NUM_EXTENSIONS:
7778 case GL_MAJOR_VERSION:
7779 case GL_MINOR_VERSION:
7780 case GL_MAX_ELEMENTS_INDICES:
7781 case GL_MAX_ELEMENTS_VERTICES:
7782 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7783 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7784 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7785 case GL_UNPACK_IMAGE_HEIGHT:
7786 case GL_UNPACK_SKIP_IMAGES:
7787 {
7788 *type = GL_INT;
7789 *numParams = 1;
7790 return true;
7791 }
7792
7793 case GL_MAX_ELEMENT_INDEX:
7794 case GL_MAX_UNIFORM_BLOCK_SIZE:
7795 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7796 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7797 case GL_MAX_SERVER_WAIT_TIMEOUT:
7798 {
7799 *type = GL_INT_64_ANGLEX;
7800 *numParams = 1;
7801 return true;
7802 }
7803
7804 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7805 case GL_TRANSFORM_FEEDBACK_PAUSED:
7806 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7807 case GL_RASTERIZER_DISCARD:
7808 {
7809 *type = GL_BOOL;
7810 *numParams = 1;
7811 return true;
7812 }
7813
7814 case GL_MAX_TEXTURE_LOD_BIAS:
7815 {
7816 *type = GL_FLOAT;
7817 *numParams = 1;
7818 return true;
7819 }
7820 }
7821
7822 if (getExtensions().requestExtension)
7823 {
7824 switch (pname)
7825 {
7826 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7827 *type = GL_INT;
7828 *numParams = 1;
7829 return true;
7830 }
7831 }
7832
Yizhou Jiang7818a852018-09-06 15:02:04 +08007833 if (getExtensions().textureMultisample)
7834 {
7835 switch (pname)
7836 {
7837 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7838 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7839 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7840 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007841 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007842 *type = GL_INT;
7843 *numParams = 1;
7844 return true;
7845 }
7846 }
7847
Jamie Madill5b772312018-03-08 20:28:32 -05007848 if (getClientVersion() < Version(3, 1))
7849 {
7850 return false;
7851 }
7852
7853 switch (pname)
7854 {
7855 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7856 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7857 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7858 case GL_MAX_FRAMEBUFFER_WIDTH:
7859 case GL_MAX_FRAMEBUFFER_HEIGHT:
7860 case GL_MAX_FRAMEBUFFER_SAMPLES:
7861 case GL_MAX_SAMPLE_MASK_WORDS:
7862 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7863 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7864 case GL_MAX_INTEGER_SAMPLES:
7865 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7866 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7867 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7868 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7869 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7870 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7871 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7872 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7873 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7874 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7875 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7876 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7877 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7878 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7879 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7880 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7881 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7882 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7883 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7884 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7885 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7886 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7887 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7888 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7889 case GL_MAX_UNIFORM_LOCATIONS:
7890 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7891 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7892 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7893 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7894 case GL_MAX_IMAGE_UNITS:
7895 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7896 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7897 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7898 case GL_SHADER_STORAGE_BUFFER_BINDING:
7899 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7900 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007901 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007902 *type = GL_INT;
7903 *numParams = 1;
7904 return true;
7905 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7906 *type = GL_INT_64_ANGLEX;
7907 *numParams = 1;
7908 return true;
7909 case GL_SAMPLE_MASK:
7910 *type = GL_BOOL;
7911 *numParams = 1;
7912 return true;
7913 }
7914
7915 if (getExtensions().geometryShader)
7916 {
7917 switch (pname)
7918 {
7919 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7920 case GL_LAYER_PROVOKING_VERTEX_EXT:
7921 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7922 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7923 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7924 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7925 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7926 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7927 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7928 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7929 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7930 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7931 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7932 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7933 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7934 *type = GL_INT;
7935 *numParams = 1;
7936 return true;
7937 }
7938 }
7939
7940 return false;
7941}
7942
7943bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7944{
7945 if (getClientVersion() < Version(3, 0))
7946 {
7947 return false;
7948 }
7949
7950 switch (target)
7951 {
7952 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7953 case GL_UNIFORM_BUFFER_BINDING:
7954 {
7955 *type = GL_INT;
7956 *numParams = 1;
7957 return true;
7958 }
7959 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7960 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7961 case GL_UNIFORM_BUFFER_START:
7962 case GL_UNIFORM_BUFFER_SIZE:
7963 {
7964 *type = GL_INT_64_ANGLEX;
7965 *numParams = 1;
7966 return true;
7967 }
7968 }
7969
7970 if (getClientVersion() < Version(3, 1))
7971 {
7972 return false;
7973 }
7974
7975 switch (target)
7976 {
7977 case GL_IMAGE_BINDING_LAYERED:
7978 {
7979 *type = GL_BOOL;
7980 *numParams = 1;
7981 return true;
7982 }
7983 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7984 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7985 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7986 case GL_SHADER_STORAGE_BUFFER_BINDING:
7987 case GL_VERTEX_BINDING_BUFFER:
7988 case GL_VERTEX_BINDING_DIVISOR:
7989 case GL_VERTEX_BINDING_OFFSET:
7990 case GL_VERTEX_BINDING_STRIDE:
7991 case GL_SAMPLE_MASK_VALUE:
7992 case GL_IMAGE_BINDING_NAME:
7993 case GL_IMAGE_BINDING_LEVEL:
7994 case GL_IMAGE_BINDING_LAYER:
7995 case GL_IMAGE_BINDING_ACCESS:
7996 case GL_IMAGE_BINDING_FORMAT:
7997 {
7998 *type = GL_INT;
7999 *numParams = 1;
8000 return true;
8001 }
8002 case GL_ATOMIC_COUNTER_BUFFER_START:
8003 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8004 case GL_SHADER_STORAGE_BUFFER_START:
8005 case GL_SHADER_STORAGE_BUFFER_SIZE:
8006 {
8007 *type = GL_INT_64_ANGLEX;
8008 *numParams = 1;
8009 return true;
8010 }
8011 }
8012
8013 return false;
8014}
8015
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008016Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008017{
8018 return mState.mShaderPrograms->getProgram(handle);
8019}
8020
8021Shader *Context::getShader(GLuint handle) const
8022{
8023 return mState.mShaderPrograms->getShader(handle);
8024}
8025
Jamie Madill5b772312018-03-08 20:28:32 -05008026bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8027{
8028 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8029}
8030
8031bool Context::isFramebufferGenerated(GLuint framebuffer) const
8032{
8033 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8034}
8035
8036bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8037{
8038 return mState.mPipelines->isHandleGenerated(pipeline);
8039}
8040
8041bool Context::usingDisplayTextureShareGroup() const
8042{
8043 return mDisplayTextureShareGroup;
8044}
8045
8046GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8047{
8048 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8049 internalformat == GL_DEPTH_STENCIL
8050 ? GL_DEPTH24_STENCIL8
8051 : internalformat;
8052}
8053
jchen1082af6202018-06-22 10:59:52 +08008054void Context::maxShaderCompilerThreads(GLuint count)
8055{
jchen107ae70d82018-07-06 13:47:01 +08008056 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008057 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008058 // A count of zero specifies a request for no parallel compiling or linking.
8059 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8060 {
8061 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8062 }
8063 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008064}
8065
Jamie Madill2eb65032018-07-30 10:25:57 -04008066bool Context::isGLES1() const
8067{
8068 return mState.getClientVersion() < Version(2, 0);
8069}
8070
Jamie Madilla11819d2018-07-30 10:26:01 -04008071void Context::onSubjectStateChange(const Context *context,
8072 angle::SubjectIndex index,
8073 angle::SubjectMessage message)
8074{
Jamie Madilla11819d2018-07-30 10:26:01 -04008075 switch (index)
8076 {
8077 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008078 switch (message)
8079 {
8080 case angle::SubjectMessage::CONTENTS_CHANGED:
8081 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8082 mStateCache.onVertexArrayBufferContentsChange(this);
8083 break;
8084 case angle::SubjectMessage::RESOURCE_MAPPED:
8085 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8086 case angle::SubjectMessage::BINDING_CHANGED:
8087 mStateCache.onVertexArrayBufferStateChange(this);
8088 break;
8089 default:
8090 break;
8091 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008092 break;
8093
8094 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008095 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8096 {
8097 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8098 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008099 break;
8100
8101 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008102 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8103 {
8104 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
8105 }
8106 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008107 break;
8108
8109 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008110 if (index < kTextureMaxSubjectIndex)
8111 {
8112 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008113 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008114 }
Jamie Madille25b8002018-09-20 13:39:49 -04008115 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008116 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008117 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008118 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008119 }
Jamie Madille25b8002018-09-20 13:39:49 -04008120 else
8121 {
8122 ASSERT(index < kSamplerMaxSubjectIndex);
8123 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8124 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008125 break;
8126 }
8127}
8128
Jamie Madill6b873dd2018-07-12 23:56:30 -04008129// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008130ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008131
8132ErrorSet::~ErrorSet() = default;
8133
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008134void ErrorSet::handleError(GLenum errorCode,
8135 const char *message,
8136 const char *file,
8137 const char *function,
8138 unsigned int line)
8139{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008140 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8141 {
8142 mContext->markContextLost();
8143 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008144
Jamie Madill4f6592f2018-11-27 16:37:45 -05008145 std::stringstream errorStream;
8146 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8147 << line << ". " << message;
8148
8149 // validationError does the necessary work to process the error.
8150 validationError(errorCode, errorStream.str().c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008151}
8152
Jamie Madilla139f012018-10-10 16:13:03 -04008153void ErrorSet::validationError(GLenum errorCode, const char *message)
8154{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008155 ASSERT(errorCode != GL_NO_ERROR);
8156 mErrors.insert(errorCode);
8157
8158 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8159 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008160}
8161
Jamie Madill6b873dd2018-07-12 23:56:30 -04008162bool ErrorSet::empty() const
8163{
8164 return mErrors.empty();
8165}
8166
8167GLenum ErrorSet::popError()
8168{
8169 ASSERT(!empty());
8170 GLenum error = *mErrors.begin();
8171 mErrors.erase(mErrors.begin());
8172 return error;
8173}
Jamie Madilldc358af2018-07-31 11:22:13 -04008174
8175// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008176StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008177 : mCachedHasAnyEnabledClientAttrib(false),
8178 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008179 mCachedInstancedVertexElementLimit(0),
8180 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008181{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008182
8183StateCache::~StateCache() = default;
8184
Jamie Madillac66f982018-10-09 18:30:01 -04008185void StateCache::initialize(Context *context)
8186{
8187 updateValidDrawModes(context);
8188 updateValidBindTextureTypes(context);
8189}
8190
Jamie Madilldc358af2018-07-31 11:22:13 -04008191void StateCache::updateActiveAttribsMask(Context *context)
8192{
8193 bool isGLES1 = context->isGLES1();
8194 const State &glState = context->getGLState();
8195
8196 if (!isGLES1 && !glState.getProgram())
8197 {
8198 mCachedActiveBufferedAttribsMask = AttributesMask();
8199 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008200 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008201 return;
8202 }
8203
8204 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8205 : glState.getProgram()->getActiveAttribLocationsMask();
8206
8207 const VertexArray *vao = glState.getVertexArray();
8208 ASSERT(vao);
8209
8210 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8211 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008212 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008213
Jamie Madill0a17e482018-08-31 17:19:11 -04008214 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8215 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008216 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008217 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8218}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008219
8220void StateCache::updateVertexElementLimits(Context *context)
8221{
8222 const VertexArray *vao = context->getGLState().getVertexArray();
8223
8224 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8225 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8226
8227 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8228 // If there are no buffered attributes then we should not limit the draw call count.
8229 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8230 {
8231 return;
8232 }
8233
8234 const auto &vertexAttribs = vao->getVertexAttributes();
8235 const auto &vertexBindings = vao->getVertexBindings();
8236
8237 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8238 {
8239 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8240 ASSERT(attrib.enabled);
8241
8242 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8243 ASSERT(context->isGLES1() ||
8244 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8245
8246 GLint64 limit = attrib.getCachedElementLimit();
8247 if (binding.getDivisor() > 0)
8248 {
8249 mCachedInstancedVertexElementLimit =
8250 std::min(mCachedInstancedVertexElementLimit, limit);
8251 }
8252 else
8253 {
8254 mCachedNonInstancedVertexElementLimit =
8255 std::min(mCachedNonInstancedVertexElementLimit, limit);
8256 }
8257 }
8258}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008259
Jamie Madilld84b6732018-09-06 15:54:35 -04008260void StateCache::updateBasicDrawStatesError()
8261{
8262 mCachedBasicDrawStatesError = kInvalidPointer;
8263}
8264
8265intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8266{
8267 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8268 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8269 return mCachedBasicDrawStatesError;
8270}
8271
Jamie Madillc43cdad2018-08-08 15:49:25 -04008272void StateCache::onVertexArrayBindingChange(Context *context)
8273{
8274 updateActiveAttribsMask(context);
8275 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008276 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008277}
8278
8279void StateCache::onProgramExecutableChange(Context *context)
8280{
8281 updateActiveAttribsMask(context);
8282 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008283 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008284 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008285}
8286
Jamie Madilld84b6732018-09-06 15:54:35 -04008287void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008288{
8289 updateVertexElementLimits(context);
8290}
8291
Jamie Madilld84b6732018-09-06 15:54:35 -04008292void StateCache::onVertexArrayBufferContentsChange(Context *context)
8293{
8294 updateVertexElementLimits(context);
8295 updateBasicDrawStatesError();
8296}
8297
Jamie Madillc43cdad2018-08-08 15:49:25 -04008298void StateCache::onVertexArrayStateChange(Context *context)
8299{
8300 updateActiveAttribsMask(context);
8301 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008302 updateBasicDrawStatesError();
8303}
8304
8305void StateCache::onVertexArrayBufferStateChange(Context *context)
8306{
8307 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008308}
8309
8310void StateCache::onGLES1ClientStateChange(Context *context)
8311{
8312 updateActiveAttribsMask(context);
8313}
Jamie Madilld84b6732018-09-06 15:54:35 -04008314
8315void StateCache::onDrawFramebufferChange(Context *context)
8316{
8317 updateBasicDrawStatesError();
8318}
8319
8320void StateCache::onContextCapChange(Context *context)
8321{
8322 updateBasicDrawStatesError();
8323}
8324
8325void StateCache::onStencilStateChange(Context *context)
8326{
8327 updateBasicDrawStatesError();
8328}
8329
8330void StateCache::onDefaultVertexAttributeChange(Context *context)
8331{
8332 updateBasicDrawStatesError();
8333}
8334
8335void StateCache::onActiveTextureChange(Context *context)
8336{
8337 updateBasicDrawStatesError();
8338}
8339
8340void StateCache::onQueryChange(Context *context)
8341{
8342 updateBasicDrawStatesError();
8343}
8344
8345void StateCache::onTransformFeedbackChange(Context *context)
8346{
8347 updateBasicDrawStatesError();
8348}
8349
8350void StateCache::onUniformBufferStateChange(Context *context)
8351{
8352 updateBasicDrawStatesError();
8353}
8354
8355void StateCache::onBufferBindingChange(Context *context)
8356{
8357 updateBasicDrawStatesError();
8358}
Jamie Madill526a6f62018-09-12 11:03:05 -04008359
8360void StateCache::updateValidDrawModes(Context *context)
8361{
8362 Program *program = context->getGLState().getProgram();
8363 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8364 {
Jamie Madill752d2202018-11-27 13:29:48 -05008365 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008366 }
8367 else
8368 {
8369 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8370
8371 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8372
8373 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008374 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8375 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8376 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8377 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8378 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8379 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8380 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8381 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8382 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8383 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8384 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008385 }};
8386 }
8387}
Jamie Madillac66f982018-10-09 18:30:01 -04008388
8389void StateCache::updateValidBindTextureTypes(Context *context)
8390{
8391 const Extensions &exts = context->getExtensions();
8392 bool isGLES3 = context->getClientMajorVersion() >= 3;
8393 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8394
8395 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008396 {TextureType::_2D, true},
8397 {TextureType::_2DArray, isGLES3},
8398 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8399 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8400 {TextureType::_3D, isGLES3},
8401 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8402 {TextureType::Rectangle, exts.textureRectangle},
8403 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008404 }};
8405}
Jamie Madillc29968b2016-01-20 11:17:23 -05008406} // namespace gl