blob: b9b1b4e4edb53710ae854ea2912addd73c6a40f3 [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"
Markus Tavenrathcb9609f2018-12-26 00:52:44 +090011#include "libANGLE/Context.inl.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000012
Jamie Madill231c7f52017-04-26 13:45:37 -040013#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050014#include <iterator>
15#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030016#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050017
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060018#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030019#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040020#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050021#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050022#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050023#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050024#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040025#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050026#include "libANGLE/Fence.h"
27#include "libANGLE/Framebuffer.h"
28#include "libANGLE/FramebufferAttachment.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/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Jamie Madill752d2202018-11-27 13:29:48 -050049namespace gl
50{
Geoff Langf6db0982015-08-25 13:04:00 -040051namespace
52{
53
Jamie Madillb6664922017-07-25 12:55:04 -040054#define ANGLE_HANDLE_ERR(X) \
Jamie Madill4f6592f2018-11-27 16:37:45 -050055 (void)(X); \
Jamie Madillb6664922017-07-25 12:55:04 -040056 return;
57#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
58
Ian Ewell3ffd78b2016-01-22 16:09:42 -050059template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -050060std::vector<Path *> GatherPaths(PathManager &resourceManager,
61 GLsizei numPaths,
62 const void *paths,
63 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030064{
Jamie Madill752d2202018-11-27 13:29:48 -050065 std::vector<Path *> ret;
Sami Väisänend59ca052016-06-21 16:10:00 +030066 ret.reserve(numPaths);
67
68 const auto *nameArray = static_cast<const T *>(paths);
69
70 for (GLsizei i = 0; i < numPaths; ++i)
71 {
72 const GLuint pathName = nameArray[i] + pathBase;
73
74 ret.push_back(resourceManager.getPath(pathName));
75 }
76
77 return ret;
78}
79
Jamie Madill752d2202018-11-27 13:29:48 -050080std::vector<Path *> GatherPaths(PathManager &resourceManager,
81 GLsizei numPaths,
82 GLenum pathNameType,
83 const void *paths,
84 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030085{
86 switch (pathNameType)
87 {
88 case GL_UNSIGNED_BYTE:
89 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_BYTE:
92 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_UNSIGNED_SHORT:
95 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_SHORT:
98 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_UNSIGNED_INT:
101 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
102
103 case GL_INT:
104 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
105 }
106
107 UNREACHABLE();
Jamie Madill752d2202018-11-27 13:29:48 -0500108 return std::vector<Path *>();
Sami Väisänend59ca052016-06-21 16:10:00 +0300109}
110
111template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -0500112angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113{
Geoff Lang2186c382016-10-14 10:54:54 -0400114 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115
116 switch (pname)
117 {
118 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400119 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 case GL_QUERY_RESULT_AVAILABLE_EXT:
121 {
122 bool available;
Jamie Madill666818e2018-11-14 09:54:33 -0500123 ANGLE_TRY(query->isResultAvailable(context, &available));
Jamie Madill752d2202018-11-27 13:29:48 -0500124 *params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Jamie Madill7c985f52018-11-29 18:16:17 -0500125 return angle::Result::Continue;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 }
127 default:
128 UNREACHABLE();
Jamie Madill7c985f52018-11-29 18:16:17 -0500129 return angle::Result::Stop;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill752d2202018-11-27 13:29:48 -0500133ANGLE_INLINE void MarkTransformFeedbackBufferUsage(const Context *context,
Jamie Madill956ab4d2018-10-10 16:13:03 -0400134 GLsizei count,
135 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400136{
Jamie Madillae6ba9f2018-12-21 23:00:04 -0500137 if (context->getStateCache().isTransformFeedbackActiveUnpaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400138 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -0500139 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Jamie Madill752d2202018-11-27 13:29:48 -0500155Version GetClientVersion(const egl::AttributeMap &attribs)
Geoff Langeb66a6e2016-10-31 13:06:12 -0400156{
Jamie Madill752d2202018-11-27 13:29:48 -0500157 return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
Geoff Langeb66a6e2016-10-31 13:06:12 -0400158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
Jamie Madill4230d482018-09-14 10:14:45 -0400196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
Jamie Madill4230d482018-09-14 10:14:45 -0400208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Jamie Madill752d2202018-11-27 13:29:48 -0500257constexpr angle::PackedEnumMap<PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
258 {PrimitiveMode::Points, 1},
259 {PrimitiveMode::Lines, 2},
260 {PrimitiveMode::LineLoop, 2},
261 {PrimitiveMode::LineStrip, 2},
262 {PrimitiveMode::Triangles, 3},
263 {PrimitiveMode::TriangleStrip, 3},
264 {PrimitiveMode::TriangleFan, 3},
265 {PrimitiveMode::LinesAdjacency, 2},
266 {PrimitiveMode::LineStripAdjacency, 2},
267 {PrimitiveMode::TrianglesAdjacency, 3},
268 {PrimitiveMode::TriangleStripAdjacency, 3},
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600269}};
Jamie Madill752d2202018-11-27 13:29:48 -0500270
271// The rest default to false.
272constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
273 kValidBasicDrawModes = {{
274 {PrimitiveMode::Points, true},
275 {PrimitiveMode::Lines, true},
276 {PrimitiveMode::LineLoop, true},
277 {PrimitiveMode::LineStrip, true},
278 {PrimitiveMode::Triangles, true},
279 {PrimitiveMode::TriangleStrip, true},
280 {PrimitiveMode::TriangleFan, true},
281 }};
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600282
Jamie Madill6d32cef2018-08-14 02:34:28 -0400283enum SubjectIndexes : angle::SubjectIndex
284{
285 kTexture0SubjectIndex = 0,
Jamie Madille3e680c2018-12-03 17:49:08 -0500286 kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
287 kImage0SubjectIndex = kTextureMaxSubjectIndex,
288 kImageMaxSubjectIndex = kImage0SubjectIndex + IMPLEMENTATION_MAX_IMAGE_UNITS,
289 kUniformBuffer0SubjectIndex = kImageMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400290 kUniformBufferMaxSubjectIndex =
Jamie Madille3e680c2018-12-03 17:49:08 -0500291 kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400292 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
Jamie Madille3e680c2018-12-03 17:49:08 -0500293 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Jamie Madille25b8002018-09-20 13:39:49 -0400294 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400295 kReadFramebufferSubjectIndex,
296 kDrawFramebufferSubjectIndex
297};
Geoff Langf6db0982015-08-25 13:04:00 -0400298} // anonymous namespace
299
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400300Context::Context(rx::EGLImplFactory *implFactory,
301 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400302 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500303 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400304 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500305 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700306 const egl::DisplayExtensions &displayExtensions,
307 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500308 : mState(reinterpret_cast<ContextID>(this),
309 shareContext ? &shareContext->mState : nullptr,
310 shareTextures,
311 GetClientVersion(attribs),
312 &mGLState,
313 mCaps,
314 mTextureCaps,
315 mExtensions,
316 mLimitations),
317 mSkipValidation(GetNoError(attribs)),
318 mDisplayTextureShareGroup(shareTextures != nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400319 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400320 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400321 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400322 mGLState(GetDebug(attribs),
323 GetBindGeneratesResource(attribs),
324 GetClientArraysEnabled(attribs),
325 GetRobustResourceInit(attribs),
326 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400327 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500328 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400329 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500330 mHasBeenCurrent(false),
331 mContextLost(false),
332 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700333 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500334 mResetStrategy(GetResetStrategy(attribs)),
335 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400336 mSurfacelessSupported(displayExtensions.surfacelessContext),
337 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400338 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
339 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500340 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400341 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400342 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400343 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
344 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
345 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400346 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800347 mZeroFilledBuffer(1000u),
348 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000349{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400350 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
351 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
352 {
353 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
354 }
Jamie Madille25b8002018-09-20 13:39:49 -0400355
356 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
357 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
358 {
359 mSamplerObserverBindings.emplace_back(this, samplerIndex);
360 }
Jamie Madille3e680c2018-12-03 17:49:08 -0500361
362 for (angle::SubjectIndex imageIndex = kImage0SubjectIndex; imageIndex < kImageMaxSubjectIndex;
363 ++imageIndex)
364 {
365 mImageObserverBindings.emplace_back(this, imageIndex);
366 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400367}
Jamie Madill5b772312018-03-08 20:28:32 -0500368
Geoff Lang33f11fb2018-05-07 13:42:47 -0400369void Context::initialize()
370{
371 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400372
Geoff Lang33f11fb2018-05-07 13:42:47 -0400373 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700374 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400375
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400376 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100377
Shannon Woods53a94a82014-06-24 15:20:36 -0400378 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400379
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000380 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400381 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000382 // and cube map texture state vectors respectively associated with them.
383 // In order that access to these initial textures not be lost, they are treated as texture
384 // objects all of whose names are 0.
385
Corentin Wallez99d492c2018-02-27 15:17:10 -0500386 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800387 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500388
Corentin Wallez99d492c2018-02-27 15:17:10 -0500389 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800390 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400391
Geoff Langeb66a6e2016-10-31 13:06:12 -0400392 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400393 {
394 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500395 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800396 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400397
Corentin Wallez99d492c2018-02-27 15:17:10 -0500398 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400400 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800401 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400402 {
403 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500404 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800405 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800406 }
407 if (getClientVersion() >= Version(3, 1))
408 {
Olli Etuahod310a432018-08-24 15:40:23 +0300409 Texture *zeroTexture2DMultisampleArray =
410 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
411 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800412
Jiajia Qin6eafb042016-12-27 17:04:07 +0800413 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
414 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800415 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800416 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800417
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800418 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
419 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400420 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800421 }
Geoff Lang3b573612016-10-31 14:08:10 -0400422 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423
Geoff Langb0f917f2017-12-05 13:41:54 -0500424 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400425 {
426 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500427 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800428 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400429 }
430
Geoff Langb0f917f2017-12-05 13:41:54 -0500431 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400432 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500433 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800434 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400435 }
436
Jamie Madill4928b7c2017-06-20 12:57:39 -0400437 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500438
Jamie Madill57a89722013-07-02 11:57:03 -0400439 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000440
Geoff Langeb66a6e2016-10-31 13:06:12 -0400441 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400442 {
443 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
444 // In the initial state, a default transform feedback object is bound and treated as
445 // a transform feedback object with a name of zero. That object is bound any time
446 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400447 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400448 }
Geoff Langc8058452014-02-03 12:04:11 -0500449
Corentin Wallez336129f2017-10-17 15:55:40 -0400450 for (auto type : angle::AllEnums<BufferBinding>())
451 {
452 bindBuffer(type, 0);
453 }
454
455 bindRenderbuffer(GL_RENDERBUFFER, 0);
456
457 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
458 {
459 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
460 }
461
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700462 // Initialize GLES1 renderer if appropriate.
463 if (getClientVersion() < Version(2, 0))
464 {
465 mGLES1Renderer.reset(new GLES1Renderer());
466 }
467
Jamie Madillad9f24e2016-02-12 09:27:24 -0500468 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400469 mAllDirtyBits.set();
470
Geoff Lang9bf86f02018-07-26 11:46:34 -0400471 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
472 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500473 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400474 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400475 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400476
477 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
478 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500479 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400480 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400481
Jamie Madillc67323a2017-11-02 23:11:41 -0400482 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500483 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500484 // No dirty objects.
485
486 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400487 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500488 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400489 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500490 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
491
492 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
493 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
494 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
495 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
496 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
497 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
498 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
499 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
500 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
501 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
502 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400503 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500504 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
505
506 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
507 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700508 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400509 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
510 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500511 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
512 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400513
Xinghua Cao10a4d432017-11-28 14:46:26 +0800514 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800515 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
516 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800517 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
518 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
519 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
520 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800521 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800522 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500523 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400524 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400525 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800526
Jamie Madillb4927eb2018-07-16 11:39:46 -0400527 mImplementation->setErrorSet(&mErrors);
528
Jamie Madill4f6592f2018-11-27 16:37:45 -0500529 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530}
531
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000533{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700534 if (mGLES1Renderer)
535 {
536 mGLES1Renderer->onDestroy(this, &mGLState);
537 }
538
Jamie Madille7b3fe22018-04-05 09:42:46 -0400539 ANGLE_TRY(releaseSurface(display));
540
Corentin Wallez80b24112015-08-25 16:41:57 -0400541 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400543 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000544 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400545 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546
Corentin Wallez80b24112015-08-25 16:41:57 -0400547 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400549 if (query.second != nullptr)
550 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400551 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400552 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000553 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400554 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000555
Corentin Wallez80b24112015-08-25 16:41:57 -0400556 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400557 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400558 if (vertexArray.second)
559 {
560 vertexArray.second->onDestroy(this);
561 }
Jamie Madill57a89722013-07-02 11:57:03 -0400562 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400563 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400564
Corentin Wallez80b24112015-08-25 16:41:57 -0400565 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500566 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500567 if (transformFeedback.second != nullptr)
568 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500569 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500570 }
Geoff Langc8058452014-02-03 12:04:11 -0500571 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400572 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500573
Jamie Madill5b772312018-03-08 20:28:32 -0500574 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400575 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800576 if (zeroTexture.get() != nullptr)
577 {
Jamie Madill1c7f08c2018-10-10 16:13:02 -0400578 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800579 zeroTexture.set(this, nullptr);
580 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400581 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000582
Jamie Madill2f348d22017-06-05 10:50:59 -0400583 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500584
Jamie Madill4928b7c2017-06-20 12:57:39 -0400585 mGLState.reset(this);
586
Jamie Madill6c1f6712017-02-14 19:08:04 -0500587 mState.mBuffers->release(this);
588 mState.mShaderPrograms->release(this);
589 mState.mTextures->release(this);
590 mState.mRenderbuffers->release(this);
591 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400592 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500593 mState.mPaths->release(this);
594 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800595 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400596
jchen107ae70d82018-07-06 13:47:01 +0800597 mThreadPool.reset();
598
Jamie Madill76e471e2017-10-21 09:56:01 -0400599 mImplementation->onDestroy(this);
600
Jamie Madill4928b7c2017-06-20 12:57:39 -0400601 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602}
603
Jamie Madillb980c562018-11-27 11:34:27 -0500604Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500605
Geoff Lang75359662018-04-11 01:42:27 -0400606void Context::setLabel(EGLLabelKHR label)
607{
608 mLabel = label;
609}
610
611EGLLabelKHR Context::getLabel() const
612{
613 return mLabel;
614}
615
Jamie Madill4928b7c2017-06-20 12:57:39 -0400616egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000617{
Jamie Madill61e16b42017-06-19 11:13:23 -0400618 mCurrentDisplay = display;
619
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620 if (!mHasBeenCurrent)
621 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400622 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500624 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400625 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626
Corentin Wallezc295e512017-01-27 17:47:50 -0500627 int width = 0;
628 int height = 0;
629 if (surface != nullptr)
630 {
631 width = surface->getWidth();
632 height = surface->getHeight();
633 }
634
635 mGLState.setViewportParams(0, 0, width, height);
636 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637
638 mHasBeenCurrent = true;
639 }
640
Jamie Madill1b94d432015-08-07 13:23:23 -0400641 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700642 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400643 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400644
Jamie Madill4928b7c2017-06-20 12:57:39 -0400645 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500646
647 Framebuffer *newDefault = nullptr;
648 if (surface != nullptr)
649 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400650 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500651 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400652 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500653 }
654 else
655 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400656 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500657 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000658
Corentin Wallez37c39792015-08-20 14:19:46 -0400659 // Update default framebuffer, the binding of the previous default
660 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400661 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400662 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700663 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400664 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400665 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400666 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700667 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400668 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400669 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400670 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400671 }
Ian Ewell292f0052016-02-04 10:37:32 -0500672
Jamie Madill32643ce2018-10-19 11:38:03 -0400673 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500674 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
Jamie Madill4928b7c2017-06-20 12:57:39 -0400677egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400678{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400679 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400680
Geoff Langbf7b95d2018-05-01 16:48:21 -0400681 // Remove the default framebuffer
682 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500683 {
684 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400685 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500686 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400687
688 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500689 {
690 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400691 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500692 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400693
694 if (defaultFramebuffer)
695 {
696 defaultFramebuffer->onDestroy(this);
697 delete defaultFramebuffer;
698 }
699
Corentin Wallezc295e512017-01-27 17:47:50 -0500700 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
701
702 if (mCurrentSurface)
703 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400704 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500705 mCurrentSurface = nullptr;
706 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400707
708 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400709}
710
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711GLuint Context::createBuffer()
712{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500713 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000714}
715
716GLuint Context::createProgram()
717{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500718 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000719}
720
Jiawei Shao385b3e02018-03-21 09:43:28 +0800721GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500723 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000724}
725
726GLuint Context::createTexture()
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000729}
730
731GLuint Context::createRenderbuffer()
732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000734}
735
Jamie Madill13951342018-09-30 15:24:28 -0400736void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
737{
Jamie Madill526392d2018-11-16 09:35:14 -0500738 ANGLE_CONTEXT_TRY(mState.mPaths->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400739}
740
Brandon Jones59770802018-04-02 13:18:42 -0700741GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742{
Jamie Madill13951342018-09-30 15:24:28 -0400743 GLuint created = 0;
744 tryGenPaths(range, &created);
745 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746}
747
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000748// Returns an unused framebuffer name
749GLuint Context::createFramebuffer()
750{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500751 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000752}
753
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500754void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000755{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500756 for (int i = 0; i < n; i++)
757 {
758 GLuint handle = mFenceNVHandleAllocator.allocate();
759 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
760 fences[i] = handle;
761 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000762}
763
Yunchao Hea336b902017-08-02 16:05:21 +0800764GLuint Context::createProgramPipeline()
765{
766 return mState.mPipelines->createProgramPipeline();
767}
768
Jiawei Shao385b3e02018-03-21 09:43:28 +0800769GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800770{
771 UNIMPLEMENTED();
772 return 0u;
773}
774
James Darpinian4d9d4832018-03-13 12:43:28 -0700775void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000776{
James Darpinian4d9d4832018-03-13 12:43:28 -0700777 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
778 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000779 {
780 detachBuffer(buffer);
781 }
Jamie Madill893ab082014-05-16 16:56:10 -0400782
James Darpinian4d9d4832018-03-13 12:43:28 -0700783 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000784}
785
786void Context::deleteShader(GLuint shader)
787{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500788 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000789}
790
791void Context::deleteProgram(GLuint program)
792{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500793 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000794}
795
796void Context::deleteTexture(GLuint texture)
797{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500798 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000799 {
800 detachTexture(texture);
801 }
802
Jamie Madill6c1f6712017-02-14 19:08:04 -0500803 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000804}
805
806void Context::deleteRenderbuffer(GLuint renderbuffer)
807{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500808 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809 {
810 detachRenderbuffer(renderbuffer);
811 }
Jamie Madill893ab082014-05-16 16:56:10 -0400812
Jamie Madill6c1f6712017-02-14 19:08:04 -0500813 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000814}
815
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400816void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400817{
818 // The spec specifies the underlying Fence object is not deleted until all current
819 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
820 // and since our API is currently designed for being called from a single thread, we can delete
821 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400822 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400823}
824
Yunchao Hea336b902017-08-02 16:05:21 +0800825void Context::deleteProgramPipeline(GLuint pipeline)
826{
827 if (mState.mPipelines->getProgramPipeline(pipeline))
828 {
829 detachProgramPipeline(pipeline);
830 }
831
832 mState.mPipelines->deleteObject(this, pipeline);
833}
834
Sami Väisänene45e53b2016-05-25 10:36:04 +0300835void Context::deletePaths(GLuint first, GLsizei range)
836{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500837 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300838}
839
Brandon Jones59770802018-04-02 13:18:42 -0700840bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300841{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500842 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843 if (pathObj == nullptr)
844 return false;
845
846 return pathObj->hasPathData();
847}
848
Brandon Jones59770802018-04-02 13:18:42 -0700849bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300850{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500851 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300852}
853
Brandon Jones59770802018-04-02 13:18:42 -0700854void Context::pathCommands(GLuint path,
855 GLsizei numCommands,
856 const GLubyte *commands,
857 GLsizei numCoords,
858 GLenum coordType,
859 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862
Jamie Madill4f6592f2018-11-27 16:37:45 -0500863 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300864}
865
Jamie Madill007530e2017-12-28 14:27:04 -0500866void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867{
Jamie Madill007530e2017-12-28 14:27:04 -0500868 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300869
870 switch (pname)
871 {
872 case GL_PATH_STROKE_WIDTH_CHROMIUM:
873 pathObj->setStrokeWidth(value);
874 break;
875 case GL_PATH_END_CAPS_CHROMIUM:
876 pathObj->setEndCaps(static_cast<GLenum>(value));
877 break;
878 case GL_PATH_JOIN_STYLE_CHROMIUM:
879 pathObj->setJoinStyle(static_cast<GLenum>(value));
880 break;
881 case GL_PATH_MITER_LIMIT_CHROMIUM:
882 pathObj->setMiterLimit(value);
883 break;
884 case GL_PATH_STROKE_BOUND_CHROMIUM:
885 pathObj->setStrokeBound(value);
886 break;
887 default:
888 UNREACHABLE();
889 break;
890 }
891}
892
Jamie Madill007530e2017-12-28 14:27:04 -0500893void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300894{
Jamie Madill007530e2017-12-28 14:27:04 -0500895 // TODO(jmadill): Should use proper clamping/casting.
896 pathParameterf(path, pname, static_cast<GLfloat>(value));
897}
898
899void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
900{
901 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300902
903 switch (pname)
904 {
905 case GL_PATH_STROKE_WIDTH_CHROMIUM:
906 *value = pathObj->getStrokeWidth();
907 break;
908 case GL_PATH_END_CAPS_CHROMIUM:
909 *value = static_cast<GLfloat>(pathObj->getEndCaps());
910 break;
911 case GL_PATH_JOIN_STYLE_CHROMIUM:
912 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
913 break;
914 case GL_PATH_MITER_LIMIT_CHROMIUM:
915 *value = pathObj->getMiterLimit();
916 break;
917 case GL_PATH_STROKE_BOUND_CHROMIUM:
918 *value = pathObj->getStrokeBound();
919 break;
920 default:
921 UNREACHABLE();
922 break;
923 }
924}
925
Jamie Madill007530e2017-12-28 14:27:04 -0500926void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
927{
928 GLfloat val = 0.0f;
929 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
930 if (value)
931 *value = static_cast<GLint>(val);
932}
933
Brandon Jones59770802018-04-02 13:18:42 -0700934void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300935{
936 mGLState.setPathStencilFunc(func, ref, mask);
937}
938
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000939void Context::deleteFramebuffer(GLuint framebuffer)
940{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500941 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000942 {
943 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000944 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500945
Jamie Madill6c1f6712017-02-14 19:08:04 -0500946 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947}
948
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500949void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500951 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500953 GLuint fence = fences[i];
954
955 FenceNV *fenceObject = nullptr;
956 if (mFenceNVMap.erase(fence, &fenceObject))
957 {
958 mFenceNVHandleAllocator.release(fence);
959 delete fenceObject;
960 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961 }
962}
963
Geoff Lang70d0f492015-12-10 17:45:46 -0500964Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000965{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500966 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000967}
968
Geoff Lang70d0f492015-12-10 17:45:46 -0500969Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000970{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500971 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972}
973
Jamie Madill70b5bb02017-08-28 13:32:37 -0400974Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400975{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400976 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400977}
978
Jamie Madill57a89722013-07-02 11:57:03 -0400979VertexArray *Context::getVertexArray(GLuint handle) const
980{
Jamie Madill96a483b2017-06-27 16:49:21 -0400981 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400982}
983
Jamie Madilldc356042013-07-19 16:36:57 -0400984Sampler *Context::getSampler(GLuint handle) const
985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500986 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400987}
988
Geoff Langc8058452014-02-03 12:04:11 -0500989TransformFeedback *Context::getTransformFeedback(GLuint handle) const
990{
Jamie Madill96a483b2017-06-27 16:49:21 -0400991 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500992}
993
Yunchao Hea336b902017-08-02 16:05:21 +0800994ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
995{
996 return mState.mPipelines->getProgramPipeline(handle);
997}
998
Geoff Lang75359662018-04-11 01:42:27 -0400999gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001000{
1001 switch (identifier)
1002 {
1003 case GL_BUFFER:
1004 return getBuffer(name);
1005 case GL_SHADER:
1006 return getShader(name);
1007 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001008 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -05001009 case GL_VERTEX_ARRAY:
1010 return getVertexArray(name);
1011 case GL_QUERY:
1012 return getQuery(name);
1013 case GL_TRANSFORM_FEEDBACK:
1014 return getTransformFeedback(name);
1015 case GL_SAMPLER:
1016 return getSampler(name);
1017 case GL_TEXTURE:
1018 return getTexture(name);
1019 case GL_RENDERBUFFER:
1020 return getRenderbuffer(name);
1021 case GL_FRAMEBUFFER:
1022 return getFramebuffer(name);
1023 default:
1024 UNREACHABLE();
1025 return nullptr;
1026 }
1027}
1028
Geoff Lang75359662018-04-11 01:42:27 -04001029gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001030{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001031 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001032}
1033
Martin Radev9d901792016-07-15 15:58:58 +03001034void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1035{
Geoff Lang75359662018-04-11 01:42:27 -04001036 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001037 ASSERT(object != nullptr);
1038
1039 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001040 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001041
1042 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1043 // specified object is active until we do this.
1044 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001045}
1046
1047void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1048{
Geoff Lang75359662018-04-11 01:42:27 -04001049 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001050 ASSERT(object != nullptr);
1051
1052 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001053 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001054}
1055
1056void Context::getObjectLabel(GLenum identifier,
1057 GLuint name,
1058 GLsizei bufSize,
1059 GLsizei *length,
1060 GLchar *label) const
1061{
Geoff Lang75359662018-04-11 01:42:27 -04001062 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001063 ASSERT(object != nullptr);
1064
1065 const std::string &objectLabel = object->getLabel();
1066 GetObjectLabelBase(objectLabel, bufSize, length, label);
1067}
1068
1069void Context::getObjectPtrLabel(const void *ptr,
1070 GLsizei bufSize,
1071 GLsizei *length,
1072 GLchar *label) const
1073{
Geoff Lang75359662018-04-11 01:42:27 -04001074 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001075 ASSERT(object != nullptr);
1076
1077 const std::string &objectLabel = object->getLabel();
1078 GetObjectLabelBase(objectLabel, bufSize, length, label);
1079}
1080
Jamie Madilldc356042013-07-19 16:36:57 -04001081bool Context::isSampler(GLuint samplerName) const
1082{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001083 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001084}
1085
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001086void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001087{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001088 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Jamie Madilldedd7b92014-11-05 16:30:36 -05001090 if (handle == 0)
1091 {
1092 texture = mZeroTextures[target].get();
1093 }
1094 else
1095 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001096 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001097 }
1098
1099 ASSERT(texture);
Jamie Madille3e680c2018-12-03 17:49:08 -05001100 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001101 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001102}
1103
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001104void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001106 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1107 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001108 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001109 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001112void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001114 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1115 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001116 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001117 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001118 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119}
1120
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001121void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001122{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001123 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001124 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001125 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001126 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001127}
1128
Shao80957d92017-02-20 21:25:59 +08001129void Context::bindVertexBuffer(GLuint bindingIndex,
1130 GLuint bufferHandle,
1131 GLintptr offset,
1132 GLsizei stride)
1133{
1134 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001135 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001136 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001137}
1138
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001139void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001140{
Geoff Lang76b10c92014-09-05 16:28:14 -04001141 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001142 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001143 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001144 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001145 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001146}
1147
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001148void Context::bindImageTexture(GLuint unit,
1149 GLuint texture,
1150 GLint level,
1151 GLboolean layered,
1152 GLint layer,
1153 GLenum access,
1154 GLenum format)
1155{
1156 Texture *tex = mState.mTextures->getTexture(texture);
1157 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Jamie Madille3e680c2018-12-03 17:49:08 -05001158 mImageObserverBindings[unit].bind(tex);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001159}
1160
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161void Context::useProgram(GLuint program)
1162{
Jamie Madille3bb6b72018-10-03 17:51:15 -04001163 ANGLE_CONTEXT_TRY(mGLState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001164 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001165}
1166
Jiajia Qin5451d532017-11-16 17:16:34 +08001167void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1168{
1169 UNIMPLEMENTED();
1170}
1171
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001172void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001173{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001174 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001175 TransformFeedback *transformFeedback =
1176 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001177 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001178}
1179
Yunchao Hea336b902017-08-02 16:05:21 +08001180void Context::bindProgramPipeline(GLuint pipelineHandle)
1181{
1182 ProgramPipeline *pipeline =
1183 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1184 mGLState.setProgramPipelineBinding(this, pipeline);
1185}
1186
Corentin Wallezad3ae902018-03-09 13:40:42 -05001187void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001188{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001190 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191
Geoff Lang5aad9672014-09-08 11:10:42 -04001192 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001193 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001194
1195 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001196 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001197 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198}
1199
Corentin Wallezad3ae902018-03-09 13:40:42 -05001200void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001202 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001203 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001204
Jamie Madill4f6592f2018-11-27 16:37:45 -05001205 // Intentionally don't call try here. We don't want an early return.
1206 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207
Geoff Lang5aad9672014-09-08 11:10:42 -04001208 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001209 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001210 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211}
1212
Corentin Wallezad3ae902018-03-09 13:40:42 -05001213void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001214{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001215 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001216
1217 Query *queryObject = getQuery(id, true, target);
1218 ASSERT(queryObject);
1219
Jamie Madill4f6592f2018-11-27 16:37:45 -05001220 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001221}
1222
Corentin Wallezad3ae902018-03-09 13:40:42 -05001223void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001224{
1225 switch (pname)
1226 {
1227 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001228 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229 break;
1230 case GL_QUERY_COUNTER_BITS_EXT:
1231 switch (target)
1232 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001233 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1235 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001236 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001237 params[0] = getExtensions().queryCounterBitsTimestamp;
1238 break;
1239 default:
1240 UNREACHABLE();
1241 params[0] = 0;
1242 break;
1243 }
1244 break;
1245 default:
1246 UNREACHABLE();
1247 return;
1248 }
1249}
1250
Corentin Wallezad3ae902018-03-09 13:40:42 -05001251void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001252 GLenum pname,
1253 GLsizei bufSize,
1254 GLsizei *length,
1255 GLint *params)
1256{
1257 getQueryiv(target, pname, params);
1258}
1259
Geoff Lang2186c382016-10-14 10:54:54 -04001260void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001261{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001262 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001263}
1264
Brandon Jones59770802018-04-02 13:18:42 -07001265void Context::getQueryObjectivRobust(GLuint id,
1266 GLenum pname,
1267 GLsizei bufSize,
1268 GLsizei *length,
1269 GLint *params)
1270{
1271 getQueryObjectiv(id, pname, params);
1272}
1273
Geoff Lang2186c382016-10-14 10:54:54 -04001274void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001275{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001276 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001277}
1278
Brandon Jones59770802018-04-02 13:18:42 -07001279void Context::getQueryObjectuivRobust(GLuint id,
1280 GLenum pname,
1281 GLsizei bufSize,
1282 GLsizei *length,
1283 GLuint *params)
1284{
1285 getQueryObjectuiv(id, pname, params);
1286}
1287
Geoff Lang2186c382016-10-14 10:54:54 -04001288void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001289{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001290 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001291}
1292
Brandon Jones59770802018-04-02 13:18:42 -07001293void Context::getQueryObjecti64vRobust(GLuint id,
1294 GLenum pname,
1295 GLsizei bufSize,
1296 GLsizei *length,
1297 GLint64 *params)
1298{
1299 getQueryObjecti64v(id, pname, params);
1300}
1301
Geoff Lang2186c382016-10-14 10:54:54 -04001302void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001303{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001304 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001305}
1306
Brandon Jones59770802018-04-02 13:18:42 -07001307void Context::getQueryObjectui64vRobust(GLuint id,
1308 GLenum pname,
1309 GLsizei bufSize,
1310 GLsizei *length,
1311 GLuint64 *params)
1312{
1313 getQueryObjectui64v(id, pname, params);
1314}
1315
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001316Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001318 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319}
1320
Jamie Madill2f348d22017-06-05 10:50:59 -04001321FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322{
Jamie Madill96a483b2017-06-27 16:49:21 -04001323 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324}
1325
Corentin Wallezad3ae902018-03-09 13:40:42 -05001326Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327{
Jamie Madill96a483b2017-06-27 16:49:21 -04001328 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001329 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001330 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001332
1333 Query *query = mQueryMap.query(handle);
1334 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001336 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001337 query = new Query(mImplementation->createQuery(type), handle);
1338 query->addRef();
1339 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001341 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342}
1343
Geoff Lang70d0f492015-12-10 17:45:46 -05001344Query *Context::getQuery(GLuint handle) const
1345{
Jamie Madill96a483b2017-06-27 16:49:21 -04001346 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001347}
1348
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001349Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001350{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001351 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1352 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001353}
1354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001355Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001356{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001357 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358}
1359
Geoff Lang492a7e42014-11-05 13:27:06 -05001360Compiler *Context::getCompiler() const
1361{
Jamie Madill2f348d22017-06-05 10:50:59 -04001362 if (mCompiler.get() == nullptr)
1363 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001364 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001365 }
1366 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001367}
1368
Jamie Madillc1d770e2017-04-13 17:31:24 -04001369void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370{
1371 switch (pname)
1372 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 case GL_SHADER_COMPILER:
1374 *params = GL_TRUE;
1375 break;
1376 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1377 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1378 break;
1379 default:
1380 mGLState.getBooleanv(pname, params);
1381 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001382 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001383}
1384
Jamie Madillc1d770e2017-04-13 17:31:24 -04001385void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001386{
Shannon Woods53a94a82014-06-24 15:20:36 -04001387 // Queries about context capabilities and maximums are answered by Context.
1388 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001389 switch (pname)
1390 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 case GL_ALIASED_LINE_WIDTH_RANGE:
1392 params[0] = mCaps.minAliasedLineWidth;
1393 params[1] = mCaps.maxAliasedLineWidth;
1394 break;
1395 case GL_ALIASED_POINT_SIZE_RANGE:
1396 params[0] = mCaps.minAliasedPointSize;
1397 params[1] = mCaps.maxAliasedPointSize;
1398 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001399 case GL_SMOOTH_POINT_SIZE_RANGE:
1400 params[0] = mCaps.minSmoothPointSize;
1401 params[1] = mCaps.maxSmoothPointSize;
1402 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001403 case GL_SMOOTH_LINE_WIDTH_RANGE:
1404 params[0] = mCaps.minSmoothLineWidth;
1405 params[1] = mCaps.maxSmoothLineWidth;
1406 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1408 ASSERT(mExtensions.textureFilterAnisotropic);
1409 *params = mExtensions.maxTextureAnisotropy;
1410 break;
1411 case GL_MAX_TEXTURE_LOD_BIAS:
1412 *params = mCaps.maxLODBias;
1413 break;
1414
1415 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1416 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1417 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001418 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1419 // GLES1 constants for modelview/projection matrix.
1420 if (getClientVersion() < Version(2, 0))
1421 {
1422 mGLState.getFloatv(pname, params);
1423 }
1424 else
1425 {
1426 ASSERT(mExtensions.pathRendering);
1427 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1428 memcpy(params, m, 16 * sizeof(GLfloat));
1429 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001431 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001432
Jamie Madill231c7f52017-04-26 13:45:37 -04001433 default:
1434 mGLState.getFloatv(pname, params);
1435 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001436 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437}
1438
Jamie Madillc1d770e2017-04-13 17:31:24 -04001439void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001440{
Shannon Woods53a94a82014-06-24 15:20:36 -04001441 // Queries about context capabilities and maximums are answered by Context.
1442 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001443
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001444 switch (pname)
1445 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 case GL_MAX_VERTEX_ATTRIBS:
1447 *params = mCaps.maxVertexAttributes;
1448 break;
1449 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1450 *params = mCaps.maxVertexUniformVectors;
1451 break;
1452 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001453 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001454 break;
1455 case GL_MAX_VARYING_VECTORS:
1456 *params = mCaps.maxVaryingVectors;
1457 break;
1458 case GL_MAX_VARYING_COMPONENTS:
1459 *params = mCaps.maxVertexOutputComponents;
1460 break;
1461 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1462 *params = mCaps.maxCombinedTextureImageUnits;
1463 break;
1464 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001465 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 break;
1467 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001468 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001469 break;
1470 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1471 *params = mCaps.maxFragmentUniformVectors;
1472 break;
1473 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001474 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 break;
1476 case GL_MAX_RENDERBUFFER_SIZE:
1477 *params = mCaps.maxRenderbufferSize;
1478 break;
1479 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1480 *params = mCaps.maxColorAttachments;
1481 break;
1482 case GL_MAX_DRAW_BUFFERS_EXT:
1483 *params = mCaps.maxDrawBuffers;
1484 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001485 case GL_SUBPIXEL_BITS:
1486 *params = 4;
1487 break;
1488 case GL_MAX_TEXTURE_SIZE:
1489 *params = mCaps.max2DTextureSize;
1490 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001491 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1492 *params = mCaps.maxRectangleTextureSize;
1493 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1495 *params = mCaps.maxCubeMapTextureSize;
1496 break;
1497 case GL_MAX_3D_TEXTURE_SIZE:
1498 *params = mCaps.max3DTextureSize;
1499 break;
1500 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1501 *params = mCaps.maxArrayTextureLayers;
1502 break;
1503 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1504 *params = mCaps.uniformBufferOffsetAlignment;
1505 break;
1506 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1507 *params = mCaps.maxUniformBufferBindings;
1508 break;
1509 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001510 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001511 break;
1512 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001513 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001514 break;
1515 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1516 *params = mCaps.maxCombinedTextureImageUnits;
1517 break;
1518 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1519 *params = mCaps.maxVertexOutputComponents;
1520 break;
1521 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1522 *params = mCaps.maxFragmentInputComponents;
1523 break;
1524 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1525 *params = mCaps.minProgramTexelOffset;
1526 break;
1527 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1528 *params = mCaps.maxProgramTexelOffset;
1529 break;
1530 case GL_MAJOR_VERSION:
1531 *params = getClientVersion().major;
1532 break;
1533 case GL_MINOR_VERSION:
1534 *params = getClientVersion().minor;
1535 break;
1536 case GL_MAX_ELEMENTS_INDICES:
1537 *params = mCaps.maxElementsIndices;
1538 break;
1539 case GL_MAX_ELEMENTS_VERTICES:
1540 *params = mCaps.maxElementsVertices;
1541 break;
1542 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1543 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1544 break;
1545 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1546 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1547 break;
1548 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1549 *params = mCaps.maxTransformFeedbackSeparateComponents;
1550 break;
1551 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1552 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1553 break;
1554 case GL_MAX_SAMPLES_ANGLE:
1555 *params = mCaps.maxSamples;
1556 break;
1557 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001558 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001559 params[0] = mCaps.maxViewportWidth;
1560 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001561 }
1562 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001563 case GL_COMPRESSED_TEXTURE_FORMATS:
1564 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1565 params);
1566 break;
1567 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1568 *params = mResetStrategy;
1569 break;
1570 case GL_NUM_SHADER_BINARY_FORMATS:
1571 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1572 break;
1573 case GL_SHADER_BINARY_FORMATS:
1574 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1575 break;
1576 case GL_NUM_PROGRAM_BINARY_FORMATS:
1577 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1578 break;
1579 case GL_PROGRAM_BINARY_FORMATS:
1580 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1581 break;
1582 case GL_NUM_EXTENSIONS:
1583 *params = static_cast<GLint>(mExtensionStrings.size());
1584 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001585
Geoff Lang38f24ee2018-10-01 13:04:59 -04001586 // GL_ANGLE_request_extension
1587 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1588 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1589 break;
1590
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 // GL_KHR_debug
1592 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1593 *params = mExtensions.maxDebugMessageLength;
1594 break;
1595 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1596 *params = mExtensions.maxDebugLoggedMessages;
1597 break;
1598 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1599 *params = mExtensions.maxDebugGroupStackDepth;
1600 break;
1601 case GL_MAX_LABEL_LENGTH:
1602 *params = mExtensions.maxLabelLength;
1603 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001604
Martin Radeve5285d22017-07-14 16:23:53 +03001605 // GL_ANGLE_multiview
1606 case GL_MAX_VIEWS_ANGLE:
1607 *params = mExtensions.maxViews;
1608 break;
1609
Jamie Madill231c7f52017-04-26 13:45:37 -04001610 // GL_EXT_disjoint_timer_query
1611 case GL_GPU_DISJOINT_EXT:
1612 *params = mImplementation->getGPUDisjoint();
1613 break;
1614 case GL_MAX_FRAMEBUFFER_WIDTH:
1615 *params = mCaps.maxFramebufferWidth;
1616 break;
1617 case GL_MAX_FRAMEBUFFER_HEIGHT:
1618 *params = mCaps.maxFramebufferHeight;
1619 break;
1620 case GL_MAX_FRAMEBUFFER_SAMPLES:
1621 *params = mCaps.maxFramebufferSamples;
1622 break;
1623 case GL_MAX_SAMPLE_MASK_WORDS:
1624 *params = mCaps.maxSampleMaskWords;
1625 break;
1626 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1627 *params = mCaps.maxColorTextureSamples;
1628 break;
1629 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1630 *params = mCaps.maxDepthTextureSamples;
1631 break;
1632 case GL_MAX_INTEGER_SAMPLES:
1633 *params = mCaps.maxIntegerSamples;
1634 break;
1635 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1636 *params = mCaps.maxVertexAttribRelativeOffset;
1637 break;
1638 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1639 *params = mCaps.maxVertexAttribBindings;
1640 break;
1641 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1642 *params = mCaps.maxVertexAttribStride;
1643 break;
1644 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001645 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 break;
1647 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001654 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001666 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1669 *params = mCaps.minProgramTextureGatherOffset;
1670 break;
1671 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1672 *params = mCaps.maxProgramTextureGatherOffset;
1673 break;
1674 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1675 *params = mCaps.maxComputeWorkGroupInvocations;
1676 break;
1677 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001678 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001679 break;
1680 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001681 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1684 *params = mCaps.maxComputeSharedMemorySize;
1685 break;
1686 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001687 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001688 break;
1689 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001690 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 break;
1692 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001693 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001696 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001699 *params =
1700 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 break;
1702 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001703 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001704 break;
1705 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1706 *params = mCaps.maxCombinedShaderOutputResources;
1707 break;
1708 case GL_MAX_UNIFORM_LOCATIONS:
1709 *params = mCaps.maxUniformLocations;
1710 break;
1711 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1712 *params = mCaps.maxAtomicCounterBufferBindings;
1713 break;
1714 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1715 *params = mCaps.maxAtomicCounterBufferSize;
1716 break;
1717 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1718 *params = mCaps.maxCombinedAtomicCounterBuffers;
1719 break;
1720 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1721 *params = mCaps.maxCombinedAtomicCounters;
1722 break;
1723 case GL_MAX_IMAGE_UNITS:
1724 *params = mCaps.maxImageUnits;
1725 break;
1726 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1727 *params = mCaps.maxCombinedImageUniforms;
1728 break;
1729 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1730 *params = mCaps.maxShaderStorageBufferBindings;
1731 break;
1732 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1733 *params = mCaps.maxCombinedShaderStorageBlocks;
1734 break;
1735 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1736 *params = mCaps.shaderStorageBufferOffsetAlignment;
1737 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001738
1739 // GL_EXT_geometry_shader
1740 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1741 *params = mCaps.maxFramebufferLayers;
1742 break;
1743 case GL_LAYER_PROVOKING_VERTEX_EXT:
1744 *params = mCaps.layerProvokingVertex;
1745 break;
1746 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001747 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001748 break;
1749 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001750 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001751 break;
1752 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001753 *params =
1754 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001755 break;
1756 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1757 *params = mCaps.maxGeometryInputComponents;
1758 break;
1759 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1760 *params = mCaps.maxGeometryOutputComponents;
1761 break;
1762 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1763 *params = mCaps.maxGeometryOutputVertices;
1764 break;
1765 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1766 *params = mCaps.maxGeometryTotalOutputComponents;
1767 break;
1768 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1769 *params = mCaps.maxGeometryShaderInvocations;
1770 break;
1771 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001772 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001773 break;
1774 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001775 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001776 break;
1777 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001778 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001779 break;
1780 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001781 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001782 break;
1783 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001784 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001785 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001786 // GLES1 emulation: Caps queries
1787 case GL_MAX_TEXTURE_UNITS:
1788 *params = mCaps.maxMultitextureUnits;
1789 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001790 case GL_MAX_MODELVIEW_STACK_DEPTH:
1791 *params = mCaps.maxModelviewMatrixStackDepth;
1792 break;
1793 case GL_MAX_PROJECTION_STACK_DEPTH:
1794 *params = mCaps.maxProjectionMatrixStackDepth;
1795 break;
1796 case GL_MAX_TEXTURE_STACK_DEPTH:
1797 *params = mCaps.maxTextureMatrixStackDepth;
1798 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001799 case GL_MAX_LIGHTS:
1800 *params = mCaps.maxLights;
1801 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001802 case GL_MAX_CLIP_PLANES:
1803 *params = mCaps.maxClipPlanes;
1804 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001805 // GLES1 emulation: Vertex attribute queries
1806 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1807 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1808 case GL_COLOR_ARRAY_BUFFER_BINDING:
1809 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1810 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1811 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1812 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1813 break;
1814 case GL_VERTEX_ARRAY_STRIDE:
1815 case GL_NORMAL_ARRAY_STRIDE:
1816 case GL_COLOR_ARRAY_STRIDE:
1817 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1818 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1819 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1820 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1821 break;
1822 case GL_VERTEX_ARRAY_SIZE:
1823 case GL_COLOR_ARRAY_SIZE:
1824 case GL_TEXTURE_COORD_ARRAY_SIZE:
1825 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1826 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1827 break;
1828 case GL_VERTEX_ARRAY_TYPE:
1829 case GL_COLOR_ARRAY_TYPE:
1830 case GL_NORMAL_ARRAY_TYPE:
1831 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1832 case GL_TEXTURE_COORD_ARRAY_TYPE:
1833 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1834 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1835 break;
1836
jchen1082af6202018-06-22 10:59:52 +08001837 // GL_KHR_parallel_shader_compile
1838 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1839 *params = mGLState.getMaxShaderCompilerThreads();
1840 break;
1841
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001842 // GL_EXT_blend_func_extended
1843 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1844 *params = mExtensions.maxDualSourceDrawBuffers;
1845 break;
1846
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001848 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001849 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001850 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001851}
1852
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001853void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001854{
Shannon Woods53a94a82014-06-24 15:20:36 -04001855 // Queries about context capabilities and maximums are answered by Context.
1856 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001857 switch (pname)
1858 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001859 case GL_MAX_ELEMENT_INDEX:
1860 *params = mCaps.maxElementIndex;
1861 break;
1862 case GL_MAX_UNIFORM_BLOCK_SIZE:
1863 *params = mCaps.maxUniformBlockSize;
1864 break;
1865 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001866 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001867 break;
1868 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001869 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001870 break;
1871 case GL_MAX_SERVER_WAIT_TIMEOUT:
1872 *params = mCaps.maxServerWaitTimeout;
1873 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001874
Jamie Madill231c7f52017-04-26 13:45:37 -04001875 // GL_EXT_disjoint_timer_query
1876 case GL_TIMESTAMP_EXT:
1877 *params = mImplementation->getTimestamp();
1878 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001879
Jamie Madill231c7f52017-04-26 13:45:37 -04001880 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1881 *params = mCaps.maxShaderStorageBlockSize;
1882 break;
1883 default:
1884 UNREACHABLE();
1885 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001886 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001887}
1888
Geoff Lang70d0f492015-12-10 17:45:46 -05001889void Context::getPointerv(GLenum pname, void **params) const
1890{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001891 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001892}
1893
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001894void Context::getPointervRobustANGLERobust(GLenum pname,
1895 GLsizei bufSize,
1896 GLsizei *length,
1897 void **params)
1898{
1899 UNIMPLEMENTED();
1900}
1901
Martin Radev66fb8202016-07-28 11:45:20 +03001902void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001903{
Shannon Woods53a94a82014-06-24 15:20:36 -04001904 // Queries about context capabilities and maximums are answered by Context.
1905 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001906
1907 GLenum nativeType;
1908 unsigned int numParams;
1909 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1910 ASSERT(queryStatus);
1911
1912 if (nativeType == GL_INT)
1913 {
1914 switch (target)
1915 {
1916 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1917 ASSERT(index < 3u);
1918 *data = mCaps.maxComputeWorkGroupCount[index];
1919 break;
1920 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1921 ASSERT(index < 3u);
1922 *data = mCaps.maxComputeWorkGroupSize[index];
1923 break;
1924 default:
1925 mGLState.getIntegeri_v(target, index, data);
1926 }
1927 }
1928 else
1929 {
1930 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1931 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001932}
1933
Brandon Jones59770802018-04-02 13:18:42 -07001934void Context::getIntegeri_vRobust(GLenum target,
1935 GLuint index,
1936 GLsizei bufSize,
1937 GLsizei *length,
1938 GLint *data)
1939{
1940 getIntegeri_v(target, index, data);
1941}
1942
Martin Radev66fb8202016-07-28 11:45:20 +03001943void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001944{
Shannon Woods53a94a82014-06-24 15:20:36 -04001945 // Queries about context capabilities and maximums are answered by Context.
1946 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001947
1948 GLenum nativeType;
1949 unsigned int numParams;
1950 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1951 ASSERT(queryStatus);
1952
1953 if (nativeType == GL_INT_64_ANGLEX)
1954 {
1955 mGLState.getInteger64i_v(target, index, data);
1956 }
1957 else
1958 {
1959 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1960 }
1961}
1962
Brandon Jones59770802018-04-02 13:18:42 -07001963void Context::getInteger64i_vRobust(GLenum target,
1964 GLuint index,
1965 GLsizei bufSize,
1966 GLsizei *length,
1967 GLint64 *data)
1968{
1969 getInteger64i_v(target, index, data);
1970}
1971
Martin Radev66fb8202016-07-28 11:45:20 +03001972void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1973{
1974 // Queries about context capabilities and maximums are answered by Context.
1975 // Queries about current GL state values are answered by State.
1976
1977 GLenum nativeType;
1978 unsigned int numParams;
1979 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1980 ASSERT(queryStatus);
1981
1982 if (nativeType == GL_BOOL)
1983 {
1984 mGLState.getBooleani_v(target, index, data);
1985 }
1986 else
1987 {
1988 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1989 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001990}
1991
Brandon Jones59770802018-04-02 13:18:42 -07001992void Context::getBooleani_vRobust(GLenum target,
1993 GLuint index,
1994 GLsizei bufSize,
1995 GLsizei *length,
1996 GLboolean *data)
1997{
1998 getBooleani_v(target, index, data);
1999}
2000
Corentin Wallez336129f2017-10-17 15:55:40 -04002001void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002002{
2003 Buffer *buffer = mGLState.getTargetBuffer(target);
2004 QueryBufferParameteriv(buffer, pname, params);
2005}
2006
Brandon Jones59770802018-04-02 13:18:42 -07002007void Context::getBufferParameterivRobust(BufferBinding target,
2008 GLenum pname,
2009 GLsizei bufSize,
2010 GLsizei *length,
2011 GLint *params)
2012{
2013 getBufferParameteriv(target, pname, params);
2014}
2015
He Yunchao010e4db2017-03-03 14:22:06 +08002016void Context::getFramebufferAttachmentParameteriv(GLenum target,
2017 GLenum attachment,
2018 GLenum pname,
2019 GLint *params)
2020{
2021 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002022 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002023}
2024
Brandon Jones59770802018-04-02 13:18:42 -07002025void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2026 GLenum attachment,
2027 GLenum pname,
2028 GLsizei bufSize,
2029 GLsizei *length,
2030 GLint *params)
2031{
2032 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2033}
2034
He Yunchao010e4db2017-03-03 14:22:06 +08002035void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2036{
2037 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2038 QueryRenderbufferiv(this, renderbuffer, pname, params);
2039}
2040
Brandon Jones59770802018-04-02 13:18:42 -07002041void Context::getRenderbufferParameterivRobust(GLenum target,
2042 GLenum pname,
2043 GLsizei bufSize,
2044 GLsizei *length,
2045 GLint *params)
2046{
2047 getRenderbufferParameteriv(target, pname, params);
2048}
2049
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002050void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002051{
Till Rathmannb8543632018-10-02 19:46:14 +02002052 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002053 QueryTexParameterfv(texture, pname, params);
2054}
2055
Brandon Jones59770802018-04-02 13:18:42 -07002056void Context::getTexParameterfvRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLfloat *params)
2061{
2062 getTexParameterfv(target, pname, params);
2063}
2064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002065void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002066{
Till Rathmannb8543632018-10-02 19:46:14 +02002067 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002068 QueryTexParameteriv(texture, pname, params);
2069}
Jiajia Qin5451d532017-11-16 17:16:34 +08002070
Till Rathmannb8543632018-10-02 19:46:14 +02002071void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2072{
2073 const Texture *const texture = getTargetTexture(target);
2074 QueryTexParameterIiv(texture, pname, params);
2075}
2076
2077void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2078{
2079 const Texture *const texture = getTargetTexture(target);
2080 QueryTexParameterIuiv(texture, pname, params);
2081}
2082
Brandon Jones59770802018-04-02 13:18:42 -07002083void Context::getTexParameterivRobust(TextureType target,
2084 GLenum pname,
2085 GLsizei bufSize,
2086 GLsizei *length,
2087 GLint *params)
2088{
2089 getTexParameteriv(target, pname, params);
2090}
2091
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002092void Context::getTexParameterIivRobust(TextureType target,
2093 GLenum pname,
2094 GLsizei bufSize,
2095 GLsizei *length,
2096 GLint *params)
2097{
2098 UNIMPLEMENTED();
2099}
2100
2101void Context::getTexParameterIuivRobust(TextureType target,
2102 GLenum pname,
2103 GLsizei bufSize,
2104 GLsizei *length,
2105 GLuint *params)
2106{
2107 UNIMPLEMENTED();
2108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002111{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002113 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002114}
2115
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002116void Context::getTexLevelParameterivRobust(TextureTarget target,
2117 GLint level,
2118 GLenum pname,
2119 GLsizei bufSize,
2120 GLsizei *length,
2121 GLint *params)
2122{
2123 UNIMPLEMENTED();
2124}
2125
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002126void Context::getTexLevelParameterfv(TextureTarget target,
2127 GLint level,
2128 GLenum pname,
2129 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002130{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002132 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002133}
2134
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002135void Context::getTexLevelParameterfvRobust(TextureTarget target,
2136 GLint level,
2137 GLenum pname,
2138 GLsizei bufSize,
2139 GLsizei *length,
2140 GLfloat *params)
2141{
2142 UNIMPLEMENTED();
2143}
2144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002145void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002146{
Till Rathmannb8543632018-10-02 19:46:14 +02002147 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002148 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002149}
2150
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002151void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002152{
Till Rathmannb8543632018-10-02 19:46:14 +02002153 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002154 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002155}
2156
Brandon Jones59770802018-04-02 13:18:42 -07002157void Context::texParameterfvRobust(TextureType target,
2158 GLenum pname,
2159 GLsizei bufSize,
2160 const GLfloat *params)
2161{
2162 texParameterfv(target, pname, params);
2163}
2164
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002165void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002166{
Till Rathmannb8543632018-10-02 19:46:14 +02002167 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002168 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002169}
2170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002171void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002172{
Till Rathmannb8543632018-10-02 19:46:14 +02002173 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002174 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002175}
2176
Till Rathmannb8543632018-10-02 19:46:14 +02002177void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2178{
2179 Texture *const texture = getTargetTexture(target);
2180 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002181}
2182
2183void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2184{
2185 Texture *const texture = getTargetTexture(target);
2186 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002187}
2188
Brandon Jones59770802018-04-02 13:18:42 -07002189void Context::texParameterivRobust(TextureType target,
2190 GLenum pname,
2191 GLsizei bufSize,
2192 const GLint *params)
2193{
2194 texParameteriv(target, pname, params);
2195}
2196
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002197void Context::texParameterIivRobust(TextureType target,
2198 GLenum pname,
2199 GLsizei bufSize,
2200 const GLint *params)
2201{
2202 UNIMPLEMENTED();
2203}
2204
2205void Context::texParameterIuivRobust(TextureType target,
2206 GLenum pname,
2207 GLsizei bufSize,
2208 const GLuint *params)
2209{
2210 UNIMPLEMENTED();
2211}
2212
Jamie Madill493f9572018-05-24 19:52:15 -04002213void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002215 // No-op if count draws no primitives for given mode
2216 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002217 {
2218 return;
2219 }
2220
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002221 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002222 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002223 MarkTransformFeedbackBufferUsage(this, count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224}
2225
Jamie Madill493f9572018-05-24 19:52:15 -04002226void Context::drawArraysInstanced(PrimitiveMode mode,
2227 GLint first,
2228 GLsizei count,
2229 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002230{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002231 // No-op if count draws no primitives for given mode
2232 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002233 {
2234 return;
2235 }
2236
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002237 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002238 ANGLE_CONTEXT_TRY(
2239 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002240 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002241}
2242
Jamie Madill493f9572018-05-24 19:52:15 -04002243void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002244 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002245 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002246 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002247 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002248{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002249 // No-op if count draws no primitives for given mode
2250 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002251 {
2252 return;
2253 }
2254
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002255 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002256 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002257 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002258}
2259
Jamie Madill493f9572018-05-24 19:52:15 -04002260void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002261 GLuint start,
2262 GLuint end,
2263 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002264 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002265 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002266{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002267 // No-op if count draws no primitives for given mode
2268 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002269 {
2270 return;
2271 }
2272
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002273 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002274 ANGLE_CONTEXT_TRY(
2275 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002276}
2277
Jamie Madill493f9572018-05-24 19:52:15 -04002278void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002279{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002280 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002281 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002282}
2283
Jamie Madill8dc27f92018-11-29 11:45:44 -05002284void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002285{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002286 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002287 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002288}
2289
Jamie Madill675fe712016-12-19 13:07:54 -05002290void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002291{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002292 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002293}
2294
Jamie Madill675fe712016-12-19 13:07:54 -05002295void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002296{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002297 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002298}
2299
Austin Kinross6ee1e782015-05-29 17:05:37 -07002300void Context::insertEventMarker(GLsizei length, const char *marker)
2301{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002302 ASSERT(mImplementation);
2303 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002304}
2305
2306void Context::pushGroupMarker(GLsizei length, const char *marker)
2307{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002308 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002309
2310 if (marker == nullptr)
2311 {
2312 // From the EXT_debug_marker spec,
2313 // "If <marker> is null then an empty string is pushed on the stack."
2314 mImplementation->pushGroupMarker(length, "");
2315 }
2316 else
2317 {
2318 mImplementation->pushGroupMarker(length, marker);
2319 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002320}
2321
2322void Context::popGroupMarker()
2323{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002324 ASSERT(mImplementation);
2325 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002326}
2327
Geoff Langd8605522016-04-13 10:19:12 -04002328void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2329{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002330 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002331 ASSERT(programObject);
2332
2333 programObject->bindUniformLocation(location, name);
2334}
2335
Brandon Jones59770802018-04-02 13:18:42 -07002336void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002338 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002339}
2340
Brandon Jones59770802018-04-02 13:18:42 -07002341void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002342{
2343 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2344}
2345
Brandon Jones59770802018-04-02 13:18:42 -07002346void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002347{
2348 GLfloat I[16];
2349 angle::Matrix<GLfloat>::setToIdentity(I);
2350
2351 mGLState.loadPathRenderingMatrix(matrixMode, I);
2352}
2353
2354void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2355{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002356 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357 if (!pathObj)
2358 return;
2359
Geoff Lang9bf86f02018-07-26 11:46:34 -04002360 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361
2362 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2363}
2364
2365void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2366{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002367 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002368 if (!pathObj)
2369 return;
2370
Geoff Lang9bf86f02018-07-26 11:46:34 -04002371 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002372
2373 mImplementation->stencilStrokePath(pathObj, reference, mask);
2374}
2375
2376void Context::coverFillPath(GLuint path, GLenum coverMode)
2377{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002378 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002379 if (!pathObj)
2380 return;
2381
Geoff Lang9bf86f02018-07-26 11:46:34 -04002382 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002383
2384 mImplementation->coverFillPath(pathObj, coverMode);
2385}
2386
2387void Context::coverStrokePath(GLuint path, GLenum coverMode)
2388{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002389 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002390 if (!pathObj)
2391 return;
2392
Geoff Lang9bf86f02018-07-26 11:46:34 -04002393 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002394
2395 mImplementation->coverStrokePath(pathObj, coverMode);
2396}
2397
2398void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2399{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002400 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002401 if (!pathObj)
2402 return;
2403
Geoff Lang9bf86f02018-07-26 11:46:34 -04002404 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002405
2406 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2407}
2408
2409void Context::stencilThenCoverStrokePath(GLuint path,
2410 GLint reference,
2411 GLuint mask,
2412 GLenum coverMode)
2413{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002414 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002415 if (!pathObj)
2416 return;
2417
Geoff Lang9bf86f02018-07-26 11:46:34 -04002418 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002419
2420 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2421}
2422
Sami Väisänend59ca052016-06-21 16:10:00 +03002423void Context::coverFillPathInstanced(GLsizei numPaths,
2424 GLenum pathNameType,
2425 const void *paths,
2426 GLuint pathBase,
2427 GLenum coverMode,
2428 GLenum transformType,
2429 const GLfloat *transformValues)
2430{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002432
Geoff Lang9bf86f02018-07-26 11:46:34 -04002433 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002434
2435 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2436}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002437
Sami Väisänend59ca052016-06-21 16:10:00 +03002438void Context::coverStrokePathInstanced(GLsizei numPaths,
2439 GLenum pathNameType,
2440 const void *paths,
2441 GLuint pathBase,
2442 GLenum coverMode,
2443 GLenum transformType,
2444 const GLfloat *transformValues)
2445{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002446 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002449 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
2451 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2452 transformValues);
2453}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002454
Sami Väisänend59ca052016-06-21 16:10:00 +03002455void Context::stencilFillPathInstanced(GLsizei numPaths,
2456 GLenum pathNameType,
2457 const void *paths,
2458 GLuint pathBase,
2459 GLenum fillMode,
2460 GLuint mask,
2461 GLenum transformType,
2462 const GLfloat *transformValues)
2463{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002464 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
2466 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002467 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
2469 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2470 transformValues);
2471}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002472
Sami Väisänend59ca052016-06-21 16:10:00 +03002473void Context::stencilStrokePathInstanced(GLsizei numPaths,
2474 GLenum pathNameType,
2475 const void *paths,
2476 GLuint pathBase,
2477 GLint reference,
2478 GLuint mask,
2479 GLenum transformType,
2480 const GLfloat *transformValues)
2481{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002482 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002483
Geoff Lang9bf86f02018-07-26 11:46:34 -04002484 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002485
2486 mImplementation->stencilStrokePathInstanced(pathObjects, reference, 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::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2491 GLenum pathNameType,
2492 const void *paths,
2493 GLuint pathBase,
2494 GLenum fillMode,
2495 GLuint mask,
2496 GLenum coverMode,
2497 GLenum transformType,
2498 const GLfloat *transformValues)
2499{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002500 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002501
Geoff Lang9bf86f02018-07-26 11:46:34 -04002502 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002503
2504 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2505 transformType, transformValues);
2506}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002507
Sami Väisänend59ca052016-06-21 16:10:00 +03002508void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2509 GLenum pathNameType,
2510 const void *paths,
2511 GLuint pathBase,
2512 GLint reference,
2513 GLuint mask,
2514 GLenum coverMode,
2515 GLenum transformType,
2516 const GLfloat *transformValues)
2517{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002518 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002519
Geoff Lang9bf86f02018-07-26 11:46:34 -04002520 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002521
2522 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2523 transformType, transformValues);
2524}
2525
Sami Väisänen46eaa942016-06-29 10:26:37 +03002526void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2527{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002528 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002529
2530 programObject->bindFragmentInputLocation(location, name);
2531}
2532
2533void Context::programPathFragmentInputGen(GLuint program,
2534 GLint location,
2535 GLenum genMode,
2536 GLint components,
2537 const GLfloat *coeffs)
2538{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002539 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002540
jchen103fd614d2018-08-13 12:21:58 +08002541 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002542}
2543
jchen1015015f72017-03-16 13:54:21 +08002544GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002546 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002547 return QueryProgramResourceIndex(programObject, programInterface, name);
2548}
2549
jchen10fd7c3b52017-03-21 15:36:03 +08002550void Context::getProgramResourceName(GLuint program,
2551 GLenum programInterface,
2552 GLuint index,
2553 GLsizei bufSize,
2554 GLsizei *length,
2555 GLchar *name)
2556{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002557 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002558 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2559}
2560
jchen10191381f2017-04-11 13:59:04 +08002561GLint Context::getProgramResourceLocation(GLuint program,
2562 GLenum programInterface,
2563 const GLchar *name)
2564{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002565 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002566 return QueryProgramResourceLocation(programObject, programInterface, name);
2567}
2568
jchen10880683b2017-04-12 16:21:55 +08002569void Context::getProgramResourceiv(GLuint program,
2570 GLenum programInterface,
2571 GLuint index,
2572 GLsizei propCount,
2573 const GLenum *props,
2574 GLsizei bufSize,
2575 GLsizei *length,
2576 GLint *params)
2577{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002578 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002579 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2580 length, params);
2581}
2582
jchen10d9cd7b72017-08-30 15:04:25 +08002583void Context::getProgramInterfaceiv(GLuint program,
2584 GLenum programInterface,
2585 GLenum pname,
2586 GLint *params)
2587{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002588 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002589 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2590}
2591
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002592void Context::getProgramInterfaceivRobust(GLuint program,
2593 GLenum programInterface,
2594 GLenum pname,
2595 GLsizei bufSize,
2596 GLsizei *length,
2597 GLint *params)
2598{
2599 UNIMPLEMENTED();
2600}
2601
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002602void Context::handleError(GLenum errorCode,
2603 const char *message,
2604 const char *file,
2605 const char *function,
2606 unsigned int line)
2607{
2608 mErrors.handleError(errorCode, message, file, function, line);
2609}
2610
Jamie Madilla139f012018-10-10 16:13:03 -04002611void Context::validationError(GLenum errorCode, const char *message)
2612{
2613 mErrors.validationError(errorCode, message);
2614}
2615
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002616// Get one of the recorded errors and clear its flag, if any.
2617// [OpenGL ES 2.0.24] section 2.5 page 13.
2618GLenum Context::getError()
2619{
Geoff Langda5777c2014-07-11 09:52:58 -04002620 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 {
Geoff Langda5777c2014-07-11 09:52:58 -04002622 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002623 }
Geoff Langda5777c2014-07-11 09:52:58 -04002624 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002626 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002628}
2629
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002631void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002632{
2633 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002634 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002635 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002636 mContextLostForced = true;
2637 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002638 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002639}
2640
Jamie Madillfa920eb2018-01-04 11:45:50 -05002641GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002643 // Even if the application doesn't want to know about resets, we want to know
2644 // as it will allow us to skip all the calls.
2645 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002648 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002649 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002650 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002651
2652 // EXT_robustness, section 2.6: If the reset notification behavior is
2653 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2654 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2655 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656 }
2657
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002658 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2659 // status should be returned at least once, and GL_NO_ERROR should be returned
2660 // once the device has finished resetting.
2661 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002663 ASSERT(mResetStatus == GL_NO_ERROR);
2664 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002665
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002668 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002669 }
2670 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002671 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002672 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002673 // If markContextLost was used to mark the context lost then
2674 // assume that is not recoverable, and continue to report the
2675 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 mResetStatus = mImplementation->getResetStatus();
2677 }
Jamie Madill893ab082014-05-16 16:56:10 -04002678
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002679 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002680}
2681
2682bool Context::isResetNotificationEnabled()
2683{
2684 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2685}
2686
Corentin Walleze3b10e82015-05-20 11:06:25 -04002687const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002688{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002689 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002690}
2691
2692EGLenum Context::getClientType() const
2693{
2694 return mClientType;
2695}
2696
2697EGLenum Context::getRenderBuffer() const
2698{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002699 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2700 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002701 {
2702 return EGL_NONE;
2703 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002704
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002705 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002706 ASSERT(backAttachment != nullptr);
2707 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002708}
2709
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002710VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002711{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002712 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002713 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2714 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002716 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2717 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002718
Jamie Madill96a483b2017-06-27 16:49:21 -04002719 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002720 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002721
2722 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002723}
2724
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002726{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002727 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002728 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2729 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002730 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002731 transformFeedback =
2732 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002733 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002734 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002735 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002736
2737 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002738}
2739
2740bool Context::isVertexArrayGenerated(GLuint vertexArray)
2741{
Jamie Madill96a483b2017-06-27 16:49:21 -04002742 ASSERT(mVertexArrayMap.contains(0));
2743 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002744}
2745
2746bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2747{
Jamie Madill96a483b2017-06-27 16:49:21 -04002748 ASSERT(mTransformFeedbackMap.contains(0));
2749 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002750}
2751
Shannon Woods53a94a82014-06-24 15:20:36 -04002752void Context::detachTexture(GLuint texture)
2753{
2754 // Simple pass-through to State's detachTexture method, as textures do not require
2755 // allocation map management either here or in the resource manager at detach time.
2756 // Zero textures are held by the Context, and we don't attempt to request them from
2757 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002758 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002759}
2760
James Darpinian4d9d4832018-03-13 12:43:28 -07002761void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002762{
Yuly Novikov5807a532015-12-03 13:01:22 -05002763 // Simple pass-through to State's detachBuffer method, since
2764 // only buffer attachments to container objects that are bound to the current context
2765 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002766
Yuly Novikov5807a532015-12-03 13:01:22 -05002767 // [OpenGL ES 3.2] section 5.1.2 page 45:
2768 // Attachments to unbound container objects, such as
2769 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2770 // are not affected and continue to act as references on the deleted object
Geoff Lang91002262018-12-12 16:05:24 -05002771 ANGLE_CONTEXT_TRY(mGLState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002772}
2773
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002774void Context::detachFramebuffer(GLuint framebuffer)
2775{
Shannon Woods53a94a82014-06-24 15:20:36 -04002776 // Framebuffer detachment is handled by Context, because 0 is a valid
2777 // Framebuffer object, and a pointer to it must be passed from Context
2778 // to State at binding time.
2779
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002780 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002781 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2782 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2783 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002785 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786 {
2787 bindReadFramebuffer(0);
2788 }
2789
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002790 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002791 {
2792 bindDrawFramebuffer(0);
2793 }
2794}
2795
2796void Context::detachRenderbuffer(GLuint renderbuffer)
2797{
Jamie Madilla02315b2017-02-23 14:14:47 -05002798 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002799}
2800
Jamie Madill57a89722013-07-02 11:57:03 -04002801void Context::detachVertexArray(GLuint vertexArray)
2802{
Jamie Madill77a72f62015-04-14 11:18:32 -04002803 // Vertex array detachment is handled by Context, because 0 is a valid
2804 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002805 // binding time.
2806
Jamie Madill57a89722013-07-02 11:57:03 -04002807 // [OpenGL ES 3.0.2] section 2.10 page 43:
2808 // If a vertex array object that is currently bound is deleted, the binding
2809 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002810 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002811 {
2812 bindVertexArray(0);
2813 }
2814}
2815
Geoff Langc8058452014-02-03 12:04:11 -05002816void Context::detachTransformFeedback(GLuint transformFeedback)
2817{
Corentin Walleza2257da2016-04-19 16:43:12 -04002818 // Transform feedback detachment is handled by Context, because 0 is a valid
2819 // transform feedback, and a pointer to it must be passed from Context to State at
2820 // binding time.
2821
2822 // The OpenGL specification doesn't mention what should happen when the currently bound
2823 // transform feedback object is deleted. Since it is a container object, we treat it like
2824 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002825 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002826 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002827 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002828 }
Geoff Langc8058452014-02-03 12:04:11 -05002829}
2830
Jamie Madilldc356042013-07-19 16:36:57 -04002831void Context::detachSampler(GLuint sampler)
2832{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002833 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002834}
2835
Yunchao Hea336b902017-08-02 16:05:21 +08002836void Context::detachProgramPipeline(GLuint pipeline)
2837{
2838 mGLState.detachProgramPipeline(this, pipeline);
2839}
2840
Jamie Madill3ef140a2017-08-26 23:11:21 -04002841void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002842{
Shaodde78e82017-05-22 14:13:27 +08002843 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002844 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002845}
2846
Jamie Madille29d1672013-07-19 16:36:57 -04002847void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2848{
Till Rathmannb8543632018-10-02 19:46:14 +02002849 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002850 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002851 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002852}
Jamie Madille29d1672013-07-19 16:36:57 -04002853
Geoff Langc1984ed2016-10-07 12:41:00 -04002854void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2855{
Till Rathmannb8543632018-10-02 19:46:14 +02002856 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002857 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002858 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002859}
2860
Till Rathmannb8543632018-10-02 19:46:14 +02002861void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2862{
2863 Sampler *const samplerObject =
2864 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2865 SetSamplerParameterIiv(this, samplerObject, pname, param);
2866}
2867
2868void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2869{
2870 Sampler *const samplerObject =
2871 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2872 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2873}
2874
Brandon Jones59770802018-04-02 13:18:42 -07002875void Context::samplerParameterivRobust(GLuint sampler,
2876 GLenum pname,
2877 GLsizei bufSize,
2878 const GLint *param)
2879{
2880 samplerParameteriv(sampler, pname, param);
2881}
2882
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002883void Context::samplerParameterIivRobust(GLuint sampler,
2884 GLenum pname,
2885 GLsizei bufSize,
2886 const GLint *param)
2887{
2888 UNIMPLEMENTED();
2889}
2890
2891void Context::samplerParameterIuivRobust(GLuint sampler,
2892 GLenum pname,
2893 GLsizei bufSize,
2894 const GLuint *param)
2895{
2896 UNIMPLEMENTED();
2897}
2898
Jamie Madille29d1672013-07-19 16:36:57 -04002899void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2900{
Till Rathmannb8543632018-10-02 19:46:14 +02002901 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002902 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002903 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002904}
2905
Geoff Langc1984ed2016-10-07 12:41:00 -04002906void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002907{
Till Rathmannb8543632018-10-02 19:46:14 +02002908 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002909 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002910 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002911}
2912
Brandon Jones59770802018-04-02 13:18:42 -07002913void Context::samplerParameterfvRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 const GLfloat *param)
2917{
2918 samplerParameterfv(sampler, pname, param);
2919}
2920
Geoff Langc1984ed2016-10-07 12:41:00 -04002921void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002922{
Till Rathmannb8543632018-10-02 19:46:14 +02002923 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002924 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002925 QuerySamplerParameteriv(samplerObject, pname, params);
2926}
Jamie Madill9675b802013-07-19 16:36:59 -04002927
Till Rathmannb8543632018-10-02 19:46:14 +02002928void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2929{
2930 const Sampler *const samplerObject =
2931 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2932 QuerySamplerParameterIiv(samplerObject, pname, params);
2933}
2934
2935void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2936{
2937 const Sampler *const samplerObject =
2938 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2939 QuerySamplerParameterIuiv(samplerObject, pname, params);
2940}
2941
Brandon Jones59770802018-04-02 13:18:42 -07002942void Context::getSamplerParameterivRobust(GLuint sampler,
2943 GLenum pname,
2944 GLsizei bufSize,
2945 GLsizei *length,
2946 GLint *params)
2947{
2948 getSamplerParameteriv(sampler, pname, params);
2949}
2950
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002951void Context::getSamplerParameterIivRobust(GLuint sampler,
2952 GLenum pname,
2953 GLsizei bufSize,
2954 GLsizei *length,
2955 GLint *params)
2956{
2957 UNIMPLEMENTED();
2958}
2959
2960void Context::getSamplerParameterIuivRobust(GLuint sampler,
2961 GLenum pname,
2962 GLsizei bufSize,
2963 GLsizei *length,
2964 GLuint *params)
2965{
2966 UNIMPLEMENTED();
2967}
2968
Geoff Langc1984ed2016-10-07 12:41:00 -04002969void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2970{
Till Rathmannb8543632018-10-02 19:46:14 +02002971 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002972 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002973 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002974}
2975
Brandon Jones59770802018-04-02 13:18:42 -07002976void Context::getSamplerParameterfvRobust(GLuint sampler,
2977 GLenum pname,
2978 GLsizei bufSize,
2979 GLsizei *length,
2980 GLfloat *params)
2981{
2982 getSamplerParameterfv(sampler, pname, params);
2983}
2984
Olli Etuahof0fee072016-03-30 15:11:58 +03002985void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2986{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002987 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002988 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002989}
2990
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002991void Context::initRendererString()
2992{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002993 std::ostringstream rendererString;
2994 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002995 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002996 rendererString << ")";
2997
Geoff Langcec35902014-04-16 10:52:36 -04002998 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002999}
3000
Geoff Langc339c4e2016-11-29 10:37:36 -05003001void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003002{
Geoff Langc339c4e2016-11-29 10:37:36 -05003003 const Version &clientVersion = getClientVersion();
3004
3005 std::ostringstream versionString;
3006 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3007 << ANGLE_VERSION_STRING << ")";
3008 mVersionString = MakeStaticString(versionString.str());
3009
3010 std::ostringstream shadingLanguageVersionString;
3011 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3012 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3013 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3014 << ")";
3015 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003016}
3017
Geoff Langcec35902014-04-16 10:52:36 -04003018void Context::initExtensionStrings()
3019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3021 std::ostringstream combinedStringStream;
3022 std::copy(strings.begin(), strings.end(),
3023 std::ostream_iterator<const char *>(combinedStringStream, " "));
3024 return MakeStaticString(combinedStringStream.str());
3025 };
3026
3027 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003028 for (const auto &extensionString : mExtensions.getStrings())
3029 {
3030 mExtensionStrings.push_back(MakeStaticString(extensionString));
3031 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003032 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003033
Geoff Langc339c4e2016-11-29 10:37:36 -05003034 mRequestableExtensionStrings.clear();
3035 for (const auto &extensionInfo : GetExtensionInfoMap())
3036 {
3037 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003038 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003039 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003040 {
3041 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3042 }
3043 }
3044 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003045}
3046
Geoff Langc339c4e2016-11-29 10:37:36 -05003047const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003048{
Geoff Langc339c4e2016-11-29 10:37:36 -05003049 switch (name)
3050 {
3051 case GL_VENDOR:
3052 return reinterpret_cast<const GLubyte *>("Google Inc.");
3053
3054 case GL_RENDERER:
3055 return reinterpret_cast<const GLubyte *>(mRendererString);
3056
3057 case GL_VERSION:
3058 return reinterpret_cast<const GLubyte *>(mVersionString);
3059
3060 case GL_SHADING_LANGUAGE_VERSION:
3061 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3062
3063 case GL_EXTENSIONS:
3064 return reinterpret_cast<const GLubyte *>(mExtensionString);
3065
3066 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3067 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3068
3069 default:
3070 UNREACHABLE();
3071 return nullptr;
3072 }
Geoff Langcec35902014-04-16 10:52:36 -04003073}
3074
Geoff Langc339c4e2016-11-29 10:37:36 -05003075const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003076{
Geoff Langc339c4e2016-11-29 10:37:36 -05003077 switch (name)
3078 {
3079 case GL_EXTENSIONS:
3080 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3081
3082 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3083 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3084
3085 default:
3086 UNREACHABLE();
3087 return nullptr;
3088 }
Geoff Langcec35902014-04-16 10:52:36 -04003089}
3090
3091size_t Context::getExtensionStringCount() const
3092{
3093 return mExtensionStrings.size();
3094}
3095
Geoff Lang111a99e2017-10-17 10:58:41 -04003096bool Context::isExtensionRequestable(const char *name)
3097{
3098 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3099 auto extension = extensionInfos.find(name);
3100
Geoff Lang111a99e2017-10-17 10:58:41 -04003101 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003102 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003103}
3104
Geoff Langc339c4e2016-11-29 10:37:36 -05003105void Context::requestExtension(const char *name)
3106{
3107 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3108 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3109 const auto &extension = extensionInfos.at(name);
3110 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003111 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003112
3113 if (mExtensions.*(extension.ExtensionsMember))
3114 {
3115 // Extension already enabled
3116 return;
3117 }
3118
3119 mExtensions.*(extension.ExtensionsMember) = true;
3120 updateCaps();
3121 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003122
Jamie Madill2f348d22017-06-05 10:50:59 -04003123 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3124 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003125
Jamie Madill81c2e252017-09-09 23:32:46 -04003126 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3127 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003128 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003129 for (auto &zeroTexture : mZeroTextures)
3130 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003131 if (zeroTexture.get() != nullptr)
3132 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003133 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003134 }
Geoff Lang9aded172017-04-05 11:07:56 -04003135 }
3136
Jamie Madillb983a4b2018-08-01 11:34:51 -04003137 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003138}
3139
3140size_t Context::getRequestableExtensionStringCount() const
3141{
3142 return mRequestableExtensionStrings.size();
3143}
3144
Jamie Madill493f9572018-05-24 19:52:15 -04003145void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003146{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003147 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003148 ASSERT(transformFeedback != nullptr);
3149 ASSERT(!transformFeedback->isPaused());
3150
Geoff Lang91002262018-12-12 16:05:24 -05003151 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mGLState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003152 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003153}
3154
3155bool Context::hasActiveTransformFeedback(GLuint program) const
3156{
3157 for (auto pair : mTransformFeedbackMap)
3158 {
3159 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3160 {
3161 return true;
3162 }
3163 }
3164 return false;
3165}
3166
Geoff Lang33f11fb2018-05-07 13:42:47 -04003167Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003168{
3169 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3170
jchen1082af6202018-06-22 10:59:52 +08003171 // Explicitly enable GL_KHR_parallel_shader_compile
3172 supportedExtensions.parallelShaderCompile = true;
3173
Geoff Langb0f917f2017-12-05 13:41:54 -05003174 if (getClientVersion() < ES_2_0)
3175 {
3176 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003177 supportedExtensions.pointSizeArray = true;
3178 supportedExtensions.textureCubeMap = true;
3179 supportedExtensions.pointSprite = true;
3180 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003181 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003182 }
3183
3184 if (getClientVersion() < ES_3_0)
3185 {
3186 // Disable ES3+ extensions
3187 supportedExtensions.colorBufferFloat = false;
3188 supportedExtensions.eglImageExternalEssl3 = false;
3189 supportedExtensions.textureNorm16 = false;
3190 supportedExtensions.multiview = false;
3191 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003192 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003193 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003194
3195 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3196 if (!supportedExtensions.sRGB)
3197 {
3198 supportedExtensions.textureSRGBDecode = false;
3199 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003200 }
3201
3202 if (getClientVersion() < ES_3_1)
3203 {
3204 // Disable ES3.1+ extensions
3205 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003206
3207 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3208 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003209 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003210 }
3211
3212 if (getClientVersion() > ES_2_0)
3213 {
3214 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3215 // supportedExtensions.sRGB = false;
3216 }
3217
3218 // Some extensions are always available because they are implemented in the GL layer.
3219 supportedExtensions.bindUniformLocation = true;
3220 supportedExtensions.vertexArrayObject = true;
3221 supportedExtensions.bindGeneratesResource = true;
3222 supportedExtensions.clientArrays = true;
3223 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003224 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003225
3226 // Enable the no error extension if the context was created with the flag.
3227 supportedExtensions.noError = mSkipValidation;
3228
3229 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003230 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003231
3232 // Explicitly enable GL_KHR_debug
3233 supportedExtensions.debug = true;
3234 supportedExtensions.maxDebugMessageLength = 1024;
3235 supportedExtensions.maxDebugLoggedMessages = 1024;
3236 supportedExtensions.maxDebugGroupStackDepth = 1024;
3237 supportedExtensions.maxLabelLength = 1024;
3238
3239 // Explicitly enable GL_ANGLE_robust_client_memory
3240 supportedExtensions.robustClientMemory = true;
3241
3242 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003243 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003244
3245 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3246 // supports it.
3247 supportedExtensions.robustBufferAccessBehavior =
3248 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3249
3250 // Enable the cache control query unconditionally.
3251 supportedExtensions.programCacheControl = true;
3252
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003253 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003254 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003255 {
3256 // GL_ANGLE_explicit_context_gles1
3257 supportedExtensions.explicitContextGles1 = true;
3258 // GL_ANGLE_explicit_context
3259 supportedExtensions.explicitContext = true;
3260 }
3261
Geoff Lang79b91402018-10-04 15:11:30 -04003262 supportedExtensions.memorySize = true;
3263
Geoff Langb0f917f2017-12-05 13:41:54 -05003264 return supportedExtensions;
3265}
3266
Geoff Lang33f11fb2018-05-07 13:42:47 -04003267void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003268{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003269 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003270
Geoff Lang33f11fb2018-05-07 13:42:47 -04003271 mSupportedExtensions = generateSupportedExtensions();
3272 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003273
3274 mLimitations = mImplementation->getNativeLimitations();
3275
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003276 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3277 if (getClientVersion() < Version(2, 0))
3278 {
3279 mCaps.maxMultitextureUnits = 4;
3280 mCaps.maxClipPlanes = 6;
3281 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003282 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3283 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3284 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003285 mCaps.minSmoothPointSize = 1.0f;
3286 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003287 mCaps.minSmoothLineWidth = 1.0f;
3288 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003289 }
3290
Luc Ferronad2ae932018-06-11 15:31:17 -04003291 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003292 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003293
Luc Ferronad2ae932018-06-11 15:31:17 -04003294 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3295
Jamie Madill0f80ed82017-09-19 00:24:56 -04003296 if (getClientVersion() < ES_3_1)
3297 {
3298 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3299 }
3300 else
3301 {
3302 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3303 }
Geoff Lang301d1612014-07-09 10:34:37 -04003304
Jiawei Shao54aafe52018-04-27 14:54:57 +08003305 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3306 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003307 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3308
Jamie Madill0f80ed82017-09-19 00:24:56 -04003309 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3310 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3311
3312 // Limit textures as well, so we can use fast bitsets with texture bindings.
3313 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003314 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3315 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3316 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3317 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003318
Jamie Madille3e680c2018-12-03 17:49:08 -05003319 LimitCap(&mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
3320
Jiawei Shaodb342272017-09-27 10:21:45 +08003321 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3322
Geoff Langc287ea62016-09-16 14:46:51 -04003323 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003324 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003325 for (const auto &extensionInfo : GetExtensionInfoMap())
3326 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003327 // If the user has requested that extensions start disabled and they are requestable,
3328 // disable them.
3329 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003330 {
3331 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3332 }
3333 }
3334
3335 // Generate texture caps
3336 updateCaps();
3337}
3338
3339void Context::updateCaps()
3340{
Geoff Lang900013c2014-07-07 11:32:19 -04003341 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003342 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003343
Jamie Madill7b62cf92017-11-02 15:20:49 -04003344 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003345 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003346 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003347 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003348
Geoff Lang0d8b7242015-09-09 14:56:53 -04003349 // Update the format caps based on the client version and extensions.
3350 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3351 // ES3.
3352 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003353 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003354 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003355 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003356 formatCaps.textureAttachment =
3357 formatCaps.textureAttachment &&
3358 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3359 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3360 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003361
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003362 // OpenGL ES does not support multisampling with non-rendererable formats
3363 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003364 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003365 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003366 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003367 {
Geoff Langd87878e2014-09-19 15:42:59 -04003368 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003369 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003370 else
3371 {
3372 // We may have limited the max samples for some required renderbuffer formats due to
3373 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3374 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3375
3376 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3377 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3378 // exception of signed and unsigned integer formats."
3379 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3380 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3381 {
3382 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3383 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3384 }
3385
3386 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003387 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003388 {
3389 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3390 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3391 // the exception that the signed and unsigned integer formats are required only to
3392 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3393 // multisamples, which must be at least one."
3394 if (formatInfo.componentType == GL_INT ||
3395 formatInfo.componentType == GL_UNSIGNED_INT)
3396 {
3397 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3398 }
3399
3400 // GLES 3.1 section 19.3.1.
3401 if (formatCaps.texturable)
3402 {
3403 if (formatInfo.depthBits > 0)
3404 {
3405 mCaps.maxDepthTextureSamples =
3406 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3407 }
3408 else if (formatInfo.redBits > 0)
3409 {
3410 mCaps.maxColorTextureSamples =
3411 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3412 }
3413 }
3414 }
3415 }
Geoff Langd87878e2014-09-19 15:42:59 -04003416
3417 if (formatCaps.texturable && formatInfo.compressed)
3418 {
Geoff Langca271392017-04-05 12:30:00 -04003419 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003420 }
3421
Geoff Langca271392017-04-05 12:30:00 -04003422 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003423 }
Jamie Madill32447362017-06-28 14:53:52 -04003424
3425 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003426 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003427 {
3428 mMemoryProgramCache = nullptr;
3429 }
Corentin Walleze4477002017-12-01 14:39:58 -05003430
3431 // Compute which buffer types are allowed
3432 mValidBufferBindings.reset();
3433 mValidBufferBindings.set(BufferBinding::ElementArray);
3434 mValidBufferBindings.set(BufferBinding::Array);
3435
3436 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3437 {
3438 mValidBufferBindings.set(BufferBinding::PixelPack);
3439 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3440 }
3441
3442 if (getClientVersion() >= ES_3_0)
3443 {
3444 mValidBufferBindings.set(BufferBinding::CopyRead);
3445 mValidBufferBindings.set(BufferBinding::CopyWrite);
3446 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3447 mValidBufferBindings.set(BufferBinding::Uniform);
3448 }
3449
3450 if (getClientVersion() >= ES_3_1)
3451 {
3452 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3453 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3454 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3455 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3456 }
jchen107ae70d82018-07-06 13:47:01 +08003457
3458 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003459
Jamie Madillef9fcd92018-11-28 14:03:59 -05003460 // Reinitialize some dirty bits that depend on extensions.
Jamie Madill132d15c2018-11-30 15:25:38 -05003461 bool robustInit = mGLState.isRobustResourceInitEnabled();
3462 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3463 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3464 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3465 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3466 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3467 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003468
Jamie Madillac66f982018-10-09 18:30:01 -04003469 // Reinitialize state cache after extension changes.
3470 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003471}
3472
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003473void Context::initWorkarounds()
3474{
Jamie Madill761b02c2017-06-23 16:27:06 -04003475 // Apply back-end workarounds.
3476 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3477
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003478 // Lose the context upon out of memory error if the application is
3479 // expecting to watch for those events.
3480 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003481
3482 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3483 {
3484 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3485 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3486 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3487 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003488}
3489
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003490// Return true if the draw is a no-op, else return false.
3491// A no-op draw occurs if the count of vertices is less than the minimum required to
3492// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3493bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3494{
3495 return count < kMinimumPrimitiveCounts[mode];
3496}
3497
3498bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3499{
3500 return (instanceCount == 0) || noopDraw(mode, count);
3501}
3502
Jamie Madill526392d2018-11-16 09:35:14 -05003503angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003504{
Geoff Langa8cb2872018-03-09 16:09:40 -05003505 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003506 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003507 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003508 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003509}
3510
Jamie Madill526392d2018-11-16 09:35:14 -05003511angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003512{
Geoff Langa8cb2872018-03-09 16:09:40 -05003513 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003514 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3515 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003516 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003517 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003518}
3519
Jamie Madill132d15c2018-11-30 15:25:38 -05003520ANGLE_INLINE angle::Result Context::prepareForDispatch()
3521{
3522 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3523 return syncDirtyBits(mComputeDirtyBits);
3524}
3525
Jamie Madill526392d2018-11-16 09:35:14 -05003526angle::Result Context::syncState(const State::DirtyBits &bitMask,
3527 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003528{
Geoff Langa8cb2872018-03-09 16:09:40 -05003529 ANGLE_TRY(syncDirtyObjects(objectMask));
3530 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003531 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003532}
3533
Jamie Madillc29968b2016-01-20 11:17:23 -05003534void Context::blitFramebuffer(GLint srcX0,
3535 GLint srcY0,
3536 GLint srcX1,
3537 GLint srcY1,
3538 GLint dstX0,
3539 GLint dstY0,
3540 GLint dstX1,
3541 GLint dstY1,
3542 GLbitfield mask,
3543 GLenum filter)
3544{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003545 if (mask == 0)
3546 {
3547 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3548 // buffers are copied.
3549 return;
3550 }
3551
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003552 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003553 ASSERT(drawFramebuffer);
3554
3555 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3556 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3557
Jamie Madillbc918e72018-03-08 09:47:21 -05003558 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003559
Jamie Madill4f6592f2018-11-27 16:37:45 -05003560 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003561}
Jamie Madillc29968b2016-01-20 11:17:23 -05003562
3563void Context::clear(GLbitfield mask)
3564{
Geoff Langd4fff502017-09-22 11:28:28 -04003565 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3566 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003567}
3568
3569void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3570{
Olli Etuaho78df3362018-10-05 16:43:27 +03003571 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3572 const FramebufferAttachment *attachment = nullptr;
3573 if (buffer == GL_DEPTH)
3574 {
3575 attachment = framebufferObject->getDepthbuffer();
3576 }
3577 if (buffer == GL_COLOR &&
3578 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3579 {
3580 attachment = framebufferObject->getColorbuffer(drawbuffer);
3581 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003582 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3583 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003584 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003585 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003586 return;
3587 }
Geoff Langd4fff502017-09-22 11:28:28 -04003588 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003589 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003590}
3591
3592void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3593{
Olli Etuaho78df3362018-10-05 16:43:27 +03003594 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3595 const FramebufferAttachment *attachment = nullptr;
3596 if (buffer == GL_COLOR &&
3597 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3598 {
3599 attachment = framebufferObject->getColorbuffer(drawbuffer);
3600 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003601 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3602 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003603 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003604 {
3605 return;
3606 }
Geoff Langd4fff502017-09-22 11:28:28 -04003607 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003608 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003609}
3610
3611void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3612{
Olli Etuaho78df3362018-10-05 16:43:27 +03003613 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3614 const FramebufferAttachment *attachment = nullptr;
3615 if (buffer == GL_STENCIL)
3616 {
3617 attachment = framebufferObject->getStencilbuffer();
3618 }
3619 if (buffer == GL_COLOR &&
3620 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3621 {
3622 attachment = framebufferObject->getColorbuffer(drawbuffer);
3623 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003624 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3625 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003626 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003627 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003628 return;
3629 }
Geoff Langd4fff502017-09-22 11:28:28 -04003630 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003631 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003632}
3633
3634void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3635{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003637 ASSERT(framebufferObject);
3638
3639 // If a buffer is not present, the clear has no effect
3640 if (framebufferObject->getDepthbuffer() == nullptr &&
3641 framebufferObject->getStencilbuffer() == nullptr)
3642 {
3643 return;
3644 }
3645
Geoff Langd4fff502017-09-22 11:28:28 -04003646 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3647 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003648}
3649
3650void Context::readPixels(GLint x,
3651 GLint y,
3652 GLsizei width,
3653 GLsizei height,
3654 GLenum format,
3655 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003656 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003657{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003658 if (width == 0 || height == 0)
3659 {
3660 return;
3661 }
3662
Jamie Madillbc918e72018-03-08 09:47:21 -05003663 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003664
Jamie Madillb6664922017-07-25 12:55:04 -04003665 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3666 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003667
3668 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003669 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003670}
3671
Brandon Jones59770802018-04-02 13:18:42 -07003672void Context::readPixelsRobust(GLint x,
3673 GLint y,
3674 GLsizei width,
3675 GLsizei height,
3676 GLenum format,
3677 GLenum type,
3678 GLsizei bufSize,
3679 GLsizei *length,
3680 GLsizei *columns,
3681 GLsizei *rows,
3682 void *pixels)
3683{
3684 readPixels(x, y, width, height, format, type, pixels);
3685}
3686
3687void Context::readnPixelsRobust(GLint x,
3688 GLint y,
3689 GLsizei width,
3690 GLsizei height,
3691 GLenum format,
3692 GLenum type,
3693 GLsizei bufSize,
3694 GLsizei *length,
3695 GLsizei *columns,
3696 GLsizei *rows,
3697 void *data)
3698{
3699 readPixels(x, y, width, height, format, type, data);
3700}
3701
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003702void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003703 GLint level,
3704 GLenum internalformat,
3705 GLint x,
3706 GLint y,
3707 GLsizei width,
3708 GLsizei height,
3709 GLint border)
3710{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003711 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003712 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003713
Jamie Madillc29968b2016-01-20 11:17:23 -05003714 Rectangle sourceArea(x, y, width, height);
3715
Jamie Madill05b35b22017-10-03 09:01:44 -04003716 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003717 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003718 ANGLE_CONTEXT_TRY(
3719 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003720}
3721
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003722void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 GLint level,
3724 GLint xoffset,
3725 GLint yoffset,
3726 GLint x,
3727 GLint y,
3728 GLsizei width,
3729 GLsizei height)
3730{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003731 if (width == 0 || height == 0)
3732 {
3733 return;
3734 }
3735
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003736 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003737 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003738
Jamie Madillc29968b2016-01-20 11:17:23 -05003739 Offset destOffset(xoffset, yoffset, 0);
3740 Rectangle sourceArea(x, y, width, height);
3741
Jamie Madill05b35b22017-10-03 09:01:44 -04003742 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003743 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003744 ANGLE_CONTEXT_TRY(
3745 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003746}
3747
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003748void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 GLint level,
3750 GLint xoffset,
3751 GLint yoffset,
3752 GLint zoffset,
3753 GLint x,
3754 GLint y,
3755 GLsizei width,
3756 GLsizei height)
3757{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003758 if (width == 0 || height == 0)
3759 {
3760 return;
3761 }
3762
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003763 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003764 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003765
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 Offset destOffset(xoffset, yoffset, zoffset);
3767 Rectangle sourceArea(x, y, width, height);
3768
Jamie Madill05b35b22017-10-03 09:01:44 -04003769 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3770 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003771 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3772 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003773}
3774
3775void Context::framebufferTexture2D(GLenum target,
3776 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003777 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003778 GLuint texture,
3779 GLint level)
3780{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003782 ASSERT(framebuffer);
3783
3784 if (texture != 0)
3785 {
3786 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003787 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003788 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003789 }
3790 else
3791 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003792 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003793 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003794
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796}
3797
3798void Context::framebufferRenderbuffer(GLenum target,
3799 GLenum attachment,
3800 GLenum renderbuffertarget,
3801 GLuint renderbuffer)
3802{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804 ASSERT(framebuffer);
3805
3806 if (renderbuffer != 0)
3807 {
3808 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003809
Jamie Madillcc129372018-04-12 09:13:18 -04003810 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003811 renderbufferObject);
3812 }
3813 else
3814 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003815 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003816 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003817
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003819}
3820
3821void Context::framebufferTextureLayer(GLenum target,
3822 GLenum attachment,
3823 GLuint texture,
3824 GLint level,
3825 GLint layer)
3826{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003828 ASSERT(framebuffer);
3829
3830 if (texture != 0)
3831 {
3832 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003833 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003834 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003835 }
3836 else
3837 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003838 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003839 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003840
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003842}
3843
Brandon Jones59770802018-04-02 13:18:42 -07003844void Context::framebufferTextureMultiviewLayered(GLenum target,
3845 GLenum attachment,
3846 GLuint texture,
3847 GLint level,
3848 GLint baseViewIndex,
3849 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003850{
Martin Radev82ef7742017-08-08 17:44:58 +03003851 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3852 ASSERT(framebuffer);
3853
3854 if (texture != 0)
3855 {
3856 Texture *textureObj = getTexture(texture);
3857
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003858 ImageIndex index;
3859 if (textureObj->getType() == TextureType::_2DArray)
3860 {
3861 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3862 }
3863 else
3864 {
3865 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3866 ASSERT(level == 0);
3867 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3868 }
Martin Radev82ef7742017-08-08 17:44:58 +03003869 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3870 numViews, baseViewIndex);
3871 }
3872 else
3873 {
3874 framebuffer->resetAttachment(this, attachment);
3875 }
3876
3877 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003878}
3879
Brandon Jones59770802018-04-02 13:18:42 -07003880void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3881 GLenum attachment,
3882 GLuint texture,
3883 GLint level,
3884 GLsizei numViews,
3885 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003886{
Martin Radev5dae57b2017-07-14 16:15:55 +03003887 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3888 ASSERT(framebuffer);
3889
3890 if (texture != 0)
3891 {
3892 Texture *textureObj = getTexture(texture);
3893
3894 ImageIndex index = ImageIndex::Make2D(level);
3895 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3896 textureObj, numViews, viewportOffsets);
3897 }
3898 else
3899 {
3900 framebuffer->resetAttachment(this, attachment);
3901 }
3902
3903 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003904}
3905
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003906void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3907{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003908 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3909 ASSERT(framebuffer);
3910
3911 if (texture != 0)
3912 {
3913 Texture *textureObj = getTexture(texture);
3914
3915 ImageIndex index = ImageIndex::MakeFromType(
3916 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3917 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3918 }
3919 else
3920 {
3921 framebuffer->resetAttachment(this, attachment);
3922 }
3923
3924 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003925}
3926
Jamie Madillc29968b2016-01-20 11:17:23 -05003927void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3928{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003929 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003930 ASSERT(framebuffer);
3931 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003932 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003933 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003934}
3935
3936void Context::readBuffer(GLenum mode)
3937{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003938 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003939 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003940 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003941}
3942
3943void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3944{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003945 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003946 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003947
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003949 ASSERT(framebuffer);
3950
3951 // The specification isn't clear what should be done when the framebuffer isn't complete.
3952 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003953 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003954}
3955
3956void Context::invalidateFramebuffer(GLenum target,
3957 GLsizei numAttachments,
3958 const GLenum *attachments)
3959{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003960 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003961 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003962
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003963 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003964 ASSERT(framebuffer);
3965
Jamie Madill427064d2018-04-13 16:20:34 -04003966 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003967 {
Jamie Madill437fa652016-05-03 15:13:24 -04003968 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003969 }
Jamie Madill437fa652016-05-03 15:13:24 -04003970
Jamie Madill4f6592f2018-11-27 16:37:45 -05003971 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003972}
3973
3974void Context::invalidateSubFramebuffer(GLenum target,
3975 GLsizei numAttachments,
3976 const GLenum *attachments,
3977 GLint x,
3978 GLint y,
3979 GLsizei width,
3980 GLsizei height)
3981{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003982 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003983 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003984
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003986 ASSERT(framebuffer);
3987
Jamie Madill427064d2018-04-13 16:20:34 -04003988 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003989 {
Jamie Madill437fa652016-05-03 15:13:24 -04003990 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003991 }
Jamie Madill437fa652016-05-03 15:13:24 -04003992
3993 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003994 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003995}
3996
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003997void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003998 GLint level,
3999 GLint internalformat,
4000 GLsizei width,
4001 GLsizei height,
4002 GLint border,
4003 GLenum format,
4004 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004005 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004006{
Jamie Madillbc918e72018-03-08 09:47:21 -05004007 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004008
4009 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004011 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4012 internalformat, size, format, type,
4013 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004014}
4015
Brandon Jones59770802018-04-02 13:18:42 -07004016void Context::texImage2DRobust(TextureTarget target,
4017 GLint level,
4018 GLint internalformat,
4019 GLsizei width,
4020 GLsizei height,
4021 GLint border,
4022 GLenum format,
4023 GLenum type,
4024 GLsizei bufSize,
4025 const void *pixels)
4026{
4027 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4028}
4029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004030void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004031 GLint level,
4032 GLint internalformat,
4033 GLsizei width,
4034 GLsizei height,
4035 GLsizei depth,
4036 GLint border,
4037 GLenum format,
4038 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004039 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004040{
Jamie Madillbc918e72018-03-08 09:47:21 -05004041 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004042
4043 Extents size(width, height, depth);
4044 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004045 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4046 NonCubeTextureTypeToTarget(target), level, internalformat,
4047 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004048}
4049
Brandon Jones59770802018-04-02 13:18:42 -07004050void Context::texImage3DRobust(TextureType target,
4051 GLint level,
4052 GLint internalformat,
4053 GLsizei width,
4054 GLsizei height,
4055 GLsizei depth,
4056 GLint border,
4057 GLenum format,
4058 GLenum type,
4059 GLsizei bufSize,
4060 const void *pixels)
4061{
4062 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4063}
4064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004065void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004066 GLint level,
4067 GLint xoffset,
4068 GLint yoffset,
4069 GLsizei width,
4070 GLsizei height,
4071 GLenum format,
4072 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004073 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004074{
4075 // Zero sized uploads are valid but no-ops
4076 if (width == 0 || height == 0)
4077 {
4078 return;
4079 }
4080
Jamie Madillbc918e72018-03-08 09:47:21 -05004081 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004082
4083 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004084 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004085
4086 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4087
Jamie Madill4f6592f2018-11-27 16:37:45 -05004088 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4089 level, area, format, type,
4090 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004091}
4092
Brandon Jones59770802018-04-02 13:18:42 -07004093void Context::texSubImage2DRobust(TextureTarget target,
4094 GLint level,
4095 GLint xoffset,
4096 GLint yoffset,
4097 GLsizei width,
4098 GLsizei height,
4099 GLenum format,
4100 GLenum type,
4101 GLsizei bufSize,
4102 const void *pixels)
4103{
4104 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4105}
4106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004107void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004108 GLint level,
4109 GLint xoffset,
4110 GLint yoffset,
4111 GLint zoffset,
4112 GLsizei width,
4113 GLsizei height,
4114 GLsizei depth,
4115 GLenum format,
4116 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004117 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004118{
4119 // Zero sized uploads are valid but no-ops
4120 if (width == 0 || height == 0 || depth == 0)
4121 {
4122 return;
4123 }
4124
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004126
4127 Box area(xoffset, yoffset, zoffset, width, height, depth);
4128 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004129
4130 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4131
Jamie Madill4f6592f2018-11-27 16:37:45 -05004132 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4133 NonCubeTextureTypeToTarget(target), level, area, format,
4134 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004135}
4136
Brandon Jones59770802018-04-02 13:18:42 -07004137void Context::texSubImage3DRobust(TextureType target,
4138 GLint level,
4139 GLint xoffset,
4140 GLint yoffset,
4141 GLint zoffset,
4142 GLsizei width,
4143 GLsizei height,
4144 GLsizei depth,
4145 GLenum format,
4146 GLenum type,
4147 GLsizei bufSize,
4148 const void *pixels)
4149{
4150 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4151 pixels);
4152}
4153
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004154void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004155 GLint level,
4156 GLenum internalformat,
4157 GLsizei width,
4158 GLsizei height,
4159 GLint border,
4160 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004161 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004162{
Jamie Madillbc918e72018-03-08 09:47:21 -05004163 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004164
4165 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004166 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004167 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4168 internalformat, size, imageSize,
4169 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004170}
4171
Brandon Jones59770802018-04-02 13:18:42 -07004172void Context::compressedTexImage2DRobust(TextureTarget target,
4173 GLint level,
4174 GLenum internalformat,
4175 GLsizei width,
4176 GLsizei height,
4177 GLint border,
4178 GLsizei imageSize,
4179 GLsizei dataSize,
4180 const GLvoid *data)
4181{
4182 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4183}
4184
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004185void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004186 GLint level,
4187 GLenum internalformat,
4188 GLsizei width,
4189 GLsizei height,
4190 GLsizei depth,
4191 GLint border,
4192 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004193 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004194{
Jamie Madillbc918e72018-03-08 09:47:21 -05004195 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004196
4197 Extents size(width, height, depth);
4198 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004199 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004200 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004201 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004202}
4203
Brandon Jones59770802018-04-02 13:18:42 -07004204void Context::compressedTexImage3DRobust(TextureType target,
4205 GLint level,
4206 GLenum internalformat,
4207 GLsizei width,
4208 GLsizei height,
4209 GLsizei depth,
4210 GLint border,
4211 GLsizei imageSize,
4212 GLsizei dataSize,
4213 const GLvoid *data)
4214{
4215 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4216 data);
4217}
4218
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004219void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004220 GLint level,
4221 GLint xoffset,
4222 GLint yoffset,
4223 GLsizei width,
4224 GLsizei height,
4225 GLenum format,
4226 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004227 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004228{
Jamie Madillbc918e72018-03-08 09:47:21 -05004229 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004230
4231 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004232 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004233 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4234 area, format, imageSize,
4235 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004236}
4237
Brandon Jones59770802018-04-02 13:18:42 -07004238void Context::compressedTexSubImage2DRobust(TextureTarget target,
4239 GLint level,
4240 GLint xoffset,
4241 GLint yoffset,
4242 GLsizei width,
4243 GLsizei height,
4244 GLenum format,
4245 GLsizei imageSize,
4246 GLsizei dataSize,
4247 const GLvoid *data)
4248{
4249 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4250 data);
4251}
4252
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004253void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004254 GLint level,
4255 GLint xoffset,
4256 GLint yoffset,
4257 GLint zoffset,
4258 GLsizei width,
4259 GLsizei height,
4260 GLsizei depth,
4261 GLenum format,
4262 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004263 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004264{
4265 // Zero sized uploads are valid but no-ops
4266 if (width == 0 || height == 0)
4267 {
4268 return;
4269 }
4270
Jamie Madillbc918e72018-03-08 09:47:21 -05004271 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004272
4273 Box area(xoffset, yoffset, zoffset, width, height, depth);
4274 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004275 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004276 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004277 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004278}
4279
Brandon Jones59770802018-04-02 13:18:42 -07004280void Context::compressedTexSubImage3DRobust(TextureType target,
4281 GLint level,
4282 GLint xoffset,
4283 GLint yoffset,
4284 GLint zoffset,
4285 GLsizei width,
4286 GLsizei height,
4287 GLsizei depth,
4288 GLenum format,
4289 GLsizei imageSize,
4290 GLsizei dataSize,
4291 const GLvoid *data)
4292{
4293 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4294 imageSize, data);
4295}
4296
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004297void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004298{
4299 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004300 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004301}
4302
Jamie Madill007530e2017-12-28 14:27:04 -05004303void Context::copyTexture(GLuint sourceId,
4304 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004305 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004306 GLuint destId,
4307 GLint destLevel,
4308 GLint internalFormat,
4309 GLenum destType,
4310 GLboolean unpackFlipY,
4311 GLboolean unpackPremultiplyAlpha,
4312 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004313{
Jamie Madillbc918e72018-03-08 09:47:21 -05004314 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004315
4316 gl::Texture *sourceTexture = getTexture(sourceId);
4317 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004318 ANGLE_CONTEXT_TRY(
4319 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4320 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4321 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004322}
4323
Jamie Madill007530e2017-12-28 14:27:04 -05004324void Context::copySubTexture(GLuint sourceId,
4325 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004326 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004327 GLuint destId,
4328 GLint destLevel,
4329 GLint xoffset,
4330 GLint yoffset,
4331 GLint x,
4332 GLint y,
4333 GLsizei width,
4334 GLsizei height,
4335 GLboolean unpackFlipY,
4336 GLboolean unpackPremultiplyAlpha,
4337 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004338{
4339 // Zero sized copies are valid but no-ops
4340 if (width == 0 || height == 0)
4341 {
4342 return;
4343 }
4344
Jamie Madillbc918e72018-03-08 09:47:21 -05004345 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004346
4347 gl::Texture *sourceTexture = getTexture(sourceId);
4348 gl::Texture *destTexture = getTexture(destId);
4349 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004350 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004351 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4352 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4353 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4354 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004355}
4356
4357void Context::copyTexture3D(GLuint sourceId,
4358 GLint sourceLevel,
4359 TextureTarget destTarget,
4360 GLuint destId,
4361 GLint destLevel,
4362 GLint internalFormat,
4363 GLenum destType,
4364 GLboolean unpackFlipY,
4365 GLboolean unpackPremultiplyAlpha,
4366 GLboolean unpackUnmultiplyAlpha)
4367{
4368 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4369
4370 Texture *sourceTexture = getTexture(sourceId);
4371 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004372 ANGLE_CONTEXT_TRY(
4373 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4374 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4375 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004376}
4377
4378void Context::copySubTexture3D(GLuint sourceId,
4379 GLint sourceLevel,
4380 TextureTarget destTarget,
4381 GLuint destId,
4382 GLint destLevel,
4383 GLint xoffset,
4384 GLint yoffset,
4385 GLint zoffset,
4386 GLint x,
4387 GLint y,
4388 GLint z,
4389 GLsizei width,
4390 GLsizei height,
4391 GLsizei depth,
4392 GLboolean unpackFlipY,
4393 GLboolean unpackPremultiplyAlpha,
4394 GLboolean unpackUnmultiplyAlpha)
4395{
4396 // Zero sized copies are valid but no-ops
4397 if (width == 0 || height == 0 || depth == 0)
4398 {
4399 return;
4400 }
4401
4402 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4403
4404 Texture *sourceTexture = getTexture(sourceId);
4405 Texture *destTexture = getTexture(destId);
4406 Offset offset(xoffset, yoffset, zoffset);
4407 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004408 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4409 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4410 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4411 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004412}
4413
Jamie Madill007530e2017-12-28 14:27:04 -05004414void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004415{
Jamie Madillbc918e72018-03-08 09:47:21 -05004416 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004417
4418 gl::Texture *sourceTexture = getTexture(sourceId);
4419 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004420 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004421}
4422
Corentin Wallez336129f2017-10-17 15:55:40 -04004423void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004424{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004425 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004426 ASSERT(buffer);
4427
Geoff Lang496c02d2016-10-20 11:38:11 -07004428 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004429}
4430
Brandon Jones59770802018-04-02 13:18:42 -07004431void Context::getBufferPointervRobust(BufferBinding target,
4432 GLenum pname,
4433 GLsizei bufSize,
4434 GLsizei *length,
4435 void **params)
4436{
4437 getBufferPointerv(target, pname, params);
4438}
4439
Corentin Wallez336129f2017-10-17 15:55:40 -04004440void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004441{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004443 ASSERT(buffer);
4444
Jamie Madill7c985f52018-11-29 18:16:17 -05004445 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004446 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004447 return nullptr;
4448 }
4449
4450 return buffer->getMapPointer();
4451}
4452
Corentin Wallez336129f2017-10-17 15:55:40 -04004453GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004456 ASSERT(buffer);
4457
4458 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004459 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004460 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004461 return GL_FALSE;
4462 }
4463
4464 return result;
4465}
4466
Corentin Wallez336129f2017-10-17 15:55:40 -04004467void *Context::mapBufferRange(BufferBinding target,
4468 GLintptr offset,
4469 GLsizeiptr length,
4470 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004471{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004472 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004473 ASSERT(buffer);
4474
Jamie Madill7c985f52018-11-29 18:16:17 -05004475 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004476 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004477 return nullptr;
4478 }
4479
4480 return buffer->getMapPointer();
4481}
4482
Corentin Wallez336129f2017-10-17 15:55:40 -04004483void Context::flushMappedBufferRange(BufferBinding /*target*/,
4484 GLintptr /*offset*/,
4485 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004486{
4487 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4488}
4489
Jamie Madill526392d2018-11-16 09:35:14 -05004490angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004491{
Geoff Langa8cb2872018-03-09 16:09:40 -05004492 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004493}
4494
Jamie Madill526392d2018-11-16 09:35:14 -05004495angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004496{
Geoff Langa8cb2872018-03-09 16:09:40 -05004497 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004498}
4499
Jamie Madill526392d2018-11-16 09:35:14 -05004500angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004501{
Geoff Langa8cb2872018-03-09 16:09:40 -05004502 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004503}
4504
Jamie Madill526392d2018-11-16 09:35:14 -05004505angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004506{
4507 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4508
4509 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4510 ANGLE_TRY(syncDirtyBits());
4511
Jamie Madill7c985f52018-11-29 18:16:17 -05004512 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004513}
4514
Jiajia Qin5451d532017-11-16 17:16:34 +08004515void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4516{
4517 UNIMPLEMENTED();
4518}
4519
Jamie Madillc20ab272016-06-09 07:20:46 -07004520void Context::activeTexture(GLenum texture)
4521{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
Jamie Madill876429b2017-04-20 15:46:24 -04004525void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004526{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004527 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004528}
4529
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004530void Context::blendEquation(GLenum mode)
4531{
4532 mGLState.setBlendEquation(mode, mode);
4533}
4534
Jamie Madillc20ab272016-06-09 07:20:46 -07004535void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4536{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538}
4539
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004540void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4541{
4542 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4543}
4544
Jamie Madillc20ab272016-06-09 07:20:46 -07004545void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
Jamie Madill876429b2017-04-20 15:46:24 -04004550void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004551{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004552 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553}
4554
Jamie Madill876429b2017-04-20 15:46:24 -04004555void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004556{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004557 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
4560void Context::clearStencil(GLint s)
4561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4566{
Geoff Lang92019432017-11-20 13:09:34 -05004567 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4568 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004571void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
4576void Context::depthFunc(GLenum func)
4577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::depthMask(GLboolean flag)
4582{
Geoff Lang92019432017-11-20 13:09:34 -05004583 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004584}
4585
Jamie Madill876429b2017-04-20 15:46:24 -04004586void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004587{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004588 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004589}
4590
4591void Context::disable(GLenum cap)
4592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004593 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004594 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004595}
4596
4597void Context::disableVertexAttribArray(GLuint index)
4598{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004599 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004600 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
4603void Context::enable(GLenum cap)
4604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004606 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
4609void Context::enableVertexAttribArray(GLuint index)
4610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004612 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
4615void Context::frontFace(GLenum mode)
4616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
4620void Context::hint(GLenum target, GLenum mode)
4621{
4622 switch (target)
4623 {
4624 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626 break;
4627
4628 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004629 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630 break;
4631
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004632 case GL_PERSPECTIVE_CORRECTION_HINT:
4633 case GL_POINT_SMOOTH_HINT:
4634 case GL_LINE_SMOOTH_HINT:
4635 case GL_FOG_HINT:
4636 mGLState.gles1().setHint(target, mode);
4637 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004638 default:
4639 UNREACHABLE();
4640 return;
4641 }
4642}
4643
4644void Context::lineWidth(GLfloat width)
4645{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004646 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004647}
4648
4649void Context::pixelStorei(GLenum pname, GLint param)
4650{
4651 switch (pname)
4652 {
4653 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004654 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004655 break;
4656
4657 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659 break;
4660
4661 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004662 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663 break;
4664
4665 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004666 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668 break;
4669
4670 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004671 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004673 break;
4674
4675 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004676 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678 break;
4679
4680 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004681 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004682 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683 break;
4684
4685 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004686 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004687 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688 break;
4689
4690 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004691 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004692 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004693 break;
4694
4695 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004696 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698 break;
4699
4700 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004701 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004703 break;
4704
4705 default:
4706 UNREACHABLE();
4707 return;
4708 }
4709}
4710
4711void Context::polygonOffset(GLfloat factor, GLfloat units)
4712{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004713 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004714}
4715
Jamie Madill876429b2017-04-20 15:46:24 -04004716void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004717{
Geoff Lang92019432017-11-20 13:09:34 -05004718 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004719}
4720
Jiawei Shaodb342272017-09-27 10:21:45 +08004721void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4722{
4723 mGLState.setSampleMaskParams(maskNumber, mask);
4724}
4725
Jamie Madillc20ab272016-06-09 07:20:46 -07004726void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4727{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004728 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004729}
4730
4731void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4732{
4733 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4734 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004735 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004736 }
4737
4738 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4739 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004740 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004741 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004742
4743 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004744}
4745
4746void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4747{
4748 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4749 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004750 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004751 }
4752
4753 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4754 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004755 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004756 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004757
4758 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004759}
4760
4761void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4762{
4763 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4764 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004765 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004766 }
4767
4768 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004770 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004771 }
4772}
4773
4774void Context::vertexAttrib1f(GLuint index, GLfloat x)
4775{
4776 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004777 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004778 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004779}
4780
4781void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4782{
4783 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004784 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004785 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004786}
4787
4788void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4789{
4790 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004791 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004792 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004793}
4794
4795void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4796{
4797 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004798 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004799 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004800}
4801
4802void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4803{
4804 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004805 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004806 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004807}
4808
4809void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4810{
4811 GLfloat vals[4] = {values[0], values[1], values[2], 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::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4817{
4818 GLfloat vals[4] = {x, y, z, w};
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::vertexAttrib4fv(GLuint index, const GLfloat *values)
4824{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004825 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004826 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004827}
4828
4829void Context::vertexAttribPointer(GLuint index,
4830 GLint size,
4831 GLenum type,
4832 GLboolean normalized,
4833 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004834 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004835{
Corentin Wallez336129f2017-10-17 15:55:40 -04004836 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004837 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004838 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004839}
4840
Shao80957d92017-02-20 21:25:59 +08004841void Context::vertexAttribFormat(GLuint attribIndex,
4842 GLint size,
4843 GLenum type,
4844 GLboolean normalized,
4845 GLuint relativeOffset)
4846{
Geoff Lang92019432017-11-20 13:09:34 -05004847 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004848 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004849 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004850}
4851
4852void Context::vertexAttribIFormat(GLuint attribIndex,
4853 GLint size,
4854 GLenum type,
4855 GLuint relativeOffset)
4856{
4857 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004858 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004859}
4860
4861void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4862{
Shaodde78e82017-05-22 14:13:27 +08004863 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004864 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004865}
4866
Jiajia Qin5451d532017-11-16 17:16:34 +08004867void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004868{
4869 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004870 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004871}
4872
Jamie Madillc20ab272016-06-09 07:20:46 -07004873void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4874{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004875 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004876}
4877
4878void Context::vertexAttribIPointer(GLuint index,
4879 GLint size,
4880 GLenum type,
4881 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004882 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004883{
Corentin Wallez336129f2017-10-17 15:55:40 -04004884 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4885 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004886 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004887}
4888
4889void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4890{
4891 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004892 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004893 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004894}
4895
4896void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4897{
4898 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004899 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004900 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004901}
4902
4903void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4904{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004905 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004906 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004907}
4908
4909void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4910{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004911 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004912 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004913}
4914
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004915void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4916{
4917 const VertexAttribCurrentValueData &currentValues =
4918 getGLState().getVertexAttribCurrentValue(index);
4919 const VertexArray *vao = getGLState().getVertexArray();
4920 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4921 currentValues, pname, params);
4922}
4923
Brandon Jones59770802018-04-02 13:18:42 -07004924void Context::getVertexAttribivRobust(GLuint index,
4925 GLenum pname,
4926 GLsizei bufSize,
4927 GLsizei *length,
4928 GLint *params)
4929{
4930 getVertexAttribiv(index, pname, params);
4931}
4932
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004933void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4934{
4935 const VertexAttribCurrentValueData &currentValues =
4936 getGLState().getVertexAttribCurrentValue(index);
4937 const VertexArray *vao = getGLState().getVertexArray();
4938 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4939 currentValues, pname, params);
4940}
4941
Brandon Jones59770802018-04-02 13:18:42 -07004942void Context::getVertexAttribfvRobust(GLuint index,
4943 GLenum pname,
4944 GLsizei bufSize,
4945 GLsizei *length,
4946 GLfloat *params)
4947{
4948 getVertexAttribfv(index, pname, params);
4949}
4950
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004951void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4952{
4953 const VertexAttribCurrentValueData &currentValues =
4954 getGLState().getVertexAttribCurrentValue(index);
4955 const VertexArray *vao = getGLState().getVertexArray();
4956 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4957 currentValues, pname, params);
4958}
4959
Brandon Jones59770802018-04-02 13:18:42 -07004960void Context::getVertexAttribIivRobust(GLuint index,
4961 GLenum pname,
4962 GLsizei bufSize,
4963 GLsizei *length,
4964 GLint *params)
4965{
4966 getVertexAttribIiv(index, pname, params);
4967}
4968
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004969void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4970{
4971 const VertexAttribCurrentValueData &currentValues =
4972 getGLState().getVertexAttribCurrentValue(index);
4973 const VertexArray *vao = getGLState().getVertexArray();
4974 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4975 currentValues, pname, params);
4976}
4977
Brandon Jones59770802018-04-02 13:18:42 -07004978void Context::getVertexAttribIuivRobust(GLuint index,
4979 GLenum pname,
4980 GLsizei bufSize,
4981 GLsizei *length,
4982 GLuint *params)
4983{
4984 getVertexAttribIuiv(index, pname, params);
4985}
4986
Jamie Madill876429b2017-04-20 15:46:24 -04004987void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004988{
4989 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4990 QueryVertexAttribPointerv(attrib, pname, pointer);
4991}
4992
Brandon Jones59770802018-04-02 13:18:42 -07004993void Context::getVertexAttribPointervRobust(GLuint index,
4994 GLenum pname,
4995 GLsizei bufSize,
4996 GLsizei *length,
4997 void **pointer)
4998{
4999 getVertexAttribPointerv(index, pname, pointer);
5000}
5001
Jamie Madillc20ab272016-06-09 07:20:46 -07005002void Context::debugMessageControl(GLenum source,
5003 GLenum type,
5004 GLenum severity,
5005 GLsizei count,
5006 const GLuint *ids,
5007 GLboolean enabled)
5008{
5009 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005010 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005011 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005012}
5013
5014void Context::debugMessageInsert(GLenum source,
5015 GLenum type,
5016 GLuint id,
5017 GLenum severity,
5018 GLsizei length,
5019 const GLchar *buf)
5020{
5021 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005022 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005023}
5024
5025void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5026{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005027 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005028}
5029
5030GLuint Context::getDebugMessageLog(GLuint count,
5031 GLsizei bufSize,
5032 GLenum *sources,
5033 GLenum *types,
5034 GLuint *ids,
5035 GLenum *severities,
5036 GLsizei *lengths,
5037 GLchar *messageLog)
5038{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005039 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5040 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005041}
5042
5043void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5044{
5045 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005046 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005047 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005048}
5049
5050void Context::popDebugGroup()
5051{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005052 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005053 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005054}
5055
Corentin Wallez336129f2017-10-17 15:55:40 -04005056void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005057{
5058 Buffer *buffer = mGLState.getTargetBuffer(target);
5059 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005060 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005061}
5062
Corentin Wallez336129f2017-10-17 15:55:40 -04005063void Context::bufferSubData(BufferBinding target,
5064 GLintptr offset,
5065 GLsizeiptr size,
5066 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005067{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005068 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005069 {
5070 return;
5071 }
5072
5073 Buffer *buffer = mGLState.getTargetBuffer(target);
5074 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005075 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005076}
5077
Jamie Madillef300b12016-10-07 15:12:09 -04005078void Context::attachShader(GLuint program, GLuint shader)
5079{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005080 Program *programObject = mState.mShaderPrograms->getProgram(program);
5081 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005082 ASSERT(programObject && shaderObject);
5083 programObject->attachShader(shaderObject);
5084}
5085
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005086const Workarounds &Context::getWorkarounds() const
5087{
5088 return mWorkarounds;
5089}
5090
Corentin Wallez336129f2017-10-17 15:55:40 -04005091void Context::copyBufferSubData(BufferBinding readTarget,
5092 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005093 GLintptr readOffset,
5094 GLintptr writeOffset,
5095 GLsizeiptr size)
5096{
5097 // if size is zero, the copy is a successful no-op
5098 if (size == 0)
5099 {
5100 return;
5101 }
5102
5103 // TODO(jmadill): cache these.
5104 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5105 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5106
Jamie Madill4f6592f2018-11-27 16:37:45 -05005107 ANGLE_CONTEXT_TRY(
5108 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005109}
5110
Jamie Madill01a80ee2016-11-07 12:06:18 -05005111void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5112{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005113 // Ideally we could share the program query with the validation layer if possible.
5114 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005115 ASSERT(programObject);
5116 programObject->bindAttributeLocation(index, name);
5117}
5118
Corentin Wallez336129f2017-10-17 15:55:40 -04005119void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005120{
Corentin Wallez336129f2017-10-17 15:55:40 -04005121 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5122 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005123 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005124}
5125
Corentin Wallez336129f2017-10-17 15:55:40 -04005126void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005127{
5128 bindBufferRange(target, index, buffer, 0, 0);
5129}
5130
Corentin Wallez336129f2017-10-17 15:55:40 -04005131void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005132 GLuint index,
5133 GLuint buffer,
5134 GLintptr offset,
5135 GLsizeiptr size)
5136{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005137 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
Geoff Lang91002262018-12-12 16:05:24 -05005138 ANGLE_CONTEXT_TRY(mGLState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005139 if (target == BufferBinding::Uniform)
5140 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005141 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005142 mStateCache.onUniformBufferStateChange(this);
5143 }
5144 else
5145 {
5146 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005147 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005148}
5149
Jamie Madill01a80ee2016-11-07 12:06:18 -05005150void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5151{
5152 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5153 {
5154 bindReadFramebuffer(framebuffer);
5155 }
5156
5157 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5158 {
5159 bindDrawFramebuffer(framebuffer);
5160 }
5161}
5162
5163void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5164{
5165 ASSERT(target == GL_RENDERBUFFER);
5166 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005167 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005168 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005169}
5170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005171void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005172 GLsizei samples,
5173 GLenum internalformat,
5174 GLsizei width,
5175 GLsizei height,
5176 GLboolean fixedsamplelocations)
5177{
5178 Extents size(width, height, 1);
5179 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005180 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5181 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005182}
5183
Olli Etuaho89664842018-08-24 14:45:36 +03005184void Context::texStorage3DMultisample(TextureType target,
5185 GLsizei samples,
5186 GLenum internalformat,
5187 GLsizei width,
5188 GLsizei height,
5189 GLsizei depth,
5190 GLboolean fixedsamplelocations)
5191{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005192 Extents size(width, height, depth);
5193 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005194 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5195 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005196}
5197
JiangYizhoubddc46b2016-12-09 09:50:51 +08005198void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5199{
JiangYizhou5b03f472017-01-09 10:22:53 +08005200 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5201 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005202 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005203 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005204
5205 switch (pname)
5206 {
5207 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005208 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005209 break;
5210 default:
5211 UNREACHABLE();
5212 }
5213}
5214
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005215void Context::getMultisamplefvRobust(GLenum pname,
5216 GLuint index,
5217 GLsizei bufSize,
5218 GLsizei *length,
5219 GLfloat *val)
5220{
5221 UNIMPLEMENTED();
5222}
5223
Jamie Madille8fb6402017-02-14 17:56:40 -05005224void Context::renderbufferStorage(GLenum target,
5225 GLenum internalformat,
5226 GLsizei width,
5227 GLsizei height)
5228{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005229 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5230 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5231
Jamie Madille8fb6402017-02-14 17:56:40 -05005232 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005233 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005234}
5235
5236void Context::renderbufferStorageMultisample(GLenum target,
5237 GLsizei samples,
5238 GLenum internalformat,
5239 GLsizei width,
5240 GLsizei height)
5241{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005242 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5243 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005244
5245 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005246 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005247 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005248}
5249
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005250void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5251{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005252 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005253 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005254}
5255
JiangYizhoue18e6392017-02-20 10:32:23 +08005256void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5257{
5258 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5259 QueryFramebufferParameteriv(framebuffer, pname, params);
5260}
5261
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005262void Context::getFramebufferParameterivRobust(GLenum target,
5263 GLenum pname,
5264 GLsizei bufSize,
5265 GLsizei *length,
5266 GLint *params)
5267{
5268 UNIMPLEMENTED();
5269}
5270
Jiajia Qin5451d532017-11-16 17:16:34 +08005271void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005272{
5273 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005274 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005275}
5276
Jamie Madilldec86232018-07-11 09:01:18 -04005277bool Context::getScratchBuffer(size_t requstedSizeBytes,
5278 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005279{
Jamie Madilldec86232018-07-11 09:01:18 -04005280 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005281}
5282
Jamie Madilldec86232018-07-11 09:01:18 -04005283bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5284 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005285{
Jamie Madilldec86232018-07-11 09:01:18 -04005286 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005287}
5288
Xinghua Cao2b396592017-03-29 15:36:04 +08005289void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5290{
5291 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5292 {
5293 return;
5294 }
5295
Xinghua Cao10a4d432017-11-28 14:46:26 +08005296 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005297 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005298}
5299
Jiajia Qin5451d532017-11-16 17:16:34 +08005300void Context::dispatchComputeIndirect(GLintptr indirect)
5301{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005302 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005303 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005304}
5305
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005306void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005307 GLsizei levels,
5308 GLenum internalFormat,
5309 GLsizei width,
5310 GLsizei height)
5311{
5312 Extents size(width, height, 1);
5313 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005314 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005315}
5316
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005317void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005318 GLsizei levels,
5319 GLenum internalFormat,
5320 GLsizei width,
5321 GLsizei height,
5322 GLsizei depth)
5323{
5324 Extents size(width, height, depth);
5325 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005326 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005327}
5328
Jiajia Qin5451d532017-11-16 17:16:34 +08005329void Context::memoryBarrier(GLbitfield barriers)
5330{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005331 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005332}
5333
5334void Context::memoryBarrierByRegion(GLbitfield barriers)
5335{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005336 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005337}
5338
Austin Eng1bf18ce2018-10-19 15:34:02 -07005339void Context::multiDrawArrays(PrimitiveMode mode,
5340 const GLint *firsts,
5341 const GLsizei *counts,
5342 GLsizei drawcount)
5343{
5344 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5345 Program *programObject = mGLState.getLinkedProgram(this);
5346 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5347 if (hasDrawID)
5348 {
5349 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5350 {
5351 if (noopDraw(mode, counts[drawID]))
5352 {
5353 continue;
5354 }
5355 programObject->setDrawIDUniform(drawID);
5356 ANGLE_CONTEXT_TRY(
5357 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005358 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005359 }
5360 }
5361 else
5362 {
5363 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5364 {
5365 if (noopDraw(mode, counts[drawID]))
5366 {
5367 continue;
5368 }
5369 ANGLE_CONTEXT_TRY(
5370 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005371 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005372 }
5373 }
5374}
5375
5376void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5377 const GLint *firsts,
5378 const GLsizei *counts,
5379 const GLsizei *instanceCounts,
5380 GLsizei drawcount)
5381{
5382 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5383 Program *programObject = mGLState.getLinkedProgram(this);
5384 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5385 if (hasDrawID)
5386 {
5387 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5388 {
5389 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5390 {
5391 continue;
5392 }
5393 programObject->setDrawIDUniform(drawID);
5394 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5395 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005396 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005397 }
5398 }
5399 else
5400 {
5401 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5402 {
5403 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5404 {
5405 continue;
5406 }
5407 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5408 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005409 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005410 }
5411 }
5412}
5413
5414void Context::multiDrawElements(PrimitiveMode mode,
5415 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005416 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005417 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005418 GLsizei drawcount)
5419{
5420 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5421 Program *programObject = mGLState.getLinkedProgram(this);
5422 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5423 if (hasDrawID)
5424 {
5425 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5426 {
5427 if (noopDraw(mode, counts[drawID]))
5428 {
5429 continue;
5430 }
5431 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005432 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005433 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005434 }
5435 }
5436 else
5437 {
5438 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5439 {
5440 if (noopDraw(mode, counts[drawID]))
5441 {
5442 continue;
5443 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005444 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005445 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005446 }
5447 }
5448}
5449
5450void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5451 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005452 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005453 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005454 const GLsizei *instanceCounts,
5455 GLsizei drawcount)
5456{
5457 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5458 Program *programObject = mGLState.getLinkedProgram(this);
5459 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5460 if (hasDrawID)
5461 {
5462 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5463 {
5464 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5465 {
5466 continue;
5467 }
5468 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005469 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005470 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005471 }
5472 }
5473 else
5474 {
5475 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5476 {
5477 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5478 {
5479 continue;
5480 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005481 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005482 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005483 }
5484 }
5485}
5486
Jamie Madillc1d770e2017-04-13 17:31:24 -04005487GLenum Context::checkFramebufferStatus(GLenum target)
5488{
5489 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5490 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005491 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005492}
5493
5494void Context::compileShader(GLuint shader)
5495{
5496 Shader *shaderObject = GetValidShader(this, shader);
5497 if (!shaderObject)
5498 {
5499 return;
5500 }
5501 shaderObject->compile(this);
5502}
5503
5504void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5505{
5506 for (int i = 0; i < n; i++)
5507 {
5508 deleteBuffer(buffers[i]);
5509 }
5510}
5511
5512void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5513{
5514 for (int i = 0; i < n; i++)
5515 {
5516 if (framebuffers[i] != 0)
5517 {
5518 deleteFramebuffer(framebuffers[i]);
5519 }
5520 }
5521}
5522
5523void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5524{
5525 for (int i = 0; i < n; i++)
5526 {
5527 deleteRenderbuffer(renderbuffers[i]);
5528 }
5529}
5530
5531void Context::deleteTextures(GLsizei n, const GLuint *textures)
5532{
5533 for (int i = 0; i < n; i++)
5534 {
5535 if (textures[i] != 0)
5536 {
5537 deleteTexture(textures[i]);
5538 }
5539 }
5540}
5541
5542void Context::detachShader(GLuint program, GLuint shader)
5543{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005544 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005545 ASSERT(programObject);
5546
5547 Shader *shaderObject = getShader(shader);
5548 ASSERT(shaderObject);
5549
5550 programObject->detachShader(this, shaderObject);
5551}
5552
5553void Context::genBuffers(GLsizei n, GLuint *buffers)
5554{
5555 for (int i = 0; i < n; i++)
5556 {
5557 buffers[i] = createBuffer();
5558 }
5559}
5560
5561void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5562{
5563 for (int i = 0; i < n; i++)
5564 {
5565 framebuffers[i] = createFramebuffer();
5566 }
5567}
5568
5569void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5570{
5571 for (int i = 0; i < n; i++)
5572 {
5573 renderbuffers[i] = createRenderbuffer();
5574 }
5575}
5576
5577void Context::genTextures(GLsizei n, GLuint *textures)
5578{
5579 for (int i = 0; i < n; i++)
5580 {
5581 textures[i] = createTexture();
5582 }
5583}
5584
5585void Context::getActiveAttrib(GLuint program,
5586 GLuint index,
5587 GLsizei bufsize,
5588 GLsizei *length,
5589 GLint *size,
5590 GLenum *type,
5591 GLchar *name)
5592{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005593 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594 ASSERT(programObject);
5595 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5596}
5597
5598void Context::getActiveUniform(GLuint program,
5599 GLuint index,
5600 GLsizei bufsize,
5601 GLsizei *length,
5602 GLint *size,
5603 GLenum *type,
5604 GLchar *name)
5605{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005606 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005607 ASSERT(programObject);
5608 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5609}
5610
5611void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5612{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005613 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005614 ASSERT(programObject);
5615 programObject->getAttachedShaders(maxcount, count, shaders);
5616}
5617
5618GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5619{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005620 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005621 ASSERT(programObject);
5622 return programObject->getAttributeLocation(name);
5623}
5624
5625void Context::getBooleanv(GLenum pname, GLboolean *params)
5626{
5627 GLenum nativeType;
5628 unsigned int numParams = 0;
5629 getQueryParameterInfo(pname, &nativeType, &numParams);
5630
5631 if (nativeType == GL_BOOL)
5632 {
5633 getBooleanvImpl(pname, params);
5634 }
5635 else
5636 {
5637 CastStateValues(this, nativeType, pname, numParams, params);
5638 }
5639}
5640
Brandon Jones59770802018-04-02 13:18:42 -07005641void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5642{
5643 getBooleanv(pname, params);
5644}
5645
Jamie Madillc1d770e2017-04-13 17:31:24 -04005646void Context::getFloatv(GLenum pname, GLfloat *params)
5647{
5648 GLenum nativeType;
5649 unsigned int numParams = 0;
5650 getQueryParameterInfo(pname, &nativeType, &numParams);
5651
5652 if (nativeType == GL_FLOAT)
5653 {
5654 getFloatvImpl(pname, params);
5655 }
5656 else
5657 {
5658 CastStateValues(this, nativeType, pname, numParams, params);
5659 }
5660}
5661
Brandon Jones59770802018-04-02 13:18:42 -07005662void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5663{
5664 getFloatv(pname, params);
5665}
5666
Jamie Madillc1d770e2017-04-13 17:31:24 -04005667void Context::getIntegerv(GLenum pname, GLint *params)
5668{
5669 GLenum nativeType;
5670 unsigned int numParams = 0;
5671 getQueryParameterInfo(pname, &nativeType, &numParams);
5672
5673 if (nativeType == GL_INT)
5674 {
5675 getIntegervImpl(pname, params);
5676 }
5677 else
5678 {
5679 CastStateValues(this, nativeType, pname, numParams, params);
5680 }
5681}
5682
Brandon Jones59770802018-04-02 13:18:42 -07005683void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5684{
5685 getIntegerv(pname, data);
5686}
5687
Jamie Madillc1d770e2017-04-13 17:31:24 -04005688void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5689{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005690 // Don't resolve link if checking the link completion status.
5691 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5692 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005693 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005694 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695}
5696
Brandon Jones59770802018-04-02 13:18:42 -07005697void Context::getProgramivRobust(GLuint program,
5698 GLenum pname,
5699 GLsizei bufSize,
5700 GLsizei *length,
5701 GLint *params)
5702{
5703 getProgramiv(program, pname, params);
5704}
5705
Jiajia Qin5451d532017-11-16 17:16:34 +08005706void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5707{
5708 UNIMPLEMENTED();
5709}
5710
Jamie Madillbe849e42017-05-02 15:49:00 -04005711void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005712{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005713 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005714 ASSERT(programObject);
5715 programObject->getInfoLog(bufsize, length, infolog);
5716}
5717
Jiajia Qin5451d532017-11-16 17:16:34 +08005718void Context::getProgramPipelineInfoLog(GLuint pipeline,
5719 GLsizei bufSize,
5720 GLsizei *length,
5721 GLchar *infoLog)
5722{
5723 UNIMPLEMENTED();
5724}
5725
Jamie Madillc1d770e2017-04-13 17:31:24 -04005726void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5727{
5728 Shader *shaderObject = getShader(shader);
5729 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005730 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731}
5732
Brandon Jones59770802018-04-02 13:18:42 -07005733void Context::getShaderivRobust(GLuint shader,
5734 GLenum pname,
5735 GLsizei bufSize,
5736 GLsizei *length,
5737 GLint *params)
5738{
5739 getShaderiv(shader, pname, params);
5740}
5741
Jamie Madillc1d770e2017-04-13 17:31:24 -04005742void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5743{
5744 Shader *shaderObject = getShader(shader);
5745 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005746 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005747}
5748
5749void Context::getShaderPrecisionFormat(GLenum shadertype,
5750 GLenum precisiontype,
5751 GLint *range,
5752 GLint *precision)
5753{
5754 // TODO(jmadill): Compute shaders.
5755
5756 switch (shadertype)
5757 {
5758 case GL_VERTEX_SHADER:
5759 switch (precisiontype)
5760 {
5761 case GL_LOW_FLOAT:
5762 mCaps.vertexLowpFloat.get(range, precision);
5763 break;
5764 case GL_MEDIUM_FLOAT:
5765 mCaps.vertexMediumpFloat.get(range, precision);
5766 break;
5767 case GL_HIGH_FLOAT:
5768 mCaps.vertexHighpFloat.get(range, precision);
5769 break;
5770
5771 case GL_LOW_INT:
5772 mCaps.vertexLowpInt.get(range, precision);
5773 break;
5774 case GL_MEDIUM_INT:
5775 mCaps.vertexMediumpInt.get(range, precision);
5776 break;
5777 case GL_HIGH_INT:
5778 mCaps.vertexHighpInt.get(range, precision);
5779 break;
5780
5781 default:
5782 UNREACHABLE();
5783 return;
5784 }
5785 break;
5786
5787 case GL_FRAGMENT_SHADER:
5788 switch (precisiontype)
5789 {
5790 case GL_LOW_FLOAT:
5791 mCaps.fragmentLowpFloat.get(range, precision);
5792 break;
5793 case GL_MEDIUM_FLOAT:
5794 mCaps.fragmentMediumpFloat.get(range, precision);
5795 break;
5796 case GL_HIGH_FLOAT:
5797 mCaps.fragmentHighpFloat.get(range, precision);
5798 break;
5799
5800 case GL_LOW_INT:
5801 mCaps.fragmentLowpInt.get(range, precision);
5802 break;
5803 case GL_MEDIUM_INT:
5804 mCaps.fragmentMediumpInt.get(range, precision);
5805 break;
5806 case GL_HIGH_INT:
5807 mCaps.fragmentHighpInt.get(range, precision);
5808 break;
5809
5810 default:
5811 UNREACHABLE();
5812 return;
5813 }
5814 break;
5815
5816 default:
5817 UNREACHABLE();
5818 return;
5819 }
5820}
5821
5822void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5823{
5824 Shader *shaderObject = getShader(shader);
5825 ASSERT(shaderObject);
5826 shaderObject->getSource(bufsize, length, source);
5827}
5828
5829void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5830{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005831 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005832 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005833 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005834}
5835
Brandon Jones59770802018-04-02 13:18:42 -07005836void Context::getUniformfvRobust(GLuint program,
5837 GLint location,
5838 GLsizei bufSize,
5839 GLsizei *length,
5840 GLfloat *params)
5841{
5842 getUniformfv(program, location, params);
5843}
5844
Jamie Madillc1d770e2017-04-13 17:31:24 -04005845void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5846{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005847 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005848 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005849 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005850}
5851
Brandon Jones59770802018-04-02 13:18:42 -07005852void Context::getUniformivRobust(GLuint program,
5853 GLint location,
5854 GLsizei bufSize,
5855 GLsizei *length,
5856 GLint *params)
5857{
5858 getUniformiv(program, location, params);
5859}
5860
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5862{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005863 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005864 ASSERT(programObject);
5865 return programObject->getUniformLocation(name);
5866}
5867
5868GLboolean Context::isBuffer(GLuint buffer)
5869{
5870 if (buffer == 0)
5871 {
5872 return GL_FALSE;
5873 }
5874
5875 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5876}
5877
5878GLboolean Context::isEnabled(GLenum cap)
5879{
5880 return mGLState.getEnableFeature(cap);
5881}
5882
5883GLboolean Context::isFramebuffer(GLuint framebuffer)
5884{
5885 if (framebuffer == 0)
5886 {
5887 return GL_FALSE;
5888 }
5889
5890 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5891}
5892
5893GLboolean Context::isProgram(GLuint program)
5894{
5895 if (program == 0)
5896 {
5897 return GL_FALSE;
5898 }
5899
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005900 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901}
5902
5903GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5904{
5905 if (renderbuffer == 0)
5906 {
5907 return GL_FALSE;
5908 }
5909
5910 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5911}
5912
5913GLboolean Context::isShader(GLuint shader)
5914{
5915 if (shader == 0)
5916 {
5917 return GL_FALSE;
5918 }
5919
5920 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5921}
5922
5923GLboolean Context::isTexture(GLuint texture)
5924{
5925 if (texture == 0)
5926 {
5927 return GL_FALSE;
5928 }
5929
5930 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5931}
5932
5933void Context::linkProgram(GLuint program)
5934{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005935 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005936 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005937 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005938
5939 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5940 // don't need to worry that:
5941 // 1. Draw calls after link use the new executable code or the old one depending on the link
5942 // result.
5943 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5944 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5945 // ProgramD3D.
5946 if (programObject->isInUse())
5947 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005948 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005949 if (programObject->isLinked())
5950 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04005951 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005952 }
jchen107ae70d82018-07-06 13:47:01 +08005953 mStateCache.onProgramExecutableChange(this);
5954 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005955}
5956
5957void Context::releaseShaderCompiler()
5958{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005959 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005960}
5961
5962void Context::shaderBinary(GLsizei n,
5963 const GLuint *shaders,
5964 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005965 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005966 GLsizei length)
5967{
5968 // No binary shader formats are supported.
5969 UNIMPLEMENTED();
5970}
5971
Olli Etuaho0ca09752018-09-24 11:00:50 +03005972void Context::bindFragDataLocationIndexed(GLuint program,
5973 GLuint colorNumber,
5974 GLuint index,
5975 const char *name)
5976{
5977 Program *programObject = getProgramNoResolveLink(program);
5978 programObject->bindFragmentOutputLocation(colorNumber, name);
5979 programObject->bindFragmentOutputIndex(index, name);
5980}
5981
5982void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5983{
5984 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5985}
5986
5987int Context::getFragDataIndex(GLuint program, const char *name)
5988{
5989 Program *programObject = getProgramResolveLink(program);
5990 return programObject->getFragDataIndex(name);
5991}
5992
5993int Context::getProgramResourceLocationIndex(GLuint program,
5994 GLenum programInterface,
5995 const char *name)
5996{
5997 Program *programObject = getProgramResolveLink(program);
5998 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5999 return programObject->getFragDataIndex(name);
6000}
6001
Jamie Madillc1d770e2017-04-13 17:31:24 -04006002void Context::shaderSource(GLuint shader,
6003 GLsizei count,
6004 const GLchar *const *string,
6005 const GLint *length)
6006{
6007 Shader *shaderObject = getShader(shader);
6008 ASSERT(shaderObject);
6009 shaderObject->setSource(count, string, length);
6010}
6011
6012void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6013{
6014 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6015}
6016
6017void Context::stencilMask(GLuint mask)
6018{
6019 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6020}
6021
6022void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6023{
6024 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6025}
6026
6027void Context::uniform1f(GLint location, GLfloat x)
6028{
6029 Program *program = mGLState.getProgram();
6030 program->setUniform1fv(location, 1, &x);
6031}
6032
6033void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6034{
6035 Program *program = mGLState.getProgram();
6036 program->setUniform1fv(location, count, v);
6037}
6038
Jamie Madill7e4eff12018-08-08 15:49:26 -04006039void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006040{
Jamie Madille3e680c2018-12-03 17:49:08 -05006041 program->setUniform1iv(this, location, count, v);
6042}
6043
6044void Context::onSamplerUniformChange(size_t textureUnitIndex)
6045{
6046 mGLState.onActiveTextureChange(this, textureUnitIndex);
6047 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048}
6049
Jamie Madill7e4eff12018-08-08 15:49:26 -04006050void Context::uniform1i(GLint location, GLint x)
6051{
6052 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6053}
6054
Jamie Madillc1d770e2017-04-13 17:31:24 -04006055void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6056{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006057 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006058}
6059
6060void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6061{
6062 GLfloat xy[2] = {x, y};
6063 Program *program = mGLState.getProgram();
6064 program->setUniform2fv(location, 1, xy);
6065}
6066
6067void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6068{
6069 Program *program = mGLState.getProgram();
6070 program->setUniform2fv(location, count, v);
6071}
6072
6073void Context::uniform2i(GLint location, GLint x, GLint y)
6074{
6075 GLint xy[2] = {x, y};
6076 Program *program = mGLState.getProgram();
6077 program->setUniform2iv(location, 1, xy);
6078}
6079
6080void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6081{
6082 Program *program = mGLState.getProgram();
6083 program->setUniform2iv(location, count, v);
6084}
6085
6086void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6087{
6088 GLfloat xyz[3] = {x, y, z};
6089 Program *program = mGLState.getProgram();
6090 program->setUniform3fv(location, 1, xyz);
6091}
6092
6093void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6094{
6095 Program *program = mGLState.getProgram();
6096 program->setUniform3fv(location, count, v);
6097}
6098
6099void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6100{
6101 GLint xyz[3] = {x, y, z};
6102 Program *program = mGLState.getProgram();
6103 program->setUniform3iv(location, 1, xyz);
6104}
6105
6106void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6107{
6108 Program *program = mGLState.getProgram();
6109 program->setUniform3iv(location, count, v);
6110}
6111
6112void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6113{
6114 GLfloat xyzw[4] = {x, y, z, w};
6115 Program *program = mGLState.getProgram();
6116 program->setUniform4fv(location, 1, xyzw);
6117}
6118
6119void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6120{
6121 Program *program = mGLState.getProgram();
6122 program->setUniform4fv(location, count, v);
6123}
6124
6125void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6126{
6127 GLint xyzw[4] = {x, y, z, w};
6128 Program *program = mGLState.getProgram();
6129 program->setUniform4iv(location, 1, xyzw);
6130}
6131
6132void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6133{
6134 Program *program = mGLState.getProgram();
6135 program->setUniform4iv(location, count, v);
6136}
6137
6138void Context::uniformMatrix2fv(GLint location,
6139 GLsizei count,
6140 GLboolean transpose,
6141 const GLfloat *value)
6142{
6143 Program *program = mGLState.getProgram();
6144 program->setUniformMatrix2fv(location, count, transpose, value);
6145}
6146
6147void Context::uniformMatrix3fv(GLint location,
6148 GLsizei count,
6149 GLboolean transpose,
6150 const GLfloat *value)
6151{
6152 Program *program = mGLState.getProgram();
6153 program->setUniformMatrix3fv(location, count, transpose, value);
6154}
6155
6156void Context::uniformMatrix4fv(GLint location,
6157 GLsizei count,
6158 GLboolean transpose,
6159 const GLfloat *value)
6160{
6161 Program *program = mGLState.getProgram();
6162 program->setUniformMatrix4fv(location, count, transpose, value);
6163}
6164
6165void Context::validateProgram(GLuint program)
6166{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006167 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006168 ASSERT(programObject);
6169 programObject->validate(mCaps);
6170}
6171
Jiajia Qin5451d532017-11-16 17:16:34 +08006172void Context::validateProgramPipeline(GLuint pipeline)
6173{
6174 UNIMPLEMENTED();
6175}
6176
Jamie Madilld04908b2017-06-09 14:15:35 -04006177void Context::getProgramBinary(GLuint program,
6178 GLsizei bufSize,
6179 GLsizei *length,
6180 GLenum *binaryFormat,
6181 void *binary)
6182{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006183 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006184 ASSERT(programObject != nullptr);
6185
Jamie Madill4f6592f2018-11-27 16:37:45 -05006186 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006187}
6188
6189void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6190{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006191 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006192 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006193
Jamie Madill4f6592f2018-11-27 16:37:45 -05006194 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006195 if (programObject->isInUse())
6196 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006197 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006198 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006199 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006200}
6201
Jamie Madillff325f12017-08-26 15:06:05 -04006202void Context::uniform1ui(GLint location, GLuint v0)
6203{
6204 Program *program = mGLState.getProgram();
6205 program->setUniform1uiv(location, 1, &v0);
6206}
6207
6208void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6209{
6210 Program *program = mGLState.getProgram();
6211 const GLuint xy[] = {v0, v1};
6212 program->setUniform2uiv(location, 1, xy);
6213}
6214
6215void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6216{
6217 Program *program = mGLState.getProgram();
6218 const GLuint xyz[] = {v0, v1, v2};
6219 program->setUniform3uiv(location, 1, xyz);
6220}
6221
6222void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6223{
6224 Program *program = mGLState.getProgram();
6225 const GLuint xyzw[] = {v0, v1, v2, v3};
6226 program->setUniform4uiv(location, 1, xyzw);
6227}
6228
6229void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6230{
6231 Program *program = mGLState.getProgram();
6232 program->setUniform1uiv(location, count, value);
6233}
6234void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6235{
6236 Program *program = mGLState.getProgram();
6237 program->setUniform2uiv(location, count, value);
6238}
6239
6240void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6241{
6242 Program *program = mGLState.getProgram();
6243 program->setUniform3uiv(location, count, value);
6244}
6245
6246void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6247{
6248 Program *program = mGLState.getProgram();
6249 program->setUniform4uiv(location, count, value);
6250}
6251
Jamie Madillf0e04492017-08-26 15:28:42 -04006252void Context::genQueries(GLsizei n, GLuint *ids)
6253{
6254 for (GLsizei i = 0; i < n; i++)
6255 {
6256 GLuint handle = mQueryHandleAllocator.allocate();
6257 mQueryMap.assign(handle, nullptr);
6258 ids[i] = handle;
6259 }
6260}
6261
6262void Context::deleteQueries(GLsizei n, const GLuint *ids)
6263{
6264 for (int i = 0; i < n; i++)
6265 {
6266 GLuint query = ids[i];
6267
6268 Query *queryObject = nullptr;
6269 if (mQueryMap.erase(query, &queryObject))
6270 {
6271 mQueryHandleAllocator.release(query);
6272 if (queryObject)
6273 {
6274 queryObject->release(this);
6275 }
6276 }
6277 }
6278}
6279
6280GLboolean Context::isQuery(GLuint id)
6281{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006282 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006283}
6284
Jamie Madillc8c95812017-08-26 18:40:09 -04006285void Context::uniformMatrix2x3fv(GLint location,
6286 GLsizei count,
6287 GLboolean transpose,
6288 const GLfloat *value)
6289{
6290 Program *program = mGLState.getProgram();
6291 program->setUniformMatrix2x3fv(location, count, transpose, value);
6292}
6293
6294void Context::uniformMatrix3x2fv(GLint location,
6295 GLsizei count,
6296 GLboolean transpose,
6297 const GLfloat *value)
6298{
6299 Program *program = mGLState.getProgram();
6300 program->setUniformMatrix3x2fv(location, count, transpose, value);
6301}
6302
6303void Context::uniformMatrix2x4fv(GLint location,
6304 GLsizei count,
6305 GLboolean transpose,
6306 const GLfloat *value)
6307{
6308 Program *program = mGLState.getProgram();
6309 program->setUniformMatrix2x4fv(location, count, transpose, value);
6310}
6311
6312void Context::uniformMatrix4x2fv(GLint location,
6313 GLsizei count,
6314 GLboolean transpose,
6315 const GLfloat *value)
6316{
6317 Program *program = mGLState.getProgram();
6318 program->setUniformMatrix4x2fv(location, count, transpose, value);
6319}
6320
6321void Context::uniformMatrix3x4fv(GLint location,
6322 GLsizei count,
6323 GLboolean transpose,
6324 const GLfloat *value)
6325{
6326 Program *program = mGLState.getProgram();
6327 program->setUniformMatrix3x4fv(location, count, transpose, value);
6328}
6329
6330void Context::uniformMatrix4x3fv(GLint location,
6331 GLsizei count,
6332 GLboolean transpose,
6333 const GLfloat *value)
6334{
6335 Program *program = mGLState.getProgram();
6336 program->setUniformMatrix4x3fv(location, count, transpose, value);
6337}
6338
Jamie Madilld7576732017-08-26 18:49:50 -04006339void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6340{
6341 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6342 {
6343 GLuint vertexArray = arrays[arrayIndex];
6344
6345 if (arrays[arrayIndex] != 0)
6346 {
6347 VertexArray *vertexArrayObject = nullptr;
6348 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6349 {
6350 if (vertexArrayObject != nullptr)
6351 {
6352 detachVertexArray(vertexArray);
6353 vertexArrayObject->onDestroy(this);
6354 }
6355
6356 mVertexArrayHandleAllocator.release(vertexArray);
6357 }
6358 }
6359 }
6360}
6361
6362void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6363{
6364 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6365 {
6366 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6367 mVertexArrayMap.assign(vertexArray, nullptr);
6368 arrays[arrayIndex] = vertexArray;
6369 }
6370}
6371
6372bool Context::isVertexArray(GLuint array)
6373{
6374 if (array == 0)
6375 {
6376 return GL_FALSE;
6377 }
6378
6379 VertexArray *vao = getVertexArray(array);
6380 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6381}
6382
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006383void Context::endTransformFeedback()
6384{
6385 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006386 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006387 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006388}
6389
6390void Context::transformFeedbackVaryings(GLuint program,
6391 GLsizei count,
6392 const GLchar *const *varyings,
6393 GLenum bufferMode)
6394{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006395 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006396 ASSERT(programObject);
6397 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6398}
6399
6400void Context::getTransformFeedbackVarying(GLuint program,
6401 GLuint index,
6402 GLsizei bufSize,
6403 GLsizei *length,
6404 GLsizei *size,
6405 GLenum *type,
6406 GLchar *name)
6407{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006408 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006409 ASSERT(programObject);
6410 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6411}
6412
6413void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6414{
6415 for (int i = 0; i < n; i++)
6416 {
6417 GLuint transformFeedback = ids[i];
6418 if (transformFeedback == 0)
6419 {
6420 continue;
6421 }
6422
6423 TransformFeedback *transformFeedbackObject = nullptr;
6424 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6425 {
6426 if (transformFeedbackObject != nullptr)
6427 {
6428 detachTransformFeedback(transformFeedback);
6429 transformFeedbackObject->release(this);
6430 }
6431
6432 mTransformFeedbackHandleAllocator.release(transformFeedback);
6433 }
6434 }
6435}
6436
6437void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6438{
6439 for (int i = 0; i < n; i++)
6440 {
6441 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6442 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6443 ids[i] = transformFeedback;
6444 }
6445}
6446
6447bool Context::isTransformFeedback(GLuint id)
6448{
6449 if (id == 0)
6450 {
6451 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6452 // returns FALSE
6453 return GL_FALSE;
6454 }
6455
6456 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6457 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6458}
6459
6460void Context::pauseTransformFeedback()
6461{
6462 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006463 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006464 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006465}
6466
6467void Context::resumeTransformFeedback()
6468{
6469 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006470 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006471 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006472}
6473
Jamie Madill12e957f2017-08-26 21:42:26 -04006474void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6475{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006476 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006477 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006478}
6479
Brandon Jones59770802018-04-02 13:18:42 -07006480void Context::getUniformuivRobust(GLuint program,
6481 GLint location,
6482 GLsizei bufSize,
6483 GLsizei *length,
6484 GLuint *params)
6485{
6486 getUniformuiv(program, location, params);
6487}
6488
Jamie Madill12e957f2017-08-26 21:42:26 -04006489GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6490{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006491 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006492 return programObject->getFragDataLocation(name);
6493}
6494
6495void Context::getUniformIndices(GLuint program,
6496 GLsizei uniformCount,
6497 const GLchar *const *uniformNames,
6498 GLuint *uniformIndices)
6499{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006500 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006501 if (!programObject->isLinked())
6502 {
6503 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6504 {
6505 uniformIndices[uniformId] = GL_INVALID_INDEX;
6506 }
6507 }
6508 else
6509 {
6510 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6511 {
6512 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6513 }
6514 }
6515}
6516
6517void Context::getActiveUniformsiv(GLuint program,
6518 GLsizei uniformCount,
6519 const GLuint *uniformIndices,
6520 GLenum pname,
6521 GLint *params)
6522{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006523 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006524 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6525 {
6526 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006527 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006528 }
6529}
6530
6531GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6532{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006533 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006534 return programObject->getUniformBlockIndex(uniformBlockName);
6535}
6536
6537void Context::getActiveUniformBlockiv(GLuint program,
6538 GLuint uniformBlockIndex,
6539 GLenum pname,
6540 GLint *params)
6541{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006542 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006543 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6544}
6545
Brandon Jones59770802018-04-02 13:18:42 -07006546void Context::getActiveUniformBlockivRobust(GLuint program,
6547 GLuint uniformBlockIndex,
6548 GLenum pname,
6549 GLsizei bufSize,
6550 GLsizei *length,
6551 GLint *params)
6552{
6553 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6554}
6555
Jamie Madill12e957f2017-08-26 21:42:26 -04006556void Context::getActiveUniformBlockName(GLuint program,
6557 GLuint uniformBlockIndex,
6558 GLsizei bufSize,
6559 GLsizei *length,
6560 GLchar *uniformBlockName)
6561{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006562 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006563 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6564}
6565
6566void Context::uniformBlockBinding(GLuint program,
6567 GLuint uniformBlockIndex,
6568 GLuint uniformBlockBinding)
6569{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006570 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006571 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006572
Jamie Madill956ab4d2018-10-10 16:13:03 -04006573 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006574 if (programObject->isInUse())
6575 {
6576 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006577 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006578 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006579}
6580
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006581GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6582{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006583 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6584 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006585
Jamie Madill70b5bb02017-08-28 13:32:37 -04006586 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006587 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006588 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006589 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006590 return nullptr;
6591 }
6592
Jamie Madill70b5bb02017-08-28 13:32:37 -04006593 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006594}
6595
6596GLboolean Context::isSync(GLsync sync)
6597{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006598 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006599}
6600
6601GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6602{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006603 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006604
6605 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006606 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006607 {
6608 return GL_WAIT_FAILED;
6609 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006610 return result;
6611}
6612
6613void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6614{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006615 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006616 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006617}
6618
6619void Context::getInteger64v(GLenum pname, GLint64 *params)
6620{
6621 GLenum nativeType = GL_NONE;
6622 unsigned int numParams = 0;
6623 getQueryParameterInfo(pname, &nativeType, &numParams);
6624
6625 if (nativeType == GL_INT_64_ANGLEX)
6626 {
6627 getInteger64vImpl(pname, params);
6628 }
6629 else
6630 {
6631 CastStateValues(this, nativeType, pname, numParams, params);
6632 }
6633}
6634
Brandon Jones59770802018-04-02 13:18:42 -07006635void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6636{
6637 getInteger64v(pname, data);
6638}
6639
Corentin Wallez336129f2017-10-17 15:55:40 -04006640void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006641{
6642 Buffer *buffer = mGLState.getTargetBuffer(target);
6643 QueryBufferParameteri64v(buffer, pname, params);
6644}
6645
Brandon Jones59770802018-04-02 13:18:42 -07006646void Context::getBufferParameteri64vRobust(BufferBinding target,
6647 GLenum pname,
6648 GLsizei bufSize,
6649 GLsizei *length,
6650 GLint64 *params)
6651{
6652 getBufferParameteri64v(target, pname, params);
6653}
6654
Jamie Madill3ef140a2017-08-26 23:11:21 -04006655void Context::genSamplers(GLsizei count, GLuint *samplers)
6656{
6657 for (int i = 0; i < count; i++)
6658 {
6659 samplers[i] = mState.mSamplers->createSampler();
6660 }
6661}
6662
6663void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6664{
6665 for (int i = 0; i < count; i++)
6666 {
6667 GLuint sampler = samplers[i];
6668
6669 if (mState.mSamplers->getSampler(sampler))
6670 {
6671 detachSampler(sampler);
6672 }
6673
6674 mState.mSamplers->deleteObject(this, sampler);
6675 }
6676}
6677
6678void Context::getInternalformativ(GLenum target,
6679 GLenum internalformat,
6680 GLenum pname,
6681 GLsizei bufSize,
6682 GLint *params)
6683{
6684 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6685 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6686}
6687
Brandon Jones59770802018-04-02 13:18:42 -07006688void Context::getInternalformativRobust(GLenum target,
6689 GLenum internalformat,
6690 GLenum pname,
6691 GLsizei bufSize,
6692 GLsizei *length,
6693 GLint *params)
6694{
6695 getInternalformativ(target, internalformat, pname, bufSize, params);
6696}
6697
Jiajia Qin5451d532017-11-16 17:16:34 +08006698void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6699{
6700 programUniform1iv(program, location, 1, &v0);
6701}
6702
6703void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6704{
6705 GLint xy[2] = {v0, v1};
6706 programUniform2iv(program, location, 1, xy);
6707}
6708
6709void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6710{
6711 GLint xyz[3] = {v0, v1, v2};
6712 programUniform3iv(program, location, 1, xyz);
6713}
6714
6715void Context::programUniform4i(GLuint program,
6716 GLint location,
6717 GLint v0,
6718 GLint v1,
6719 GLint v2,
6720 GLint v3)
6721{
6722 GLint xyzw[4] = {v0, v1, v2, v3};
6723 programUniform4iv(program, location, 1, xyzw);
6724}
6725
6726void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6727{
6728 programUniform1uiv(program, location, 1, &v0);
6729}
6730
6731void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6732{
6733 GLuint xy[2] = {v0, v1};
6734 programUniform2uiv(program, location, 1, xy);
6735}
6736
6737void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6738{
6739 GLuint xyz[3] = {v0, v1, v2};
6740 programUniform3uiv(program, location, 1, xyz);
6741}
6742
6743void Context::programUniform4ui(GLuint program,
6744 GLint location,
6745 GLuint v0,
6746 GLuint v1,
6747 GLuint v2,
6748 GLuint v3)
6749{
6750 GLuint xyzw[4] = {v0, v1, v2, v3};
6751 programUniform4uiv(program, location, 1, xyzw);
6752}
6753
6754void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6755{
6756 programUniform1fv(program, location, 1, &v0);
6757}
6758
6759void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6760{
6761 GLfloat xy[2] = {v0, v1};
6762 programUniform2fv(program, location, 1, xy);
6763}
6764
6765void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6766{
6767 GLfloat xyz[3] = {v0, v1, v2};
6768 programUniform3fv(program, location, 1, xyz);
6769}
6770
6771void Context::programUniform4f(GLuint program,
6772 GLint location,
6773 GLfloat v0,
6774 GLfloat v1,
6775 GLfloat v2,
6776 GLfloat v3)
6777{
6778 GLfloat xyzw[4] = {v0, v1, v2, v3};
6779 programUniform4fv(program, location, 1, xyzw);
6780}
6781
Jamie Madill81c2e252017-09-09 23:32:46 -04006782void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6783{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006784 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006785 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006786 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006787}
6788
Jiajia Qin5451d532017-11-16 17:16:34 +08006789void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6790{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006791 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006792 ASSERT(programObject);
6793 programObject->setUniform2iv(location, count, value);
6794}
6795
6796void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6797{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006798 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006799 ASSERT(programObject);
6800 programObject->setUniform3iv(location, count, value);
6801}
6802
6803void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6804{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006805 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006806 ASSERT(programObject);
6807 programObject->setUniform4iv(location, count, value);
6808}
6809
6810void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6811{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006812 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006813 ASSERT(programObject);
6814 programObject->setUniform1uiv(location, count, value);
6815}
6816
6817void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6818{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006819 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006820 ASSERT(programObject);
6821 programObject->setUniform2uiv(location, count, value);
6822}
6823
6824void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6825{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006826 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006827 ASSERT(programObject);
6828 programObject->setUniform3uiv(location, count, value);
6829}
6830
6831void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6832{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006833 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006834 ASSERT(programObject);
6835 programObject->setUniform4uiv(location, count, value);
6836}
6837
6838void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6839{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006840 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006841 ASSERT(programObject);
6842 programObject->setUniform1fv(location, count, value);
6843}
6844
6845void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6846{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006847 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006848 ASSERT(programObject);
6849 programObject->setUniform2fv(location, count, value);
6850}
6851
6852void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6853{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006854 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006855 ASSERT(programObject);
6856 programObject->setUniform3fv(location, count, value);
6857}
6858
6859void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6860{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006861 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006862 ASSERT(programObject);
6863 programObject->setUniform4fv(location, count, value);
6864}
6865
6866void Context::programUniformMatrix2fv(GLuint program,
6867 GLint location,
6868 GLsizei count,
6869 GLboolean transpose,
6870 const GLfloat *value)
6871{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006872 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006873 ASSERT(programObject);
6874 programObject->setUniformMatrix2fv(location, count, transpose, value);
6875}
6876
6877void Context::programUniformMatrix3fv(GLuint program,
6878 GLint location,
6879 GLsizei count,
6880 GLboolean transpose,
6881 const GLfloat *value)
6882{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006883 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006884 ASSERT(programObject);
6885 programObject->setUniformMatrix3fv(location, count, transpose, value);
6886}
6887
6888void Context::programUniformMatrix4fv(GLuint program,
6889 GLint location,
6890 GLsizei count,
6891 GLboolean transpose,
6892 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->setUniformMatrix4fv(location, count, transpose, value);
6897}
6898
6899void Context::programUniformMatrix2x3fv(GLuint program,
6900 GLint location,
6901 GLsizei count,
6902 GLboolean transpose,
6903 const GLfloat *value)
6904{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006905 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006906 ASSERT(programObject);
6907 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6908}
6909
6910void Context::programUniformMatrix3x2fv(GLuint program,
6911 GLint location,
6912 GLsizei count,
6913 GLboolean transpose,
6914 const GLfloat *value)
6915{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006916 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006917 ASSERT(programObject);
6918 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6919}
6920
6921void Context::programUniformMatrix2x4fv(GLuint program,
6922 GLint location,
6923 GLsizei count,
6924 GLboolean transpose,
6925 const GLfloat *value)
6926{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006927 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006928 ASSERT(programObject);
6929 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6930}
6931
6932void Context::programUniformMatrix4x2fv(GLuint program,
6933 GLint location,
6934 GLsizei count,
6935 GLboolean transpose,
6936 const GLfloat *value)
6937{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006938 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006939 ASSERT(programObject);
6940 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6941}
6942
6943void Context::programUniformMatrix3x4fv(GLuint program,
6944 GLint location,
6945 GLsizei count,
6946 GLboolean transpose,
6947 const GLfloat *value)
6948{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006949 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006950 ASSERT(programObject);
6951 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6952}
6953
6954void Context::programUniformMatrix4x3fv(GLuint program,
6955 GLint location,
6956 GLsizei count,
6957 GLboolean transpose,
6958 const GLfloat *value)
6959{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006960 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006961 ASSERT(programObject);
6962 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6963}
6964
James Darpiniane8a93c62018-01-04 18:02:24 -08006965bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6966{
6967 return mGLState.isCurrentTransformFeedback(tf);
6968}
James Darpiniane8a93c62018-01-04 18:02:24 -08006969
Yunchao Hea336b902017-08-02 16:05:21 +08006970void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6971{
6972 for (int i = 0; i < count; i++)
6973 {
6974 pipelines[i] = createProgramPipeline();
6975 }
6976}
6977
6978void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6979{
6980 for (int i = 0; i < count; i++)
6981 {
6982 if (pipelines[i] != 0)
6983 {
6984 deleteProgramPipeline(pipelines[i]);
6985 }
6986 }
6987}
6988
6989GLboolean Context::isProgramPipeline(GLuint pipeline)
6990{
6991 if (pipeline == 0)
6992 {
6993 return GL_FALSE;
6994 }
6995
6996 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6997}
6998
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006999void Context::finishFenceNV(GLuint fence)
7000{
7001 FenceNV *fenceObject = getFenceNV(fence);
7002
7003 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007004 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007005}
7006
7007void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7008{
7009 FenceNV *fenceObject = getFenceNV(fence);
7010
7011 ASSERT(fenceObject && fenceObject->isSet());
7012
7013 switch (pname)
7014 {
7015 case GL_FENCE_STATUS_NV:
7016 {
7017 // GL_NV_fence spec:
7018 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7019 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7020 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7021 GLboolean status = GL_TRUE;
7022 if (fenceObject->getStatus() != GL_TRUE)
7023 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007024 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007025 }
7026 *params = status;
7027 break;
7028 }
7029
7030 case GL_FENCE_CONDITION_NV:
7031 {
7032 *params = static_cast<GLint>(fenceObject->getCondition());
7033 break;
7034 }
7035
7036 default:
7037 UNREACHABLE();
7038 }
7039}
7040
7041void Context::getTranslatedShaderSource(GLuint shader,
7042 GLsizei bufsize,
7043 GLsizei *length,
7044 GLchar *source)
7045{
7046 Shader *shaderObject = getShader(shader);
7047 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007048 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007049}
7050
7051void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7052{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007053 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007054 ASSERT(programObject);
7055
7056 programObject->getUniformfv(this, location, params);
7057}
7058
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007059void Context::getnUniformfvRobust(GLuint program,
7060 GLint location,
7061 GLsizei bufSize,
7062 GLsizei *length,
7063 GLfloat *params)
7064{
7065 UNIMPLEMENTED();
7066}
7067
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007068void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7069{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007070 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007071 ASSERT(programObject);
7072
7073 programObject->getUniformiv(this, location, params);
7074}
7075
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007076void Context::getnUniformivRobust(GLuint program,
7077 GLint location,
7078 GLsizei bufSize,
7079 GLsizei *length,
7080 GLint *params)
7081{
7082 UNIMPLEMENTED();
7083}
7084
7085void Context::getnUniformuivRobust(GLuint program,
7086 GLint location,
7087 GLsizei bufSize,
7088 GLsizei *length,
7089 GLuint *params)
7090{
7091 UNIMPLEMENTED();
7092}
7093
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007094GLboolean Context::isFenceNV(GLuint fence)
7095{
7096 FenceNV *fenceObject = getFenceNV(fence);
7097
7098 if (fenceObject == nullptr)
7099 {
7100 return GL_FALSE;
7101 }
7102
7103 // GL_NV_fence spec:
7104 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7105 // existing fence.
7106 return fenceObject->isSet();
7107}
7108
7109void Context::readnPixels(GLint x,
7110 GLint y,
7111 GLsizei width,
7112 GLsizei height,
7113 GLenum format,
7114 GLenum type,
7115 GLsizei bufSize,
7116 void *data)
7117{
7118 return readPixels(x, y, width, height, format, type, data);
7119}
7120
Jamie Madill007530e2017-12-28 14:27:04 -05007121void Context::setFenceNV(GLuint fence, GLenum condition)
7122{
7123 ASSERT(condition == GL_ALL_COMPLETED_NV);
7124
7125 FenceNV *fenceObject = getFenceNV(fence);
7126 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007127 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007128}
7129
7130GLboolean Context::testFenceNV(GLuint fence)
7131{
7132 FenceNV *fenceObject = getFenceNV(fence);
7133
7134 ASSERT(fenceObject != nullptr);
7135 ASSERT(fenceObject->isSet() == GL_TRUE);
7136
7137 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007138 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007139 {
Jamie Madill007530e2017-12-28 14:27:04 -05007140 return GL_TRUE;
7141 }
7142
7143 return result;
7144}
7145
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007146void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007147{
7148 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007149 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007150 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007151}
7152
Jamie Madillfa920eb2018-01-04 11:45:50 -05007153void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007154{
7155 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007156 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007157 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007158}
7159
Jamie Madillfa920eb2018-01-04 11:45:50 -05007160void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7161{
7162 UNIMPLEMENTED();
7163}
7164
Jamie Madill5b772312018-03-08 20:28:32 -05007165bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7166{
7167 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7168 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7169 // to the fact that it is stored internally as a float, and so would require conversion
7170 // if returned from Context::getIntegerv. Since this conversion is already implemented
7171 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7172 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7173 // application.
7174 switch (pname)
7175 {
7176 case GL_COMPRESSED_TEXTURE_FORMATS:
7177 {
7178 *type = GL_INT;
7179 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7180 return true;
7181 }
7182 case GL_SHADER_BINARY_FORMATS:
7183 {
7184 *type = GL_INT;
7185 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7186 return true;
7187 }
7188
7189 case GL_MAX_VERTEX_ATTRIBS:
7190 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7191 case GL_MAX_VARYING_VECTORS:
7192 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7193 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7194 case GL_MAX_TEXTURE_IMAGE_UNITS:
7195 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7196 case GL_MAX_RENDERBUFFER_SIZE:
7197 case GL_NUM_SHADER_BINARY_FORMATS:
7198 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7199 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007200 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7201 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007202 case GL_RENDERBUFFER_BINDING:
7203 case GL_CURRENT_PROGRAM:
7204 case GL_PACK_ALIGNMENT:
7205 case GL_UNPACK_ALIGNMENT:
7206 case GL_GENERATE_MIPMAP_HINT:
7207 case GL_RED_BITS:
7208 case GL_GREEN_BITS:
7209 case GL_BLUE_BITS:
7210 case GL_ALPHA_BITS:
7211 case GL_DEPTH_BITS:
7212 case GL_STENCIL_BITS:
7213 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7214 case GL_CULL_FACE_MODE:
7215 case GL_FRONT_FACE:
7216 case GL_ACTIVE_TEXTURE:
7217 case GL_STENCIL_FUNC:
7218 case GL_STENCIL_VALUE_MASK:
7219 case GL_STENCIL_REF:
7220 case GL_STENCIL_FAIL:
7221 case GL_STENCIL_PASS_DEPTH_FAIL:
7222 case GL_STENCIL_PASS_DEPTH_PASS:
7223 case GL_STENCIL_BACK_FUNC:
7224 case GL_STENCIL_BACK_VALUE_MASK:
7225 case GL_STENCIL_BACK_REF:
7226 case GL_STENCIL_BACK_FAIL:
7227 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7228 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7229 case GL_DEPTH_FUNC:
7230 case GL_BLEND_SRC_RGB:
7231 case GL_BLEND_SRC_ALPHA:
7232 case GL_BLEND_DST_RGB:
7233 case GL_BLEND_DST_ALPHA:
7234 case GL_BLEND_EQUATION_RGB:
7235 case GL_BLEND_EQUATION_ALPHA:
7236 case GL_STENCIL_WRITEMASK:
7237 case GL_STENCIL_BACK_WRITEMASK:
7238 case GL_STENCIL_CLEAR_VALUE:
7239 case GL_SUBPIXEL_BITS:
7240 case GL_MAX_TEXTURE_SIZE:
7241 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7242 case GL_SAMPLE_BUFFERS:
7243 case GL_SAMPLES:
7244 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7245 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7246 case GL_TEXTURE_BINDING_2D:
7247 case GL_TEXTURE_BINDING_CUBE_MAP:
7248 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7249 {
7250 *type = GL_INT;
7251 *numParams = 1;
7252 return true;
7253 }
7254 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7255 {
7256 if (!getExtensions().packReverseRowOrder)
7257 {
7258 return false;
7259 }
7260 *type = GL_INT;
7261 *numParams = 1;
7262 return true;
7263 }
7264 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7265 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7266 {
7267 if (!getExtensions().textureRectangle)
7268 {
7269 return false;
7270 }
7271 *type = GL_INT;
7272 *numParams = 1;
7273 return true;
7274 }
7275 case GL_MAX_DRAW_BUFFERS_EXT:
7276 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7277 {
7278 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7279 {
7280 return false;
7281 }
7282 *type = GL_INT;
7283 *numParams = 1;
7284 return true;
7285 }
7286 case GL_MAX_VIEWPORT_DIMS:
7287 {
7288 *type = GL_INT;
7289 *numParams = 2;
7290 return true;
7291 }
7292 case GL_VIEWPORT:
7293 case GL_SCISSOR_BOX:
7294 {
7295 *type = GL_INT;
7296 *numParams = 4;
7297 return true;
7298 }
7299 case GL_SHADER_COMPILER:
7300 case GL_SAMPLE_COVERAGE_INVERT:
7301 case GL_DEPTH_WRITEMASK:
7302 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7303 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7304 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7305 // bool-natural
7306 case GL_SAMPLE_COVERAGE:
7307 case GL_SCISSOR_TEST:
7308 case GL_STENCIL_TEST:
7309 case GL_DEPTH_TEST:
7310 case GL_BLEND:
7311 case GL_DITHER:
7312 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7313 {
7314 *type = GL_BOOL;
7315 *numParams = 1;
7316 return true;
7317 }
7318 case GL_COLOR_WRITEMASK:
7319 {
7320 *type = GL_BOOL;
7321 *numParams = 4;
7322 return true;
7323 }
7324 case GL_POLYGON_OFFSET_FACTOR:
7325 case GL_POLYGON_OFFSET_UNITS:
7326 case GL_SAMPLE_COVERAGE_VALUE:
7327 case GL_DEPTH_CLEAR_VALUE:
7328 case GL_LINE_WIDTH:
7329 {
7330 *type = GL_FLOAT;
7331 *numParams = 1;
7332 return true;
7333 }
7334 case GL_ALIASED_LINE_WIDTH_RANGE:
7335 case GL_ALIASED_POINT_SIZE_RANGE:
7336 case GL_DEPTH_RANGE:
7337 {
7338 *type = GL_FLOAT;
7339 *numParams = 2;
7340 return true;
7341 }
7342 case GL_COLOR_CLEAR_VALUE:
7343 case GL_BLEND_COLOR:
7344 {
7345 *type = GL_FLOAT;
7346 *numParams = 4;
7347 return true;
7348 }
7349 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7350 if (!getExtensions().textureFilterAnisotropic)
7351 {
7352 return false;
7353 }
7354 *type = GL_FLOAT;
7355 *numParams = 1;
7356 return true;
7357 case GL_TIMESTAMP_EXT:
7358 if (!getExtensions().disjointTimerQuery)
7359 {
7360 return false;
7361 }
7362 *type = GL_INT_64_ANGLEX;
7363 *numParams = 1;
7364 return true;
7365 case GL_GPU_DISJOINT_EXT:
7366 if (!getExtensions().disjointTimerQuery)
7367 {
7368 return false;
7369 }
7370 *type = GL_INT;
7371 *numParams = 1;
7372 return true;
7373 case GL_COVERAGE_MODULATION_CHROMIUM:
7374 if (!getExtensions().framebufferMixedSamples)
7375 {
7376 return false;
7377 }
7378 *type = GL_INT;
7379 *numParams = 1;
7380 return true;
7381 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7382 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7383 {
7384 return false;
7385 }
7386 *type = GL_INT;
7387 *numParams = 1;
7388 return true;
7389 }
7390
7391 if (getExtensions().debug)
7392 {
7393 switch (pname)
7394 {
7395 case GL_DEBUG_LOGGED_MESSAGES:
7396 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7397 case GL_DEBUG_GROUP_STACK_DEPTH:
7398 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7399 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7400 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7401 case GL_MAX_LABEL_LENGTH:
7402 *type = GL_INT;
7403 *numParams = 1;
7404 return true;
7405
7406 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7407 case GL_DEBUG_OUTPUT:
7408 *type = GL_BOOL;
7409 *numParams = 1;
7410 return true;
7411 }
7412 }
7413
7414 if (getExtensions().multisampleCompatibility)
7415 {
7416 switch (pname)
7417 {
7418 case GL_MULTISAMPLE_EXT:
7419 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7420 *type = GL_BOOL;
7421 *numParams = 1;
7422 return true;
7423 }
7424 }
7425
7426 if (getExtensions().pathRendering)
7427 {
7428 switch (pname)
7429 {
7430 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7431 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7432 *type = GL_FLOAT;
7433 *numParams = 16;
7434 return true;
7435 }
7436 }
7437
7438 if (getExtensions().bindGeneratesResource)
7439 {
7440 switch (pname)
7441 {
7442 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7443 *type = GL_BOOL;
7444 *numParams = 1;
7445 return true;
7446 }
7447 }
7448
7449 if (getExtensions().clientArrays)
7450 {
7451 switch (pname)
7452 {
7453 case GL_CLIENT_ARRAYS_ANGLE:
7454 *type = GL_BOOL;
7455 *numParams = 1;
7456 return true;
7457 }
7458 }
7459
7460 if (getExtensions().sRGBWriteControl)
7461 {
7462 switch (pname)
7463 {
7464 case GL_FRAMEBUFFER_SRGB_EXT:
7465 *type = GL_BOOL;
7466 *numParams = 1;
7467 return true;
7468 }
7469 }
7470
7471 if (getExtensions().robustResourceInitialization &&
7472 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7473 {
7474 *type = GL_BOOL;
7475 *numParams = 1;
7476 return true;
7477 }
7478
7479 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7480 {
7481 *type = GL_BOOL;
7482 *numParams = 1;
7483 return true;
7484 }
7485
jchen1082af6202018-06-22 10:59:52 +08007486 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7487 {
7488 *type = GL_INT;
7489 *numParams = 1;
7490 return true;
7491 }
7492
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007493 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7494 {
7495 *type = GL_INT;
7496 *numParams = 1;
7497 return true;
7498 }
7499
Jamie Madill5b772312018-03-08 20:28:32 -05007500 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7501 switch (pname)
7502 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007503 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007504 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7505 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7506 {
7507 return false;
7508 }
7509 *type = GL_INT;
7510 *numParams = 1;
7511 return true;
7512
7513 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7514 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7515 {
7516 return false;
7517 }
7518 *type = GL_INT;
7519 *numParams = 1;
7520 return true;
7521
7522 case GL_PROGRAM_BINARY_FORMATS_OES:
7523 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7524 {
7525 return false;
7526 }
7527 *type = GL_INT;
7528 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7529 return true;
7530
7531 case GL_PACK_ROW_LENGTH:
7532 case GL_PACK_SKIP_ROWS:
7533 case GL_PACK_SKIP_PIXELS:
7534 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7535 {
7536 return false;
7537 }
7538 *type = GL_INT;
7539 *numParams = 1;
7540 return true;
7541 case GL_UNPACK_ROW_LENGTH:
7542 case GL_UNPACK_SKIP_ROWS:
7543 case GL_UNPACK_SKIP_PIXELS:
7544 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7545 {
7546 return false;
7547 }
7548 *type = GL_INT;
7549 *numParams = 1;
7550 return true;
7551 case GL_VERTEX_ARRAY_BINDING:
7552 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7553 {
7554 return false;
7555 }
7556 *type = GL_INT;
7557 *numParams = 1;
7558 return true;
7559 case GL_PIXEL_PACK_BUFFER_BINDING:
7560 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7561 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7562 {
7563 return false;
7564 }
7565 *type = GL_INT;
7566 *numParams = 1;
7567 return true;
7568 case GL_MAX_SAMPLES:
7569 {
7570 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7571 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7572 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7573 {
7574 return false;
7575 }
7576 *type = GL_INT;
7577 *numParams = 1;
7578 return true;
7579
7580 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7581 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7582 {
7583 return false;
7584 }
7585 *type = GL_INT;
7586 *numParams = 1;
7587 return true;
7588 }
7589 }
7590
7591 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7592 {
7593 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7594 {
7595 return false;
7596 }
7597 *type = GL_INT;
7598 *numParams = 1;
7599 return true;
7600 }
7601
7602 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7603 {
7604 *type = GL_INT;
7605 *numParams = 1;
7606 return true;
7607 }
7608
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007609 if (getClientVersion() < Version(2, 0))
7610 {
7611 switch (pname)
7612 {
7613 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007614 case GL_CLIENT_ACTIVE_TEXTURE:
7615 case GL_MATRIX_MODE:
7616 case GL_MAX_TEXTURE_UNITS:
7617 case GL_MAX_MODELVIEW_STACK_DEPTH:
7618 case GL_MAX_PROJECTION_STACK_DEPTH:
7619 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007620 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007621 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007622 case GL_VERTEX_ARRAY_STRIDE:
7623 case GL_NORMAL_ARRAY_STRIDE:
7624 case GL_COLOR_ARRAY_STRIDE:
7625 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7626 case GL_VERTEX_ARRAY_SIZE:
7627 case GL_COLOR_ARRAY_SIZE:
7628 case GL_TEXTURE_COORD_ARRAY_SIZE:
7629 case GL_VERTEX_ARRAY_TYPE:
7630 case GL_NORMAL_ARRAY_TYPE:
7631 case GL_COLOR_ARRAY_TYPE:
7632 case GL_TEXTURE_COORD_ARRAY_TYPE:
7633 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7634 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7635 case GL_COLOR_ARRAY_BUFFER_BINDING:
7636 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7637 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7638 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7639 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007640 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007641 case GL_MODELVIEW_STACK_DEPTH:
7642 case GL_PROJECTION_STACK_DEPTH:
7643 case GL_TEXTURE_STACK_DEPTH:
7644 case GL_LOGIC_OP_MODE:
7645 case GL_BLEND_SRC:
7646 case GL_BLEND_DST:
7647 case GL_PERSPECTIVE_CORRECTION_HINT:
7648 case GL_POINT_SMOOTH_HINT:
7649 case GL_LINE_SMOOTH_HINT:
7650 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007651 *type = GL_INT;
7652 *numParams = 1;
7653 return true;
7654 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007655 case GL_FOG_DENSITY:
7656 case GL_FOG_START:
7657 case GL_FOG_END:
7658 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007659 case GL_POINT_SIZE:
7660 case GL_POINT_SIZE_MIN:
7661 case GL_POINT_SIZE_MAX:
7662 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007663 *type = GL_FLOAT;
7664 *numParams = 1;
7665 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007666 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007667 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007668 *type = GL_FLOAT;
7669 *numParams = 2;
7670 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007671 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007672 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007673 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007674 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007675 *type = GL_FLOAT;
7676 *numParams = 4;
7677 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007678 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007679 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007680 *type = GL_FLOAT;
7681 *numParams = 3;
7682 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007683 case GL_MODELVIEW_MATRIX:
7684 case GL_PROJECTION_MATRIX:
7685 case GL_TEXTURE_MATRIX:
7686 *type = GL_FLOAT;
7687 *numParams = 16;
7688 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007689 case GL_LIGHT_MODEL_TWO_SIDE:
7690 *type = GL_BOOL;
7691 *numParams = 1;
7692 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007693 }
7694 }
7695
Jamie Madill5b772312018-03-08 20:28:32 -05007696 if (getClientVersion() < Version(3, 0))
7697 {
7698 return false;
7699 }
7700
7701 // Check for ES3.0+ parameter names
7702 switch (pname)
7703 {
7704 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7705 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7706 case GL_UNIFORM_BUFFER_BINDING:
7707 case GL_TRANSFORM_FEEDBACK_BINDING:
7708 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7709 case GL_COPY_READ_BUFFER_BINDING:
7710 case GL_COPY_WRITE_BUFFER_BINDING:
7711 case GL_SAMPLER_BINDING:
7712 case GL_READ_BUFFER:
7713 case GL_TEXTURE_BINDING_3D:
7714 case GL_TEXTURE_BINDING_2D_ARRAY:
7715 case GL_MAX_3D_TEXTURE_SIZE:
7716 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7717 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7718 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7719 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7720 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7721 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7722 case GL_MAX_VARYING_COMPONENTS:
7723 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7724 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7725 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7726 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7727 case GL_NUM_EXTENSIONS:
7728 case GL_MAJOR_VERSION:
7729 case GL_MINOR_VERSION:
7730 case GL_MAX_ELEMENTS_INDICES:
7731 case GL_MAX_ELEMENTS_VERTICES:
7732 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7733 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7734 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7735 case GL_UNPACK_IMAGE_HEIGHT:
7736 case GL_UNPACK_SKIP_IMAGES:
7737 {
7738 *type = GL_INT;
7739 *numParams = 1;
7740 return true;
7741 }
7742
7743 case GL_MAX_ELEMENT_INDEX:
7744 case GL_MAX_UNIFORM_BLOCK_SIZE:
7745 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7746 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7747 case GL_MAX_SERVER_WAIT_TIMEOUT:
7748 {
7749 *type = GL_INT_64_ANGLEX;
7750 *numParams = 1;
7751 return true;
7752 }
7753
7754 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7755 case GL_TRANSFORM_FEEDBACK_PAUSED:
7756 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7757 case GL_RASTERIZER_DISCARD:
7758 {
7759 *type = GL_BOOL;
7760 *numParams = 1;
7761 return true;
7762 }
7763
7764 case GL_MAX_TEXTURE_LOD_BIAS:
7765 {
7766 *type = GL_FLOAT;
7767 *numParams = 1;
7768 return true;
7769 }
7770 }
7771
7772 if (getExtensions().requestExtension)
7773 {
7774 switch (pname)
7775 {
7776 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7777 *type = GL_INT;
7778 *numParams = 1;
7779 return true;
7780 }
7781 }
7782
Yizhou Jiang7818a852018-09-06 15:02:04 +08007783 if (getExtensions().textureMultisample)
7784 {
7785 switch (pname)
7786 {
7787 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7788 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7789 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7790 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007791 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007792 *type = GL_INT;
7793 *numParams = 1;
7794 return true;
7795 }
7796 }
7797
Jamie Madill5b772312018-03-08 20:28:32 -05007798 if (getClientVersion() < Version(3, 1))
7799 {
7800 return false;
7801 }
7802
7803 switch (pname)
7804 {
7805 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7806 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7807 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7808 case GL_MAX_FRAMEBUFFER_WIDTH:
7809 case GL_MAX_FRAMEBUFFER_HEIGHT:
7810 case GL_MAX_FRAMEBUFFER_SAMPLES:
7811 case GL_MAX_SAMPLE_MASK_WORDS:
7812 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7813 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7814 case GL_MAX_INTEGER_SAMPLES:
7815 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7816 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7817 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7818 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7819 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7820 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7821 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7822 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7823 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7824 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7825 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7826 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7827 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7828 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7829 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7830 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7831 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7832 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7833 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7834 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7835 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7836 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7837 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7838 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7839 case GL_MAX_UNIFORM_LOCATIONS:
7840 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7841 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7842 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7843 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7844 case GL_MAX_IMAGE_UNITS:
7845 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7846 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7847 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7848 case GL_SHADER_STORAGE_BUFFER_BINDING:
7849 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7850 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007851 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007852 *type = GL_INT;
7853 *numParams = 1;
7854 return true;
7855 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7856 *type = GL_INT_64_ANGLEX;
7857 *numParams = 1;
7858 return true;
7859 case GL_SAMPLE_MASK:
7860 *type = GL_BOOL;
7861 *numParams = 1;
7862 return true;
7863 }
7864
7865 if (getExtensions().geometryShader)
7866 {
7867 switch (pname)
7868 {
7869 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7870 case GL_LAYER_PROVOKING_VERTEX_EXT:
7871 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7872 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7873 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7874 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7875 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7876 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7877 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7878 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7879 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7880 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7881 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7882 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7883 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7884 *type = GL_INT;
7885 *numParams = 1;
7886 return true;
7887 }
7888 }
7889
7890 return false;
7891}
7892
7893bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7894{
7895 if (getClientVersion() < Version(3, 0))
7896 {
7897 return false;
7898 }
7899
7900 switch (target)
7901 {
7902 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7903 case GL_UNIFORM_BUFFER_BINDING:
7904 {
7905 *type = GL_INT;
7906 *numParams = 1;
7907 return true;
7908 }
7909 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7910 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7911 case GL_UNIFORM_BUFFER_START:
7912 case GL_UNIFORM_BUFFER_SIZE:
7913 {
7914 *type = GL_INT_64_ANGLEX;
7915 *numParams = 1;
7916 return true;
7917 }
7918 }
7919
7920 if (getClientVersion() < Version(3, 1))
7921 {
7922 return false;
7923 }
7924
7925 switch (target)
7926 {
7927 case GL_IMAGE_BINDING_LAYERED:
7928 {
7929 *type = GL_BOOL;
7930 *numParams = 1;
7931 return true;
7932 }
7933 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7934 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7935 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7936 case GL_SHADER_STORAGE_BUFFER_BINDING:
7937 case GL_VERTEX_BINDING_BUFFER:
7938 case GL_VERTEX_BINDING_DIVISOR:
7939 case GL_VERTEX_BINDING_OFFSET:
7940 case GL_VERTEX_BINDING_STRIDE:
7941 case GL_SAMPLE_MASK_VALUE:
7942 case GL_IMAGE_BINDING_NAME:
7943 case GL_IMAGE_BINDING_LEVEL:
7944 case GL_IMAGE_BINDING_LAYER:
7945 case GL_IMAGE_BINDING_ACCESS:
7946 case GL_IMAGE_BINDING_FORMAT:
7947 {
7948 *type = GL_INT;
7949 *numParams = 1;
7950 return true;
7951 }
7952 case GL_ATOMIC_COUNTER_BUFFER_START:
7953 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7954 case GL_SHADER_STORAGE_BUFFER_START:
7955 case GL_SHADER_STORAGE_BUFFER_SIZE:
7956 {
7957 *type = GL_INT_64_ANGLEX;
7958 *numParams = 1;
7959 return true;
7960 }
7961 }
7962
7963 return false;
7964}
7965
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007966Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007967{
7968 return mState.mShaderPrograms->getProgram(handle);
7969}
7970
7971Shader *Context::getShader(GLuint handle) const
7972{
7973 return mState.mShaderPrograms->getShader(handle);
7974}
7975
Jamie Madill5b772312018-03-08 20:28:32 -05007976bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7977{
7978 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7979}
7980
7981bool Context::isFramebufferGenerated(GLuint framebuffer) const
7982{
7983 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7984}
7985
7986bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7987{
7988 return mState.mPipelines->isHandleGenerated(pipeline);
7989}
7990
7991bool Context::usingDisplayTextureShareGroup() const
7992{
7993 return mDisplayTextureShareGroup;
7994}
7995
7996GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7997{
7998 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7999 internalformat == GL_DEPTH_STENCIL
8000 ? GL_DEPTH24_STENCIL8
8001 : internalformat;
8002}
8003
jchen1082af6202018-06-22 10:59:52 +08008004void Context::maxShaderCompilerThreads(GLuint count)
8005{
jchen107ae70d82018-07-06 13:47:01 +08008006 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008007 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008008 // A count of zero specifies a request for no parallel compiling or linking.
8009 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8010 {
8011 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8012 }
8013 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008014}
8015
Jamie Madill2eb65032018-07-30 10:25:57 -04008016bool Context::isGLES1() const
8017{
8018 return mState.getClientVersion() < Version(2, 0);
8019}
8020
Jamie Madilla11819d2018-07-30 10:26:01 -04008021void Context::onSubjectStateChange(const Context *context,
8022 angle::SubjectIndex index,
8023 angle::SubjectMessage message)
8024{
Jamie Madilla11819d2018-07-30 10:26:01 -04008025 switch (index)
8026 {
8027 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008028 switch (message)
8029 {
8030 case angle::SubjectMessage::CONTENTS_CHANGED:
8031 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8032 mStateCache.onVertexArrayBufferContentsChange(this);
8033 break;
8034 case angle::SubjectMessage::RESOURCE_MAPPED:
8035 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8036 case angle::SubjectMessage::BINDING_CHANGED:
8037 mStateCache.onVertexArrayBufferStateChange(this);
8038 break;
8039 default:
8040 break;
8041 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008042 break;
8043
8044 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008045 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8046 {
8047 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8048 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008049 break;
8050
8051 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008052 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8053 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008054 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008055 }
8056 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008057 break;
8058
8059 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008060 if (index < kTextureMaxSubjectIndex)
8061 {
Jamie Madille3e680c2018-12-03 17:49:08 -05008062 mGLState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008063 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008064 }
Jamie Madille3e680c2018-12-03 17:49:08 -05008065 else if (index < kImageMaxSubjectIndex)
8066 {
8067 mGLState.onImageStateChange(this, index - kImage0SubjectIndex);
8068 }
Jamie Madille25b8002018-09-20 13:39:49 -04008069 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008070 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008071 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008072 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008073 }
Jamie Madille25b8002018-09-20 13:39:49 -04008074 else
8075 {
8076 ASSERT(index < kSamplerMaxSubjectIndex);
8077 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8078 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008079 break;
8080 }
8081}
8082
Jamie Madill6b873dd2018-07-12 23:56:30 -04008083// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008084ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008085
8086ErrorSet::~ErrorSet() = default;
8087
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008088void ErrorSet::handleError(GLenum errorCode,
8089 const char *message,
8090 const char *file,
8091 const char *function,
8092 unsigned int line)
8093{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008094 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8095 {
8096 mContext->markContextLost();
8097 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008098
Jamie Madill4f6592f2018-11-27 16:37:45 -05008099 std::stringstream errorStream;
8100 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8101 << line << ". " << message;
8102
Geoff Lang7139b432018-12-14 16:57:28 -05008103 std::string formattedMessage = errorStream.str();
8104
8105 // Always log a warning, this function is only called on unexpected internal errors.
8106 WARN() << formattedMessage;
8107
Jamie Madill4f6592f2018-11-27 16:37:45 -05008108 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008109 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008110}
8111
Jamie Madilla139f012018-10-10 16:13:03 -04008112void ErrorSet::validationError(GLenum errorCode, const char *message)
8113{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008114 ASSERT(errorCode != GL_NO_ERROR);
8115 mErrors.insert(errorCode);
8116
8117 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8118 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008119}
8120
Jamie Madill6b873dd2018-07-12 23:56:30 -04008121bool ErrorSet::empty() const
8122{
8123 return mErrors.empty();
8124}
8125
8126GLenum ErrorSet::popError()
8127{
8128 ASSERT(!empty());
8129 GLenum error = *mErrors.begin();
8130 mErrors.erase(mErrors.begin());
8131 return error;
8132}
Jamie Madilldc358af2018-07-31 11:22:13 -04008133
8134// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008135StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008136 : mCachedHasAnyEnabledClientAttrib(false),
8137 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008138 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008139 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008140 mCachedBasicDrawElementsError(kInvalidPointer),
8141 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008142{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008143
8144StateCache::~StateCache() = default;
8145
Jamie Madillac66f982018-10-09 18:30:01 -04008146void StateCache::initialize(Context *context)
8147{
8148 updateValidDrawModes(context);
8149 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008150 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008151 updateBasicDrawStatesError();
8152 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008153}
8154
Jamie Madilldc358af2018-07-31 11:22:13 -04008155void StateCache::updateActiveAttribsMask(Context *context)
8156{
8157 bool isGLES1 = context->isGLES1();
8158 const State &glState = context->getGLState();
8159
8160 if (!isGLES1 && !glState.getProgram())
8161 {
8162 mCachedActiveBufferedAttribsMask = AttributesMask();
8163 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008164 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008165 return;
8166 }
8167
8168 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8169 : glState.getProgram()->getActiveAttribLocationsMask();
8170
8171 const VertexArray *vao = glState.getVertexArray();
8172 ASSERT(vao);
8173
8174 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8175 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008176 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008177
Jamie Madill0a17e482018-08-31 17:19:11 -04008178 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8179 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008180 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008181 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8182}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008183
8184void StateCache::updateVertexElementLimits(Context *context)
8185{
8186 const VertexArray *vao = context->getGLState().getVertexArray();
8187
8188 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8189 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8190
8191 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8192 // If there are no buffered attributes then we should not limit the draw call count.
8193 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8194 {
8195 return;
8196 }
8197
8198 const auto &vertexAttribs = vao->getVertexAttributes();
8199 const auto &vertexBindings = vao->getVertexBindings();
8200
8201 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8202 {
8203 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8204 ASSERT(attrib.enabled);
8205
8206 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8207 ASSERT(context->isGLES1() ||
8208 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8209
8210 GLint64 limit = attrib.getCachedElementLimit();
8211 if (binding.getDivisor() > 0)
8212 {
8213 mCachedInstancedVertexElementLimit =
8214 std::min(mCachedInstancedVertexElementLimit, limit);
8215 }
8216 else
8217 {
8218 mCachedNonInstancedVertexElementLimit =
8219 std::min(mCachedNonInstancedVertexElementLimit, limit);
8220 }
8221 }
8222}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008223
Jamie Madilld84b6732018-09-06 15:54:35 -04008224void StateCache::updateBasicDrawStatesError()
8225{
8226 mCachedBasicDrawStatesError = kInvalidPointer;
8227}
8228
Jamie Madill1e853262018-12-21 09:07:38 -05008229void StateCache::updateBasicDrawElementsError()
8230{
8231 mCachedBasicDrawElementsError = kInvalidPointer;
8232}
8233
Jamie Madilld84b6732018-09-06 15:54:35 -04008234intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8235{
8236 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8237 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8238 return mCachedBasicDrawStatesError;
8239}
8240
Jamie Madill1e853262018-12-21 09:07:38 -05008241intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8242{
8243 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8244 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8245 return mCachedBasicDrawElementsError;
8246}
8247
Jamie Madillc43cdad2018-08-08 15:49:25 -04008248void StateCache::onVertexArrayBindingChange(Context *context)
8249{
8250 updateActiveAttribsMask(context);
8251 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008252 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008253}
8254
8255void StateCache::onProgramExecutableChange(Context *context)
8256{
8257 updateActiveAttribsMask(context);
8258 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008259 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008260 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008261}
8262
Jamie Madilld84b6732018-09-06 15:54:35 -04008263void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008264{
8265 updateVertexElementLimits(context);
8266}
8267
Jamie Madilld84b6732018-09-06 15:54:35 -04008268void StateCache::onVertexArrayBufferContentsChange(Context *context)
8269{
8270 updateVertexElementLimits(context);
8271 updateBasicDrawStatesError();
8272}
8273
Jamie Madillc43cdad2018-08-08 15:49:25 -04008274void StateCache::onVertexArrayStateChange(Context *context)
8275{
8276 updateActiveAttribsMask(context);
8277 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008278 updateBasicDrawStatesError();
8279}
8280
8281void StateCache::onVertexArrayBufferStateChange(Context *context)
8282{
8283 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008284 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008285}
8286
8287void StateCache::onGLES1ClientStateChange(Context *context)
8288{
8289 updateActiveAttribsMask(context);
8290}
Jamie Madilld84b6732018-09-06 15:54:35 -04008291
8292void StateCache::onDrawFramebufferChange(Context *context)
8293{
8294 updateBasicDrawStatesError();
8295}
8296
8297void StateCache::onContextCapChange(Context *context)
8298{
8299 updateBasicDrawStatesError();
8300}
8301
8302void StateCache::onStencilStateChange(Context *context)
8303{
8304 updateBasicDrawStatesError();
8305}
8306
8307void StateCache::onDefaultVertexAttributeChange(Context *context)
8308{
8309 updateBasicDrawStatesError();
8310}
8311
8312void StateCache::onActiveTextureChange(Context *context)
8313{
8314 updateBasicDrawStatesError();
8315}
8316
8317void StateCache::onQueryChange(Context *context)
8318{
8319 updateBasicDrawStatesError();
8320}
8321
Jamie Madill3a256222018-12-08 09:56:39 -05008322void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008323{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008324 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008325 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008326 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008327 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008328}
8329
8330void StateCache::onUniformBufferStateChange(Context *context)
8331{
8332 updateBasicDrawStatesError();
8333}
8334
8335void StateCache::onBufferBindingChange(Context *context)
8336{
8337 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008338 updateBasicDrawElementsError();
Jamie Madilld84b6732018-09-06 15:54:35 -04008339}
Jamie Madill526a6f62018-09-12 11:03:05 -04008340
Jamie Madill9b025062018-12-12 15:44:12 -05008341void StateCache::setValidDrawModes(bool pointsOK,
8342 bool linesOK,
8343 bool trisOK,
8344 bool lineAdjOK,
8345 bool triAdjOK)
8346{
8347 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8348 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8349 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8350 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8351 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8352 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8353 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8354 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8355 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8356 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8357 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8358}
8359
Jamie Madill526a6f62018-09-12 11:03:05 -04008360void StateCache::updateValidDrawModes(Context *context)
8361{
Jamie Madill9b025062018-12-12 15:44:12 -05008362 const State &state = context->getGLState();
8363 Program *program = state.getProgram();
8364
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008365 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008366 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008367 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8368
Jamie Madill9b025062018-12-12 15:44:12 -05008369 // ES Spec 3.0 validation text:
8370 // When transform feedback is active and not paused, all geometric primitives generated must
8371 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8372 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8373 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8374 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8375 // active and not paused, regardless of mode. Any primitive type may be used while transform
8376 // feedback is paused.
8377 if (!context->getExtensions().geometryShader)
8378 {
8379 mCachedValidDrawModes.fill(false);
8380 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8381 return;
8382 }
8383
8384 // EXT_geometry_shader validation text:
8385 // When transform feedback is active and not paused, all geometric primitives generated must
8386 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8387 // geometry shader is active, the type of primitive emitted by that shader is used instead
8388 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8389 // Any primitive type may be used while transform feedback is paused.
8390 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8391 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8392 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8393
8394 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8395 return;
8396 }
8397
Jamie Madill526a6f62018-09-12 11:03:05 -04008398 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8399 {
Jamie Madill752d2202018-11-27 13:29:48 -05008400 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008401 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008402 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008403
Jamie Madill9b025062018-12-12 15:44:12 -05008404 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8405 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008406
Jamie Madill9b025062018-12-12 15:44:12 -05008407 bool pointsOK = gsMode == PrimitiveMode::Points;
8408 bool linesOK = gsMode == PrimitiveMode::Lines;
8409 bool trisOK = gsMode == PrimitiveMode::Triangles;
8410 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8411 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8412
8413 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008414}
Jamie Madillac66f982018-10-09 18:30:01 -04008415
8416void StateCache::updateValidBindTextureTypes(Context *context)
8417{
8418 const Extensions &exts = context->getExtensions();
8419 bool isGLES3 = context->getClientMajorVersion() >= 3;
8420 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8421
8422 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008423 {TextureType::_2D, true},
8424 {TextureType::_2DArray, isGLES3},
8425 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8426 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8427 {TextureType::_3D, isGLES3},
8428 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8429 {TextureType::Rectangle, exts.textureRectangle},
8430 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008431 }};
8432}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008433
8434void StateCache::updateValidDrawElementsTypes(Context *context)
8435{
8436 bool supportsUint =
8437 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8438
8439 mCachedValidDrawElementsTypes = {{
8440 {DrawElementsType::UnsignedByte, true},
8441 {DrawElementsType::UnsignedShort, true},
8442 {DrawElementsType::UnsignedInt, supportsUint},
8443 }};
8444}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008445
8446void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8447{
Markus Tavenrathcb9609f2018-12-26 00:52:44 +09008448 TransformFeedback *xfb = context->getGLState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008449 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8450}
Jamie Madillc29968b2016-01-20 11:17:23 -05008451} // namespace gl