blob: 150301f83d6b40b79f014542367711723871a282 [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 Madill8dc27f92018-11-29 11:45:44 -05002245void Context::drawElements(PrimitiveMode mode,
2246 GLsizei count,
2247 DrawElementsType type,
2248 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002249{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002250 // No-op if count draws no primitives for given mode
2251 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002252 {
2253 return;
2254 }
2255
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002256 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002257 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002258}
2259
Jamie Madill493f9572018-05-24 19:52:15 -04002260void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002261 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002262 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002263 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002264 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002265{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002266 // No-op if count draws no primitives for given mode
2267 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002268 {
2269 return;
2270 }
2271
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002272 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002273 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002274 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002275}
2276
Jamie Madill493f9572018-05-24 19:52:15 -04002277void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002278 GLuint start,
2279 GLuint end,
2280 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002281 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002282 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002283{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002284 // No-op if count draws no primitives for given mode
2285 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002286 {
2287 return;
2288 }
2289
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002290 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002291 ANGLE_CONTEXT_TRY(
2292 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002293}
2294
Jamie Madill493f9572018-05-24 19:52:15 -04002295void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002296{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002297 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002298 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002299}
2300
Jamie Madill8dc27f92018-11-29 11:45:44 -05002301void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002302{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002303 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002304 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002305}
2306
Jamie Madill675fe712016-12-19 13:07:54 -05002307void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002308{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002309 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002310}
2311
Jamie Madill675fe712016-12-19 13:07:54 -05002312void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002313{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002314 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002315}
2316
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317void Context::insertEventMarker(GLsizei length, const char *marker)
2318{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002319 ASSERT(mImplementation);
2320 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002321}
2322
2323void Context::pushGroupMarker(GLsizei length, const char *marker)
2324{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002325 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002326
2327 if (marker == nullptr)
2328 {
2329 // From the EXT_debug_marker spec,
2330 // "If <marker> is null then an empty string is pushed on the stack."
2331 mImplementation->pushGroupMarker(length, "");
2332 }
2333 else
2334 {
2335 mImplementation->pushGroupMarker(length, marker);
2336 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002337}
2338
2339void Context::popGroupMarker()
2340{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002341 ASSERT(mImplementation);
2342 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002343}
2344
Geoff Langd8605522016-04-13 10:19:12 -04002345void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2346{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002347 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002348 ASSERT(programObject);
2349
2350 programObject->bindUniformLocation(location, name);
2351}
2352
Brandon Jones59770802018-04-02 13:18:42 -07002353void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002355 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002356}
2357
Brandon Jones59770802018-04-02 13:18:42 -07002358void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359{
2360 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2361}
2362
Brandon Jones59770802018-04-02 13:18:42 -07002363void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002364{
2365 GLfloat I[16];
2366 angle::Matrix<GLfloat>::setToIdentity(I);
2367
2368 mGLState.loadPathRenderingMatrix(matrixMode, I);
2369}
2370
2371void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2372{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002373 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374 if (!pathObj)
2375 return;
2376
Geoff Lang9bf86f02018-07-26 11:46:34 -04002377 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002378
2379 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2380}
2381
2382void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2383{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002384 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385 if (!pathObj)
2386 return;
2387
Geoff Lang9bf86f02018-07-26 11:46:34 -04002388 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002389
2390 mImplementation->stencilStrokePath(pathObj, reference, mask);
2391}
2392
2393void Context::coverFillPath(GLuint path, GLenum coverMode)
2394{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002395 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396 if (!pathObj)
2397 return;
2398
Geoff Lang9bf86f02018-07-26 11:46:34 -04002399 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002400
2401 mImplementation->coverFillPath(pathObj, coverMode);
2402}
2403
2404void Context::coverStrokePath(GLuint path, GLenum coverMode)
2405{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002406 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002407 if (!pathObj)
2408 return;
2409
Geoff Lang9bf86f02018-07-26 11:46:34 -04002410 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002411
2412 mImplementation->coverStrokePath(pathObj, coverMode);
2413}
2414
2415void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2416{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002417 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002418 if (!pathObj)
2419 return;
2420
Geoff Lang9bf86f02018-07-26 11:46:34 -04002421 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002422
2423 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2424}
2425
2426void Context::stencilThenCoverStrokePath(GLuint path,
2427 GLint reference,
2428 GLuint mask,
2429 GLenum coverMode)
2430{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002432 if (!pathObj)
2433 return;
2434
Geoff Lang9bf86f02018-07-26 11:46:34 -04002435 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002436
2437 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2438}
2439
Sami Väisänend59ca052016-06-21 16:10:00 +03002440void Context::coverFillPathInstanced(GLsizei numPaths,
2441 GLenum pathNameType,
2442 const void *paths,
2443 GLuint pathBase,
2444 GLenum coverMode,
2445 GLenum transformType,
2446 const GLfloat *transformValues)
2447{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002448 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002449
Geoff Lang9bf86f02018-07-26 11:46:34 -04002450 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002451
2452 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2453}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002454
Sami Väisänend59ca052016-06-21 16:10:00 +03002455void Context::coverStrokePathInstanced(GLsizei numPaths,
2456 GLenum pathNameType,
2457 const void *paths,
2458 GLuint pathBase,
2459 GLenum coverMode,
2460 GLenum transformType,
2461 const GLfloat *transformValues)
2462{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002464
2465 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002466 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002467
2468 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2469 transformValues);
2470}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002471
Sami Väisänend59ca052016-06-21 16:10:00 +03002472void Context::stencilFillPathInstanced(GLsizei numPaths,
2473 GLenum pathNameType,
2474 const void *paths,
2475 GLuint pathBase,
2476 GLenum fillMode,
2477 GLuint mask,
2478 GLenum transformType,
2479 const GLfloat *transformValues)
2480{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002481 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002482
2483 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002484 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002485
2486 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2487 transformValues);
2488}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002489
Sami Väisänend59ca052016-06-21 16:10:00 +03002490void Context::stencilStrokePathInstanced(GLsizei numPaths,
2491 GLenum pathNameType,
2492 const void *paths,
2493 GLuint pathBase,
2494 GLint reference,
2495 GLuint mask,
2496 GLenum transformType,
2497 const GLfloat *transformValues)
2498{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002499 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002500
Geoff Lang9bf86f02018-07-26 11:46:34 -04002501 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002502
2503 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2504 transformValues);
2505}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002506
Sami Väisänend59ca052016-06-21 16:10:00 +03002507void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2508 GLenum pathNameType,
2509 const void *paths,
2510 GLuint pathBase,
2511 GLenum fillMode,
2512 GLuint mask,
2513 GLenum coverMode,
2514 GLenum transformType,
2515 const GLfloat *transformValues)
2516{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002517 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002518
Geoff Lang9bf86f02018-07-26 11:46:34 -04002519 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002520
2521 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2522 transformType, transformValues);
2523}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002524
Sami Väisänend59ca052016-06-21 16:10:00 +03002525void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2526 GLenum pathNameType,
2527 const void *paths,
2528 GLuint pathBase,
2529 GLint reference,
2530 GLuint mask,
2531 GLenum coverMode,
2532 GLenum transformType,
2533 const GLfloat *transformValues)
2534{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002535 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002536
Geoff Lang9bf86f02018-07-26 11:46:34 -04002537 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002538
2539 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2540 transformType, transformValues);
2541}
2542
Sami Väisänen46eaa942016-06-29 10:26:37 +03002543void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002545 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002546
2547 programObject->bindFragmentInputLocation(location, name);
2548}
2549
2550void Context::programPathFragmentInputGen(GLuint program,
2551 GLint location,
2552 GLenum genMode,
2553 GLint components,
2554 const GLfloat *coeffs)
2555{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002556 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002557
jchen103fd614d2018-08-13 12:21:58 +08002558 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002559}
2560
jchen1015015f72017-03-16 13:54:21 +08002561GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2562{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002563 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002564 return QueryProgramResourceIndex(programObject, programInterface, name);
2565}
2566
jchen10fd7c3b52017-03-21 15:36:03 +08002567void Context::getProgramResourceName(GLuint program,
2568 GLenum programInterface,
2569 GLuint index,
2570 GLsizei bufSize,
2571 GLsizei *length,
2572 GLchar *name)
2573{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002574 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002575 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2576}
2577
jchen10191381f2017-04-11 13:59:04 +08002578GLint Context::getProgramResourceLocation(GLuint program,
2579 GLenum programInterface,
2580 const GLchar *name)
2581{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002582 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002583 return QueryProgramResourceLocation(programObject, programInterface, name);
2584}
2585
jchen10880683b2017-04-12 16:21:55 +08002586void Context::getProgramResourceiv(GLuint program,
2587 GLenum programInterface,
2588 GLuint index,
2589 GLsizei propCount,
2590 const GLenum *props,
2591 GLsizei bufSize,
2592 GLsizei *length,
2593 GLint *params)
2594{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002595 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002596 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2597 length, params);
2598}
2599
jchen10d9cd7b72017-08-30 15:04:25 +08002600void Context::getProgramInterfaceiv(GLuint program,
2601 GLenum programInterface,
2602 GLenum pname,
2603 GLint *params)
2604{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002605 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002606 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2607}
2608
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002609void Context::getProgramInterfaceivRobust(GLuint program,
2610 GLenum programInterface,
2611 GLenum pname,
2612 GLsizei bufSize,
2613 GLsizei *length,
2614 GLint *params)
2615{
2616 UNIMPLEMENTED();
2617}
2618
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002619void Context::handleError(GLenum errorCode,
2620 const char *message,
2621 const char *file,
2622 const char *function,
2623 unsigned int line)
2624{
2625 mErrors.handleError(errorCode, message, file, function, line);
2626}
2627
Jamie Madilla139f012018-10-10 16:13:03 -04002628void Context::validationError(GLenum errorCode, const char *message)
2629{
2630 mErrors.validationError(errorCode, message);
2631}
2632
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002633// Get one of the recorded errors and clear its flag, if any.
2634// [OpenGL ES 2.0.24] section 2.5 page 13.
2635GLenum Context::getError()
2636{
Geoff Langda5777c2014-07-11 09:52:58 -04002637 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638 {
Geoff Langda5777c2014-07-11 09:52:58 -04002639 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002640 }
Geoff Langda5777c2014-07-11 09:52:58 -04002641 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002643 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002644 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645}
2646
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002648void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002649{
2650 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002651 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002652 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002653 mContextLostForced = true;
2654 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002655 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002656}
2657
Jamie Madillfa920eb2018-01-04 11:45:50 -05002658GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002660 // Even if the application doesn't want to know about resets, we want to know
2661 // as it will allow us to skip all the calls.
2662 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002664 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002665 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002667 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002668
2669 // EXT_robustness, section 2.6: If the reset notification behavior is
2670 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2671 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2672 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 }
2674
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002675 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2676 // status should be returned at least once, and GL_NO_ERROR should be returned
2677 // once the device has finished resetting.
2678 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 ASSERT(mResetStatus == GL_NO_ERROR);
2681 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002682
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002685 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686 }
2687 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002688 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002689 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002690 // If markContextLost was used to mark the context lost then
2691 // assume that is not recoverable, and continue to report the
2692 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002693 mResetStatus = mImplementation->getResetStatus();
2694 }
Jamie Madill893ab082014-05-16 16:56:10 -04002695
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002696 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002697}
2698
2699bool Context::isResetNotificationEnabled()
2700{
2701 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2702}
2703
Corentin Walleze3b10e82015-05-20 11:06:25 -04002704const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002705{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002706 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002707}
2708
2709EGLenum Context::getClientType() const
2710{
2711 return mClientType;
2712}
2713
2714EGLenum Context::getRenderBuffer() const
2715{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002716 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2717 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002718 {
2719 return EGL_NONE;
2720 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002721
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002722 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002723 ASSERT(backAttachment != nullptr);
2724 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002725}
2726
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002727VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002728{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002729 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002730 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2731 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002732 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002733 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2734 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002735
Jamie Madill96a483b2017-06-27 16:49:21 -04002736 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002737 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002738
2739 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002740}
2741
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002742TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002743{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002744 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002745 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2746 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002747 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002748 transformFeedback =
2749 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002750 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002751 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002752 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002753
2754 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002755}
2756
2757bool Context::isVertexArrayGenerated(GLuint vertexArray)
2758{
Jamie Madill96a483b2017-06-27 16:49:21 -04002759 ASSERT(mVertexArrayMap.contains(0));
2760 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002761}
2762
2763bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2764{
Jamie Madill96a483b2017-06-27 16:49:21 -04002765 ASSERT(mTransformFeedbackMap.contains(0));
2766 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002767}
2768
Shannon Woods53a94a82014-06-24 15:20:36 -04002769void Context::detachTexture(GLuint texture)
2770{
2771 // Simple pass-through to State's detachTexture method, as textures do not require
2772 // allocation map management either here or in the resource manager at detach time.
2773 // Zero textures are held by the Context, and we don't attempt to request them from
2774 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002775 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002776}
2777
James Darpinian4d9d4832018-03-13 12:43:28 -07002778void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002779{
Yuly Novikov5807a532015-12-03 13:01:22 -05002780 // Simple pass-through to State's detachBuffer method, since
2781 // only buffer attachments to container objects that are bound to the current context
2782 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002783
Yuly Novikov5807a532015-12-03 13:01:22 -05002784 // [OpenGL ES 3.2] section 5.1.2 page 45:
2785 // Attachments to unbound container objects, such as
2786 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2787 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002788 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002789}
2790
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002791void Context::detachFramebuffer(GLuint framebuffer)
2792{
Shannon Woods53a94a82014-06-24 15:20:36 -04002793 // Framebuffer detachment is handled by Context, because 0 is a valid
2794 // Framebuffer object, and a pointer to it must be passed from Context
2795 // to State at binding time.
2796
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002797 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002798 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2799 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2800 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002802 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803 {
2804 bindReadFramebuffer(0);
2805 }
2806
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002807 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002808 {
2809 bindDrawFramebuffer(0);
2810 }
2811}
2812
2813void Context::detachRenderbuffer(GLuint renderbuffer)
2814{
Jamie Madilla02315b2017-02-23 14:14:47 -05002815 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002816}
2817
Jamie Madill57a89722013-07-02 11:57:03 -04002818void Context::detachVertexArray(GLuint vertexArray)
2819{
Jamie Madill77a72f62015-04-14 11:18:32 -04002820 // Vertex array detachment is handled by Context, because 0 is a valid
2821 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002822 // binding time.
2823
Jamie Madill57a89722013-07-02 11:57:03 -04002824 // [OpenGL ES 3.0.2] section 2.10 page 43:
2825 // If a vertex array object that is currently bound is deleted, the binding
2826 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002827 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002828 {
2829 bindVertexArray(0);
2830 }
2831}
2832
Geoff Langc8058452014-02-03 12:04:11 -05002833void Context::detachTransformFeedback(GLuint transformFeedback)
2834{
Corentin Walleza2257da2016-04-19 16:43:12 -04002835 // Transform feedback detachment is handled by Context, because 0 is a valid
2836 // transform feedback, and a pointer to it must be passed from Context to State at
2837 // binding time.
2838
2839 // The OpenGL specification doesn't mention what should happen when the currently bound
2840 // transform feedback object is deleted. Since it is a container object, we treat it like
2841 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002842 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002843 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002844 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002845 }
Geoff Langc8058452014-02-03 12:04:11 -05002846}
2847
Jamie Madilldc356042013-07-19 16:36:57 -04002848void Context::detachSampler(GLuint sampler)
2849{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002850 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002851}
2852
Yunchao Hea336b902017-08-02 16:05:21 +08002853void Context::detachProgramPipeline(GLuint pipeline)
2854{
2855 mGLState.detachProgramPipeline(this, pipeline);
2856}
2857
Jamie Madill3ef140a2017-08-26 23:11:21 -04002858void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002859{
Shaodde78e82017-05-22 14:13:27 +08002860 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002861 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002862}
2863
Jamie Madille29d1672013-07-19 16:36:57 -04002864void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2865{
Till Rathmannb8543632018-10-02 19:46:14 +02002866 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002867 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002868 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002869}
Jamie Madille29d1672013-07-19 16:36:57 -04002870
Geoff Langc1984ed2016-10-07 12:41:00 -04002871void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2872{
Till Rathmannb8543632018-10-02 19:46:14 +02002873 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002874 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002875 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002876}
2877
Till Rathmannb8543632018-10-02 19:46:14 +02002878void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2879{
2880 Sampler *const samplerObject =
2881 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2882 SetSamplerParameterIiv(this, samplerObject, pname, param);
2883}
2884
2885void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2886{
2887 Sampler *const samplerObject =
2888 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2889 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2890}
2891
Brandon Jones59770802018-04-02 13:18:42 -07002892void Context::samplerParameterivRobust(GLuint sampler,
2893 GLenum pname,
2894 GLsizei bufSize,
2895 const GLint *param)
2896{
2897 samplerParameteriv(sampler, pname, param);
2898}
2899
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002900void Context::samplerParameterIivRobust(GLuint sampler,
2901 GLenum pname,
2902 GLsizei bufSize,
2903 const GLint *param)
2904{
2905 UNIMPLEMENTED();
2906}
2907
2908void Context::samplerParameterIuivRobust(GLuint sampler,
2909 GLenum pname,
2910 GLsizei bufSize,
2911 const GLuint *param)
2912{
2913 UNIMPLEMENTED();
2914}
2915
Jamie Madille29d1672013-07-19 16:36:57 -04002916void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2917{
Till Rathmannb8543632018-10-02 19:46:14 +02002918 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002919 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002920 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002921}
2922
Geoff Langc1984ed2016-10-07 12:41:00 -04002923void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002924{
Till Rathmannb8543632018-10-02 19:46:14 +02002925 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002926 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002927 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002928}
2929
Brandon Jones59770802018-04-02 13:18:42 -07002930void Context::samplerParameterfvRobust(GLuint sampler,
2931 GLenum pname,
2932 GLsizei bufSize,
2933 const GLfloat *param)
2934{
2935 samplerParameterfv(sampler, pname, param);
2936}
2937
Geoff Langc1984ed2016-10-07 12:41:00 -04002938void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002939{
Till Rathmannb8543632018-10-02 19:46:14 +02002940 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002941 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002942 QuerySamplerParameteriv(samplerObject, pname, params);
2943}
Jamie Madill9675b802013-07-19 16:36:59 -04002944
Till Rathmannb8543632018-10-02 19:46:14 +02002945void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2946{
2947 const Sampler *const samplerObject =
2948 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2949 QuerySamplerParameterIiv(samplerObject, pname, params);
2950}
2951
2952void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2953{
2954 const Sampler *const samplerObject =
2955 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2956 QuerySamplerParameterIuiv(samplerObject, pname, params);
2957}
2958
Brandon Jones59770802018-04-02 13:18:42 -07002959void Context::getSamplerParameterivRobust(GLuint sampler,
2960 GLenum pname,
2961 GLsizei bufSize,
2962 GLsizei *length,
2963 GLint *params)
2964{
2965 getSamplerParameteriv(sampler, pname, params);
2966}
2967
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002968void Context::getSamplerParameterIivRobust(GLuint sampler,
2969 GLenum pname,
2970 GLsizei bufSize,
2971 GLsizei *length,
2972 GLint *params)
2973{
2974 UNIMPLEMENTED();
2975}
2976
2977void Context::getSamplerParameterIuivRobust(GLuint sampler,
2978 GLenum pname,
2979 GLsizei bufSize,
2980 GLsizei *length,
2981 GLuint *params)
2982{
2983 UNIMPLEMENTED();
2984}
2985
Geoff Langc1984ed2016-10-07 12:41:00 -04002986void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2987{
Till Rathmannb8543632018-10-02 19:46:14 +02002988 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002989 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002990 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002991}
2992
Brandon Jones59770802018-04-02 13:18:42 -07002993void Context::getSamplerParameterfvRobust(GLuint sampler,
2994 GLenum pname,
2995 GLsizei bufSize,
2996 GLsizei *length,
2997 GLfloat *params)
2998{
2999 getSamplerParameterfv(sampler, pname, params);
3000}
3001
Olli Etuahof0fee072016-03-30 15:11:58 +03003002void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3003{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003004 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003005 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003006}
3007
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003008void Context::initRendererString()
3009{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003010 std::ostringstream rendererString;
3011 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003012 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003013 rendererString << ")";
3014
Geoff Langcec35902014-04-16 10:52:36 -04003015 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003016}
3017
Geoff Langc339c4e2016-11-29 10:37:36 -05003018void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 const Version &clientVersion = getClientVersion();
3021
3022 std::ostringstream versionString;
3023 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3024 << ANGLE_VERSION_STRING << ")";
3025 mVersionString = MakeStaticString(versionString.str());
3026
3027 std::ostringstream shadingLanguageVersionString;
3028 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3029 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3030 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3031 << ")";
3032 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003033}
3034
Geoff Langcec35902014-04-16 10:52:36 -04003035void Context::initExtensionStrings()
3036{
Geoff Langc339c4e2016-11-29 10:37:36 -05003037 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3038 std::ostringstream combinedStringStream;
3039 std::copy(strings.begin(), strings.end(),
3040 std::ostream_iterator<const char *>(combinedStringStream, " "));
3041 return MakeStaticString(combinedStringStream.str());
3042 };
3043
3044 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003045 for (const auto &extensionString : mExtensions.getStrings())
3046 {
3047 mExtensionStrings.push_back(MakeStaticString(extensionString));
3048 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003049 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003050
Geoff Langc339c4e2016-11-29 10:37:36 -05003051 mRequestableExtensionStrings.clear();
3052 for (const auto &extensionInfo : GetExtensionInfoMap())
3053 {
3054 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003055 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003056 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003057 {
3058 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3059 }
3060 }
3061 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003062}
3063
Geoff Langc339c4e2016-11-29 10:37:36 -05003064const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003065{
Geoff Langc339c4e2016-11-29 10:37:36 -05003066 switch (name)
3067 {
3068 case GL_VENDOR:
3069 return reinterpret_cast<const GLubyte *>("Google Inc.");
3070
3071 case GL_RENDERER:
3072 return reinterpret_cast<const GLubyte *>(mRendererString);
3073
3074 case GL_VERSION:
3075 return reinterpret_cast<const GLubyte *>(mVersionString);
3076
3077 case GL_SHADING_LANGUAGE_VERSION:
3078 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3079
3080 case GL_EXTENSIONS:
3081 return reinterpret_cast<const GLubyte *>(mExtensionString);
3082
3083 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3084 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3085
3086 default:
3087 UNREACHABLE();
3088 return nullptr;
3089 }
Geoff Langcec35902014-04-16 10:52:36 -04003090}
3091
Geoff Langc339c4e2016-11-29 10:37:36 -05003092const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003093{
Geoff Langc339c4e2016-11-29 10:37:36 -05003094 switch (name)
3095 {
3096 case GL_EXTENSIONS:
3097 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3098
3099 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3100 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3101
3102 default:
3103 UNREACHABLE();
3104 return nullptr;
3105 }
Geoff Langcec35902014-04-16 10:52:36 -04003106}
3107
3108size_t Context::getExtensionStringCount() const
3109{
3110 return mExtensionStrings.size();
3111}
3112
Geoff Lang111a99e2017-10-17 10:58:41 -04003113bool Context::isExtensionRequestable(const char *name)
3114{
3115 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3116 auto extension = extensionInfos.find(name);
3117
Geoff Lang111a99e2017-10-17 10:58:41 -04003118 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003119 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003120}
3121
Geoff Langc339c4e2016-11-29 10:37:36 -05003122void Context::requestExtension(const char *name)
3123{
3124 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3125 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3126 const auto &extension = extensionInfos.at(name);
3127 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003128 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003129
3130 if (mExtensions.*(extension.ExtensionsMember))
3131 {
3132 // Extension already enabled
3133 return;
3134 }
3135
3136 mExtensions.*(extension.ExtensionsMember) = true;
3137 updateCaps();
3138 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003139
Jamie Madill2f348d22017-06-05 10:50:59 -04003140 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3141 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003142
Jamie Madill81c2e252017-09-09 23:32:46 -04003143 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3144 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003145 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003146 for (auto &zeroTexture : mZeroTextures)
3147 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003148 if (zeroTexture.get() != nullptr)
3149 {
3150 zeroTexture->signalDirty(this, InitState::Initialized);
3151 }
Geoff Lang9aded172017-04-05 11:07:56 -04003152 }
3153
Jamie Madillb983a4b2018-08-01 11:34:51 -04003154 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003155}
3156
3157size_t Context::getRequestableExtensionStringCount() const
3158{
3159 return mRequestableExtensionStrings.size();
3160}
3161
Jamie Madill493f9572018-05-24 19:52:15 -04003162void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003163{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003164 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003165 ASSERT(transformFeedback != nullptr);
3166 ASSERT(!transformFeedback->isPaused());
3167
Jamie Madill6c1f6712017-02-14 19:08:04 -05003168 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003169 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003170}
3171
3172bool Context::hasActiveTransformFeedback(GLuint program) const
3173{
3174 for (auto pair : mTransformFeedbackMap)
3175 {
3176 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3177 {
3178 return true;
3179 }
3180 }
3181 return false;
3182}
3183
Geoff Lang33f11fb2018-05-07 13:42:47 -04003184Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003185{
3186 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3187
jchen1082af6202018-06-22 10:59:52 +08003188 // Explicitly enable GL_KHR_parallel_shader_compile
3189 supportedExtensions.parallelShaderCompile = true;
3190
Geoff Langb0f917f2017-12-05 13:41:54 -05003191 if (getClientVersion() < ES_2_0)
3192 {
3193 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003194 supportedExtensions.pointSizeArray = true;
3195 supportedExtensions.textureCubeMap = true;
3196 supportedExtensions.pointSprite = true;
3197 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003198 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003199 }
3200
3201 if (getClientVersion() < ES_3_0)
3202 {
3203 // Disable ES3+ extensions
3204 supportedExtensions.colorBufferFloat = false;
3205 supportedExtensions.eglImageExternalEssl3 = false;
3206 supportedExtensions.textureNorm16 = false;
3207 supportedExtensions.multiview = false;
3208 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003209 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003210 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003211
3212 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3213 if (!supportedExtensions.sRGB)
3214 {
3215 supportedExtensions.textureSRGBDecode = false;
3216 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003217 }
3218
3219 if (getClientVersion() < ES_3_1)
3220 {
3221 // Disable ES3.1+ extensions
3222 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003223
3224 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3225 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003226 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003227 }
3228
3229 if (getClientVersion() > ES_2_0)
3230 {
3231 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3232 // supportedExtensions.sRGB = false;
3233 }
3234
3235 // Some extensions are always available because they are implemented in the GL layer.
3236 supportedExtensions.bindUniformLocation = true;
3237 supportedExtensions.vertexArrayObject = true;
3238 supportedExtensions.bindGeneratesResource = true;
3239 supportedExtensions.clientArrays = true;
3240 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003241 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003242
3243 // Enable the no error extension if the context was created with the flag.
3244 supportedExtensions.noError = mSkipValidation;
3245
3246 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003247 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003248
3249 // Explicitly enable GL_KHR_debug
3250 supportedExtensions.debug = true;
3251 supportedExtensions.maxDebugMessageLength = 1024;
3252 supportedExtensions.maxDebugLoggedMessages = 1024;
3253 supportedExtensions.maxDebugGroupStackDepth = 1024;
3254 supportedExtensions.maxLabelLength = 1024;
3255
3256 // Explicitly enable GL_ANGLE_robust_client_memory
3257 supportedExtensions.robustClientMemory = true;
3258
3259 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003260 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003261
3262 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3263 // supports it.
3264 supportedExtensions.robustBufferAccessBehavior =
3265 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3266
3267 // Enable the cache control query unconditionally.
3268 supportedExtensions.programCacheControl = true;
3269
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003270 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003271 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003272 {
3273 // GL_ANGLE_explicit_context_gles1
3274 supportedExtensions.explicitContextGles1 = true;
3275 // GL_ANGLE_explicit_context
3276 supportedExtensions.explicitContext = true;
3277 }
3278
Geoff Lang79b91402018-10-04 15:11:30 -04003279 supportedExtensions.memorySize = true;
3280
Geoff Langb0f917f2017-12-05 13:41:54 -05003281 return supportedExtensions;
3282}
3283
Geoff Lang33f11fb2018-05-07 13:42:47 -04003284void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003285{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003286 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003287
Geoff Lang33f11fb2018-05-07 13:42:47 -04003288 mSupportedExtensions = generateSupportedExtensions();
3289 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003290
3291 mLimitations = mImplementation->getNativeLimitations();
3292
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003293 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3294 if (getClientVersion() < Version(2, 0))
3295 {
3296 mCaps.maxMultitextureUnits = 4;
3297 mCaps.maxClipPlanes = 6;
3298 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003299 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3300 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3301 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003302 mCaps.minSmoothPointSize = 1.0f;
3303 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003304 mCaps.minSmoothLineWidth = 1.0f;
3305 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003306 }
3307
Luc Ferronad2ae932018-06-11 15:31:17 -04003308 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003309 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003310
Luc Ferronad2ae932018-06-11 15:31:17 -04003311 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3312
Jamie Madill0f80ed82017-09-19 00:24:56 -04003313 if (getClientVersion() < ES_3_1)
3314 {
3315 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3316 }
3317 else
3318 {
3319 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3320 }
Geoff Lang301d1612014-07-09 10:34:37 -04003321
Jiawei Shao54aafe52018-04-27 14:54:57 +08003322 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3323 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003324 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3325
Jamie Madill0f80ed82017-09-19 00:24:56 -04003326 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3327 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3328
3329 // Limit textures as well, so we can use fast bitsets with texture bindings.
3330 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003331 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3332 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3333 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3334 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003335
Jiawei Shaodb342272017-09-27 10:21:45 +08003336 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3337
Geoff Langc287ea62016-09-16 14:46:51 -04003338 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003339 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003340 for (const auto &extensionInfo : GetExtensionInfoMap())
3341 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003342 // If the user has requested that extensions start disabled and they are requestable,
3343 // disable them.
3344 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003345 {
3346 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3347 }
3348 }
3349
3350 // Generate texture caps
3351 updateCaps();
3352}
3353
3354void Context::updateCaps()
3355{
Geoff Lang900013c2014-07-07 11:32:19 -04003356 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003357 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003358
Jamie Madill7b62cf92017-11-02 15:20:49 -04003359 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003360 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003361 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003362 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003363
Geoff Lang0d8b7242015-09-09 14:56:53 -04003364 // Update the format caps based on the client version and extensions.
3365 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3366 // ES3.
3367 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003368 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003369 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003370 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003371 formatCaps.textureAttachment =
3372 formatCaps.textureAttachment &&
3373 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3374 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3375 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003376
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003377 // OpenGL ES does not support multisampling with non-rendererable formats
3378 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003379 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003380 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003381 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003382 {
Geoff Langd87878e2014-09-19 15:42:59 -04003383 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003384 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003385 else
3386 {
3387 // We may have limited the max samples for some required renderbuffer formats due to
3388 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3389 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3390
3391 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3392 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3393 // exception of signed and unsigned integer formats."
3394 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3395 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3396 {
3397 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3398 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3399 }
3400
3401 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003402 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003403 {
3404 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3405 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3406 // the exception that the signed and unsigned integer formats are required only to
3407 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3408 // multisamples, which must be at least one."
3409 if (formatInfo.componentType == GL_INT ||
3410 formatInfo.componentType == GL_UNSIGNED_INT)
3411 {
3412 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3413 }
3414
3415 // GLES 3.1 section 19.3.1.
3416 if (formatCaps.texturable)
3417 {
3418 if (formatInfo.depthBits > 0)
3419 {
3420 mCaps.maxDepthTextureSamples =
3421 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3422 }
3423 else if (formatInfo.redBits > 0)
3424 {
3425 mCaps.maxColorTextureSamples =
3426 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3427 }
3428 }
3429 }
3430 }
Geoff Langd87878e2014-09-19 15:42:59 -04003431
3432 if (formatCaps.texturable && formatInfo.compressed)
3433 {
Geoff Langca271392017-04-05 12:30:00 -04003434 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003435 }
3436
Geoff Langca271392017-04-05 12:30:00 -04003437 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003438 }
Jamie Madill32447362017-06-28 14:53:52 -04003439
3440 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003441 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003442 {
3443 mMemoryProgramCache = nullptr;
3444 }
Corentin Walleze4477002017-12-01 14:39:58 -05003445
3446 // Compute which buffer types are allowed
3447 mValidBufferBindings.reset();
3448 mValidBufferBindings.set(BufferBinding::ElementArray);
3449 mValidBufferBindings.set(BufferBinding::Array);
3450
3451 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3452 {
3453 mValidBufferBindings.set(BufferBinding::PixelPack);
3454 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3455 }
3456
3457 if (getClientVersion() >= ES_3_0)
3458 {
3459 mValidBufferBindings.set(BufferBinding::CopyRead);
3460 mValidBufferBindings.set(BufferBinding::CopyWrite);
3461 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3462 mValidBufferBindings.set(BufferBinding::Uniform);
3463 }
3464
3465 if (getClientVersion() >= ES_3_1)
3466 {
3467 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3468 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3469 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3470 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3471 }
jchen107ae70d82018-07-06 13:47:01 +08003472
3473 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003474
3475 // Reinitialize state cache after extension changes.
3476 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003477}
3478
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003479void Context::initWorkarounds()
3480{
Jamie Madill761b02c2017-06-23 16:27:06 -04003481 // Apply back-end workarounds.
3482 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3483
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003484 // Lose the context upon out of memory error if the application is
3485 // expecting to watch for those events.
3486 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003487
3488 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3489 {
3490 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3491 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3492 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3493 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003494}
3495
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003496// Return true if the draw is a no-op, else return false.
3497// A no-op draw occurs if the count of vertices is less than the minimum required to
3498// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3499bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3500{
3501 return count < kMinimumPrimitiveCounts[mode];
3502}
3503
3504bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3505{
3506 return (instanceCount == 0) || noopDraw(mode, count);
3507}
3508
Jamie Madill6f755b22018-10-09 12:48:54 -04003509angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003510{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003511 if (mGLES1Renderer)
3512 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003513 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003514 }
3515
Geoff Lang9bf86f02018-07-26 11:46:34 -04003516 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003517
3518 if (isRobustResourceInitEnabled())
3519 {
3520 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3521 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3522 }
3523
Jamie Madill9e63a812018-11-16 12:30:04 +00003524 ANGLE_TRY(syncDirtyBits());
3525 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003526}
3527
Jamie Madill526392d2018-11-16 09:35:14 -05003528angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003529{
Geoff Langa8cb2872018-03-09 16:09:40 -05003530 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003531 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003532 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003533 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003534}
3535
Jamie Madill526392d2018-11-16 09:35:14 -05003536angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003537{
Geoff Langa8cb2872018-03-09 16:09:40 -05003538 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003539 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3540 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003541 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill526392d2018-11-16 09:35:14 -05003542 return angle::Result::Continue();
Jamie Madill05b35b22017-10-03 09:01:44 -04003543}
3544
Jamie Madill526392d2018-11-16 09:35:14 -05003545angle::Result Context::syncState(const State::DirtyBits &bitMask,
3546 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003547{
Geoff Langa8cb2872018-03-09 16:09:40 -05003548 ANGLE_TRY(syncDirtyObjects(objectMask));
3549 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill526392d2018-11-16 09:35:14 -05003550 return angle::Result::Continue();
Geoff Langd4fff502017-09-22 11:28:28 -04003551}
3552
Jamie Madill9e63a812018-11-16 12:30:04 +00003553angle::Result Context::syncDirtyBits()
3554{
3555 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3556 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3557 mGLState.clearDirtyBits();
3558 return angle::Result::Continue();
3559}
3560
3561angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3562{
3563 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3564 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3565 mGLState.clearDirtyBits(dirtyBits);
3566 return angle::Result::Continue();
3567}
3568
Jamie Madillc29968b2016-01-20 11:17:23 -05003569void Context::blitFramebuffer(GLint srcX0,
3570 GLint srcY0,
3571 GLint srcX1,
3572 GLint srcY1,
3573 GLint dstX0,
3574 GLint dstY0,
3575 GLint dstX1,
3576 GLint dstY1,
3577 GLbitfield mask,
3578 GLenum filter)
3579{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003580 if (mask == 0)
3581 {
3582 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3583 // buffers are copied.
3584 return;
3585 }
3586
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003588 ASSERT(drawFramebuffer);
3589
3590 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3591 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3592
Jamie Madillbc918e72018-03-08 09:47:21 -05003593 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003594
Jamie Madill4f6592f2018-11-27 16:37:45 -05003595 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003596}
Jamie Madillc29968b2016-01-20 11:17:23 -05003597
3598void Context::clear(GLbitfield mask)
3599{
Geoff Langd4fff502017-09-22 11:28:28 -04003600 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3601 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003602}
3603
3604void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3605{
Olli Etuaho78df3362018-10-05 16:43:27 +03003606 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3607 const FramebufferAttachment *attachment = nullptr;
3608 if (buffer == GL_DEPTH)
3609 {
3610 attachment = framebufferObject->getDepthbuffer();
3611 }
3612 if (buffer == GL_COLOR &&
3613 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3614 {
3615 attachment = framebufferObject->getColorbuffer(drawbuffer);
3616 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003617 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3618 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003619 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003620 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003621 return;
3622 }
Geoff Langd4fff502017-09-22 11:28:28 -04003623 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003624 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003625}
3626
3627void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3628{
Olli Etuaho78df3362018-10-05 16:43:27 +03003629 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3630 const FramebufferAttachment *attachment = nullptr;
3631 if (buffer == GL_COLOR &&
3632 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3633 {
3634 attachment = framebufferObject->getColorbuffer(drawbuffer);
3635 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003636 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3637 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003638 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003639 {
3640 return;
3641 }
Geoff Langd4fff502017-09-22 11:28:28 -04003642 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003643 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003644}
3645
3646void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3647{
Olli Etuaho78df3362018-10-05 16:43:27 +03003648 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3649 const FramebufferAttachment *attachment = nullptr;
3650 if (buffer == GL_STENCIL)
3651 {
3652 attachment = framebufferObject->getStencilbuffer();
3653 }
3654 if (buffer == GL_COLOR &&
3655 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3656 {
3657 attachment = framebufferObject->getColorbuffer(drawbuffer);
3658 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003659 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3660 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003661 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003662 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003663 return;
3664 }
Geoff Langd4fff502017-09-22 11:28:28 -04003665 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003666 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003667}
3668
3669void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3670{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003672 ASSERT(framebufferObject);
3673
3674 // If a buffer is not present, the clear has no effect
3675 if (framebufferObject->getDepthbuffer() == nullptr &&
3676 framebufferObject->getStencilbuffer() == nullptr)
3677 {
3678 return;
3679 }
3680
Geoff Langd4fff502017-09-22 11:28:28 -04003681 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3682 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003683}
3684
3685void Context::readPixels(GLint x,
3686 GLint y,
3687 GLsizei width,
3688 GLsizei height,
3689 GLenum format,
3690 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003691 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003692{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003693 if (width == 0 || height == 0)
3694 {
3695 return;
3696 }
3697
Jamie Madillbc918e72018-03-08 09:47:21 -05003698 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003699
Jamie Madillb6664922017-07-25 12:55:04 -04003700 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3701 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702
3703 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003704 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003705}
3706
Brandon Jones59770802018-04-02 13:18:42 -07003707void Context::readPixelsRobust(GLint x,
3708 GLint y,
3709 GLsizei width,
3710 GLsizei height,
3711 GLenum format,
3712 GLenum type,
3713 GLsizei bufSize,
3714 GLsizei *length,
3715 GLsizei *columns,
3716 GLsizei *rows,
3717 void *pixels)
3718{
3719 readPixels(x, y, width, height, format, type, pixels);
3720}
3721
3722void Context::readnPixelsRobust(GLint x,
3723 GLint y,
3724 GLsizei width,
3725 GLsizei height,
3726 GLenum format,
3727 GLenum type,
3728 GLsizei bufSize,
3729 GLsizei *length,
3730 GLsizei *columns,
3731 GLsizei *rows,
3732 void *data)
3733{
3734 readPixels(x, y, width, height, format, type, data);
3735}
3736
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003737void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 GLint level,
3739 GLenum internalformat,
3740 GLint x,
3741 GLint y,
3742 GLsizei width,
3743 GLsizei height,
3744 GLint border)
3745{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003746 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003747 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003748
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 Rectangle sourceArea(x, y, width, height);
3750
Jamie Madill05b35b22017-10-03 09:01:44 -04003751 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003752 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003753 ANGLE_CONTEXT_TRY(
3754 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003755}
3756
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003757void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 GLint level,
3759 GLint xoffset,
3760 GLint yoffset,
3761 GLint x,
3762 GLint y,
3763 GLsizei width,
3764 GLsizei height)
3765{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003766 if (width == 0 || height == 0)
3767 {
3768 return;
3769 }
3770
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003771 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003772 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003773
Jamie Madillc29968b2016-01-20 11:17:23 -05003774 Offset destOffset(xoffset, yoffset, 0);
3775 Rectangle sourceArea(x, y, width, height);
3776
Jamie Madill05b35b22017-10-03 09:01:44 -04003777 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003778 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003779 ANGLE_CONTEXT_TRY(
3780 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003781}
3782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003783void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003784 GLint level,
3785 GLint xoffset,
3786 GLint yoffset,
3787 GLint zoffset,
3788 GLint x,
3789 GLint y,
3790 GLsizei width,
3791 GLsizei height)
3792{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003793 if (width == 0 || height == 0)
3794 {
3795 return;
3796 }
3797
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003798 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003799 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003800
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 Offset destOffset(xoffset, yoffset, zoffset);
3802 Rectangle sourceArea(x, y, width, height);
3803
Jamie Madill05b35b22017-10-03 09:01:44 -04003804 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3805 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003806 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3807 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003808}
3809
3810void Context::framebufferTexture2D(GLenum target,
3811 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003812 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003813 GLuint texture,
3814 GLint level)
3815{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003817 ASSERT(framebuffer);
3818
3819 if (texture != 0)
3820 {
3821 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003822 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003823 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003824 }
3825 else
3826 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003827 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003828 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003829
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003831}
3832
3833void Context::framebufferRenderbuffer(GLenum target,
3834 GLenum attachment,
3835 GLenum renderbuffertarget,
3836 GLuint renderbuffer)
3837{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003839 ASSERT(framebuffer);
3840
3841 if (renderbuffer != 0)
3842 {
3843 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003844
Jamie Madillcc129372018-04-12 09:13:18 -04003845 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003846 renderbufferObject);
3847 }
3848 else
3849 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003850 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003851 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003852
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003853 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003854}
3855
3856void Context::framebufferTextureLayer(GLenum target,
3857 GLenum attachment,
3858 GLuint texture,
3859 GLint level,
3860 GLint layer)
3861{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003863 ASSERT(framebuffer);
3864
3865 if (texture != 0)
3866 {
3867 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003868 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003869 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003870 }
3871 else
3872 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003873 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003874 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003875
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003877}
3878
Brandon Jones59770802018-04-02 13:18:42 -07003879void Context::framebufferTextureMultiviewLayered(GLenum target,
3880 GLenum attachment,
3881 GLuint texture,
3882 GLint level,
3883 GLint baseViewIndex,
3884 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003885{
Martin Radev82ef7742017-08-08 17:44:58 +03003886 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3887 ASSERT(framebuffer);
3888
3889 if (texture != 0)
3890 {
3891 Texture *textureObj = getTexture(texture);
3892
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003893 ImageIndex index;
3894 if (textureObj->getType() == TextureType::_2DArray)
3895 {
3896 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3897 }
3898 else
3899 {
3900 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3901 ASSERT(level == 0);
3902 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3903 }
Martin Radev82ef7742017-08-08 17:44:58 +03003904 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3905 numViews, baseViewIndex);
3906 }
3907 else
3908 {
3909 framebuffer->resetAttachment(this, attachment);
3910 }
3911
3912 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003913}
3914
Brandon Jones59770802018-04-02 13:18:42 -07003915void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3916 GLenum attachment,
3917 GLuint texture,
3918 GLint level,
3919 GLsizei numViews,
3920 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003921{
Martin Radev5dae57b2017-07-14 16:15:55 +03003922 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3923 ASSERT(framebuffer);
3924
3925 if (texture != 0)
3926 {
3927 Texture *textureObj = getTexture(texture);
3928
3929 ImageIndex index = ImageIndex::Make2D(level);
3930 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3931 textureObj, numViews, viewportOffsets);
3932 }
3933 else
3934 {
3935 framebuffer->resetAttachment(this, attachment);
3936 }
3937
3938 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003939}
3940
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003941void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3942{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003943 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3944 ASSERT(framebuffer);
3945
3946 if (texture != 0)
3947 {
3948 Texture *textureObj = getTexture(texture);
3949
3950 ImageIndex index = ImageIndex::MakeFromType(
3951 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3952 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3953 }
3954 else
3955 {
3956 framebuffer->resetAttachment(this, attachment);
3957 }
3958
3959 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003960}
3961
Jamie Madillc29968b2016-01-20 11:17:23 -05003962void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3963{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003964 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003965 ASSERT(framebuffer);
3966 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003967 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003968 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003969}
3970
3971void Context::readBuffer(GLenum mode)
3972{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003974 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003975 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003976}
3977
3978void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3979{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003980 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003981 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003982
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003984 ASSERT(framebuffer);
3985
3986 // The specification isn't clear what should be done when the framebuffer isn't complete.
3987 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003988 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003989}
3990
3991void Context::invalidateFramebuffer(GLenum target,
3992 GLsizei numAttachments,
3993 const GLenum *attachments)
3994{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003995 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003996 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003997
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003998 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003999 ASSERT(framebuffer);
4000
Jamie Madill427064d2018-04-13 16:20:34 -04004001 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004002 {
Jamie Madill437fa652016-05-03 15:13:24 -04004003 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004004 }
Jamie Madill437fa652016-05-03 15:13:24 -04004005
Jamie Madill4f6592f2018-11-27 16:37:45 -05004006 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004007}
4008
4009void Context::invalidateSubFramebuffer(GLenum target,
4010 GLsizei numAttachments,
4011 const GLenum *attachments,
4012 GLint x,
4013 GLint y,
4014 GLsizei width,
4015 GLsizei height)
4016{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004017 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004018 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004019
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004020 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004021 ASSERT(framebuffer);
4022
Jamie Madill427064d2018-04-13 16:20:34 -04004023 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004024 {
Jamie Madill437fa652016-05-03 15:13:24 -04004025 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004026 }
Jamie Madill437fa652016-05-03 15:13:24 -04004027
4028 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004029 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004030}
4031
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004032void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004033 GLint level,
4034 GLint internalformat,
4035 GLsizei width,
4036 GLsizei height,
4037 GLint border,
4038 GLenum format,
4039 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004040 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004041{
Jamie Madillbc918e72018-03-08 09:47:21 -05004042 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004043
4044 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004045 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004046 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4047 internalformat, size, format, type,
4048 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004049}
4050
Brandon Jones59770802018-04-02 13:18:42 -07004051void Context::texImage2DRobust(TextureTarget target,
4052 GLint level,
4053 GLint internalformat,
4054 GLsizei width,
4055 GLsizei height,
4056 GLint border,
4057 GLenum format,
4058 GLenum type,
4059 GLsizei bufSize,
4060 const void *pixels)
4061{
4062 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4063}
4064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004065void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004066 GLint level,
4067 GLint internalformat,
4068 GLsizei width,
4069 GLsizei height,
4070 GLsizei depth,
4071 GLint border,
4072 GLenum format,
4073 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004074 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004075{
Jamie Madillbc918e72018-03-08 09:47:21 -05004076 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004077
4078 Extents size(width, height, depth);
4079 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004080 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4081 NonCubeTextureTypeToTarget(target), level, internalformat,
4082 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004083}
4084
Brandon Jones59770802018-04-02 13:18:42 -07004085void Context::texImage3DRobust(TextureType target,
4086 GLint level,
4087 GLint internalformat,
4088 GLsizei width,
4089 GLsizei height,
4090 GLsizei depth,
4091 GLint border,
4092 GLenum format,
4093 GLenum type,
4094 GLsizei bufSize,
4095 const void *pixels)
4096{
4097 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4098}
4099
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004100void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004101 GLint level,
4102 GLint xoffset,
4103 GLint yoffset,
4104 GLsizei width,
4105 GLsizei height,
4106 GLenum format,
4107 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004108 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004109{
4110 // Zero sized uploads are valid but no-ops
4111 if (width == 0 || height == 0)
4112 {
4113 return;
4114 }
4115
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004117
4118 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004119 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004120
4121 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4122
Jamie Madill4f6592f2018-11-27 16:37:45 -05004123 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4124 level, area, format, type,
4125 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004126}
4127
Brandon Jones59770802018-04-02 13:18:42 -07004128void Context::texSubImage2DRobust(TextureTarget target,
4129 GLint level,
4130 GLint xoffset,
4131 GLint yoffset,
4132 GLsizei width,
4133 GLsizei height,
4134 GLenum format,
4135 GLenum type,
4136 GLsizei bufSize,
4137 const void *pixels)
4138{
4139 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4140}
4141
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004142void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004143 GLint level,
4144 GLint xoffset,
4145 GLint yoffset,
4146 GLint zoffset,
4147 GLsizei width,
4148 GLsizei height,
4149 GLsizei depth,
4150 GLenum format,
4151 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004152 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004153{
4154 // Zero sized uploads are valid but no-ops
4155 if (width == 0 || height == 0 || depth == 0)
4156 {
4157 return;
4158 }
4159
Jamie Madillbc918e72018-03-08 09:47:21 -05004160 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004161
4162 Box area(xoffset, yoffset, zoffset, width, height, depth);
4163 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004164
4165 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4166
Jamie Madill4f6592f2018-11-27 16:37:45 -05004167 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4168 NonCubeTextureTypeToTarget(target), level, area, format,
4169 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004170}
4171
Brandon Jones59770802018-04-02 13:18:42 -07004172void Context::texSubImage3DRobust(TextureType target,
4173 GLint level,
4174 GLint xoffset,
4175 GLint yoffset,
4176 GLint zoffset,
4177 GLsizei width,
4178 GLsizei height,
4179 GLsizei depth,
4180 GLenum format,
4181 GLenum type,
4182 GLsizei bufSize,
4183 const void *pixels)
4184{
4185 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4186 pixels);
4187}
4188
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004189void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004190 GLint level,
4191 GLenum internalformat,
4192 GLsizei width,
4193 GLsizei height,
4194 GLint border,
4195 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004196 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004197{
Jamie Madillbc918e72018-03-08 09:47:21 -05004198 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004199
4200 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004201 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004202 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4203 internalformat, size, imageSize,
4204 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004205}
4206
Brandon Jones59770802018-04-02 13:18:42 -07004207void Context::compressedTexImage2DRobust(TextureTarget target,
4208 GLint level,
4209 GLenum internalformat,
4210 GLsizei width,
4211 GLsizei height,
4212 GLint border,
4213 GLsizei imageSize,
4214 GLsizei dataSize,
4215 const GLvoid *data)
4216{
4217 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4218}
4219
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004220void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004221 GLint level,
4222 GLenum internalformat,
4223 GLsizei width,
4224 GLsizei height,
4225 GLsizei depth,
4226 GLint border,
4227 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004228 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004229{
Jamie Madillbc918e72018-03-08 09:47:21 -05004230 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004231
4232 Extents size(width, height, depth);
4233 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004234 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004235 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004236 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004237}
4238
Brandon Jones59770802018-04-02 13:18:42 -07004239void Context::compressedTexImage3DRobust(TextureType target,
4240 GLint level,
4241 GLenum internalformat,
4242 GLsizei width,
4243 GLsizei height,
4244 GLsizei depth,
4245 GLint border,
4246 GLsizei imageSize,
4247 GLsizei dataSize,
4248 const GLvoid *data)
4249{
4250 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4251 data);
4252}
4253
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004254void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004255 GLint level,
4256 GLint xoffset,
4257 GLint yoffset,
4258 GLsizei width,
4259 GLsizei height,
4260 GLenum format,
4261 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004262 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004263{
Jamie Madillbc918e72018-03-08 09:47:21 -05004264 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004265
4266 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004267 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004268 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4269 area, format, imageSize,
4270 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004271}
4272
Brandon Jones59770802018-04-02 13:18:42 -07004273void Context::compressedTexSubImage2DRobust(TextureTarget target,
4274 GLint level,
4275 GLint xoffset,
4276 GLint yoffset,
4277 GLsizei width,
4278 GLsizei height,
4279 GLenum format,
4280 GLsizei imageSize,
4281 GLsizei dataSize,
4282 const GLvoid *data)
4283{
4284 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4285 data);
4286}
4287
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004288void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004289 GLint level,
4290 GLint xoffset,
4291 GLint yoffset,
4292 GLint zoffset,
4293 GLsizei width,
4294 GLsizei height,
4295 GLsizei depth,
4296 GLenum format,
4297 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004298 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004299{
4300 // Zero sized uploads are valid but no-ops
4301 if (width == 0 || height == 0)
4302 {
4303 return;
4304 }
4305
Jamie Madillbc918e72018-03-08 09:47:21 -05004306 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004307
4308 Box area(xoffset, yoffset, zoffset, width, height, depth);
4309 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004310 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004311 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004312 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004313}
4314
Brandon Jones59770802018-04-02 13:18:42 -07004315void Context::compressedTexSubImage3DRobust(TextureType target,
4316 GLint level,
4317 GLint xoffset,
4318 GLint yoffset,
4319 GLint zoffset,
4320 GLsizei width,
4321 GLsizei height,
4322 GLsizei depth,
4323 GLenum format,
4324 GLsizei imageSize,
4325 GLsizei dataSize,
4326 const GLvoid *data)
4327{
4328 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4329 imageSize, data);
4330}
4331
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004332void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004333{
4334 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004335 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004336}
4337
Jamie Madill007530e2017-12-28 14:27:04 -05004338void Context::copyTexture(GLuint sourceId,
4339 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004340 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004341 GLuint destId,
4342 GLint destLevel,
4343 GLint internalFormat,
4344 GLenum destType,
4345 GLboolean unpackFlipY,
4346 GLboolean unpackPremultiplyAlpha,
4347 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004348{
Jamie Madillbc918e72018-03-08 09:47:21 -05004349 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004350
4351 gl::Texture *sourceTexture = getTexture(sourceId);
4352 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004353 ANGLE_CONTEXT_TRY(
4354 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4355 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4356 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004357}
4358
Jamie Madill007530e2017-12-28 14:27:04 -05004359void Context::copySubTexture(GLuint sourceId,
4360 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004361 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004362 GLuint destId,
4363 GLint destLevel,
4364 GLint xoffset,
4365 GLint yoffset,
4366 GLint x,
4367 GLint y,
4368 GLsizei width,
4369 GLsizei height,
4370 GLboolean unpackFlipY,
4371 GLboolean unpackPremultiplyAlpha,
4372 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004373{
4374 // Zero sized copies are valid but no-ops
4375 if (width == 0 || height == 0)
4376 {
4377 return;
4378 }
4379
Jamie Madillbc918e72018-03-08 09:47:21 -05004380 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004381
4382 gl::Texture *sourceTexture = getTexture(sourceId);
4383 gl::Texture *destTexture = getTexture(destId);
4384 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004385 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004386 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4387 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4388 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4389 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004390}
4391
4392void Context::copyTexture3D(GLuint sourceId,
4393 GLint sourceLevel,
4394 TextureTarget destTarget,
4395 GLuint destId,
4396 GLint destLevel,
4397 GLint internalFormat,
4398 GLenum destType,
4399 GLboolean unpackFlipY,
4400 GLboolean unpackPremultiplyAlpha,
4401 GLboolean unpackUnmultiplyAlpha)
4402{
4403 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4404
4405 Texture *sourceTexture = getTexture(sourceId);
4406 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004407 ANGLE_CONTEXT_TRY(
4408 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4409 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4410 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004411}
4412
4413void Context::copySubTexture3D(GLuint sourceId,
4414 GLint sourceLevel,
4415 TextureTarget destTarget,
4416 GLuint destId,
4417 GLint destLevel,
4418 GLint xoffset,
4419 GLint yoffset,
4420 GLint zoffset,
4421 GLint x,
4422 GLint y,
4423 GLint z,
4424 GLsizei width,
4425 GLsizei height,
4426 GLsizei depth,
4427 GLboolean unpackFlipY,
4428 GLboolean unpackPremultiplyAlpha,
4429 GLboolean unpackUnmultiplyAlpha)
4430{
4431 // Zero sized copies are valid but no-ops
4432 if (width == 0 || height == 0 || depth == 0)
4433 {
4434 return;
4435 }
4436
4437 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4438
4439 Texture *sourceTexture = getTexture(sourceId);
4440 Texture *destTexture = getTexture(destId);
4441 Offset offset(xoffset, yoffset, zoffset);
4442 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004443 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4444 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4445 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4446 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004447}
4448
Jamie Madill007530e2017-12-28 14:27:04 -05004449void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004450{
Jamie Madillbc918e72018-03-08 09:47:21 -05004451 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004452
4453 gl::Texture *sourceTexture = getTexture(sourceId);
4454 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004455 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004456}
4457
Corentin Wallez336129f2017-10-17 15:55:40 -04004458void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004461 ASSERT(buffer);
4462
Geoff Lang496c02d2016-10-20 11:38:11 -07004463 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004464}
4465
Brandon Jones59770802018-04-02 13:18:42 -07004466void Context::getBufferPointervRobust(BufferBinding target,
4467 GLenum pname,
4468 GLsizei bufSize,
4469 GLsizei *length,
4470 void **params)
4471{
4472 getBufferPointerv(target, pname, params);
4473}
4474
Corentin Wallez336129f2017-10-17 15:55:40 -04004475void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004476{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004478 ASSERT(buffer);
4479
Jamie Madill4f6592f2018-11-27 16:37:45 -05004480 if (buffer->map(this, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004481 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004482 return nullptr;
4483 }
4484
4485 return buffer->getMapPointer();
4486}
4487
Corentin Wallez336129f2017-10-17 15:55:40 -04004488GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004489{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004490 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004491 ASSERT(buffer);
4492
4493 GLboolean result;
Jamie Madill4f6592f2018-11-27 16:37:45 -05004494 if (buffer->unmap(this, &result) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004495 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004496 return GL_FALSE;
4497 }
4498
4499 return result;
4500}
4501
Corentin Wallez336129f2017-10-17 15:55:40 -04004502void *Context::mapBufferRange(BufferBinding target,
4503 GLintptr offset,
4504 GLsizeiptr length,
4505 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004508 ASSERT(buffer);
4509
Jamie Madill4f6592f2018-11-27 16:37:45 -05004510 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop())
Olli Etuaho4f667482016-03-30 15:56:35 +03004511 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004512 return nullptr;
4513 }
4514
4515 return buffer->getMapPointer();
4516}
4517
Corentin Wallez336129f2017-10-17 15:55:40 -04004518void Context::flushMappedBufferRange(BufferBinding /*target*/,
4519 GLintptr /*offset*/,
4520 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004521{
4522 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4523}
4524
Jamie Madill526392d2018-11-16 09:35:14 -05004525angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004526{
Geoff Langa8cb2872018-03-09 16:09:40 -05004527 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004528}
4529
Jamie Madill526392d2018-11-16 09:35:14 -05004530angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004531{
Geoff Langa8cb2872018-03-09 16:09:40 -05004532 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004533}
4534
Jamie Madill526392d2018-11-16 09:35:14 -05004535angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004536{
Geoff Langa8cb2872018-03-09 16:09:40 -05004537 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004538}
4539
Jamie Madill526392d2018-11-16 09:35:14 -05004540angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004541{
4542 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4543
4544 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4545 ANGLE_TRY(syncDirtyBits());
4546
Jamie Madill526392d2018-11-16 09:35:14 -05004547 return angle::Result::Continue();
Geoff Lang9bf86f02018-07-26 11:46:34 -04004548}
4549
Jiajia Qin5451d532017-11-16 17:16:34 +08004550void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4551{
4552 UNIMPLEMENTED();
4553}
4554
Jamie Madillc20ab272016-06-09 07:20:46 -07004555void Context::activeTexture(GLenum texture)
4556{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
Jamie Madill876429b2017-04-20 15:46:24 -04004560void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004565void Context::blendEquation(GLenum mode)
4566{
4567 mGLState.setBlendEquation(mode, mode);
4568}
4569
Jamie Madillc20ab272016-06-09 07:20:46 -07004570void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004575void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4576{
4577 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4578}
4579
Jamie Madillc20ab272016-06-09 07:20:46 -07004580void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004582 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004583}
4584
Jamie Madill876429b2017-04-20 15:46:24 -04004585void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588}
4589
Jamie Madill876429b2017-04-20 15:46:24 -04004590void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004591{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004592 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::clearStencil(GLint s)
4596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
4600void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4601{
Geoff Lang92019432017-11-20 13:09:34 -05004602 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4603 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004604}
4605
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004606void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004608 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::depthFunc(GLenum func)
4612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004613 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004614}
4615
4616void Context::depthMask(GLboolean flag)
4617{
Geoff Lang92019432017-11-20 13:09:34 -05004618 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004619}
4620
Jamie Madill876429b2017-04-20 15:46:24 -04004621void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004622{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004623 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004624}
4625
4626void Context::disable(GLenum cap)
4627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004628 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004629 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630}
4631
4632void Context::disableVertexAttribArray(GLuint index)
4633{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004634 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004635 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
4638void Context::enable(GLenum cap)
4639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004640 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004641 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642}
4643
4644void Context::enableVertexAttribArray(GLuint index)
4645{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004646 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004647 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648}
4649
4650void Context::frontFace(GLenum mode)
4651{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004652 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::hint(GLenum target, GLenum mode)
4656{
4657 switch (target)
4658 {
4659 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004660 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004661 break;
4662
4663 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665 break;
4666
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004667 case GL_PERSPECTIVE_CORRECTION_HINT:
4668 case GL_POINT_SMOOTH_HINT:
4669 case GL_LINE_SMOOTH_HINT:
4670 case GL_FOG_HINT:
4671 mGLState.gles1().setHint(target, mode);
4672 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004673 default:
4674 UNREACHABLE();
4675 return;
4676 }
4677}
4678
4679void Context::lineWidth(GLfloat width)
4680{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::pixelStorei(GLenum pname, GLint param)
4685{
4686 switch (pname)
4687 {
4688 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004689 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004690 break;
4691
4692 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694 break;
4695
4696 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698 break;
4699
4700 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004701 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004703 break;
4704
4705 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004706 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004708 break;
4709
4710 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004711 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713 break;
4714
4715 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004716 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004717 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718 break;
4719
4720 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004721 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004722 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004723 break;
4724
4725 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004726 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004727 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004728 break;
4729
4730 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004731 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004732 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733 break;
4734
4735 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004736 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004737 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004738 break;
4739
4740 default:
4741 UNREACHABLE();
4742 return;
4743 }
4744}
4745
4746void Context::polygonOffset(GLfloat factor, GLfloat units)
4747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004748 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004749}
4750
Jamie Madill876429b2017-04-20 15:46:24 -04004751void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004752{
Geoff Lang92019432017-11-20 13:09:34 -05004753 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004754}
4755
Jiawei Shaodb342272017-09-27 10:21:45 +08004756void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4757{
4758 mGLState.setSampleMaskParams(maskNumber, mask);
4759}
4760
Jamie Madillc20ab272016-06-09 07:20:46 -07004761void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004763 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004764}
4765
4766void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4767{
4768 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004770 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004771 }
4772
4773 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4774 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004775 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004776 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004777
4778 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004779}
4780
4781void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4782{
4783 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4784 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004785 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004786 }
4787
4788 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4789 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004790 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004791 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004792
4793 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004794}
4795
4796void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4797{
4798 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4799 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004800 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004801 }
4802
4803 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4804 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004805 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004806 }
4807}
4808
4809void Context::vertexAttrib1f(GLuint index, GLfloat x)
4810{
4811 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004812 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004813 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004814}
4815
4816void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4817{
4818 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004819 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004820 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004821}
4822
4823void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4824{
4825 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004826 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004827 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004828}
4829
4830void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4831{
4832 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004833 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004834 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004835}
4836
4837void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4838{
4839 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004840 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004841 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004842}
4843
4844void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4845{
4846 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004847 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004848 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004849}
4850
4851void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4852{
4853 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004854 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004855 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004856}
4857
4858void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4859{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004860 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004861 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004862}
4863
4864void Context::vertexAttribPointer(GLuint index,
4865 GLint size,
4866 GLenum type,
4867 GLboolean normalized,
4868 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004869 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004870{
Corentin Wallez336129f2017-10-17 15:55:40 -04004871 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004872 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004873 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004874}
4875
Shao80957d92017-02-20 21:25:59 +08004876void Context::vertexAttribFormat(GLuint attribIndex,
4877 GLint size,
4878 GLenum type,
4879 GLboolean normalized,
4880 GLuint relativeOffset)
4881{
Geoff Lang92019432017-11-20 13:09:34 -05004882 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004883 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004884 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004885}
4886
4887void Context::vertexAttribIFormat(GLuint attribIndex,
4888 GLint size,
4889 GLenum type,
4890 GLuint relativeOffset)
4891{
4892 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004893 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004894}
4895
4896void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4897{
Shaodde78e82017-05-22 14:13:27 +08004898 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004899 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004900}
4901
Jiajia Qin5451d532017-11-16 17:16:34 +08004902void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004903{
4904 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004905 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004906}
4907
Jamie Madillc20ab272016-06-09 07:20:46 -07004908void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004910 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004911}
4912
4913void Context::vertexAttribIPointer(GLuint index,
4914 GLint size,
4915 GLenum type,
4916 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004917 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004918{
Corentin Wallez336129f2017-10-17 15:55:40 -04004919 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4920 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004921 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004922}
4923
4924void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4925{
4926 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004927 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004928 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004929}
4930
4931void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4932{
4933 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004934 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004935 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004936}
4937
4938void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4939{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004940 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004941 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004942}
4943
4944void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4945{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004946 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004947 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004948}
4949
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004950void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4951{
4952 const VertexAttribCurrentValueData &currentValues =
4953 getGLState().getVertexAttribCurrentValue(index);
4954 const VertexArray *vao = getGLState().getVertexArray();
4955 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4956 currentValues, pname, params);
4957}
4958
Brandon Jones59770802018-04-02 13:18:42 -07004959void Context::getVertexAttribivRobust(GLuint index,
4960 GLenum pname,
4961 GLsizei bufSize,
4962 GLsizei *length,
4963 GLint *params)
4964{
4965 getVertexAttribiv(index, pname, params);
4966}
4967
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004968void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4969{
4970 const VertexAttribCurrentValueData &currentValues =
4971 getGLState().getVertexAttribCurrentValue(index);
4972 const VertexArray *vao = getGLState().getVertexArray();
4973 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4974 currentValues, pname, params);
4975}
4976
Brandon Jones59770802018-04-02 13:18:42 -07004977void Context::getVertexAttribfvRobust(GLuint index,
4978 GLenum pname,
4979 GLsizei bufSize,
4980 GLsizei *length,
4981 GLfloat *params)
4982{
4983 getVertexAttribfv(index, pname, params);
4984}
4985
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004986void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4987{
4988 const VertexAttribCurrentValueData &currentValues =
4989 getGLState().getVertexAttribCurrentValue(index);
4990 const VertexArray *vao = getGLState().getVertexArray();
4991 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4992 currentValues, pname, params);
4993}
4994
Brandon Jones59770802018-04-02 13:18:42 -07004995void Context::getVertexAttribIivRobust(GLuint index,
4996 GLenum pname,
4997 GLsizei bufSize,
4998 GLsizei *length,
4999 GLint *params)
5000{
5001 getVertexAttribIiv(index, pname, params);
5002}
5003
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005004void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5005{
5006 const VertexAttribCurrentValueData &currentValues =
5007 getGLState().getVertexAttribCurrentValue(index);
5008 const VertexArray *vao = getGLState().getVertexArray();
5009 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5010 currentValues, pname, params);
5011}
5012
Brandon Jones59770802018-04-02 13:18:42 -07005013void Context::getVertexAttribIuivRobust(GLuint index,
5014 GLenum pname,
5015 GLsizei bufSize,
5016 GLsizei *length,
5017 GLuint *params)
5018{
5019 getVertexAttribIuiv(index, pname, params);
5020}
5021
Jamie Madill876429b2017-04-20 15:46:24 -04005022void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005023{
5024 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5025 QueryVertexAttribPointerv(attrib, pname, pointer);
5026}
5027
Brandon Jones59770802018-04-02 13:18:42 -07005028void Context::getVertexAttribPointervRobust(GLuint index,
5029 GLenum pname,
5030 GLsizei bufSize,
5031 GLsizei *length,
5032 void **pointer)
5033{
5034 getVertexAttribPointerv(index, pname, pointer);
5035}
5036
Jamie Madillc20ab272016-06-09 07:20:46 -07005037void Context::debugMessageControl(GLenum source,
5038 GLenum type,
5039 GLenum severity,
5040 GLsizei count,
5041 const GLuint *ids,
5042 GLboolean enabled)
5043{
5044 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005045 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005046 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005047}
5048
5049void Context::debugMessageInsert(GLenum source,
5050 GLenum type,
5051 GLuint id,
5052 GLenum severity,
5053 GLsizei length,
5054 const GLchar *buf)
5055{
5056 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005057 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005058}
5059
5060void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5061{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005062 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005063}
5064
5065GLuint Context::getDebugMessageLog(GLuint count,
5066 GLsizei bufSize,
5067 GLenum *sources,
5068 GLenum *types,
5069 GLuint *ids,
5070 GLenum *severities,
5071 GLsizei *lengths,
5072 GLchar *messageLog)
5073{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005074 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5075 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005076}
5077
5078void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5079{
5080 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005081 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005082 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005083}
5084
5085void Context::popDebugGroup()
5086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005087 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005088 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005089}
5090
Corentin Wallez336129f2017-10-17 15:55:40 -04005091void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005092{
5093 Buffer *buffer = mGLState.getTargetBuffer(target);
5094 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005095 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005096}
5097
Corentin Wallez336129f2017-10-17 15:55:40 -04005098void Context::bufferSubData(BufferBinding target,
5099 GLintptr offset,
5100 GLsizeiptr size,
5101 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005102{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005103 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005104 {
5105 return;
5106 }
5107
5108 Buffer *buffer = mGLState.getTargetBuffer(target);
5109 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005110 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005111}
5112
Jamie Madillef300b12016-10-07 15:12:09 -04005113void Context::attachShader(GLuint program, GLuint shader)
5114{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005115 Program *programObject = mState.mShaderPrograms->getProgram(program);
5116 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005117 ASSERT(programObject && shaderObject);
5118 programObject->attachShader(shaderObject);
5119}
5120
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005121const Workarounds &Context::getWorkarounds() const
5122{
5123 return mWorkarounds;
5124}
5125
Corentin Wallez336129f2017-10-17 15:55:40 -04005126void Context::copyBufferSubData(BufferBinding readTarget,
5127 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005128 GLintptr readOffset,
5129 GLintptr writeOffset,
5130 GLsizeiptr size)
5131{
5132 // if size is zero, the copy is a successful no-op
5133 if (size == 0)
5134 {
5135 return;
5136 }
5137
5138 // TODO(jmadill): cache these.
5139 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5140 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5141
Jamie Madill4f6592f2018-11-27 16:37:45 -05005142 ANGLE_CONTEXT_TRY(
5143 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005144}
5145
Jamie Madill01a80ee2016-11-07 12:06:18 -05005146void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5147{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005148 // Ideally we could share the program query with the validation layer if possible.
5149 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005150 ASSERT(programObject);
5151 programObject->bindAttributeLocation(index, name);
5152}
5153
Corentin Wallez336129f2017-10-17 15:55:40 -04005154void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005155{
Corentin Wallez336129f2017-10-17 15:55:40 -04005156 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5157 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005158 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005159}
5160
Corentin Wallez336129f2017-10-17 15:55:40 -04005161void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005162{
5163 bindBufferRange(target, index, buffer, 0, 0);
5164}
5165
Corentin Wallez336129f2017-10-17 15:55:40 -04005166void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005167 GLuint index,
5168 GLuint buffer,
5169 GLintptr offset,
5170 GLsizeiptr size)
5171{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005172 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5173 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5174 if (target == BufferBinding::Uniform)
5175 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005176 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005177 mStateCache.onUniformBufferStateChange(this);
5178 }
5179 else
5180 {
5181 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005182 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005183}
5184
Jamie Madill01a80ee2016-11-07 12:06:18 -05005185void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5186{
5187 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5188 {
5189 bindReadFramebuffer(framebuffer);
5190 }
5191
5192 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5193 {
5194 bindDrawFramebuffer(framebuffer);
5195 }
5196}
5197
5198void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5199{
5200 ASSERT(target == GL_RENDERBUFFER);
5201 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005202 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005203 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005204}
5205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005206void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005207 GLsizei samples,
5208 GLenum internalformat,
5209 GLsizei width,
5210 GLsizei height,
5211 GLboolean fixedsamplelocations)
5212{
5213 Extents size(width, height, 1);
5214 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005215 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5216 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005217}
5218
Olli Etuaho89664842018-08-24 14:45:36 +03005219void Context::texStorage3DMultisample(TextureType target,
5220 GLsizei samples,
5221 GLenum internalformat,
5222 GLsizei width,
5223 GLsizei height,
5224 GLsizei depth,
5225 GLboolean fixedsamplelocations)
5226{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005227 Extents size(width, height, depth);
5228 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005229 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5230 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005231}
5232
JiangYizhoubddc46b2016-12-09 09:50:51 +08005233void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5234{
JiangYizhou5b03f472017-01-09 10:22:53 +08005235 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5236 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005237 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005238 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005239
5240 switch (pname)
5241 {
5242 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005243 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005244 break;
5245 default:
5246 UNREACHABLE();
5247 }
5248}
5249
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005250void Context::getMultisamplefvRobust(GLenum pname,
5251 GLuint index,
5252 GLsizei bufSize,
5253 GLsizei *length,
5254 GLfloat *val)
5255{
5256 UNIMPLEMENTED();
5257}
5258
Jamie Madille8fb6402017-02-14 17:56:40 -05005259void Context::renderbufferStorage(GLenum target,
5260 GLenum internalformat,
5261 GLsizei width,
5262 GLsizei height)
5263{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005264 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5265 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5266
Jamie Madille8fb6402017-02-14 17:56:40 -05005267 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005268 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005269}
5270
5271void Context::renderbufferStorageMultisample(GLenum target,
5272 GLsizei samples,
5273 GLenum internalformat,
5274 GLsizei width,
5275 GLsizei height)
5276{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005277 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5278 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005279
5280 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005281 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005282 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005283}
5284
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005285void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5286{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005287 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005288 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005289}
5290
JiangYizhoue18e6392017-02-20 10:32:23 +08005291void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5292{
5293 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5294 QueryFramebufferParameteriv(framebuffer, pname, params);
5295}
5296
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005297void Context::getFramebufferParameterivRobust(GLenum target,
5298 GLenum pname,
5299 GLsizei bufSize,
5300 GLsizei *length,
5301 GLint *params)
5302{
5303 UNIMPLEMENTED();
5304}
5305
Jiajia Qin5451d532017-11-16 17:16:34 +08005306void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005307{
5308 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005309 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005310}
5311
Jamie Madilldec86232018-07-11 09:01:18 -04005312bool Context::getScratchBuffer(size_t requstedSizeBytes,
5313 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005314{
Jamie Madilldec86232018-07-11 09:01:18 -04005315 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005316}
5317
Jamie Madilldec86232018-07-11 09:01:18 -04005318bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5319 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005320{
Jamie Madilldec86232018-07-11 09:01:18 -04005321 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005322}
5323
Jamie Madill526392d2018-11-16 09:35:14 -05005324angle::Result Context::prepareForDispatch()
Xinghua Cao10a4d432017-11-28 14:46:26 +08005325{
Jamie Madill0cc11c62018-10-12 18:07:18 -04005326 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005327
5328 if (isRobustResourceInitEnabled())
5329 {
5330 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5331 }
5332
Jamie Madill0cc11c62018-10-12 18:07:18 -04005333 return syncDirtyBits(mComputeDirtyBits);
Xinghua Cao10a4d432017-11-28 14:46:26 +08005334}
5335
Xinghua Cao2b396592017-03-29 15:36:04 +08005336void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5337{
5338 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5339 {
5340 return;
5341 }
5342
Xinghua Cao10a4d432017-11-28 14:46:26 +08005343 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005344 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005345}
5346
Jiajia Qin5451d532017-11-16 17:16:34 +08005347void Context::dispatchComputeIndirect(GLintptr indirect)
5348{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005349 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005350 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005351}
5352
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005353void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005354 GLsizei levels,
5355 GLenum internalFormat,
5356 GLsizei width,
5357 GLsizei height)
5358{
5359 Extents size(width, height, 1);
5360 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005361 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005362}
5363
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005364void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005365 GLsizei levels,
5366 GLenum internalFormat,
5367 GLsizei width,
5368 GLsizei height,
5369 GLsizei depth)
5370{
5371 Extents size(width, height, depth);
5372 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005373 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005374}
5375
Jiajia Qin5451d532017-11-16 17:16:34 +08005376void Context::memoryBarrier(GLbitfield barriers)
5377{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005378 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005379}
5380
5381void Context::memoryBarrierByRegion(GLbitfield barriers)
5382{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005383 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005384}
5385
Austin Eng1bf18ce2018-10-19 15:34:02 -07005386void Context::multiDrawArrays(PrimitiveMode mode,
5387 const GLint *firsts,
5388 const GLsizei *counts,
5389 GLsizei drawcount)
5390{
5391 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5392 Program *programObject = mGLState.getLinkedProgram(this);
5393 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5394 if (hasDrawID)
5395 {
5396 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5397 {
5398 if (noopDraw(mode, counts[drawID]))
5399 {
5400 continue;
5401 }
5402 programObject->setDrawIDUniform(drawID);
5403 ANGLE_CONTEXT_TRY(
5404 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5405 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5406 counts[drawID], 1);
5407 }
5408 }
5409 else
5410 {
5411 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5412 {
5413 if (noopDraw(mode, counts[drawID]))
5414 {
5415 continue;
5416 }
5417 ANGLE_CONTEXT_TRY(
5418 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5419 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5420 counts[drawID], 1);
5421 }
5422 }
5423}
5424
5425void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5426 const GLint *firsts,
5427 const GLsizei *counts,
5428 const GLsizei *instanceCounts,
5429 GLsizei drawcount)
5430{
5431 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5432 Program *programObject = mGLState.getLinkedProgram(this);
5433 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5434 if (hasDrawID)
5435 {
5436 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5437 {
5438 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5439 {
5440 continue;
5441 }
5442 programObject->setDrawIDUniform(drawID);
5443 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5444 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5445 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5446 counts[drawID], instanceCounts[drawID]);
5447 }
5448 }
5449 else
5450 {
5451 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5452 {
5453 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5454 {
5455 continue;
5456 }
5457 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5458 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5459 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5460 counts[drawID], instanceCounts[drawID]);
5461 }
5462 }
5463}
5464
5465void Context::multiDrawElements(PrimitiveMode mode,
5466 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005467 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005468 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005469 GLsizei drawcount)
5470{
5471 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5472 Program *programObject = mGLState.getLinkedProgram(this);
5473 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5474 if (hasDrawID)
5475 {
5476 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5477 {
5478 if (noopDraw(mode, counts[drawID]))
5479 {
5480 continue;
5481 }
5482 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005483 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005484 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005485 }
5486 }
5487 else
5488 {
5489 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5490 {
5491 if (noopDraw(mode, counts[drawID]))
5492 {
5493 continue;
5494 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005495 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005496 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005497 }
5498 }
5499}
5500
5501void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5502 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005503 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005504 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005505 const GLsizei *instanceCounts,
5506 GLsizei drawcount)
5507{
5508 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5509 Program *programObject = mGLState.getLinkedProgram(this);
5510 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5511 if (hasDrawID)
5512 {
5513 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5514 {
5515 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5516 {
5517 continue;
5518 }
5519 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005520 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005521 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005522 }
5523 }
5524 else
5525 {
5526 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5527 {
5528 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5529 {
5530 continue;
5531 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005532 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005533 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005534 }
5535 }
5536}
5537
Jamie Madillc1d770e2017-04-13 17:31:24 -04005538GLenum Context::checkFramebufferStatus(GLenum target)
5539{
5540 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5541 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005542 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005543}
5544
5545void Context::compileShader(GLuint shader)
5546{
5547 Shader *shaderObject = GetValidShader(this, shader);
5548 if (!shaderObject)
5549 {
5550 return;
5551 }
5552 shaderObject->compile(this);
5553}
5554
5555void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5556{
5557 for (int i = 0; i < n; i++)
5558 {
5559 deleteBuffer(buffers[i]);
5560 }
5561}
5562
5563void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5564{
5565 for (int i = 0; i < n; i++)
5566 {
5567 if (framebuffers[i] != 0)
5568 {
5569 deleteFramebuffer(framebuffers[i]);
5570 }
5571 }
5572}
5573
5574void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5575{
5576 for (int i = 0; i < n; i++)
5577 {
5578 deleteRenderbuffer(renderbuffers[i]);
5579 }
5580}
5581
5582void Context::deleteTextures(GLsizei n, const GLuint *textures)
5583{
5584 for (int i = 0; i < n; i++)
5585 {
5586 if (textures[i] != 0)
5587 {
5588 deleteTexture(textures[i]);
5589 }
5590 }
5591}
5592
5593void Context::detachShader(GLuint program, GLuint shader)
5594{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005595 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005596 ASSERT(programObject);
5597
5598 Shader *shaderObject = getShader(shader);
5599 ASSERT(shaderObject);
5600
5601 programObject->detachShader(this, shaderObject);
5602}
5603
5604void Context::genBuffers(GLsizei n, GLuint *buffers)
5605{
5606 for (int i = 0; i < n; i++)
5607 {
5608 buffers[i] = createBuffer();
5609 }
5610}
5611
5612void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5613{
5614 for (int i = 0; i < n; i++)
5615 {
5616 framebuffers[i] = createFramebuffer();
5617 }
5618}
5619
5620void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5621{
5622 for (int i = 0; i < n; i++)
5623 {
5624 renderbuffers[i] = createRenderbuffer();
5625 }
5626}
5627
5628void Context::genTextures(GLsizei n, GLuint *textures)
5629{
5630 for (int i = 0; i < n; i++)
5631 {
5632 textures[i] = createTexture();
5633 }
5634}
5635
5636void Context::getActiveAttrib(GLuint program,
5637 GLuint index,
5638 GLsizei bufsize,
5639 GLsizei *length,
5640 GLint *size,
5641 GLenum *type,
5642 GLchar *name)
5643{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005644 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005645 ASSERT(programObject);
5646 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5647}
5648
5649void Context::getActiveUniform(GLuint program,
5650 GLuint index,
5651 GLsizei bufsize,
5652 GLsizei *length,
5653 GLint *size,
5654 GLenum *type,
5655 GLchar *name)
5656{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005657 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005658 ASSERT(programObject);
5659 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5660}
5661
5662void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5663{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005664 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005665 ASSERT(programObject);
5666 programObject->getAttachedShaders(maxcount, count, shaders);
5667}
5668
5669GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5670{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005671 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672 ASSERT(programObject);
5673 return programObject->getAttributeLocation(name);
5674}
5675
5676void Context::getBooleanv(GLenum pname, GLboolean *params)
5677{
5678 GLenum nativeType;
5679 unsigned int numParams = 0;
5680 getQueryParameterInfo(pname, &nativeType, &numParams);
5681
5682 if (nativeType == GL_BOOL)
5683 {
5684 getBooleanvImpl(pname, params);
5685 }
5686 else
5687 {
5688 CastStateValues(this, nativeType, pname, numParams, params);
5689 }
5690}
5691
Brandon Jones59770802018-04-02 13:18:42 -07005692void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5693{
5694 getBooleanv(pname, params);
5695}
5696
Jamie Madillc1d770e2017-04-13 17:31:24 -04005697void Context::getFloatv(GLenum pname, GLfloat *params)
5698{
5699 GLenum nativeType;
5700 unsigned int numParams = 0;
5701 getQueryParameterInfo(pname, &nativeType, &numParams);
5702
5703 if (nativeType == GL_FLOAT)
5704 {
5705 getFloatvImpl(pname, params);
5706 }
5707 else
5708 {
5709 CastStateValues(this, nativeType, pname, numParams, params);
5710 }
5711}
5712
Brandon Jones59770802018-04-02 13:18:42 -07005713void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5714{
5715 getFloatv(pname, params);
5716}
5717
Jamie Madillc1d770e2017-04-13 17:31:24 -04005718void Context::getIntegerv(GLenum pname, GLint *params)
5719{
5720 GLenum nativeType;
5721 unsigned int numParams = 0;
5722 getQueryParameterInfo(pname, &nativeType, &numParams);
5723
5724 if (nativeType == GL_INT)
5725 {
5726 getIntegervImpl(pname, params);
5727 }
5728 else
5729 {
5730 CastStateValues(this, nativeType, pname, numParams, params);
5731 }
5732}
5733
Brandon Jones59770802018-04-02 13:18:42 -07005734void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5735{
5736 getIntegerv(pname, data);
5737}
5738
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5740{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005741 // Don't resolve link if checking the link completion status.
5742 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5743 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005745 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005746}
5747
Brandon Jones59770802018-04-02 13:18:42 -07005748void Context::getProgramivRobust(GLuint program,
5749 GLenum pname,
5750 GLsizei bufSize,
5751 GLsizei *length,
5752 GLint *params)
5753{
5754 getProgramiv(program, pname, params);
5755}
5756
Jiajia Qin5451d532017-11-16 17:16:34 +08005757void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5758{
5759 UNIMPLEMENTED();
5760}
5761
Jamie Madillbe849e42017-05-02 15:49:00 -04005762void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005763{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005764 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005765 ASSERT(programObject);
5766 programObject->getInfoLog(bufsize, length, infolog);
5767}
5768
Jiajia Qin5451d532017-11-16 17:16:34 +08005769void Context::getProgramPipelineInfoLog(GLuint pipeline,
5770 GLsizei bufSize,
5771 GLsizei *length,
5772 GLchar *infoLog)
5773{
5774 UNIMPLEMENTED();
5775}
5776
Jamie Madillc1d770e2017-04-13 17:31:24 -04005777void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5778{
5779 Shader *shaderObject = getShader(shader);
5780 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005781 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005782}
5783
Brandon Jones59770802018-04-02 13:18:42 -07005784void Context::getShaderivRobust(GLuint shader,
5785 GLenum pname,
5786 GLsizei bufSize,
5787 GLsizei *length,
5788 GLint *params)
5789{
5790 getShaderiv(shader, pname, params);
5791}
5792
Jamie Madillc1d770e2017-04-13 17:31:24 -04005793void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5794{
5795 Shader *shaderObject = getShader(shader);
5796 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005797 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005798}
5799
5800void Context::getShaderPrecisionFormat(GLenum shadertype,
5801 GLenum precisiontype,
5802 GLint *range,
5803 GLint *precision)
5804{
5805 // TODO(jmadill): Compute shaders.
5806
5807 switch (shadertype)
5808 {
5809 case GL_VERTEX_SHADER:
5810 switch (precisiontype)
5811 {
5812 case GL_LOW_FLOAT:
5813 mCaps.vertexLowpFloat.get(range, precision);
5814 break;
5815 case GL_MEDIUM_FLOAT:
5816 mCaps.vertexMediumpFloat.get(range, precision);
5817 break;
5818 case GL_HIGH_FLOAT:
5819 mCaps.vertexHighpFloat.get(range, precision);
5820 break;
5821
5822 case GL_LOW_INT:
5823 mCaps.vertexLowpInt.get(range, precision);
5824 break;
5825 case GL_MEDIUM_INT:
5826 mCaps.vertexMediumpInt.get(range, precision);
5827 break;
5828 case GL_HIGH_INT:
5829 mCaps.vertexHighpInt.get(range, precision);
5830 break;
5831
5832 default:
5833 UNREACHABLE();
5834 return;
5835 }
5836 break;
5837
5838 case GL_FRAGMENT_SHADER:
5839 switch (precisiontype)
5840 {
5841 case GL_LOW_FLOAT:
5842 mCaps.fragmentLowpFloat.get(range, precision);
5843 break;
5844 case GL_MEDIUM_FLOAT:
5845 mCaps.fragmentMediumpFloat.get(range, precision);
5846 break;
5847 case GL_HIGH_FLOAT:
5848 mCaps.fragmentHighpFloat.get(range, precision);
5849 break;
5850
5851 case GL_LOW_INT:
5852 mCaps.fragmentLowpInt.get(range, precision);
5853 break;
5854 case GL_MEDIUM_INT:
5855 mCaps.fragmentMediumpInt.get(range, precision);
5856 break;
5857 case GL_HIGH_INT:
5858 mCaps.fragmentHighpInt.get(range, precision);
5859 break;
5860
5861 default:
5862 UNREACHABLE();
5863 return;
5864 }
5865 break;
5866
5867 default:
5868 UNREACHABLE();
5869 return;
5870 }
5871}
5872
5873void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5874{
5875 Shader *shaderObject = getShader(shader);
5876 ASSERT(shaderObject);
5877 shaderObject->getSource(bufsize, length, source);
5878}
5879
5880void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5881{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005882 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005883 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005884 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005885}
5886
Brandon Jones59770802018-04-02 13:18:42 -07005887void Context::getUniformfvRobust(GLuint program,
5888 GLint location,
5889 GLsizei bufSize,
5890 GLsizei *length,
5891 GLfloat *params)
5892{
5893 getUniformfv(program, location, params);
5894}
5895
Jamie Madillc1d770e2017-04-13 17:31:24 -04005896void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5897{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005898 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005899 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005900 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901}
5902
Brandon Jones59770802018-04-02 13:18:42 -07005903void Context::getUniformivRobust(GLuint program,
5904 GLint location,
5905 GLsizei bufSize,
5906 GLsizei *length,
5907 GLint *params)
5908{
5909 getUniformiv(program, location, params);
5910}
5911
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5913{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005914 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005915 ASSERT(programObject);
5916 return programObject->getUniformLocation(name);
5917}
5918
5919GLboolean Context::isBuffer(GLuint buffer)
5920{
5921 if (buffer == 0)
5922 {
5923 return GL_FALSE;
5924 }
5925
5926 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5927}
5928
5929GLboolean Context::isEnabled(GLenum cap)
5930{
5931 return mGLState.getEnableFeature(cap);
5932}
5933
5934GLboolean Context::isFramebuffer(GLuint framebuffer)
5935{
5936 if (framebuffer == 0)
5937 {
5938 return GL_FALSE;
5939 }
5940
5941 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5942}
5943
5944GLboolean Context::isProgram(GLuint program)
5945{
5946 if (program == 0)
5947 {
5948 return GL_FALSE;
5949 }
5950
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005951 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005952}
5953
5954GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5955{
5956 if (renderbuffer == 0)
5957 {
5958 return GL_FALSE;
5959 }
5960
5961 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5962}
5963
5964GLboolean Context::isShader(GLuint shader)
5965{
5966 if (shader == 0)
5967 {
5968 return GL_FALSE;
5969 }
5970
5971 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5972}
5973
5974GLboolean Context::isTexture(GLuint texture)
5975{
5976 if (texture == 0)
5977 {
5978 return GL_FALSE;
5979 }
5980
5981 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5982}
5983
5984void Context::linkProgram(GLuint program)
5985{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005986 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005987 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005988 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005989
5990 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5991 // don't need to worry that:
5992 // 1. Draw calls after link use the new executable code or the old one depending on the link
5993 // result.
5994 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5995 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5996 // ProgramD3D.
5997 if (programObject->isInUse())
5998 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005999 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006000 if (programObject->isLinked())
6001 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006002 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006003 }
jchen107ae70d82018-07-06 13:47:01 +08006004 mStateCache.onProgramExecutableChange(this);
6005 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006}
6007
6008void Context::releaseShaderCompiler()
6009{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006010 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006011}
6012
6013void Context::shaderBinary(GLsizei n,
6014 const GLuint *shaders,
6015 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006016 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006017 GLsizei length)
6018{
6019 // No binary shader formats are supported.
6020 UNIMPLEMENTED();
6021}
6022
Olli Etuaho0ca09752018-09-24 11:00:50 +03006023void Context::bindFragDataLocationIndexed(GLuint program,
6024 GLuint colorNumber,
6025 GLuint index,
6026 const char *name)
6027{
6028 Program *programObject = getProgramNoResolveLink(program);
6029 programObject->bindFragmentOutputLocation(colorNumber, name);
6030 programObject->bindFragmentOutputIndex(index, name);
6031}
6032
6033void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6034{
6035 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6036}
6037
6038int Context::getFragDataIndex(GLuint program, const char *name)
6039{
6040 Program *programObject = getProgramResolveLink(program);
6041 return programObject->getFragDataIndex(name);
6042}
6043
6044int Context::getProgramResourceLocationIndex(GLuint program,
6045 GLenum programInterface,
6046 const char *name)
6047{
6048 Program *programObject = getProgramResolveLink(program);
6049 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6050 return programObject->getFragDataIndex(name);
6051}
6052
Jamie Madillc1d770e2017-04-13 17:31:24 -04006053void Context::shaderSource(GLuint shader,
6054 GLsizei count,
6055 const GLchar *const *string,
6056 const GLint *length)
6057{
6058 Shader *shaderObject = getShader(shader);
6059 ASSERT(shaderObject);
6060 shaderObject->setSource(count, string, length);
6061}
6062
6063void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6064{
6065 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6066}
6067
6068void Context::stencilMask(GLuint mask)
6069{
6070 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6071}
6072
6073void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6074{
6075 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6076}
6077
6078void Context::uniform1f(GLint location, GLfloat x)
6079{
6080 Program *program = mGLState.getProgram();
6081 program->setUniform1fv(location, 1, &x);
6082}
6083
6084void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6085{
6086 Program *program = mGLState.getProgram();
6087 program->setUniform1fv(location, count, v);
6088}
6089
Jamie Madill7e4eff12018-08-08 15:49:26 -04006090void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006091{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006092 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04006093 {
6094 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006095 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04006096 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006097}
6098
Jamie Madill7e4eff12018-08-08 15:49:26 -04006099void Context::uniform1i(GLint location, GLint x)
6100{
6101 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6102}
6103
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6105{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006106 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006107}
6108
6109void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6110{
6111 GLfloat xy[2] = {x, y};
6112 Program *program = mGLState.getProgram();
6113 program->setUniform2fv(location, 1, xy);
6114}
6115
6116void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6117{
6118 Program *program = mGLState.getProgram();
6119 program->setUniform2fv(location, count, v);
6120}
6121
6122void Context::uniform2i(GLint location, GLint x, GLint y)
6123{
6124 GLint xy[2] = {x, y};
6125 Program *program = mGLState.getProgram();
6126 program->setUniform2iv(location, 1, xy);
6127}
6128
6129void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6130{
6131 Program *program = mGLState.getProgram();
6132 program->setUniform2iv(location, count, v);
6133}
6134
6135void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6136{
6137 GLfloat xyz[3] = {x, y, z};
6138 Program *program = mGLState.getProgram();
6139 program->setUniform3fv(location, 1, xyz);
6140}
6141
6142void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6143{
6144 Program *program = mGLState.getProgram();
6145 program->setUniform3fv(location, count, v);
6146}
6147
6148void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6149{
6150 GLint xyz[3] = {x, y, z};
6151 Program *program = mGLState.getProgram();
6152 program->setUniform3iv(location, 1, xyz);
6153}
6154
6155void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6156{
6157 Program *program = mGLState.getProgram();
6158 program->setUniform3iv(location, count, v);
6159}
6160
6161void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6162{
6163 GLfloat xyzw[4] = {x, y, z, w};
6164 Program *program = mGLState.getProgram();
6165 program->setUniform4fv(location, 1, xyzw);
6166}
6167
6168void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6169{
6170 Program *program = mGLState.getProgram();
6171 program->setUniform4fv(location, count, v);
6172}
6173
6174void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6175{
6176 GLint xyzw[4] = {x, y, z, w};
6177 Program *program = mGLState.getProgram();
6178 program->setUniform4iv(location, 1, xyzw);
6179}
6180
6181void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6182{
6183 Program *program = mGLState.getProgram();
6184 program->setUniform4iv(location, count, v);
6185}
6186
6187void Context::uniformMatrix2fv(GLint location,
6188 GLsizei count,
6189 GLboolean transpose,
6190 const GLfloat *value)
6191{
6192 Program *program = mGLState.getProgram();
6193 program->setUniformMatrix2fv(location, count, transpose, value);
6194}
6195
6196void Context::uniformMatrix3fv(GLint location,
6197 GLsizei count,
6198 GLboolean transpose,
6199 const GLfloat *value)
6200{
6201 Program *program = mGLState.getProgram();
6202 program->setUniformMatrix3fv(location, count, transpose, value);
6203}
6204
6205void Context::uniformMatrix4fv(GLint location,
6206 GLsizei count,
6207 GLboolean transpose,
6208 const GLfloat *value)
6209{
6210 Program *program = mGLState.getProgram();
6211 program->setUniformMatrix4fv(location, count, transpose, value);
6212}
6213
6214void Context::validateProgram(GLuint program)
6215{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006216 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006217 ASSERT(programObject);
6218 programObject->validate(mCaps);
6219}
6220
Jiajia Qin5451d532017-11-16 17:16:34 +08006221void Context::validateProgramPipeline(GLuint pipeline)
6222{
6223 UNIMPLEMENTED();
6224}
6225
Jamie Madilld04908b2017-06-09 14:15:35 -04006226void Context::getProgramBinary(GLuint program,
6227 GLsizei bufSize,
6228 GLsizei *length,
6229 GLenum *binaryFormat,
6230 void *binary)
6231{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006232 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006233 ASSERT(programObject != nullptr);
6234
Jamie Madill4f6592f2018-11-27 16:37:45 -05006235 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006236}
6237
6238void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6239{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006240 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006241 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006242
Jamie Madill4f6592f2018-11-27 16:37:45 -05006243 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006244 if (programObject->isInUse())
6245 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006246 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006247 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006248 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006249}
6250
Jamie Madillff325f12017-08-26 15:06:05 -04006251void Context::uniform1ui(GLint location, GLuint v0)
6252{
6253 Program *program = mGLState.getProgram();
6254 program->setUniform1uiv(location, 1, &v0);
6255}
6256
6257void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6258{
6259 Program *program = mGLState.getProgram();
6260 const GLuint xy[] = {v0, v1};
6261 program->setUniform2uiv(location, 1, xy);
6262}
6263
6264void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6265{
6266 Program *program = mGLState.getProgram();
6267 const GLuint xyz[] = {v0, v1, v2};
6268 program->setUniform3uiv(location, 1, xyz);
6269}
6270
6271void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6272{
6273 Program *program = mGLState.getProgram();
6274 const GLuint xyzw[] = {v0, v1, v2, v3};
6275 program->setUniform4uiv(location, 1, xyzw);
6276}
6277
6278void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6279{
6280 Program *program = mGLState.getProgram();
6281 program->setUniform1uiv(location, count, value);
6282}
6283void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6284{
6285 Program *program = mGLState.getProgram();
6286 program->setUniform2uiv(location, count, value);
6287}
6288
6289void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6290{
6291 Program *program = mGLState.getProgram();
6292 program->setUniform3uiv(location, count, value);
6293}
6294
6295void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6296{
6297 Program *program = mGLState.getProgram();
6298 program->setUniform4uiv(location, count, value);
6299}
6300
Jamie Madillf0e04492017-08-26 15:28:42 -04006301void Context::genQueries(GLsizei n, GLuint *ids)
6302{
6303 for (GLsizei i = 0; i < n; i++)
6304 {
6305 GLuint handle = mQueryHandleAllocator.allocate();
6306 mQueryMap.assign(handle, nullptr);
6307 ids[i] = handle;
6308 }
6309}
6310
6311void Context::deleteQueries(GLsizei n, const GLuint *ids)
6312{
6313 for (int i = 0; i < n; i++)
6314 {
6315 GLuint query = ids[i];
6316
6317 Query *queryObject = nullptr;
6318 if (mQueryMap.erase(query, &queryObject))
6319 {
6320 mQueryHandleAllocator.release(query);
6321 if (queryObject)
6322 {
6323 queryObject->release(this);
6324 }
6325 }
6326 }
6327}
6328
6329GLboolean Context::isQuery(GLuint id)
6330{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006331 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006332}
6333
Jamie Madillc8c95812017-08-26 18:40:09 -04006334void Context::uniformMatrix2x3fv(GLint location,
6335 GLsizei count,
6336 GLboolean transpose,
6337 const GLfloat *value)
6338{
6339 Program *program = mGLState.getProgram();
6340 program->setUniformMatrix2x3fv(location, count, transpose, value);
6341}
6342
6343void Context::uniformMatrix3x2fv(GLint location,
6344 GLsizei count,
6345 GLboolean transpose,
6346 const GLfloat *value)
6347{
6348 Program *program = mGLState.getProgram();
6349 program->setUniformMatrix3x2fv(location, count, transpose, value);
6350}
6351
6352void Context::uniformMatrix2x4fv(GLint location,
6353 GLsizei count,
6354 GLboolean transpose,
6355 const GLfloat *value)
6356{
6357 Program *program = mGLState.getProgram();
6358 program->setUniformMatrix2x4fv(location, count, transpose, value);
6359}
6360
6361void Context::uniformMatrix4x2fv(GLint location,
6362 GLsizei count,
6363 GLboolean transpose,
6364 const GLfloat *value)
6365{
6366 Program *program = mGLState.getProgram();
6367 program->setUniformMatrix4x2fv(location, count, transpose, value);
6368}
6369
6370void Context::uniformMatrix3x4fv(GLint location,
6371 GLsizei count,
6372 GLboolean transpose,
6373 const GLfloat *value)
6374{
6375 Program *program = mGLState.getProgram();
6376 program->setUniformMatrix3x4fv(location, count, transpose, value);
6377}
6378
6379void Context::uniformMatrix4x3fv(GLint location,
6380 GLsizei count,
6381 GLboolean transpose,
6382 const GLfloat *value)
6383{
6384 Program *program = mGLState.getProgram();
6385 program->setUniformMatrix4x3fv(location, count, transpose, value);
6386}
6387
Jamie Madilld7576732017-08-26 18:49:50 -04006388void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6389{
6390 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6391 {
6392 GLuint vertexArray = arrays[arrayIndex];
6393
6394 if (arrays[arrayIndex] != 0)
6395 {
6396 VertexArray *vertexArrayObject = nullptr;
6397 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6398 {
6399 if (vertexArrayObject != nullptr)
6400 {
6401 detachVertexArray(vertexArray);
6402 vertexArrayObject->onDestroy(this);
6403 }
6404
6405 mVertexArrayHandleAllocator.release(vertexArray);
6406 }
6407 }
6408 }
6409}
6410
6411void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6412{
6413 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6414 {
6415 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6416 mVertexArrayMap.assign(vertexArray, nullptr);
6417 arrays[arrayIndex] = vertexArray;
6418 }
6419}
6420
6421bool Context::isVertexArray(GLuint array)
6422{
6423 if (array == 0)
6424 {
6425 return GL_FALSE;
6426 }
6427
6428 VertexArray *vao = getVertexArray(array);
6429 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6430}
6431
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006432void Context::endTransformFeedback()
6433{
6434 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6435 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006436 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006437}
6438
6439void Context::transformFeedbackVaryings(GLuint program,
6440 GLsizei count,
6441 const GLchar *const *varyings,
6442 GLenum bufferMode)
6443{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006444 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006445 ASSERT(programObject);
6446 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6447}
6448
6449void Context::getTransformFeedbackVarying(GLuint program,
6450 GLuint index,
6451 GLsizei bufSize,
6452 GLsizei *length,
6453 GLsizei *size,
6454 GLenum *type,
6455 GLchar *name)
6456{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006457 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006458 ASSERT(programObject);
6459 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6460}
6461
6462void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6463{
6464 for (int i = 0; i < n; i++)
6465 {
6466 GLuint transformFeedback = ids[i];
6467 if (transformFeedback == 0)
6468 {
6469 continue;
6470 }
6471
6472 TransformFeedback *transformFeedbackObject = nullptr;
6473 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6474 {
6475 if (transformFeedbackObject != nullptr)
6476 {
6477 detachTransformFeedback(transformFeedback);
6478 transformFeedbackObject->release(this);
6479 }
6480
6481 mTransformFeedbackHandleAllocator.release(transformFeedback);
6482 }
6483 }
6484}
6485
6486void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6487{
6488 for (int i = 0; i < n; i++)
6489 {
6490 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6491 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6492 ids[i] = transformFeedback;
6493 }
6494}
6495
6496bool Context::isTransformFeedback(GLuint id)
6497{
6498 if (id == 0)
6499 {
6500 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6501 // returns FALSE
6502 return GL_FALSE;
6503 }
6504
6505 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6506 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6507}
6508
6509void Context::pauseTransformFeedback()
6510{
6511 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6512 transformFeedback->pause();
6513}
6514
6515void Context::resumeTransformFeedback()
6516{
6517 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6518 transformFeedback->resume();
6519}
6520
Jamie Madill12e957f2017-08-26 21:42:26 -04006521void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6522{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006523 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006524 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006525}
6526
Brandon Jones59770802018-04-02 13:18:42 -07006527void Context::getUniformuivRobust(GLuint program,
6528 GLint location,
6529 GLsizei bufSize,
6530 GLsizei *length,
6531 GLuint *params)
6532{
6533 getUniformuiv(program, location, params);
6534}
6535
Jamie Madill12e957f2017-08-26 21:42:26 -04006536GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6537{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006538 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006539 return programObject->getFragDataLocation(name);
6540}
6541
6542void Context::getUniformIndices(GLuint program,
6543 GLsizei uniformCount,
6544 const GLchar *const *uniformNames,
6545 GLuint *uniformIndices)
6546{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006547 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006548 if (!programObject->isLinked())
6549 {
6550 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6551 {
6552 uniformIndices[uniformId] = GL_INVALID_INDEX;
6553 }
6554 }
6555 else
6556 {
6557 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6558 {
6559 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6560 }
6561 }
6562}
6563
6564void Context::getActiveUniformsiv(GLuint program,
6565 GLsizei uniformCount,
6566 const GLuint *uniformIndices,
6567 GLenum pname,
6568 GLint *params)
6569{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006570 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006571 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6572 {
6573 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006574 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006575 }
6576}
6577
6578GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6579{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006580 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006581 return programObject->getUniformBlockIndex(uniformBlockName);
6582}
6583
6584void Context::getActiveUniformBlockiv(GLuint program,
6585 GLuint uniformBlockIndex,
6586 GLenum pname,
6587 GLint *params)
6588{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006589 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006590 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6591}
6592
Brandon Jones59770802018-04-02 13:18:42 -07006593void Context::getActiveUniformBlockivRobust(GLuint program,
6594 GLuint uniformBlockIndex,
6595 GLenum pname,
6596 GLsizei bufSize,
6597 GLsizei *length,
6598 GLint *params)
6599{
6600 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6601}
6602
Jamie Madill12e957f2017-08-26 21:42:26 -04006603void Context::getActiveUniformBlockName(GLuint program,
6604 GLuint uniformBlockIndex,
6605 GLsizei bufSize,
6606 GLsizei *length,
6607 GLchar *uniformBlockName)
6608{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006609 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006610 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6611}
6612
6613void Context::uniformBlockBinding(GLuint program,
6614 GLuint uniformBlockIndex,
6615 GLuint uniformBlockBinding)
6616{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006617 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006618 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006619
Jamie Madill956ab4d2018-10-10 16:13:03 -04006620 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006621 if (programObject->isInUse())
6622 {
6623 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006624 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006625 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006626}
6627
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006628GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6629{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006630 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6631 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006632
Jamie Madill70b5bb02017-08-28 13:32:37 -04006633 Sync *syncObject = getSync(syncHandle);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006634 if (syncObject->set(this, condition, flags) == angle::Result::Stop())
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006635 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006636 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006637 return nullptr;
6638 }
6639
Jamie Madill70b5bb02017-08-28 13:32:37 -04006640 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006641}
6642
6643GLboolean Context::isSync(GLsync sync)
6644{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006645 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006646}
6647
6648GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6649{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006650 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006651
6652 GLenum result = GL_WAIT_FAILED;
Jamie Madill4f6592f2018-11-27 16:37:45 -05006653 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop())
6654 {
6655 return GL_WAIT_FAILED;
6656 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006657 return result;
6658}
6659
6660void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6661{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006662 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006663 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006664}
6665
6666void Context::getInteger64v(GLenum pname, GLint64 *params)
6667{
6668 GLenum nativeType = GL_NONE;
6669 unsigned int numParams = 0;
6670 getQueryParameterInfo(pname, &nativeType, &numParams);
6671
6672 if (nativeType == GL_INT_64_ANGLEX)
6673 {
6674 getInteger64vImpl(pname, params);
6675 }
6676 else
6677 {
6678 CastStateValues(this, nativeType, pname, numParams, params);
6679 }
6680}
6681
Brandon Jones59770802018-04-02 13:18:42 -07006682void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6683{
6684 getInteger64v(pname, data);
6685}
6686
Corentin Wallez336129f2017-10-17 15:55:40 -04006687void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006688{
6689 Buffer *buffer = mGLState.getTargetBuffer(target);
6690 QueryBufferParameteri64v(buffer, pname, params);
6691}
6692
Brandon Jones59770802018-04-02 13:18:42 -07006693void Context::getBufferParameteri64vRobust(BufferBinding target,
6694 GLenum pname,
6695 GLsizei bufSize,
6696 GLsizei *length,
6697 GLint64 *params)
6698{
6699 getBufferParameteri64v(target, pname, params);
6700}
6701
Jamie Madill3ef140a2017-08-26 23:11:21 -04006702void Context::genSamplers(GLsizei count, GLuint *samplers)
6703{
6704 for (int i = 0; i < count; i++)
6705 {
6706 samplers[i] = mState.mSamplers->createSampler();
6707 }
6708}
6709
6710void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6711{
6712 for (int i = 0; i < count; i++)
6713 {
6714 GLuint sampler = samplers[i];
6715
6716 if (mState.mSamplers->getSampler(sampler))
6717 {
6718 detachSampler(sampler);
6719 }
6720
6721 mState.mSamplers->deleteObject(this, sampler);
6722 }
6723}
6724
6725void Context::getInternalformativ(GLenum target,
6726 GLenum internalformat,
6727 GLenum pname,
6728 GLsizei bufSize,
6729 GLint *params)
6730{
6731 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6732 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6733}
6734
Brandon Jones59770802018-04-02 13:18:42 -07006735void Context::getInternalformativRobust(GLenum target,
6736 GLenum internalformat,
6737 GLenum pname,
6738 GLsizei bufSize,
6739 GLsizei *length,
6740 GLint *params)
6741{
6742 getInternalformativ(target, internalformat, pname, bufSize, params);
6743}
6744
Jiajia Qin5451d532017-11-16 17:16:34 +08006745void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6746{
6747 programUniform1iv(program, location, 1, &v0);
6748}
6749
6750void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6751{
6752 GLint xy[2] = {v0, v1};
6753 programUniform2iv(program, location, 1, xy);
6754}
6755
6756void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6757{
6758 GLint xyz[3] = {v0, v1, v2};
6759 programUniform3iv(program, location, 1, xyz);
6760}
6761
6762void Context::programUniform4i(GLuint program,
6763 GLint location,
6764 GLint v0,
6765 GLint v1,
6766 GLint v2,
6767 GLint v3)
6768{
6769 GLint xyzw[4] = {v0, v1, v2, v3};
6770 programUniform4iv(program, location, 1, xyzw);
6771}
6772
6773void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6774{
6775 programUniform1uiv(program, location, 1, &v0);
6776}
6777
6778void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6779{
6780 GLuint xy[2] = {v0, v1};
6781 programUniform2uiv(program, location, 1, xy);
6782}
6783
6784void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6785{
6786 GLuint xyz[3] = {v0, v1, v2};
6787 programUniform3uiv(program, location, 1, xyz);
6788}
6789
6790void Context::programUniform4ui(GLuint program,
6791 GLint location,
6792 GLuint v0,
6793 GLuint v1,
6794 GLuint v2,
6795 GLuint v3)
6796{
6797 GLuint xyzw[4] = {v0, v1, v2, v3};
6798 programUniform4uiv(program, location, 1, xyzw);
6799}
6800
6801void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6802{
6803 programUniform1fv(program, location, 1, &v0);
6804}
6805
6806void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6807{
6808 GLfloat xy[2] = {v0, v1};
6809 programUniform2fv(program, location, 1, xy);
6810}
6811
6812void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6813{
6814 GLfloat xyz[3] = {v0, v1, v2};
6815 programUniform3fv(program, location, 1, xyz);
6816}
6817
6818void Context::programUniform4f(GLuint program,
6819 GLint location,
6820 GLfloat v0,
6821 GLfloat v1,
6822 GLfloat v2,
6823 GLfloat v3)
6824{
6825 GLfloat xyzw[4] = {v0, v1, v2, v3};
6826 programUniform4fv(program, location, 1, xyzw);
6827}
6828
Jamie Madill81c2e252017-09-09 23:32:46 -04006829void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6830{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006831 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006832 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006833 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006834}
6835
Jiajia Qin5451d532017-11-16 17:16:34 +08006836void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6837{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006838 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006839 ASSERT(programObject);
6840 programObject->setUniform2iv(location, count, value);
6841}
6842
6843void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6844{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006845 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006846 ASSERT(programObject);
6847 programObject->setUniform3iv(location, count, value);
6848}
6849
6850void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6851{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006852 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006853 ASSERT(programObject);
6854 programObject->setUniform4iv(location, count, value);
6855}
6856
6857void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6858{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006859 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006860 ASSERT(programObject);
6861 programObject->setUniform1uiv(location, count, value);
6862}
6863
6864void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6865{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006866 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006867 ASSERT(programObject);
6868 programObject->setUniform2uiv(location, count, value);
6869}
6870
6871void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6872{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006873 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006874 ASSERT(programObject);
6875 programObject->setUniform3uiv(location, count, value);
6876}
6877
6878void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6879{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006880 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006881 ASSERT(programObject);
6882 programObject->setUniform4uiv(location, count, value);
6883}
6884
6885void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6886{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006887 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006888 ASSERT(programObject);
6889 programObject->setUniform1fv(location, count, value);
6890}
6891
6892void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6893{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006894 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006895 ASSERT(programObject);
6896 programObject->setUniform2fv(location, count, value);
6897}
6898
6899void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6900{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006901 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006902 ASSERT(programObject);
6903 programObject->setUniform3fv(location, count, value);
6904}
6905
6906void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6907{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006908 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006909 ASSERT(programObject);
6910 programObject->setUniform4fv(location, count, value);
6911}
6912
6913void Context::programUniformMatrix2fv(GLuint program,
6914 GLint location,
6915 GLsizei count,
6916 GLboolean transpose,
6917 const GLfloat *value)
6918{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006919 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006920 ASSERT(programObject);
6921 programObject->setUniformMatrix2fv(location, count, transpose, value);
6922}
6923
6924void Context::programUniformMatrix3fv(GLuint program,
6925 GLint location,
6926 GLsizei count,
6927 GLboolean transpose,
6928 const GLfloat *value)
6929{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006930 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006931 ASSERT(programObject);
6932 programObject->setUniformMatrix3fv(location, count, transpose, value);
6933}
6934
6935void Context::programUniformMatrix4fv(GLuint program,
6936 GLint location,
6937 GLsizei count,
6938 GLboolean transpose,
6939 const GLfloat *value)
6940{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006941 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006942 ASSERT(programObject);
6943 programObject->setUniformMatrix4fv(location, count, transpose, value);
6944}
6945
6946void Context::programUniformMatrix2x3fv(GLuint program,
6947 GLint location,
6948 GLsizei count,
6949 GLboolean transpose,
6950 const GLfloat *value)
6951{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006952 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006953 ASSERT(programObject);
6954 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6955}
6956
6957void Context::programUniformMatrix3x2fv(GLuint program,
6958 GLint location,
6959 GLsizei count,
6960 GLboolean transpose,
6961 const GLfloat *value)
6962{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006963 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006964 ASSERT(programObject);
6965 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6966}
6967
6968void Context::programUniformMatrix2x4fv(GLuint program,
6969 GLint location,
6970 GLsizei count,
6971 GLboolean transpose,
6972 const GLfloat *value)
6973{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006974 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006975 ASSERT(programObject);
6976 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6977}
6978
6979void Context::programUniformMatrix4x2fv(GLuint program,
6980 GLint location,
6981 GLsizei count,
6982 GLboolean transpose,
6983 const GLfloat *value)
6984{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006985 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006986 ASSERT(programObject);
6987 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6988}
6989
6990void Context::programUniformMatrix3x4fv(GLuint program,
6991 GLint location,
6992 GLsizei count,
6993 GLboolean transpose,
6994 const GLfloat *value)
6995{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006996 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006997 ASSERT(programObject);
6998 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6999}
7000
7001void Context::programUniformMatrix4x3fv(GLuint program,
7002 GLint location,
7003 GLsizei count,
7004 GLboolean transpose,
7005 const GLfloat *value)
7006{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007007 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007008 ASSERT(programObject);
7009 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7010}
7011
Jamie Madill81c2e252017-09-09 23:32:46 -04007012void Context::onTextureChange(const Texture *texture)
7013{
7014 // Conservatively assume all textures are dirty.
7015 // TODO(jmadill): More fine-grained update.
7016 mGLState.setObjectDirty(GL_TEXTURE);
7017}
7018
James Darpiniane8a93c62018-01-04 18:02:24 -08007019bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7020{
7021 return mGLState.isCurrentTransformFeedback(tf);
7022}
James Darpiniane8a93c62018-01-04 18:02:24 -08007023
Yunchao Hea336b902017-08-02 16:05:21 +08007024void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7025{
7026 for (int i = 0; i < count; i++)
7027 {
7028 pipelines[i] = createProgramPipeline();
7029 }
7030}
7031
7032void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7033{
7034 for (int i = 0; i < count; i++)
7035 {
7036 if (pipelines[i] != 0)
7037 {
7038 deleteProgramPipeline(pipelines[i]);
7039 }
7040 }
7041}
7042
7043GLboolean Context::isProgramPipeline(GLuint pipeline)
7044{
7045 if (pipeline == 0)
7046 {
7047 return GL_FALSE;
7048 }
7049
7050 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7051}
7052
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007053void Context::finishFenceNV(GLuint fence)
7054{
7055 FenceNV *fenceObject = getFenceNV(fence);
7056
7057 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007058 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007059}
7060
7061void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7062{
7063 FenceNV *fenceObject = getFenceNV(fence);
7064
7065 ASSERT(fenceObject && fenceObject->isSet());
7066
7067 switch (pname)
7068 {
7069 case GL_FENCE_STATUS_NV:
7070 {
7071 // GL_NV_fence spec:
7072 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7073 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7074 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7075 GLboolean status = GL_TRUE;
7076 if (fenceObject->getStatus() != GL_TRUE)
7077 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007078 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007079 }
7080 *params = status;
7081 break;
7082 }
7083
7084 case GL_FENCE_CONDITION_NV:
7085 {
7086 *params = static_cast<GLint>(fenceObject->getCondition());
7087 break;
7088 }
7089
7090 default:
7091 UNREACHABLE();
7092 }
7093}
7094
7095void Context::getTranslatedShaderSource(GLuint shader,
7096 GLsizei bufsize,
7097 GLsizei *length,
7098 GLchar *source)
7099{
7100 Shader *shaderObject = getShader(shader);
7101 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007102 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007103}
7104
7105void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7106{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007107 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007108 ASSERT(programObject);
7109
7110 programObject->getUniformfv(this, location, params);
7111}
7112
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007113void Context::getnUniformfvRobust(GLuint program,
7114 GLint location,
7115 GLsizei bufSize,
7116 GLsizei *length,
7117 GLfloat *params)
7118{
7119 UNIMPLEMENTED();
7120}
7121
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007122void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7123{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007124 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007125 ASSERT(programObject);
7126
7127 programObject->getUniformiv(this, location, params);
7128}
7129
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007130void Context::getnUniformivRobust(GLuint program,
7131 GLint location,
7132 GLsizei bufSize,
7133 GLsizei *length,
7134 GLint *params)
7135{
7136 UNIMPLEMENTED();
7137}
7138
7139void Context::getnUniformuivRobust(GLuint program,
7140 GLint location,
7141 GLsizei bufSize,
7142 GLsizei *length,
7143 GLuint *params)
7144{
7145 UNIMPLEMENTED();
7146}
7147
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007148GLboolean Context::isFenceNV(GLuint fence)
7149{
7150 FenceNV *fenceObject = getFenceNV(fence);
7151
7152 if (fenceObject == nullptr)
7153 {
7154 return GL_FALSE;
7155 }
7156
7157 // GL_NV_fence spec:
7158 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7159 // existing fence.
7160 return fenceObject->isSet();
7161}
7162
7163void Context::readnPixels(GLint x,
7164 GLint y,
7165 GLsizei width,
7166 GLsizei height,
7167 GLenum format,
7168 GLenum type,
7169 GLsizei bufSize,
7170 void *data)
7171{
7172 return readPixels(x, y, width, height, format, type, data);
7173}
7174
Jamie Madill007530e2017-12-28 14:27:04 -05007175void Context::setFenceNV(GLuint fence, GLenum condition)
7176{
7177 ASSERT(condition == GL_ALL_COMPLETED_NV);
7178
7179 FenceNV *fenceObject = getFenceNV(fence);
7180 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007181 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007182}
7183
7184GLboolean Context::testFenceNV(GLuint fence)
7185{
7186 FenceNV *fenceObject = getFenceNV(fence);
7187
7188 ASSERT(fenceObject != nullptr);
7189 ASSERT(fenceObject->isSet() == GL_TRUE);
7190
7191 GLboolean result = GL_TRUE;
Jamie Madill4f6592f2018-11-27 16:37:45 -05007192 if (fenceObject->test(this, &result) == angle::Result::Stop())
Jamie Madill007530e2017-12-28 14:27:04 -05007193 {
Jamie Madill007530e2017-12-28 14:27:04 -05007194 return GL_TRUE;
7195 }
7196
7197 return result;
7198}
7199
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007200void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007201{
7202 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007203 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007204 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007205}
7206
Jamie Madillfa920eb2018-01-04 11:45:50 -05007207void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007208{
7209 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007210 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007211 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007212}
7213
Jamie Madillfa920eb2018-01-04 11:45:50 -05007214void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7215{
7216 UNIMPLEMENTED();
7217}
7218
Jamie Madill5b772312018-03-08 20:28:32 -05007219bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7220{
7221 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7222 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7223 // to the fact that it is stored internally as a float, and so would require conversion
7224 // if returned from Context::getIntegerv. Since this conversion is already implemented
7225 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7226 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7227 // application.
7228 switch (pname)
7229 {
7230 case GL_COMPRESSED_TEXTURE_FORMATS:
7231 {
7232 *type = GL_INT;
7233 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7234 return true;
7235 }
7236 case GL_SHADER_BINARY_FORMATS:
7237 {
7238 *type = GL_INT;
7239 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7240 return true;
7241 }
7242
7243 case GL_MAX_VERTEX_ATTRIBS:
7244 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7245 case GL_MAX_VARYING_VECTORS:
7246 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7247 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7248 case GL_MAX_TEXTURE_IMAGE_UNITS:
7249 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7250 case GL_MAX_RENDERBUFFER_SIZE:
7251 case GL_NUM_SHADER_BINARY_FORMATS:
7252 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7253 case GL_ARRAY_BUFFER_BINDING:
7254 case GL_FRAMEBUFFER_BINDING:
7255 case GL_RENDERBUFFER_BINDING:
7256 case GL_CURRENT_PROGRAM:
7257 case GL_PACK_ALIGNMENT:
7258 case GL_UNPACK_ALIGNMENT:
7259 case GL_GENERATE_MIPMAP_HINT:
7260 case GL_RED_BITS:
7261 case GL_GREEN_BITS:
7262 case GL_BLUE_BITS:
7263 case GL_ALPHA_BITS:
7264 case GL_DEPTH_BITS:
7265 case GL_STENCIL_BITS:
7266 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7267 case GL_CULL_FACE_MODE:
7268 case GL_FRONT_FACE:
7269 case GL_ACTIVE_TEXTURE:
7270 case GL_STENCIL_FUNC:
7271 case GL_STENCIL_VALUE_MASK:
7272 case GL_STENCIL_REF:
7273 case GL_STENCIL_FAIL:
7274 case GL_STENCIL_PASS_DEPTH_FAIL:
7275 case GL_STENCIL_PASS_DEPTH_PASS:
7276 case GL_STENCIL_BACK_FUNC:
7277 case GL_STENCIL_BACK_VALUE_MASK:
7278 case GL_STENCIL_BACK_REF:
7279 case GL_STENCIL_BACK_FAIL:
7280 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7281 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7282 case GL_DEPTH_FUNC:
7283 case GL_BLEND_SRC_RGB:
7284 case GL_BLEND_SRC_ALPHA:
7285 case GL_BLEND_DST_RGB:
7286 case GL_BLEND_DST_ALPHA:
7287 case GL_BLEND_EQUATION_RGB:
7288 case GL_BLEND_EQUATION_ALPHA:
7289 case GL_STENCIL_WRITEMASK:
7290 case GL_STENCIL_BACK_WRITEMASK:
7291 case GL_STENCIL_CLEAR_VALUE:
7292 case GL_SUBPIXEL_BITS:
7293 case GL_MAX_TEXTURE_SIZE:
7294 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7295 case GL_SAMPLE_BUFFERS:
7296 case GL_SAMPLES:
7297 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7298 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7299 case GL_TEXTURE_BINDING_2D:
7300 case GL_TEXTURE_BINDING_CUBE_MAP:
7301 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7302 {
7303 *type = GL_INT;
7304 *numParams = 1;
7305 return true;
7306 }
7307 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7308 {
7309 if (!getExtensions().packReverseRowOrder)
7310 {
7311 return false;
7312 }
7313 *type = GL_INT;
7314 *numParams = 1;
7315 return true;
7316 }
7317 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7318 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7319 {
7320 if (!getExtensions().textureRectangle)
7321 {
7322 return false;
7323 }
7324 *type = GL_INT;
7325 *numParams = 1;
7326 return true;
7327 }
7328 case GL_MAX_DRAW_BUFFERS_EXT:
7329 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7330 {
7331 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7332 {
7333 return false;
7334 }
7335 *type = GL_INT;
7336 *numParams = 1;
7337 return true;
7338 }
7339 case GL_MAX_VIEWPORT_DIMS:
7340 {
7341 *type = GL_INT;
7342 *numParams = 2;
7343 return true;
7344 }
7345 case GL_VIEWPORT:
7346 case GL_SCISSOR_BOX:
7347 {
7348 *type = GL_INT;
7349 *numParams = 4;
7350 return true;
7351 }
7352 case GL_SHADER_COMPILER:
7353 case GL_SAMPLE_COVERAGE_INVERT:
7354 case GL_DEPTH_WRITEMASK:
7355 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7356 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7357 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7358 // bool-natural
7359 case GL_SAMPLE_COVERAGE:
7360 case GL_SCISSOR_TEST:
7361 case GL_STENCIL_TEST:
7362 case GL_DEPTH_TEST:
7363 case GL_BLEND:
7364 case GL_DITHER:
7365 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7366 {
7367 *type = GL_BOOL;
7368 *numParams = 1;
7369 return true;
7370 }
7371 case GL_COLOR_WRITEMASK:
7372 {
7373 *type = GL_BOOL;
7374 *numParams = 4;
7375 return true;
7376 }
7377 case GL_POLYGON_OFFSET_FACTOR:
7378 case GL_POLYGON_OFFSET_UNITS:
7379 case GL_SAMPLE_COVERAGE_VALUE:
7380 case GL_DEPTH_CLEAR_VALUE:
7381 case GL_LINE_WIDTH:
7382 {
7383 *type = GL_FLOAT;
7384 *numParams = 1;
7385 return true;
7386 }
7387 case GL_ALIASED_LINE_WIDTH_RANGE:
7388 case GL_ALIASED_POINT_SIZE_RANGE:
7389 case GL_DEPTH_RANGE:
7390 {
7391 *type = GL_FLOAT;
7392 *numParams = 2;
7393 return true;
7394 }
7395 case GL_COLOR_CLEAR_VALUE:
7396 case GL_BLEND_COLOR:
7397 {
7398 *type = GL_FLOAT;
7399 *numParams = 4;
7400 return true;
7401 }
7402 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7403 if (!getExtensions().textureFilterAnisotropic)
7404 {
7405 return false;
7406 }
7407 *type = GL_FLOAT;
7408 *numParams = 1;
7409 return true;
7410 case GL_TIMESTAMP_EXT:
7411 if (!getExtensions().disjointTimerQuery)
7412 {
7413 return false;
7414 }
7415 *type = GL_INT_64_ANGLEX;
7416 *numParams = 1;
7417 return true;
7418 case GL_GPU_DISJOINT_EXT:
7419 if (!getExtensions().disjointTimerQuery)
7420 {
7421 return false;
7422 }
7423 *type = GL_INT;
7424 *numParams = 1;
7425 return true;
7426 case GL_COVERAGE_MODULATION_CHROMIUM:
7427 if (!getExtensions().framebufferMixedSamples)
7428 {
7429 return false;
7430 }
7431 *type = GL_INT;
7432 *numParams = 1;
7433 return true;
7434 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7435 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7436 {
7437 return false;
7438 }
7439 *type = GL_INT;
7440 *numParams = 1;
7441 return true;
7442 }
7443
7444 if (getExtensions().debug)
7445 {
7446 switch (pname)
7447 {
7448 case GL_DEBUG_LOGGED_MESSAGES:
7449 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7450 case GL_DEBUG_GROUP_STACK_DEPTH:
7451 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7452 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7453 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7454 case GL_MAX_LABEL_LENGTH:
7455 *type = GL_INT;
7456 *numParams = 1;
7457 return true;
7458
7459 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7460 case GL_DEBUG_OUTPUT:
7461 *type = GL_BOOL;
7462 *numParams = 1;
7463 return true;
7464 }
7465 }
7466
7467 if (getExtensions().multisampleCompatibility)
7468 {
7469 switch (pname)
7470 {
7471 case GL_MULTISAMPLE_EXT:
7472 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7473 *type = GL_BOOL;
7474 *numParams = 1;
7475 return true;
7476 }
7477 }
7478
7479 if (getExtensions().pathRendering)
7480 {
7481 switch (pname)
7482 {
7483 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7484 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7485 *type = GL_FLOAT;
7486 *numParams = 16;
7487 return true;
7488 }
7489 }
7490
7491 if (getExtensions().bindGeneratesResource)
7492 {
7493 switch (pname)
7494 {
7495 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7496 *type = GL_BOOL;
7497 *numParams = 1;
7498 return true;
7499 }
7500 }
7501
7502 if (getExtensions().clientArrays)
7503 {
7504 switch (pname)
7505 {
7506 case GL_CLIENT_ARRAYS_ANGLE:
7507 *type = GL_BOOL;
7508 *numParams = 1;
7509 return true;
7510 }
7511 }
7512
7513 if (getExtensions().sRGBWriteControl)
7514 {
7515 switch (pname)
7516 {
7517 case GL_FRAMEBUFFER_SRGB_EXT:
7518 *type = GL_BOOL;
7519 *numParams = 1;
7520 return true;
7521 }
7522 }
7523
7524 if (getExtensions().robustResourceInitialization &&
7525 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7526 {
7527 *type = GL_BOOL;
7528 *numParams = 1;
7529 return true;
7530 }
7531
7532 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7533 {
7534 *type = GL_BOOL;
7535 *numParams = 1;
7536 return true;
7537 }
7538
jchen1082af6202018-06-22 10:59:52 +08007539 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7540 {
7541 *type = GL_INT;
7542 *numParams = 1;
7543 return true;
7544 }
7545
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007546 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7547 {
7548 *type = GL_INT;
7549 *numParams = 1;
7550 return true;
7551 }
7552
Jamie Madill5b772312018-03-08 20:28:32 -05007553 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7554 switch (pname)
7555 {
7556 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7557 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7558 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7559 {
7560 return false;
7561 }
7562 *type = GL_INT;
7563 *numParams = 1;
7564 return true;
7565
7566 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7567 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7568 {
7569 return false;
7570 }
7571 *type = GL_INT;
7572 *numParams = 1;
7573 return true;
7574
7575 case GL_PROGRAM_BINARY_FORMATS_OES:
7576 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7577 {
7578 return false;
7579 }
7580 *type = GL_INT;
7581 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7582 return true;
7583
7584 case GL_PACK_ROW_LENGTH:
7585 case GL_PACK_SKIP_ROWS:
7586 case GL_PACK_SKIP_PIXELS:
7587 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7588 {
7589 return false;
7590 }
7591 *type = GL_INT;
7592 *numParams = 1;
7593 return true;
7594 case GL_UNPACK_ROW_LENGTH:
7595 case GL_UNPACK_SKIP_ROWS:
7596 case GL_UNPACK_SKIP_PIXELS:
7597 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7598 {
7599 return false;
7600 }
7601 *type = GL_INT;
7602 *numParams = 1;
7603 return true;
7604 case GL_VERTEX_ARRAY_BINDING:
7605 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7606 {
7607 return false;
7608 }
7609 *type = GL_INT;
7610 *numParams = 1;
7611 return true;
7612 case GL_PIXEL_PACK_BUFFER_BINDING:
7613 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7614 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7615 {
7616 return false;
7617 }
7618 *type = GL_INT;
7619 *numParams = 1;
7620 return true;
7621 case GL_MAX_SAMPLES:
7622 {
7623 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7624 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7625 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7626 {
7627 return false;
7628 }
7629 *type = GL_INT;
7630 *numParams = 1;
7631 return true;
7632
7633 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7634 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7635 {
7636 return false;
7637 }
7638 *type = GL_INT;
7639 *numParams = 1;
7640 return true;
7641 }
7642 }
7643
7644 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7645 {
7646 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7647 {
7648 return false;
7649 }
7650 *type = GL_INT;
7651 *numParams = 1;
7652 return true;
7653 }
7654
7655 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7656 {
7657 *type = GL_INT;
7658 *numParams = 1;
7659 return true;
7660 }
7661
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007662 if (getClientVersion() < Version(2, 0))
7663 {
7664 switch (pname)
7665 {
7666 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007667 case GL_CLIENT_ACTIVE_TEXTURE:
7668 case GL_MATRIX_MODE:
7669 case GL_MAX_TEXTURE_UNITS:
7670 case GL_MAX_MODELVIEW_STACK_DEPTH:
7671 case GL_MAX_PROJECTION_STACK_DEPTH:
7672 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007673 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007674 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007675 case GL_VERTEX_ARRAY_STRIDE:
7676 case GL_NORMAL_ARRAY_STRIDE:
7677 case GL_COLOR_ARRAY_STRIDE:
7678 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7679 case GL_VERTEX_ARRAY_SIZE:
7680 case GL_COLOR_ARRAY_SIZE:
7681 case GL_TEXTURE_COORD_ARRAY_SIZE:
7682 case GL_VERTEX_ARRAY_TYPE:
7683 case GL_NORMAL_ARRAY_TYPE:
7684 case GL_COLOR_ARRAY_TYPE:
7685 case GL_TEXTURE_COORD_ARRAY_TYPE:
7686 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7687 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7688 case GL_COLOR_ARRAY_BUFFER_BINDING:
7689 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7690 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7691 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7692 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007693 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007694 case GL_MODELVIEW_STACK_DEPTH:
7695 case GL_PROJECTION_STACK_DEPTH:
7696 case GL_TEXTURE_STACK_DEPTH:
7697 case GL_LOGIC_OP_MODE:
7698 case GL_BLEND_SRC:
7699 case GL_BLEND_DST:
7700 case GL_PERSPECTIVE_CORRECTION_HINT:
7701 case GL_POINT_SMOOTH_HINT:
7702 case GL_LINE_SMOOTH_HINT:
7703 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007704 *type = GL_INT;
7705 *numParams = 1;
7706 return true;
7707 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007708 case GL_FOG_DENSITY:
7709 case GL_FOG_START:
7710 case GL_FOG_END:
7711 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007712 case GL_POINT_SIZE:
7713 case GL_POINT_SIZE_MIN:
7714 case GL_POINT_SIZE_MAX:
7715 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007716 *type = GL_FLOAT;
7717 *numParams = 1;
7718 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007719 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007720 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007721 *type = GL_FLOAT;
7722 *numParams = 2;
7723 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007724 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007725 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007726 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007727 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007728 *type = GL_FLOAT;
7729 *numParams = 4;
7730 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007731 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007732 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007733 *type = GL_FLOAT;
7734 *numParams = 3;
7735 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007736 case GL_MODELVIEW_MATRIX:
7737 case GL_PROJECTION_MATRIX:
7738 case GL_TEXTURE_MATRIX:
7739 *type = GL_FLOAT;
7740 *numParams = 16;
7741 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007742 case GL_LIGHT_MODEL_TWO_SIDE:
7743 *type = GL_BOOL;
7744 *numParams = 1;
7745 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007746 }
7747 }
7748
Jamie Madill5b772312018-03-08 20:28:32 -05007749 if (getClientVersion() < Version(3, 0))
7750 {
7751 return false;
7752 }
7753
7754 // Check for ES3.0+ parameter names
7755 switch (pname)
7756 {
7757 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7758 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7759 case GL_UNIFORM_BUFFER_BINDING:
7760 case GL_TRANSFORM_FEEDBACK_BINDING:
7761 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7762 case GL_COPY_READ_BUFFER_BINDING:
7763 case GL_COPY_WRITE_BUFFER_BINDING:
7764 case GL_SAMPLER_BINDING:
7765 case GL_READ_BUFFER:
7766 case GL_TEXTURE_BINDING_3D:
7767 case GL_TEXTURE_BINDING_2D_ARRAY:
7768 case GL_MAX_3D_TEXTURE_SIZE:
7769 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7770 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7771 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7772 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7773 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7774 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7775 case GL_MAX_VARYING_COMPONENTS:
7776 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7777 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7778 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7779 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7780 case GL_NUM_EXTENSIONS:
7781 case GL_MAJOR_VERSION:
7782 case GL_MINOR_VERSION:
7783 case GL_MAX_ELEMENTS_INDICES:
7784 case GL_MAX_ELEMENTS_VERTICES:
7785 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7786 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7787 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7788 case GL_UNPACK_IMAGE_HEIGHT:
7789 case GL_UNPACK_SKIP_IMAGES:
7790 {
7791 *type = GL_INT;
7792 *numParams = 1;
7793 return true;
7794 }
7795
7796 case GL_MAX_ELEMENT_INDEX:
7797 case GL_MAX_UNIFORM_BLOCK_SIZE:
7798 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7799 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7800 case GL_MAX_SERVER_WAIT_TIMEOUT:
7801 {
7802 *type = GL_INT_64_ANGLEX;
7803 *numParams = 1;
7804 return true;
7805 }
7806
7807 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7808 case GL_TRANSFORM_FEEDBACK_PAUSED:
7809 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7810 case GL_RASTERIZER_DISCARD:
7811 {
7812 *type = GL_BOOL;
7813 *numParams = 1;
7814 return true;
7815 }
7816
7817 case GL_MAX_TEXTURE_LOD_BIAS:
7818 {
7819 *type = GL_FLOAT;
7820 *numParams = 1;
7821 return true;
7822 }
7823 }
7824
7825 if (getExtensions().requestExtension)
7826 {
7827 switch (pname)
7828 {
7829 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7830 *type = GL_INT;
7831 *numParams = 1;
7832 return true;
7833 }
7834 }
7835
Yizhou Jiang7818a852018-09-06 15:02:04 +08007836 if (getExtensions().textureMultisample)
7837 {
7838 switch (pname)
7839 {
7840 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7841 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7842 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7843 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007844 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007845 *type = GL_INT;
7846 *numParams = 1;
7847 return true;
7848 }
7849 }
7850
Jamie Madill5b772312018-03-08 20:28:32 -05007851 if (getClientVersion() < Version(3, 1))
7852 {
7853 return false;
7854 }
7855
7856 switch (pname)
7857 {
7858 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7859 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7860 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7861 case GL_MAX_FRAMEBUFFER_WIDTH:
7862 case GL_MAX_FRAMEBUFFER_HEIGHT:
7863 case GL_MAX_FRAMEBUFFER_SAMPLES:
7864 case GL_MAX_SAMPLE_MASK_WORDS:
7865 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7866 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7867 case GL_MAX_INTEGER_SAMPLES:
7868 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7869 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7870 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7871 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7872 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7873 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7874 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7875 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7876 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7877 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7878 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7879 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7880 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7881 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7882 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7883 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7884 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7885 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7886 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7887 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7888 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7889 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7890 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7891 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7892 case GL_MAX_UNIFORM_LOCATIONS:
7893 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7894 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7895 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7896 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7897 case GL_MAX_IMAGE_UNITS:
7898 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7899 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7900 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7901 case GL_SHADER_STORAGE_BUFFER_BINDING:
7902 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7903 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007904 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007905 *type = GL_INT;
7906 *numParams = 1;
7907 return true;
7908 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7909 *type = GL_INT_64_ANGLEX;
7910 *numParams = 1;
7911 return true;
7912 case GL_SAMPLE_MASK:
7913 *type = GL_BOOL;
7914 *numParams = 1;
7915 return true;
7916 }
7917
7918 if (getExtensions().geometryShader)
7919 {
7920 switch (pname)
7921 {
7922 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7923 case GL_LAYER_PROVOKING_VERTEX_EXT:
7924 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7925 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7926 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7927 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7928 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7929 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7930 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7931 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7932 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7933 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7934 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7935 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7936 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7937 *type = GL_INT;
7938 *numParams = 1;
7939 return true;
7940 }
7941 }
7942
7943 return false;
7944}
7945
7946bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7947{
7948 if (getClientVersion() < Version(3, 0))
7949 {
7950 return false;
7951 }
7952
7953 switch (target)
7954 {
7955 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7956 case GL_UNIFORM_BUFFER_BINDING:
7957 {
7958 *type = GL_INT;
7959 *numParams = 1;
7960 return true;
7961 }
7962 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7963 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7964 case GL_UNIFORM_BUFFER_START:
7965 case GL_UNIFORM_BUFFER_SIZE:
7966 {
7967 *type = GL_INT_64_ANGLEX;
7968 *numParams = 1;
7969 return true;
7970 }
7971 }
7972
7973 if (getClientVersion() < Version(3, 1))
7974 {
7975 return false;
7976 }
7977
7978 switch (target)
7979 {
7980 case GL_IMAGE_BINDING_LAYERED:
7981 {
7982 *type = GL_BOOL;
7983 *numParams = 1;
7984 return true;
7985 }
7986 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7987 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7988 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7989 case GL_SHADER_STORAGE_BUFFER_BINDING:
7990 case GL_VERTEX_BINDING_BUFFER:
7991 case GL_VERTEX_BINDING_DIVISOR:
7992 case GL_VERTEX_BINDING_OFFSET:
7993 case GL_VERTEX_BINDING_STRIDE:
7994 case GL_SAMPLE_MASK_VALUE:
7995 case GL_IMAGE_BINDING_NAME:
7996 case GL_IMAGE_BINDING_LEVEL:
7997 case GL_IMAGE_BINDING_LAYER:
7998 case GL_IMAGE_BINDING_ACCESS:
7999 case GL_IMAGE_BINDING_FORMAT:
8000 {
8001 *type = GL_INT;
8002 *numParams = 1;
8003 return true;
8004 }
8005 case GL_ATOMIC_COUNTER_BUFFER_START:
8006 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8007 case GL_SHADER_STORAGE_BUFFER_START:
8008 case GL_SHADER_STORAGE_BUFFER_SIZE:
8009 {
8010 *type = GL_INT_64_ANGLEX;
8011 *numParams = 1;
8012 return true;
8013 }
8014 }
8015
8016 return false;
8017}
8018
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008019Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008020{
8021 return mState.mShaderPrograms->getProgram(handle);
8022}
8023
8024Shader *Context::getShader(GLuint handle) const
8025{
8026 return mState.mShaderPrograms->getShader(handle);
8027}
8028
Jamie Madill5b772312018-03-08 20:28:32 -05008029bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8030{
8031 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8032}
8033
8034bool Context::isFramebufferGenerated(GLuint framebuffer) const
8035{
8036 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8037}
8038
8039bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8040{
8041 return mState.mPipelines->isHandleGenerated(pipeline);
8042}
8043
8044bool Context::usingDisplayTextureShareGroup() const
8045{
8046 return mDisplayTextureShareGroup;
8047}
8048
8049GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8050{
8051 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8052 internalformat == GL_DEPTH_STENCIL
8053 ? GL_DEPTH24_STENCIL8
8054 : internalformat;
8055}
8056
jchen1082af6202018-06-22 10:59:52 +08008057void Context::maxShaderCompilerThreads(GLuint count)
8058{
jchen107ae70d82018-07-06 13:47:01 +08008059 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008060 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008061 // A count of zero specifies a request for no parallel compiling or linking.
8062 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8063 {
8064 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8065 }
8066 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008067}
8068
Jamie Madill2eb65032018-07-30 10:25:57 -04008069bool Context::isGLES1() const
8070{
8071 return mState.getClientVersion() < Version(2, 0);
8072}
8073
Jamie Madilla11819d2018-07-30 10:26:01 -04008074void Context::onSubjectStateChange(const Context *context,
8075 angle::SubjectIndex index,
8076 angle::SubjectMessage message)
8077{
Jamie Madilla11819d2018-07-30 10:26:01 -04008078 switch (index)
8079 {
8080 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008081 switch (message)
8082 {
8083 case angle::SubjectMessage::CONTENTS_CHANGED:
8084 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8085 mStateCache.onVertexArrayBufferContentsChange(this);
8086 break;
8087 case angle::SubjectMessage::RESOURCE_MAPPED:
8088 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8089 case angle::SubjectMessage::BINDING_CHANGED:
8090 mStateCache.onVertexArrayBufferStateChange(this);
8091 break;
8092 default:
8093 break;
8094 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008095 break;
8096
8097 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008098 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8099 {
8100 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8101 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008102 break;
8103
8104 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008105 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8106 {
8107 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
8108 }
8109 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008110 break;
8111
8112 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008113 if (index < kTextureMaxSubjectIndex)
8114 {
8115 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008116 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008117 }
Jamie Madille25b8002018-09-20 13:39:49 -04008118 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008119 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008120 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008121 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008122 }
Jamie Madille25b8002018-09-20 13:39:49 -04008123 else
8124 {
8125 ASSERT(index < kSamplerMaxSubjectIndex);
8126 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8127 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008128 break;
8129 }
8130}
8131
Jamie Madill6b873dd2018-07-12 23:56:30 -04008132// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008133ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008134
8135ErrorSet::~ErrorSet() = default;
8136
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008137void ErrorSet::handleError(GLenum errorCode,
8138 const char *message,
8139 const char *file,
8140 const char *function,
8141 unsigned int line)
8142{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008143 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8144 {
8145 mContext->markContextLost();
8146 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008147
Jamie Madill4f6592f2018-11-27 16:37:45 -05008148 std::stringstream errorStream;
8149 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8150 << line << ". " << message;
8151
8152 // validationError does the necessary work to process the error.
8153 validationError(errorCode, errorStream.str().c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008154}
8155
Jamie Madilla139f012018-10-10 16:13:03 -04008156void ErrorSet::validationError(GLenum errorCode, const char *message)
8157{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008158 ASSERT(errorCode != GL_NO_ERROR);
8159 mErrors.insert(errorCode);
8160
8161 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8162 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008163}
8164
Jamie Madill6b873dd2018-07-12 23:56:30 -04008165bool ErrorSet::empty() const
8166{
8167 return mErrors.empty();
8168}
8169
8170GLenum ErrorSet::popError()
8171{
8172 ASSERT(!empty());
8173 GLenum error = *mErrors.begin();
8174 mErrors.erase(mErrors.begin());
8175 return error;
8176}
Jamie Madilldc358af2018-07-31 11:22:13 -04008177
8178// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008179StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008180 : mCachedHasAnyEnabledClientAttrib(false),
8181 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008182 mCachedInstancedVertexElementLimit(0),
8183 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008184{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008185
8186StateCache::~StateCache() = default;
8187
Jamie Madillac66f982018-10-09 18:30:01 -04008188void StateCache::initialize(Context *context)
8189{
8190 updateValidDrawModes(context);
8191 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008192 updateValidDrawElementsTypes(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008193}
8194
Jamie Madilldc358af2018-07-31 11:22:13 -04008195void StateCache::updateActiveAttribsMask(Context *context)
8196{
8197 bool isGLES1 = context->isGLES1();
8198 const State &glState = context->getGLState();
8199
8200 if (!isGLES1 && !glState.getProgram())
8201 {
8202 mCachedActiveBufferedAttribsMask = AttributesMask();
8203 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008204 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008205 return;
8206 }
8207
8208 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8209 : glState.getProgram()->getActiveAttribLocationsMask();
8210
8211 const VertexArray *vao = glState.getVertexArray();
8212 ASSERT(vao);
8213
8214 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8215 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008216 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008217
Jamie Madill0a17e482018-08-31 17:19:11 -04008218 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8219 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008220 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008221 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8222}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008223
8224void StateCache::updateVertexElementLimits(Context *context)
8225{
8226 const VertexArray *vao = context->getGLState().getVertexArray();
8227
8228 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8229 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8230
8231 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8232 // If there are no buffered attributes then we should not limit the draw call count.
8233 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8234 {
8235 return;
8236 }
8237
8238 const auto &vertexAttribs = vao->getVertexAttributes();
8239 const auto &vertexBindings = vao->getVertexBindings();
8240
8241 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8242 {
8243 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8244 ASSERT(attrib.enabled);
8245
8246 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8247 ASSERT(context->isGLES1() ||
8248 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8249
8250 GLint64 limit = attrib.getCachedElementLimit();
8251 if (binding.getDivisor() > 0)
8252 {
8253 mCachedInstancedVertexElementLimit =
8254 std::min(mCachedInstancedVertexElementLimit, limit);
8255 }
8256 else
8257 {
8258 mCachedNonInstancedVertexElementLimit =
8259 std::min(mCachedNonInstancedVertexElementLimit, limit);
8260 }
8261 }
8262}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008263
Jamie Madilld84b6732018-09-06 15:54:35 -04008264void StateCache::updateBasicDrawStatesError()
8265{
8266 mCachedBasicDrawStatesError = kInvalidPointer;
8267}
8268
8269intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8270{
8271 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8272 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8273 return mCachedBasicDrawStatesError;
8274}
8275
Jamie Madillc43cdad2018-08-08 15:49:25 -04008276void StateCache::onVertexArrayBindingChange(Context *context)
8277{
8278 updateActiveAttribsMask(context);
8279 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008280 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008281}
8282
8283void StateCache::onProgramExecutableChange(Context *context)
8284{
8285 updateActiveAttribsMask(context);
8286 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008287 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008288 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008289}
8290
Jamie Madilld84b6732018-09-06 15:54:35 -04008291void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008292{
8293 updateVertexElementLimits(context);
8294}
8295
Jamie Madilld84b6732018-09-06 15:54:35 -04008296void StateCache::onVertexArrayBufferContentsChange(Context *context)
8297{
8298 updateVertexElementLimits(context);
8299 updateBasicDrawStatesError();
8300}
8301
Jamie Madillc43cdad2018-08-08 15:49:25 -04008302void StateCache::onVertexArrayStateChange(Context *context)
8303{
8304 updateActiveAttribsMask(context);
8305 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008306 updateBasicDrawStatesError();
8307}
8308
8309void StateCache::onVertexArrayBufferStateChange(Context *context)
8310{
8311 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008312}
8313
8314void StateCache::onGLES1ClientStateChange(Context *context)
8315{
8316 updateActiveAttribsMask(context);
8317}
Jamie Madilld84b6732018-09-06 15:54:35 -04008318
8319void StateCache::onDrawFramebufferChange(Context *context)
8320{
8321 updateBasicDrawStatesError();
8322}
8323
8324void StateCache::onContextCapChange(Context *context)
8325{
8326 updateBasicDrawStatesError();
8327}
8328
8329void StateCache::onStencilStateChange(Context *context)
8330{
8331 updateBasicDrawStatesError();
8332}
8333
8334void StateCache::onDefaultVertexAttributeChange(Context *context)
8335{
8336 updateBasicDrawStatesError();
8337}
8338
8339void StateCache::onActiveTextureChange(Context *context)
8340{
8341 updateBasicDrawStatesError();
8342}
8343
8344void StateCache::onQueryChange(Context *context)
8345{
8346 updateBasicDrawStatesError();
8347}
8348
8349void StateCache::onTransformFeedbackChange(Context *context)
8350{
8351 updateBasicDrawStatesError();
8352}
8353
8354void StateCache::onUniformBufferStateChange(Context *context)
8355{
8356 updateBasicDrawStatesError();
8357}
8358
8359void StateCache::onBufferBindingChange(Context *context)
8360{
8361 updateBasicDrawStatesError();
8362}
Jamie Madill526a6f62018-09-12 11:03:05 -04008363
8364void StateCache::updateValidDrawModes(Context *context)
8365{
8366 Program *program = context->getGLState().getProgram();
8367 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8368 {
Jamie Madill752d2202018-11-27 13:29:48 -05008369 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008370 }
8371 else
8372 {
8373 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8374
8375 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8376
8377 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008378 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8379 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8380 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8381 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8382 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8383 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8384 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8385 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8386 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8387 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8388 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008389 }};
8390 }
8391}
Jamie Madillac66f982018-10-09 18:30:01 -04008392
8393void StateCache::updateValidBindTextureTypes(Context *context)
8394{
8395 const Extensions &exts = context->getExtensions();
8396 bool isGLES3 = context->getClientMajorVersion() >= 3;
8397 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8398
8399 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008400 {TextureType::_2D, true},
8401 {TextureType::_2DArray, isGLES3},
8402 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8403 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8404 {TextureType::_3D, isGLES3},
8405 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8406 {TextureType::Rectangle, exts.textureRectangle},
8407 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008408 }};
8409}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008410
8411void StateCache::updateValidDrawElementsTypes(Context *context)
8412{
8413 bool supportsUint =
8414 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8415
8416 mCachedValidDrawElementsTypes = {{
8417 {DrawElementsType::UnsignedByte, true},
8418 {DrawElementsType::UnsignedShort, true},
8419 {DrawElementsType::UnsignedInt, supportsUint},
8420 }};
8421}
Jamie Madillc29968b2016-01-20 11:17:23 -05008422} // namespace gl