blob: 9e28d42be2ff4e81e3f43de0ee228ad210a53292 [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),
Jamie Madill0c667212019-01-01 14:40:36 -0500292 mErrors(this),
293 mImplementation(implFactory->createContext(mState, &mErrors, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400294 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400295 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400296 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500297 mClientType(EGL_OPENGL_ES_API),
298 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 Madill4f6592f2018-11-27 16:37:45 -0500489 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000490}
491
Jamie Madill4928b7c2017-06-20 12:57:39 -0400492egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700494 if (mGLES1Renderer)
495 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500496 mGLES1Renderer->onDestroy(this, &mState);
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700497 }
498
Jamie Madille7b3fe22018-04-05 09:42:46 -0400499 ANGLE_TRY(releaseSurface(display));
500
Corentin Wallez80b24112015-08-25 16:41:57 -0400501 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400503 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400505 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506
Corentin Wallez80b24112015-08-25 16:41:57 -0400507 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400509 if (query.second != nullptr)
510 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400512 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400514 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515
Corentin Wallez80b24112015-08-25 16:41:57 -0400516 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400517 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400518 if (vertexArray.second)
519 {
520 vertexArray.second->onDestroy(this);
521 }
Jamie Madill57a89722013-07-02 11:57:03 -0400522 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400523 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400524
Corentin Wallez80b24112015-08-25 16:41:57 -0400525 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500526 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500527 if (transformFeedback.second != nullptr)
528 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500529 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500530 }
Geoff Langc8058452014-02-03 12:04:11 -0500531 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400532 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500533
Jamie Madill5b772312018-03-08 20:28:32 -0500534 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400535 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800536 if (zeroTexture.get() != nullptr)
537 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800538 zeroTexture.set(this, nullptr);
539 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400540 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541
Jamie Madill2f348d22017-06-05 10:50:59 -0400542 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500543
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500544 mState.reset(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400545
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500546 mState.mBufferManager->release(this);
547 mState.mShaderProgramManager->release(this);
548 mState.mTextureManager->release(this);
549 mState.mRenderbufferManager->release(this);
550 mState.mSamplerManager->release(this);
551 mState.mSyncManager->release(this);
552 mState.mPathManager->release(this);
553 mState.mFramebufferManager->release(this);
554 mState.mProgramPipelineManager->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555
jchen107ae70d82018-07-06 13:47:01 +0800556 mThreadPool.reset();
557
Jamie Madill76e471e2017-10-21 09:56:01 -0400558 mImplementation->onDestroy(this);
559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561}
562
Jamie Madillb980c562018-11-27 11:34:27 -0500563Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500564
Geoff Lang75359662018-04-11 01:42:27 -0400565void Context::setLabel(EGLLabelKHR label)
566{
567 mLabel = label;
568}
569
570EGLLabelKHR Context::getLabel() const
571{
572 return mLabel;
573}
574
Jamie Madill4928b7c2017-06-20 12:57:39 -0400575egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000576{
Jamie Madill61e16b42017-06-19 11:13:23 -0400577 mCurrentDisplay = display;
578
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000579 if (!mHasBeenCurrent)
580 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400581 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000582 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500583 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400584 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585
Corentin Wallezc295e512017-01-27 17:47:50 -0500586 int width = 0;
587 int height = 0;
588 if (surface != nullptr)
589 {
590 width = surface->getWidth();
591 height = surface->getHeight();
592 }
593
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500594 mState.setViewportParams(0, 0, width, height);
595 mState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596
597 mHasBeenCurrent = true;
598 }
599
Jamie Madill1b94d432015-08-07 13:23:23 -0400600 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500601 mState.setAllDirtyBits();
602 mState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400603
Jamie Madill4928b7c2017-06-20 12:57:39 -0400604 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500605
606 Framebuffer *newDefault = nullptr;
607 if (surface != nullptr)
608 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400609 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500610 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400611 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500612 }
613 else
614 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400615 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500616 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000617
Corentin Wallez37c39792015-08-20 14:19:46 -0400618 // Update default framebuffer, the binding of the previous default
619 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400620 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500621 mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
622 if (mState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400623 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400624 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400625 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500626 if (mState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400627 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400628 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400629 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400630 }
Ian Ewell292f0052016-02-04 10:37:32 -0500631
Jamie Madill32643ce2018-10-19 11:38:03 -0400632 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500633 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634}
635
Jamie Madill4928b7c2017-06-20 12:57:39 -0400636egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400637{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500638 gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400639
Geoff Langbf7b95d2018-05-01 16:48:21 -0400640 // Remove the default framebuffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500641 if (mState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500642 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500643 mState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400644 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500645 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400646
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500647 if (mState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500648 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500649 mState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400650 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500651 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400652
653 if (defaultFramebuffer)
654 {
655 defaultFramebuffer->onDestroy(this);
656 delete defaultFramebuffer;
657 }
658
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500659 mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500660
661 if (mCurrentSurface)
662 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400663 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500664 mCurrentSurface = nullptr;
665 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400666
667 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400668}
669
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670GLuint Context::createBuffer()
671{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500672 return mState.mBufferManager->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
675GLuint Context::createProgram()
676{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500677 return mState.mShaderProgramManager->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
Jiawei Shao385b3e02018-03-21 09:43:28 +0800680GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500682 return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
683 type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686GLuint Context::createTexture()
687{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500688 return mState.mTextureManager->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691GLuint Context::createRenderbuffer()
692{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500693 return mState.mRenderbufferManager->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694}
695
Jamie Madill13951342018-09-30 15:24:28 -0400696void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
697{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500698 ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400699}
700
Brandon Jones59770802018-04-02 13:18:42 -0700701GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300702{
Jamie Madill13951342018-09-30 15:24:28 -0400703 GLuint created = 0;
704 tryGenPaths(range, &created);
705 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300706}
707
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708// Returns an unused framebuffer name
709GLuint Context::createFramebuffer()
710{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500711 return mState.mFramebufferManager->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500714void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500716 for (int i = 0; i < n; i++)
717 {
718 GLuint handle = mFenceNVHandleAllocator.allocate();
719 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
720 fences[i] = handle;
721 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722}
723
Yunchao Hea336b902017-08-02 16:05:21 +0800724GLuint Context::createProgramPipeline()
725{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500726 return mState.mProgramPipelineManager->createProgramPipeline();
Yunchao Hea336b902017-08-02 16:05:21 +0800727}
728
Jiawei Shao385b3e02018-03-21 09:43:28 +0800729GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800730{
731 UNIMPLEMENTED();
732 return 0u;
733}
734
James Darpinian4d9d4832018-03-13 12:43:28 -0700735void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500737 Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
James Darpinian4d9d4832018-03-13 12:43:28 -0700738 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739 {
740 detachBuffer(buffer);
741 }
Jamie Madill893ab082014-05-16 16:56:10 -0400742
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500743 mState.mBufferManager->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744}
745
746void Context::deleteShader(GLuint shader)
747{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500748 mState.mShaderProgramManager->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751void Context::deleteProgram(GLuint program)
752{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500753 mState.mShaderProgramManager->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754}
755
756void Context::deleteTexture(GLuint texture)
757{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500758 if (mState.mTextureManager->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000759 {
760 detachTexture(texture);
761 }
762
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500763 mState.mTextureManager->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000764}
765
766void Context::deleteRenderbuffer(GLuint renderbuffer)
767{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500768 if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769 {
770 detachRenderbuffer(renderbuffer);
771 }
Jamie Madill893ab082014-05-16 16:56:10 -0400772
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500773 mState.mRenderbufferManager->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000774}
775
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400776void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400777{
778 // The spec specifies the underlying Fence object is not deleted until all current
779 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
780 // and since our API is currently designed for being called from a single thread, we can delete
781 // the fence immediately.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500782 mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400783}
784
Yunchao Hea336b902017-08-02 16:05:21 +0800785void Context::deleteProgramPipeline(GLuint pipeline)
786{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500787 if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
Yunchao Hea336b902017-08-02 16:05:21 +0800788 {
789 detachProgramPipeline(pipeline);
790 }
791
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500792 mState.mProgramPipelineManager->deleteObject(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +0800793}
794
Sami Väisänene45e53b2016-05-25 10:36:04 +0300795void Context::deletePaths(GLuint first, GLsizei range)
796{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500797 mState.mPathManager->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300798}
799
Brandon Jones59770802018-04-02 13:18:42 -0700800bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500802 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300803 if (pathObj == nullptr)
804 return false;
805
806 return pathObj->hasPathData();
807}
808
Brandon Jones59770802018-04-02 13:18:42 -0700809bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300810{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500811 return mState.mPathManager->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812}
813
Brandon Jones59770802018-04-02 13:18:42 -0700814void Context::pathCommands(GLuint path,
815 GLsizei numCommands,
816 const GLubyte *commands,
817 GLsizei numCoords,
818 GLenum coordType,
819 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300820{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500821 auto *pathObject = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300822
Jamie Madill4f6592f2018-11-27 16:37:45 -0500823 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300824}
825
Jamie Madill007530e2017-12-28 14:27:04 -0500826void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300827{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500828 Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829
830 switch (pname)
831 {
832 case GL_PATH_STROKE_WIDTH_CHROMIUM:
833 pathObj->setStrokeWidth(value);
834 break;
835 case GL_PATH_END_CAPS_CHROMIUM:
836 pathObj->setEndCaps(static_cast<GLenum>(value));
837 break;
838 case GL_PATH_JOIN_STYLE_CHROMIUM:
839 pathObj->setJoinStyle(static_cast<GLenum>(value));
840 break;
841 case GL_PATH_MITER_LIMIT_CHROMIUM:
842 pathObj->setMiterLimit(value);
843 break;
844 case GL_PATH_STROKE_BOUND_CHROMIUM:
845 pathObj->setStrokeBound(value);
846 break;
847 default:
848 UNREACHABLE();
849 break;
850 }
851}
852
Jamie Madill007530e2017-12-28 14:27:04 -0500853void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300854{
Jamie Madill007530e2017-12-28 14:27:04 -0500855 // TODO(jmadill): Should use proper clamping/casting.
856 pathParameterf(path, pname, static_cast<GLfloat>(value));
857}
858
859void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
860{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500861 const Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862
863 switch (pname)
864 {
865 case GL_PATH_STROKE_WIDTH_CHROMIUM:
866 *value = pathObj->getStrokeWidth();
867 break;
868 case GL_PATH_END_CAPS_CHROMIUM:
869 *value = static_cast<GLfloat>(pathObj->getEndCaps());
870 break;
871 case GL_PATH_JOIN_STYLE_CHROMIUM:
872 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
873 break;
874 case GL_PATH_MITER_LIMIT_CHROMIUM:
875 *value = pathObj->getMiterLimit();
876 break;
877 case GL_PATH_STROKE_BOUND_CHROMIUM:
878 *value = pathObj->getStrokeBound();
879 break;
880 default:
881 UNREACHABLE();
882 break;
883 }
884}
885
Jamie Madill007530e2017-12-28 14:27:04 -0500886void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
887{
888 GLfloat val = 0.0f;
889 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
890 if (value)
891 *value = static_cast<GLint>(val);
892}
893
Brandon Jones59770802018-04-02 13:18:42 -0700894void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300895{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500896 mState.setPathStencilFunc(func, ref, mask);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300897}
898
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000899void Context::deleteFramebuffer(GLuint framebuffer)
900{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500901 if (mState.mFramebufferManager->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000902 {
903 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000904 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500905
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500906 mState.mFramebufferManager->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000907}
908
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500909void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000910{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500911 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500913 GLuint fence = fences[i];
914
915 FenceNV *fenceObject = nullptr;
916 if (mFenceNVMap.erase(fence, &fenceObject))
917 {
918 mFenceNVHandleAllocator.release(fence);
919 delete fenceObject;
920 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000921 }
922}
923
Geoff Lang70d0f492015-12-10 17:45:46 -0500924Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500926 return mState.mBufferManager->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000927}
928
Geoff Lang70d0f492015-12-10 17:45:46 -0500929Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500931 return mState.mRenderbufferManager->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932}
933
Jamie Madill70b5bb02017-08-28 13:32:37 -0400934Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400935{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500936 return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400937}
938
Jamie Madill57a89722013-07-02 11:57:03 -0400939VertexArray *Context::getVertexArray(GLuint handle) const
940{
Jamie Madill96a483b2017-06-27 16:49:21 -0400941 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400942}
943
Jamie Madilldc356042013-07-19 16:36:57 -0400944Sampler *Context::getSampler(GLuint handle) const
945{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500946 return mState.mSamplerManager->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400947}
948
Geoff Langc8058452014-02-03 12:04:11 -0500949TransformFeedback *Context::getTransformFeedback(GLuint handle) const
950{
Jamie Madill96a483b2017-06-27 16:49:21 -0400951 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500952}
953
Yunchao Hea336b902017-08-02 16:05:21 +0800954ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
955{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500956 return mState.mProgramPipelineManager->getProgramPipeline(handle);
Yunchao Hea336b902017-08-02 16:05:21 +0800957}
958
Geoff Lang75359662018-04-11 01:42:27 -0400959gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500960{
961 switch (identifier)
962 {
963 case GL_BUFFER:
964 return getBuffer(name);
965 case GL_SHADER:
966 return getShader(name);
967 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -0400968 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -0500969 case GL_VERTEX_ARRAY:
970 return getVertexArray(name);
971 case GL_QUERY:
972 return getQuery(name);
973 case GL_TRANSFORM_FEEDBACK:
974 return getTransformFeedback(name);
975 case GL_SAMPLER:
976 return getSampler(name);
977 case GL_TEXTURE:
978 return getTexture(name);
979 case GL_RENDERBUFFER:
980 return getRenderbuffer(name);
981 case GL_FRAMEBUFFER:
982 return getFramebuffer(name);
983 default:
984 UNREACHABLE();
985 return nullptr;
986 }
987}
988
Geoff Lang75359662018-04-11 01:42:27 -0400989gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500990{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400991 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500992}
993
Martin Radev9d901792016-07-15 15:58:58 +0300994void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
995{
Geoff Lang75359662018-04-11 01:42:27 -0400996 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300997 ASSERT(object != nullptr);
998
999 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001000 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001001
1002 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1003 // specified object is active until we do this.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001004 mState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001005}
1006
1007void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1008{
Geoff Lang75359662018-04-11 01:42:27 -04001009 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001010 ASSERT(object != nullptr);
1011
1012 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001013 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001014}
1015
1016void Context::getObjectLabel(GLenum identifier,
1017 GLuint name,
1018 GLsizei bufSize,
1019 GLsizei *length,
1020 GLchar *label) const
1021{
Geoff Lang75359662018-04-11 01:42:27 -04001022 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001023 ASSERT(object != nullptr);
1024
1025 const std::string &objectLabel = object->getLabel();
1026 GetObjectLabelBase(objectLabel, bufSize, length, label);
1027}
1028
1029void Context::getObjectPtrLabel(const void *ptr,
1030 GLsizei bufSize,
1031 GLsizei *length,
1032 GLchar *label) const
1033{
Geoff Lang75359662018-04-11 01:42:27 -04001034 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001035 ASSERT(object != nullptr);
1036
1037 const std::string &objectLabel = object->getLabel();
1038 GetObjectLabelBase(objectLabel, bufSize, length, label);
1039}
1040
Jamie Madilldc356042013-07-19 16:36:57 -04001041bool Context::isSampler(GLuint samplerName) const
1042{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001043 return mState.mSamplerManager->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001044}
1045
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001046void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001047{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001048 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001049
Jamie Madilldedd7b92014-11-05 16:30:36 -05001050 if (handle == 0)
1051 {
1052 texture = mZeroTextures[target].get();
1053 }
1054 else
1055 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001056 texture =
1057 mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001058 }
1059
1060 ASSERT(texture);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001061 mState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001062 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001063}
1064
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001065void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001066{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001067 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1068 mImplementation.get(), mState.mCaps, framebufferHandle);
1069 mState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001070 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071}
1072
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001073void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001075 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1076 mImplementation.get(), mState.mCaps, framebufferHandle);
1077 mState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001078 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001079 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080}
1081
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001082void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001083{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001084 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001085 mState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001086 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001087 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001088}
1089
Shao80957d92017-02-20 21:25:59 +08001090void Context::bindVertexBuffer(GLuint bindingIndex,
1091 GLuint bufferHandle,
1092 GLintptr offset,
1093 GLsizei stride)
1094{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001095 Buffer *buffer =
1096 mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
1097 mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001098 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001099}
1100
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001101void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001102{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001103 ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001104 Sampler *sampler =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001105 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
1106 mState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001107 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001108}
1109
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001110void Context::bindImageTexture(GLuint unit,
1111 GLuint texture,
1112 GLint level,
1113 GLboolean layered,
1114 GLint layer,
1115 GLenum access,
1116 GLenum format)
1117{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001118 Texture *tex = mState.mTextureManager->getTexture(texture);
1119 mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001120}
1121
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001122void Context::useProgram(GLuint program)
1123{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001124 ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001125 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001126}
1127
Jiajia Qin5451d532017-11-16 17:16:34 +08001128void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1129{
1130 UNIMPLEMENTED();
1131}
1132
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001133void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001134{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001135 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001136 TransformFeedback *transformFeedback =
1137 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001138 mState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001139}
1140
Yunchao Hea336b902017-08-02 16:05:21 +08001141void Context::bindProgramPipeline(GLuint pipelineHandle)
1142{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001143 ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
1144 mImplementation.get(), pipelineHandle);
1145 mState.setProgramPipelineBinding(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08001146}
1147
Corentin Wallezad3ae902018-03-09 13:40:42 -05001148void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001151 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152
Geoff Lang5aad9672014-09-08 11:10:42 -04001153 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001154 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001155
1156 // set query as active for specified target only if begin succeeded
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001157 mState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001158 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159}
1160
Corentin Wallezad3ae902018-03-09 13:40:42 -05001161void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001163 Query *queryObject = mState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001164 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165
Jamie Madill4f6592f2018-11-27 16:37:45 -05001166 // Intentionally don't call try here. We don't want an early return.
1167 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168
Geoff Lang5aad9672014-09-08 11:10:42 -04001169 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001170 mState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001171 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172}
1173
Corentin Wallezad3ae902018-03-09 13:40:42 -05001174void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001176 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001177
1178 Query *queryObject = getQuery(id, true, target);
1179 ASSERT(queryObject);
1180
Jamie Madill4f6592f2018-11-27 16:37:45 -05001181 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001182}
1183
Corentin Wallezad3ae902018-03-09 13:40:42 -05001184void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185{
1186 switch (pname)
1187 {
1188 case GL_CURRENT_QUERY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001189 params[0] = mState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190 break;
1191 case GL_QUERY_COUNTER_BITS_EXT:
1192 switch (target)
1193 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001194 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1196 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001197 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198 params[0] = getExtensions().queryCounterBitsTimestamp;
1199 break;
1200 default:
1201 UNREACHABLE();
1202 params[0] = 0;
1203 break;
1204 }
1205 break;
1206 default:
1207 UNREACHABLE();
1208 return;
1209 }
1210}
1211
Corentin Wallezad3ae902018-03-09 13:40:42 -05001212void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001213 GLenum pname,
1214 GLsizei bufSize,
1215 GLsizei *length,
1216 GLint *params)
1217{
1218 getQueryiv(target, pname, params);
1219}
1220
Geoff Lang2186c382016-10-14 10:54:54 -04001221void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001223 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001224}
1225
Brandon Jones59770802018-04-02 13:18:42 -07001226void Context::getQueryObjectivRobust(GLuint id,
1227 GLenum pname,
1228 GLsizei bufSize,
1229 GLsizei *length,
1230 GLint *params)
1231{
1232 getQueryObjectiv(id, pname, params);
1233}
1234
Geoff Lang2186c382016-10-14 10:54:54 -04001235void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001236{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001237 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001238}
1239
Brandon Jones59770802018-04-02 13:18:42 -07001240void Context::getQueryObjectuivRobust(GLuint id,
1241 GLenum pname,
1242 GLsizei bufSize,
1243 GLsizei *length,
1244 GLuint *params)
1245{
1246 getQueryObjectuiv(id, pname, params);
1247}
1248
Geoff Lang2186c382016-10-14 10:54:54 -04001249void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001250{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001251 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001252}
1253
Brandon Jones59770802018-04-02 13:18:42 -07001254void Context::getQueryObjecti64vRobust(GLuint id,
1255 GLenum pname,
1256 GLsizei bufSize,
1257 GLsizei *length,
1258 GLint64 *params)
1259{
1260 getQueryObjecti64v(id, pname, params);
1261}
1262
Geoff Lang2186c382016-10-14 10:54:54 -04001263void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001264{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001265 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001266}
1267
Brandon Jones59770802018-04-02 13:18:42 -07001268void Context::getQueryObjectui64vRobust(GLuint id,
1269 GLenum pname,
1270 GLsizei bufSize,
1271 GLsizei *length,
1272 GLuint64 *params)
1273{
1274 getQueryObjectui64v(id, pname, params);
1275}
1276
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001277Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001279 return mState.mFramebufferManager->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280}
1281
Jamie Madill2f348d22017-06-05 10:50:59 -04001282FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283{
Jamie Madill96a483b2017-06-27 16:49:21 -04001284 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285}
1286
Corentin Wallezad3ae902018-03-09 13:40:42 -05001287Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288{
Jamie Madill96a483b2017-06-27 16:49:21 -04001289 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001290 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001291 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001293
1294 Query *query = mQueryMap.query(handle);
1295 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001297 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001298 query = new Query(mImplementation->createQuery(type), handle);
1299 query->addRef();
1300 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001301 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001302 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001303}
1304
Geoff Lang70d0f492015-12-10 17:45:46 -05001305Query *Context::getQuery(GLuint handle) const
1306{
Jamie Madill96a483b2017-06-27 16:49:21 -04001307 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001308}
1309
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001310Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001311{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001312 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001313 return mState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001314}
1315
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001316Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001318 return mState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319}
1320
Geoff Lang492a7e42014-11-05 13:27:06 -05001321Compiler *Context::getCompiler() const
1322{
Jamie Madill2f348d22017-06-05 10:50:59 -04001323 if (mCompiler.get() == nullptr)
1324 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001325 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001326 }
1327 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001328}
1329
Jamie Madillc1d770e2017-04-13 17:31:24 -04001330void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
1332 switch (pname)
1333 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001334 case GL_SHADER_COMPILER:
1335 *params = GL_TRUE;
1336 break;
1337 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1338 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1339 break;
Jeff Gilbert465d6092019-01-02 16:21:18 -08001340
Jamie Madill231c7f52017-04-26 13:45:37 -04001341 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001342 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001343 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345}
1346
Jamie Madillc1d770e2017-04-13 17:31:24 -04001347void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348{
Shannon Woods53a94a82014-06-24 15:20:36 -04001349 // Queries about context capabilities and maximums are answered by Context.
1350 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351 switch (pname)
1352 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001353 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001354 params[0] = mState.mCaps.minAliasedLineWidth;
1355 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001358 params[0] = mState.mCaps.minAliasedPointSize;
1359 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001361 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001362 params[0] = mState.mCaps.minSmoothPointSize;
1363 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001364 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001365 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001366 params[0] = mState.mCaps.minSmoothLineWidth;
1367 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001368 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001369 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001370 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1371 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 break;
1373 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001374 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 break;
1376
1377 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1378 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1379 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001380 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1381 // GLES1 constants for modelview/projection matrix.
1382 if (getClientVersion() < Version(2, 0))
1383 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001384 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001385 }
1386 else
1387 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001388 ASSERT(mState.mExtensions.pathRendering);
1389 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001390 memcpy(params, m, 16 * sizeof(GLfloat));
1391 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001393 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001394
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001396 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001398 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001399}
1400
Jamie Madillc1d770e2017-04-13 17:31:24 -04001401void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001402{
Shannon Woods53a94a82014-06-24 15:20:36 -04001403 // Queries about context capabilities and maximums are answered by Context.
1404 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001405
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001406 switch (pname)
1407 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001408 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001409 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 break;
1411 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001412 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 break;
1414 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001415 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 break;
1417 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001418 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001421 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001424 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001425 break;
1426 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001427 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001428 break;
1429 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001430 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001431 break;
1432 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001433 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001434 break;
1435 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001436 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001437 break;
1438 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001439 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001440 break;
1441 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001442 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001443 break;
1444 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001445 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 case GL_SUBPIXEL_BITS:
1448 *params = 4;
1449 break;
1450 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001451 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001453 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001454 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001455 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001457 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001458 break;
1459 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001460 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001461 break;
1462 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001463 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001464 break;
1465 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001466 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001467 break;
1468 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001469 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 break;
1471 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001472 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001473 break;
1474 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001475 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001476 break;
1477 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001478 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 break;
1480 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001481 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001482 break;
1483 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001484 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001485 break;
1486 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001487 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001488 break;
1489 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001490 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001491 break;
1492 case GL_MAJOR_VERSION:
1493 *params = getClientVersion().major;
1494 break;
1495 case GL_MINOR_VERSION:
1496 *params = getClientVersion().minor;
1497 break;
1498 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001499 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001500 break;
1501 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001502 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001503 break;
1504 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001505 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001506 break;
1507 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001508 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001509 break;
1510 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001511 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 break;
1513 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001514 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001515 break;
1516 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001517 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001518 break;
1519 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001520 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001521 params[0] = mState.mCaps.maxViewportWidth;
1522 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001523 }
1524 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001526 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1527 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001528 break;
1529 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1530 *params = mResetStrategy;
1531 break;
1532 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001533 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001536 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1537 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001538 break;
1539 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001540 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001541 break;
1542 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001543 std::copy(mState.mCaps.programBinaryFormats.begin(),
1544 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 break;
1546 case GL_NUM_EXTENSIONS:
1547 *params = static_cast<GLint>(mExtensionStrings.size());
1548 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001549
Geoff Lang38f24ee2018-10-01 13:04:59 -04001550 // GL_ANGLE_request_extension
1551 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1552 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1553 break;
1554
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 // GL_KHR_debug
1556 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001557 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001560 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001561 break;
1562 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001563 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 break;
1565 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001566 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001568
Martin Radeve5285d22017-07-14 16:23:53 +03001569 // GL_ANGLE_multiview
1570 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001571 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001572 break;
1573
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 // GL_EXT_disjoint_timer_query
1575 case GL_GPU_DISJOINT_EXT:
1576 *params = mImplementation->getGPUDisjoint();
1577 break;
1578 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001579 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001580 break;
1581 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001582 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 break;
1584 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001585 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001586 break;
1587 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001588 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 break;
1590 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001591 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 break;
1593 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001594 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001595 break;
1596 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001597 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001598 break;
1599 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001600 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001601 break;
1602 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001603 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 break;
1605 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001606 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001609 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001610 break;
1611 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001612 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 break;
1614 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001615 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 break;
1617 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001618 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001619 break;
1620 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001621 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 break;
1623 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001624 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 break;
1626 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001627 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 break;
1629 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001630 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001631 break;
1632 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001633 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001634 break;
1635 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001636 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001637 break;
1638 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001639 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001640 break;
1641 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001642 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001643 break;
1644 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001645 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 break;
1647 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001648 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001651 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001654 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001657 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001660 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001663 *params = static_cast<GLint>(
1664 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001667 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001670 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 break;
1672 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001673 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 break;
1675 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001676 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001677 break;
1678 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001679 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 break;
1681 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001682 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 break;
1684 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001685 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001686 break;
1687 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001688 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001689 break;
1690 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001691 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 break;
1693 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001694 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001695 break;
1696 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001697 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001698 break;
1699 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001700 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001702
1703 // GL_EXT_geometry_shader
1704 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001705 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001706 break;
1707 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001708 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001709 break;
1710 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001711 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001712 break;
1713 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001714 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001715 break;
1716 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001717 *params = static_cast<GLint>(
1718 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001719 break;
1720 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001721 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001722 break;
1723 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001724 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001725 break;
1726 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001727 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001728 break;
1729 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001730 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001731 break;
1732 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001733 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001734 break;
1735 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001736 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001737 break;
1738 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001739 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001740 break;
1741 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001742 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001743 break;
1744 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001745 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001746 break;
1747 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001748 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001749 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001750 // GLES1 emulation: Caps queries
1751 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001752 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001753 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001754 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001755 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001756 break;
1757 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001758 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001759 break;
1760 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001761 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001762 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001763 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001764 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001765 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001766 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001767 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001768 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001769 // GLES1 emulation: Vertex attribute queries
1770 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1771 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1772 case GL_COLOR_ARRAY_BUFFER_BINDING:
1773 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1774 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1775 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1776 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1777 break;
1778 case GL_VERTEX_ARRAY_STRIDE:
1779 case GL_NORMAL_ARRAY_STRIDE:
1780 case GL_COLOR_ARRAY_STRIDE:
1781 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1782 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1783 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1784 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1785 break;
1786 case GL_VERTEX_ARRAY_SIZE:
1787 case GL_COLOR_ARRAY_SIZE:
1788 case GL_TEXTURE_COORD_ARRAY_SIZE:
1789 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1790 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1791 break;
1792 case GL_VERTEX_ARRAY_TYPE:
1793 case GL_COLOR_ARRAY_TYPE:
1794 case GL_NORMAL_ARRAY_TYPE:
1795 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1796 case GL_TEXTURE_COORD_ARRAY_TYPE:
1797 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1798 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1799 break;
1800
jchen1082af6202018-06-22 10:59:52 +08001801 // GL_KHR_parallel_shader_compile
1802 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001803 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001804 break;
1805
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001806 // GL_EXT_blend_func_extended
1807 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001808 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001809 break;
1810
Jamie Madill231c7f52017-04-26 13:45:37 -04001811 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001812 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001813 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001814 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001815}
1816
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001817void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001818{
Shannon Woods53a94a82014-06-24 15:20:36 -04001819 // Queries about context capabilities and maximums are answered by Context.
1820 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001821 switch (pname)
1822 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001824 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 break;
1826 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001827 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001828 break;
1829 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001830 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001831 break;
1832 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001833 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001834 break;
1835 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001836 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001837 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001838
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 // GL_EXT_disjoint_timer_query
1840 case GL_TIMESTAMP_EXT:
1841 *params = mImplementation->getTimestamp();
1842 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001843
Jamie Madill231c7f52017-04-26 13:45:37 -04001844 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001845 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001846 break;
1847 default:
1848 UNREACHABLE();
1849 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001850 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001851}
1852
Geoff Lang70d0f492015-12-10 17:45:46 -05001853void Context::getPointerv(GLenum pname, void **params) const
1854{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001855 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001856}
1857
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001858void Context::getPointervRobustANGLERobust(GLenum pname,
1859 GLsizei bufSize,
1860 GLsizei *length,
1861 void **params)
1862{
1863 UNIMPLEMENTED();
1864}
1865
Martin Radev66fb8202016-07-28 11:45:20 +03001866void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001867{
Shannon Woods53a94a82014-06-24 15:20:36 -04001868 // Queries about context capabilities and maximums are answered by Context.
1869 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001870
1871 GLenum nativeType;
1872 unsigned int numParams;
1873 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1874 ASSERT(queryStatus);
1875
1876 if (nativeType == GL_INT)
1877 {
1878 switch (target)
1879 {
1880 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1881 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001882 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001883 break;
1884 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1885 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001886 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001887 break;
1888 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001889 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001890 }
1891 }
1892 else
1893 {
1894 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1895 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001896}
1897
Brandon Jones59770802018-04-02 13:18:42 -07001898void Context::getIntegeri_vRobust(GLenum target,
1899 GLuint index,
1900 GLsizei bufSize,
1901 GLsizei *length,
1902 GLint *data)
1903{
1904 getIntegeri_v(target, index, data);
1905}
1906
Martin Radev66fb8202016-07-28 11:45:20 +03001907void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001908{
Shannon Woods53a94a82014-06-24 15:20:36 -04001909 // Queries about context capabilities and maximums are answered by Context.
1910 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001911
1912 GLenum nativeType;
1913 unsigned int numParams;
1914 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1915 ASSERT(queryStatus);
1916
1917 if (nativeType == GL_INT_64_ANGLEX)
1918 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001919 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001920 }
1921 else
1922 {
1923 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1924 }
1925}
1926
Brandon Jones59770802018-04-02 13:18:42 -07001927void Context::getInteger64i_vRobust(GLenum target,
1928 GLuint index,
1929 GLsizei bufSize,
1930 GLsizei *length,
1931 GLint64 *data)
1932{
1933 getInteger64i_v(target, index, data);
1934}
1935
Martin Radev66fb8202016-07-28 11:45:20 +03001936void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1937{
1938 // Queries about context capabilities and maximums are answered by Context.
1939 // Queries about current GL state values are answered by State.
1940
1941 GLenum nativeType;
1942 unsigned int numParams;
1943 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1944 ASSERT(queryStatus);
1945
1946 if (nativeType == GL_BOOL)
1947 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001948 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001949 }
1950 else
1951 {
1952 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1953 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001954}
1955
Brandon Jones59770802018-04-02 13:18:42 -07001956void Context::getBooleani_vRobust(GLenum target,
1957 GLuint index,
1958 GLsizei bufSize,
1959 GLsizei *length,
1960 GLboolean *data)
1961{
1962 getBooleani_v(target, index, data);
1963}
1964
Corentin Wallez336129f2017-10-17 15:55:40 -04001965void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001966{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001967 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001968 QueryBufferParameteriv(buffer, pname, params);
1969}
1970
Brandon Jones59770802018-04-02 13:18:42 -07001971void Context::getBufferParameterivRobust(BufferBinding target,
1972 GLenum pname,
1973 GLsizei bufSize,
1974 GLsizei *length,
1975 GLint *params)
1976{
1977 getBufferParameteriv(target, pname, params);
1978}
1979
He Yunchao010e4db2017-03-03 14:22:06 +08001980void Context::getFramebufferAttachmentParameteriv(GLenum target,
1981 GLenum attachment,
1982 GLenum pname,
1983 GLint *params)
1984{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001985 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001986 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001987}
1988
Brandon Jones59770802018-04-02 13:18:42 -07001989void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1990 GLenum attachment,
1991 GLenum pname,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLint *params)
1995{
1996 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1997}
1998
He Yunchao010e4db2017-03-03 14:22:06 +08001999void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2000{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002001 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08002002 QueryRenderbufferiv(this, renderbuffer, pname, params);
2003}
2004
Brandon Jones59770802018-04-02 13:18:42 -07002005void Context::getRenderbufferParameterivRobust(GLenum target,
2006 GLenum pname,
2007 GLsizei bufSize,
2008 GLsizei *length,
2009 GLint *params)
2010{
2011 getRenderbufferParameteriv(target, pname, params);
2012}
2013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002014void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002015{
Till Rathmannb8543632018-10-02 19:46:14 +02002016 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002017 QueryTexParameterfv(texture, pname, params);
2018}
2019
Brandon Jones59770802018-04-02 13:18:42 -07002020void Context::getTexParameterfvRobust(TextureType target,
2021 GLenum pname,
2022 GLsizei bufSize,
2023 GLsizei *length,
2024 GLfloat *params)
2025{
2026 getTexParameterfv(target, pname, params);
2027}
2028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002029void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002030{
Till Rathmannb8543632018-10-02 19:46:14 +02002031 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002032 QueryTexParameteriv(texture, pname, params);
2033}
Jiajia Qin5451d532017-11-16 17:16:34 +08002034
Till Rathmannb8543632018-10-02 19:46:14 +02002035void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2036{
2037 const Texture *const texture = getTargetTexture(target);
2038 QueryTexParameterIiv(texture, pname, params);
2039}
2040
2041void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2042{
2043 const Texture *const texture = getTargetTexture(target);
2044 QueryTexParameterIuiv(texture, pname, params);
2045}
2046
Brandon Jones59770802018-04-02 13:18:42 -07002047void Context::getTexParameterivRobust(TextureType target,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 GLsizei *length,
2051 GLint *params)
2052{
2053 getTexParameteriv(target, pname, params);
2054}
2055
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002056void Context::getTexParameterIivRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLint *params)
2061{
2062 UNIMPLEMENTED();
2063}
2064
2065void Context::getTexParameterIuivRobust(TextureType target,
2066 GLenum pname,
2067 GLsizei bufSize,
2068 GLsizei *length,
2069 GLuint *params)
2070{
2071 UNIMPLEMENTED();
2072}
2073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002074void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002075{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002076 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002077 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002078}
2079
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002080void Context::getTexLevelParameterivRobust(TextureTarget target,
2081 GLint level,
2082 GLenum pname,
2083 GLsizei bufSize,
2084 GLsizei *length,
2085 GLint *params)
2086{
2087 UNIMPLEMENTED();
2088}
2089
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002090void Context::getTexLevelParameterfv(TextureTarget target,
2091 GLint level,
2092 GLenum pname,
2093 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002094{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002095 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002096 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002097}
2098
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002099void Context::getTexLevelParameterfvRobust(TextureTarget target,
2100 GLint level,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 GLsizei *length,
2104 GLfloat *params)
2105{
2106 UNIMPLEMENTED();
2107}
2108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002109void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002110{
Till Rathmannb8543632018-10-02 19:46:14 +02002111 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002112 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002113}
2114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002116{
Till Rathmannb8543632018-10-02 19:46:14 +02002117 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002118 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002119}
2120
Brandon Jones59770802018-04-02 13:18:42 -07002121void Context::texParameterfvRobust(TextureType target,
2122 GLenum pname,
2123 GLsizei bufSize,
2124 const GLfloat *params)
2125{
2126 texParameterfv(target, pname, params);
2127}
2128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002129void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002130{
Till Rathmannb8543632018-10-02 19:46:14 +02002131 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002132 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002133}
2134
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002135void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002136{
Till Rathmannb8543632018-10-02 19:46:14 +02002137 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002138 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002139}
2140
Till Rathmannb8543632018-10-02 19:46:14 +02002141void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2142{
2143 Texture *const texture = getTargetTexture(target);
2144 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002145}
2146
2147void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2148{
2149 Texture *const texture = getTargetTexture(target);
2150 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002151}
2152
Brandon Jones59770802018-04-02 13:18:42 -07002153void Context::texParameterivRobust(TextureType target,
2154 GLenum pname,
2155 GLsizei bufSize,
2156 const GLint *params)
2157{
2158 texParameteriv(target, pname, params);
2159}
2160
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002161void Context::texParameterIivRobust(TextureType target,
2162 GLenum pname,
2163 GLsizei bufSize,
2164 const GLint *params)
2165{
2166 UNIMPLEMENTED();
2167}
2168
2169void Context::texParameterIuivRobust(TextureType target,
2170 GLenum pname,
2171 GLsizei bufSize,
2172 const GLuint *params)
2173{
2174 UNIMPLEMENTED();
2175}
2176
Jamie Madill493f9572018-05-24 19:52:15 -04002177void Context::drawArraysInstanced(PrimitiveMode mode,
2178 GLint first,
2179 GLsizei count,
2180 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002181{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002182 // No-op if count draws no primitives for given mode
2183 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002184 {
2185 return;
2186 }
2187
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002188 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002189 ANGLE_CONTEXT_TRY(
2190 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002191 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002192}
2193
Jamie Madill493f9572018-05-24 19:52:15 -04002194void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002195 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002196 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002197 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002198 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002199{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002200 // No-op if count draws no primitives for given mode
2201 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002202 {
2203 return;
2204 }
2205
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002206 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002207 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002208 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002209}
2210
Jamie Madill493f9572018-05-24 19:52:15 -04002211void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002212 GLuint start,
2213 GLuint end,
2214 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002215 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002216 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002217{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002218 // No-op if count draws no primitives for given mode
2219 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002220 {
2221 return;
2222 }
2223
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002224 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002225 ANGLE_CONTEXT_TRY(
2226 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227}
2228
Jamie Madill493f9572018-05-24 19:52:15 -04002229void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002230{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002231 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002232 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002233}
2234
Jamie Madill8dc27f92018-11-29 11:45:44 -05002235void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002236{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002237 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002238 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002239}
2240
Jamie Madill675fe712016-12-19 13:07:54 -05002241void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002243 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002244}
2245
Jamie Madill675fe712016-12-19 13:07:54 -05002246void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002247{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002248 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002249}
2250
Austin Kinross6ee1e782015-05-29 17:05:37 -07002251void Context::insertEventMarker(GLsizei length, const char *marker)
2252{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002253 ASSERT(mImplementation);
2254 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002255}
2256
2257void Context::pushGroupMarker(GLsizei length, const char *marker)
2258{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002259 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002260
2261 if (marker == nullptr)
2262 {
2263 // From the EXT_debug_marker spec,
2264 // "If <marker> is null then an empty string is pushed on the stack."
2265 mImplementation->pushGroupMarker(length, "");
2266 }
2267 else
2268 {
2269 mImplementation->pushGroupMarker(length, marker);
2270 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002271}
2272
2273void Context::popGroupMarker()
2274{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002275 ASSERT(mImplementation);
2276 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002277}
2278
Geoff Langd8605522016-04-13 10:19:12 -04002279void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2280{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002281 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002282 ASSERT(programObject);
2283
2284 programObject->bindUniformLocation(location, name);
2285}
2286
Brandon Jones59770802018-04-02 13:18:42 -07002287void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002288{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002289 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002290}
2291
Brandon Jones59770802018-04-02 13:18:42 -07002292void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002293{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002294 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002295}
2296
Brandon Jones59770802018-04-02 13:18:42 -07002297void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002298{
2299 GLfloat I[16];
2300 angle::Matrix<GLfloat>::setToIdentity(I);
2301
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002302 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002303}
2304
2305void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2306{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002307 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002308 if (!pathObj)
2309 return;
2310
Geoff Lang9bf86f02018-07-26 11:46:34 -04002311 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002312
2313 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2314}
2315
2316void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2317{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002318 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002319 if (!pathObj)
2320 return;
2321
Geoff Lang9bf86f02018-07-26 11:46:34 -04002322 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002323
2324 mImplementation->stencilStrokePath(pathObj, reference, mask);
2325}
2326
2327void Context::coverFillPath(GLuint path, GLenum coverMode)
2328{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002329 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002330 if (!pathObj)
2331 return;
2332
Geoff Lang9bf86f02018-07-26 11:46:34 -04002333 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002334
2335 mImplementation->coverFillPath(pathObj, coverMode);
2336}
2337
2338void Context::coverStrokePath(GLuint path, GLenum coverMode)
2339{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002340 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002341 if (!pathObj)
2342 return;
2343
Geoff Lang9bf86f02018-07-26 11:46:34 -04002344 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002345
2346 mImplementation->coverStrokePath(pathObj, coverMode);
2347}
2348
2349void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2350{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002351 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352 if (!pathObj)
2353 return;
2354
Geoff Lang9bf86f02018-07-26 11:46:34 -04002355 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002356
2357 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2358}
2359
2360void Context::stencilThenCoverStrokePath(GLuint path,
2361 GLint reference,
2362 GLuint mask,
2363 GLenum coverMode)
2364{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002365 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002366 if (!pathObj)
2367 return;
2368
Geoff Lang9bf86f02018-07-26 11:46:34 -04002369 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370
2371 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2372}
2373
Sami Väisänend59ca052016-06-21 16:10:00 +03002374void Context::coverFillPathInstanced(GLsizei numPaths,
2375 GLenum pathNameType,
2376 const void *paths,
2377 GLuint pathBase,
2378 GLenum coverMode,
2379 GLenum transformType,
2380 const GLfloat *transformValues)
2381{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002382 const auto &pathObjects =
2383 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002384
Geoff Lang9bf86f02018-07-26 11:46:34 -04002385 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002386
2387 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2388}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002389
Sami Väisänend59ca052016-06-21 16:10:00 +03002390void Context::coverStrokePathInstanced(GLsizei numPaths,
2391 GLenum pathNameType,
2392 const void *paths,
2393 GLuint pathBase,
2394 GLenum coverMode,
2395 GLenum transformType,
2396 const GLfloat *transformValues)
2397{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002398 const auto &pathObjects =
2399 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002400
2401 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002402 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002403
2404 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2405 transformValues);
2406}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002407
Sami Väisänend59ca052016-06-21 16:10:00 +03002408void Context::stencilFillPathInstanced(GLsizei numPaths,
2409 GLenum pathNameType,
2410 const void *paths,
2411 GLuint pathBase,
2412 GLenum fillMode,
2413 GLuint mask,
2414 GLenum transformType,
2415 const GLfloat *transformValues)
2416{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002417 const auto &pathObjects =
2418 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002419
2420 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002421 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002422
2423 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2424 transformValues);
2425}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002426
Sami Väisänend59ca052016-06-21 16:10:00 +03002427void Context::stencilStrokePathInstanced(GLsizei numPaths,
2428 GLenum pathNameType,
2429 const void *paths,
2430 GLuint pathBase,
2431 GLint reference,
2432 GLuint mask,
2433 GLenum transformType,
2434 const GLfloat *transformValues)
2435{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002436 const auto &pathObjects =
2437 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002438
Geoff Lang9bf86f02018-07-26 11:46:34 -04002439 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002440
2441 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2442 transformValues);
2443}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002444
Sami Väisänend59ca052016-06-21 16:10:00 +03002445void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2446 GLenum pathNameType,
2447 const void *paths,
2448 GLuint pathBase,
2449 GLenum fillMode,
2450 GLuint mask,
2451 GLenum coverMode,
2452 GLenum transformType,
2453 const GLfloat *transformValues)
2454{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002455 const auto &pathObjects =
2456 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002457
Geoff Lang9bf86f02018-07-26 11:46:34 -04002458 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
2460 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2461 transformType, transformValues);
2462}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002463
Sami Väisänend59ca052016-06-21 16:10:00 +03002464void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2465 GLenum pathNameType,
2466 const void *paths,
2467 GLuint pathBase,
2468 GLint reference,
2469 GLuint mask,
2470 GLenum coverMode,
2471 GLenum transformType,
2472 const GLfloat *transformValues)
2473{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002474 const auto &pathObjects =
2475 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
Geoff Lang9bf86f02018-07-26 11:46:34 -04002477 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
2479 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2480 transformType, transformValues);
2481}
2482
Sami Väisänen46eaa942016-06-29 10:26:37 +03002483void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2484{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002485 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002486
2487 programObject->bindFragmentInputLocation(location, name);
2488}
2489
2490void Context::programPathFragmentInputGen(GLuint program,
2491 GLint location,
2492 GLenum genMode,
2493 GLint components,
2494 const GLfloat *coeffs)
2495{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002496 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002497
jchen103fd614d2018-08-13 12:21:58 +08002498 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002499}
2500
jchen1015015f72017-03-16 13:54:21 +08002501GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2502{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002503 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002504 return QueryProgramResourceIndex(programObject, programInterface, name);
2505}
2506
jchen10fd7c3b52017-03-21 15:36:03 +08002507void Context::getProgramResourceName(GLuint program,
2508 GLenum programInterface,
2509 GLuint index,
2510 GLsizei bufSize,
2511 GLsizei *length,
2512 GLchar *name)
2513{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002514 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002515 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2516}
2517
jchen10191381f2017-04-11 13:59:04 +08002518GLint Context::getProgramResourceLocation(GLuint program,
2519 GLenum programInterface,
2520 const GLchar *name)
2521{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002522 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002523 return QueryProgramResourceLocation(programObject, programInterface, name);
2524}
2525
jchen10880683b2017-04-12 16:21:55 +08002526void Context::getProgramResourceiv(GLuint program,
2527 GLenum programInterface,
2528 GLuint index,
2529 GLsizei propCount,
2530 const GLenum *props,
2531 GLsizei bufSize,
2532 GLsizei *length,
2533 GLint *params)
2534{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002535 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002536 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2537 length, params);
2538}
2539
jchen10d9cd7b72017-08-30 15:04:25 +08002540void Context::getProgramInterfaceiv(GLuint program,
2541 GLenum programInterface,
2542 GLenum pname,
2543 GLint *params)
2544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002545 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002546 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2547}
2548
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002549void Context::getProgramInterfaceivRobust(GLuint program,
2550 GLenum programInterface,
2551 GLenum pname,
2552 GLsizei bufSize,
2553 GLsizei *length,
2554 GLint *params)
2555{
2556 UNIMPLEMENTED();
2557}
2558
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002559void Context::handleError(GLenum errorCode,
2560 const char *message,
2561 const char *file,
2562 const char *function,
2563 unsigned int line)
2564{
2565 mErrors.handleError(errorCode, message, file, function, line);
2566}
2567
Jamie Madilla139f012018-10-10 16:13:03 -04002568void Context::validationError(GLenum errorCode, const char *message)
2569{
2570 mErrors.validationError(errorCode, message);
2571}
2572
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002573// Get one of the recorded errors and clear its flag, if any.
2574// [OpenGL ES 2.0.24] section 2.5 page 13.
2575GLenum Context::getError()
2576{
Geoff Langda5777c2014-07-11 09:52:58 -04002577 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002578 {
Geoff Langda5777c2014-07-11 09:52:58 -04002579 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580 }
Geoff Langda5777c2014-07-11 09:52:58 -04002581 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002582 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002583 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585}
2586
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002587// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002588void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002589{
2590 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002591 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002592 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002593 mContextLostForced = true;
2594 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002595 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002596}
2597
Jamie Madillfa920eb2018-01-04 11:45:50 -05002598GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002599{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002600 // Even if the application doesn't want to know about resets, we want to know
2601 // as it will allow us to skip all the calls.
2602 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002604 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002605 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002606 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002607 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608
2609 // EXT_robustness, section 2.6: If the reset notification behavior is
2610 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2611 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2612 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613 }
2614
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2616 // status should be returned at least once, and GL_NO_ERROR should be returned
2617 // once the device has finished resetting.
2618 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 ASSERT(mResetStatus == GL_NO_ERROR);
2621 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002622
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002623 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002625 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002626 }
2627 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002628 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002629 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002630 // If markContextLost was used to mark the context lost then
2631 // assume that is not recoverable, and continue to report the
2632 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 mResetStatus = mImplementation->getResetStatus();
2634 }
Jamie Madill893ab082014-05-16 16:56:10 -04002635
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637}
2638
2639bool Context::isResetNotificationEnabled()
2640{
2641 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2642}
2643
Corentin Walleze3b10e82015-05-20 11:06:25 -04002644const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002645{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002646 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002647}
2648
2649EGLenum Context::getClientType() const
2650{
2651 return mClientType;
2652}
2653
2654EGLenum Context::getRenderBuffer() const
2655{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002656 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002657 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002658 {
2659 return EGL_NONE;
2660 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002661
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002662 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002663 ASSERT(backAttachment != nullptr);
2664 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002665}
2666
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002667VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002668{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002669 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002670 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2671 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002672 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002673 vertexArray =
2674 new VertexArray(mImplementation.get(), vertexArrayHandle,
2675 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676
Jamie Madill96a483b2017-06-27 16:49:21 -04002677 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002678 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002679
2680 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002681}
2682
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002683TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002684{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002685 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2687 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002688 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002689 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002690 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002691 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002692 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002693 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002694
2695 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002696}
2697
2698bool Context::isVertexArrayGenerated(GLuint vertexArray)
2699{
Jamie Madill96a483b2017-06-27 16:49:21 -04002700 ASSERT(mVertexArrayMap.contains(0));
2701 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002702}
2703
2704bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2705{
Jamie Madill96a483b2017-06-27 16:49:21 -04002706 ASSERT(mTransformFeedbackMap.contains(0));
2707 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002708}
2709
Shannon Woods53a94a82014-06-24 15:20:36 -04002710void Context::detachTexture(GLuint texture)
2711{
2712 // Simple pass-through to State's detachTexture method, as textures do not require
2713 // allocation map management either here or in the resource manager at detach time.
2714 // Zero textures are held by the Context, and we don't attempt to request them from
2715 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002716 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002717}
2718
James Darpinian4d9d4832018-03-13 12:43:28 -07002719void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002720{
Yuly Novikov5807a532015-12-03 13:01:22 -05002721 // Simple pass-through to State's detachBuffer method, since
2722 // only buffer attachments to container objects that are bound to the current context
2723 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002724
Yuly Novikov5807a532015-12-03 13:01:22 -05002725 // [OpenGL ES 3.2] section 5.1.2 page 45:
2726 // Attachments to unbound container objects, such as
2727 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2728 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002729 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730}
2731
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732void Context::detachFramebuffer(GLuint framebuffer)
2733{
Shannon Woods53a94a82014-06-24 15:20:36 -04002734 // Framebuffer detachment is handled by Context, because 0 is a valid
2735 // Framebuffer object, and a pointer to it must be passed from Context
2736 // to State at binding time.
2737
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002738 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002739 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2740 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2741 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002742
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002743 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744 {
2745 bindReadFramebuffer(0);
2746 }
2747
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002748 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749 {
2750 bindDrawFramebuffer(0);
2751 }
2752}
2753
2754void Context::detachRenderbuffer(GLuint renderbuffer)
2755{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002756 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002757}
2758
Jamie Madill57a89722013-07-02 11:57:03 -04002759void Context::detachVertexArray(GLuint vertexArray)
2760{
Jamie Madill77a72f62015-04-14 11:18:32 -04002761 // Vertex array detachment is handled by Context, because 0 is a valid
2762 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002763 // binding time.
2764
Jamie Madill57a89722013-07-02 11:57:03 -04002765 // [OpenGL ES 3.0.2] section 2.10 page 43:
2766 // If a vertex array object that is currently bound is deleted, the binding
2767 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002768 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002769 {
2770 bindVertexArray(0);
2771 }
2772}
2773
Geoff Langc8058452014-02-03 12:04:11 -05002774void Context::detachTransformFeedback(GLuint transformFeedback)
2775{
Corentin Walleza2257da2016-04-19 16:43:12 -04002776 // Transform feedback detachment is handled by Context, because 0 is a valid
2777 // transform feedback, and a pointer to it must be passed from Context to State at
2778 // binding time.
2779
2780 // The OpenGL specification doesn't mention what should happen when the currently bound
2781 // transform feedback object is deleted. Since it is a container object, we treat it like
2782 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002783 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002784 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002785 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002786 }
Geoff Langc8058452014-02-03 12:04:11 -05002787}
2788
Jamie Madilldc356042013-07-19 16:36:57 -04002789void Context::detachSampler(GLuint sampler)
2790{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002791 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002792}
2793
Yunchao Hea336b902017-08-02 16:05:21 +08002794void Context::detachProgramPipeline(GLuint pipeline)
2795{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002796 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002797}
2798
Jamie Madill3ef140a2017-08-26 23:11:21 -04002799void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002801 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002802 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803}
2804
Jamie Madille29d1672013-07-19 16:36:57 -04002805void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2806{
Till Rathmannb8543632018-10-02 19:46:14 +02002807 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002808 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002809 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002810}
Jamie Madille29d1672013-07-19 16:36:57 -04002811
Geoff Langc1984ed2016-10-07 12:41:00 -04002812void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2813{
Till Rathmannb8543632018-10-02 19:46:14 +02002814 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002815 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002816 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002817}
2818
Till Rathmannb8543632018-10-02 19:46:14 +02002819void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2820{
2821 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002822 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002823 SetSamplerParameterIiv(this, samplerObject, pname, param);
2824}
2825
2826void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2827{
2828 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002829 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002830 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2831}
2832
Brandon Jones59770802018-04-02 13:18:42 -07002833void Context::samplerParameterivRobust(GLuint sampler,
2834 GLenum pname,
2835 GLsizei bufSize,
2836 const GLint *param)
2837{
2838 samplerParameteriv(sampler, pname, param);
2839}
2840
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002841void Context::samplerParameterIivRobust(GLuint sampler,
2842 GLenum pname,
2843 GLsizei bufSize,
2844 const GLint *param)
2845{
2846 UNIMPLEMENTED();
2847}
2848
2849void Context::samplerParameterIuivRobust(GLuint sampler,
2850 GLenum pname,
2851 GLsizei bufSize,
2852 const GLuint *param)
2853{
2854 UNIMPLEMENTED();
2855}
2856
Jamie Madille29d1672013-07-19 16:36:57 -04002857void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2858{
Till Rathmannb8543632018-10-02 19:46:14 +02002859 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002860 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002861 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002862}
2863
Geoff Langc1984ed2016-10-07 12:41:00 -04002864void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002865{
Till Rathmannb8543632018-10-02 19:46:14 +02002866 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002867 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002868 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002869}
2870
Brandon Jones59770802018-04-02 13:18:42 -07002871void Context::samplerParameterfvRobust(GLuint sampler,
2872 GLenum pname,
2873 GLsizei bufSize,
2874 const GLfloat *param)
2875{
2876 samplerParameterfv(sampler, pname, param);
2877}
2878
Geoff Langc1984ed2016-10-07 12:41:00 -04002879void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002880{
Till Rathmannb8543632018-10-02 19:46:14 +02002881 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002882 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002883 QuerySamplerParameteriv(samplerObject, pname, params);
2884}
Jamie Madill9675b802013-07-19 16:36:59 -04002885
Till Rathmannb8543632018-10-02 19:46:14 +02002886void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2887{
2888 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002889 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002890 QuerySamplerParameterIiv(samplerObject, pname, params);
2891}
2892
2893void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2894{
2895 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002896 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002897 QuerySamplerParameterIuiv(samplerObject, pname, params);
2898}
2899
Brandon Jones59770802018-04-02 13:18:42 -07002900void Context::getSamplerParameterivRobust(GLuint sampler,
2901 GLenum pname,
2902 GLsizei bufSize,
2903 GLsizei *length,
2904 GLint *params)
2905{
2906 getSamplerParameteriv(sampler, pname, params);
2907}
2908
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002909void Context::getSamplerParameterIivRobust(GLuint sampler,
2910 GLenum pname,
2911 GLsizei bufSize,
2912 GLsizei *length,
2913 GLint *params)
2914{
2915 UNIMPLEMENTED();
2916}
2917
2918void Context::getSamplerParameterIuivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLuint *params)
2923{
2924 UNIMPLEMENTED();
2925}
2926
Geoff Langc1984ed2016-10-07 12:41:00 -04002927void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2928{
Till Rathmannb8543632018-10-02 19:46:14 +02002929 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002930 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002931 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002932}
2933
Brandon Jones59770802018-04-02 13:18:42 -07002934void Context::getSamplerParameterfvRobust(GLuint sampler,
2935 GLenum pname,
2936 GLsizei bufSize,
2937 GLsizei *length,
2938 GLfloat *params)
2939{
2940 getSamplerParameterfv(sampler, pname, params);
2941}
2942
Olli Etuahof0fee072016-03-30 15:11:58 +03002943void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2944{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002945 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002946 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002947}
2948
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002949void Context::initRendererString()
2950{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002951 std::ostringstream rendererString;
2952 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002953 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002954 rendererString << ")";
2955
Geoff Langcec35902014-04-16 10:52:36 -04002956 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002957}
2958
Geoff Langc339c4e2016-11-29 10:37:36 -05002959void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002960{
Geoff Langc339c4e2016-11-29 10:37:36 -05002961 const Version &clientVersion = getClientVersion();
2962
2963 std::ostringstream versionString;
2964 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2965 << ANGLE_VERSION_STRING << ")";
2966 mVersionString = MakeStaticString(versionString.str());
2967
2968 std::ostringstream shadingLanguageVersionString;
2969 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2970 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2971 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2972 << ")";
2973 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002974}
2975
Geoff Langcec35902014-04-16 10:52:36 -04002976void Context::initExtensionStrings()
2977{
Geoff Langc339c4e2016-11-29 10:37:36 -05002978 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2979 std::ostringstream combinedStringStream;
2980 std::copy(strings.begin(), strings.end(),
2981 std::ostream_iterator<const char *>(combinedStringStream, " "));
2982 return MakeStaticString(combinedStringStream.str());
2983 };
2984
2985 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002986 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002987 {
2988 mExtensionStrings.push_back(MakeStaticString(extensionString));
2989 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002990 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002991
Geoff Langc339c4e2016-11-29 10:37:36 -05002992 mRequestableExtensionStrings.clear();
2993 for (const auto &extensionInfo : GetExtensionInfoMap())
2994 {
2995 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002996 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002997 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002998 {
2999 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3000 }
3001 }
3002 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003003}
3004
Geoff Langc339c4e2016-11-29 10:37:36 -05003005const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003006{
Geoff Langc339c4e2016-11-29 10:37:36 -05003007 switch (name)
3008 {
3009 case GL_VENDOR:
3010 return reinterpret_cast<const GLubyte *>("Google Inc.");
3011
3012 case GL_RENDERER:
3013 return reinterpret_cast<const GLubyte *>(mRendererString);
3014
3015 case GL_VERSION:
3016 return reinterpret_cast<const GLubyte *>(mVersionString);
3017
3018 case GL_SHADING_LANGUAGE_VERSION:
3019 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3020
3021 case GL_EXTENSIONS:
3022 return reinterpret_cast<const GLubyte *>(mExtensionString);
3023
3024 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3025 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3026
3027 default:
3028 UNREACHABLE();
3029 return nullptr;
3030 }
Geoff Langcec35902014-04-16 10:52:36 -04003031}
3032
Geoff Langc339c4e2016-11-29 10:37:36 -05003033const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003034{
Geoff Langc339c4e2016-11-29 10:37:36 -05003035 switch (name)
3036 {
3037 case GL_EXTENSIONS:
3038 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3039
3040 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3041 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3042
3043 default:
3044 UNREACHABLE();
3045 return nullptr;
3046 }
Geoff Langcec35902014-04-16 10:52:36 -04003047}
3048
3049size_t Context::getExtensionStringCount() const
3050{
3051 return mExtensionStrings.size();
3052}
3053
Geoff Lang111a99e2017-10-17 10:58:41 -04003054bool Context::isExtensionRequestable(const char *name)
3055{
3056 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3057 auto extension = extensionInfos.find(name);
3058
Geoff Lang111a99e2017-10-17 10:58:41 -04003059 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003060 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003061}
3062
Geoff Langc339c4e2016-11-29 10:37:36 -05003063void Context::requestExtension(const char *name)
3064{
3065 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3066 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3067 const auto &extension = extensionInfos.at(name);
3068 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003069 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003070
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003071 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003072 {
3073 // Extension already enabled
3074 return;
3075 }
3076
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003077 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003078 updateCaps();
3079 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003080
Jamie Madill2f348d22017-06-05 10:50:59 -04003081 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3082 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003083
Jamie Madill81c2e252017-09-09 23:32:46 -04003084 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3085 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003086 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003087 for (auto &zeroTexture : mZeroTextures)
3088 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003089 if (zeroTexture.get() != nullptr)
3090 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003091 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003092 }
Geoff Lang9aded172017-04-05 11:07:56 -04003093 }
3094
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003095 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003096}
3097
3098size_t Context::getRequestableExtensionStringCount() const
3099{
3100 return mRequestableExtensionStrings.size();
3101}
3102
Jamie Madill493f9572018-05-24 19:52:15 -04003103void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003104{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003105 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003106 ASSERT(transformFeedback != nullptr);
3107 ASSERT(!transformFeedback->isPaused());
3108
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003109 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003110 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003111}
3112
3113bool Context::hasActiveTransformFeedback(GLuint program) const
3114{
3115 for (auto pair : mTransformFeedbackMap)
3116 {
3117 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3118 {
3119 return true;
3120 }
3121 }
3122 return false;
3123}
3124
Geoff Lang33f11fb2018-05-07 13:42:47 -04003125Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003126{
3127 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3128
jchen1082af6202018-06-22 10:59:52 +08003129 // Explicitly enable GL_KHR_parallel_shader_compile
3130 supportedExtensions.parallelShaderCompile = true;
3131
Geoff Langb0f917f2017-12-05 13:41:54 -05003132 if (getClientVersion() < ES_2_0)
3133 {
3134 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003135 supportedExtensions.pointSizeArray = true;
3136 supportedExtensions.textureCubeMap = true;
3137 supportedExtensions.pointSprite = true;
3138 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003139 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003140 }
3141
3142 if (getClientVersion() < ES_3_0)
3143 {
3144 // Disable ES3+ extensions
3145 supportedExtensions.colorBufferFloat = false;
3146 supportedExtensions.eglImageExternalEssl3 = false;
3147 supportedExtensions.textureNorm16 = false;
3148 supportedExtensions.multiview = false;
3149 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003150 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003151 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003152
3153 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3154 if (!supportedExtensions.sRGB)
3155 {
3156 supportedExtensions.textureSRGBDecode = false;
3157 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003158 }
3159
3160 if (getClientVersion() < ES_3_1)
3161 {
3162 // Disable ES3.1+ extensions
3163 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003164
3165 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3166 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003167 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003168 }
3169
3170 if (getClientVersion() > ES_2_0)
3171 {
3172 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3173 // supportedExtensions.sRGB = false;
3174 }
3175
3176 // Some extensions are always available because they are implemented in the GL layer.
3177 supportedExtensions.bindUniformLocation = true;
3178 supportedExtensions.vertexArrayObject = true;
3179 supportedExtensions.bindGeneratesResource = true;
3180 supportedExtensions.clientArrays = true;
3181 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003182 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003183
3184 // Enable the no error extension if the context was created with the flag.
3185 supportedExtensions.noError = mSkipValidation;
3186
3187 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003188 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003189
3190 // Explicitly enable GL_KHR_debug
3191 supportedExtensions.debug = true;
3192 supportedExtensions.maxDebugMessageLength = 1024;
3193 supportedExtensions.maxDebugLoggedMessages = 1024;
3194 supportedExtensions.maxDebugGroupStackDepth = 1024;
3195 supportedExtensions.maxLabelLength = 1024;
3196
3197 // Explicitly enable GL_ANGLE_robust_client_memory
3198 supportedExtensions.robustClientMemory = true;
3199
3200 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003201 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003202
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003203 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3204 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003205 supportedExtensions.robustBufferAccessBehavior =
3206 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3207
3208 // Enable the cache control query unconditionally.
3209 supportedExtensions.programCacheControl = true;
3210
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003211 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003212 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003213 {
3214 // GL_ANGLE_explicit_context_gles1
3215 supportedExtensions.explicitContextGles1 = true;
3216 // GL_ANGLE_explicit_context
3217 supportedExtensions.explicitContext = true;
3218 }
3219
Geoff Lang79b91402018-10-04 15:11:30 -04003220 supportedExtensions.memorySize = true;
3221
Geoff Langb0f917f2017-12-05 13:41:54 -05003222 return supportedExtensions;
3223}
3224
Geoff Lang33f11fb2018-05-07 13:42:47 -04003225void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003226{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003227 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003228
Geoff Lang33f11fb2018-05-07 13:42:47 -04003229 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003230 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003231
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003232 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003233
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003234 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3235 if (getClientVersion() < Version(2, 0))
3236 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003237 mState.mCaps.maxMultitextureUnits = 4;
3238 mState.mCaps.maxClipPlanes = 6;
3239 mState.mCaps.maxLights = 8;
3240 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3241 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3242 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mState.mCaps.minSmoothPointSize = 1.0f;
3244 mState.mCaps.maxSmoothPointSize = 1.0f;
3245 mState.mCaps.minSmoothLineWidth = 1.0f;
3246 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003247 }
3248
Luc Ferronad2ae932018-06-11 15:31:17 -04003249 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003250 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003251
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003252 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003253
Jamie Madill0f80ed82017-09-19 00:24:56 -04003254 if (getClientVersion() < ES_3_1)
3255 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003256 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003257 }
3258 else
3259 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003260 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003261 }
Geoff Lang301d1612014-07-09 10:34:37 -04003262
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003263 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003264 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003265 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003266
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003267 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3268 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003269
3270 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003271 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3272 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003273 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003274 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003276
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003277 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003278
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003279 mState.mCaps.maxSampleMaskWords =
3280 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003281
Geoff Langc287ea62016-09-16 14:46:51 -04003282 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003283 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003284 for (const auto &extensionInfo : GetExtensionInfoMap())
3285 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003286 // If the user has requested that extensions start disabled and they are requestable,
3287 // disable them.
3288 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003289 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003290 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003291 }
3292 }
3293
3294 // Generate texture caps
3295 updateCaps();
3296}
3297
3298void Context::updateCaps()
3299{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003300 mState.mCaps.compressedTextureFormats.clear();
3301 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003302
Jamie Madill7b62cf92017-11-02 15:20:49 -04003303 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003304 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003305 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003306 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003307
Geoff Lang0d8b7242015-09-09 14:56:53 -04003308 // Update the format caps based on the client version and extensions.
3309 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3310 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003311 formatCaps.texturable = formatCaps.texturable &&
3312 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3313 formatCaps.filterable = formatCaps.filterable &&
3314 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003315 formatCaps.textureAttachment =
3316 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003317 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3318 formatCaps.renderbuffer =
3319 formatCaps.renderbuffer &&
3320 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003321
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003322 // OpenGL ES does not support multisampling with non-rendererable formats
3323 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003324 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003325 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003326 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003327 {
Geoff Langd87878e2014-09-19 15:42:59 -04003328 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003329 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003330 else
3331 {
3332 // We may have limited the max samples for some required renderbuffer formats due to
3333 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3334 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3335
3336 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3337 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3338 // exception of signed and unsigned integer formats."
3339 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3340 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3341 {
3342 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003343 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003344 }
3345
3346 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003347 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003348 {
3349 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3350 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3351 // the exception that the signed and unsigned integer formats are required only to
3352 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3353 // multisamples, which must be at least one."
3354 if (formatInfo.componentType == GL_INT ||
3355 formatInfo.componentType == GL_UNSIGNED_INT)
3356 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003357 mState.mCaps.maxIntegerSamples =
3358 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003359 }
3360
3361 // GLES 3.1 section 19.3.1.
3362 if (formatCaps.texturable)
3363 {
3364 if (formatInfo.depthBits > 0)
3365 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003366 mState.mCaps.maxDepthTextureSamples =
3367 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003368 }
3369 else if (formatInfo.redBits > 0)
3370 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003371 mState.mCaps.maxColorTextureSamples =
3372 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003373 }
3374 }
3375 }
3376 }
Geoff Langd87878e2014-09-19 15:42:59 -04003377
3378 if (formatCaps.texturable && formatInfo.compressed)
3379 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003380 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003381 }
3382
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003383 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003384 }
Jamie Madill32447362017-06-28 14:53:52 -04003385
3386 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003387 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003388 {
3389 mMemoryProgramCache = nullptr;
3390 }
Corentin Walleze4477002017-12-01 14:39:58 -05003391
3392 // Compute which buffer types are allowed
3393 mValidBufferBindings.reset();
3394 mValidBufferBindings.set(BufferBinding::ElementArray);
3395 mValidBufferBindings.set(BufferBinding::Array);
3396
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003397 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003398 {
3399 mValidBufferBindings.set(BufferBinding::PixelPack);
3400 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3401 }
3402
3403 if (getClientVersion() >= ES_3_0)
3404 {
3405 mValidBufferBindings.set(BufferBinding::CopyRead);
3406 mValidBufferBindings.set(BufferBinding::CopyWrite);
3407 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3408 mValidBufferBindings.set(BufferBinding::Uniform);
3409 }
3410
3411 if (getClientVersion() >= ES_3_1)
3412 {
3413 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3414 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3415 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3416 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3417 }
jchen107ae70d82018-07-06 13:47:01 +08003418
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003419 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003420
Jamie Madillef9fcd92018-11-28 14:03:59 -05003421 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003422 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003423 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3424 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3425 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3427 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003429
Jamie Madillac66f982018-10-09 18:30:01 -04003430 // Reinitialize state cache after extension changes.
3431 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003432}
3433
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003434void Context::initWorkarounds()
3435{
Jamie Madill761b02c2017-06-23 16:27:06 -04003436 // Apply back-end workarounds.
3437 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3438
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003439 // Lose the context upon out of memory error if the application is
3440 // expecting to watch for those events.
3441 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003442
3443 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3444 {
3445 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3446 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3447 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3448 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003449}
3450
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003451bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3452{
3453 return (instanceCount == 0) || noopDraw(mode, count);
3454}
3455
Jamie Madill526392d2018-11-16 09:35:14 -05003456angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003457{
Geoff Langa8cb2872018-03-09 16:09:40 -05003458 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003459 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003460 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003461 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003462}
3463
Jamie Madill526392d2018-11-16 09:35:14 -05003464angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003465{
Geoff Langa8cb2872018-03-09 16:09:40 -05003466 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003467 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3468 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003469 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003470 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003471}
3472
Jamie Madill132d15c2018-11-30 15:25:38 -05003473ANGLE_INLINE angle::Result Context::prepareForDispatch()
3474{
3475 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3476 return syncDirtyBits(mComputeDirtyBits);
3477}
3478
Jamie Madill526392d2018-11-16 09:35:14 -05003479angle::Result Context::syncState(const State::DirtyBits &bitMask,
3480 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003481{
Geoff Langa8cb2872018-03-09 16:09:40 -05003482 ANGLE_TRY(syncDirtyObjects(objectMask));
3483 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003484 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003485}
3486
Jamie Madillc29968b2016-01-20 11:17:23 -05003487void Context::blitFramebuffer(GLint srcX0,
3488 GLint srcY0,
3489 GLint srcX1,
3490 GLint srcY1,
3491 GLint dstX0,
3492 GLint dstY0,
3493 GLint dstX1,
3494 GLint dstY1,
3495 GLbitfield mask,
3496 GLenum filter)
3497{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003498 if (mask == 0)
3499 {
3500 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3501 // buffers are copied.
3502 return;
3503 }
3504
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003505 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003506 ASSERT(drawFramebuffer);
3507
3508 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3509 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3510
Jamie Madillbc918e72018-03-08 09:47:21 -05003511 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003512
Jamie Madill4f6592f2018-11-27 16:37:45 -05003513 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003514}
Jamie Madillc29968b2016-01-20 11:17:23 -05003515
3516void Context::clear(GLbitfield mask)
3517{
Geoff Langd4fff502017-09-22 11:28:28 -04003518 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003519 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003520}
3521
3522void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3523{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003524 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003525 const FramebufferAttachment *attachment = nullptr;
3526 if (buffer == GL_DEPTH)
3527 {
3528 attachment = framebufferObject->getDepthbuffer();
3529 }
3530 if (buffer == GL_COLOR &&
3531 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3532 {
3533 attachment = framebufferObject->getColorbuffer(drawbuffer);
3534 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003535 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3536 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003537 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003538 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003539 return;
3540 }
Geoff Langd4fff502017-09-22 11:28:28 -04003541 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003542 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
3545void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3546{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003547 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003548 const FramebufferAttachment *attachment = nullptr;
3549 if (buffer == GL_COLOR &&
3550 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3551 {
3552 attachment = framebufferObject->getColorbuffer(drawbuffer);
3553 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003554 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3555 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003556 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003557 {
3558 return;
3559 }
Geoff Langd4fff502017-09-22 11:28:28 -04003560 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003561 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003562}
3563
3564void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3565{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003566 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003567 const FramebufferAttachment *attachment = nullptr;
3568 if (buffer == GL_STENCIL)
3569 {
3570 attachment = framebufferObject->getStencilbuffer();
3571 }
3572 if (buffer == GL_COLOR &&
3573 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3574 {
3575 attachment = framebufferObject->getColorbuffer(drawbuffer);
3576 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003577 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3578 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003579 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003580 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003581 return;
3582 }
Geoff Langd4fff502017-09-22 11:28:28 -04003583 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003584 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003585}
3586
3587void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3588{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003589 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 ASSERT(framebufferObject);
3591
3592 // If a buffer is not present, the clear has no effect
3593 if (framebufferObject->getDepthbuffer() == nullptr &&
3594 framebufferObject->getStencilbuffer() == nullptr)
3595 {
3596 return;
3597 }
3598
Geoff Langd4fff502017-09-22 11:28:28 -04003599 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3600 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003601}
3602
3603void Context::readPixels(GLint x,
3604 GLint y,
3605 GLsizei width,
3606 GLsizei height,
3607 GLenum format,
3608 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003609 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003610{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003611 if (width == 0 || height == 0)
3612 {
3613 return;
3614 }
3615
Jamie Madillbc918e72018-03-08 09:47:21 -05003616 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003617
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003618 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003619 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003620
3621 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003622 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003623}
3624
Brandon Jones59770802018-04-02 13:18:42 -07003625void Context::readPixelsRobust(GLint x,
3626 GLint y,
3627 GLsizei width,
3628 GLsizei height,
3629 GLenum format,
3630 GLenum type,
3631 GLsizei bufSize,
3632 GLsizei *length,
3633 GLsizei *columns,
3634 GLsizei *rows,
3635 void *pixels)
3636{
3637 readPixels(x, y, width, height, format, type, pixels);
3638}
3639
3640void Context::readnPixelsRobust(GLint x,
3641 GLint y,
3642 GLsizei width,
3643 GLsizei height,
3644 GLenum format,
3645 GLenum type,
3646 GLsizei bufSize,
3647 GLsizei *length,
3648 GLsizei *columns,
3649 GLsizei *rows,
3650 void *data)
3651{
3652 readPixels(x, y, width, height, format, type, data);
3653}
3654
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003655void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 GLint level,
3657 GLenum internalformat,
3658 GLint x,
3659 GLint y,
3660 GLsizei width,
3661 GLsizei height,
3662 GLint border)
3663{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003664 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003665 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003666
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 Rectangle sourceArea(x, y, width, height);
3668
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003669 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003670 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003671 ANGLE_CONTEXT_TRY(
3672 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003673}
3674
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003675void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 GLint level,
3677 GLint xoffset,
3678 GLint yoffset,
3679 GLint x,
3680 GLint y,
3681 GLsizei width,
3682 GLsizei height)
3683{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003684 if (width == 0 || height == 0)
3685 {
3686 return;
3687 }
3688
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003689 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003690 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691
Jamie Madillc29968b2016-01-20 11:17:23 -05003692 Offset destOffset(xoffset, yoffset, 0);
3693 Rectangle sourceArea(x, y, width, height);
3694
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003695 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003696 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003697 ANGLE_CONTEXT_TRY(
3698 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003699}
3700
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003701void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 GLint level,
3703 GLint xoffset,
3704 GLint yoffset,
3705 GLint zoffset,
3706 GLint x,
3707 GLint y,
3708 GLsizei width,
3709 GLsizei height)
3710{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003711 if (width == 0 || height == 0)
3712 {
3713 return;
3714 }
3715
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003716 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003717 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003718
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 Offset destOffset(xoffset, yoffset, zoffset);
3720 Rectangle sourceArea(x, y, width, height);
3721
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003722 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003723 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003724 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3725 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003726}
3727
3728void Context::framebufferTexture2D(GLenum target,
3729 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003730 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003731 GLuint texture,
3732 GLint level)
3733{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003734 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 ASSERT(framebuffer);
3736
3737 if (texture != 0)
3738 {
3739 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003740 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003741 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003742 }
3743 else
3744 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003745 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003748 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003749}
3750
3751void Context::framebufferRenderbuffer(GLenum target,
3752 GLenum attachment,
3753 GLenum renderbuffertarget,
3754 GLuint renderbuffer)
3755{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003756 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 ASSERT(framebuffer);
3758
3759 if (renderbuffer != 0)
3760 {
3761 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003762
Jamie Madillcc129372018-04-12 09:13:18 -04003763 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003764 renderbufferObject);
3765 }
3766 else
3767 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003768 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003769 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003771 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003772}
3773
3774void Context::framebufferTextureLayer(GLenum target,
3775 GLenum attachment,
3776 GLuint texture,
3777 GLint level,
3778 GLint layer)
3779{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003780 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781 ASSERT(framebuffer);
3782
3783 if (texture != 0)
3784 {
3785 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003786 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003787 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 }
3789 else
3790 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003791 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003792 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003793
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003794 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003795}
3796
Brandon Jones59770802018-04-02 13:18:42 -07003797void Context::framebufferTextureMultiviewLayered(GLenum target,
3798 GLenum attachment,
3799 GLuint texture,
3800 GLint level,
3801 GLint baseViewIndex,
3802 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003803{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003804 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003805 ASSERT(framebuffer);
3806
3807 if (texture != 0)
3808 {
3809 Texture *textureObj = getTexture(texture);
3810
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003811 ImageIndex index;
3812 if (textureObj->getType() == TextureType::_2DArray)
3813 {
3814 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3815 }
3816 else
3817 {
3818 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3819 ASSERT(level == 0);
3820 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3821 }
Martin Radev82ef7742017-08-08 17:44:58 +03003822 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3823 numViews, baseViewIndex);
3824 }
3825 else
3826 {
3827 framebuffer->resetAttachment(this, attachment);
3828 }
3829
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003830 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003831}
3832
Brandon Jones59770802018-04-02 13:18:42 -07003833void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3834 GLenum attachment,
3835 GLuint texture,
3836 GLint level,
3837 GLsizei numViews,
3838 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003839{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003840 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003841 ASSERT(framebuffer);
3842
3843 if (texture != 0)
3844 {
3845 Texture *textureObj = getTexture(texture);
3846
3847 ImageIndex index = ImageIndex::Make2D(level);
3848 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3849 textureObj, numViews, viewportOffsets);
3850 }
3851 else
3852 {
3853 framebuffer->resetAttachment(this, attachment);
3854 }
3855
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003856 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003857}
3858
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003859void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3860{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003861 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003862 ASSERT(framebuffer);
3863
3864 if (texture != 0)
3865 {
3866 Texture *textureObj = getTexture(texture);
3867
3868 ImageIndex index = ImageIndex::MakeFromType(
3869 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3870 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3871 }
3872 else
3873 {
3874 framebuffer->resetAttachment(this, attachment);
3875 }
3876
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003877 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003878}
3879
Jamie Madillc29968b2016-01-20 11:17:23 -05003880void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3881{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003882 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003883 ASSERT(framebuffer);
3884 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003885 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003886 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003887}
3888
3889void Context::readBuffer(GLenum mode)
3890{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003891 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003892 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003893 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894}
3895
3896void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3897{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003898 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003899 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003900
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003901 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003902 ASSERT(framebuffer);
3903
3904 // The specification isn't clear what should be done when the framebuffer isn't complete.
3905 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003906 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003907}
3908
3909void Context::invalidateFramebuffer(GLenum target,
3910 GLsizei numAttachments,
3911 const GLenum *attachments)
3912{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003913 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003914 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003915
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003916 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003917 ASSERT(framebuffer);
3918
Jamie Madill427064d2018-04-13 16:20:34 -04003919 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003920 {
Jamie Madill437fa652016-05-03 15:13:24 -04003921 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003922 }
Jamie Madill437fa652016-05-03 15:13:24 -04003923
Jamie Madill4f6592f2018-11-27 16:37:45 -05003924 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003925}
3926
3927void Context::invalidateSubFramebuffer(GLenum target,
3928 GLsizei numAttachments,
3929 const GLenum *attachments,
3930 GLint x,
3931 GLint y,
3932 GLsizei width,
3933 GLsizei height)
3934{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003935 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003936 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003937
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003938 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003939 ASSERT(framebuffer);
3940
Jamie Madill427064d2018-04-13 16:20:34 -04003941 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003942 {
Jamie Madill437fa652016-05-03 15:13:24 -04003943 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003944 }
Jamie Madill437fa652016-05-03 15:13:24 -04003945
3946 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003947 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003948}
3949
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003950void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003951 GLint level,
3952 GLint internalformat,
3953 GLsizei width,
3954 GLsizei height,
3955 GLint border,
3956 GLenum format,
3957 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003958 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003959{
Jamie Madillbc918e72018-03-08 09:47:21 -05003960 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003961
3962 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003963 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003964 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003965 internalformat, size, format, type,
3966 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003967}
3968
Brandon Jones59770802018-04-02 13:18:42 -07003969void Context::texImage2DRobust(TextureTarget target,
3970 GLint level,
3971 GLint internalformat,
3972 GLsizei width,
3973 GLsizei height,
3974 GLint border,
3975 GLenum format,
3976 GLenum type,
3977 GLsizei bufSize,
3978 const void *pixels)
3979{
3980 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3981}
3982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003983void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003984 GLint level,
3985 GLint internalformat,
3986 GLsizei width,
3987 GLsizei height,
3988 GLsizei depth,
3989 GLint border,
3990 GLenum format,
3991 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003992 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003993{
Jamie Madillbc918e72018-03-08 09:47:21 -05003994 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003995
3996 Extents size(width, height, depth);
3997 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003998 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05003999 NonCubeTextureTypeToTarget(target), level, internalformat,
4000 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004001}
4002
Brandon Jones59770802018-04-02 13:18:42 -07004003void Context::texImage3DRobust(TextureType target,
4004 GLint level,
4005 GLint internalformat,
4006 GLsizei width,
4007 GLsizei height,
4008 GLsizei depth,
4009 GLint border,
4010 GLenum format,
4011 GLenum type,
4012 GLsizei bufSize,
4013 const void *pixels)
4014{
4015 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4016}
4017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004018void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004019 GLint level,
4020 GLint xoffset,
4021 GLint yoffset,
4022 GLsizei width,
4023 GLsizei height,
4024 GLenum format,
4025 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004026 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004027{
4028 // Zero sized uploads are valid but no-ops
4029 if (width == 0 || height == 0)
4030 {
4031 return;
4032 }
4033
Jamie Madillbc918e72018-03-08 09:47:21 -05004034 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004035
4036 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004037 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004038
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004039 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004040
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004041 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004042 level, area, format, type,
4043 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004044}
4045
Brandon Jones59770802018-04-02 13:18:42 -07004046void Context::texSubImage2DRobust(TextureTarget target,
4047 GLint level,
4048 GLint xoffset,
4049 GLint yoffset,
4050 GLsizei width,
4051 GLsizei height,
4052 GLenum format,
4053 GLenum type,
4054 GLsizei bufSize,
4055 const void *pixels)
4056{
4057 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4058}
4059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004060void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004061 GLint level,
4062 GLint xoffset,
4063 GLint yoffset,
4064 GLint zoffset,
4065 GLsizei width,
4066 GLsizei height,
4067 GLsizei depth,
4068 GLenum format,
4069 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004070 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004071{
4072 // Zero sized uploads are valid but no-ops
4073 if (width == 0 || height == 0 || depth == 0)
4074 {
4075 return;
4076 }
4077
Jamie Madillbc918e72018-03-08 09:47:21 -05004078 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004079
4080 Box area(xoffset, yoffset, zoffset, width, height, depth);
4081 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004082
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004083 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004084
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004085 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004086 NonCubeTextureTypeToTarget(target), level, area, format,
4087 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004088}
4089
Brandon Jones59770802018-04-02 13:18:42 -07004090void Context::texSubImage3DRobust(TextureType target,
4091 GLint level,
4092 GLint xoffset,
4093 GLint yoffset,
4094 GLint zoffset,
4095 GLsizei width,
4096 GLsizei height,
4097 GLsizei depth,
4098 GLenum format,
4099 GLenum type,
4100 GLsizei bufSize,
4101 const void *pixels)
4102{
4103 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4104 pixels);
4105}
4106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004107void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004108 GLint level,
4109 GLenum internalformat,
4110 GLsizei width,
4111 GLsizei height,
4112 GLint border,
4113 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004114 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004115{
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004117
4118 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004119 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004120 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004121 internalformat, size, imageSize,
4122 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004123}
4124
Brandon Jones59770802018-04-02 13:18:42 -07004125void Context::compressedTexImage2DRobust(TextureTarget target,
4126 GLint level,
4127 GLenum internalformat,
4128 GLsizei width,
4129 GLsizei height,
4130 GLint border,
4131 GLsizei imageSize,
4132 GLsizei dataSize,
4133 const GLvoid *data)
4134{
4135 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4136}
4137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004138void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004139 GLint level,
4140 GLenum internalformat,
4141 GLsizei width,
4142 GLsizei height,
4143 GLsizei depth,
4144 GLint border,
4145 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004146 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004147{
Jamie Madillbc918e72018-03-08 09:47:21 -05004148 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004149
4150 Extents size(width, height, depth);
4151 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004152 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004153 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004154 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004155}
4156
Brandon Jones59770802018-04-02 13:18:42 -07004157void Context::compressedTexImage3DRobust(TextureType target,
4158 GLint level,
4159 GLenum internalformat,
4160 GLsizei width,
4161 GLsizei height,
4162 GLsizei depth,
4163 GLint border,
4164 GLsizei imageSize,
4165 GLsizei dataSize,
4166 const GLvoid *data)
4167{
4168 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4169 data);
4170}
4171
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004172void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004173 GLint level,
4174 GLint xoffset,
4175 GLint yoffset,
4176 GLsizei width,
4177 GLsizei height,
4178 GLenum format,
4179 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004180 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004181{
Jamie Madillbc918e72018-03-08 09:47:21 -05004182 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004183
4184 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004185 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004186 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004187 area, format, imageSize,
4188 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004189}
4190
Brandon Jones59770802018-04-02 13:18:42 -07004191void Context::compressedTexSubImage2DRobust(TextureTarget target,
4192 GLint level,
4193 GLint xoffset,
4194 GLint yoffset,
4195 GLsizei width,
4196 GLsizei height,
4197 GLenum format,
4198 GLsizei imageSize,
4199 GLsizei dataSize,
4200 const GLvoid *data)
4201{
4202 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4203 data);
4204}
4205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004206void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004207 GLint level,
4208 GLint xoffset,
4209 GLint yoffset,
4210 GLint zoffset,
4211 GLsizei width,
4212 GLsizei height,
4213 GLsizei depth,
4214 GLenum format,
4215 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004216 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004217{
4218 // Zero sized uploads are valid but no-ops
4219 if (width == 0 || height == 0)
4220 {
4221 return;
4222 }
4223
Jamie Madillbc918e72018-03-08 09:47:21 -05004224 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004225
4226 Box area(xoffset, yoffset, zoffset, width, height, depth);
4227 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004228 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004229 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004230 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004231}
4232
Brandon Jones59770802018-04-02 13:18:42 -07004233void Context::compressedTexSubImage3DRobust(TextureType target,
4234 GLint level,
4235 GLint xoffset,
4236 GLint yoffset,
4237 GLint zoffset,
4238 GLsizei width,
4239 GLsizei height,
4240 GLsizei depth,
4241 GLenum format,
4242 GLsizei imageSize,
4243 GLsizei dataSize,
4244 const GLvoid *data)
4245{
4246 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4247 imageSize, data);
4248}
4249
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004250void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004251{
4252 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004253 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004254}
4255
Jamie Madill007530e2017-12-28 14:27:04 -05004256void Context::copyTexture(GLuint sourceId,
4257 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004258 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004259 GLuint destId,
4260 GLint destLevel,
4261 GLint internalFormat,
4262 GLenum destType,
4263 GLboolean unpackFlipY,
4264 GLboolean unpackPremultiplyAlpha,
4265 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004266{
Jamie Madillbc918e72018-03-08 09:47:21 -05004267 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004268
4269 gl::Texture *sourceTexture = getTexture(sourceId);
4270 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004271 ANGLE_CONTEXT_TRY(
4272 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4273 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4274 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004275}
4276
Jamie Madill007530e2017-12-28 14:27:04 -05004277void Context::copySubTexture(GLuint sourceId,
4278 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004279 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004280 GLuint destId,
4281 GLint destLevel,
4282 GLint xoffset,
4283 GLint yoffset,
4284 GLint x,
4285 GLint y,
4286 GLsizei width,
4287 GLsizei height,
4288 GLboolean unpackFlipY,
4289 GLboolean unpackPremultiplyAlpha,
4290 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004291{
4292 // Zero sized copies are valid but no-ops
4293 if (width == 0 || height == 0)
4294 {
4295 return;
4296 }
4297
Jamie Madillbc918e72018-03-08 09:47:21 -05004298 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004299
4300 gl::Texture *sourceTexture = getTexture(sourceId);
4301 gl::Texture *destTexture = getTexture(destId);
4302 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004303 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004304 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4305 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4306 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4307 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004308}
4309
4310void Context::copyTexture3D(GLuint sourceId,
4311 GLint sourceLevel,
4312 TextureTarget destTarget,
4313 GLuint destId,
4314 GLint destLevel,
4315 GLint internalFormat,
4316 GLenum destType,
4317 GLboolean unpackFlipY,
4318 GLboolean unpackPremultiplyAlpha,
4319 GLboolean unpackUnmultiplyAlpha)
4320{
4321 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4322
4323 Texture *sourceTexture = getTexture(sourceId);
4324 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004325 ANGLE_CONTEXT_TRY(
4326 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4327 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4328 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004329}
4330
4331void Context::copySubTexture3D(GLuint sourceId,
4332 GLint sourceLevel,
4333 TextureTarget destTarget,
4334 GLuint destId,
4335 GLint destLevel,
4336 GLint xoffset,
4337 GLint yoffset,
4338 GLint zoffset,
4339 GLint x,
4340 GLint y,
4341 GLint z,
4342 GLsizei width,
4343 GLsizei height,
4344 GLsizei depth,
4345 GLboolean unpackFlipY,
4346 GLboolean unpackPremultiplyAlpha,
4347 GLboolean unpackUnmultiplyAlpha)
4348{
4349 // Zero sized copies are valid but no-ops
4350 if (width == 0 || height == 0 || depth == 0)
4351 {
4352 return;
4353 }
4354
4355 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4356
4357 Texture *sourceTexture = getTexture(sourceId);
4358 Texture *destTexture = getTexture(destId);
4359 Offset offset(xoffset, yoffset, zoffset);
4360 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004361 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4362 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4363 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4364 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004365}
4366
Jamie Madill007530e2017-12-28 14:27:04 -05004367void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004368{
Jamie Madillbc918e72018-03-08 09:47:21 -05004369 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004370
4371 gl::Texture *sourceTexture = getTexture(sourceId);
4372 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004373 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004374}
4375
Corentin Wallez336129f2017-10-17 15:55:40 -04004376void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004377{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004378 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004379 ASSERT(buffer);
4380
Geoff Lang496c02d2016-10-20 11:38:11 -07004381 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004382}
4383
Brandon Jones59770802018-04-02 13:18:42 -07004384void Context::getBufferPointervRobust(BufferBinding target,
4385 GLenum pname,
4386 GLsizei bufSize,
4387 GLsizei *length,
4388 void **params)
4389{
4390 getBufferPointerv(target, pname, params);
4391}
4392
Corentin Wallez336129f2017-10-17 15:55:40 -04004393void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004394{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004395 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004396 ASSERT(buffer);
4397
Jamie Madill7c985f52018-11-29 18:16:17 -05004398 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004399 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004400 return nullptr;
4401 }
4402
4403 return buffer->getMapPointer();
4404}
4405
Corentin Wallez336129f2017-10-17 15:55:40 -04004406GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004407{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004408 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004409 ASSERT(buffer);
4410
4411 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004412 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004413 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004414 return GL_FALSE;
4415 }
4416
4417 return result;
4418}
4419
Corentin Wallez336129f2017-10-17 15:55:40 -04004420void *Context::mapBufferRange(BufferBinding target,
4421 GLintptr offset,
4422 GLsizeiptr length,
4423 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004424{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004425 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004426 ASSERT(buffer);
4427
Jamie Madill7c985f52018-11-29 18:16:17 -05004428 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004429 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004430 return nullptr;
4431 }
4432
4433 return buffer->getMapPointer();
4434}
4435
Corentin Wallez336129f2017-10-17 15:55:40 -04004436void Context::flushMappedBufferRange(BufferBinding /*target*/,
4437 GLintptr /*offset*/,
4438 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004439{
4440 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4441}
4442
Jamie Madill526392d2018-11-16 09:35:14 -05004443angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004444{
Geoff Langa8cb2872018-03-09 16:09:40 -05004445 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004446}
4447
Jamie Madill526392d2018-11-16 09:35:14 -05004448angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004449{
Geoff Langa8cb2872018-03-09 16:09:40 -05004450 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004451}
4452
Jamie Madill526392d2018-11-16 09:35:14 -05004453angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004454{
Geoff Langa8cb2872018-03-09 16:09:40 -05004455 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004456}
4457
Jamie Madill526392d2018-11-16 09:35:14 -05004458angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004459{
4460 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4461
4462 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4463 ANGLE_TRY(syncDirtyBits());
4464
Jamie Madill7c985f52018-11-29 18:16:17 -05004465 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004466}
4467
Jiajia Qin5451d532017-11-16 17:16:34 +08004468void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4469{
4470 UNIMPLEMENTED();
4471}
4472
Jamie Madillc20ab272016-06-09 07:20:46 -07004473void Context::activeTexture(GLenum texture)
4474{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004475 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476}
4477
Jamie Madill876429b2017-04-20 15:46:24 -04004478void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004479{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004480 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004483void Context::blendEquation(GLenum mode)
4484{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004485 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004486}
4487
Jamie Madillc20ab272016-06-09 07:20:46 -07004488void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4489{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004490 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004491}
4492
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004493void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4494{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004495 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004496}
4497
Jamie Madillc20ab272016-06-09 07:20:46 -07004498void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4499{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004500 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
Jamie Madill876429b2017-04-20 15:46:24 -04004503void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004504{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004505 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
Jamie Madill876429b2017-04-20 15:46:24 -04004508void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004509{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004510 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::clearStencil(GLint s)
4514{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004515 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
4518void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4519{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004520 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4521 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004524void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004525{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004526 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527}
4528
4529void Context::depthFunc(GLenum func)
4530{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004531 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532}
4533
4534void Context::depthMask(GLboolean flag)
4535{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004536 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
Jamie Madill876429b2017-04-20 15:46:24 -04004539void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004540{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004541 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::disable(GLenum cap)
4545{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004546 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004547 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
4550void Context::disableVertexAttribArray(GLuint index)
4551{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004552 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004553 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554}
4555
4556void Context::enable(GLenum cap)
4557{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004558 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004559 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560}
4561
4562void Context::enableVertexAttribArray(GLuint index)
4563{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004564 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004565 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566}
4567
4568void Context::frontFace(GLenum mode)
4569{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004570 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571}
4572
4573void Context::hint(GLenum target, GLenum mode)
4574{
4575 switch (target)
4576 {
4577 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004578 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579 break;
4580
4581 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004582 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004583 break;
4584
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004585 case GL_PERSPECTIVE_CORRECTION_HINT:
4586 case GL_POINT_SMOOTH_HINT:
4587 case GL_LINE_SMOOTH_HINT:
4588 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004589 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004590 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004591 default:
4592 UNREACHABLE();
4593 return;
4594 }
4595}
4596
4597void Context::lineWidth(GLfloat width)
4598{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004599 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
4602void Context::pixelStorei(GLenum pname, GLint param)
4603{
4604 switch (pname)
4605 {
4606 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004607 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608 break;
4609
4610 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004611 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612 break;
4613
4614 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004615 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616 break;
4617
4618 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004619 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004620 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621 break;
4622
4623 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004624 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004625 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626 break;
4627
4628 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004629 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004630 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631 break;
4632
4633 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004634 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004635 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636 break;
4637
4638 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004639 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004640 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004641 break;
4642
4643 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004644 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004645 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646 break;
4647
4648 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004649 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004650 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004651 break;
4652
4653 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004654 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004655 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656 break;
4657
4658 default:
4659 UNREACHABLE();
4660 return;
4661 }
4662}
4663
4664void Context::polygonOffset(GLfloat factor, GLfloat units)
4665{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004666 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
Jamie Madill876429b2017-04-20 15:46:24 -04004669void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004670{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004671 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004672}
4673
Jiawei Shaodb342272017-09-27 10:21:45 +08004674void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4675{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004676 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004677}
4678
Jamie Madillc20ab272016-06-09 07:20:46 -07004679void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4680{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004681 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4685{
4686 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4687 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004688 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004689 }
4690
4691 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4692 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004693 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004695
4696 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4700{
4701 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4702 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004703 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704 }
4705
4706 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4707 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004708 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004710
4711 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712}
4713
4714void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4715{
4716 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4717 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004718 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004719 }
4720
4721 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4722 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004723 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004724 }
4725}
4726
4727void Context::vertexAttrib1f(GLuint index, GLfloat x)
4728{
4729 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004730 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004731 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004732}
4733
4734void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4735{
4736 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004737 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004738 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004739}
4740
4741void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4742{
4743 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004744 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004745 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4749{
4750 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004751 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004752 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
4755void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4756{
4757 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004758 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004759 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004760}
4761
4762void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4763{
4764 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004765 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004766 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004767}
4768
4769void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4770{
4771 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004772 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004773 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004774}
4775
4776void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4777{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004778 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004779 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
4782void Context::vertexAttribPointer(GLuint index,
4783 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004784 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004785 GLboolean normalized,
4786 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004787 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004788{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004789 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
Jamie Madill6e18a232019-01-16 13:27:14 -05004790 type, ConvertToBool(normalized), stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004791 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004792}
4793
Shao80957d92017-02-20 21:25:59 +08004794void Context::vertexAttribFormat(GLuint attribIndex,
4795 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004796 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004797 GLboolean normalized,
4798 GLuint relativeOffset)
4799{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004800 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4801 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004802 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004803}
4804
4805void Context::vertexAttribIFormat(GLuint attribIndex,
4806 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004807 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004808 GLuint relativeOffset)
4809{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004810 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004811 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004812}
4813
4814void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4815{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004816 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004817 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004818}
4819
Jiajia Qin5451d532017-11-16 17:16:34 +08004820void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004821{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004822 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004823 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004824}
4825
Jamie Madillc20ab272016-06-09 07:20:46 -07004826void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4827{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004828 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004829}
4830
4831void Context::vertexAttribIPointer(GLuint index,
4832 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004833 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004834 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004835 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004836{
Jamie Madill6e18a232019-01-16 13:27:14 -05004837 mState.setVertexAttribIPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4838 type, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004839 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004840}
4841
4842void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4843{
4844 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004845 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004846 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004847}
4848
4849void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4850{
4851 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004852 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004853 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004854}
4855
4856void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4857{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004858 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004859 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004860}
4861
4862void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4863{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004864 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004865 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004866}
4867
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004868void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4869{
4870 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004871 getState().getVertexAttribCurrentValue(index);
4872 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004873 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4874 currentValues, pname, params);
4875}
4876
Brandon Jones59770802018-04-02 13:18:42 -07004877void Context::getVertexAttribivRobust(GLuint index,
4878 GLenum pname,
4879 GLsizei bufSize,
4880 GLsizei *length,
4881 GLint *params)
4882{
4883 getVertexAttribiv(index, pname, params);
4884}
4885
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004886void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4887{
4888 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004889 getState().getVertexAttribCurrentValue(index);
4890 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004891 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4892 currentValues, pname, params);
4893}
4894
Brandon Jones59770802018-04-02 13:18:42 -07004895void Context::getVertexAttribfvRobust(GLuint index,
4896 GLenum pname,
4897 GLsizei bufSize,
4898 GLsizei *length,
4899 GLfloat *params)
4900{
4901 getVertexAttribfv(index, pname, params);
4902}
4903
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004904void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4905{
4906 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004907 getState().getVertexAttribCurrentValue(index);
4908 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004909 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4910 currentValues, pname, params);
4911}
4912
Brandon Jones59770802018-04-02 13:18:42 -07004913void Context::getVertexAttribIivRobust(GLuint index,
4914 GLenum pname,
4915 GLsizei bufSize,
4916 GLsizei *length,
4917 GLint *params)
4918{
4919 getVertexAttribIiv(index, pname, params);
4920}
4921
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004922void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4923{
4924 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004925 getState().getVertexAttribCurrentValue(index);
4926 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004927 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4928 currentValues, pname, params);
4929}
4930
Brandon Jones59770802018-04-02 13:18:42 -07004931void Context::getVertexAttribIuivRobust(GLuint index,
4932 GLenum pname,
4933 GLsizei bufSize,
4934 GLsizei *length,
4935 GLuint *params)
4936{
4937 getVertexAttribIuiv(index, pname, params);
4938}
4939
Jamie Madill876429b2017-04-20 15:46:24 -04004940void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004941{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004942 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004943 QueryVertexAttribPointerv(attrib, pname, pointer);
4944}
4945
Brandon Jones59770802018-04-02 13:18:42 -07004946void Context::getVertexAttribPointervRobust(GLuint index,
4947 GLenum pname,
4948 GLsizei bufSize,
4949 GLsizei *length,
4950 void **pointer)
4951{
4952 getVertexAttribPointerv(index, pname, pointer);
4953}
4954
Jamie Madillc20ab272016-06-09 07:20:46 -07004955void Context::debugMessageControl(GLenum source,
4956 GLenum type,
4957 GLenum severity,
4958 GLsizei count,
4959 const GLuint *ids,
4960 GLboolean enabled)
4961{
4962 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004963 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4964 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004965}
4966
4967void Context::debugMessageInsert(GLenum source,
4968 GLenum type,
4969 GLuint id,
4970 GLenum severity,
4971 GLsizei length,
4972 const GLchar *buf)
4973{
4974 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004975 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004976}
4977
4978void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4979{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004980 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004981}
4982
4983GLuint Context::getDebugMessageLog(GLuint count,
4984 GLsizei bufSize,
4985 GLenum *sources,
4986 GLenum *types,
4987 GLuint *ids,
4988 GLenum *severities,
4989 GLsizei *lengths,
4990 GLchar *messageLog)
4991{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004992 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
4993 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004994}
4995
4996void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4997{
4998 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004999 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005000 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005001}
5002
5003void Context::popDebugGroup()
5004{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005005 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005006 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005007}
5008
Corentin Wallez336129f2017-10-17 15:55:40 -04005009void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005010{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005011 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005012 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005013 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005014}
5015
Corentin Wallez336129f2017-10-17 15:55:40 -04005016void Context::bufferSubData(BufferBinding target,
5017 GLintptr offset,
5018 GLsizeiptr size,
5019 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005020{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005021 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005022 {
5023 return;
5024 }
5025
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005026 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005027 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005028 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005029}
5030
Jamie Madillef300b12016-10-07 15:12:09 -04005031void Context::attachShader(GLuint program, GLuint shader)
5032{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005033 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5034 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005035 ASSERT(programObject && shaderObject);
5036 programObject->attachShader(shaderObject);
5037}
5038
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005039const Workarounds &Context::getWorkarounds() const
5040{
5041 return mWorkarounds;
5042}
5043
Corentin Wallez336129f2017-10-17 15:55:40 -04005044void Context::copyBufferSubData(BufferBinding readTarget,
5045 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005046 GLintptr readOffset,
5047 GLintptr writeOffset,
5048 GLsizeiptr size)
5049{
5050 // if size is zero, the copy is a successful no-op
5051 if (size == 0)
5052 {
5053 return;
5054 }
5055
5056 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005057 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5058 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005059
Jamie Madill4f6592f2018-11-27 16:37:45 -05005060 ANGLE_CONTEXT_TRY(
5061 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005062}
5063
Jamie Madill01a80ee2016-11-07 12:06:18 -05005064void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5065{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005066 // Ideally we could share the program query with the validation layer if possible.
5067 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005068 ASSERT(programObject);
5069 programObject->bindAttributeLocation(index, name);
5070}
5071
Corentin Wallez336129f2017-10-17 15:55:40 -04005072void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005073{
5074 bindBufferRange(target, index, buffer, 0, 0);
5075}
5076
Corentin Wallez336129f2017-10-17 15:55:40 -04005077void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005078 GLuint index,
5079 GLuint buffer,
5080 GLintptr offset,
5081 GLsizeiptr size)
5082{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005083 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5084 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005085 if (target == BufferBinding::Uniform)
5086 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005087 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005088 mStateCache.onUniformBufferStateChange(this);
5089 }
5090 else
5091 {
5092 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005093 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005094}
5095
Jamie Madill01a80ee2016-11-07 12:06:18 -05005096void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5097{
5098 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5099 {
5100 bindReadFramebuffer(framebuffer);
5101 }
5102
5103 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5104 {
5105 bindDrawFramebuffer(framebuffer);
5106 }
5107}
5108
5109void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5110{
5111 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005112 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5113 mImplementation.get(), renderbuffer);
5114 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005115}
5116
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005117void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005118 GLsizei samples,
5119 GLenum internalformat,
5120 GLsizei width,
5121 GLsizei height,
5122 GLboolean fixedsamplelocations)
5123{
5124 Extents size(width, height, 1);
5125 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005126 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5127 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005128}
5129
Olli Etuaho89664842018-08-24 14:45:36 +03005130void Context::texStorage3DMultisample(TextureType target,
5131 GLsizei samples,
5132 GLenum internalformat,
5133 GLsizei width,
5134 GLsizei height,
5135 GLsizei depth,
5136 GLboolean fixedsamplelocations)
5137{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005138 Extents size(width, height, depth);
5139 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005140 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5141 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005142}
5143
JiangYizhoubddc46b2016-12-09 09:50:51 +08005144void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5145{
JiangYizhou5b03f472017-01-09 10:22:53 +08005146 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5147 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005148 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5149 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005150
5151 switch (pname)
5152 {
5153 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005154 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005155 break;
5156 default:
5157 UNREACHABLE();
5158 }
5159}
5160
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005161void Context::getMultisamplefvRobust(GLenum pname,
5162 GLuint index,
5163 GLsizei bufSize,
5164 GLsizei *length,
5165 GLfloat *val)
5166{
5167 UNIMPLEMENTED();
5168}
5169
Jamie Madille8fb6402017-02-14 17:56:40 -05005170void Context::renderbufferStorage(GLenum target,
5171 GLenum internalformat,
5172 GLsizei width,
5173 GLsizei height)
5174{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005175 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5176 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5177
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005178 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005179 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005180}
5181
5182void Context::renderbufferStorageMultisample(GLenum target,
5183 GLsizei samples,
5184 GLenum internalformat,
5185 GLsizei width,
5186 GLsizei height)
5187{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005188 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5189 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005190
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005191 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005192 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005193 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005194}
5195
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005196void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5197{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005198 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005199 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005200}
5201
JiangYizhoue18e6392017-02-20 10:32:23 +08005202void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5203{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005204 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005205 QueryFramebufferParameteriv(framebuffer, pname, params);
5206}
5207
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005208void Context::getFramebufferParameterivRobust(GLenum target,
5209 GLenum pname,
5210 GLsizei bufSize,
5211 GLsizei *length,
5212 GLint *params)
5213{
5214 UNIMPLEMENTED();
5215}
5216
Jiajia Qin5451d532017-11-16 17:16:34 +08005217void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005218{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005219 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005220 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005221}
5222
Jamie Madilldec86232018-07-11 09:01:18 -04005223bool Context::getScratchBuffer(size_t requstedSizeBytes,
5224 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005225{
Jamie Madilldec86232018-07-11 09:01:18 -04005226 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005227}
5228
Jamie Madilldec86232018-07-11 09:01:18 -04005229bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5230 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005231{
Jamie Madilldec86232018-07-11 09:01:18 -04005232 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005233}
5234
Xinghua Cao2b396592017-03-29 15:36:04 +08005235void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5236{
5237 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5238 {
5239 return;
5240 }
5241
Xinghua Cao10a4d432017-11-28 14:46:26 +08005242 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005243 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005244}
5245
Jiajia Qin5451d532017-11-16 17:16:34 +08005246void Context::dispatchComputeIndirect(GLintptr indirect)
5247{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005248 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005249 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005250}
5251
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005252void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005253 GLsizei levels,
5254 GLenum internalFormat,
5255 GLsizei width,
5256 GLsizei height)
5257{
5258 Extents size(width, height, 1);
5259 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005260 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005261}
5262
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005263void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005264 GLsizei levels,
5265 GLenum internalFormat,
5266 GLsizei width,
5267 GLsizei height,
5268 GLsizei depth)
5269{
5270 Extents size(width, height, depth);
5271 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005272 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005273}
5274
Jiajia Qin5451d532017-11-16 17:16:34 +08005275void Context::memoryBarrier(GLbitfield barriers)
5276{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005277 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005278}
5279
5280void Context::memoryBarrierByRegion(GLbitfield barriers)
5281{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005282 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005283}
5284
Austin Eng1bf18ce2018-10-19 15:34:02 -07005285void Context::multiDrawArrays(PrimitiveMode mode,
5286 const GLint *firsts,
5287 const GLsizei *counts,
5288 GLsizei drawcount)
5289{
5290 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005291 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005292 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5293 if (hasDrawID)
5294 {
5295 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5296 {
5297 if (noopDraw(mode, counts[drawID]))
5298 {
5299 continue;
5300 }
5301 programObject->setDrawIDUniform(drawID);
5302 ANGLE_CONTEXT_TRY(
5303 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005304 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005305 }
5306 }
5307 else
5308 {
5309 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5310 {
5311 if (noopDraw(mode, counts[drawID]))
5312 {
5313 continue;
5314 }
5315 ANGLE_CONTEXT_TRY(
5316 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005317 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005318 }
5319 }
5320}
5321
5322void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5323 const GLint *firsts,
5324 const GLsizei *counts,
5325 const GLsizei *instanceCounts,
5326 GLsizei drawcount)
5327{
5328 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005329 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005330 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5331 if (hasDrawID)
5332 {
5333 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5334 {
5335 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5336 {
5337 continue;
5338 }
5339 programObject->setDrawIDUniform(drawID);
5340 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5341 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005342 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005343 }
5344 }
5345 else
5346 {
5347 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5348 {
5349 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5350 {
5351 continue;
5352 }
5353 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5354 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005355 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005356 }
5357 }
5358}
5359
5360void Context::multiDrawElements(PrimitiveMode mode,
5361 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005362 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005363 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005364 GLsizei drawcount)
5365{
5366 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005367 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005368 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5369 if (hasDrawID)
5370 {
5371 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5372 {
5373 if (noopDraw(mode, counts[drawID]))
5374 {
5375 continue;
5376 }
5377 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005378 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005379 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005380 }
5381 }
5382 else
5383 {
5384 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5385 {
5386 if (noopDraw(mode, counts[drawID]))
5387 {
5388 continue;
5389 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005390 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005391 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005392 }
5393 }
5394}
5395
5396void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5397 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005398 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005399 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005400 const GLsizei *instanceCounts,
5401 GLsizei drawcount)
5402{
5403 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005404 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005405 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5406 if (hasDrawID)
5407 {
5408 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5409 {
5410 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5411 {
5412 continue;
5413 }
5414 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005415 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005416 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005417 }
5418 }
5419 else
5420 {
5421 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5422 {
5423 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5424 {
5425 continue;
5426 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005427 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005428 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005429 }
5430 }
5431}
5432
Jeff Gilbert465d6092019-01-02 16:21:18 -08005433void Context::provokingVertex(ProvokingVertex provokeMode)
5434{
5435 mState.setProvokingVertex(provokeMode);
5436}
5437
Jamie Madillc1d770e2017-04-13 17:31:24 -04005438GLenum Context::checkFramebufferStatus(GLenum target)
5439{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005440 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005441 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005442 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443}
5444
5445void Context::compileShader(GLuint shader)
5446{
5447 Shader *shaderObject = GetValidShader(this, shader);
5448 if (!shaderObject)
5449 {
5450 return;
5451 }
5452 shaderObject->compile(this);
5453}
5454
5455void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5456{
5457 for (int i = 0; i < n; i++)
5458 {
5459 deleteBuffer(buffers[i]);
5460 }
5461}
5462
5463void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5464{
5465 for (int i = 0; i < n; i++)
5466 {
5467 if (framebuffers[i] != 0)
5468 {
5469 deleteFramebuffer(framebuffers[i]);
5470 }
5471 }
5472}
5473
5474void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5475{
5476 for (int i = 0; i < n; i++)
5477 {
5478 deleteRenderbuffer(renderbuffers[i]);
5479 }
5480}
5481
5482void Context::deleteTextures(GLsizei n, const GLuint *textures)
5483{
5484 for (int i = 0; i < n; i++)
5485 {
5486 if (textures[i] != 0)
5487 {
5488 deleteTexture(textures[i]);
5489 }
5490 }
5491}
5492
5493void Context::detachShader(GLuint program, GLuint shader)
5494{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005495 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496 ASSERT(programObject);
5497
5498 Shader *shaderObject = getShader(shader);
5499 ASSERT(shaderObject);
5500
5501 programObject->detachShader(this, shaderObject);
5502}
5503
5504void Context::genBuffers(GLsizei n, GLuint *buffers)
5505{
5506 for (int i = 0; i < n; i++)
5507 {
5508 buffers[i] = createBuffer();
5509 }
5510}
5511
5512void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5513{
5514 for (int i = 0; i < n; i++)
5515 {
5516 framebuffers[i] = createFramebuffer();
5517 }
5518}
5519
5520void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5521{
5522 for (int i = 0; i < n; i++)
5523 {
5524 renderbuffers[i] = createRenderbuffer();
5525 }
5526}
5527
5528void Context::genTextures(GLsizei n, GLuint *textures)
5529{
5530 for (int i = 0; i < n; i++)
5531 {
5532 textures[i] = createTexture();
5533 }
5534}
5535
5536void Context::getActiveAttrib(GLuint program,
5537 GLuint index,
5538 GLsizei bufsize,
5539 GLsizei *length,
5540 GLint *size,
5541 GLenum *type,
5542 GLchar *name)
5543{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005544 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005545 ASSERT(programObject);
5546 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5547}
5548
5549void Context::getActiveUniform(GLuint program,
5550 GLuint index,
5551 GLsizei bufsize,
5552 GLsizei *length,
5553 GLint *size,
5554 GLenum *type,
5555 GLchar *name)
5556{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005557 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005558 ASSERT(programObject);
5559 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5560}
5561
5562void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5563{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005564 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005565 ASSERT(programObject);
5566 programObject->getAttachedShaders(maxcount, count, shaders);
5567}
5568
5569GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5570{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005571 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572 ASSERT(programObject);
5573 return programObject->getAttributeLocation(name);
5574}
5575
5576void Context::getBooleanv(GLenum pname, GLboolean *params)
5577{
5578 GLenum nativeType;
5579 unsigned int numParams = 0;
5580 getQueryParameterInfo(pname, &nativeType, &numParams);
5581
5582 if (nativeType == GL_BOOL)
5583 {
5584 getBooleanvImpl(pname, params);
5585 }
5586 else
5587 {
5588 CastStateValues(this, nativeType, pname, numParams, params);
5589 }
5590}
5591
Brandon Jones59770802018-04-02 13:18:42 -07005592void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5593{
5594 getBooleanv(pname, params);
5595}
5596
Jamie Madillc1d770e2017-04-13 17:31:24 -04005597void Context::getFloatv(GLenum pname, GLfloat *params)
5598{
5599 GLenum nativeType;
5600 unsigned int numParams = 0;
5601 getQueryParameterInfo(pname, &nativeType, &numParams);
5602
5603 if (nativeType == GL_FLOAT)
5604 {
5605 getFloatvImpl(pname, params);
5606 }
5607 else
5608 {
5609 CastStateValues(this, nativeType, pname, numParams, params);
5610 }
5611}
5612
Brandon Jones59770802018-04-02 13:18:42 -07005613void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5614{
5615 getFloatv(pname, params);
5616}
5617
Jamie Madillc1d770e2017-04-13 17:31:24 -04005618void Context::getIntegerv(GLenum pname, GLint *params)
5619{
5620 GLenum nativeType;
5621 unsigned int numParams = 0;
5622 getQueryParameterInfo(pname, &nativeType, &numParams);
5623
5624 if (nativeType == GL_INT)
5625 {
5626 getIntegervImpl(pname, params);
5627 }
5628 else
5629 {
5630 CastStateValues(this, nativeType, pname, numParams, params);
5631 }
5632}
5633
Brandon Jones59770802018-04-02 13:18:42 -07005634void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5635{
5636 getIntegerv(pname, data);
5637}
5638
Jamie Madillc1d770e2017-04-13 17:31:24 -04005639void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5640{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005641 // Don't resolve link if checking the link completion status.
5642 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5643 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005644 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005645 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005646}
5647
Brandon Jones59770802018-04-02 13:18:42 -07005648void Context::getProgramivRobust(GLuint program,
5649 GLenum pname,
5650 GLsizei bufSize,
5651 GLsizei *length,
5652 GLint *params)
5653{
5654 getProgramiv(program, pname, params);
5655}
5656
Jiajia Qin5451d532017-11-16 17:16:34 +08005657void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5658{
5659 UNIMPLEMENTED();
5660}
5661
Jamie Madillbe849e42017-05-02 15:49:00 -04005662void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005663{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005664 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005665 ASSERT(programObject);
5666 programObject->getInfoLog(bufsize, length, infolog);
5667}
5668
Jiajia Qin5451d532017-11-16 17:16:34 +08005669void Context::getProgramPipelineInfoLog(GLuint pipeline,
5670 GLsizei bufSize,
5671 GLsizei *length,
5672 GLchar *infoLog)
5673{
5674 UNIMPLEMENTED();
5675}
5676
Jamie Madillc1d770e2017-04-13 17:31:24 -04005677void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5678{
5679 Shader *shaderObject = getShader(shader);
5680 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005681 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005682}
5683
Brandon Jones59770802018-04-02 13:18:42 -07005684void Context::getShaderivRobust(GLuint shader,
5685 GLenum pname,
5686 GLsizei bufSize,
5687 GLsizei *length,
5688 GLint *params)
5689{
5690 getShaderiv(shader, pname, params);
5691}
5692
Jamie Madillc1d770e2017-04-13 17:31:24 -04005693void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5694{
5695 Shader *shaderObject = getShader(shader);
5696 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005697 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005698}
5699
5700void Context::getShaderPrecisionFormat(GLenum shadertype,
5701 GLenum precisiontype,
5702 GLint *range,
5703 GLint *precision)
5704{
5705 // TODO(jmadill): Compute shaders.
5706
5707 switch (shadertype)
5708 {
5709 case GL_VERTEX_SHADER:
5710 switch (precisiontype)
5711 {
5712 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005713 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005714 break;
5715 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005716 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717 break;
5718 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005719 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005720 break;
5721
5722 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005723 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724 break;
5725 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005726 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727 break;
5728 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005729 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005730 break;
5731
5732 default:
5733 UNREACHABLE();
5734 return;
5735 }
5736 break;
5737
5738 case GL_FRAGMENT_SHADER:
5739 switch (precisiontype)
5740 {
5741 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005742 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 break;
5744 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005745 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005746 break;
5747 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005748 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005749 break;
5750
5751 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005752 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005753 break;
5754 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005755 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756 break;
5757 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005758 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005759 break;
5760
5761 default:
5762 UNREACHABLE();
5763 return;
5764 }
5765 break;
5766
5767 default:
5768 UNREACHABLE();
5769 return;
5770 }
5771}
5772
5773void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5774{
5775 Shader *shaderObject = getShader(shader);
5776 ASSERT(shaderObject);
5777 shaderObject->getSource(bufsize, length, source);
5778}
5779
5780void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5781{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005782 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005783 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005784 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005785}
5786
Brandon Jones59770802018-04-02 13:18:42 -07005787void Context::getUniformfvRobust(GLuint program,
5788 GLint location,
5789 GLsizei bufSize,
5790 GLsizei *length,
5791 GLfloat *params)
5792{
5793 getUniformfv(program, location, params);
5794}
5795
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5797{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005798 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005799 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005800 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005801}
5802
Brandon Jones59770802018-04-02 13:18:42 -07005803void Context::getUniformivRobust(GLuint program,
5804 GLint location,
5805 GLsizei bufSize,
5806 GLsizei *length,
5807 GLint *params)
5808{
5809 getUniformiv(program, location, params);
5810}
5811
Jamie Madillc1d770e2017-04-13 17:31:24 -04005812GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5813{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005814 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005815 ASSERT(programObject);
5816 return programObject->getUniformLocation(name);
5817}
5818
5819GLboolean Context::isBuffer(GLuint buffer)
5820{
5821 if (buffer == 0)
5822 {
5823 return GL_FALSE;
5824 }
5825
5826 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5827}
5828
5829GLboolean Context::isEnabled(GLenum cap)
5830{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005831 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005832}
5833
5834GLboolean Context::isFramebuffer(GLuint framebuffer)
5835{
5836 if (framebuffer == 0)
5837 {
5838 return GL_FALSE;
5839 }
5840
5841 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5842}
5843
5844GLboolean Context::isProgram(GLuint program)
5845{
5846 if (program == 0)
5847 {
5848 return GL_FALSE;
5849 }
5850
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005851 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005852}
5853
5854GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5855{
5856 if (renderbuffer == 0)
5857 {
5858 return GL_FALSE;
5859 }
5860
5861 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5862}
5863
5864GLboolean Context::isShader(GLuint shader)
5865{
5866 if (shader == 0)
5867 {
5868 return GL_FALSE;
5869 }
5870
5871 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5872}
5873
5874GLboolean Context::isTexture(GLuint texture)
5875{
5876 if (texture == 0)
5877 {
5878 return GL_FALSE;
5879 }
5880
5881 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5882}
5883
5884void Context::linkProgram(GLuint program)
5885{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005886 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005887 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005888 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005889
5890 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5891 // don't need to worry that:
5892 // 1. Draw calls after link use the new executable code or the old one depending on the link
5893 // result.
5894 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5895 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5896 // ProgramD3D.
5897 if (programObject->isInUse())
5898 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005899 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005900 if (programObject->isLinked())
5901 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005902 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005903 }
jchen107ae70d82018-07-06 13:47:01 +08005904 mStateCache.onProgramExecutableChange(this);
5905 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005906}
5907
5908void Context::releaseShaderCompiler()
5909{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005910 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005911}
5912
5913void Context::shaderBinary(GLsizei n,
5914 const GLuint *shaders,
5915 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005916 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917 GLsizei length)
5918{
5919 // No binary shader formats are supported.
5920 UNIMPLEMENTED();
5921}
5922
Olli Etuaho0ca09752018-09-24 11:00:50 +03005923void Context::bindFragDataLocationIndexed(GLuint program,
5924 GLuint colorNumber,
5925 GLuint index,
5926 const char *name)
5927{
5928 Program *programObject = getProgramNoResolveLink(program);
5929 programObject->bindFragmentOutputLocation(colorNumber, name);
5930 programObject->bindFragmentOutputIndex(index, name);
5931}
5932
5933void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5934{
5935 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5936}
5937
5938int Context::getFragDataIndex(GLuint program, const char *name)
5939{
5940 Program *programObject = getProgramResolveLink(program);
5941 return programObject->getFragDataIndex(name);
5942}
5943
5944int Context::getProgramResourceLocationIndex(GLuint program,
5945 GLenum programInterface,
5946 const char *name)
5947{
5948 Program *programObject = getProgramResolveLink(program);
5949 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5950 return programObject->getFragDataIndex(name);
5951}
5952
Jamie Madillc1d770e2017-04-13 17:31:24 -04005953void Context::shaderSource(GLuint shader,
5954 GLsizei count,
5955 const GLchar *const *string,
5956 const GLint *length)
5957{
5958 Shader *shaderObject = getShader(shader);
5959 ASSERT(shaderObject);
5960 shaderObject->setSource(count, string, length);
5961}
5962
5963void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5964{
5965 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5966}
5967
5968void Context::stencilMask(GLuint mask)
5969{
5970 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5971}
5972
5973void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5974{
5975 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5976}
5977
5978void Context::uniform1f(GLint location, GLfloat x)
5979{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005980 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005981 program->setUniform1fv(location, 1, &x);
5982}
5983
5984void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5985{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005986 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005987 program->setUniform1fv(location, count, v);
5988}
5989
Jamie Madill7e4eff12018-08-08 15:49:26 -04005990void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005991{
Jamie Madille3e680c2018-12-03 17:49:08 -05005992 program->setUniform1iv(this, location, count, v);
5993}
5994
5995void Context::onSamplerUniformChange(size_t textureUnitIndex)
5996{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005997 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05005998 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005999}
6000
Jamie Madill7e4eff12018-08-08 15:49:26 -04006001void Context::uniform1i(GLint location, GLint x)
6002{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006003 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006004}
6005
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6007{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006008 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006009}
6010
6011void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6012{
6013 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006014 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006015 program->setUniform2fv(location, 1, xy);
6016}
6017
6018void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6019{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006020 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006021 program->setUniform2fv(location, count, v);
6022}
6023
6024void Context::uniform2i(GLint location, GLint x, GLint y)
6025{
6026 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006027 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006028 program->setUniform2iv(location, 1, xy);
6029}
6030
6031void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6032{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006033 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006034 program->setUniform2iv(location, count, v);
6035}
6036
6037void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6038{
6039 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006040 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006041 program->setUniform3fv(location, 1, xyz);
6042}
6043
6044void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6045{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006046 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006047 program->setUniform3fv(location, count, v);
6048}
6049
6050void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6051{
6052 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006053 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006054 program->setUniform3iv(location, 1, xyz);
6055}
6056
6057void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6058{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006059 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006060 program->setUniform3iv(location, count, v);
6061}
6062
6063void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6064{
6065 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006066 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006067 program->setUniform4fv(location, 1, xyzw);
6068}
6069
6070void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6071{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006072 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006073 program->setUniform4fv(location, count, v);
6074}
6075
6076void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6077{
6078 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006079 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006080 program->setUniform4iv(location, 1, xyzw);
6081}
6082
6083void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6084{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006085 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006086 program->setUniform4iv(location, count, v);
6087}
6088
6089void Context::uniformMatrix2fv(GLint location,
6090 GLsizei count,
6091 GLboolean transpose,
6092 const GLfloat *value)
6093{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006094 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006095 program->setUniformMatrix2fv(location, count, transpose, value);
6096}
6097
6098void Context::uniformMatrix3fv(GLint location,
6099 GLsizei count,
6100 GLboolean transpose,
6101 const GLfloat *value)
6102{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006103 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104 program->setUniformMatrix3fv(location, count, transpose, value);
6105}
6106
6107void Context::uniformMatrix4fv(GLint location,
6108 GLsizei count,
6109 GLboolean transpose,
6110 const GLfloat *value)
6111{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006112 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006113 program->setUniformMatrix4fv(location, count, transpose, value);
6114}
6115
6116void Context::validateProgram(GLuint program)
6117{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006118 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006119 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006120 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006121}
6122
Jiajia Qin5451d532017-11-16 17:16:34 +08006123void Context::validateProgramPipeline(GLuint pipeline)
6124{
6125 UNIMPLEMENTED();
6126}
6127
Jamie Madilld04908b2017-06-09 14:15:35 -04006128void Context::getProgramBinary(GLuint program,
6129 GLsizei bufSize,
6130 GLsizei *length,
6131 GLenum *binaryFormat,
6132 void *binary)
6133{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006134 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006135 ASSERT(programObject != nullptr);
6136
Jamie Madill4f6592f2018-11-27 16:37:45 -05006137 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006138}
6139
6140void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6141{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006142 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006143 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006144
Jamie Madill4f6592f2018-11-27 16:37:45 -05006145 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006146 if (programObject->isInUse())
6147 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006148 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006149 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006150 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006151}
6152
Jamie Madillff325f12017-08-26 15:06:05 -04006153void Context::uniform1ui(GLint location, GLuint v0)
6154{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006155 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006156 program->setUniform1uiv(location, 1, &v0);
6157}
6158
6159void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6160{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006161 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006162 const GLuint xy[] = {v0, v1};
6163 program->setUniform2uiv(location, 1, xy);
6164}
6165
6166void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6167{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006168 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006169 const GLuint xyz[] = {v0, v1, v2};
6170 program->setUniform3uiv(location, 1, xyz);
6171}
6172
6173void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6174{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006175 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006176 const GLuint xyzw[] = {v0, v1, v2, v3};
6177 program->setUniform4uiv(location, 1, xyzw);
6178}
6179
6180void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6181{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006182 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006183 program->setUniform1uiv(location, count, value);
6184}
6185void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6186{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006187 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006188 program->setUniform2uiv(location, count, value);
6189}
6190
6191void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6192{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006193 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006194 program->setUniform3uiv(location, count, value);
6195}
6196
6197void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6198{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006199 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006200 program->setUniform4uiv(location, count, value);
6201}
6202
Jamie Madillf0e04492017-08-26 15:28:42 -04006203void Context::genQueries(GLsizei n, GLuint *ids)
6204{
6205 for (GLsizei i = 0; i < n; i++)
6206 {
6207 GLuint handle = mQueryHandleAllocator.allocate();
6208 mQueryMap.assign(handle, nullptr);
6209 ids[i] = handle;
6210 }
6211}
6212
6213void Context::deleteQueries(GLsizei n, const GLuint *ids)
6214{
6215 for (int i = 0; i < n; i++)
6216 {
6217 GLuint query = ids[i];
6218
6219 Query *queryObject = nullptr;
6220 if (mQueryMap.erase(query, &queryObject))
6221 {
6222 mQueryHandleAllocator.release(query);
6223 if (queryObject)
6224 {
6225 queryObject->release(this);
6226 }
6227 }
6228 }
6229}
6230
6231GLboolean Context::isQuery(GLuint id)
6232{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006233 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006234}
6235
Jamie Madillc8c95812017-08-26 18:40:09 -04006236void Context::uniformMatrix2x3fv(GLint location,
6237 GLsizei count,
6238 GLboolean transpose,
6239 const GLfloat *value)
6240{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006241 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006242 program->setUniformMatrix2x3fv(location, count, transpose, value);
6243}
6244
6245void Context::uniformMatrix3x2fv(GLint location,
6246 GLsizei count,
6247 GLboolean transpose,
6248 const GLfloat *value)
6249{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006250 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006251 program->setUniformMatrix3x2fv(location, count, transpose, value);
6252}
6253
6254void Context::uniformMatrix2x4fv(GLint location,
6255 GLsizei count,
6256 GLboolean transpose,
6257 const GLfloat *value)
6258{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006259 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006260 program->setUniformMatrix2x4fv(location, count, transpose, value);
6261}
6262
6263void Context::uniformMatrix4x2fv(GLint location,
6264 GLsizei count,
6265 GLboolean transpose,
6266 const GLfloat *value)
6267{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006268 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006269 program->setUniformMatrix4x2fv(location, count, transpose, value);
6270}
6271
6272void Context::uniformMatrix3x4fv(GLint location,
6273 GLsizei count,
6274 GLboolean transpose,
6275 const GLfloat *value)
6276{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006277 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006278 program->setUniformMatrix3x4fv(location, count, transpose, value);
6279}
6280
6281void Context::uniformMatrix4x3fv(GLint location,
6282 GLsizei count,
6283 GLboolean transpose,
6284 const GLfloat *value)
6285{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006286 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006287 program->setUniformMatrix4x3fv(location, count, transpose, value);
6288}
6289
Jamie Madilld7576732017-08-26 18:49:50 -04006290void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6291{
6292 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6293 {
6294 GLuint vertexArray = arrays[arrayIndex];
6295
6296 if (arrays[arrayIndex] != 0)
6297 {
6298 VertexArray *vertexArrayObject = nullptr;
6299 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6300 {
6301 if (vertexArrayObject != nullptr)
6302 {
6303 detachVertexArray(vertexArray);
6304 vertexArrayObject->onDestroy(this);
6305 }
6306
6307 mVertexArrayHandleAllocator.release(vertexArray);
6308 }
6309 }
6310 }
6311}
6312
6313void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6314{
6315 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6316 {
6317 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6318 mVertexArrayMap.assign(vertexArray, nullptr);
6319 arrays[arrayIndex] = vertexArray;
6320 }
6321}
6322
6323bool Context::isVertexArray(GLuint array)
6324{
6325 if (array == 0)
6326 {
6327 return GL_FALSE;
6328 }
6329
6330 VertexArray *vao = getVertexArray(array);
6331 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6332}
6333
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006334void Context::endTransformFeedback()
6335{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006336 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006337 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006338 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006339}
6340
6341void Context::transformFeedbackVaryings(GLuint program,
6342 GLsizei count,
6343 const GLchar *const *varyings,
6344 GLenum bufferMode)
6345{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006346 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006347 ASSERT(programObject);
6348 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6349}
6350
6351void Context::getTransformFeedbackVarying(GLuint program,
6352 GLuint index,
6353 GLsizei bufSize,
6354 GLsizei *length,
6355 GLsizei *size,
6356 GLenum *type,
6357 GLchar *name)
6358{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006359 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006360 ASSERT(programObject);
6361 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6362}
6363
6364void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6365{
6366 for (int i = 0; i < n; i++)
6367 {
6368 GLuint transformFeedback = ids[i];
6369 if (transformFeedback == 0)
6370 {
6371 continue;
6372 }
6373
6374 TransformFeedback *transformFeedbackObject = nullptr;
6375 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6376 {
6377 if (transformFeedbackObject != nullptr)
6378 {
6379 detachTransformFeedback(transformFeedback);
6380 transformFeedbackObject->release(this);
6381 }
6382
6383 mTransformFeedbackHandleAllocator.release(transformFeedback);
6384 }
6385 }
6386}
6387
6388void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6389{
6390 for (int i = 0; i < n; i++)
6391 {
6392 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6393 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6394 ids[i] = transformFeedback;
6395 }
6396}
6397
6398bool Context::isTransformFeedback(GLuint id)
6399{
6400 if (id == 0)
6401 {
6402 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6403 // returns FALSE
6404 return GL_FALSE;
6405 }
6406
6407 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6408 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6409}
6410
6411void Context::pauseTransformFeedback()
6412{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006413 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006414 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006415 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006416}
6417
6418void Context::resumeTransformFeedback()
6419{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006420 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006421 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006422 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006423}
6424
Jamie Madill12e957f2017-08-26 21:42:26 -04006425void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6426{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006427 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006428 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006429}
6430
Brandon Jones59770802018-04-02 13:18:42 -07006431void Context::getUniformuivRobust(GLuint program,
6432 GLint location,
6433 GLsizei bufSize,
6434 GLsizei *length,
6435 GLuint *params)
6436{
6437 getUniformuiv(program, location, params);
6438}
6439
Jamie Madill12e957f2017-08-26 21:42:26 -04006440GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6441{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006442 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006443 return programObject->getFragDataLocation(name);
6444}
6445
6446void Context::getUniformIndices(GLuint program,
6447 GLsizei uniformCount,
6448 const GLchar *const *uniformNames,
6449 GLuint *uniformIndices)
6450{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006451 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006452 if (!programObject->isLinked())
6453 {
6454 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6455 {
6456 uniformIndices[uniformId] = GL_INVALID_INDEX;
6457 }
6458 }
6459 else
6460 {
6461 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6462 {
6463 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6464 }
6465 }
6466}
6467
6468void Context::getActiveUniformsiv(GLuint program,
6469 GLsizei uniformCount,
6470 const GLuint *uniformIndices,
6471 GLenum pname,
6472 GLint *params)
6473{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006474 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006475 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6476 {
6477 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006478 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006479 }
6480}
6481
6482GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6483{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006484 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006485 return programObject->getUniformBlockIndex(uniformBlockName);
6486}
6487
6488void Context::getActiveUniformBlockiv(GLuint program,
6489 GLuint uniformBlockIndex,
6490 GLenum pname,
6491 GLint *params)
6492{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006493 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006494 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6495}
6496
Brandon Jones59770802018-04-02 13:18:42 -07006497void Context::getActiveUniformBlockivRobust(GLuint program,
6498 GLuint uniformBlockIndex,
6499 GLenum pname,
6500 GLsizei bufSize,
6501 GLsizei *length,
6502 GLint *params)
6503{
6504 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6505}
6506
Jamie Madill12e957f2017-08-26 21:42:26 -04006507void Context::getActiveUniformBlockName(GLuint program,
6508 GLuint uniformBlockIndex,
6509 GLsizei bufSize,
6510 GLsizei *length,
6511 GLchar *uniformBlockName)
6512{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006513 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006514 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6515}
6516
6517void Context::uniformBlockBinding(GLuint program,
6518 GLuint uniformBlockIndex,
6519 GLuint uniformBlockBinding)
6520{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006521 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006522 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006523
Jamie Madill956ab4d2018-10-10 16:13:03 -04006524 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006525 if (programObject->isInUse())
6526 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006527 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006528 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006529 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006530}
6531
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006532GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6533{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006534 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006535 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006536
Jamie Madill70b5bb02017-08-28 13:32:37 -04006537 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006538 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006539 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006540 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006541 return nullptr;
6542 }
6543
Jamie Madill70b5bb02017-08-28 13:32:37 -04006544 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006545}
6546
6547GLboolean Context::isSync(GLsync sync)
6548{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006549 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006550}
6551
6552GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6553{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006554 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006555
6556 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006557 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006558 {
6559 return GL_WAIT_FAILED;
6560 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006561 return result;
6562}
6563
6564void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6565{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006566 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006567 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006568}
6569
6570void Context::getInteger64v(GLenum pname, GLint64 *params)
6571{
6572 GLenum nativeType = GL_NONE;
6573 unsigned int numParams = 0;
6574 getQueryParameterInfo(pname, &nativeType, &numParams);
6575
6576 if (nativeType == GL_INT_64_ANGLEX)
6577 {
6578 getInteger64vImpl(pname, params);
6579 }
6580 else
6581 {
6582 CastStateValues(this, nativeType, pname, numParams, params);
6583 }
6584}
6585
Brandon Jones59770802018-04-02 13:18:42 -07006586void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6587{
6588 getInteger64v(pname, data);
6589}
6590
Corentin Wallez336129f2017-10-17 15:55:40 -04006591void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006592{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006593 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006594 QueryBufferParameteri64v(buffer, pname, params);
6595}
6596
Brandon Jones59770802018-04-02 13:18:42 -07006597void Context::getBufferParameteri64vRobust(BufferBinding target,
6598 GLenum pname,
6599 GLsizei bufSize,
6600 GLsizei *length,
6601 GLint64 *params)
6602{
6603 getBufferParameteri64v(target, pname, params);
6604}
6605
Jamie Madill3ef140a2017-08-26 23:11:21 -04006606void Context::genSamplers(GLsizei count, GLuint *samplers)
6607{
6608 for (int i = 0; i < count; i++)
6609 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006610 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006611 }
6612}
6613
6614void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6615{
6616 for (int i = 0; i < count; i++)
6617 {
6618 GLuint sampler = samplers[i];
6619
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006620 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006621 {
6622 detachSampler(sampler);
6623 }
6624
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006625 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006626 }
6627}
6628
6629void Context::getInternalformativ(GLenum target,
6630 GLenum internalformat,
6631 GLenum pname,
6632 GLsizei bufSize,
6633 GLint *params)
6634{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006635 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006636 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6637}
6638
Brandon Jones59770802018-04-02 13:18:42 -07006639void Context::getInternalformativRobust(GLenum target,
6640 GLenum internalformat,
6641 GLenum pname,
6642 GLsizei bufSize,
6643 GLsizei *length,
6644 GLint *params)
6645{
6646 getInternalformativ(target, internalformat, pname, bufSize, params);
6647}
6648
Jiajia Qin5451d532017-11-16 17:16:34 +08006649void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6650{
6651 programUniform1iv(program, location, 1, &v0);
6652}
6653
6654void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6655{
6656 GLint xy[2] = {v0, v1};
6657 programUniform2iv(program, location, 1, xy);
6658}
6659
6660void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6661{
6662 GLint xyz[3] = {v0, v1, v2};
6663 programUniform3iv(program, location, 1, xyz);
6664}
6665
6666void Context::programUniform4i(GLuint program,
6667 GLint location,
6668 GLint v0,
6669 GLint v1,
6670 GLint v2,
6671 GLint v3)
6672{
6673 GLint xyzw[4] = {v0, v1, v2, v3};
6674 programUniform4iv(program, location, 1, xyzw);
6675}
6676
6677void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6678{
6679 programUniform1uiv(program, location, 1, &v0);
6680}
6681
6682void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6683{
6684 GLuint xy[2] = {v0, v1};
6685 programUniform2uiv(program, location, 1, xy);
6686}
6687
6688void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6689{
6690 GLuint xyz[3] = {v0, v1, v2};
6691 programUniform3uiv(program, location, 1, xyz);
6692}
6693
6694void Context::programUniform4ui(GLuint program,
6695 GLint location,
6696 GLuint v0,
6697 GLuint v1,
6698 GLuint v2,
6699 GLuint v3)
6700{
6701 GLuint xyzw[4] = {v0, v1, v2, v3};
6702 programUniform4uiv(program, location, 1, xyzw);
6703}
6704
6705void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6706{
6707 programUniform1fv(program, location, 1, &v0);
6708}
6709
6710void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6711{
6712 GLfloat xy[2] = {v0, v1};
6713 programUniform2fv(program, location, 1, xy);
6714}
6715
6716void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6717{
6718 GLfloat xyz[3] = {v0, v1, v2};
6719 programUniform3fv(program, location, 1, xyz);
6720}
6721
6722void Context::programUniform4f(GLuint program,
6723 GLint location,
6724 GLfloat v0,
6725 GLfloat v1,
6726 GLfloat v2,
6727 GLfloat v3)
6728{
6729 GLfloat xyzw[4] = {v0, v1, v2, v3};
6730 programUniform4fv(program, location, 1, xyzw);
6731}
6732
Jamie Madill81c2e252017-09-09 23:32:46 -04006733void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6734{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006735 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006736 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006737 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006738}
6739
Jiajia Qin5451d532017-11-16 17:16:34 +08006740void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6741{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006742 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006743 ASSERT(programObject);
6744 programObject->setUniform2iv(location, count, value);
6745}
6746
6747void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6748{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006749 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006750 ASSERT(programObject);
6751 programObject->setUniform3iv(location, count, value);
6752}
6753
6754void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6755{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006756 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006757 ASSERT(programObject);
6758 programObject->setUniform4iv(location, count, value);
6759}
6760
6761void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6762{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006763 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006764 ASSERT(programObject);
6765 programObject->setUniform1uiv(location, count, value);
6766}
6767
6768void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6769{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006770 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006771 ASSERT(programObject);
6772 programObject->setUniform2uiv(location, count, value);
6773}
6774
6775void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6776{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006777 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006778 ASSERT(programObject);
6779 programObject->setUniform3uiv(location, count, value);
6780}
6781
6782void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6783{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006784 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006785 ASSERT(programObject);
6786 programObject->setUniform4uiv(location, count, value);
6787}
6788
6789void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6790{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006791 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006792 ASSERT(programObject);
6793 programObject->setUniform1fv(location, count, value);
6794}
6795
6796void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6797{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006798 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006799 ASSERT(programObject);
6800 programObject->setUniform2fv(location, count, value);
6801}
6802
6803void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6804{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006805 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006806 ASSERT(programObject);
6807 programObject->setUniform3fv(location, count, value);
6808}
6809
6810void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6811{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006812 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006813 ASSERT(programObject);
6814 programObject->setUniform4fv(location, count, value);
6815}
6816
6817void Context::programUniformMatrix2fv(GLuint program,
6818 GLint location,
6819 GLsizei count,
6820 GLboolean transpose,
6821 const GLfloat *value)
6822{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006823 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006824 ASSERT(programObject);
6825 programObject->setUniformMatrix2fv(location, count, transpose, value);
6826}
6827
6828void Context::programUniformMatrix3fv(GLuint program,
6829 GLint location,
6830 GLsizei count,
6831 GLboolean transpose,
6832 const GLfloat *value)
6833{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006834 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006835 ASSERT(programObject);
6836 programObject->setUniformMatrix3fv(location, count, transpose, value);
6837}
6838
6839void Context::programUniformMatrix4fv(GLuint program,
6840 GLint location,
6841 GLsizei count,
6842 GLboolean transpose,
6843 const GLfloat *value)
6844{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006845 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006846 ASSERT(programObject);
6847 programObject->setUniformMatrix4fv(location, count, transpose, value);
6848}
6849
6850void Context::programUniformMatrix2x3fv(GLuint program,
6851 GLint location,
6852 GLsizei count,
6853 GLboolean transpose,
6854 const GLfloat *value)
6855{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006856 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006857 ASSERT(programObject);
6858 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6859}
6860
6861void Context::programUniformMatrix3x2fv(GLuint program,
6862 GLint location,
6863 GLsizei count,
6864 GLboolean transpose,
6865 const GLfloat *value)
6866{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006867 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006868 ASSERT(programObject);
6869 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6870}
6871
6872void Context::programUniformMatrix2x4fv(GLuint program,
6873 GLint location,
6874 GLsizei count,
6875 GLboolean transpose,
6876 const GLfloat *value)
6877{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006878 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006879 ASSERT(programObject);
6880 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6881}
6882
6883void Context::programUniformMatrix4x2fv(GLuint program,
6884 GLint location,
6885 GLsizei count,
6886 GLboolean transpose,
6887 const GLfloat *value)
6888{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006889 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006890 ASSERT(programObject);
6891 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6892}
6893
6894void Context::programUniformMatrix3x4fv(GLuint program,
6895 GLint location,
6896 GLsizei count,
6897 GLboolean transpose,
6898 const GLfloat *value)
6899{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006900 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006901 ASSERT(programObject);
6902 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6903}
6904
6905void Context::programUniformMatrix4x3fv(GLuint program,
6906 GLint location,
6907 GLsizei count,
6908 GLboolean transpose,
6909 const GLfloat *value)
6910{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006911 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006912 ASSERT(programObject);
6913 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6914}
6915
James Darpiniane8a93c62018-01-04 18:02:24 -08006916bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6917{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006918 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006919}
James Darpiniane8a93c62018-01-04 18:02:24 -08006920
Yunchao Hea336b902017-08-02 16:05:21 +08006921void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6922{
6923 for (int i = 0; i < count; i++)
6924 {
6925 pipelines[i] = createProgramPipeline();
6926 }
6927}
6928
6929void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6930{
6931 for (int i = 0; i < count; i++)
6932 {
6933 if (pipelines[i] != 0)
6934 {
6935 deleteProgramPipeline(pipelines[i]);
6936 }
6937 }
6938}
6939
6940GLboolean Context::isProgramPipeline(GLuint pipeline)
6941{
6942 if (pipeline == 0)
6943 {
6944 return GL_FALSE;
6945 }
6946
6947 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6948}
6949
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006950void Context::finishFenceNV(GLuint fence)
6951{
6952 FenceNV *fenceObject = getFenceNV(fence);
6953
6954 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006955 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006956}
6957
6958void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6959{
6960 FenceNV *fenceObject = getFenceNV(fence);
6961
6962 ASSERT(fenceObject && fenceObject->isSet());
6963
6964 switch (pname)
6965 {
6966 case GL_FENCE_STATUS_NV:
6967 {
6968 // GL_NV_fence spec:
6969 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6970 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6971 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6972 GLboolean status = GL_TRUE;
6973 if (fenceObject->getStatus() != GL_TRUE)
6974 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006975 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006976 }
6977 *params = status;
6978 break;
6979 }
6980
6981 case GL_FENCE_CONDITION_NV:
6982 {
6983 *params = static_cast<GLint>(fenceObject->getCondition());
6984 break;
6985 }
6986
6987 default:
6988 UNREACHABLE();
6989 }
6990}
6991
6992void Context::getTranslatedShaderSource(GLuint shader,
6993 GLsizei bufsize,
6994 GLsizei *length,
6995 GLchar *source)
6996{
6997 Shader *shaderObject = getShader(shader);
6998 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006999 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007000}
7001
7002void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7003{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007004 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007005 ASSERT(programObject);
7006
7007 programObject->getUniformfv(this, location, params);
7008}
7009
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007010void Context::getnUniformfvRobust(GLuint program,
7011 GLint location,
7012 GLsizei bufSize,
7013 GLsizei *length,
7014 GLfloat *params)
7015{
7016 UNIMPLEMENTED();
7017}
7018
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007019void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7020{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007021 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007022 ASSERT(programObject);
7023
7024 programObject->getUniformiv(this, location, params);
7025}
7026
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007027void Context::getnUniformivRobust(GLuint program,
7028 GLint location,
7029 GLsizei bufSize,
7030 GLsizei *length,
7031 GLint *params)
7032{
7033 UNIMPLEMENTED();
7034}
7035
7036void Context::getnUniformuivRobust(GLuint program,
7037 GLint location,
7038 GLsizei bufSize,
7039 GLsizei *length,
7040 GLuint *params)
7041{
7042 UNIMPLEMENTED();
7043}
7044
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007045GLboolean Context::isFenceNV(GLuint fence)
7046{
7047 FenceNV *fenceObject = getFenceNV(fence);
7048
7049 if (fenceObject == nullptr)
7050 {
7051 return GL_FALSE;
7052 }
7053
7054 // GL_NV_fence spec:
7055 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7056 // existing fence.
7057 return fenceObject->isSet();
7058}
7059
7060void Context::readnPixels(GLint x,
7061 GLint y,
7062 GLsizei width,
7063 GLsizei height,
7064 GLenum format,
7065 GLenum type,
7066 GLsizei bufSize,
7067 void *data)
7068{
7069 return readPixels(x, y, width, height, format, type, data);
7070}
7071
Jamie Madill007530e2017-12-28 14:27:04 -05007072void Context::setFenceNV(GLuint fence, GLenum condition)
7073{
7074 ASSERT(condition == GL_ALL_COMPLETED_NV);
7075
7076 FenceNV *fenceObject = getFenceNV(fence);
7077 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007078 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007079}
7080
7081GLboolean Context::testFenceNV(GLuint fence)
7082{
7083 FenceNV *fenceObject = getFenceNV(fence);
7084
7085 ASSERT(fenceObject != nullptr);
7086 ASSERT(fenceObject->isSet() == GL_TRUE);
7087
7088 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007089 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007090 {
Jamie Madill007530e2017-12-28 14:27:04 -05007091 return GL_TRUE;
7092 }
7093
7094 return result;
7095}
7096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007097void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007098{
7099 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007100 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007101 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007102}
7103
Jamie Madillfa920eb2018-01-04 11:45:50 -05007104void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007105{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007106 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007107 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007108 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007109}
7110
Jamie Madillfa920eb2018-01-04 11:45:50 -05007111void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7112{
7113 UNIMPLEMENTED();
7114}
7115
Jamie Madill5b772312018-03-08 20:28:32 -05007116bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7117{
7118 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7119 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7120 // to the fact that it is stored internally as a float, and so would require conversion
7121 // if returned from Context::getIntegerv. Since this conversion is already implemented
7122 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7123 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7124 // application.
7125 switch (pname)
7126 {
7127 case GL_COMPRESSED_TEXTURE_FORMATS:
7128 {
7129 *type = GL_INT;
7130 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7131 return true;
7132 }
7133 case GL_SHADER_BINARY_FORMATS:
7134 {
7135 *type = GL_INT;
7136 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7137 return true;
7138 }
7139
7140 case GL_MAX_VERTEX_ATTRIBS:
7141 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7142 case GL_MAX_VARYING_VECTORS:
7143 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7144 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7145 case GL_MAX_TEXTURE_IMAGE_UNITS:
7146 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7147 case GL_MAX_RENDERBUFFER_SIZE:
7148 case GL_NUM_SHADER_BINARY_FORMATS:
7149 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7150 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007151 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7152 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007153 case GL_RENDERBUFFER_BINDING:
7154 case GL_CURRENT_PROGRAM:
7155 case GL_PACK_ALIGNMENT:
7156 case GL_UNPACK_ALIGNMENT:
7157 case GL_GENERATE_MIPMAP_HINT:
7158 case GL_RED_BITS:
7159 case GL_GREEN_BITS:
7160 case GL_BLUE_BITS:
7161 case GL_ALPHA_BITS:
7162 case GL_DEPTH_BITS:
7163 case GL_STENCIL_BITS:
7164 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7165 case GL_CULL_FACE_MODE:
7166 case GL_FRONT_FACE:
7167 case GL_ACTIVE_TEXTURE:
7168 case GL_STENCIL_FUNC:
7169 case GL_STENCIL_VALUE_MASK:
7170 case GL_STENCIL_REF:
7171 case GL_STENCIL_FAIL:
7172 case GL_STENCIL_PASS_DEPTH_FAIL:
7173 case GL_STENCIL_PASS_DEPTH_PASS:
7174 case GL_STENCIL_BACK_FUNC:
7175 case GL_STENCIL_BACK_VALUE_MASK:
7176 case GL_STENCIL_BACK_REF:
7177 case GL_STENCIL_BACK_FAIL:
7178 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7179 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7180 case GL_DEPTH_FUNC:
7181 case GL_BLEND_SRC_RGB:
7182 case GL_BLEND_SRC_ALPHA:
7183 case GL_BLEND_DST_RGB:
7184 case GL_BLEND_DST_ALPHA:
7185 case GL_BLEND_EQUATION_RGB:
7186 case GL_BLEND_EQUATION_ALPHA:
7187 case GL_STENCIL_WRITEMASK:
7188 case GL_STENCIL_BACK_WRITEMASK:
7189 case GL_STENCIL_CLEAR_VALUE:
7190 case GL_SUBPIXEL_BITS:
7191 case GL_MAX_TEXTURE_SIZE:
7192 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7193 case GL_SAMPLE_BUFFERS:
7194 case GL_SAMPLES:
7195 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7196 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7197 case GL_TEXTURE_BINDING_2D:
7198 case GL_TEXTURE_BINDING_CUBE_MAP:
7199 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7200 {
7201 *type = GL_INT;
7202 *numParams = 1;
7203 return true;
7204 }
7205 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7206 {
7207 if (!getExtensions().packReverseRowOrder)
7208 {
7209 return false;
7210 }
7211 *type = GL_INT;
7212 *numParams = 1;
7213 return true;
7214 }
7215 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7216 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7217 {
7218 if (!getExtensions().textureRectangle)
7219 {
7220 return false;
7221 }
7222 *type = GL_INT;
7223 *numParams = 1;
7224 return true;
7225 }
7226 case GL_MAX_DRAW_BUFFERS_EXT:
7227 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7228 {
7229 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7230 {
7231 return false;
7232 }
7233 *type = GL_INT;
7234 *numParams = 1;
7235 return true;
7236 }
7237 case GL_MAX_VIEWPORT_DIMS:
7238 {
7239 *type = GL_INT;
7240 *numParams = 2;
7241 return true;
7242 }
7243 case GL_VIEWPORT:
7244 case GL_SCISSOR_BOX:
7245 {
7246 *type = GL_INT;
7247 *numParams = 4;
7248 return true;
7249 }
7250 case GL_SHADER_COMPILER:
7251 case GL_SAMPLE_COVERAGE_INVERT:
7252 case GL_DEPTH_WRITEMASK:
7253 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7254 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7255 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7256 // bool-natural
7257 case GL_SAMPLE_COVERAGE:
7258 case GL_SCISSOR_TEST:
7259 case GL_STENCIL_TEST:
7260 case GL_DEPTH_TEST:
7261 case GL_BLEND:
7262 case GL_DITHER:
7263 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7264 {
7265 *type = GL_BOOL;
7266 *numParams = 1;
7267 return true;
7268 }
7269 case GL_COLOR_WRITEMASK:
7270 {
7271 *type = GL_BOOL;
7272 *numParams = 4;
7273 return true;
7274 }
7275 case GL_POLYGON_OFFSET_FACTOR:
7276 case GL_POLYGON_OFFSET_UNITS:
7277 case GL_SAMPLE_COVERAGE_VALUE:
7278 case GL_DEPTH_CLEAR_VALUE:
7279 case GL_LINE_WIDTH:
7280 {
7281 *type = GL_FLOAT;
7282 *numParams = 1;
7283 return true;
7284 }
7285 case GL_ALIASED_LINE_WIDTH_RANGE:
7286 case GL_ALIASED_POINT_SIZE_RANGE:
7287 case GL_DEPTH_RANGE:
7288 {
7289 *type = GL_FLOAT;
7290 *numParams = 2;
7291 return true;
7292 }
7293 case GL_COLOR_CLEAR_VALUE:
7294 case GL_BLEND_COLOR:
7295 {
7296 *type = GL_FLOAT;
7297 *numParams = 4;
7298 return true;
7299 }
7300 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7301 if (!getExtensions().textureFilterAnisotropic)
7302 {
7303 return false;
7304 }
7305 *type = GL_FLOAT;
7306 *numParams = 1;
7307 return true;
7308 case GL_TIMESTAMP_EXT:
7309 if (!getExtensions().disjointTimerQuery)
7310 {
7311 return false;
7312 }
7313 *type = GL_INT_64_ANGLEX;
7314 *numParams = 1;
7315 return true;
7316 case GL_GPU_DISJOINT_EXT:
7317 if (!getExtensions().disjointTimerQuery)
7318 {
7319 return false;
7320 }
7321 *type = GL_INT;
7322 *numParams = 1;
7323 return true;
7324 case GL_COVERAGE_MODULATION_CHROMIUM:
7325 if (!getExtensions().framebufferMixedSamples)
7326 {
7327 return false;
7328 }
7329 *type = GL_INT;
7330 *numParams = 1;
7331 return true;
7332 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7333 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7334 {
7335 return false;
7336 }
7337 *type = GL_INT;
7338 *numParams = 1;
7339 return true;
7340 }
7341
7342 if (getExtensions().debug)
7343 {
7344 switch (pname)
7345 {
7346 case GL_DEBUG_LOGGED_MESSAGES:
7347 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7348 case GL_DEBUG_GROUP_STACK_DEPTH:
7349 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7350 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7351 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7352 case GL_MAX_LABEL_LENGTH:
7353 *type = GL_INT;
7354 *numParams = 1;
7355 return true;
7356
7357 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7358 case GL_DEBUG_OUTPUT:
7359 *type = GL_BOOL;
7360 *numParams = 1;
7361 return true;
7362 }
7363 }
7364
7365 if (getExtensions().multisampleCompatibility)
7366 {
7367 switch (pname)
7368 {
7369 case GL_MULTISAMPLE_EXT:
7370 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7371 *type = GL_BOOL;
7372 *numParams = 1;
7373 return true;
7374 }
7375 }
7376
7377 if (getExtensions().pathRendering)
7378 {
7379 switch (pname)
7380 {
7381 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7382 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7383 *type = GL_FLOAT;
7384 *numParams = 16;
7385 return true;
7386 }
7387 }
7388
7389 if (getExtensions().bindGeneratesResource)
7390 {
7391 switch (pname)
7392 {
7393 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7394 *type = GL_BOOL;
7395 *numParams = 1;
7396 return true;
7397 }
7398 }
7399
7400 if (getExtensions().clientArrays)
7401 {
7402 switch (pname)
7403 {
7404 case GL_CLIENT_ARRAYS_ANGLE:
7405 *type = GL_BOOL;
7406 *numParams = 1;
7407 return true;
7408 }
7409 }
7410
7411 if (getExtensions().sRGBWriteControl)
7412 {
7413 switch (pname)
7414 {
7415 case GL_FRAMEBUFFER_SRGB_EXT:
7416 *type = GL_BOOL;
7417 *numParams = 1;
7418 return true;
7419 }
7420 }
7421
7422 if (getExtensions().robustResourceInitialization &&
7423 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7424 {
7425 *type = GL_BOOL;
7426 *numParams = 1;
7427 return true;
7428 }
7429
7430 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7431 {
7432 *type = GL_BOOL;
7433 *numParams = 1;
7434 return true;
7435 }
7436
jchen1082af6202018-06-22 10:59:52 +08007437 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7438 {
7439 *type = GL_INT;
7440 *numParams = 1;
7441 return true;
7442 }
7443
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007444 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7445 {
7446 *type = GL_INT;
7447 *numParams = 1;
7448 return true;
7449 }
7450
Jamie Madill5b772312018-03-08 20:28:32 -05007451 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7452 switch (pname)
7453 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007454 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007455 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7456 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7457 {
7458 return false;
7459 }
7460 *type = GL_INT;
7461 *numParams = 1;
7462 return true;
7463
7464 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7465 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7466 {
7467 return false;
7468 }
7469 *type = GL_INT;
7470 *numParams = 1;
7471 return true;
7472
7473 case GL_PROGRAM_BINARY_FORMATS_OES:
7474 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7475 {
7476 return false;
7477 }
7478 *type = GL_INT;
7479 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7480 return true;
7481
7482 case GL_PACK_ROW_LENGTH:
7483 case GL_PACK_SKIP_ROWS:
7484 case GL_PACK_SKIP_PIXELS:
7485 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7486 {
7487 return false;
7488 }
7489 *type = GL_INT;
7490 *numParams = 1;
7491 return true;
7492 case GL_UNPACK_ROW_LENGTH:
7493 case GL_UNPACK_SKIP_ROWS:
7494 case GL_UNPACK_SKIP_PIXELS:
7495 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7496 {
7497 return false;
7498 }
7499 *type = GL_INT;
7500 *numParams = 1;
7501 return true;
7502 case GL_VERTEX_ARRAY_BINDING:
7503 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7504 {
7505 return false;
7506 }
7507 *type = GL_INT;
7508 *numParams = 1;
7509 return true;
7510 case GL_PIXEL_PACK_BUFFER_BINDING:
7511 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7512 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7513 {
7514 return false;
7515 }
7516 *type = GL_INT;
7517 *numParams = 1;
7518 return true;
7519 case GL_MAX_SAMPLES:
7520 {
7521 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7522 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7523 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7524 {
7525 return false;
7526 }
7527 *type = GL_INT;
7528 *numParams = 1;
7529 return true;
7530
7531 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7532 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7533 {
7534 return false;
7535 }
7536 *type = GL_INT;
7537 *numParams = 1;
7538 return true;
7539 }
7540 }
7541
7542 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7543 {
7544 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7545 {
7546 return false;
7547 }
7548 *type = GL_INT;
7549 *numParams = 1;
7550 return true;
7551 }
7552
7553 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7554 {
7555 *type = GL_INT;
7556 *numParams = 1;
7557 return true;
7558 }
7559
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007560 if (getClientVersion() < Version(2, 0))
7561 {
7562 switch (pname)
7563 {
7564 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007565 case GL_CLIENT_ACTIVE_TEXTURE:
7566 case GL_MATRIX_MODE:
7567 case GL_MAX_TEXTURE_UNITS:
7568 case GL_MAX_MODELVIEW_STACK_DEPTH:
7569 case GL_MAX_PROJECTION_STACK_DEPTH:
7570 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007571 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007572 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007573 case GL_VERTEX_ARRAY_STRIDE:
7574 case GL_NORMAL_ARRAY_STRIDE:
7575 case GL_COLOR_ARRAY_STRIDE:
7576 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7577 case GL_VERTEX_ARRAY_SIZE:
7578 case GL_COLOR_ARRAY_SIZE:
7579 case GL_TEXTURE_COORD_ARRAY_SIZE:
7580 case GL_VERTEX_ARRAY_TYPE:
7581 case GL_NORMAL_ARRAY_TYPE:
7582 case GL_COLOR_ARRAY_TYPE:
7583 case GL_TEXTURE_COORD_ARRAY_TYPE:
7584 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7585 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7586 case GL_COLOR_ARRAY_BUFFER_BINDING:
7587 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7588 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7589 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7590 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007591 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007592 case GL_MODELVIEW_STACK_DEPTH:
7593 case GL_PROJECTION_STACK_DEPTH:
7594 case GL_TEXTURE_STACK_DEPTH:
7595 case GL_LOGIC_OP_MODE:
7596 case GL_BLEND_SRC:
7597 case GL_BLEND_DST:
7598 case GL_PERSPECTIVE_CORRECTION_HINT:
7599 case GL_POINT_SMOOTH_HINT:
7600 case GL_LINE_SMOOTH_HINT:
7601 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007602 *type = GL_INT;
7603 *numParams = 1;
7604 return true;
7605 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007606 case GL_FOG_DENSITY:
7607 case GL_FOG_START:
7608 case GL_FOG_END:
7609 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007610 case GL_POINT_SIZE:
7611 case GL_POINT_SIZE_MIN:
7612 case GL_POINT_SIZE_MAX:
7613 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007614 *type = GL_FLOAT;
7615 *numParams = 1;
7616 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007617 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007618 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007619 *type = GL_FLOAT;
7620 *numParams = 2;
7621 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007622 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007623 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007624 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007625 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007626 *type = GL_FLOAT;
7627 *numParams = 4;
7628 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007629 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007630 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007631 *type = GL_FLOAT;
7632 *numParams = 3;
7633 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007634 case GL_MODELVIEW_MATRIX:
7635 case GL_PROJECTION_MATRIX:
7636 case GL_TEXTURE_MATRIX:
7637 *type = GL_FLOAT;
7638 *numParams = 16;
7639 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007640 case GL_LIGHT_MODEL_TWO_SIDE:
7641 *type = GL_BOOL;
7642 *numParams = 1;
7643 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007644 }
7645 }
7646
Jamie Madill5b772312018-03-08 20:28:32 -05007647 if (getClientVersion() < Version(3, 0))
7648 {
7649 return false;
7650 }
7651
7652 // Check for ES3.0+ parameter names
7653 switch (pname)
7654 {
7655 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7656 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7657 case GL_UNIFORM_BUFFER_BINDING:
7658 case GL_TRANSFORM_FEEDBACK_BINDING:
7659 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7660 case GL_COPY_READ_BUFFER_BINDING:
7661 case GL_COPY_WRITE_BUFFER_BINDING:
7662 case GL_SAMPLER_BINDING:
7663 case GL_READ_BUFFER:
7664 case GL_TEXTURE_BINDING_3D:
7665 case GL_TEXTURE_BINDING_2D_ARRAY:
7666 case GL_MAX_3D_TEXTURE_SIZE:
7667 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7668 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7669 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7670 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7671 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7672 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7673 case GL_MAX_VARYING_COMPONENTS:
7674 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7675 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7676 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7677 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7678 case GL_NUM_EXTENSIONS:
7679 case GL_MAJOR_VERSION:
7680 case GL_MINOR_VERSION:
7681 case GL_MAX_ELEMENTS_INDICES:
7682 case GL_MAX_ELEMENTS_VERTICES:
7683 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7684 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7685 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7686 case GL_UNPACK_IMAGE_HEIGHT:
7687 case GL_UNPACK_SKIP_IMAGES:
7688 {
7689 *type = GL_INT;
7690 *numParams = 1;
7691 return true;
7692 }
7693
7694 case GL_MAX_ELEMENT_INDEX:
7695 case GL_MAX_UNIFORM_BLOCK_SIZE:
7696 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7697 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7698 case GL_MAX_SERVER_WAIT_TIMEOUT:
7699 {
7700 *type = GL_INT_64_ANGLEX;
7701 *numParams = 1;
7702 return true;
7703 }
7704
7705 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7706 case GL_TRANSFORM_FEEDBACK_PAUSED:
7707 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7708 case GL_RASTERIZER_DISCARD:
7709 {
7710 *type = GL_BOOL;
7711 *numParams = 1;
7712 return true;
7713 }
7714
7715 case GL_MAX_TEXTURE_LOD_BIAS:
7716 {
7717 *type = GL_FLOAT;
7718 *numParams = 1;
7719 return true;
7720 }
7721 }
7722
7723 if (getExtensions().requestExtension)
7724 {
7725 switch (pname)
7726 {
7727 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7728 *type = GL_INT;
7729 *numParams = 1;
7730 return true;
7731 }
7732 }
7733
Yizhou Jiang7818a852018-09-06 15:02:04 +08007734 if (getExtensions().textureMultisample)
7735 {
7736 switch (pname)
7737 {
7738 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7739 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7740 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7741 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007742 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007743 *type = GL_INT;
7744 *numParams = 1;
7745 return true;
7746 }
7747 }
7748
Jamie Madill5b772312018-03-08 20:28:32 -05007749 if (getClientVersion() < Version(3, 1))
7750 {
7751 return false;
7752 }
7753
7754 switch (pname)
7755 {
7756 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7757 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7758 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7759 case GL_MAX_FRAMEBUFFER_WIDTH:
7760 case GL_MAX_FRAMEBUFFER_HEIGHT:
7761 case GL_MAX_FRAMEBUFFER_SAMPLES:
7762 case GL_MAX_SAMPLE_MASK_WORDS:
7763 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7764 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7765 case GL_MAX_INTEGER_SAMPLES:
7766 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7767 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7768 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7769 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7770 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7771 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7772 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7773 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7774 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7775 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7776 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7777 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7778 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7779 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7780 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7781 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7782 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7783 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7784 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7785 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7786 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7787 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7788 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7789 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7790 case GL_MAX_UNIFORM_LOCATIONS:
7791 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7792 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7793 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7794 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7795 case GL_MAX_IMAGE_UNITS:
7796 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7797 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7798 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7799 case GL_SHADER_STORAGE_BUFFER_BINDING:
7800 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7801 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007802 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007803 *type = GL_INT;
7804 *numParams = 1;
7805 return true;
7806 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7807 *type = GL_INT_64_ANGLEX;
7808 *numParams = 1;
7809 return true;
7810 case GL_SAMPLE_MASK:
7811 *type = GL_BOOL;
7812 *numParams = 1;
7813 return true;
7814 }
7815
7816 if (getExtensions().geometryShader)
7817 {
7818 switch (pname)
7819 {
7820 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7821 case GL_LAYER_PROVOKING_VERTEX_EXT:
7822 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7823 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7824 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7825 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7826 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7827 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7828 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7829 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7830 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7831 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7832 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7833 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7834 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7835 *type = GL_INT;
7836 *numParams = 1;
7837 return true;
7838 }
7839 }
7840
7841 return false;
7842}
7843
7844bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7845{
7846 if (getClientVersion() < Version(3, 0))
7847 {
7848 return false;
7849 }
7850
7851 switch (target)
7852 {
7853 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7854 case GL_UNIFORM_BUFFER_BINDING:
7855 {
7856 *type = GL_INT;
7857 *numParams = 1;
7858 return true;
7859 }
7860 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7861 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7862 case GL_UNIFORM_BUFFER_START:
7863 case GL_UNIFORM_BUFFER_SIZE:
7864 {
7865 *type = GL_INT_64_ANGLEX;
7866 *numParams = 1;
7867 return true;
7868 }
7869 }
7870
7871 if (getClientVersion() < Version(3, 1))
7872 {
7873 return false;
7874 }
7875
7876 switch (target)
7877 {
7878 case GL_IMAGE_BINDING_LAYERED:
7879 {
7880 *type = GL_BOOL;
7881 *numParams = 1;
7882 return true;
7883 }
7884 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7885 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7886 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7887 case GL_SHADER_STORAGE_BUFFER_BINDING:
7888 case GL_VERTEX_BINDING_BUFFER:
7889 case GL_VERTEX_BINDING_DIVISOR:
7890 case GL_VERTEX_BINDING_OFFSET:
7891 case GL_VERTEX_BINDING_STRIDE:
7892 case GL_SAMPLE_MASK_VALUE:
7893 case GL_IMAGE_BINDING_NAME:
7894 case GL_IMAGE_BINDING_LEVEL:
7895 case GL_IMAGE_BINDING_LAYER:
7896 case GL_IMAGE_BINDING_ACCESS:
7897 case GL_IMAGE_BINDING_FORMAT:
7898 {
7899 *type = GL_INT;
7900 *numParams = 1;
7901 return true;
7902 }
7903 case GL_ATOMIC_COUNTER_BUFFER_START:
7904 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7905 case GL_SHADER_STORAGE_BUFFER_START:
7906 case GL_SHADER_STORAGE_BUFFER_SIZE:
7907 {
7908 *type = GL_INT_64_ANGLEX;
7909 *numParams = 1;
7910 return true;
7911 }
7912 }
7913
7914 return false;
7915}
7916
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007917Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007918{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007919 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007920}
7921
7922Shader *Context::getShader(GLuint handle) const
7923{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007924 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007925}
7926
Jamie Madill5b772312018-03-08 20:28:32 -05007927bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7928{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007929 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007930}
7931
7932bool Context::isFramebufferGenerated(GLuint framebuffer) const
7933{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007934 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007935}
7936
7937bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7938{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007939 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007940}
7941
7942bool Context::usingDisplayTextureShareGroup() const
7943{
7944 return mDisplayTextureShareGroup;
7945}
7946
7947GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7948{
7949 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7950 internalformat == GL_DEPTH_STENCIL
7951 ? GL_DEPTH24_STENCIL8
7952 : internalformat;
7953}
7954
jchen1082af6202018-06-22 10:59:52 +08007955void Context::maxShaderCompilerThreads(GLuint count)
7956{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007957 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7958 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007959 // A count of zero specifies a request for no parallel compiling or linking.
7960 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7961 {
7962 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7963 }
7964 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007965}
7966
Jamie Madill2eb65032018-07-30 10:25:57 -04007967bool Context::isGLES1() const
7968{
7969 return mState.getClientVersion() < Version(2, 0);
7970}
7971
Jamie Madilla11819d2018-07-30 10:26:01 -04007972void Context::onSubjectStateChange(const Context *context,
7973 angle::SubjectIndex index,
7974 angle::SubjectMessage message)
7975{
Jamie Madilla11819d2018-07-30 10:26:01 -04007976 switch (index)
7977 {
7978 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007979 switch (message)
7980 {
7981 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007982 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007983 mStateCache.onVertexArrayBufferContentsChange(this);
7984 break;
7985 case angle::SubjectMessage::RESOURCE_MAPPED:
7986 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7987 case angle::SubjectMessage::BINDING_CHANGED:
7988 mStateCache.onVertexArrayBufferStateChange(this);
7989 break;
7990 default:
7991 break;
7992 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007993 break;
7994
7995 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007996 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7997 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007998 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04007999 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008000 break;
8001
8002 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008003 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8004 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008005 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008006 }
8007 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008008 break;
8009
8010 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008011 if (index < kTextureMaxSubjectIndex)
8012 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008013 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008014 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008015 }
Jamie Madille25b8002018-09-20 13:39:49 -04008016 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008017 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008018 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008019 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008020 }
Jamie Madille25b8002018-09-20 13:39:49 -04008021 else
8022 {
8023 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008024 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008025 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008026 break;
8027 }
8028}
8029
Jamie Madill6b873dd2018-07-12 23:56:30 -04008030// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008031ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008032
8033ErrorSet::~ErrorSet() = default;
8034
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008035void ErrorSet::handleError(GLenum errorCode,
8036 const char *message,
8037 const char *file,
8038 const char *function,
8039 unsigned int line)
8040{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008041 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8042 {
8043 mContext->markContextLost();
8044 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008045
Jamie Madill4f6592f2018-11-27 16:37:45 -05008046 std::stringstream errorStream;
8047 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8048 << line << ". " << message;
8049
Geoff Lang7139b432018-12-14 16:57:28 -05008050 std::string formattedMessage = errorStream.str();
8051
8052 // Always log a warning, this function is only called on unexpected internal errors.
8053 WARN() << formattedMessage;
8054
Jamie Madill4f6592f2018-11-27 16:37:45 -05008055 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008056 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008057}
8058
Jamie Madilla139f012018-10-10 16:13:03 -04008059void ErrorSet::validationError(GLenum errorCode, const char *message)
8060{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008061 ASSERT(errorCode != GL_NO_ERROR);
8062 mErrors.insert(errorCode);
8063
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008064 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8065 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008066}
8067
Jamie Madill6b873dd2018-07-12 23:56:30 -04008068bool ErrorSet::empty() const
8069{
8070 return mErrors.empty();
8071}
8072
8073GLenum ErrorSet::popError()
8074{
8075 ASSERT(!empty());
8076 GLenum error = *mErrors.begin();
8077 mErrors.erase(mErrors.begin());
8078 return error;
8079}
Jamie Madilldc358af2018-07-31 11:22:13 -04008080
8081// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008082StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008083 : mCachedHasAnyEnabledClientAttrib(false),
8084 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008085 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008086 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008087 mCachedBasicDrawElementsError(kInvalidPointer),
8088 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008089{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008090
8091StateCache::~StateCache() = default;
8092
Jamie Madillac66f982018-10-09 18:30:01 -04008093void StateCache::initialize(Context *context)
8094{
8095 updateValidDrawModes(context);
8096 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008097 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008098 updateBasicDrawStatesError();
8099 updateBasicDrawElementsError();
Jamie Madillc8c7d402019-01-16 13:27:15 -05008100 updateVertexAttribTypesValidation(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008101}
8102
Jamie Madilldc358af2018-07-31 11:22:13 -04008103void StateCache::updateActiveAttribsMask(Context *context)
8104{
8105 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008106 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008107
8108 if (!isGLES1 && !glState.getProgram())
8109 {
8110 mCachedActiveBufferedAttribsMask = AttributesMask();
8111 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008112 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008113 return;
8114 }
8115
8116 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8117 : glState.getProgram()->getActiveAttribLocationsMask();
8118
8119 const VertexArray *vao = glState.getVertexArray();
8120 ASSERT(vao);
8121
8122 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8123 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008124 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008125
Jamie Madill0a17e482018-08-31 17:19:11 -04008126 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8127 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008128 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008129 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8130}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008131
8132void StateCache::updateVertexElementLimits(Context *context)
8133{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008134 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008135
8136 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8137 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8138
8139 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8140 // If there are no buffered attributes then we should not limit the draw call count.
8141 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8142 {
8143 return;
8144 }
8145
8146 const auto &vertexAttribs = vao->getVertexAttributes();
8147 const auto &vertexBindings = vao->getVertexBindings();
8148
8149 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8150 {
8151 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008152
8153 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8154 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008155 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008156
8157 GLint64 limit = attrib.getCachedElementLimit();
8158 if (binding.getDivisor() > 0)
8159 {
8160 mCachedInstancedVertexElementLimit =
8161 std::min(mCachedInstancedVertexElementLimit, limit);
8162 }
8163 else
8164 {
8165 mCachedNonInstancedVertexElementLimit =
8166 std::min(mCachedNonInstancedVertexElementLimit, limit);
8167 }
8168 }
8169}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008170
Jamie Madilld84b6732018-09-06 15:54:35 -04008171void StateCache::updateBasicDrawStatesError()
8172{
8173 mCachedBasicDrawStatesError = kInvalidPointer;
8174}
8175
Jamie Madill1e853262018-12-21 09:07:38 -05008176void StateCache::updateBasicDrawElementsError()
8177{
8178 mCachedBasicDrawElementsError = kInvalidPointer;
8179}
8180
Jamie Madilld84b6732018-09-06 15:54:35 -04008181intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8182{
8183 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8184 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8185 return mCachedBasicDrawStatesError;
8186}
8187
Jamie Madill1e853262018-12-21 09:07:38 -05008188intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8189{
8190 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8191 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8192 return mCachedBasicDrawElementsError;
8193}
8194
Jamie Madillc43cdad2018-08-08 15:49:25 -04008195void StateCache::onVertexArrayBindingChange(Context *context)
8196{
8197 updateActiveAttribsMask(context);
8198 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008199 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008200}
8201
8202void StateCache::onProgramExecutableChange(Context *context)
8203{
8204 updateActiveAttribsMask(context);
8205 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008206 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008207 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008208}
8209
Jamie Madilld84b6732018-09-06 15:54:35 -04008210void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008211{
8212 updateVertexElementLimits(context);
8213}
8214
Jamie Madilld84b6732018-09-06 15:54:35 -04008215void StateCache::onVertexArrayBufferContentsChange(Context *context)
8216{
8217 updateVertexElementLimits(context);
8218 updateBasicDrawStatesError();
8219}
8220
Jamie Madillc43cdad2018-08-08 15:49:25 -04008221void StateCache::onVertexArrayStateChange(Context *context)
8222{
8223 updateActiveAttribsMask(context);
8224 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008225 updateBasicDrawStatesError();
8226}
8227
8228void StateCache::onVertexArrayBufferStateChange(Context *context)
8229{
8230 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008231 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008232}
8233
8234void StateCache::onGLES1ClientStateChange(Context *context)
8235{
8236 updateActiveAttribsMask(context);
8237}
Jamie Madilld84b6732018-09-06 15:54:35 -04008238
8239void StateCache::onDrawFramebufferChange(Context *context)
8240{
8241 updateBasicDrawStatesError();
8242}
8243
8244void StateCache::onContextCapChange(Context *context)
8245{
8246 updateBasicDrawStatesError();
8247}
8248
8249void StateCache::onStencilStateChange(Context *context)
8250{
8251 updateBasicDrawStatesError();
8252}
8253
8254void StateCache::onDefaultVertexAttributeChange(Context *context)
8255{
8256 updateBasicDrawStatesError();
8257}
8258
8259void StateCache::onActiveTextureChange(Context *context)
8260{
8261 updateBasicDrawStatesError();
8262}
8263
8264void StateCache::onQueryChange(Context *context)
8265{
8266 updateBasicDrawStatesError();
8267}
8268
Jamie Madill3a256222018-12-08 09:56:39 -05008269void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008270{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008271 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008272 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008273 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008274 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008275}
8276
8277void StateCache::onUniformBufferStateChange(Context *context)
8278{
8279 updateBasicDrawStatesError();
8280}
8281
Jamie Madill9b025062018-12-12 15:44:12 -05008282void StateCache::setValidDrawModes(bool pointsOK,
8283 bool linesOK,
8284 bool trisOK,
8285 bool lineAdjOK,
8286 bool triAdjOK)
8287{
8288 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8289 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8290 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8291 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8292 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8293 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8294 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8295 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8296 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8297 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8298 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8299}
8300
Jamie Madill526a6f62018-09-12 11:03:05 -04008301void StateCache::updateValidDrawModes(Context *context)
8302{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008303 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008304 Program *program = state.getProgram();
8305
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008306 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008307 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008308 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8309
Jamie Madill9b025062018-12-12 15:44:12 -05008310 // ES Spec 3.0 validation text:
8311 // When transform feedback is active and not paused, all geometric primitives generated must
8312 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8313 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8314 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8315 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8316 // active and not paused, regardless of mode. Any primitive type may be used while transform
8317 // feedback is paused.
8318 if (!context->getExtensions().geometryShader)
8319 {
8320 mCachedValidDrawModes.fill(false);
8321 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8322 return;
8323 }
8324
8325 // EXT_geometry_shader validation text:
8326 // When transform feedback is active and not paused, all geometric primitives generated must
8327 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8328 // geometry shader is active, the type of primitive emitted by that shader is used instead
8329 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8330 // Any primitive type may be used while transform feedback is paused.
8331 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8332 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8333 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8334
8335 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8336 return;
8337 }
8338
Jamie Madill526a6f62018-09-12 11:03:05 -04008339 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8340 {
Jamie Madill752d2202018-11-27 13:29:48 -05008341 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008342 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008343 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008344
Jamie Madill9b025062018-12-12 15:44:12 -05008345 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8346 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008347
Jamie Madill9b025062018-12-12 15:44:12 -05008348 bool pointsOK = gsMode == PrimitiveMode::Points;
8349 bool linesOK = gsMode == PrimitiveMode::Lines;
8350 bool trisOK = gsMode == PrimitiveMode::Triangles;
8351 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8352 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8353
8354 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008355}
Jamie Madillac66f982018-10-09 18:30:01 -04008356
8357void StateCache::updateValidBindTextureTypes(Context *context)
8358{
8359 const Extensions &exts = context->getExtensions();
8360 bool isGLES3 = context->getClientMajorVersion() >= 3;
8361 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8362
8363 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008364 {TextureType::_2D, true},
8365 {TextureType::_2DArray, isGLES3},
8366 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8367 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8368 {TextureType::_3D, isGLES3},
8369 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8370 {TextureType::Rectangle, exts.textureRectangle},
8371 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008372 }};
8373}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008374
8375void StateCache::updateValidDrawElementsTypes(Context *context)
8376{
8377 bool supportsUint =
8378 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8379
8380 mCachedValidDrawElementsTypes = {{
8381 {DrawElementsType::UnsignedByte, true},
8382 {DrawElementsType::UnsignedShort, true},
8383 {DrawElementsType::UnsignedInt, supportsUint},
8384 }};
8385}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008386
8387void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8388{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008389 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008390 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8391}
Jamie Madillc8c7d402019-01-16 13:27:15 -05008392
8393void StateCache::updateVertexAttribTypesValidation(Context *context)
8394{
8395 if (context->getClientMajorVersion() <= 2)
8396 {
8397 mCachedVertexAttribTypesValidation = {{
8398 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8399 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8400 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8401 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8402 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8403 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8404 }};
8405 }
8406 else
8407 {
8408 mCachedVertexAttribTypesValidation = {{
8409 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8410 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8411 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8412 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8413 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8414 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8415 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8416 {VertexAttribType::HalfFloat, VertexAttribTypeCase::Valid},
8417 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8418 {VertexAttribType::Int2101010, VertexAttribTypeCase::ValidSize4Only},
8419 {VertexAttribType::UnsignedInt2101010, VertexAttribTypeCase::ValidSize4Only},
8420 }};
8421
8422 mCachedIntegerVertexAttribTypesValidation = {{
8423 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8424 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8425 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8426 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8427 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8428 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8429 }};
8430 }
8431}
Jamie Madillc29968b2016-01-20 11:17:23 -05008432} // namespace gl