blob: 28ee13576f0f3667a967287fe06d5bc3efed78dc [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 Madill46e6c7a2016-01-18 14:42:30 -0500133// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300134EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500135{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400136 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500137}
138
Martin Radev1be913c2016-07-11 17:59:16 +0300139EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
140{
141 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
142}
143
Jamie Madill752d2202018-11-27 13:29:48 -0500144Version GetClientVersion(const egl::AttributeMap &attribs)
Geoff Langeb66a6e2016-10-31 13:06:12 -0400145{
Jamie Madill752d2202018-11-27 13:29:48 -0500146 return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
Geoff Langeb66a6e2016-10-31 13:06:12 -0400147}
148
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149GLenum GetResetStrategy(const egl::AttributeMap &attribs)
150{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800151 EGLAttrib attrib =
152 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153 switch (attrib)
154 {
155 case EGL_NO_RESET_NOTIFICATION:
156 return GL_NO_RESET_NOTIFICATION_EXT;
157 case EGL_LOSE_CONTEXT_ON_RESET:
158 return GL_LOSE_CONTEXT_ON_RESET_EXT;
159 default:
160 UNREACHABLE();
161 return GL_NONE;
162 }
163}
164
165bool GetRobustAccess(const egl::AttributeMap &attribs)
166{
Geoff Lang077f20a2016-11-01 10:08:02 -0400167 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
168 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
169 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500170}
171
172bool GetDebug(const egl::AttributeMap &attribs)
173{
Geoff Lang077f20a2016-11-01 10:08:02 -0400174 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
175 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500176}
177
178bool GetNoError(const egl::AttributeMap &attribs)
179{
180 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
181}
182
Geoff Langc287ea62016-09-16 14:46:51 -0400183bool GetWebGLContext(const egl::AttributeMap &attribs)
184{
Jamie Madill4230d482018-09-14 10:14:45 -0400185 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400186}
187
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400188bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
189{
190 // If the context is WebGL, extensions are disabled by default
191 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
192 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
193}
194
Geoff Langf41a7152016-09-19 15:11:17 -0400195bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
196{
Jamie Madill4230d482018-09-14 10:14:45 -0400197 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400198}
199
Geoff Langfeb8c682017-02-13 16:07:35 -0500200bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
201{
202 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
203}
204
Geoff Langb433e872017-10-05 14:01:47 -0400205bool GetRobustResourceInit(const egl::AttributeMap &attribs)
206{
207 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
208}
209
Martin Radev9d901792016-07-15 15:58:58 +0300210std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
211{
212 std::string labelName;
213 if (label != nullptr)
214 {
215 size_t labelLength = length < 0 ? strlen(label) : length;
216 labelName = std::string(label, labelLength);
217 }
218 return labelName;
219}
220
221void GetObjectLabelBase(const std::string &objectLabel,
222 GLsizei bufSize,
223 GLsizei *length,
224 GLchar *label)
225{
226 size_t writeLength = objectLabel.length();
227 if (label != nullptr && bufSize > 0)
228 {
229 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
230 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
231 label[writeLength] = '\0';
232 }
233
234 if (length != nullptr)
235 {
236 *length = static_cast<GLsizei>(writeLength);
237 }
238}
239
Jamie Madill0f80ed82017-09-19 00:24:56 -0400240template <typename CapT, typename MaxT>
241void LimitCap(CapT *cap, MaxT maximum)
242{
243 *cap = std::min(*cap, static_cast<CapT>(maximum));
244}
245
Jamie Madill752d2202018-11-27 13:29:48 -0500246// The rest default to false.
247constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
248 kValidBasicDrawModes = {{
249 {PrimitiveMode::Points, true},
250 {PrimitiveMode::Lines, true},
251 {PrimitiveMode::LineLoop, true},
252 {PrimitiveMode::LineStrip, true},
253 {PrimitiveMode::Triangles, true},
254 {PrimitiveMode::TriangleStrip, true},
255 {PrimitiveMode::TriangleFan, true},
256 }};
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600257
Jamie Madill6d32cef2018-08-14 02:34:28 -0400258enum SubjectIndexes : angle::SubjectIndex
259{
260 kTexture0SubjectIndex = 0,
Jamie Madille3e680c2018-12-03 17:49:08 -0500261 kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Qin Jiajia3f01f532018-12-11 15:13:51 +0800262 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400263 kUniformBufferMaxSubjectIndex =
Jamie Madille3e680c2018-12-03 17:49:08 -0500264 kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400265 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
Jamie Madille3e680c2018-12-03 17:49:08 -0500266 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Jamie Madille25b8002018-09-20 13:39:49 -0400267 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400268 kReadFramebufferSubjectIndex,
269 kDrawFramebufferSubjectIndex
270};
Geoff Langf6db0982015-08-25 13:04:00 -0400271} // anonymous namespace
272
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400273Context::Context(rx::EGLImplFactory *implFactory,
274 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400275 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500276 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400277 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500278 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700279 const egl::DisplayExtensions &displayExtensions,
280 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500281 : mState(reinterpret_cast<ContextID>(this),
282 shareContext ? &shareContext->mState : nullptr,
283 shareTextures,
284 GetClientVersion(attribs),
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500285 GetDebug(attribs),
286 GetBindGeneratesResource(attribs),
287 GetClientArraysEnabled(attribs),
288 GetRobustResourceInit(attribs),
289 memoryProgramCache != nullptr),
Jamie Madill5b772312018-03-08 20:28:32 -0500290 mSkipValidation(GetNoError(attribs)),
291 mDisplayTextureShareGroup(shareTextures != nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400292 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400293 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400294 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400295 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500296 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400297 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500298 mHasBeenCurrent(false),
299 mContextLost(false),
300 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700301 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500302 mResetStrategy(GetResetStrategy(attribs)),
303 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400304 mSurfacelessSupported(displayExtensions.surfacelessContext),
305 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400306 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
307 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500308 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400309 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400310 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400311 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
312 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
313 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400314 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800315 mZeroFilledBuffer(1000u),
316 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400318 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
319 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
320 {
321 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
322 }
Jamie Madille25b8002018-09-20 13:39:49 -0400323
324 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
325 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
326 {
327 mSamplerObserverBindings.emplace_back(this, samplerIndex);
328 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400329}
Jamie Madill5b772312018-03-08 20:28:32 -0500330
Geoff Lang33f11fb2018-05-07 13:42:47 -0400331void Context::initialize()
332{
333 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400334
Geoff Lang33f11fb2018-05-07 13:42:47 -0400335 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700336 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400337
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500338 mState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100339
Shannon Woods53a94a82014-06-24 15:20:36 -0400340 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400341
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000342 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400343 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344 // and cube map texture state vectors respectively associated with them.
345 // In order that access to these initial textures not be lost, they are treated as texture
346 // objects all of whose names are 0.
347
Corentin Wallez99d492c2018-02-27 15:17:10 -0500348 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800349 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500350
Corentin Wallez99d492c2018-02-27 15:17:10 -0500351 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800352 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400353
Geoff Langeb66a6e2016-10-31 13:06:12 -0400354 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400355 {
356 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400359
Corentin Wallez99d492c2018-02-27 15:17:10 -0500360 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800361 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400362 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800363 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400364 {
365 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500366 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800367 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800368 }
369 if (getClientVersion() >= Version(3, 1))
370 {
Olli Etuahod310a432018-08-24 15:40:23 +0300371 Texture *zeroTexture2DMultisampleArray =
372 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
373 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800374
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500375 for (unsigned int i = 0; i < mState.mCaps.maxAtomicCounterBufferBindings; i++)
Jiajia Qin6eafb042016-12-27 17:04:07 +0800376 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800377 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800378 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800379
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500380 for (unsigned int i = 0; i < mState.mCaps.maxShaderStorageBufferBindings; i++)
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800381 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400382 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800383 }
Geoff Lang3b573612016-10-31 14:08:10 -0400384 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000385
Geoff Langb0f917f2017-12-05 13:41:54 -0500386 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400387 {
388 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500389 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800390 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400391 }
392
Geoff Langb0f917f2017-12-05 13:41:54 -0500393 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400394 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500395 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800396 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400397 }
398
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500399 mState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500400
Jamie Madill57a89722013-07-02 11:57:03 -0400401 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000402
Geoff Langeb66a6e2016-10-31 13:06:12 -0400403 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400404 {
405 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
406 // In the initial state, a default transform feedback object is bound and treated as
407 // a transform feedback object with a name of zero. That object is bound any time
408 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400409 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400410 }
Geoff Langc8058452014-02-03 12:04:11 -0500411
Corentin Wallez336129f2017-10-17 15:55:40 -0400412 for (auto type : angle::AllEnums<BufferBinding>())
413 {
414 bindBuffer(type, 0);
415 }
416
417 bindRenderbuffer(GL_RENDERBUFFER, 0);
418
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500419 for (unsigned int i = 0; i < mState.mCaps.maxUniformBufferBindings; i++)
Corentin Wallez336129f2017-10-17 15:55:40 -0400420 {
421 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
422 }
423
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700424 // Initialize GLES1 renderer if appropriate.
425 if (getClientVersion() < Version(2, 0))
426 {
427 mGLES1Renderer.reset(new GLES1Renderer());
428 }
429
Jamie Madillad9f24e2016-02-12 09:27:24 -0500430 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400431 mAllDirtyBits.set();
432
Geoff Lang9bf86f02018-07-26 11:46:34 -0400433 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
434 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500435 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400436 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400437 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400438
439 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
440 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500441 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400442 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400443
Jamie Madillc67323a2017-11-02 23:11:41 -0400444 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500445 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500446 // No dirty objects.
447
448 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400449 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500450 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400451 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500452 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
453
454 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
455 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
456 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
457 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
458 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
459 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
460 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
461 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
462 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
463 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
464 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400465 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500466 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
467
468 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
469 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700470 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400471 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
472 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500473 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
474 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400475
Xinghua Cao10a4d432017-11-28 14:46:26 +0800476 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800477 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
478 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800479 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
480 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
481 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
482 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800483 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800484 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500485 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400486 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400487 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800488
Jamie Madillb4927eb2018-07-16 11:39:46 -0400489 mImplementation->setErrorSet(&mErrors);
490
Jamie Madill4f6592f2018-11-27 16:37:45 -0500491 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000492}
493
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700496 if (mGLES1Renderer)
497 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500498 mGLES1Renderer->onDestroy(this, &mState);
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700499 }
500
Jamie Madille7b3fe22018-04-05 09:42:46 -0400501 ANGLE_TRY(releaseSurface(display));
502
Corentin Wallez80b24112015-08-25 16:41:57 -0400503 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400505 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400507 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508
Corentin Wallez80b24112015-08-25 16:41:57 -0400509 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400511 if (query.second != nullptr)
512 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400514 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400516 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517
Corentin Wallez80b24112015-08-25 16:41:57 -0400518 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400519 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400520 if (vertexArray.second)
521 {
522 vertexArray.second->onDestroy(this);
523 }
Jamie Madill57a89722013-07-02 11:57:03 -0400524 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400525 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400526
Corentin Wallez80b24112015-08-25 16:41:57 -0400527 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500528 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500529 if (transformFeedback.second != nullptr)
530 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500531 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500532 }
Geoff Langc8058452014-02-03 12:04:11 -0500533 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400534 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500535
Jamie Madill5b772312018-03-08 20:28:32 -0500536 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400537 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800538 if (zeroTexture.get() != nullptr)
539 {
Jamie Madill1c7f08c2018-10-10 16:13:02 -0400540 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800541 zeroTexture.set(this, nullptr);
542 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400543 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000544
Jamie Madill2f348d22017-06-05 10:50:59 -0400545 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500546
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500547 mState.reset(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400548
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500549 mState.mBufferManager->release(this);
550 mState.mShaderProgramManager->release(this);
551 mState.mTextureManager->release(this);
552 mState.mRenderbufferManager->release(this);
553 mState.mSamplerManager->release(this);
554 mState.mSyncManager->release(this);
555 mState.mPathManager->release(this);
556 mState.mFramebufferManager->release(this);
557 mState.mProgramPipelineManager->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400558
jchen107ae70d82018-07-06 13:47:01 +0800559 mThreadPool.reset();
560
Jamie Madill76e471e2017-10-21 09:56:01 -0400561 mImplementation->onDestroy(this);
562
Jamie Madill4928b7c2017-06-20 12:57:39 -0400563 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
Jamie Madillb980c562018-11-27 11:34:27 -0500566Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500567
Geoff Lang75359662018-04-11 01:42:27 -0400568void Context::setLabel(EGLLabelKHR label)
569{
570 mLabel = label;
571}
572
573EGLLabelKHR Context::getLabel() const
574{
575 return mLabel;
576}
577
Jamie Madill4928b7c2017-06-20 12:57:39 -0400578egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000579{
Jamie Madill61e16b42017-06-19 11:13:23 -0400580 mCurrentDisplay = display;
581
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000582 if (!mHasBeenCurrent)
583 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400584 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500586 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400587 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000588
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 int width = 0;
590 int height = 0;
591 if (surface != nullptr)
592 {
593 width = surface->getWidth();
594 height = surface->getHeight();
595 }
596
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500597 mState.setViewportParams(0, 0, width, height);
598 mState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599
600 mHasBeenCurrent = true;
601 }
602
Jamie Madill1b94d432015-08-07 13:23:23 -0400603 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500604 mState.setAllDirtyBits();
605 mState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400606
Jamie Madill4928b7c2017-06-20 12:57:39 -0400607 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500608
609 Framebuffer *newDefault = nullptr;
610 if (surface != nullptr)
611 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500613 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400614 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500615 }
616 else
617 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400618 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500619 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000620
Corentin Wallez37c39792015-08-20 14:19:46 -0400621 // Update default framebuffer, the binding of the previous default
622 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400623 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500624 mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
625 if (mState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400626 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400627 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400628 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500629 if (mState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400630 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400631 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400632 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400633 }
Ian Ewell292f0052016-02-04 10:37:32 -0500634
Jamie Madill32643ce2018-10-19 11:38:03 -0400635 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500636 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
Jamie Madill4928b7c2017-06-20 12:57:39 -0400639egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400640{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500641 gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400642
Geoff Langbf7b95d2018-05-01 16:48:21 -0400643 // Remove the default framebuffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500644 if (mState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500645 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500646 mState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400647 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500648 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400649
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500650 if (mState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500651 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500652 mState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400653 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500654 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400655
656 if (defaultFramebuffer)
657 {
658 defaultFramebuffer->onDestroy(this);
659 delete defaultFramebuffer;
660 }
661
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500662 mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500663
664 if (mCurrentSurface)
665 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400666 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500667 mCurrentSurface = nullptr;
668 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400669
670 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400671}
672
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673GLuint Context::createBuffer()
674{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500675 return mState.mBufferManager->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676}
677
678GLuint Context::createProgram()
679{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500680 return mState.mShaderProgramManager->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
Jiawei Shao385b3e02018-03-21 09:43:28 +0800683GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500685 return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
686 type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
689GLuint Context::createTexture()
690{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500691 return mState.mTextureManager->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
694GLuint Context::createRenderbuffer()
695{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500696 return mState.mRenderbufferManager->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697}
698
Jamie Madill13951342018-09-30 15:24:28 -0400699void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
700{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500701 ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400702}
703
Brandon Jones59770802018-04-02 13:18:42 -0700704GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300705{
Jamie Madill13951342018-09-30 15:24:28 -0400706 GLuint created = 0;
707 tryGenPaths(range, &created);
708 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300709}
710
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711// Returns an unused framebuffer name
712GLuint Context::createFramebuffer()
713{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500714 return mState.mFramebufferManager->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715}
716
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500717void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500719 for (int i = 0; i < n; i++)
720 {
721 GLuint handle = mFenceNVHandleAllocator.allocate();
722 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
723 fences[i] = handle;
724 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
Yunchao Hea336b902017-08-02 16:05:21 +0800727GLuint Context::createProgramPipeline()
728{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500729 return mState.mProgramPipelineManager->createProgramPipeline();
Yunchao Hea336b902017-08-02 16:05:21 +0800730}
731
Jiawei Shao385b3e02018-03-21 09:43:28 +0800732GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800733{
734 UNIMPLEMENTED();
735 return 0u;
736}
737
James Darpinian4d9d4832018-03-13 12:43:28 -0700738void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500740 Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
James Darpinian4d9d4832018-03-13 12:43:28 -0700741 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000742 {
743 detachBuffer(buffer);
744 }
Jamie Madill893ab082014-05-16 16:56:10 -0400745
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500746 mState.mBufferManager->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000747}
748
749void Context::deleteShader(GLuint shader)
750{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500751 mState.mShaderProgramManager->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000752}
753
754void Context::deleteProgram(GLuint program)
755{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500756 mState.mShaderProgramManager->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000757}
758
759void Context::deleteTexture(GLuint texture)
760{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500761 if (mState.mTextureManager->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000762 {
763 detachTexture(texture);
764 }
765
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500766 mState.mTextureManager->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767}
768
769void Context::deleteRenderbuffer(GLuint renderbuffer)
770{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500771 if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772 {
773 detachRenderbuffer(renderbuffer);
774 }
Jamie Madill893ab082014-05-16 16:56:10 -0400775
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500776 mState.mRenderbufferManager->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777}
778
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400779void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400780{
781 // The spec specifies the underlying Fence object is not deleted until all current
782 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
783 // and since our API is currently designed for being called from a single thread, we can delete
784 // the fence immediately.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500785 mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400786}
787
Yunchao Hea336b902017-08-02 16:05:21 +0800788void Context::deleteProgramPipeline(GLuint pipeline)
789{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500790 if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
Yunchao Hea336b902017-08-02 16:05:21 +0800791 {
792 detachProgramPipeline(pipeline);
793 }
794
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500795 mState.mProgramPipelineManager->deleteObject(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +0800796}
797
Sami Väisänene45e53b2016-05-25 10:36:04 +0300798void Context::deletePaths(GLuint first, GLsizei range)
799{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500800 mState.mPathManager->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801}
802
Brandon Jones59770802018-04-02 13:18:42 -0700803bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300804{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500805 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300806 if (pathObj == nullptr)
807 return false;
808
809 return pathObj->hasPathData();
810}
811
Brandon Jones59770802018-04-02 13:18:42 -0700812bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300813{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500814 return mState.mPathManager->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300815}
816
Brandon Jones59770802018-04-02 13:18:42 -0700817void Context::pathCommands(GLuint path,
818 GLsizei numCommands,
819 const GLubyte *commands,
820 GLsizei numCoords,
821 GLenum coordType,
822 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500824 auto *pathObject = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825
Jamie Madill4f6592f2018-11-27 16:37:45 -0500826 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300827}
828
Jamie Madill007530e2017-12-28 14:27:04 -0500829void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300830{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500831 Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300832
833 switch (pname)
834 {
835 case GL_PATH_STROKE_WIDTH_CHROMIUM:
836 pathObj->setStrokeWidth(value);
837 break;
838 case GL_PATH_END_CAPS_CHROMIUM:
839 pathObj->setEndCaps(static_cast<GLenum>(value));
840 break;
841 case GL_PATH_JOIN_STYLE_CHROMIUM:
842 pathObj->setJoinStyle(static_cast<GLenum>(value));
843 break;
844 case GL_PATH_MITER_LIMIT_CHROMIUM:
845 pathObj->setMiterLimit(value);
846 break;
847 case GL_PATH_STROKE_BOUND_CHROMIUM:
848 pathObj->setStrokeBound(value);
849 break;
850 default:
851 UNREACHABLE();
852 break;
853 }
854}
855
Jamie Madill007530e2017-12-28 14:27:04 -0500856void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857{
Jamie Madill007530e2017-12-28 14:27:04 -0500858 // TODO(jmadill): Should use proper clamping/casting.
859 pathParameterf(path, pname, static_cast<GLfloat>(value));
860}
861
862void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
863{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500864 const Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300865
866 switch (pname)
867 {
868 case GL_PATH_STROKE_WIDTH_CHROMIUM:
869 *value = pathObj->getStrokeWidth();
870 break;
871 case GL_PATH_END_CAPS_CHROMIUM:
872 *value = static_cast<GLfloat>(pathObj->getEndCaps());
873 break;
874 case GL_PATH_JOIN_STYLE_CHROMIUM:
875 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
876 break;
877 case GL_PATH_MITER_LIMIT_CHROMIUM:
878 *value = pathObj->getMiterLimit();
879 break;
880 case GL_PATH_STROKE_BOUND_CHROMIUM:
881 *value = pathObj->getStrokeBound();
882 break;
883 default:
884 UNREACHABLE();
885 break;
886 }
887}
888
Jamie Madill007530e2017-12-28 14:27:04 -0500889void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
890{
891 GLfloat val = 0.0f;
892 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
893 if (value)
894 *value = static_cast<GLint>(val);
895}
896
Brandon Jones59770802018-04-02 13:18:42 -0700897void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300898{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500899 mState.setPathStencilFunc(func, ref, mask);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300900}
901
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000902void Context::deleteFramebuffer(GLuint framebuffer)
903{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500904 if (mState.mFramebufferManager->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000905 {
906 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000907 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500908
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500909 mState.mFramebufferManager->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000910}
911
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500912void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000913{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500914 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000915 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500916 GLuint fence = fences[i];
917
918 FenceNV *fenceObject = nullptr;
919 if (mFenceNVMap.erase(fence, &fenceObject))
920 {
921 mFenceNVHandleAllocator.release(fence);
922 delete fenceObject;
923 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000924 }
925}
926
Geoff Lang70d0f492015-12-10 17:45:46 -0500927Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000928{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500929 return mState.mBufferManager->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930}
931
Geoff Lang70d0f492015-12-10 17:45:46 -0500932Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000933{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500934 return mState.mRenderbufferManager->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000935}
936
Jamie Madill70b5bb02017-08-28 13:32:37 -0400937Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400938{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500939 return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400940}
941
Jamie Madill57a89722013-07-02 11:57:03 -0400942VertexArray *Context::getVertexArray(GLuint handle) const
943{
Jamie Madill96a483b2017-06-27 16:49:21 -0400944 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400945}
946
Jamie Madilldc356042013-07-19 16:36:57 -0400947Sampler *Context::getSampler(GLuint handle) const
948{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500949 return mState.mSamplerManager->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400950}
951
Geoff Langc8058452014-02-03 12:04:11 -0500952TransformFeedback *Context::getTransformFeedback(GLuint handle) const
953{
Jamie Madill96a483b2017-06-27 16:49:21 -0400954 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500955}
956
Yunchao Hea336b902017-08-02 16:05:21 +0800957ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
958{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500959 return mState.mProgramPipelineManager->getProgramPipeline(handle);
Yunchao Hea336b902017-08-02 16:05:21 +0800960}
961
Geoff Lang75359662018-04-11 01:42:27 -0400962gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500963{
964 switch (identifier)
965 {
966 case GL_BUFFER:
967 return getBuffer(name);
968 case GL_SHADER:
969 return getShader(name);
970 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -0400971 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -0500972 case GL_VERTEX_ARRAY:
973 return getVertexArray(name);
974 case GL_QUERY:
975 return getQuery(name);
976 case GL_TRANSFORM_FEEDBACK:
977 return getTransformFeedback(name);
978 case GL_SAMPLER:
979 return getSampler(name);
980 case GL_TEXTURE:
981 return getTexture(name);
982 case GL_RENDERBUFFER:
983 return getRenderbuffer(name);
984 case GL_FRAMEBUFFER:
985 return getFramebuffer(name);
986 default:
987 UNREACHABLE();
988 return nullptr;
989 }
990}
991
Geoff Lang75359662018-04-11 01:42:27 -0400992gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500993{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400994 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500995}
996
Martin Radev9d901792016-07-15 15:58:58 +0300997void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
998{
Geoff Lang75359662018-04-11 01:42:27 -0400999 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001000 ASSERT(object != nullptr);
1001
1002 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001003 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001004
1005 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1006 // specified object is active until we do this.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001007 mState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001008}
1009
1010void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1011{
Geoff Lang75359662018-04-11 01:42:27 -04001012 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001013 ASSERT(object != nullptr);
1014
1015 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001016 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001017}
1018
1019void Context::getObjectLabel(GLenum identifier,
1020 GLuint name,
1021 GLsizei bufSize,
1022 GLsizei *length,
1023 GLchar *label) const
1024{
Geoff Lang75359662018-04-11 01:42:27 -04001025 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001026 ASSERT(object != nullptr);
1027
1028 const std::string &objectLabel = object->getLabel();
1029 GetObjectLabelBase(objectLabel, bufSize, length, label);
1030}
1031
1032void Context::getObjectPtrLabel(const void *ptr,
1033 GLsizei bufSize,
1034 GLsizei *length,
1035 GLchar *label) const
1036{
Geoff Lang75359662018-04-11 01:42:27 -04001037 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001038 ASSERT(object != nullptr);
1039
1040 const std::string &objectLabel = object->getLabel();
1041 GetObjectLabelBase(objectLabel, bufSize, length, label);
1042}
1043
Jamie Madilldc356042013-07-19 16:36:57 -04001044bool Context::isSampler(GLuint samplerName) const
1045{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001046 return mState.mSamplerManager->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001047}
1048
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001049void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001050{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001051 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001052
Jamie Madilldedd7b92014-11-05 16:30:36 -05001053 if (handle == 0)
1054 {
1055 texture = mZeroTextures[target].get();
1056 }
1057 else
1058 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001059 texture =
1060 mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001061 }
1062
1063 ASSERT(texture);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001064 mState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001065 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001066}
1067
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001068void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001070 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1071 mImplementation.get(), mState.mCaps, framebufferHandle);
1072 mState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001073 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074}
1075
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001076void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001078 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1079 mImplementation.get(), mState.mCaps, framebufferHandle);
1080 mState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001081 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001082 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083}
1084
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001085void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001086{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001087 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001088 mState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001089 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001090 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001091}
1092
Shao80957d92017-02-20 21:25:59 +08001093void Context::bindVertexBuffer(GLuint bindingIndex,
1094 GLuint bufferHandle,
1095 GLintptr offset,
1096 GLsizei stride)
1097{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001098 Buffer *buffer =
1099 mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
1100 mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001101 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001102}
1103
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001104void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001105{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001106 ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001107 Sampler *sampler =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001108 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
1109 mState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001110 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001111}
1112
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001113void Context::bindImageTexture(GLuint unit,
1114 GLuint texture,
1115 GLint level,
1116 GLboolean layered,
1117 GLint layer,
1118 GLenum access,
1119 GLenum format)
1120{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001121 Texture *tex = mState.mTextureManager->getTexture(texture);
1122 mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001123}
1124
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001125void Context::useProgram(GLuint program)
1126{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001127 ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001128 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001129}
1130
Jiajia Qin5451d532017-11-16 17:16:34 +08001131void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1132{
1133 UNIMPLEMENTED();
1134}
1135
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001136void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001137{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001138 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001139 TransformFeedback *transformFeedback =
1140 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001141 mState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001142}
1143
Yunchao Hea336b902017-08-02 16:05:21 +08001144void Context::bindProgramPipeline(GLuint pipelineHandle)
1145{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001146 ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
1147 mImplementation.get(), pipelineHandle);
1148 mState.setProgramPipelineBinding(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08001149}
1150
Corentin Wallezad3ae902018-03-09 13:40:42 -05001151void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001154 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155
Geoff Lang5aad9672014-09-08 11:10:42 -04001156 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001157 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001158
1159 // set query as active for specified target only if begin succeeded
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001160 mState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001161 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162}
1163
Corentin Wallezad3ae902018-03-09 13:40:42 -05001164void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001166 Query *queryObject = mState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001167 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168
Jamie Madill4f6592f2018-11-27 16:37:45 -05001169 // Intentionally don't call try here. We don't want an early return.
1170 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171
Geoff Lang5aad9672014-09-08 11:10:42 -04001172 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001173 mState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001174 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001175}
1176
Corentin Wallezad3ae902018-03-09 13:40:42 -05001177void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001179 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001180
1181 Query *queryObject = getQuery(id, true, target);
1182 ASSERT(queryObject);
1183
Jamie Madill4f6592f2018-11-27 16:37:45 -05001184 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185}
1186
Corentin Wallezad3ae902018-03-09 13:40:42 -05001187void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188{
1189 switch (pname)
1190 {
1191 case GL_CURRENT_QUERY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001192 params[0] = mState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001193 break;
1194 case GL_QUERY_COUNTER_BITS_EXT:
1195 switch (target)
1196 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001197 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1199 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001200 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201 params[0] = getExtensions().queryCounterBitsTimestamp;
1202 break;
1203 default:
1204 UNREACHABLE();
1205 params[0] = 0;
1206 break;
1207 }
1208 break;
1209 default:
1210 UNREACHABLE();
1211 return;
1212 }
1213}
1214
Corentin Wallezad3ae902018-03-09 13:40:42 -05001215void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001216 GLenum pname,
1217 GLsizei bufSize,
1218 GLsizei *length,
1219 GLint *params)
1220{
1221 getQueryiv(target, pname, params);
1222}
1223
Geoff Lang2186c382016-10-14 10:54:54 -04001224void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001226 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227}
1228
Brandon Jones59770802018-04-02 13:18:42 -07001229void Context::getQueryObjectivRobust(GLuint id,
1230 GLenum pname,
1231 GLsizei bufSize,
1232 GLsizei *length,
1233 GLint *params)
1234{
1235 getQueryObjectiv(id, pname, params);
1236}
1237
Geoff Lang2186c382016-10-14 10:54:54 -04001238void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001240 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241}
1242
Brandon Jones59770802018-04-02 13:18:42 -07001243void Context::getQueryObjectuivRobust(GLuint id,
1244 GLenum pname,
1245 GLsizei bufSize,
1246 GLsizei *length,
1247 GLuint *params)
1248{
1249 getQueryObjectuiv(id, pname, params);
1250}
1251
Geoff Lang2186c382016-10-14 10:54:54 -04001252void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001253{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001254 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001255}
1256
Brandon Jones59770802018-04-02 13:18:42 -07001257void Context::getQueryObjecti64vRobust(GLuint id,
1258 GLenum pname,
1259 GLsizei bufSize,
1260 GLsizei *length,
1261 GLint64 *params)
1262{
1263 getQueryObjecti64v(id, pname, params);
1264}
1265
Geoff Lang2186c382016-10-14 10:54:54 -04001266void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001268 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001269}
1270
Brandon Jones59770802018-04-02 13:18:42 -07001271void Context::getQueryObjectui64vRobust(GLuint id,
1272 GLenum pname,
1273 GLsizei bufSize,
1274 GLsizei *length,
1275 GLuint64 *params)
1276{
1277 getQueryObjectui64v(id, pname, params);
1278}
1279
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001280Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001282 return mState.mFramebufferManager->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283}
1284
Jamie Madill2f348d22017-06-05 10:50:59 -04001285FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286{
Jamie Madill96a483b2017-06-27 16:49:21 -04001287 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288}
1289
Corentin Wallezad3ae902018-03-09 13:40:42 -05001290Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291{
Jamie Madill96a483b2017-06-27 16:49:21 -04001292 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001294 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001295 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001296
1297 Query *query = mQueryMap.query(handle);
1298 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001300 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001301 query = new Query(mImplementation->createQuery(type), handle);
1302 query->addRef();
1303 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001304 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001305 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001306}
1307
Geoff Lang70d0f492015-12-10 17:45:46 -05001308Query *Context::getQuery(GLuint handle) const
1309{
Jamie Madill96a483b2017-06-27 16:49:21 -04001310 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001311}
1312
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001313Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001314{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001315 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001316 return mState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001317}
1318
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001319Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001321 return mState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322}
1323
Geoff Lang492a7e42014-11-05 13:27:06 -05001324Compiler *Context::getCompiler() const
1325{
Jamie Madill2f348d22017-06-05 10:50:59 -04001326 if (mCompiler.get() == nullptr)
1327 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001328 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001329 }
1330 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001331}
1332
Jamie Madillc1d770e2017-04-13 17:31:24 -04001333void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001334{
1335 switch (pname)
1336 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001337 case GL_SHADER_COMPILER:
1338 *params = GL_TRUE;
1339 break;
1340 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1341 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1342 break;
1343 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001344 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001345 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347}
1348
Jamie Madillc1d770e2017-04-13 17:31:24 -04001349void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001350{
Shannon Woods53a94a82014-06-24 15:20:36 -04001351 // Queries about context capabilities and maximums are answered by Context.
1352 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001353 switch (pname)
1354 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001355 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001356 params[0] = mState.mCaps.minAliasedLineWidth;
1357 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001358 break;
1359 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001360 params[0] = mState.mCaps.minAliasedPointSize;
1361 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001362 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001363 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001364 params[0] = mState.mCaps.minSmoothPointSize;
1365 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001366 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001367 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001368 params[0] = mState.mCaps.minSmoothLineWidth;
1369 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001370 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001371 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001372 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1373 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001374 break;
1375 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001376 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001377 break;
1378
1379 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1380 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1381 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001382 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1383 // GLES1 constants for modelview/projection matrix.
1384 if (getClientVersion() < Version(2, 0))
1385 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001386 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001387 }
1388 else
1389 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001390 ASSERT(mState.mExtensions.pathRendering);
1391 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001392 memcpy(params, m, 16 * sizeof(GLfloat));
1393 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001395 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001396
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001398 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001399 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401}
1402
Jamie Madillc1d770e2017-04-13 17:31:24 -04001403void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001404{
Shannon Woods53a94a82014-06-24 15:20:36 -04001405 // Queries about context capabilities and maximums are answered by Context.
1406 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001407
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001408 switch (pname)
1409 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001411 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001412 break;
1413 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001414 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 break;
1416 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001417 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001418 break;
1419 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001420 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001421 break;
1422 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001423 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001424 break;
1425 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001426 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001427 break;
1428 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001429 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 break;
1431 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001432 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001433 break;
1434 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001435 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001436 break;
1437 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001438 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 break;
1440 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001441 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001442 break;
1443 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001444 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001445 break;
1446 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001447 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001449 case GL_SUBPIXEL_BITS:
1450 *params = 4;
1451 break;
1452 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001453 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001454 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001455 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001456 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001457 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001458 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001459 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 break;
1461 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001462 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001463 break;
1464 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001465 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 break;
1467 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001468 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001469 break;
1470 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001471 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 break;
1473 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001474 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 break;
1476 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001477 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001478 break;
1479 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001480 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 break;
1482 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001483 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001484 break;
1485 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001486 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 break;
1488 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001489 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001490 break;
1491 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001492 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001493 break;
1494 case GL_MAJOR_VERSION:
1495 *params = getClientVersion().major;
1496 break;
1497 case GL_MINOR_VERSION:
1498 *params = getClientVersion().minor;
1499 break;
1500 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001501 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001502 break;
1503 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001504 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001505 break;
1506 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001507 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001508 break;
1509 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001510 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001511 break;
1512 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001513 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001514 break;
1515 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001516 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001517 break;
1518 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001519 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001520 break;
1521 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001522 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001523 params[0] = mState.mCaps.maxViewportWidth;
1524 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001525 }
1526 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001527 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001528 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1529 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001530 break;
1531 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1532 *params = mResetStrategy;
1533 break;
1534 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001535 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 break;
1537 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001538 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1539 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001540 break;
1541 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001542 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001545 std::copy(mState.mCaps.programBinaryFormats.begin(),
1546 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001547 break;
1548 case GL_NUM_EXTENSIONS:
1549 *params = static_cast<GLint>(mExtensionStrings.size());
1550 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001551
Geoff Lang38f24ee2018-10-01 13:04:59 -04001552 // GL_ANGLE_request_extension
1553 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1554 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1555 break;
1556
Jamie Madill231c7f52017-04-26 13:45:37 -04001557 // GL_KHR_debug
1558 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001559 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001560 break;
1561 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001562 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001563 break;
1564 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001565 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 break;
1567 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001568 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001569 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001570
Martin Radeve5285d22017-07-14 16:23:53 +03001571 // GL_ANGLE_multiview
1572 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001573 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001574 break;
1575
Jamie Madill231c7f52017-04-26 13:45:37 -04001576 // GL_EXT_disjoint_timer_query
1577 case GL_GPU_DISJOINT_EXT:
1578 *params = mImplementation->getGPUDisjoint();
1579 break;
1580 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001581 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001582 break;
1583 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001584 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001587 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001588 break;
1589 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001590 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001593 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 break;
1595 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001596 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 break;
1598 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001599 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 break;
1601 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001602 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001603 break;
1604 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001605 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001606 break;
1607 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001608 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001609 break;
1610 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001611 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001612 break;
1613 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001614 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001615 break;
1616 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001617 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001618 break;
1619 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001620 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001621 break;
1622 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001623 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001624 break;
1625 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001626 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001627 break;
1628 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001629 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001630 break;
1631 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001632 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001633 break;
1634 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001635 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001636 break;
1637 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001638 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001639 break;
1640 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001641 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 break;
1643 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001644 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001645 break;
1646 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001647 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001650 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001653 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001656 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001657 break;
1658 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001659 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001662 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001665 *params = static_cast<GLint>(
1666 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001669 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001672 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001673 break;
1674 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001675 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001676 break;
1677 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001678 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001679 break;
1680 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001681 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001684 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 break;
1686 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001687 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001688 break;
1689 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001690 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 break;
1692 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001693 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001696 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001699 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 break;
1701 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001702 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001704
1705 // GL_EXT_geometry_shader
1706 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001707 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001708 break;
1709 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001710 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001711 break;
1712 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001713 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001714 break;
1715 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001716 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001717 break;
1718 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001719 *params = static_cast<GLint>(
1720 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001721 break;
1722 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001723 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001724 break;
1725 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001726 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001727 break;
1728 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001729 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001730 break;
1731 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001732 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001733 break;
1734 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001735 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001736 break;
1737 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001738 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001739 break;
1740 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001741 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001742 break;
1743 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001744 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001745 break;
1746 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001747 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001748 break;
1749 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001750 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001751 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001752 // GLES1 emulation: Caps queries
1753 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001754 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001755 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001756 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001757 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001758 break;
1759 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001760 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001761 break;
1762 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001763 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001764 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001765 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001766 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001767 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001768 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001769 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001770 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001771 // GLES1 emulation: Vertex attribute queries
1772 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1773 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1774 case GL_COLOR_ARRAY_BUFFER_BINDING:
1775 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1776 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1777 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1778 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1779 break;
1780 case GL_VERTEX_ARRAY_STRIDE:
1781 case GL_NORMAL_ARRAY_STRIDE:
1782 case GL_COLOR_ARRAY_STRIDE:
1783 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1784 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1785 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1786 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1787 break;
1788 case GL_VERTEX_ARRAY_SIZE:
1789 case GL_COLOR_ARRAY_SIZE:
1790 case GL_TEXTURE_COORD_ARRAY_SIZE:
1791 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1792 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1793 break;
1794 case GL_VERTEX_ARRAY_TYPE:
1795 case GL_COLOR_ARRAY_TYPE:
1796 case GL_NORMAL_ARRAY_TYPE:
1797 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1798 case GL_TEXTURE_COORD_ARRAY_TYPE:
1799 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1800 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1801 break;
1802
jchen1082af6202018-06-22 10:59:52 +08001803 // GL_KHR_parallel_shader_compile
1804 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001805 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001806 break;
1807
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001808 // GL_EXT_blend_func_extended
1809 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001810 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001811 break;
1812
Jamie Madill231c7f52017-04-26 13:45:37 -04001813 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001814 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001815 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001816 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001817}
1818
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001819void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001820{
Shannon Woods53a94a82014-06-24 15:20:36 -04001821 // Queries about context capabilities and maximums are answered by Context.
1822 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001823 switch (pname)
1824 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001826 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001827 break;
1828 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001829 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001830 break;
1831 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001832 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001833 break;
1834 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001835 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001836 break;
1837 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001838 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001840
Jamie Madill231c7f52017-04-26 13:45:37 -04001841 // GL_EXT_disjoint_timer_query
1842 case GL_TIMESTAMP_EXT:
1843 *params = mImplementation->getTimestamp();
1844 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001845
Jamie Madill231c7f52017-04-26 13:45:37 -04001846 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001847 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001848 break;
1849 default:
1850 UNREACHABLE();
1851 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001852 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001853}
1854
Geoff Lang70d0f492015-12-10 17:45:46 -05001855void Context::getPointerv(GLenum pname, void **params) const
1856{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001857 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001858}
1859
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001860void Context::getPointervRobustANGLERobust(GLenum pname,
1861 GLsizei bufSize,
1862 GLsizei *length,
1863 void **params)
1864{
1865 UNIMPLEMENTED();
1866}
1867
Martin Radev66fb8202016-07-28 11:45:20 +03001868void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001869{
Shannon Woods53a94a82014-06-24 15:20:36 -04001870 // Queries about context capabilities and maximums are answered by Context.
1871 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001872
1873 GLenum nativeType;
1874 unsigned int numParams;
1875 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1876 ASSERT(queryStatus);
1877
1878 if (nativeType == GL_INT)
1879 {
1880 switch (target)
1881 {
1882 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1883 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001884 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001885 break;
1886 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1887 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001888 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001889 break;
1890 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001891 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001892 }
1893 }
1894 else
1895 {
1896 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1897 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001898}
1899
Brandon Jones59770802018-04-02 13:18:42 -07001900void Context::getIntegeri_vRobust(GLenum target,
1901 GLuint index,
1902 GLsizei bufSize,
1903 GLsizei *length,
1904 GLint *data)
1905{
1906 getIntegeri_v(target, index, data);
1907}
1908
Martin Radev66fb8202016-07-28 11:45:20 +03001909void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001910{
Shannon Woods53a94a82014-06-24 15:20:36 -04001911 // Queries about context capabilities and maximums are answered by Context.
1912 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001913
1914 GLenum nativeType;
1915 unsigned int numParams;
1916 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1917 ASSERT(queryStatus);
1918
1919 if (nativeType == GL_INT_64_ANGLEX)
1920 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001921 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001922 }
1923 else
1924 {
1925 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1926 }
1927}
1928
Brandon Jones59770802018-04-02 13:18:42 -07001929void Context::getInteger64i_vRobust(GLenum target,
1930 GLuint index,
1931 GLsizei bufSize,
1932 GLsizei *length,
1933 GLint64 *data)
1934{
1935 getInteger64i_v(target, index, data);
1936}
1937
Martin Radev66fb8202016-07-28 11:45:20 +03001938void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1939{
1940 // Queries about context capabilities and maximums are answered by Context.
1941 // Queries about current GL state values are answered by State.
1942
1943 GLenum nativeType;
1944 unsigned int numParams;
1945 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1946 ASSERT(queryStatus);
1947
1948 if (nativeType == GL_BOOL)
1949 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001950 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001951 }
1952 else
1953 {
1954 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1955 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001956}
1957
Brandon Jones59770802018-04-02 13:18:42 -07001958void Context::getBooleani_vRobust(GLenum target,
1959 GLuint index,
1960 GLsizei bufSize,
1961 GLsizei *length,
1962 GLboolean *data)
1963{
1964 getBooleani_v(target, index, data);
1965}
1966
Corentin Wallez336129f2017-10-17 15:55:40 -04001967void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001968{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001969 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001970 QueryBufferParameteriv(buffer, pname, params);
1971}
1972
Brandon Jones59770802018-04-02 13:18:42 -07001973void Context::getBufferParameterivRobust(BufferBinding target,
1974 GLenum pname,
1975 GLsizei bufSize,
1976 GLsizei *length,
1977 GLint *params)
1978{
1979 getBufferParameteriv(target, pname, params);
1980}
1981
He Yunchao010e4db2017-03-03 14:22:06 +08001982void Context::getFramebufferAttachmentParameteriv(GLenum target,
1983 GLenum attachment,
1984 GLenum pname,
1985 GLint *params)
1986{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001987 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001988 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001989}
1990
Brandon Jones59770802018-04-02 13:18:42 -07001991void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1992 GLenum attachment,
1993 GLenum pname,
1994 GLsizei bufSize,
1995 GLsizei *length,
1996 GLint *params)
1997{
1998 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1999}
2000
He Yunchao010e4db2017-03-03 14:22:06 +08002001void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2002{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002003 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08002004 QueryRenderbufferiv(this, renderbuffer, pname, params);
2005}
2006
Brandon Jones59770802018-04-02 13:18:42 -07002007void Context::getRenderbufferParameterivRobust(GLenum target,
2008 GLenum pname,
2009 GLsizei bufSize,
2010 GLsizei *length,
2011 GLint *params)
2012{
2013 getRenderbufferParameteriv(target, pname, params);
2014}
2015
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002016void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002017{
Till Rathmannb8543632018-10-02 19:46:14 +02002018 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002019 QueryTexParameterfv(texture, pname, params);
2020}
2021
Brandon Jones59770802018-04-02 13:18:42 -07002022void Context::getTexParameterfvRobust(TextureType target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLfloat *params)
2027{
2028 getTexParameterfv(target, pname, params);
2029}
2030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002031void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002032{
Till Rathmannb8543632018-10-02 19:46:14 +02002033 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002034 QueryTexParameteriv(texture, pname, params);
2035}
Jiajia Qin5451d532017-11-16 17:16:34 +08002036
Till Rathmannb8543632018-10-02 19:46:14 +02002037void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2038{
2039 const Texture *const texture = getTargetTexture(target);
2040 QueryTexParameterIiv(texture, pname, params);
2041}
2042
2043void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2044{
2045 const Texture *const texture = getTargetTexture(target);
2046 QueryTexParameterIuiv(texture, pname, params);
2047}
2048
Brandon Jones59770802018-04-02 13:18:42 -07002049void Context::getTexParameterivRobust(TextureType target,
2050 GLenum pname,
2051 GLsizei bufSize,
2052 GLsizei *length,
2053 GLint *params)
2054{
2055 getTexParameteriv(target, pname, params);
2056}
2057
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002058void Context::getTexParameterIivRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
2067void Context::getTexParameterIuivRobust(TextureType target,
2068 GLenum pname,
2069 GLsizei bufSize,
2070 GLsizei *length,
2071 GLuint *params)
2072{
2073 UNIMPLEMENTED();
2074}
2075
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002076void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002077{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002078 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002079 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002080}
2081
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002082void Context::getTexLevelParameterivRobust(TextureTarget target,
2083 GLint level,
2084 GLenum pname,
2085 GLsizei bufSize,
2086 GLsizei *length,
2087 GLint *params)
2088{
2089 UNIMPLEMENTED();
2090}
2091
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002092void Context::getTexLevelParameterfv(TextureTarget target,
2093 GLint level,
2094 GLenum pname,
2095 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002096{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002097 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002098 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002099}
2100
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002101void Context::getTexLevelParameterfvRobust(TextureTarget target,
2102 GLint level,
2103 GLenum pname,
2104 GLsizei bufSize,
2105 GLsizei *length,
2106 GLfloat *params)
2107{
2108 UNIMPLEMENTED();
2109}
2110
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002111void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002112{
Till Rathmannb8543632018-10-02 19:46:14 +02002113 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002114 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002115}
2116
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002117void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002118{
Till Rathmannb8543632018-10-02 19:46:14 +02002119 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002120 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002121}
2122
Brandon Jones59770802018-04-02 13:18:42 -07002123void Context::texParameterfvRobust(TextureType target,
2124 GLenum pname,
2125 GLsizei bufSize,
2126 const GLfloat *params)
2127{
2128 texParameterfv(target, pname, params);
2129}
2130
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002132{
Till Rathmannb8543632018-10-02 19:46:14 +02002133 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002134 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002135}
2136
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002137void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002138{
Till Rathmannb8543632018-10-02 19:46:14 +02002139 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002140 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002141}
2142
Till Rathmannb8543632018-10-02 19:46:14 +02002143void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2144{
2145 Texture *const texture = getTargetTexture(target);
2146 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002147}
2148
2149void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2150{
2151 Texture *const texture = getTargetTexture(target);
2152 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002153}
2154
Brandon Jones59770802018-04-02 13:18:42 -07002155void Context::texParameterivRobust(TextureType target,
2156 GLenum pname,
2157 GLsizei bufSize,
2158 const GLint *params)
2159{
2160 texParameteriv(target, pname, params);
2161}
2162
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002163void Context::texParameterIivRobust(TextureType target,
2164 GLenum pname,
2165 GLsizei bufSize,
2166 const GLint *params)
2167{
2168 UNIMPLEMENTED();
2169}
2170
2171void Context::texParameterIuivRobust(TextureType target,
2172 GLenum pname,
2173 GLsizei bufSize,
2174 const GLuint *params)
2175{
2176 UNIMPLEMENTED();
2177}
2178
Jamie Madill493f9572018-05-24 19:52:15 -04002179void Context::drawArraysInstanced(PrimitiveMode mode,
2180 GLint first,
2181 GLsizei count,
2182 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002183{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002184 // No-op if count draws no primitives for given mode
2185 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002186 {
2187 return;
2188 }
2189
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002190 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002191 ANGLE_CONTEXT_TRY(
2192 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002193 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002194}
2195
Jamie Madill493f9572018-05-24 19:52:15 -04002196void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002197 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002198 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002199 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002200 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002201{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002202 // No-op if count draws no primitives for given mode
2203 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002204 {
2205 return;
2206 }
2207
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002208 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002209 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002210 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002211}
2212
Jamie Madill493f9572018-05-24 19:52:15 -04002213void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002214 GLuint start,
2215 GLuint end,
2216 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002217 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002218 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002219{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002220 // No-op if count draws no primitives for given mode
2221 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002222 {
2223 return;
2224 }
2225
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002226 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002227 ANGLE_CONTEXT_TRY(
2228 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002229}
2230
Jamie Madill493f9572018-05-24 19:52:15 -04002231void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002232{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002233 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002234 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002235}
2236
Jamie Madill8dc27f92018-11-29 11:45:44 -05002237void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002238{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002239 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002240 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002241}
2242
Jamie Madill675fe712016-12-19 13:07:54 -05002243void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002245 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002246}
2247
Jamie Madill675fe712016-12-19 13:07:54 -05002248void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002249{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002250 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002251}
2252
Austin Kinross6ee1e782015-05-29 17:05:37 -07002253void Context::insertEventMarker(GLsizei length, const char *marker)
2254{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002255 ASSERT(mImplementation);
2256 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002257}
2258
2259void Context::pushGroupMarker(GLsizei length, const char *marker)
2260{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002261 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002262
2263 if (marker == nullptr)
2264 {
2265 // From the EXT_debug_marker spec,
2266 // "If <marker> is null then an empty string is pushed on the stack."
2267 mImplementation->pushGroupMarker(length, "");
2268 }
2269 else
2270 {
2271 mImplementation->pushGroupMarker(length, marker);
2272 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002273}
2274
2275void Context::popGroupMarker()
2276{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002277 ASSERT(mImplementation);
2278 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002279}
2280
Geoff Langd8605522016-04-13 10:19:12 -04002281void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2282{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002283 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002284 ASSERT(programObject);
2285
2286 programObject->bindUniformLocation(location, name);
2287}
2288
Brandon Jones59770802018-04-02 13:18:42 -07002289void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002290{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002291 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002292}
2293
Brandon Jones59770802018-04-02 13:18:42 -07002294void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002295{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002296 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002297}
2298
Brandon Jones59770802018-04-02 13:18:42 -07002299void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002300{
2301 GLfloat I[16];
2302 angle::Matrix<GLfloat>::setToIdentity(I);
2303
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002304 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002305}
2306
2307void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2308{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002309 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002310 if (!pathObj)
2311 return;
2312
Geoff Lang9bf86f02018-07-26 11:46:34 -04002313 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002314
2315 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2316}
2317
2318void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2319{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002320 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002321 if (!pathObj)
2322 return;
2323
Geoff Lang9bf86f02018-07-26 11:46:34 -04002324 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002325
2326 mImplementation->stencilStrokePath(pathObj, reference, mask);
2327}
2328
2329void Context::coverFillPath(GLuint path, GLenum coverMode)
2330{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002331 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002332 if (!pathObj)
2333 return;
2334
Geoff Lang9bf86f02018-07-26 11:46:34 -04002335 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336
2337 mImplementation->coverFillPath(pathObj, coverMode);
2338}
2339
2340void Context::coverStrokePath(GLuint path, GLenum coverMode)
2341{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002342 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002343 if (!pathObj)
2344 return;
2345
Geoff Lang9bf86f02018-07-26 11:46:34 -04002346 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002347
2348 mImplementation->coverStrokePath(pathObj, coverMode);
2349}
2350
2351void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2352{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002353 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002354 if (!pathObj)
2355 return;
2356
Geoff Lang9bf86f02018-07-26 11:46:34 -04002357 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002358
2359 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2360}
2361
2362void Context::stencilThenCoverStrokePath(GLuint path,
2363 GLint reference,
2364 GLuint mask,
2365 GLenum coverMode)
2366{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002367 const auto *pathObj = mState.mPathManager->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->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2374}
2375
Sami Väisänend59ca052016-06-21 16:10:00 +03002376void Context::coverFillPathInstanced(GLsizei numPaths,
2377 GLenum pathNameType,
2378 const void *paths,
2379 GLuint pathBase,
2380 GLenum coverMode,
2381 GLenum transformType,
2382 const GLfloat *transformValues)
2383{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002384 const auto &pathObjects =
2385 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002386
Geoff Lang9bf86f02018-07-26 11:46:34 -04002387 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002388
2389 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2390}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002391
Sami Väisänend59ca052016-06-21 16:10:00 +03002392void Context::coverStrokePathInstanced(GLsizei numPaths,
2393 GLenum pathNameType,
2394 const void *paths,
2395 GLuint pathBase,
2396 GLenum coverMode,
2397 GLenum transformType,
2398 const GLfloat *transformValues)
2399{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002400 const auto &pathObjects =
2401 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002402
2403 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002404 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002405
2406 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2407 transformValues);
2408}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002409
Sami Väisänend59ca052016-06-21 16:10:00 +03002410void Context::stencilFillPathInstanced(GLsizei numPaths,
2411 GLenum pathNameType,
2412 const void *paths,
2413 GLuint pathBase,
2414 GLenum fillMode,
2415 GLuint mask,
2416 GLenum transformType,
2417 const GLfloat *transformValues)
2418{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002419 const auto &pathObjects =
2420 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002421
2422 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002423 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002424
2425 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2426 transformValues);
2427}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002428
Sami Väisänend59ca052016-06-21 16:10:00 +03002429void Context::stencilStrokePathInstanced(GLsizei numPaths,
2430 GLenum pathNameType,
2431 const void *paths,
2432 GLuint pathBase,
2433 GLint reference,
2434 GLuint mask,
2435 GLenum transformType,
2436 const GLfloat *transformValues)
2437{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002438 const auto &pathObjects =
2439 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002440
Geoff Lang9bf86f02018-07-26 11:46:34 -04002441 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002442
2443 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2444 transformValues);
2445}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002446
Sami Väisänend59ca052016-06-21 16:10:00 +03002447void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2448 GLenum pathNameType,
2449 const void *paths,
2450 GLuint pathBase,
2451 GLenum fillMode,
2452 GLuint mask,
2453 GLenum coverMode,
2454 GLenum transformType,
2455 const GLfloat *transformValues)
2456{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002457 const auto &pathObjects =
2458 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
Geoff Lang9bf86f02018-07-26 11:46:34 -04002460 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002461
2462 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2463 transformType, transformValues);
2464}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002465
Sami Väisänend59ca052016-06-21 16:10:00 +03002466void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2467 GLenum pathNameType,
2468 const void *paths,
2469 GLuint pathBase,
2470 GLint reference,
2471 GLuint mask,
2472 GLenum coverMode,
2473 GLenum transformType,
2474 const GLfloat *transformValues)
2475{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002476 const auto &pathObjects =
2477 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
Geoff Lang9bf86f02018-07-26 11:46:34 -04002479 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002480
2481 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2482 transformType, transformValues);
2483}
2484
Sami Väisänen46eaa942016-06-29 10:26:37 +03002485void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2486{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002487 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002488
2489 programObject->bindFragmentInputLocation(location, name);
2490}
2491
2492void Context::programPathFragmentInputGen(GLuint program,
2493 GLint location,
2494 GLenum genMode,
2495 GLint components,
2496 const GLfloat *coeffs)
2497{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002498 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002499
jchen103fd614d2018-08-13 12:21:58 +08002500 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002501}
2502
jchen1015015f72017-03-16 13:54:21 +08002503GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2504{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002505 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002506 return QueryProgramResourceIndex(programObject, programInterface, name);
2507}
2508
jchen10fd7c3b52017-03-21 15:36:03 +08002509void Context::getProgramResourceName(GLuint program,
2510 GLenum programInterface,
2511 GLuint index,
2512 GLsizei bufSize,
2513 GLsizei *length,
2514 GLchar *name)
2515{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002516 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002517 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2518}
2519
jchen10191381f2017-04-11 13:59:04 +08002520GLint Context::getProgramResourceLocation(GLuint program,
2521 GLenum programInterface,
2522 const GLchar *name)
2523{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002524 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002525 return QueryProgramResourceLocation(programObject, programInterface, name);
2526}
2527
jchen10880683b2017-04-12 16:21:55 +08002528void Context::getProgramResourceiv(GLuint program,
2529 GLenum programInterface,
2530 GLuint index,
2531 GLsizei propCount,
2532 const GLenum *props,
2533 GLsizei bufSize,
2534 GLsizei *length,
2535 GLint *params)
2536{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002537 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002538 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2539 length, params);
2540}
2541
jchen10d9cd7b72017-08-30 15:04:25 +08002542void Context::getProgramInterfaceiv(GLuint program,
2543 GLenum programInterface,
2544 GLenum pname,
2545 GLint *params)
2546{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002547 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002548 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2549}
2550
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002551void Context::getProgramInterfaceivRobust(GLuint program,
2552 GLenum programInterface,
2553 GLenum pname,
2554 GLsizei bufSize,
2555 GLsizei *length,
2556 GLint *params)
2557{
2558 UNIMPLEMENTED();
2559}
2560
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002561void Context::handleError(GLenum errorCode,
2562 const char *message,
2563 const char *file,
2564 const char *function,
2565 unsigned int line)
2566{
2567 mErrors.handleError(errorCode, message, file, function, line);
2568}
2569
Jamie Madilla139f012018-10-10 16:13:03 -04002570void Context::validationError(GLenum errorCode, const char *message)
2571{
2572 mErrors.validationError(errorCode, message);
2573}
2574
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002575// Get one of the recorded errors and clear its flag, if any.
2576// [OpenGL ES 2.0.24] section 2.5 page 13.
2577GLenum Context::getError()
2578{
Geoff Langda5777c2014-07-11 09:52:58 -04002579 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580 {
Geoff Langda5777c2014-07-11 09:52:58 -04002581 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002582 }
Geoff Langda5777c2014-07-11 09:52:58 -04002583 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002585 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002586 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002587}
2588
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002589// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002590void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002591{
2592 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002593 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002594 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002595 mContextLostForced = true;
2596 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002597 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002598}
2599
Jamie Madillfa920eb2018-01-04 11:45:50 -05002600GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002601{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002602 // Even if the application doesn't want to know about resets, we want to know
2603 // as it will allow us to skip all the calls.
2604 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002606 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002607 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002609 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610
2611 // EXT_robustness, section 2.6: If the reset notification behavior is
2612 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2613 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2614 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002615 }
2616
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002617 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2618 // status should be returned at least once, and GL_NO_ERROR should be returned
2619 // once the device has finished resetting.
2620 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002622 ASSERT(mResetStatus == GL_NO_ERROR);
2623 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002624
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002625 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002626 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002627 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002628 }
2629 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002630 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002631 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002632 // If markContextLost was used to mark the context lost then
2633 // assume that is not recoverable, and continue to report the
2634 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002635 mResetStatus = mImplementation->getResetStatus();
2636 }
Jamie Madill893ab082014-05-16 16:56:10 -04002637
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639}
2640
2641bool Context::isResetNotificationEnabled()
2642{
2643 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2644}
2645
Corentin Walleze3b10e82015-05-20 11:06:25 -04002646const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002647{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002648 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002649}
2650
2651EGLenum Context::getClientType() const
2652{
2653 return mClientType;
2654}
2655
2656EGLenum Context::getRenderBuffer() const
2657{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002658 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002659 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002660 {
2661 return EGL_NONE;
2662 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002663
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002664 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002665 ASSERT(backAttachment != nullptr);
2666 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002667}
2668
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002669VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002670{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002671 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002672 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2673 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002674 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002675 vertexArray =
2676 new VertexArray(mImplementation.get(), vertexArrayHandle,
2677 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002678
Jamie Madill96a483b2017-06-27 16:49:21 -04002679 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002680 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002681
2682 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002683}
2684
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002685TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002686{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002687 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002688 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2689 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002690 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002691 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002692 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002693 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002694 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002695 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002696
2697 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002698}
2699
2700bool Context::isVertexArrayGenerated(GLuint vertexArray)
2701{
Jamie Madill96a483b2017-06-27 16:49:21 -04002702 ASSERT(mVertexArrayMap.contains(0));
2703 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002704}
2705
2706bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2707{
Jamie Madill96a483b2017-06-27 16:49:21 -04002708 ASSERT(mTransformFeedbackMap.contains(0));
2709 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002710}
2711
Shannon Woods53a94a82014-06-24 15:20:36 -04002712void Context::detachTexture(GLuint texture)
2713{
2714 // Simple pass-through to State's detachTexture method, as textures do not require
2715 // allocation map management either here or in the resource manager at detach time.
2716 // Zero textures are held by the Context, and we don't attempt to request them from
2717 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002718 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002719}
2720
James Darpinian4d9d4832018-03-13 12:43:28 -07002721void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002722{
Yuly Novikov5807a532015-12-03 13:01:22 -05002723 // Simple pass-through to State's detachBuffer method, since
2724 // only buffer attachments to container objects that are bound to the current context
2725 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002726
Yuly Novikov5807a532015-12-03 13:01:22 -05002727 // [OpenGL ES 3.2] section 5.1.2 page 45:
2728 // Attachments to unbound container objects, such as
2729 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2730 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002731 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732}
2733
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002734void Context::detachFramebuffer(GLuint framebuffer)
2735{
Shannon Woods53a94a82014-06-24 15:20:36 -04002736 // Framebuffer detachment is handled by Context, because 0 is a valid
2737 // Framebuffer object, and a pointer to it must be passed from Context
2738 // to State at binding time.
2739
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002740 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002741 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2742 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2743 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002745 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002746 {
2747 bindReadFramebuffer(0);
2748 }
2749
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002750 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002751 {
2752 bindDrawFramebuffer(0);
2753 }
2754}
2755
2756void Context::detachRenderbuffer(GLuint renderbuffer)
2757{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002758 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002759}
2760
Jamie Madill57a89722013-07-02 11:57:03 -04002761void Context::detachVertexArray(GLuint vertexArray)
2762{
Jamie Madill77a72f62015-04-14 11:18:32 -04002763 // Vertex array detachment is handled by Context, because 0 is a valid
2764 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002765 // binding time.
2766
Jamie Madill57a89722013-07-02 11:57:03 -04002767 // [OpenGL ES 3.0.2] section 2.10 page 43:
2768 // If a vertex array object that is currently bound is deleted, the binding
2769 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002770 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002771 {
2772 bindVertexArray(0);
2773 }
2774}
2775
Geoff Langc8058452014-02-03 12:04:11 -05002776void Context::detachTransformFeedback(GLuint transformFeedback)
2777{
Corentin Walleza2257da2016-04-19 16:43:12 -04002778 // Transform feedback detachment is handled by Context, because 0 is a valid
2779 // transform feedback, and a pointer to it must be passed from Context to State at
2780 // binding time.
2781
2782 // The OpenGL specification doesn't mention what should happen when the currently bound
2783 // transform feedback object is deleted. Since it is a container object, we treat it like
2784 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002785 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002786 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002787 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002788 }
Geoff Langc8058452014-02-03 12:04:11 -05002789}
2790
Jamie Madilldc356042013-07-19 16:36:57 -04002791void Context::detachSampler(GLuint sampler)
2792{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002793 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002794}
2795
Yunchao Hea336b902017-08-02 16:05:21 +08002796void Context::detachProgramPipeline(GLuint pipeline)
2797{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002798 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002799}
2800
Jamie Madill3ef140a2017-08-26 23:11:21 -04002801void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002802{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002803 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002804 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002805}
2806
Jamie Madille29d1672013-07-19 16:36:57 -04002807void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2808{
Till Rathmannb8543632018-10-02 19:46:14 +02002809 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002810 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002811 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812}
Jamie Madille29d1672013-07-19 16:36:57 -04002813
Geoff Langc1984ed2016-10-07 12:41:00 -04002814void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2815{
Till Rathmannb8543632018-10-02 19:46:14 +02002816 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002817 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002818 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002819}
2820
Till Rathmannb8543632018-10-02 19:46:14 +02002821void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2822{
2823 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002824 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002825 SetSamplerParameterIiv(this, samplerObject, pname, param);
2826}
2827
2828void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2829{
2830 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002831 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002832 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2833}
2834
Brandon Jones59770802018-04-02 13:18:42 -07002835void Context::samplerParameterivRobust(GLuint sampler,
2836 GLenum pname,
2837 GLsizei bufSize,
2838 const GLint *param)
2839{
2840 samplerParameteriv(sampler, pname, param);
2841}
2842
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002843void Context::samplerParameterIivRobust(GLuint sampler,
2844 GLenum pname,
2845 GLsizei bufSize,
2846 const GLint *param)
2847{
2848 UNIMPLEMENTED();
2849}
2850
2851void Context::samplerParameterIuivRobust(GLuint sampler,
2852 GLenum pname,
2853 GLsizei bufSize,
2854 const GLuint *param)
2855{
2856 UNIMPLEMENTED();
2857}
2858
Jamie Madille29d1672013-07-19 16:36:57 -04002859void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2860{
Till Rathmannb8543632018-10-02 19:46:14 +02002861 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002862 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002863 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002864}
2865
Geoff Langc1984ed2016-10-07 12:41:00 -04002866void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002867{
Till Rathmannb8543632018-10-02 19:46:14 +02002868 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002869 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002870 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002871}
2872
Brandon Jones59770802018-04-02 13:18:42 -07002873void Context::samplerParameterfvRobust(GLuint sampler,
2874 GLenum pname,
2875 GLsizei bufSize,
2876 const GLfloat *param)
2877{
2878 samplerParameterfv(sampler, pname, param);
2879}
2880
Geoff Langc1984ed2016-10-07 12:41:00 -04002881void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002882{
Till Rathmannb8543632018-10-02 19:46:14 +02002883 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002884 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002885 QuerySamplerParameteriv(samplerObject, pname, params);
2886}
Jamie Madill9675b802013-07-19 16:36:59 -04002887
Till Rathmannb8543632018-10-02 19:46:14 +02002888void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2889{
2890 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002891 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002892 QuerySamplerParameterIiv(samplerObject, pname, params);
2893}
2894
2895void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2896{
2897 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002898 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002899 QuerySamplerParameterIuiv(samplerObject, pname, params);
2900}
2901
Brandon Jones59770802018-04-02 13:18:42 -07002902void Context::getSamplerParameterivRobust(GLuint sampler,
2903 GLenum pname,
2904 GLsizei bufSize,
2905 GLsizei *length,
2906 GLint *params)
2907{
2908 getSamplerParameteriv(sampler, pname, params);
2909}
2910
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002911void Context::getSamplerParameterIivRobust(GLuint sampler,
2912 GLenum pname,
2913 GLsizei bufSize,
2914 GLsizei *length,
2915 GLint *params)
2916{
2917 UNIMPLEMENTED();
2918}
2919
2920void Context::getSamplerParameterIuivRobust(GLuint sampler,
2921 GLenum pname,
2922 GLsizei bufSize,
2923 GLsizei *length,
2924 GLuint *params)
2925{
2926 UNIMPLEMENTED();
2927}
2928
Geoff Langc1984ed2016-10-07 12:41:00 -04002929void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2930{
Till Rathmannb8543632018-10-02 19:46:14 +02002931 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002932 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002933 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002934}
2935
Brandon Jones59770802018-04-02 13:18:42 -07002936void Context::getSamplerParameterfvRobust(GLuint sampler,
2937 GLenum pname,
2938 GLsizei bufSize,
2939 GLsizei *length,
2940 GLfloat *params)
2941{
2942 getSamplerParameterfv(sampler, pname, params);
2943}
2944
Olli Etuahof0fee072016-03-30 15:11:58 +03002945void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2946{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002947 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002948 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002949}
2950
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002951void Context::initRendererString()
2952{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002953 std::ostringstream rendererString;
2954 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002955 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002956 rendererString << ")";
2957
Geoff Langcec35902014-04-16 10:52:36 -04002958 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002959}
2960
Geoff Langc339c4e2016-11-29 10:37:36 -05002961void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002962{
Geoff Langc339c4e2016-11-29 10:37:36 -05002963 const Version &clientVersion = getClientVersion();
2964
2965 std::ostringstream versionString;
2966 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2967 << ANGLE_VERSION_STRING << ")";
2968 mVersionString = MakeStaticString(versionString.str());
2969
2970 std::ostringstream shadingLanguageVersionString;
2971 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2972 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2973 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2974 << ")";
2975 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002976}
2977
Geoff Langcec35902014-04-16 10:52:36 -04002978void Context::initExtensionStrings()
2979{
Geoff Langc339c4e2016-11-29 10:37:36 -05002980 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2981 std::ostringstream combinedStringStream;
2982 std::copy(strings.begin(), strings.end(),
2983 std::ostream_iterator<const char *>(combinedStringStream, " "));
2984 return MakeStaticString(combinedStringStream.str());
2985 };
2986
2987 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002988 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002989 {
2990 mExtensionStrings.push_back(MakeStaticString(extensionString));
2991 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002992 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002993
Geoff Langc339c4e2016-11-29 10:37:36 -05002994 mRequestableExtensionStrings.clear();
2995 for (const auto &extensionInfo : GetExtensionInfoMap())
2996 {
2997 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002998 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002999 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003000 {
3001 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3002 }
3003 }
3004 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003005}
3006
Geoff Langc339c4e2016-11-29 10:37:36 -05003007const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003008{
Geoff Langc339c4e2016-11-29 10:37:36 -05003009 switch (name)
3010 {
3011 case GL_VENDOR:
3012 return reinterpret_cast<const GLubyte *>("Google Inc.");
3013
3014 case GL_RENDERER:
3015 return reinterpret_cast<const GLubyte *>(mRendererString);
3016
3017 case GL_VERSION:
3018 return reinterpret_cast<const GLubyte *>(mVersionString);
3019
3020 case GL_SHADING_LANGUAGE_VERSION:
3021 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3022
3023 case GL_EXTENSIONS:
3024 return reinterpret_cast<const GLubyte *>(mExtensionString);
3025
3026 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3027 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3028
3029 default:
3030 UNREACHABLE();
3031 return nullptr;
3032 }
Geoff Langcec35902014-04-16 10:52:36 -04003033}
3034
Geoff Langc339c4e2016-11-29 10:37:36 -05003035const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003036{
Geoff Langc339c4e2016-11-29 10:37:36 -05003037 switch (name)
3038 {
3039 case GL_EXTENSIONS:
3040 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3041
3042 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3043 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3044
3045 default:
3046 UNREACHABLE();
3047 return nullptr;
3048 }
Geoff Langcec35902014-04-16 10:52:36 -04003049}
3050
3051size_t Context::getExtensionStringCount() const
3052{
3053 return mExtensionStrings.size();
3054}
3055
Geoff Lang111a99e2017-10-17 10:58:41 -04003056bool Context::isExtensionRequestable(const char *name)
3057{
3058 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3059 auto extension = extensionInfos.find(name);
3060
Geoff Lang111a99e2017-10-17 10:58:41 -04003061 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003062 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003063}
3064
Geoff Langc339c4e2016-11-29 10:37:36 -05003065void Context::requestExtension(const char *name)
3066{
3067 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3068 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3069 const auto &extension = extensionInfos.at(name);
3070 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003071 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003072
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003073 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003074 {
3075 // Extension already enabled
3076 return;
3077 }
3078
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003079 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003080 updateCaps();
3081 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003082
Jamie Madill2f348d22017-06-05 10:50:59 -04003083 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3084 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003085
Jamie Madill81c2e252017-09-09 23:32:46 -04003086 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3087 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003088 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003089 for (auto &zeroTexture : mZeroTextures)
3090 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003091 if (zeroTexture.get() != nullptr)
3092 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003093 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003094 }
Geoff Lang9aded172017-04-05 11:07:56 -04003095 }
3096
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003097 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003098}
3099
3100size_t Context::getRequestableExtensionStringCount() const
3101{
3102 return mRequestableExtensionStrings.size();
3103}
3104
Jamie Madill493f9572018-05-24 19:52:15 -04003105void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003106{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003107 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003108 ASSERT(transformFeedback != nullptr);
3109 ASSERT(!transformFeedback->isPaused());
3110
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003111 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003112 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003113}
3114
3115bool Context::hasActiveTransformFeedback(GLuint program) const
3116{
3117 for (auto pair : mTransformFeedbackMap)
3118 {
3119 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3120 {
3121 return true;
3122 }
3123 }
3124 return false;
3125}
3126
Geoff Lang33f11fb2018-05-07 13:42:47 -04003127Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003128{
3129 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3130
jchen1082af6202018-06-22 10:59:52 +08003131 // Explicitly enable GL_KHR_parallel_shader_compile
3132 supportedExtensions.parallelShaderCompile = true;
3133
Geoff Langb0f917f2017-12-05 13:41:54 -05003134 if (getClientVersion() < ES_2_0)
3135 {
3136 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003137 supportedExtensions.pointSizeArray = true;
3138 supportedExtensions.textureCubeMap = true;
3139 supportedExtensions.pointSprite = true;
3140 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003141 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003142 }
3143
3144 if (getClientVersion() < ES_3_0)
3145 {
3146 // Disable ES3+ extensions
3147 supportedExtensions.colorBufferFloat = false;
3148 supportedExtensions.eglImageExternalEssl3 = false;
3149 supportedExtensions.textureNorm16 = false;
3150 supportedExtensions.multiview = false;
3151 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003152 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003153 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003154
3155 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3156 if (!supportedExtensions.sRGB)
3157 {
3158 supportedExtensions.textureSRGBDecode = false;
3159 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003160 }
3161
3162 if (getClientVersion() < ES_3_1)
3163 {
3164 // Disable ES3.1+ extensions
3165 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003166
3167 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3168 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003169 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003170 }
3171
3172 if (getClientVersion() > ES_2_0)
3173 {
3174 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3175 // supportedExtensions.sRGB = false;
3176 }
3177
3178 // Some extensions are always available because they are implemented in the GL layer.
3179 supportedExtensions.bindUniformLocation = true;
3180 supportedExtensions.vertexArrayObject = true;
3181 supportedExtensions.bindGeneratesResource = true;
3182 supportedExtensions.clientArrays = true;
3183 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003184 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003185
3186 // Enable the no error extension if the context was created with the flag.
3187 supportedExtensions.noError = mSkipValidation;
3188
3189 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003190 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003191
3192 // Explicitly enable GL_KHR_debug
3193 supportedExtensions.debug = true;
3194 supportedExtensions.maxDebugMessageLength = 1024;
3195 supportedExtensions.maxDebugLoggedMessages = 1024;
3196 supportedExtensions.maxDebugGroupStackDepth = 1024;
3197 supportedExtensions.maxLabelLength = 1024;
3198
3199 // Explicitly enable GL_ANGLE_robust_client_memory
3200 supportedExtensions.robustClientMemory = true;
3201
3202 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003203 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003204
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003205 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3206 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003207 supportedExtensions.robustBufferAccessBehavior =
3208 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3209
3210 // Enable the cache control query unconditionally.
3211 supportedExtensions.programCacheControl = true;
3212
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003213 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003214 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003215 {
3216 // GL_ANGLE_explicit_context_gles1
3217 supportedExtensions.explicitContextGles1 = true;
3218 // GL_ANGLE_explicit_context
3219 supportedExtensions.explicitContext = true;
3220 }
3221
Geoff Lang79b91402018-10-04 15:11:30 -04003222 supportedExtensions.memorySize = true;
3223
Geoff Langb0f917f2017-12-05 13:41:54 -05003224 return supportedExtensions;
3225}
3226
Geoff Lang33f11fb2018-05-07 13:42:47 -04003227void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003228{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003229 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003230
Geoff Lang33f11fb2018-05-07 13:42:47 -04003231 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003232 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003233
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003234 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003235
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003236 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3237 if (getClientVersion() < Version(2, 0))
3238 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003239 mState.mCaps.maxMultitextureUnits = 4;
3240 mState.mCaps.maxClipPlanes = 6;
3241 mState.mCaps.maxLights = 8;
3242 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3244 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3245 mState.mCaps.minSmoothPointSize = 1.0f;
3246 mState.mCaps.maxSmoothPointSize = 1.0f;
3247 mState.mCaps.minSmoothLineWidth = 1.0f;
3248 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003249 }
3250
Luc Ferronad2ae932018-06-11 15:31:17 -04003251 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003252 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003253
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003254 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003255
Jamie Madill0f80ed82017-09-19 00:24:56 -04003256 if (getClientVersion() < ES_3_1)
3257 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003258 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003259 }
3260 else
3261 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003262 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003263 }
Geoff Lang301d1612014-07-09 10:34:37 -04003264
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003265 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003266 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003267 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003268
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003269 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3270 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003271
3272 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003273 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3274 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003276 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003277 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003278
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003279 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003280
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003281 mState.mCaps.maxSampleMaskWords =
3282 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003283
Geoff Langc287ea62016-09-16 14:46:51 -04003284 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003285 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003286 for (const auto &extensionInfo : GetExtensionInfoMap())
3287 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003288 // If the user has requested that extensions start disabled and they are requestable,
3289 // disable them.
3290 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003291 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003292 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003293 }
3294 }
3295
3296 // Generate texture caps
3297 updateCaps();
3298}
3299
3300void Context::updateCaps()
3301{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003302 mState.mCaps.compressedTextureFormats.clear();
3303 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003304
Jamie Madill7b62cf92017-11-02 15:20:49 -04003305 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003306 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003307 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003308 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003309
Geoff Lang0d8b7242015-09-09 14:56:53 -04003310 // Update the format caps based on the client version and extensions.
3311 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3312 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003313 formatCaps.texturable = formatCaps.texturable &&
3314 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3315 formatCaps.filterable = formatCaps.filterable &&
3316 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003317 formatCaps.textureAttachment =
3318 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003319 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3320 formatCaps.renderbuffer =
3321 formatCaps.renderbuffer &&
3322 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003323
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003324 // OpenGL ES does not support multisampling with non-rendererable formats
3325 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003326 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003327 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003328 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003329 {
Geoff Langd87878e2014-09-19 15:42:59 -04003330 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003331 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003332 else
3333 {
3334 // We may have limited the max samples for some required renderbuffer formats due to
3335 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3336 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3337
3338 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3339 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3340 // exception of signed and unsigned integer formats."
3341 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3342 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3343 {
3344 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003345 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003346 }
3347
3348 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003349 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003350 {
3351 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3352 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3353 // the exception that the signed and unsigned integer formats are required only to
3354 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3355 // multisamples, which must be at least one."
3356 if (formatInfo.componentType == GL_INT ||
3357 formatInfo.componentType == GL_UNSIGNED_INT)
3358 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003359 mState.mCaps.maxIntegerSamples =
3360 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003361 }
3362
3363 // GLES 3.1 section 19.3.1.
3364 if (formatCaps.texturable)
3365 {
3366 if (formatInfo.depthBits > 0)
3367 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003368 mState.mCaps.maxDepthTextureSamples =
3369 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003370 }
3371 else if (formatInfo.redBits > 0)
3372 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003373 mState.mCaps.maxColorTextureSamples =
3374 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003375 }
3376 }
3377 }
3378 }
Geoff Langd87878e2014-09-19 15:42:59 -04003379
3380 if (formatCaps.texturable && formatInfo.compressed)
3381 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003382 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003383 }
3384
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003385 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003386 }
Jamie Madill32447362017-06-28 14:53:52 -04003387
3388 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003389 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003390 {
3391 mMemoryProgramCache = nullptr;
3392 }
Corentin Walleze4477002017-12-01 14:39:58 -05003393
3394 // Compute which buffer types are allowed
3395 mValidBufferBindings.reset();
3396 mValidBufferBindings.set(BufferBinding::ElementArray);
3397 mValidBufferBindings.set(BufferBinding::Array);
3398
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003399 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003400 {
3401 mValidBufferBindings.set(BufferBinding::PixelPack);
3402 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3403 }
3404
3405 if (getClientVersion() >= ES_3_0)
3406 {
3407 mValidBufferBindings.set(BufferBinding::CopyRead);
3408 mValidBufferBindings.set(BufferBinding::CopyWrite);
3409 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3410 mValidBufferBindings.set(BufferBinding::Uniform);
3411 }
3412
3413 if (getClientVersion() >= ES_3_1)
3414 {
3415 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3416 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3417 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3418 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3419 }
jchen107ae70d82018-07-06 13:47:01 +08003420
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003421 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003422
Jamie Madillef9fcd92018-11-28 14:03:59 -05003423 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003424 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003425 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3426 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3427 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3428 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3429 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3430 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003431
Jamie Madillac66f982018-10-09 18:30:01 -04003432 // Reinitialize state cache after extension changes.
3433 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003434}
3435
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003436void Context::initWorkarounds()
3437{
Jamie Madill761b02c2017-06-23 16:27:06 -04003438 // Apply back-end workarounds.
3439 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3440
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003441 // Lose the context upon out of memory error if the application is
3442 // expecting to watch for those events.
3443 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003444
3445 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3446 {
3447 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3448 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3449 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3450 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003451}
3452
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003453bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3454{
3455 return (instanceCount == 0) || noopDraw(mode, count);
3456}
3457
Jamie Madill526392d2018-11-16 09:35:14 -05003458angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003459{
Geoff Langa8cb2872018-03-09 16:09:40 -05003460 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003461 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003462 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003463 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003464}
3465
Jamie Madill526392d2018-11-16 09:35:14 -05003466angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003467{
Geoff Langa8cb2872018-03-09 16:09:40 -05003468 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003469 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3470 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003471 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003472 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003473}
3474
Jamie Madill132d15c2018-11-30 15:25:38 -05003475ANGLE_INLINE angle::Result Context::prepareForDispatch()
3476{
3477 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3478 return syncDirtyBits(mComputeDirtyBits);
3479}
3480
Jamie Madill526392d2018-11-16 09:35:14 -05003481angle::Result Context::syncState(const State::DirtyBits &bitMask,
3482 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003483{
Geoff Langa8cb2872018-03-09 16:09:40 -05003484 ANGLE_TRY(syncDirtyObjects(objectMask));
3485 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003486 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003487}
3488
Jamie Madillc29968b2016-01-20 11:17:23 -05003489void Context::blitFramebuffer(GLint srcX0,
3490 GLint srcY0,
3491 GLint srcX1,
3492 GLint srcY1,
3493 GLint dstX0,
3494 GLint dstY0,
3495 GLint dstX1,
3496 GLint dstY1,
3497 GLbitfield mask,
3498 GLenum filter)
3499{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003500 if (mask == 0)
3501 {
3502 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3503 // buffers are copied.
3504 return;
3505 }
3506
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003507 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003508 ASSERT(drawFramebuffer);
3509
3510 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3511 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3512
Jamie Madillbc918e72018-03-08 09:47:21 -05003513 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003514
Jamie Madill4f6592f2018-11-27 16:37:45 -05003515 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003516}
Jamie Madillc29968b2016-01-20 11:17:23 -05003517
3518void Context::clear(GLbitfield mask)
3519{
Geoff Langd4fff502017-09-22 11:28:28 -04003520 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003521 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003522}
3523
3524void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3525{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003526 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003527 const FramebufferAttachment *attachment = nullptr;
3528 if (buffer == GL_DEPTH)
3529 {
3530 attachment = framebufferObject->getDepthbuffer();
3531 }
3532 if (buffer == GL_COLOR &&
3533 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3534 {
3535 attachment = framebufferObject->getColorbuffer(drawbuffer);
3536 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003537 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3538 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003539 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003540 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003541 return;
3542 }
Geoff Langd4fff502017-09-22 11:28:28 -04003543 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003544 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003545}
3546
3547void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3548{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003549 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003550 const FramebufferAttachment *attachment = nullptr;
3551 if (buffer == GL_COLOR &&
3552 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3553 {
3554 attachment = framebufferObject->getColorbuffer(drawbuffer);
3555 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003556 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3557 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003558 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003559 {
3560 return;
3561 }
Geoff Langd4fff502017-09-22 11:28:28 -04003562 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003563 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003564}
3565
3566void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3567{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003568 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003569 const FramebufferAttachment *attachment = nullptr;
3570 if (buffer == GL_STENCIL)
3571 {
3572 attachment = framebufferObject->getStencilbuffer();
3573 }
3574 if (buffer == GL_COLOR &&
3575 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3576 {
3577 attachment = framebufferObject->getColorbuffer(drawbuffer);
3578 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003579 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3580 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003581 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003582 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003583 return;
3584 }
Geoff Langd4fff502017-09-22 11:28:28 -04003585 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003586 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003587}
3588
3589void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3590{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003591 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 ASSERT(framebufferObject);
3593
3594 // If a buffer is not present, the clear has no effect
3595 if (framebufferObject->getDepthbuffer() == nullptr &&
3596 framebufferObject->getStencilbuffer() == nullptr)
3597 {
3598 return;
3599 }
3600
Geoff Langd4fff502017-09-22 11:28:28 -04003601 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3602 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003603}
3604
3605void Context::readPixels(GLint x,
3606 GLint y,
3607 GLsizei width,
3608 GLsizei height,
3609 GLenum format,
3610 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003611 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003612{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003613 if (width == 0 || height == 0)
3614 {
3615 return;
3616 }
3617
Jamie Madillbc918e72018-03-08 09:47:21 -05003618 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003619
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003620 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003621 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003622
3623 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003624 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003625}
3626
Brandon Jones59770802018-04-02 13:18:42 -07003627void Context::readPixelsRobust(GLint x,
3628 GLint y,
3629 GLsizei width,
3630 GLsizei height,
3631 GLenum format,
3632 GLenum type,
3633 GLsizei bufSize,
3634 GLsizei *length,
3635 GLsizei *columns,
3636 GLsizei *rows,
3637 void *pixels)
3638{
3639 readPixels(x, y, width, height, format, type, pixels);
3640}
3641
3642void Context::readnPixelsRobust(GLint x,
3643 GLint y,
3644 GLsizei width,
3645 GLsizei height,
3646 GLenum format,
3647 GLenum type,
3648 GLsizei bufSize,
3649 GLsizei *length,
3650 GLsizei *columns,
3651 GLsizei *rows,
3652 void *data)
3653{
3654 readPixels(x, y, width, height, format, type, data);
3655}
3656
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003657void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003658 GLint level,
3659 GLenum internalformat,
3660 GLint x,
3661 GLint y,
3662 GLsizei width,
3663 GLsizei height,
3664 GLint border)
3665{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003666 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003667 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003668
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 Rectangle sourceArea(x, y, width, height);
3670
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003671 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003672 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003673 ANGLE_CONTEXT_TRY(
3674 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003675}
3676
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003677void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 GLint level,
3679 GLint xoffset,
3680 GLint yoffset,
3681 GLint x,
3682 GLint y,
3683 GLsizei width,
3684 GLsizei height)
3685{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003686 if (width == 0 || height == 0)
3687 {
3688 return;
3689 }
3690
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003692 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003693
Jamie Madillc29968b2016-01-20 11:17:23 -05003694 Offset destOffset(xoffset, yoffset, 0);
3695 Rectangle sourceArea(x, y, width, height);
3696
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003697 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003698 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003699 ANGLE_CONTEXT_TRY(
3700 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003701}
3702
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003703void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003704 GLint level,
3705 GLint xoffset,
3706 GLint yoffset,
3707 GLint zoffset,
3708 GLint x,
3709 GLint y,
3710 GLsizei width,
3711 GLsizei height)
3712{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003713 if (width == 0 || height == 0)
3714 {
3715 return;
3716 }
3717
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003718 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003719 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003720
Jamie Madillc29968b2016-01-20 11:17:23 -05003721 Offset destOffset(xoffset, yoffset, zoffset);
3722 Rectangle sourceArea(x, y, width, height);
3723
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003724 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003725 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003726 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3727 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003728}
3729
3730void Context::framebufferTexture2D(GLenum target,
3731 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003732 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003733 GLuint texture,
3734 GLint level)
3735{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003736 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003737 ASSERT(framebuffer);
3738
3739 if (texture != 0)
3740 {
3741 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003742 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003743 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003744 }
3745 else
3746 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003747 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003748 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003749
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003750 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751}
3752
3753void Context::framebufferRenderbuffer(GLenum target,
3754 GLenum attachment,
3755 GLenum renderbuffertarget,
3756 GLuint renderbuffer)
3757{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003758 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003759 ASSERT(framebuffer);
3760
3761 if (renderbuffer != 0)
3762 {
3763 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003764
Jamie Madillcc129372018-04-12 09:13:18 -04003765 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 renderbufferObject);
3767 }
3768 else
3769 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003770 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003771 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003772
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003773 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003774}
3775
3776void Context::framebufferTextureLayer(GLenum target,
3777 GLenum attachment,
3778 GLuint texture,
3779 GLint level,
3780 GLint layer)
3781{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003782 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003783 ASSERT(framebuffer);
3784
3785 if (texture != 0)
3786 {
3787 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003788 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003789 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 }
3791 else
3792 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003793 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003794 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003795
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003796 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797}
3798
Brandon Jones59770802018-04-02 13:18:42 -07003799void Context::framebufferTextureMultiviewLayered(GLenum target,
3800 GLenum attachment,
3801 GLuint texture,
3802 GLint level,
3803 GLint baseViewIndex,
3804 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003805{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003806 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003807 ASSERT(framebuffer);
3808
3809 if (texture != 0)
3810 {
3811 Texture *textureObj = getTexture(texture);
3812
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003813 ImageIndex index;
3814 if (textureObj->getType() == TextureType::_2DArray)
3815 {
3816 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3817 }
3818 else
3819 {
3820 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3821 ASSERT(level == 0);
3822 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3823 }
Martin Radev82ef7742017-08-08 17:44:58 +03003824 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3825 numViews, baseViewIndex);
3826 }
3827 else
3828 {
3829 framebuffer->resetAttachment(this, attachment);
3830 }
3831
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003832 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003833}
3834
Brandon Jones59770802018-04-02 13:18:42 -07003835void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3836 GLenum attachment,
3837 GLuint texture,
3838 GLint level,
3839 GLsizei numViews,
3840 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003841{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003842 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003843 ASSERT(framebuffer);
3844
3845 if (texture != 0)
3846 {
3847 Texture *textureObj = getTexture(texture);
3848
3849 ImageIndex index = ImageIndex::Make2D(level);
3850 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3851 textureObj, numViews, viewportOffsets);
3852 }
3853 else
3854 {
3855 framebuffer->resetAttachment(this, attachment);
3856 }
3857
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003858 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003859}
3860
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003861void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3862{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003863 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003864 ASSERT(framebuffer);
3865
3866 if (texture != 0)
3867 {
3868 Texture *textureObj = getTexture(texture);
3869
3870 ImageIndex index = ImageIndex::MakeFromType(
3871 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3872 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3873 }
3874 else
3875 {
3876 framebuffer->resetAttachment(this, attachment);
3877 }
3878
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003879 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003880}
3881
Jamie Madillc29968b2016-01-20 11:17:23 -05003882void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3883{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003884 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003885 ASSERT(framebuffer);
3886 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003887 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003888 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003889}
3890
3891void Context::readBuffer(GLenum mode)
3892{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003893 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003894 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003895 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003896}
3897
3898void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3899{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003900 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003901 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003902
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003903 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003904 ASSERT(framebuffer);
3905
3906 // The specification isn't clear what should be done when the framebuffer isn't complete.
3907 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003908 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003909}
3910
3911void Context::invalidateFramebuffer(GLenum target,
3912 GLsizei numAttachments,
3913 const GLenum *attachments)
3914{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003915 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003916 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003917
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003918 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003919 ASSERT(framebuffer);
3920
Jamie Madill427064d2018-04-13 16:20:34 -04003921 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003922 {
Jamie Madill437fa652016-05-03 15:13:24 -04003923 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003924 }
Jamie Madill437fa652016-05-03 15:13:24 -04003925
Jamie Madill4f6592f2018-11-27 16:37:45 -05003926 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003927}
3928
3929void Context::invalidateSubFramebuffer(GLenum target,
3930 GLsizei numAttachments,
3931 const GLenum *attachments,
3932 GLint x,
3933 GLint y,
3934 GLsizei width,
3935 GLsizei height)
3936{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003937 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003938 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003939
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003940 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003941 ASSERT(framebuffer);
3942
Jamie Madill427064d2018-04-13 16:20:34 -04003943 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003944 {
Jamie Madill437fa652016-05-03 15:13:24 -04003945 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003946 }
Jamie Madill437fa652016-05-03 15:13:24 -04003947
3948 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003949 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003950}
3951
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003952void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003953 GLint level,
3954 GLint internalformat,
3955 GLsizei width,
3956 GLsizei height,
3957 GLint border,
3958 GLenum format,
3959 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003960 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003961{
Jamie Madillbc918e72018-03-08 09:47:21 -05003962 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003963
3964 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003966 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003967 internalformat, size, format, type,
3968 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003969}
3970
Brandon Jones59770802018-04-02 13:18:42 -07003971void Context::texImage2DRobust(TextureTarget target,
3972 GLint level,
3973 GLint internalformat,
3974 GLsizei width,
3975 GLsizei height,
3976 GLint border,
3977 GLenum format,
3978 GLenum type,
3979 GLsizei bufSize,
3980 const void *pixels)
3981{
3982 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3983}
3984
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003985void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003986 GLint level,
3987 GLint internalformat,
3988 GLsizei width,
3989 GLsizei height,
3990 GLsizei depth,
3991 GLint border,
3992 GLenum format,
3993 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003994 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003995{
Jamie Madillbc918e72018-03-08 09:47:21 -05003996 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003997
3998 Extents size(width, height, depth);
3999 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004000 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05004001 NonCubeTextureTypeToTarget(target), level, internalformat,
4002 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004003}
4004
Brandon Jones59770802018-04-02 13:18:42 -07004005void Context::texImage3DRobust(TextureType target,
4006 GLint level,
4007 GLint internalformat,
4008 GLsizei width,
4009 GLsizei height,
4010 GLsizei depth,
4011 GLint border,
4012 GLenum format,
4013 GLenum type,
4014 GLsizei bufSize,
4015 const void *pixels)
4016{
4017 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4018}
4019
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004020void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004021 GLint level,
4022 GLint xoffset,
4023 GLint yoffset,
4024 GLsizei width,
4025 GLsizei height,
4026 GLenum format,
4027 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004028 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004029{
4030 // Zero sized uploads are valid but no-ops
4031 if (width == 0 || height == 0)
4032 {
4033 return;
4034 }
4035
Jamie Madillbc918e72018-03-08 09:47:21 -05004036 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004037
4038 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004039 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004040
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004041 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004042
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004043 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004044 level, area, format, type,
4045 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004046}
4047
Brandon Jones59770802018-04-02 13:18:42 -07004048void Context::texSubImage2DRobust(TextureTarget target,
4049 GLint level,
4050 GLint xoffset,
4051 GLint yoffset,
4052 GLsizei width,
4053 GLsizei height,
4054 GLenum format,
4055 GLenum type,
4056 GLsizei bufSize,
4057 const void *pixels)
4058{
4059 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4060}
4061
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004062void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004063 GLint level,
4064 GLint xoffset,
4065 GLint yoffset,
4066 GLint zoffset,
4067 GLsizei width,
4068 GLsizei height,
4069 GLsizei depth,
4070 GLenum format,
4071 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004072 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004073{
4074 // Zero sized uploads are valid but no-ops
4075 if (width == 0 || height == 0 || depth == 0)
4076 {
4077 return;
4078 }
4079
Jamie Madillbc918e72018-03-08 09:47:21 -05004080 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004081
4082 Box area(xoffset, yoffset, zoffset, width, height, depth);
4083 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004084
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004085 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004086
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004087 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004088 NonCubeTextureTypeToTarget(target), level, area, format,
4089 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004090}
4091
Brandon Jones59770802018-04-02 13:18:42 -07004092void Context::texSubImage3DRobust(TextureType target,
4093 GLint level,
4094 GLint xoffset,
4095 GLint yoffset,
4096 GLint zoffset,
4097 GLsizei width,
4098 GLsizei height,
4099 GLsizei depth,
4100 GLenum format,
4101 GLenum type,
4102 GLsizei bufSize,
4103 const void *pixels)
4104{
4105 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4106 pixels);
4107}
4108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004109void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004110 GLint level,
4111 GLenum internalformat,
4112 GLsizei width,
4113 GLsizei height,
4114 GLint border,
4115 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004116 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004117{
Jamie Madillbc918e72018-03-08 09:47:21 -05004118 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004119
4120 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004121 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004122 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004123 internalformat, size, imageSize,
4124 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004125}
4126
Brandon Jones59770802018-04-02 13:18:42 -07004127void Context::compressedTexImage2DRobust(TextureTarget target,
4128 GLint level,
4129 GLenum internalformat,
4130 GLsizei width,
4131 GLsizei height,
4132 GLint border,
4133 GLsizei imageSize,
4134 GLsizei dataSize,
4135 const GLvoid *data)
4136{
4137 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4138}
4139
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004140void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004141 GLint level,
4142 GLenum internalformat,
4143 GLsizei width,
4144 GLsizei height,
4145 GLsizei depth,
4146 GLint border,
4147 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004148 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004149{
Jamie Madillbc918e72018-03-08 09:47:21 -05004150 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004151
4152 Extents size(width, height, depth);
4153 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004154 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004155 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004156 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004157}
4158
Brandon Jones59770802018-04-02 13:18:42 -07004159void Context::compressedTexImage3DRobust(TextureType target,
4160 GLint level,
4161 GLenum internalformat,
4162 GLsizei width,
4163 GLsizei height,
4164 GLsizei depth,
4165 GLint border,
4166 GLsizei imageSize,
4167 GLsizei dataSize,
4168 const GLvoid *data)
4169{
4170 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4171 data);
4172}
4173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004174void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004175 GLint level,
4176 GLint xoffset,
4177 GLint yoffset,
4178 GLsizei width,
4179 GLsizei height,
4180 GLenum format,
4181 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004182 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004183{
Jamie Madillbc918e72018-03-08 09:47:21 -05004184 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004185
4186 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004187 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004188 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004189 area, format, imageSize,
4190 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004191}
4192
Brandon Jones59770802018-04-02 13:18:42 -07004193void Context::compressedTexSubImage2DRobust(TextureTarget target,
4194 GLint level,
4195 GLint xoffset,
4196 GLint yoffset,
4197 GLsizei width,
4198 GLsizei height,
4199 GLenum format,
4200 GLsizei imageSize,
4201 GLsizei dataSize,
4202 const GLvoid *data)
4203{
4204 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4205 data);
4206}
4207
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004208void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004209 GLint level,
4210 GLint xoffset,
4211 GLint yoffset,
4212 GLint zoffset,
4213 GLsizei width,
4214 GLsizei height,
4215 GLsizei depth,
4216 GLenum format,
4217 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004218 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004219{
4220 // Zero sized uploads are valid but no-ops
4221 if (width == 0 || height == 0)
4222 {
4223 return;
4224 }
4225
Jamie Madillbc918e72018-03-08 09:47:21 -05004226 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004227
4228 Box area(xoffset, yoffset, zoffset, width, height, depth);
4229 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004230 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004231 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004232 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004233}
4234
Brandon Jones59770802018-04-02 13:18:42 -07004235void Context::compressedTexSubImage3DRobust(TextureType target,
4236 GLint level,
4237 GLint xoffset,
4238 GLint yoffset,
4239 GLint zoffset,
4240 GLsizei width,
4241 GLsizei height,
4242 GLsizei depth,
4243 GLenum format,
4244 GLsizei imageSize,
4245 GLsizei dataSize,
4246 const GLvoid *data)
4247{
4248 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4249 imageSize, data);
4250}
4251
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004252void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004253{
4254 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004255 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004256}
4257
Jamie Madill007530e2017-12-28 14:27:04 -05004258void Context::copyTexture(GLuint sourceId,
4259 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004260 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004261 GLuint destId,
4262 GLint destLevel,
4263 GLint internalFormat,
4264 GLenum destType,
4265 GLboolean unpackFlipY,
4266 GLboolean unpackPremultiplyAlpha,
4267 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004268{
Jamie Madillbc918e72018-03-08 09:47:21 -05004269 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004270
4271 gl::Texture *sourceTexture = getTexture(sourceId);
4272 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004273 ANGLE_CONTEXT_TRY(
4274 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4275 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4276 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004277}
4278
Jamie Madill007530e2017-12-28 14:27:04 -05004279void Context::copySubTexture(GLuint sourceId,
4280 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004281 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004282 GLuint destId,
4283 GLint destLevel,
4284 GLint xoffset,
4285 GLint yoffset,
4286 GLint x,
4287 GLint y,
4288 GLsizei width,
4289 GLsizei height,
4290 GLboolean unpackFlipY,
4291 GLboolean unpackPremultiplyAlpha,
4292 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004293{
4294 // Zero sized copies are valid but no-ops
4295 if (width == 0 || height == 0)
4296 {
4297 return;
4298 }
4299
Jamie Madillbc918e72018-03-08 09:47:21 -05004300 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004301
4302 gl::Texture *sourceTexture = getTexture(sourceId);
4303 gl::Texture *destTexture = getTexture(destId);
4304 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004305 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004306 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4307 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4308 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4309 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004310}
4311
4312void Context::copyTexture3D(GLuint sourceId,
4313 GLint sourceLevel,
4314 TextureTarget destTarget,
4315 GLuint destId,
4316 GLint destLevel,
4317 GLint internalFormat,
4318 GLenum destType,
4319 GLboolean unpackFlipY,
4320 GLboolean unpackPremultiplyAlpha,
4321 GLboolean unpackUnmultiplyAlpha)
4322{
4323 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4324
4325 Texture *sourceTexture = getTexture(sourceId);
4326 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004327 ANGLE_CONTEXT_TRY(
4328 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4329 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4330 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004331}
4332
4333void Context::copySubTexture3D(GLuint sourceId,
4334 GLint sourceLevel,
4335 TextureTarget destTarget,
4336 GLuint destId,
4337 GLint destLevel,
4338 GLint xoffset,
4339 GLint yoffset,
4340 GLint zoffset,
4341 GLint x,
4342 GLint y,
4343 GLint z,
4344 GLsizei width,
4345 GLsizei height,
4346 GLsizei depth,
4347 GLboolean unpackFlipY,
4348 GLboolean unpackPremultiplyAlpha,
4349 GLboolean unpackUnmultiplyAlpha)
4350{
4351 // Zero sized copies are valid but no-ops
4352 if (width == 0 || height == 0 || depth == 0)
4353 {
4354 return;
4355 }
4356
4357 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4358
4359 Texture *sourceTexture = getTexture(sourceId);
4360 Texture *destTexture = getTexture(destId);
4361 Offset offset(xoffset, yoffset, zoffset);
4362 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004363 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4364 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4365 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4366 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004367}
4368
Jamie Madill007530e2017-12-28 14:27:04 -05004369void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004370{
Jamie Madillbc918e72018-03-08 09:47:21 -05004371 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004372
4373 gl::Texture *sourceTexture = getTexture(sourceId);
4374 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004375 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004376}
4377
Corentin Wallez336129f2017-10-17 15:55:40 -04004378void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004379{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004380 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004381 ASSERT(buffer);
4382
Geoff Lang496c02d2016-10-20 11:38:11 -07004383 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004384}
4385
Brandon Jones59770802018-04-02 13:18:42 -07004386void Context::getBufferPointervRobust(BufferBinding target,
4387 GLenum pname,
4388 GLsizei bufSize,
4389 GLsizei *length,
4390 void **params)
4391{
4392 getBufferPointerv(target, pname, params);
4393}
4394
Corentin Wallez336129f2017-10-17 15:55:40 -04004395void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004396{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004397 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004398 ASSERT(buffer);
4399
Jamie Madill7c985f52018-11-29 18:16:17 -05004400 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004401 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004402 return nullptr;
4403 }
4404
4405 return buffer->getMapPointer();
4406}
4407
Corentin Wallez336129f2017-10-17 15:55:40 -04004408GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004409{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004410 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004411 ASSERT(buffer);
4412
4413 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004414 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004415 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004416 return GL_FALSE;
4417 }
4418
4419 return result;
4420}
4421
Corentin Wallez336129f2017-10-17 15:55:40 -04004422void *Context::mapBufferRange(BufferBinding target,
4423 GLintptr offset,
4424 GLsizeiptr length,
4425 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004426{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004427 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004428 ASSERT(buffer);
4429
Jamie Madill7c985f52018-11-29 18:16:17 -05004430 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004431 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004432 return nullptr;
4433 }
4434
4435 return buffer->getMapPointer();
4436}
4437
Corentin Wallez336129f2017-10-17 15:55:40 -04004438void Context::flushMappedBufferRange(BufferBinding /*target*/,
4439 GLintptr /*offset*/,
4440 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004441{
4442 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4443}
4444
Jamie Madill526392d2018-11-16 09:35:14 -05004445angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004446{
Geoff Langa8cb2872018-03-09 16:09:40 -05004447 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004448}
4449
Jamie Madill526392d2018-11-16 09:35:14 -05004450angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004451{
Geoff Langa8cb2872018-03-09 16:09:40 -05004452 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004453}
4454
Jamie Madill526392d2018-11-16 09:35:14 -05004455angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004456{
Geoff Langa8cb2872018-03-09 16:09:40 -05004457 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004458}
4459
Jamie Madill526392d2018-11-16 09:35:14 -05004460angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004461{
4462 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4463
4464 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4465 ANGLE_TRY(syncDirtyBits());
4466
Jamie Madill7c985f52018-11-29 18:16:17 -05004467 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004468}
4469
Jiajia Qin5451d532017-11-16 17:16:34 +08004470void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4471{
4472 UNIMPLEMENTED();
4473}
4474
Jamie Madillc20ab272016-06-09 07:20:46 -07004475void Context::activeTexture(GLenum texture)
4476{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004477 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
Jamie Madill876429b2017-04-20 15:46:24 -04004480void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004481{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004482 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004485void Context::blendEquation(GLenum mode)
4486{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004487 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004488}
4489
Jamie Madillc20ab272016-06-09 07:20:46 -07004490void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4491{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004492 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004495void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4496{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004497 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004498}
4499
Jamie Madillc20ab272016-06-09 07:20:46 -07004500void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4501{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004502 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004503}
4504
Jamie Madill876429b2017-04-20 15:46:24 -04004505void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004506{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004507 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
Jamie Madill876429b2017-04-20 15:46:24 -04004510void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004511{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004512 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004513}
4514
4515void Context::clearStencil(GLint s)
4516{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004517 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
4520void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4521{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004522 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4523 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004524}
4525
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004526void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004527{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004528 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004529}
4530
4531void Context::depthFunc(GLenum func)
4532{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004533 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004534}
4535
4536void Context::depthMask(GLboolean flag)
4537{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004538 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004539}
4540
Jamie Madill876429b2017-04-20 15:46:24 -04004541void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004542{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004543 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004544}
4545
4546void Context::disable(GLenum cap)
4547{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004548 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004549 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550}
4551
4552void Context::disableVertexAttribArray(GLuint index)
4553{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004554 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004555 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556}
4557
4558void Context::enable(GLenum cap)
4559{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004560 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004561 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562}
4563
4564void Context::enableVertexAttribArray(GLuint index)
4565{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004566 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004567 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568}
4569
4570void Context::frontFace(GLenum mode)
4571{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004572 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
4575void Context::hint(GLenum target, GLenum mode)
4576{
4577 switch (target)
4578 {
4579 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004580 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581 break;
4582
4583 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004584 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585 break;
4586
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004587 case GL_PERSPECTIVE_CORRECTION_HINT:
4588 case GL_POINT_SMOOTH_HINT:
4589 case GL_LINE_SMOOTH_HINT:
4590 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004591 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004592 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004593 default:
4594 UNREACHABLE();
4595 return;
4596 }
4597}
4598
4599void Context::lineWidth(GLfloat width)
4600{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004601 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
4604void Context::pixelStorei(GLenum pname, GLint param)
4605{
4606 switch (pname)
4607 {
4608 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004609 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004610 break;
4611
4612 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004613 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004614 break;
4615
4616 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004617 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618 break;
4619
4620 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004621 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004622 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623 break;
4624
4625 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004626 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004627 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004628 break;
4629
4630 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004631 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004632 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633 break;
4634
4635 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004636 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004637 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638 break;
4639
4640 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004641 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004642 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004643 break;
4644
4645 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004646 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004647 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648 break;
4649
4650 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004651 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004652 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653 break;
4654
4655 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004656 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004657 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658 break;
4659
4660 default:
4661 UNREACHABLE();
4662 return;
4663 }
4664}
4665
4666void Context::polygonOffset(GLfloat factor, GLfloat units)
4667{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004668 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
Jamie Madill876429b2017-04-20 15:46:24 -04004671void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004672{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004673 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
Jiawei Shaodb342272017-09-27 10:21:45 +08004676void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4677{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004678 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004679}
4680
Jamie Madillc20ab272016-06-09 07:20:46 -07004681void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4682{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004683 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004684}
4685
4686void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4687{
4688 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4689 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004690 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004691 }
4692
4693 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4694 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004695 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004696 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004697
4698 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
4701void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4702{
4703 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4704 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004705 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004706 }
4707
4708 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4709 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004710 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004711 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004712
4713 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004714}
4715
4716void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4717{
4718 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4719 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004720 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004721 }
4722
4723 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4724 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004725 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004726 }
4727}
4728
4729void Context::vertexAttrib1f(GLuint index, GLfloat x)
4730{
4731 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004732 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004733 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004734}
4735
4736void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4737{
4738 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004739 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004740 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004741}
4742
4743void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4744{
4745 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004746 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004747 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004748}
4749
4750void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4751{
4752 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004753 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004754 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004755}
4756
4757void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4758{
4759 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004760 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004761 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004762}
4763
4764void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4765{
4766 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004767 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004768 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004769}
4770
4771void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4772{
4773 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004774 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004775 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004776}
4777
4778void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4779{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004780 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004781 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004782}
4783
4784void Context::vertexAttribPointer(GLuint index,
4785 GLint size,
4786 GLenum type,
4787 GLboolean normalized,
4788 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004789 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004790{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004791 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4792 type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004793 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004794}
4795
Shao80957d92017-02-20 21:25:59 +08004796void Context::vertexAttribFormat(GLuint attribIndex,
4797 GLint size,
4798 GLenum type,
4799 GLboolean normalized,
4800 GLuint relativeOffset)
4801{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004802 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4803 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004804 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004805}
4806
4807void Context::vertexAttribIFormat(GLuint attribIndex,
4808 GLint size,
4809 GLenum type,
4810 GLuint relativeOffset)
4811{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004812 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004813 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004814}
4815
4816void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4817{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004818 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004819 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004820}
4821
Jiajia Qin5451d532017-11-16 17:16:34 +08004822void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004823{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004824 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004825 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004826}
4827
Jamie Madillc20ab272016-06-09 07:20:46 -07004828void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4829{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004830 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004831}
4832
4833void Context::vertexAttribIPointer(GLuint index,
4834 GLint size,
4835 GLenum type,
4836 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004837 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004838{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004839 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4840 type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004841 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004842}
4843
4844void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4845{
4846 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004847 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004848 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004849}
4850
4851void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4852{
4853 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004854 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004855 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004856}
4857
4858void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4859{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004860 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004861 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004862}
4863
4864void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4865{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004866 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004867 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004868}
4869
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004870void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4871{
4872 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004873 getState().getVertexAttribCurrentValue(index);
4874 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004875 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4876 currentValues, pname, params);
4877}
4878
Brandon Jones59770802018-04-02 13:18:42 -07004879void Context::getVertexAttribivRobust(GLuint index,
4880 GLenum pname,
4881 GLsizei bufSize,
4882 GLsizei *length,
4883 GLint *params)
4884{
4885 getVertexAttribiv(index, pname, params);
4886}
4887
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004888void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4889{
4890 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004891 getState().getVertexAttribCurrentValue(index);
4892 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004893 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4894 currentValues, pname, params);
4895}
4896
Brandon Jones59770802018-04-02 13:18:42 -07004897void Context::getVertexAttribfvRobust(GLuint index,
4898 GLenum pname,
4899 GLsizei bufSize,
4900 GLsizei *length,
4901 GLfloat *params)
4902{
4903 getVertexAttribfv(index, pname, params);
4904}
4905
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004906void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4907{
4908 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004909 getState().getVertexAttribCurrentValue(index);
4910 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004911 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4912 currentValues, pname, params);
4913}
4914
Brandon Jones59770802018-04-02 13:18:42 -07004915void Context::getVertexAttribIivRobust(GLuint index,
4916 GLenum pname,
4917 GLsizei bufSize,
4918 GLsizei *length,
4919 GLint *params)
4920{
4921 getVertexAttribIiv(index, pname, params);
4922}
4923
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004924void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4925{
4926 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004927 getState().getVertexAttribCurrentValue(index);
4928 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004929 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4930 currentValues, pname, params);
4931}
4932
Brandon Jones59770802018-04-02 13:18:42 -07004933void Context::getVertexAttribIuivRobust(GLuint index,
4934 GLenum pname,
4935 GLsizei bufSize,
4936 GLsizei *length,
4937 GLuint *params)
4938{
4939 getVertexAttribIuiv(index, pname, params);
4940}
4941
Jamie Madill876429b2017-04-20 15:46:24 -04004942void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004943{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004944 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004945 QueryVertexAttribPointerv(attrib, pname, pointer);
4946}
4947
Brandon Jones59770802018-04-02 13:18:42 -07004948void Context::getVertexAttribPointervRobust(GLuint index,
4949 GLenum pname,
4950 GLsizei bufSize,
4951 GLsizei *length,
4952 void **pointer)
4953{
4954 getVertexAttribPointerv(index, pname, pointer);
4955}
4956
Jamie Madillc20ab272016-06-09 07:20:46 -07004957void Context::debugMessageControl(GLenum source,
4958 GLenum type,
4959 GLenum severity,
4960 GLsizei count,
4961 const GLuint *ids,
4962 GLboolean enabled)
4963{
4964 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004965 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4966 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004967}
4968
4969void Context::debugMessageInsert(GLenum source,
4970 GLenum type,
4971 GLuint id,
4972 GLenum severity,
4973 GLsizei length,
4974 const GLchar *buf)
4975{
4976 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004977 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004978}
4979
4980void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4981{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004982 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004983}
4984
4985GLuint Context::getDebugMessageLog(GLuint count,
4986 GLsizei bufSize,
4987 GLenum *sources,
4988 GLenum *types,
4989 GLuint *ids,
4990 GLenum *severities,
4991 GLsizei *lengths,
4992 GLchar *messageLog)
4993{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004994 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
4995 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004996}
4997
4998void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4999{
5000 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005001 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005002 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005003}
5004
5005void Context::popDebugGroup()
5006{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005007 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005008 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005009}
5010
Corentin Wallez336129f2017-10-17 15:55:40 -04005011void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005012{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005013 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005014 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005015 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005016}
5017
Corentin Wallez336129f2017-10-17 15:55:40 -04005018void Context::bufferSubData(BufferBinding target,
5019 GLintptr offset,
5020 GLsizeiptr size,
5021 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005022{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005023 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005024 {
5025 return;
5026 }
5027
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005028 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005029 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005030 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005031}
5032
Jamie Madillef300b12016-10-07 15:12:09 -04005033void Context::attachShader(GLuint program, GLuint shader)
5034{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005035 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5036 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005037 ASSERT(programObject && shaderObject);
5038 programObject->attachShader(shaderObject);
5039}
5040
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005041const Workarounds &Context::getWorkarounds() const
5042{
5043 return mWorkarounds;
5044}
5045
Corentin Wallez336129f2017-10-17 15:55:40 -04005046void Context::copyBufferSubData(BufferBinding readTarget,
5047 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005048 GLintptr readOffset,
5049 GLintptr writeOffset,
5050 GLsizeiptr size)
5051{
5052 // if size is zero, the copy is a successful no-op
5053 if (size == 0)
5054 {
5055 return;
5056 }
5057
5058 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005059 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5060 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005061
Jamie Madill4f6592f2018-11-27 16:37:45 -05005062 ANGLE_CONTEXT_TRY(
5063 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005064}
5065
Jamie Madill01a80ee2016-11-07 12:06:18 -05005066void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5067{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005068 // Ideally we could share the program query with the validation layer if possible.
5069 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005070 ASSERT(programObject);
5071 programObject->bindAttributeLocation(index, name);
5072}
5073
Corentin Wallez336129f2017-10-17 15:55:40 -04005074void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005075{
5076 bindBufferRange(target, index, buffer, 0, 0);
5077}
5078
Corentin Wallez336129f2017-10-17 15:55:40 -04005079void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005080 GLuint index,
5081 GLuint buffer,
5082 GLintptr offset,
5083 GLsizeiptr size)
5084{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005085 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5086 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005087 if (target == BufferBinding::Uniform)
5088 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005089 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005090 mStateCache.onUniformBufferStateChange(this);
5091 }
5092 else
5093 {
5094 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005095 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005096}
5097
Jamie Madill01a80ee2016-11-07 12:06:18 -05005098void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5099{
5100 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5101 {
5102 bindReadFramebuffer(framebuffer);
5103 }
5104
5105 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5106 {
5107 bindDrawFramebuffer(framebuffer);
5108 }
5109}
5110
5111void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5112{
5113 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005114 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5115 mImplementation.get(), renderbuffer);
5116 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005117}
5118
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005119void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005120 GLsizei samples,
5121 GLenum internalformat,
5122 GLsizei width,
5123 GLsizei height,
5124 GLboolean fixedsamplelocations)
5125{
5126 Extents size(width, height, 1);
5127 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005128 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5129 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005130}
5131
Olli Etuaho89664842018-08-24 14:45:36 +03005132void Context::texStorage3DMultisample(TextureType target,
5133 GLsizei samples,
5134 GLenum internalformat,
5135 GLsizei width,
5136 GLsizei height,
5137 GLsizei depth,
5138 GLboolean fixedsamplelocations)
5139{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005140 Extents size(width, height, depth);
5141 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005142 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5143 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005144}
5145
JiangYizhoubddc46b2016-12-09 09:50:51 +08005146void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5147{
JiangYizhou5b03f472017-01-09 10:22:53 +08005148 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5149 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005150 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5151 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005152
5153 switch (pname)
5154 {
5155 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005156 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005157 break;
5158 default:
5159 UNREACHABLE();
5160 }
5161}
5162
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005163void Context::getMultisamplefvRobust(GLenum pname,
5164 GLuint index,
5165 GLsizei bufSize,
5166 GLsizei *length,
5167 GLfloat *val)
5168{
5169 UNIMPLEMENTED();
5170}
5171
Jamie Madille8fb6402017-02-14 17:56:40 -05005172void Context::renderbufferStorage(GLenum target,
5173 GLenum internalformat,
5174 GLsizei width,
5175 GLsizei height)
5176{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005177 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5178 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5179
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005180 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005181 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005182}
5183
5184void Context::renderbufferStorageMultisample(GLenum target,
5185 GLsizei samples,
5186 GLenum internalformat,
5187 GLsizei width,
5188 GLsizei height)
5189{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005190 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5191 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005192
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005193 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005194 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005195 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005196}
5197
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005198void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5199{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005200 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005201 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005202}
5203
JiangYizhoue18e6392017-02-20 10:32:23 +08005204void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5205{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005206 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005207 QueryFramebufferParameteriv(framebuffer, pname, params);
5208}
5209
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005210void Context::getFramebufferParameterivRobust(GLenum target,
5211 GLenum pname,
5212 GLsizei bufSize,
5213 GLsizei *length,
5214 GLint *params)
5215{
5216 UNIMPLEMENTED();
5217}
5218
Jiajia Qin5451d532017-11-16 17:16:34 +08005219void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005220{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005221 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005222 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005223}
5224
Jamie Madilldec86232018-07-11 09:01:18 -04005225bool Context::getScratchBuffer(size_t requstedSizeBytes,
5226 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005227{
Jamie Madilldec86232018-07-11 09:01:18 -04005228 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005229}
5230
Jamie Madilldec86232018-07-11 09:01:18 -04005231bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5232 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005233{
Jamie Madilldec86232018-07-11 09:01:18 -04005234 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005235}
5236
Xinghua Cao2b396592017-03-29 15:36:04 +08005237void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5238{
5239 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5240 {
5241 return;
5242 }
5243
Xinghua Cao10a4d432017-11-28 14:46:26 +08005244 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005245 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005246}
5247
Jiajia Qin5451d532017-11-16 17:16:34 +08005248void Context::dispatchComputeIndirect(GLintptr indirect)
5249{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005250 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005251 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005252}
5253
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005254void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005255 GLsizei levels,
5256 GLenum internalFormat,
5257 GLsizei width,
5258 GLsizei height)
5259{
5260 Extents size(width, height, 1);
5261 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005262 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005263}
5264
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005265void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005266 GLsizei levels,
5267 GLenum internalFormat,
5268 GLsizei width,
5269 GLsizei height,
5270 GLsizei depth)
5271{
5272 Extents size(width, height, depth);
5273 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005274 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005275}
5276
Jiajia Qin5451d532017-11-16 17:16:34 +08005277void Context::memoryBarrier(GLbitfield barriers)
5278{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005279 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005280}
5281
5282void Context::memoryBarrierByRegion(GLbitfield barriers)
5283{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005284 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005285}
5286
Austin Eng1bf18ce2018-10-19 15:34:02 -07005287void Context::multiDrawArrays(PrimitiveMode mode,
5288 const GLint *firsts,
5289 const GLsizei *counts,
5290 GLsizei drawcount)
5291{
5292 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005293 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005294 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5295 if (hasDrawID)
5296 {
5297 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5298 {
5299 if (noopDraw(mode, counts[drawID]))
5300 {
5301 continue;
5302 }
5303 programObject->setDrawIDUniform(drawID);
5304 ANGLE_CONTEXT_TRY(
5305 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005306 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005307 }
5308 }
5309 else
5310 {
5311 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5312 {
5313 if (noopDraw(mode, counts[drawID]))
5314 {
5315 continue;
5316 }
5317 ANGLE_CONTEXT_TRY(
5318 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005319 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005320 }
5321 }
5322}
5323
5324void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5325 const GLint *firsts,
5326 const GLsizei *counts,
5327 const GLsizei *instanceCounts,
5328 GLsizei drawcount)
5329{
5330 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005331 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005332 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5333 if (hasDrawID)
5334 {
5335 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5336 {
5337 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5338 {
5339 continue;
5340 }
5341 programObject->setDrawIDUniform(drawID);
5342 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5343 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005344 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005345 }
5346 }
5347 else
5348 {
5349 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5350 {
5351 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5352 {
5353 continue;
5354 }
5355 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5356 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005357 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005358 }
5359 }
5360}
5361
5362void Context::multiDrawElements(PrimitiveMode mode,
5363 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005364 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005365 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005366 GLsizei drawcount)
5367{
5368 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005369 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005370 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5371 if (hasDrawID)
5372 {
5373 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5374 {
5375 if (noopDraw(mode, counts[drawID]))
5376 {
5377 continue;
5378 }
5379 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005380 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005381 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005382 }
5383 }
5384 else
5385 {
5386 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5387 {
5388 if (noopDraw(mode, counts[drawID]))
5389 {
5390 continue;
5391 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005392 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005393 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005394 }
5395 }
5396}
5397
5398void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5399 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005400 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005401 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005402 const GLsizei *instanceCounts,
5403 GLsizei drawcount)
5404{
5405 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005406 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005407 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5408 if (hasDrawID)
5409 {
5410 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5411 {
5412 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5413 {
5414 continue;
5415 }
5416 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005417 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005418 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005419 }
5420 }
5421 else
5422 {
5423 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5424 {
5425 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5426 {
5427 continue;
5428 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005429 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005430 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005431 }
5432 }
5433}
5434
Jamie Madillc1d770e2017-04-13 17:31:24 -04005435GLenum Context::checkFramebufferStatus(GLenum target)
5436{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005437 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005438 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005439 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005440}
5441
5442void Context::compileShader(GLuint shader)
5443{
5444 Shader *shaderObject = GetValidShader(this, shader);
5445 if (!shaderObject)
5446 {
5447 return;
5448 }
5449 shaderObject->compile(this);
5450}
5451
5452void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5453{
5454 for (int i = 0; i < n; i++)
5455 {
5456 deleteBuffer(buffers[i]);
5457 }
5458}
5459
5460void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5461{
5462 for (int i = 0; i < n; i++)
5463 {
5464 if (framebuffers[i] != 0)
5465 {
5466 deleteFramebuffer(framebuffers[i]);
5467 }
5468 }
5469}
5470
5471void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5472{
5473 for (int i = 0; i < n; i++)
5474 {
5475 deleteRenderbuffer(renderbuffers[i]);
5476 }
5477}
5478
5479void Context::deleteTextures(GLsizei n, const GLuint *textures)
5480{
5481 for (int i = 0; i < n; i++)
5482 {
5483 if (textures[i] != 0)
5484 {
5485 deleteTexture(textures[i]);
5486 }
5487 }
5488}
5489
5490void Context::detachShader(GLuint program, GLuint shader)
5491{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005492 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005493 ASSERT(programObject);
5494
5495 Shader *shaderObject = getShader(shader);
5496 ASSERT(shaderObject);
5497
5498 programObject->detachShader(this, shaderObject);
5499}
5500
5501void Context::genBuffers(GLsizei n, GLuint *buffers)
5502{
5503 for (int i = 0; i < n; i++)
5504 {
5505 buffers[i] = createBuffer();
5506 }
5507}
5508
5509void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5510{
5511 for (int i = 0; i < n; i++)
5512 {
5513 framebuffers[i] = createFramebuffer();
5514 }
5515}
5516
5517void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5518{
5519 for (int i = 0; i < n; i++)
5520 {
5521 renderbuffers[i] = createRenderbuffer();
5522 }
5523}
5524
5525void Context::genTextures(GLsizei n, GLuint *textures)
5526{
5527 for (int i = 0; i < n; i++)
5528 {
5529 textures[i] = createTexture();
5530 }
5531}
5532
5533void Context::getActiveAttrib(GLuint program,
5534 GLuint index,
5535 GLsizei bufsize,
5536 GLsizei *length,
5537 GLint *size,
5538 GLenum *type,
5539 GLchar *name)
5540{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005541 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542 ASSERT(programObject);
5543 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5544}
5545
5546void Context::getActiveUniform(GLuint program,
5547 GLuint index,
5548 GLsizei bufsize,
5549 GLsizei *length,
5550 GLint *size,
5551 GLenum *type,
5552 GLchar *name)
5553{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005554 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005555 ASSERT(programObject);
5556 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5557}
5558
5559void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5560{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005561 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005562 ASSERT(programObject);
5563 programObject->getAttachedShaders(maxcount, count, shaders);
5564}
5565
5566GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5567{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005568 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005569 ASSERT(programObject);
5570 return programObject->getAttributeLocation(name);
5571}
5572
5573void Context::getBooleanv(GLenum pname, GLboolean *params)
5574{
5575 GLenum nativeType;
5576 unsigned int numParams = 0;
5577 getQueryParameterInfo(pname, &nativeType, &numParams);
5578
5579 if (nativeType == GL_BOOL)
5580 {
5581 getBooleanvImpl(pname, params);
5582 }
5583 else
5584 {
5585 CastStateValues(this, nativeType, pname, numParams, params);
5586 }
5587}
5588
Brandon Jones59770802018-04-02 13:18:42 -07005589void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5590{
5591 getBooleanv(pname, params);
5592}
5593
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594void Context::getFloatv(GLenum pname, GLfloat *params)
5595{
5596 GLenum nativeType;
5597 unsigned int numParams = 0;
5598 getQueryParameterInfo(pname, &nativeType, &numParams);
5599
5600 if (nativeType == GL_FLOAT)
5601 {
5602 getFloatvImpl(pname, params);
5603 }
5604 else
5605 {
5606 CastStateValues(this, nativeType, pname, numParams, params);
5607 }
5608}
5609
Brandon Jones59770802018-04-02 13:18:42 -07005610void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5611{
5612 getFloatv(pname, params);
5613}
5614
Jamie Madillc1d770e2017-04-13 17:31:24 -04005615void Context::getIntegerv(GLenum pname, GLint *params)
5616{
5617 GLenum nativeType;
5618 unsigned int numParams = 0;
5619 getQueryParameterInfo(pname, &nativeType, &numParams);
5620
5621 if (nativeType == GL_INT)
5622 {
5623 getIntegervImpl(pname, params);
5624 }
5625 else
5626 {
5627 CastStateValues(this, nativeType, pname, numParams, params);
5628 }
5629}
5630
Brandon Jones59770802018-04-02 13:18:42 -07005631void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5632{
5633 getIntegerv(pname, data);
5634}
5635
Jamie Madillc1d770e2017-04-13 17:31:24 -04005636void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5637{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005638 // Don't resolve link if checking the link completion status.
5639 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5640 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005641 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005642 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005643}
5644
Brandon Jones59770802018-04-02 13:18:42 -07005645void Context::getProgramivRobust(GLuint program,
5646 GLenum pname,
5647 GLsizei bufSize,
5648 GLsizei *length,
5649 GLint *params)
5650{
5651 getProgramiv(program, pname, params);
5652}
5653
Jiajia Qin5451d532017-11-16 17:16:34 +08005654void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5655{
5656 UNIMPLEMENTED();
5657}
5658
Jamie Madillbe849e42017-05-02 15:49:00 -04005659void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005660{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005661 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005662 ASSERT(programObject);
5663 programObject->getInfoLog(bufsize, length, infolog);
5664}
5665
Jiajia Qin5451d532017-11-16 17:16:34 +08005666void Context::getProgramPipelineInfoLog(GLuint pipeline,
5667 GLsizei bufSize,
5668 GLsizei *length,
5669 GLchar *infoLog)
5670{
5671 UNIMPLEMENTED();
5672}
5673
Jamie Madillc1d770e2017-04-13 17:31:24 -04005674void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5675{
5676 Shader *shaderObject = getShader(shader);
5677 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005678 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005679}
5680
Brandon Jones59770802018-04-02 13:18:42 -07005681void Context::getShaderivRobust(GLuint shader,
5682 GLenum pname,
5683 GLsizei bufSize,
5684 GLsizei *length,
5685 GLint *params)
5686{
5687 getShaderiv(shader, pname, params);
5688}
5689
Jamie Madillc1d770e2017-04-13 17:31:24 -04005690void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5691{
5692 Shader *shaderObject = getShader(shader);
5693 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005694 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695}
5696
5697void Context::getShaderPrecisionFormat(GLenum shadertype,
5698 GLenum precisiontype,
5699 GLint *range,
5700 GLint *precision)
5701{
5702 // TODO(jmadill): Compute shaders.
5703
5704 switch (shadertype)
5705 {
5706 case GL_VERTEX_SHADER:
5707 switch (precisiontype)
5708 {
5709 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005710 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005711 break;
5712 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005713 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005714 break;
5715 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005716 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717 break;
5718
5719 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005720 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005721 break;
5722 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005723 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724 break;
5725 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005726 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727 break;
5728
5729 default:
5730 UNREACHABLE();
5731 return;
5732 }
5733 break;
5734
5735 case GL_FRAGMENT_SHADER:
5736 switch (precisiontype)
5737 {
5738 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005739 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005740 break;
5741 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005742 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 break;
5744 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005745 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005746 break;
5747
5748 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005749 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750 break;
5751 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005752 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005753 break;
5754 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005755 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756 break;
5757
5758 default:
5759 UNREACHABLE();
5760 return;
5761 }
5762 break;
5763
5764 default:
5765 UNREACHABLE();
5766 return;
5767 }
5768}
5769
5770void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5771{
5772 Shader *shaderObject = getShader(shader);
5773 ASSERT(shaderObject);
5774 shaderObject->getSource(bufsize, length, source);
5775}
5776
5777void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5778{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005779 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005780 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005781 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005782}
5783
Brandon Jones59770802018-04-02 13:18:42 -07005784void Context::getUniformfvRobust(GLuint program,
5785 GLint location,
5786 GLsizei bufSize,
5787 GLsizei *length,
5788 GLfloat *params)
5789{
5790 getUniformfv(program, location, params);
5791}
5792
Jamie Madillc1d770e2017-04-13 17:31:24 -04005793void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5794{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005795 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005797 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005798}
5799
Brandon Jones59770802018-04-02 13:18:42 -07005800void Context::getUniformivRobust(GLuint program,
5801 GLint location,
5802 GLsizei bufSize,
5803 GLsizei *length,
5804 GLint *params)
5805{
5806 getUniformiv(program, location, params);
5807}
5808
Jamie Madillc1d770e2017-04-13 17:31:24 -04005809GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5810{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005811 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005812 ASSERT(programObject);
5813 return programObject->getUniformLocation(name);
5814}
5815
5816GLboolean Context::isBuffer(GLuint buffer)
5817{
5818 if (buffer == 0)
5819 {
5820 return GL_FALSE;
5821 }
5822
5823 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5824}
5825
5826GLboolean Context::isEnabled(GLenum cap)
5827{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005828 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005829}
5830
5831GLboolean Context::isFramebuffer(GLuint framebuffer)
5832{
5833 if (framebuffer == 0)
5834 {
5835 return GL_FALSE;
5836 }
5837
5838 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5839}
5840
5841GLboolean Context::isProgram(GLuint program)
5842{
5843 if (program == 0)
5844 {
5845 return GL_FALSE;
5846 }
5847
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005848 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005849}
5850
5851GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5852{
5853 if (renderbuffer == 0)
5854 {
5855 return GL_FALSE;
5856 }
5857
5858 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5859}
5860
5861GLboolean Context::isShader(GLuint shader)
5862{
5863 if (shader == 0)
5864 {
5865 return GL_FALSE;
5866 }
5867
5868 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5869}
5870
5871GLboolean Context::isTexture(GLuint texture)
5872{
5873 if (texture == 0)
5874 {
5875 return GL_FALSE;
5876 }
5877
5878 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5879}
5880
5881void Context::linkProgram(GLuint program)
5882{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005883 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005884 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005885 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005886
5887 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5888 // don't need to worry that:
5889 // 1. Draw calls after link use the new executable code or the old one depending on the link
5890 // result.
5891 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5892 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5893 // ProgramD3D.
5894 if (programObject->isInUse())
5895 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005896 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005897 if (programObject->isLinked())
5898 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005899 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005900 }
jchen107ae70d82018-07-06 13:47:01 +08005901 mStateCache.onProgramExecutableChange(this);
5902 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005903}
5904
5905void Context::releaseShaderCompiler()
5906{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005907 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005908}
5909
5910void Context::shaderBinary(GLsizei n,
5911 const GLuint *shaders,
5912 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005913 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005914 GLsizei length)
5915{
5916 // No binary shader formats are supported.
5917 UNIMPLEMENTED();
5918}
5919
Olli Etuaho0ca09752018-09-24 11:00:50 +03005920void Context::bindFragDataLocationIndexed(GLuint program,
5921 GLuint colorNumber,
5922 GLuint index,
5923 const char *name)
5924{
5925 Program *programObject = getProgramNoResolveLink(program);
5926 programObject->bindFragmentOutputLocation(colorNumber, name);
5927 programObject->bindFragmentOutputIndex(index, name);
5928}
5929
5930void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5931{
5932 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5933}
5934
5935int Context::getFragDataIndex(GLuint program, const char *name)
5936{
5937 Program *programObject = getProgramResolveLink(program);
5938 return programObject->getFragDataIndex(name);
5939}
5940
5941int Context::getProgramResourceLocationIndex(GLuint program,
5942 GLenum programInterface,
5943 const char *name)
5944{
5945 Program *programObject = getProgramResolveLink(program);
5946 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5947 return programObject->getFragDataIndex(name);
5948}
5949
Jamie Madillc1d770e2017-04-13 17:31:24 -04005950void Context::shaderSource(GLuint shader,
5951 GLsizei count,
5952 const GLchar *const *string,
5953 const GLint *length)
5954{
5955 Shader *shaderObject = getShader(shader);
5956 ASSERT(shaderObject);
5957 shaderObject->setSource(count, string, length);
5958}
5959
5960void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5961{
5962 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5963}
5964
5965void Context::stencilMask(GLuint mask)
5966{
5967 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5968}
5969
5970void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5971{
5972 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5973}
5974
5975void Context::uniform1f(GLint location, GLfloat x)
5976{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005977 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005978 program->setUniform1fv(location, 1, &x);
5979}
5980
5981void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5982{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005983 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005984 program->setUniform1fv(location, count, v);
5985}
5986
Jamie Madill7e4eff12018-08-08 15:49:26 -04005987void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988{
Jamie Madille3e680c2018-12-03 17:49:08 -05005989 program->setUniform1iv(this, location, count, v);
5990}
5991
5992void Context::onSamplerUniformChange(size_t textureUnitIndex)
5993{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005994 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05005995 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005996}
5997
Jamie Madill7e4eff12018-08-08 15:49:26 -04005998void Context::uniform1i(GLint location, GLint x)
5999{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006000 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006001}
6002
Jamie Madillc1d770e2017-04-13 17:31:24 -04006003void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6004{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006005 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006}
6007
6008void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6009{
6010 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006011 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006012 program->setUniform2fv(location, 1, xy);
6013}
6014
6015void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6016{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006017 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006018 program->setUniform2fv(location, count, v);
6019}
6020
6021void Context::uniform2i(GLint location, GLint x, GLint y)
6022{
6023 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006024 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006025 program->setUniform2iv(location, 1, xy);
6026}
6027
6028void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6029{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006030 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006031 program->setUniform2iv(location, count, v);
6032}
6033
6034void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6035{
6036 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006037 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006038 program->setUniform3fv(location, 1, xyz);
6039}
6040
6041void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6042{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006043 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006044 program->setUniform3fv(location, count, v);
6045}
6046
6047void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6048{
6049 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006050 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006051 program->setUniform3iv(location, 1, xyz);
6052}
6053
6054void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6055{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006056 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006057 program->setUniform3iv(location, count, v);
6058}
6059
6060void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6061{
6062 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006063 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006064 program->setUniform4fv(location, 1, xyzw);
6065}
6066
6067void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6068{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006069 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006070 program->setUniform4fv(location, count, v);
6071}
6072
6073void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6074{
6075 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006076 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006077 program->setUniform4iv(location, 1, xyzw);
6078}
6079
6080void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6081{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006082 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006083 program->setUniform4iv(location, count, v);
6084}
6085
6086void Context::uniformMatrix2fv(GLint location,
6087 GLsizei count,
6088 GLboolean transpose,
6089 const GLfloat *value)
6090{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006091 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006092 program->setUniformMatrix2fv(location, count, transpose, value);
6093}
6094
6095void Context::uniformMatrix3fv(GLint location,
6096 GLsizei count,
6097 GLboolean transpose,
6098 const GLfloat *value)
6099{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006100 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006101 program->setUniformMatrix3fv(location, count, transpose, value);
6102}
6103
6104void Context::uniformMatrix4fv(GLint location,
6105 GLsizei count,
6106 GLboolean transpose,
6107 const GLfloat *value)
6108{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006109 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006110 program->setUniformMatrix4fv(location, count, transpose, value);
6111}
6112
6113void Context::validateProgram(GLuint program)
6114{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006115 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006116 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006117 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006118}
6119
Jiajia Qin5451d532017-11-16 17:16:34 +08006120void Context::validateProgramPipeline(GLuint pipeline)
6121{
6122 UNIMPLEMENTED();
6123}
6124
Jamie Madilld04908b2017-06-09 14:15:35 -04006125void Context::getProgramBinary(GLuint program,
6126 GLsizei bufSize,
6127 GLsizei *length,
6128 GLenum *binaryFormat,
6129 void *binary)
6130{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006131 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006132 ASSERT(programObject != nullptr);
6133
Jamie Madill4f6592f2018-11-27 16:37:45 -05006134 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006135}
6136
6137void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6138{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006139 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006140 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006141
Jamie Madill4f6592f2018-11-27 16:37:45 -05006142 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006143 if (programObject->isInUse())
6144 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006145 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006146 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006147 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006148}
6149
Jamie Madillff325f12017-08-26 15:06:05 -04006150void Context::uniform1ui(GLint location, GLuint v0)
6151{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006152 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006153 program->setUniform1uiv(location, 1, &v0);
6154}
6155
6156void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6157{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006158 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006159 const GLuint xy[] = {v0, v1};
6160 program->setUniform2uiv(location, 1, xy);
6161}
6162
6163void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6164{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006165 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006166 const GLuint xyz[] = {v0, v1, v2};
6167 program->setUniform3uiv(location, 1, xyz);
6168}
6169
6170void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6171{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006172 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006173 const GLuint xyzw[] = {v0, v1, v2, v3};
6174 program->setUniform4uiv(location, 1, xyzw);
6175}
6176
6177void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6178{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006179 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006180 program->setUniform1uiv(location, count, value);
6181}
6182void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6183{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006184 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006185 program->setUniform2uiv(location, count, value);
6186}
6187
6188void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6189{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006190 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006191 program->setUniform3uiv(location, count, value);
6192}
6193
6194void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6195{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006196 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006197 program->setUniform4uiv(location, count, value);
6198}
6199
Jamie Madillf0e04492017-08-26 15:28:42 -04006200void Context::genQueries(GLsizei n, GLuint *ids)
6201{
6202 for (GLsizei i = 0; i < n; i++)
6203 {
6204 GLuint handle = mQueryHandleAllocator.allocate();
6205 mQueryMap.assign(handle, nullptr);
6206 ids[i] = handle;
6207 }
6208}
6209
6210void Context::deleteQueries(GLsizei n, const GLuint *ids)
6211{
6212 for (int i = 0; i < n; i++)
6213 {
6214 GLuint query = ids[i];
6215
6216 Query *queryObject = nullptr;
6217 if (mQueryMap.erase(query, &queryObject))
6218 {
6219 mQueryHandleAllocator.release(query);
6220 if (queryObject)
6221 {
6222 queryObject->release(this);
6223 }
6224 }
6225 }
6226}
6227
6228GLboolean Context::isQuery(GLuint id)
6229{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006230 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006231}
6232
Jamie Madillc8c95812017-08-26 18:40:09 -04006233void Context::uniformMatrix2x3fv(GLint location,
6234 GLsizei count,
6235 GLboolean transpose,
6236 const GLfloat *value)
6237{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006238 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006239 program->setUniformMatrix2x3fv(location, count, transpose, value);
6240}
6241
6242void Context::uniformMatrix3x2fv(GLint location,
6243 GLsizei count,
6244 GLboolean transpose,
6245 const GLfloat *value)
6246{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006247 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006248 program->setUniformMatrix3x2fv(location, count, transpose, value);
6249}
6250
6251void Context::uniformMatrix2x4fv(GLint location,
6252 GLsizei count,
6253 GLboolean transpose,
6254 const GLfloat *value)
6255{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006256 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006257 program->setUniformMatrix2x4fv(location, count, transpose, value);
6258}
6259
6260void Context::uniformMatrix4x2fv(GLint location,
6261 GLsizei count,
6262 GLboolean transpose,
6263 const GLfloat *value)
6264{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006265 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006266 program->setUniformMatrix4x2fv(location, count, transpose, value);
6267}
6268
6269void Context::uniformMatrix3x4fv(GLint location,
6270 GLsizei count,
6271 GLboolean transpose,
6272 const GLfloat *value)
6273{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006274 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006275 program->setUniformMatrix3x4fv(location, count, transpose, value);
6276}
6277
6278void Context::uniformMatrix4x3fv(GLint location,
6279 GLsizei count,
6280 GLboolean transpose,
6281 const GLfloat *value)
6282{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006283 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006284 program->setUniformMatrix4x3fv(location, count, transpose, value);
6285}
6286
Jamie Madilld7576732017-08-26 18:49:50 -04006287void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6288{
6289 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6290 {
6291 GLuint vertexArray = arrays[arrayIndex];
6292
6293 if (arrays[arrayIndex] != 0)
6294 {
6295 VertexArray *vertexArrayObject = nullptr;
6296 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6297 {
6298 if (vertexArrayObject != nullptr)
6299 {
6300 detachVertexArray(vertexArray);
6301 vertexArrayObject->onDestroy(this);
6302 }
6303
6304 mVertexArrayHandleAllocator.release(vertexArray);
6305 }
6306 }
6307 }
6308}
6309
6310void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6311{
6312 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6313 {
6314 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6315 mVertexArrayMap.assign(vertexArray, nullptr);
6316 arrays[arrayIndex] = vertexArray;
6317 }
6318}
6319
6320bool Context::isVertexArray(GLuint array)
6321{
6322 if (array == 0)
6323 {
6324 return GL_FALSE;
6325 }
6326
6327 VertexArray *vao = getVertexArray(array);
6328 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6329}
6330
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006331void Context::endTransformFeedback()
6332{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006333 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006334 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006335 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006336}
6337
6338void Context::transformFeedbackVaryings(GLuint program,
6339 GLsizei count,
6340 const GLchar *const *varyings,
6341 GLenum bufferMode)
6342{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006343 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006344 ASSERT(programObject);
6345 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6346}
6347
6348void Context::getTransformFeedbackVarying(GLuint program,
6349 GLuint index,
6350 GLsizei bufSize,
6351 GLsizei *length,
6352 GLsizei *size,
6353 GLenum *type,
6354 GLchar *name)
6355{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006356 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006357 ASSERT(programObject);
6358 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6359}
6360
6361void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6362{
6363 for (int i = 0; i < n; i++)
6364 {
6365 GLuint transformFeedback = ids[i];
6366 if (transformFeedback == 0)
6367 {
6368 continue;
6369 }
6370
6371 TransformFeedback *transformFeedbackObject = nullptr;
6372 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6373 {
6374 if (transformFeedbackObject != nullptr)
6375 {
6376 detachTransformFeedback(transformFeedback);
6377 transformFeedbackObject->release(this);
6378 }
6379
6380 mTransformFeedbackHandleAllocator.release(transformFeedback);
6381 }
6382 }
6383}
6384
6385void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6386{
6387 for (int i = 0; i < n; i++)
6388 {
6389 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6390 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6391 ids[i] = transformFeedback;
6392 }
6393}
6394
6395bool Context::isTransformFeedback(GLuint id)
6396{
6397 if (id == 0)
6398 {
6399 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6400 // returns FALSE
6401 return GL_FALSE;
6402 }
6403
6404 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6405 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6406}
6407
6408void Context::pauseTransformFeedback()
6409{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006410 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006411 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006412 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006413}
6414
6415void Context::resumeTransformFeedback()
6416{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006417 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006418 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006419 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006420}
6421
Jamie Madill12e957f2017-08-26 21:42:26 -04006422void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6423{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006424 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006425 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006426}
6427
Brandon Jones59770802018-04-02 13:18:42 -07006428void Context::getUniformuivRobust(GLuint program,
6429 GLint location,
6430 GLsizei bufSize,
6431 GLsizei *length,
6432 GLuint *params)
6433{
6434 getUniformuiv(program, location, params);
6435}
6436
Jamie Madill12e957f2017-08-26 21:42:26 -04006437GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6438{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006439 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006440 return programObject->getFragDataLocation(name);
6441}
6442
6443void Context::getUniformIndices(GLuint program,
6444 GLsizei uniformCount,
6445 const GLchar *const *uniformNames,
6446 GLuint *uniformIndices)
6447{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006448 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006449 if (!programObject->isLinked())
6450 {
6451 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6452 {
6453 uniformIndices[uniformId] = GL_INVALID_INDEX;
6454 }
6455 }
6456 else
6457 {
6458 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6459 {
6460 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6461 }
6462 }
6463}
6464
6465void Context::getActiveUniformsiv(GLuint program,
6466 GLsizei uniformCount,
6467 const GLuint *uniformIndices,
6468 GLenum pname,
6469 GLint *params)
6470{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006471 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006472 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6473 {
6474 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006475 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006476 }
6477}
6478
6479GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6480{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006481 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006482 return programObject->getUniformBlockIndex(uniformBlockName);
6483}
6484
6485void Context::getActiveUniformBlockiv(GLuint program,
6486 GLuint uniformBlockIndex,
6487 GLenum pname,
6488 GLint *params)
6489{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006490 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006491 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6492}
6493
Brandon Jones59770802018-04-02 13:18:42 -07006494void Context::getActiveUniformBlockivRobust(GLuint program,
6495 GLuint uniformBlockIndex,
6496 GLenum pname,
6497 GLsizei bufSize,
6498 GLsizei *length,
6499 GLint *params)
6500{
6501 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6502}
6503
Jamie Madill12e957f2017-08-26 21:42:26 -04006504void Context::getActiveUniformBlockName(GLuint program,
6505 GLuint uniformBlockIndex,
6506 GLsizei bufSize,
6507 GLsizei *length,
6508 GLchar *uniformBlockName)
6509{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006510 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006511 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6512}
6513
6514void Context::uniformBlockBinding(GLuint program,
6515 GLuint uniformBlockIndex,
6516 GLuint uniformBlockBinding)
6517{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006518 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006519 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006520
Jamie Madill956ab4d2018-10-10 16:13:03 -04006521 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006522 if (programObject->isInUse())
6523 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006524 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006525 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006526 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006527}
6528
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006529GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6530{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006531 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006532 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006533
Jamie Madill70b5bb02017-08-28 13:32:37 -04006534 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006535 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006536 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006537 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006538 return nullptr;
6539 }
6540
Jamie Madill70b5bb02017-08-28 13:32:37 -04006541 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006542}
6543
6544GLboolean Context::isSync(GLsync sync)
6545{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006546 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006547}
6548
6549GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6550{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006551 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006552
6553 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006554 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006555 {
6556 return GL_WAIT_FAILED;
6557 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006558 return result;
6559}
6560
6561void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6562{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006563 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006564 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006565}
6566
6567void Context::getInteger64v(GLenum pname, GLint64 *params)
6568{
6569 GLenum nativeType = GL_NONE;
6570 unsigned int numParams = 0;
6571 getQueryParameterInfo(pname, &nativeType, &numParams);
6572
6573 if (nativeType == GL_INT_64_ANGLEX)
6574 {
6575 getInteger64vImpl(pname, params);
6576 }
6577 else
6578 {
6579 CastStateValues(this, nativeType, pname, numParams, params);
6580 }
6581}
6582
Brandon Jones59770802018-04-02 13:18:42 -07006583void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6584{
6585 getInteger64v(pname, data);
6586}
6587
Corentin Wallez336129f2017-10-17 15:55:40 -04006588void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006589{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006590 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006591 QueryBufferParameteri64v(buffer, pname, params);
6592}
6593
Brandon Jones59770802018-04-02 13:18:42 -07006594void Context::getBufferParameteri64vRobust(BufferBinding target,
6595 GLenum pname,
6596 GLsizei bufSize,
6597 GLsizei *length,
6598 GLint64 *params)
6599{
6600 getBufferParameteri64v(target, pname, params);
6601}
6602
Jamie Madill3ef140a2017-08-26 23:11:21 -04006603void Context::genSamplers(GLsizei count, GLuint *samplers)
6604{
6605 for (int i = 0; i < count; i++)
6606 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006607 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006608 }
6609}
6610
6611void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6612{
6613 for (int i = 0; i < count; i++)
6614 {
6615 GLuint sampler = samplers[i];
6616
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006617 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006618 {
6619 detachSampler(sampler);
6620 }
6621
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006622 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006623 }
6624}
6625
6626void Context::getInternalformativ(GLenum target,
6627 GLenum internalformat,
6628 GLenum pname,
6629 GLsizei bufSize,
6630 GLint *params)
6631{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006632 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006633 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6634}
6635
Brandon Jones59770802018-04-02 13:18:42 -07006636void Context::getInternalformativRobust(GLenum target,
6637 GLenum internalformat,
6638 GLenum pname,
6639 GLsizei bufSize,
6640 GLsizei *length,
6641 GLint *params)
6642{
6643 getInternalformativ(target, internalformat, pname, bufSize, params);
6644}
6645
Jiajia Qin5451d532017-11-16 17:16:34 +08006646void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6647{
6648 programUniform1iv(program, location, 1, &v0);
6649}
6650
6651void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6652{
6653 GLint xy[2] = {v0, v1};
6654 programUniform2iv(program, location, 1, xy);
6655}
6656
6657void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6658{
6659 GLint xyz[3] = {v0, v1, v2};
6660 programUniform3iv(program, location, 1, xyz);
6661}
6662
6663void Context::programUniform4i(GLuint program,
6664 GLint location,
6665 GLint v0,
6666 GLint v1,
6667 GLint v2,
6668 GLint v3)
6669{
6670 GLint xyzw[4] = {v0, v1, v2, v3};
6671 programUniform4iv(program, location, 1, xyzw);
6672}
6673
6674void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6675{
6676 programUniform1uiv(program, location, 1, &v0);
6677}
6678
6679void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6680{
6681 GLuint xy[2] = {v0, v1};
6682 programUniform2uiv(program, location, 1, xy);
6683}
6684
6685void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6686{
6687 GLuint xyz[3] = {v0, v1, v2};
6688 programUniform3uiv(program, location, 1, xyz);
6689}
6690
6691void Context::programUniform4ui(GLuint program,
6692 GLint location,
6693 GLuint v0,
6694 GLuint v1,
6695 GLuint v2,
6696 GLuint v3)
6697{
6698 GLuint xyzw[4] = {v0, v1, v2, v3};
6699 programUniform4uiv(program, location, 1, xyzw);
6700}
6701
6702void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6703{
6704 programUniform1fv(program, location, 1, &v0);
6705}
6706
6707void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6708{
6709 GLfloat xy[2] = {v0, v1};
6710 programUniform2fv(program, location, 1, xy);
6711}
6712
6713void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6714{
6715 GLfloat xyz[3] = {v0, v1, v2};
6716 programUniform3fv(program, location, 1, xyz);
6717}
6718
6719void Context::programUniform4f(GLuint program,
6720 GLint location,
6721 GLfloat v0,
6722 GLfloat v1,
6723 GLfloat v2,
6724 GLfloat v3)
6725{
6726 GLfloat xyzw[4] = {v0, v1, v2, v3};
6727 programUniform4fv(program, location, 1, xyzw);
6728}
6729
Jamie Madill81c2e252017-09-09 23:32:46 -04006730void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6731{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006732 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006733 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006734 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006735}
6736
Jiajia Qin5451d532017-11-16 17:16:34 +08006737void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6738{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006739 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006740 ASSERT(programObject);
6741 programObject->setUniform2iv(location, count, value);
6742}
6743
6744void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6745{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006746 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006747 ASSERT(programObject);
6748 programObject->setUniform3iv(location, count, value);
6749}
6750
6751void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6752{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006753 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006754 ASSERT(programObject);
6755 programObject->setUniform4iv(location, count, value);
6756}
6757
6758void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6759{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006760 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006761 ASSERT(programObject);
6762 programObject->setUniform1uiv(location, count, value);
6763}
6764
6765void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6766{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006767 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006768 ASSERT(programObject);
6769 programObject->setUniform2uiv(location, count, value);
6770}
6771
6772void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6773{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006774 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006775 ASSERT(programObject);
6776 programObject->setUniform3uiv(location, count, value);
6777}
6778
6779void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6780{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006781 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006782 ASSERT(programObject);
6783 programObject->setUniform4uiv(location, count, value);
6784}
6785
6786void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6787{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006788 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006789 ASSERT(programObject);
6790 programObject->setUniform1fv(location, count, value);
6791}
6792
6793void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6794{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006795 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006796 ASSERT(programObject);
6797 programObject->setUniform2fv(location, count, value);
6798}
6799
6800void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6801{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006802 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006803 ASSERT(programObject);
6804 programObject->setUniform3fv(location, count, value);
6805}
6806
6807void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6808{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006809 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006810 ASSERT(programObject);
6811 programObject->setUniform4fv(location, count, value);
6812}
6813
6814void Context::programUniformMatrix2fv(GLuint program,
6815 GLint location,
6816 GLsizei count,
6817 GLboolean transpose,
6818 const GLfloat *value)
6819{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006820 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006821 ASSERT(programObject);
6822 programObject->setUniformMatrix2fv(location, count, transpose, value);
6823}
6824
6825void Context::programUniformMatrix3fv(GLuint program,
6826 GLint location,
6827 GLsizei count,
6828 GLboolean transpose,
6829 const GLfloat *value)
6830{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006831 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006832 ASSERT(programObject);
6833 programObject->setUniformMatrix3fv(location, count, transpose, value);
6834}
6835
6836void Context::programUniformMatrix4fv(GLuint program,
6837 GLint location,
6838 GLsizei count,
6839 GLboolean transpose,
6840 const GLfloat *value)
6841{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006842 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006843 ASSERT(programObject);
6844 programObject->setUniformMatrix4fv(location, count, transpose, value);
6845}
6846
6847void Context::programUniformMatrix2x3fv(GLuint program,
6848 GLint location,
6849 GLsizei count,
6850 GLboolean transpose,
6851 const GLfloat *value)
6852{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006853 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006854 ASSERT(programObject);
6855 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6856}
6857
6858void Context::programUniformMatrix3x2fv(GLuint program,
6859 GLint location,
6860 GLsizei count,
6861 GLboolean transpose,
6862 const GLfloat *value)
6863{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006864 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006865 ASSERT(programObject);
6866 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6867}
6868
6869void Context::programUniformMatrix2x4fv(GLuint program,
6870 GLint location,
6871 GLsizei count,
6872 GLboolean transpose,
6873 const GLfloat *value)
6874{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006875 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006876 ASSERT(programObject);
6877 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6878}
6879
6880void Context::programUniformMatrix4x2fv(GLuint program,
6881 GLint location,
6882 GLsizei count,
6883 GLboolean transpose,
6884 const GLfloat *value)
6885{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006886 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006887 ASSERT(programObject);
6888 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6889}
6890
6891void Context::programUniformMatrix3x4fv(GLuint program,
6892 GLint location,
6893 GLsizei count,
6894 GLboolean transpose,
6895 const GLfloat *value)
6896{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006897 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006898 ASSERT(programObject);
6899 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6900}
6901
6902void Context::programUniformMatrix4x3fv(GLuint program,
6903 GLint location,
6904 GLsizei count,
6905 GLboolean transpose,
6906 const GLfloat *value)
6907{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006908 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006909 ASSERT(programObject);
6910 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6911}
6912
James Darpiniane8a93c62018-01-04 18:02:24 -08006913bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6914{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006915 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006916}
James Darpiniane8a93c62018-01-04 18:02:24 -08006917
Yunchao Hea336b902017-08-02 16:05:21 +08006918void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6919{
6920 for (int i = 0; i < count; i++)
6921 {
6922 pipelines[i] = createProgramPipeline();
6923 }
6924}
6925
6926void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6927{
6928 for (int i = 0; i < count; i++)
6929 {
6930 if (pipelines[i] != 0)
6931 {
6932 deleteProgramPipeline(pipelines[i]);
6933 }
6934 }
6935}
6936
6937GLboolean Context::isProgramPipeline(GLuint pipeline)
6938{
6939 if (pipeline == 0)
6940 {
6941 return GL_FALSE;
6942 }
6943
6944 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6945}
6946
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006947void Context::finishFenceNV(GLuint fence)
6948{
6949 FenceNV *fenceObject = getFenceNV(fence);
6950
6951 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006952 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006953}
6954
6955void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6956{
6957 FenceNV *fenceObject = getFenceNV(fence);
6958
6959 ASSERT(fenceObject && fenceObject->isSet());
6960
6961 switch (pname)
6962 {
6963 case GL_FENCE_STATUS_NV:
6964 {
6965 // GL_NV_fence spec:
6966 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6967 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6968 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6969 GLboolean status = GL_TRUE;
6970 if (fenceObject->getStatus() != GL_TRUE)
6971 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006972 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006973 }
6974 *params = status;
6975 break;
6976 }
6977
6978 case GL_FENCE_CONDITION_NV:
6979 {
6980 *params = static_cast<GLint>(fenceObject->getCondition());
6981 break;
6982 }
6983
6984 default:
6985 UNREACHABLE();
6986 }
6987}
6988
6989void Context::getTranslatedShaderSource(GLuint shader,
6990 GLsizei bufsize,
6991 GLsizei *length,
6992 GLchar *source)
6993{
6994 Shader *shaderObject = getShader(shader);
6995 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006996 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006997}
6998
6999void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7000{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007001 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007002 ASSERT(programObject);
7003
7004 programObject->getUniformfv(this, location, params);
7005}
7006
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007007void Context::getnUniformfvRobust(GLuint program,
7008 GLint location,
7009 GLsizei bufSize,
7010 GLsizei *length,
7011 GLfloat *params)
7012{
7013 UNIMPLEMENTED();
7014}
7015
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007016void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7017{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007018 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007019 ASSERT(programObject);
7020
7021 programObject->getUniformiv(this, location, params);
7022}
7023
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007024void Context::getnUniformivRobust(GLuint program,
7025 GLint location,
7026 GLsizei bufSize,
7027 GLsizei *length,
7028 GLint *params)
7029{
7030 UNIMPLEMENTED();
7031}
7032
7033void Context::getnUniformuivRobust(GLuint program,
7034 GLint location,
7035 GLsizei bufSize,
7036 GLsizei *length,
7037 GLuint *params)
7038{
7039 UNIMPLEMENTED();
7040}
7041
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007042GLboolean Context::isFenceNV(GLuint fence)
7043{
7044 FenceNV *fenceObject = getFenceNV(fence);
7045
7046 if (fenceObject == nullptr)
7047 {
7048 return GL_FALSE;
7049 }
7050
7051 // GL_NV_fence spec:
7052 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7053 // existing fence.
7054 return fenceObject->isSet();
7055}
7056
7057void Context::readnPixels(GLint x,
7058 GLint y,
7059 GLsizei width,
7060 GLsizei height,
7061 GLenum format,
7062 GLenum type,
7063 GLsizei bufSize,
7064 void *data)
7065{
7066 return readPixels(x, y, width, height, format, type, data);
7067}
7068
Jamie Madill007530e2017-12-28 14:27:04 -05007069void Context::setFenceNV(GLuint fence, GLenum condition)
7070{
7071 ASSERT(condition == GL_ALL_COMPLETED_NV);
7072
7073 FenceNV *fenceObject = getFenceNV(fence);
7074 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007075 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007076}
7077
7078GLboolean Context::testFenceNV(GLuint fence)
7079{
7080 FenceNV *fenceObject = getFenceNV(fence);
7081
7082 ASSERT(fenceObject != nullptr);
7083 ASSERT(fenceObject->isSet() == GL_TRUE);
7084
7085 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007086 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007087 {
Jamie Madill007530e2017-12-28 14:27:04 -05007088 return GL_TRUE;
7089 }
7090
7091 return result;
7092}
7093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007094void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007095{
7096 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007097 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007098 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007099}
7100
Jamie Madillfa920eb2018-01-04 11:45:50 -05007101void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007102{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007103 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007104 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007105 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007106}
7107
Jamie Madillfa920eb2018-01-04 11:45:50 -05007108void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7109{
7110 UNIMPLEMENTED();
7111}
7112
Jamie Madill5b772312018-03-08 20:28:32 -05007113bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7114{
7115 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7116 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7117 // to the fact that it is stored internally as a float, and so would require conversion
7118 // if returned from Context::getIntegerv. Since this conversion is already implemented
7119 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7120 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7121 // application.
7122 switch (pname)
7123 {
7124 case GL_COMPRESSED_TEXTURE_FORMATS:
7125 {
7126 *type = GL_INT;
7127 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7128 return true;
7129 }
7130 case GL_SHADER_BINARY_FORMATS:
7131 {
7132 *type = GL_INT;
7133 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7134 return true;
7135 }
7136
7137 case GL_MAX_VERTEX_ATTRIBS:
7138 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7139 case GL_MAX_VARYING_VECTORS:
7140 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7141 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7142 case GL_MAX_TEXTURE_IMAGE_UNITS:
7143 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7144 case GL_MAX_RENDERBUFFER_SIZE:
7145 case GL_NUM_SHADER_BINARY_FORMATS:
7146 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7147 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007148 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7149 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007150 case GL_RENDERBUFFER_BINDING:
7151 case GL_CURRENT_PROGRAM:
7152 case GL_PACK_ALIGNMENT:
7153 case GL_UNPACK_ALIGNMENT:
7154 case GL_GENERATE_MIPMAP_HINT:
7155 case GL_RED_BITS:
7156 case GL_GREEN_BITS:
7157 case GL_BLUE_BITS:
7158 case GL_ALPHA_BITS:
7159 case GL_DEPTH_BITS:
7160 case GL_STENCIL_BITS:
7161 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7162 case GL_CULL_FACE_MODE:
7163 case GL_FRONT_FACE:
7164 case GL_ACTIVE_TEXTURE:
7165 case GL_STENCIL_FUNC:
7166 case GL_STENCIL_VALUE_MASK:
7167 case GL_STENCIL_REF:
7168 case GL_STENCIL_FAIL:
7169 case GL_STENCIL_PASS_DEPTH_FAIL:
7170 case GL_STENCIL_PASS_DEPTH_PASS:
7171 case GL_STENCIL_BACK_FUNC:
7172 case GL_STENCIL_BACK_VALUE_MASK:
7173 case GL_STENCIL_BACK_REF:
7174 case GL_STENCIL_BACK_FAIL:
7175 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7176 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7177 case GL_DEPTH_FUNC:
7178 case GL_BLEND_SRC_RGB:
7179 case GL_BLEND_SRC_ALPHA:
7180 case GL_BLEND_DST_RGB:
7181 case GL_BLEND_DST_ALPHA:
7182 case GL_BLEND_EQUATION_RGB:
7183 case GL_BLEND_EQUATION_ALPHA:
7184 case GL_STENCIL_WRITEMASK:
7185 case GL_STENCIL_BACK_WRITEMASK:
7186 case GL_STENCIL_CLEAR_VALUE:
7187 case GL_SUBPIXEL_BITS:
7188 case GL_MAX_TEXTURE_SIZE:
7189 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7190 case GL_SAMPLE_BUFFERS:
7191 case GL_SAMPLES:
7192 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7193 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7194 case GL_TEXTURE_BINDING_2D:
7195 case GL_TEXTURE_BINDING_CUBE_MAP:
7196 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7197 {
7198 *type = GL_INT;
7199 *numParams = 1;
7200 return true;
7201 }
7202 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7203 {
7204 if (!getExtensions().packReverseRowOrder)
7205 {
7206 return false;
7207 }
7208 *type = GL_INT;
7209 *numParams = 1;
7210 return true;
7211 }
7212 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7213 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7214 {
7215 if (!getExtensions().textureRectangle)
7216 {
7217 return false;
7218 }
7219 *type = GL_INT;
7220 *numParams = 1;
7221 return true;
7222 }
7223 case GL_MAX_DRAW_BUFFERS_EXT:
7224 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7225 {
7226 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7227 {
7228 return false;
7229 }
7230 *type = GL_INT;
7231 *numParams = 1;
7232 return true;
7233 }
7234 case GL_MAX_VIEWPORT_DIMS:
7235 {
7236 *type = GL_INT;
7237 *numParams = 2;
7238 return true;
7239 }
7240 case GL_VIEWPORT:
7241 case GL_SCISSOR_BOX:
7242 {
7243 *type = GL_INT;
7244 *numParams = 4;
7245 return true;
7246 }
7247 case GL_SHADER_COMPILER:
7248 case GL_SAMPLE_COVERAGE_INVERT:
7249 case GL_DEPTH_WRITEMASK:
7250 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7251 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7252 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7253 // bool-natural
7254 case GL_SAMPLE_COVERAGE:
7255 case GL_SCISSOR_TEST:
7256 case GL_STENCIL_TEST:
7257 case GL_DEPTH_TEST:
7258 case GL_BLEND:
7259 case GL_DITHER:
7260 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7261 {
7262 *type = GL_BOOL;
7263 *numParams = 1;
7264 return true;
7265 }
7266 case GL_COLOR_WRITEMASK:
7267 {
7268 *type = GL_BOOL;
7269 *numParams = 4;
7270 return true;
7271 }
7272 case GL_POLYGON_OFFSET_FACTOR:
7273 case GL_POLYGON_OFFSET_UNITS:
7274 case GL_SAMPLE_COVERAGE_VALUE:
7275 case GL_DEPTH_CLEAR_VALUE:
7276 case GL_LINE_WIDTH:
7277 {
7278 *type = GL_FLOAT;
7279 *numParams = 1;
7280 return true;
7281 }
7282 case GL_ALIASED_LINE_WIDTH_RANGE:
7283 case GL_ALIASED_POINT_SIZE_RANGE:
7284 case GL_DEPTH_RANGE:
7285 {
7286 *type = GL_FLOAT;
7287 *numParams = 2;
7288 return true;
7289 }
7290 case GL_COLOR_CLEAR_VALUE:
7291 case GL_BLEND_COLOR:
7292 {
7293 *type = GL_FLOAT;
7294 *numParams = 4;
7295 return true;
7296 }
7297 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7298 if (!getExtensions().textureFilterAnisotropic)
7299 {
7300 return false;
7301 }
7302 *type = GL_FLOAT;
7303 *numParams = 1;
7304 return true;
7305 case GL_TIMESTAMP_EXT:
7306 if (!getExtensions().disjointTimerQuery)
7307 {
7308 return false;
7309 }
7310 *type = GL_INT_64_ANGLEX;
7311 *numParams = 1;
7312 return true;
7313 case GL_GPU_DISJOINT_EXT:
7314 if (!getExtensions().disjointTimerQuery)
7315 {
7316 return false;
7317 }
7318 *type = GL_INT;
7319 *numParams = 1;
7320 return true;
7321 case GL_COVERAGE_MODULATION_CHROMIUM:
7322 if (!getExtensions().framebufferMixedSamples)
7323 {
7324 return false;
7325 }
7326 *type = GL_INT;
7327 *numParams = 1;
7328 return true;
7329 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7330 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7331 {
7332 return false;
7333 }
7334 *type = GL_INT;
7335 *numParams = 1;
7336 return true;
7337 }
7338
7339 if (getExtensions().debug)
7340 {
7341 switch (pname)
7342 {
7343 case GL_DEBUG_LOGGED_MESSAGES:
7344 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7345 case GL_DEBUG_GROUP_STACK_DEPTH:
7346 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7347 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7348 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7349 case GL_MAX_LABEL_LENGTH:
7350 *type = GL_INT;
7351 *numParams = 1;
7352 return true;
7353
7354 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7355 case GL_DEBUG_OUTPUT:
7356 *type = GL_BOOL;
7357 *numParams = 1;
7358 return true;
7359 }
7360 }
7361
7362 if (getExtensions().multisampleCompatibility)
7363 {
7364 switch (pname)
7365 {
7366 case GL_MULTISAMPLE_EXT:
7367 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7368 *type = GL_BOOL;
7369 *numParams = 1;
7370 return true;
7371 }
7372 }
7373
7374 if (getExtensions().pathRendering)
7375 {
7376 switch (pname)
7377 {
7378 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7379 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7380 *type = GL_FLOAT;
7381 *numParams = 16;
7382 return true;
7383 }
7384 }
7385
7386 if (getExtensions().bindGeneratesResource)
7387 {
7388 switch (pname)
7389 {
7390 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7391 *type = GL_BOOL;
7392 *numParams = 1;
7393 return true;
7394 }
7395 }
7396
7397 if (getExtensions().clientArrays)
7398 {
7399 switch (pname)
7400 {
7401 case GL_CLIENT_ARRAYS_ANGLE:
7402 *type = GL_BOOL;
7403 *numParams = 1;
7404 return true;
7405 }
7406 }
7407
7408 if (getExtensions().sRGBWriteControl)
7409 {
7410 switch (pname)
7411 {
7412 case GL_FRAMEBUFFER_SRGB_EXT:
7413 *type = GL_BOOL;
7414 *numParams = 1;
7415 return true;
7416 }
7417 }
7418
7419 if (getExtensions().robustResourceInitialization &&
7420 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7421 {
7422 *type = GL_BOOL;
7423 *numParams = 1;
7424 return true;
7425 }
7426
7427 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7428 {
7429 *type = GL_BOOL;
7430 *numParams = 1;
7431 return true;
7432 }
7433
jchen1082af6202018-06-22 10:59:52 +08007434 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7435 {
7436 *type = GL_INT;
7437 *numParams = 1;
7438 return true;
7439 }
7440
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007441 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7442 {
7443 *type = GL_INT;
7444 *numParams = 1;
7445 return true;
7446 }
7447
Jamie Madill5b772312018-03-08 20:28:32 -05007448 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7449 switch (pname)
7450 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007451 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007452 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7453 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7454 {
7455 return false;
7456 }
7457 *type = GL_INT;
7458 *numParams = 1;
7459 return true;
7460
7461 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7462 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7463 {
7464 return false;
7465 }
7466 *type = GL_INT;
7467 *numParams = 1;
7468 return true;
7469
7470 case GL_PROGRAM_BINARY_FORMATS_OES:
7471 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7472 {
7473 return false;
7474 }
7475 *type = GL_INT;
7476 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7477 return true;
7478
7479 case GL_PACK_ROW_LENGTH:
7480 case GL_PACK_SKIP_ROWS:
7481 case GL_PACK_SKIP_PIXELS:
7482 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7483 {
7484 return false;
7485 }
7486 *type = GL_INT;
7487 *numParams = 1;
7488 return true;
7489 case GL_UNPACK_ROW_LENGTH:
7490 case GL_UNPACK_SKIP_ROWS:
7491 case GL_UNPACK_SKIP_PIXELS:
7492 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7493 {
7494 return false;
7495 }
7496 *type = GL_INT;
7497 *numParams = 1;
7498 return true;
7499 case GL_VERTEX_ARRAY_BINDING:
7500 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7501 {
7502 return false;
7503 }
7504 *type = GL_INT;
7505 *numParams = 1;
7506 return true;
7507 case GL_PIXEL_PACK_BUFFER_BINDING:
7508 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7509 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7510 {
7511 return false;
7512 }
7513 *type = GL_INT;
7514 *numParams = 1;
7515 return true;
7516 case GL_MAX_SAMPLES:
7517 {
7518 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7519 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7520 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7521 {
7522 return false;
7523 }
7524 *type = GL_INT;
7525 *numParams = 1;
7526 return true;
7527
7528 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7529 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7530 {
7531 return false;
7532 }
7533 *type = GL_INT;
7534 *numParams = 1;
7535 return true;
7536 }
7537 }
7538
7539 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7540 {
7541 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7542 {
7543 return false;
7544 }
7545 *type = GL_INT;
7546 *numParams = 1;
7547 return true;
7548 }
7549
7550 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7551 {
7552 *type = GL_INT;
7553 *numParams = 1;
7554 return true;
7555 }
7556
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007557 if (getClientVersion() < Version(2, 0))
7558 {
7559 switch (pname)
7560 {
7561 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007562 case GL_CLIENT_ACTIVE_TEXTURE:
7563 case GL_MATRIX_MODE:
7564 case GL_MAX_TEXTURE_UNITS:
7565 case GL_MAX_MODELVIEW_STACK_DEPTH:
7566 case GL_MAX_PROJECTION_STACK_DEPTH:
7567 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007568 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007569 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007570 case GL_VERTEX_ARRAY_STRIDE:
7571 case GL_NORMAL_ARRAY_STRIDE:
7572 case GL_COLOR_ARRAY_STRIDE:
7573 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7574 case GL_VERTEX_ARRAY_SIZE:
7575 case GL_COLOR_ARRAY_SIZE:
7576 case GL_TEXTURE_COORD_ARRAY_SIZE:
7577 case GL_VERTEX_ARRAY_TYPE:
7578 case GL_NORMAL_ARRAY_TYPE:
7579 case GL_COLOR_ARRAY_TYPE:
7580 case GL_TEXTURE_COORD_ARRAY_TYPE:
7581 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7582 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7583 case GL_COLOR_ARRAY_BUFFER_BINDING:
7584 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7585 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7586 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7587 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007588 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007589 case GL_MODELVIEW_STACK_DEPTH:
7590 case GL_PROJECTION_STACK_DEPTH:
7591 case GL_TEXTURE_STACK_DEPTH:
7592 case GL_LOGIC_OP_MODE:
7593 case GL_BLEND_SRC:
7594 case GL_BLEND_DST:
7595 case GL_PERSPECTIVE_CORRECTION_HINT:
7596 case GL_POINT_SMOOTH_HINT:
7597 case GL_LINE_SMOOTH_HINT:
7598 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007599 *type = GL_INT;
7600 *numParams = 1;
7601 return true;
7602 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007603 case GL_FOG_DENSITY:
7604 case GL_FOG_START:
7605 case GL_FOG_END:
7606 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007607 case GL_POINT_SIZE:
7608 case GL_POINT_SIZE_MIN:
7609 case GL_POINT_SIZE_MAX:
7610 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007611 *type = GL_FLOAT;
7612 *numParams = 1;
7613 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007614 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007615 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007616 *type = GL_FLOAT;
7617 *numParams = 2;
7618 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007619 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007620 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007621 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007622 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007623 *type = GL_FLOAT;
7624 *numParams = 4;
7625 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007626 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007627 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007628 *type = GL_FLOAT;
7629 *numParams = 3;
7630 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007631 case GL_MODELVIEW_MATRIX:
7632 case GL_PROJECTION_MATRIX:
7633 case GL_TEXTURE_MATRIX:
7634 *type = GL_FLOAT;
7635 *numParams = 16;
7636 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007637 case GL_LIGHT_MODEL_TWO_SIDE:
7638 *type = GL_BOOL;
7639 *numParams = 1;
7640 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007641 }
7642 }
7643
Jamie Madill5b772312018-03-08 20:28:32 -05007644 if (getClientVersion() < Version(3, 0))
7645 {
7646 return false;
7647 }
7648
7649 // Check for ES3.0+ parameter names
7650 switch (pname)
7651 {
7652 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7653 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7654 case GL_UNIFORM_BUFFER_BINDING:
7655 case GL_TRANSFORM_FEEDBACK_BINDING:
7656 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7657 case GL_COPY_READ_BUFFER_BINDING:
7658 case GL_COPY_WRITE_BUFFER_BINDING:
7659 case GL_SAMPLER_BINDING:
7660 case GL_READ_BUFFER:
7661 case GL_TEXTURE_BINDING_3D:
7662 case GL_TEXTURE_BINDING_2D_ARRAY:
7663 case GL_MAX_3D_TEXTURE_SIZE:
7664 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7665 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7666 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7667 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7668 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7669 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7670 case GL_MAX_VARYING_COMPONENTS:
7671 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7672 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7673 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7674 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7675 case GL_NUM_EXTENSIONS:
7676 case GL_MAJOR_VERSION:
7677 case GL_MINOR_VERSION:
7678 case GL_MAX_ELEMENTS_INDICES:
7679 case GL_MAX_ELEMENTS_VERTICES:
7680 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7681 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7682 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7683 case GL_UNPACK_IMAGE_HEIGHT:
7684 case GL_UNPACK_SKIP_IMAGES:
7685 {
7686 *type = GL_INT;
7687 *numParams = 1;
7688 return true;
7689 }
7690
7691 case GL_MAX_ELEMENT_INDEX:
7692 case GL_MAX_UNIFORM_BLOCK_SIZE:
7693 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7694 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7695 case GL_MAX_SERVER_WAIT_TIMEOUT:
7696 {
7697 *type = GL_INT_64_ANGLEX;
7698 *numParams = 1;
7699 return true;
7700 }
7701
7702 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7703 case GL_TRANSFORM_FEEDBACK_PAUSED:
7704 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7705 case GL_RASTERIZER_DISCARD:
7706 {
7707 *type = GL_BOOL;
7708 *numParams = 1;
7709 return true;
7710 }
7711
7712 case GL_MAX_TEXTURE_LOD_BIAS:
7713 {
7714 *type = GL_FLOAT;
7715 *numParams = 1;
7716 return true;
7717 }
7718 }
7719
7720 if (getExtensions().requestExtension)
7721 {
7722 switch (pname)
7723 {
7724 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7725 *type = GL_INT;
7726 *numParams = 1;
7727 return true;
7728 }
7729 }
7730
Yizhou Jiang7818a852018-09-06 15:02:04 +08007731 if (getExtensions().textureMultisample)
7732 {
7733 switch (pname)
7734 {
7735 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7736 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7737 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7738 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007739 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007740 *type = GL_INT;
7741 *numParams = 1;
7742 return true;
7743 }
7744 }
7745
Jamie Madill5b772312018-03-08 20:28:32 -05007746 if (getClientVersion() < Version(3, 1))
7747 {
7748 return false;
7749 }
7750
7751 switch (pname)
7752 {
7753 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7754 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7755 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7756 case GL_MAX_FRAMEBUFFER_WIDTH:
7757 case GL_MAX_FRAMEBUFFER_HEIGHT:
7758 case GL_MAX_FRAMEBUFFER_SAMPLES:
7759 case GL_MAX_SAMPLE_MASK_WORDS:
7760 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7761 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7762 case GL_MAX_INTEGER_SAMPLES:
7763 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7764 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7765 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7766 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7767 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7768 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7769 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7770 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7771 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7772 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7773 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7774 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7775 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7776 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7777 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7778 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7779 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7780 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7781 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7782 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7783 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7784 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7785 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7786 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7787 case GL_MAX_UNIFORM_LOCATIONS:
7788 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7789 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7790 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7791 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7792 case GL_MAX_IMAGE_UNITS:
7793 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7794 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7795 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7796 case GL_SHADER_STORAGE_BUFFER_BINDING:
7797 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7798 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007799 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007800 *type = GL_INT;
7801 *numParams = 1;
7802 return true;
7803 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7804 *type = GL_INT_64_ANGLEX;
7805 *numParams = 1;
7806 return true;
7807 case GL_SAMPLE_MASK:
7808 *type = GL_BOOL;
7809 *numParams = 1;
7810 return true;
7811 }
7812
7813 if (getExtensions().geometryShader)
7814 {
7815 switch (pname)
7816 {
7817 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7818 case GL_LAYER_PROVOKING_VERTEX_EXT:
7819 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7820 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7821 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7822 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7823 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7824 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7825 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7826 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7827 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7828 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7829 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7830 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7831 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7832 *type = GL_INT;
7833 *numParams = 1;
7834 return true;
7835 }
7836 }
7837
7838 return false;
7839}
7840
7841bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7842{
7843 if (getClientVersion() < Version(3, 0))
7844 {
7845 return false;
7846 }
7847
7848 switch (target)
7849 {
7850 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7851 case GL_UNIFORM_BUFFER_BINDING:
7852 {
7853 *type = GL_INT;
7854 *numParams = 1;
7855 return true;
7856 }
7857 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7858 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7859 case GL_UNIFORM_BUFFER_START:
7860 case GL_UNIFORM_BUFFER_SIZE:
7861 {
7862 *type = GL_INT_64_ANGLEX;
7863 *numParams = 1;
7864 return true;
7865 }
7866 }
7867
7868 if (getClientVersion() < Version(3, 1))
7869 {
7870 return false;
7871 }
7872
7873 switch (target)
7874 {
7875 case GL_IMAGE_BINDING_LAYERED:
7876 {
7877 *type = GL_BOOL;
7878 *numParams = 1;
7879 return true;
7880 }
7881 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7882 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7883 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7884 case GL_SHADER_STORAGE_BUFFER_BINDING:
7885 case GL_VERTEX_BINDING_BUFFER:
7886 case GL_VERTEX_BINDING_DIVISOR:
7887 case GL_VERTEX_BINDING_OFFSET:
7888 case GL_VERTEX_BINDING_STRIDE:
7889 case GL_SAMPLE_MASK_VALUE:
7890 case GL_IMAGE_BINDING_NAME:
7891 case GL_IMAGE_BINDING_LEVEL:
7892 case GL_IMAGE_BINDING_LAYER:
7893 case GL_IMAGE_BINDING_ACCESS:
7894 case GL_IMAGE_BINDING_FORMAT:
7895 {
7896 *type = GL_INT;
7897 *numParams = 1;
7898 return true;
7899 }
7900 case GL_ATOMIC_COUNTER_BUFFER_START:
7901 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7902 case GL_SHADER_STORAGE_BUFFER_START:
7903 case GL_SHADER_STORAGE_BUFFER_SIZE:
7904 {
7905 *type = GL_INT_64_ANGLEX;
7906 *numParams = 1;
7907 return true;
7908 }
7909 }
7910
7911 return false;
7912}
7913
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007914Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007915{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007916 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007917}
7918
7919Shader *Context::getShader(GLuint handle) const
7920{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007921 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007922}
7923
Jamie Madill5b772312018-03-08 20:28:32 -05007924bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7925{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007926 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007927}
7928
7929bool Context::isFramebufferGenerated(GLuint framebuffer) const
7930{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007931 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007932}
7933
7934bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7935{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007936 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007937}
7938
7939bool Context::usingDisplayTextureShareGroup() const
7940{
7941 return mDisplayTextureShareGroup;
7942}
7943
7944GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7945{
7946 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7947 internalformat == GL_DEPTH_STENCIL
7948 ? GL_DEPTH24_STENCIL8
7949 : internalformat;
7950}
7951
jchen1082af6202018-06-22 10:59:52 +08007952void Context::maxShaderCompilerThreads(GLuint count)
7953{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007954 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7955 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007956 // A count of zero specifies a request for no parallel compiling or linking.
7957 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7958 {
7959 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7960 }
7961 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007962}
7963
Jamie Madill2eb65032018-07-30 10:25:57 -04007964bool Context::isGLES1() const
7965{
7966 return mState.getClientVersion() < Version(2, 0);
7967}
7968
Jamie Madilla11819d2018-07-30 10:26:01 -04007969void Context::onSubjectStateChange(const Context *context,
7970 angle::SubjectIndex index,
7971 angle::SubjectMessage message)
7972{
Jamie Madilla11819d2018-07-30 10:26:01 -04007973 switch (index)
7974 {
7975 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007976 switch (message)
7977 {
7978 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007979 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007980 mStateCache.onVertexArrayBufferContentsChange(this);
7981 break;
7982 case angle::SubjectMessage::RESOURCE_MAPPED:
7983 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7984 case angle::SubjectMessage::BINDING_CHANGED:
7985 mStateCache.onVertexArrayBufferStateChange(this);
7986 break;
7987 default:
7988 break;
7989 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007990 break;
7991
7992 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007993 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7994 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007995 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04007996 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007997 break;
7998
7999 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008000 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8001 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008002 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008003 }
8004 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008005 break;
8006
8007 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008008 if (index < kTextureMaxSubjectIndex)
8009 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008010 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008011 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008012 }
Jamie Madille25b8002018-09-20 13:39:49 -04008013 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008014 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008015 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008016 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008017 }
Jamie Madille25b8002018-09-20 13:39:49 -04008018 else
8019 {
8020 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008021 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008022 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008023 break;
8024 }
8025}
8026
Jamie Madill6b873dd2018-07-12 23:56:30 -04008027// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008028ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008029
8030ErrorSet::~ErrorSet() = default;
8031
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008032void ErrorSet::handleError(GLenum errorCode,
8033 const char *message,
8034 const char *file,
8035 const char *function,
8036 unsigned int line)
8037{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008038 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8039 {
8040 mContext->markContextLost();
8041 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008042
Jamie Madill4f6592f2018-11-27 16:37:45 -05008043 std::stringstream errorStream;
8044 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8045 << line << ". " << message;
8046
Geoff Lang7139b432018-12-14 16:57:28 -05008047 std::string formattedMessage = errorStream.str();
8048
8049 // Always log a warning, this function is only called on unexpected internal errors.
8050 WARN() << formattedMessage;
8051
Jamie Madill4f6592f2018-11-27 16:37:45 -05008052 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008053 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008054}
8055
Jamie Madilla139f012018-10-10 16:13:03 -04008056void ErrorSet::validationError(GLenum errorCode, const char *message)
8057{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008058 ASSERT(errorCode != GL_NO_ERROR);
8059 mErrors.insert(errorCode);
8060
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008061 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8062 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008063}
8064
Jamie Madill6b873dd2018-07-12 23:56:30 -04008065bool ErrorSet::empty() const
8066{
8067 return mErrors.empty();
8068}
8069
8070GLenum ErrorSet::popError()
8071{
8072 ASSERT(!empty());
8073 GLenum error = *mErrors.begin();
8074 mErrors.erase(mErrors.begin());
8075 return error;
8076}
Jamie Madilldc358af2018-07-31 11:22:13 -04008077
8078// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008079StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008080 : mCachedHasAnyEnabledClientAttrib(false),
8081 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008082 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008083 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008084 mCachedBasicDrawElementsError(kInvalidPointer),
8085 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008086{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008087
8088StateCache::~StateCache() = default;
8089
Jamie Madillac66f982018-10-09 18:30:01 -04008090void StateCache::initialize(Context *context)
8091{
8092 updateValidDrawModes(context);
8093 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008094 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008095 updateBasicDrawStatesError();
8096 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008097}
8098
Jamie Madilldc358af2018-07-31 11:22:13 -04008099void StateCache::updateActiveAttribsMask(Context *context)
8100{
8101 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008102 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008103
8104 if (!isGLES1 && !glState.getProgram())
8105 {
8106 mCachedActiveBufferedAttribsMask = AttributesMask();
8107 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008108 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008109 return;
8110 }
8111
8112 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8113 : glState.getProgram()->getActiveAttribLocationsMask();
8114
8115 const VertexArray *vao = glState.getVertexArray();
8116 ASSERT(vao);
8117
8118 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8119 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008120 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008121
Jamie Madill0a17e482018-08-31 17:19:11 -04008122 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8123 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008124 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008125 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8126}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008127
8128void StateCache::updateVertexElementLimits(Context *context)
8129{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008130 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008131
8132 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8133 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8134
8135 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8136 // If there are no buffered attributes then we should not limit the draw call count.
8137 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8138 {
8139 return;
8140 }
8141
8142 const auto &vertexAttribs = vao->getVertexAttributes();
8143 const auto &vertexBindings = vao->getVertexBindings();
8144
8145 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8146 {
8147 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8148 ASSERT(attrib.enabled);
8149
8150 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8151 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008152 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008153
8154 GLint64 limit = attrib.getCachedElementLimit();
8155 if (binding.getDivisor() > 0)
8156 {
8157 mCachedInstancedVertexElementLimit =
8158 std::min(mCachedInstancedVertexElementLimit, limit);
8159 }
8160 else
8161 {
8162 mCachedNonInstancedVertexElementLimit =
8163 std::min(mCachedNonInstancedVertexElementLimit, limit);
8164 }
8165 }
8166}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008167
Jamie Madilld84b6732018-09-06 15:54:35 -04008168void StateCache::updateBasicDrawStatesError()
8169{
8170 mCachedBasicDrawStatesError = kInvalidPointer;
8171}
8172
Jamie Madill1e853262018-12-21 09:07:38 -05008173void StateCache::updateBasicDrawElementsError()
8174{
8175 mCachedBasicDrawElementsError = kInvalidPointer;
8176}
8177
Jamie Madilld84b6732018-09-06 15:54:35 -04008178intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8179{
8180 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8181 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8182 return mCachedBasicDrawStatesError;
8183}
8184
Jamie Madill1e853262018-12-21 09:07:38 -05008185intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8186{
8187 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8188 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8189 return mCachedBasicDrawElementsError;
8190}
8191
Jamie Madillc43cdad2018-08-08 15:49:25 -04008192void StateCache::onVertexArrayBindingChange(Context *context)
8193{
8194 updateActiveAttribsMask(context);
8195 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008196 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008197}
8198
8199void StateCache::onProgramExecutableChange(Context *context)
8200{
8201 updateActiveAttribsMask(context);
8202 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008203 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008204 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008205}
8206
Jamie Madilld84b6732018-09-06 15:54:35 -04008207void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008208{
8209 updateVertexElementLimits(context);
8210}
8211
Jamie Madilld84b6732018-09-06 15:54:35 -04008212void StateCache::onVertexArrayBufferContentsChange(Context *context)
8213{
8214 updateVertexElementLimits(context);
8215 updateBasicDrawStatesError();
8216}
8217
Jamie Madillc43cdad2018-08-08 15:49:25 -04008218void StateCache::onVertexArrayStateChange(Context *context)
8219{
8220 updateActiveAttribsMask(context);
8221 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008222 updateBasicDrawStatesError();
8223}
8224
8225void StateCache::onVertexArrayBufferStateChange(Context *context)
8226{
8227 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008228 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008229}
8230
8231void StateCache::onGLES1ClientStateChange(Context *context)
8232{
8233 updateActiveAttribsMask(context);
8234}
Jamie Madilld84b6732018-09-06 15:54:35 -04008235
8236void StateCache::onDrawFramebufferChange(Context *context)
8237{
8238 updateBasicDrawStatesError();
8239}
8240
8241void StateCache::onContextCapChange(Context *context)
8242{
8243 updateBasicDrawStatesError();
8244}
8245
8246void StateCache::onStencilStateChange(Context *context)
8247{
8248 updateBasicDrawStatesError();
8249}
8250
8251void StateCache::onDefaultVertexAttributeChange(Context *context)
8252{
8253 updateBasicDrawStatesError();
8254}
8255
8256void StateCache::onActiveTextureChange(Context *context)
8257{
8258 updateBasicDrawStatesError();
8259}
8260
8261void StateCache::onQueryChange(Context *context)
8262{
8263 updateBasicDrawStatesError();
8264}
8265
Jamie Madill3a256222018-12-08 09:56:39 -05008266void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008267{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008268 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008269 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008270 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008271 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008272}
8273
8274void StateCache::onUniformBufferStateChange(Context *context)
8275{
8276 updateBasicDrawStatesError();
8277}
8278
Jamie Madill9b025062018-12-12 15:44:12 -05008279void StateCache::setValidDrawModes(bool pointsOK,
8280 bool linesOK,
8281 bool trisOK,
8282 bool lineAdjOK,
8283 bool triAdjOK)
8284{
8285 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8286 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8287 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8288 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8289 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8290 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8291 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8292 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8293 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8294 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8295 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8296}
8297
Jamie Madill526a6f62018-09-12 11:03:05 -04008298void StateCache::updateValidDrawModes(Context *context)
8299{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008300 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008301 Program *program = state.getProgram();
8302
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008303 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008304 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008305 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8306
Jamie Madill9b025062018-12-12 15:44:12 -05008307 // ES Spec 3.0 validation text:
8308 // When transform feedback is active and not paused, all geometric primitives generated must
8309 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8310 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8311 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8312 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8313 // active and not paused, regardless of mode. Any primitive type may be used while transform
8314 // feedback is paused.
8315 if (!context->getExtensions().geometryShader)
8316 {
8317 mCachedValidDrawModes.fill(false);
8318 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8319 return;
8320 }
8321
8322 // EXT_geometry_shader validation text:
8323 // When transform feedback is active and not paused, all geometric primitives generated must
8324 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8325 // geometry shader is active, the type of primitive emitted by that shader is used instead
8326 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8327 // Any primitive type may be used while transform feedback is paused.
8328 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8329 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8330 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8331
8332 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8333 return;
8334 }
8335
Jamie Madill526a6f62018-09-12 11:03:05 -04008336 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8337 {
Jamie Madill752d2202018-11-27 13:29:48 -05008338 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008339 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008340 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008341
Jamie Madill9b025062018-12-12 15:44:12 -05008342 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8343 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008344
Jamie Madill9b025062018-12-12 15:44:12 -05008345 bool pointsOK = gsMode == PrimitiveMode::Points;
8346 bool linesOK = gsMode == PrimitiveMode::Lines;
8347 bool trisOK = gsMode == PrimitiveMode::Triangles;
8348 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8349 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8350
8351 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008352}
Jamie Madillac66f982018-10-09 18:30:01 -04008353
8354void StateCache::updateValidBindTextureTypes(Context *context)
8355{
8356 const Extensions &exts = context->getExtensions();
8357 bool isGLES3 = context->getClientMajorVersion() >= 3;
8358 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8359
8360 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008361 {TextureType::_2D, true},
8362 {TextureType::_2DArray, isGLES3},
8363 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8364 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8365 {TextureType::_3D, isGLES3},
8366 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8367 {TextureType::Rectangle, exts.textureRectangle},
8368 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008369 }};
8370}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008371
8372void StateCache::updateValidDrawElementsTypes(Context *context)
8373{
8374 bool supportsUint =
8375 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8376
8377 mCachedValidDrawElementsTypes = {{
8378 {DrawElementsType::UnsignedByte, true},
8379 {DrawElementsType::UnsignedShort, true},
8380 {DrawElementsType::UnsignedInt, supportsUint},
8381 }};
8382}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008383
8384void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8385{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008386 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008387 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8388}
Jamie Madillc29968b2016-01-20 11:17:23 -05008389} // namespace gl