blob: 7c1bfa29bee7a2796e885162cd16f3986113cef4 [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
Shahbaz Youssefi5313c8a2019-01-14 17:02:52 -05003220 // If EGL_KHR_fence_sync is not enabled, don't expose GL_OES_EGL_sync.
3221 ASSERT(mCurrentDisplay);
3222 if (!mCurrentDisplay->getExtensions().fenceSync)
3223 {
3224 supportedExtensions.eglSync = false;
3225 }
3226
Geoff Lang79b91402018-10-04 15:11:30 -04003227 supportedExtensions.memorySize = true;
3228
Geoff Langb0f917f2017-12-05 13:41:54 -05003229 return supportedExtensions;
3230}
3231
Geoff Lang33f11fb2018-05-07 13:42:47 -04003232void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003233{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003234 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003235
Geoff Lang33f11fb2018-05-07 13:42:47 -04003236 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003237 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003238
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003239 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003240
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003241 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3242 if (getClientVersion() < Version(2, 0))
3243 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003244 mState.mCaps.maxMultitextureUnits = 4;
3245 mState.mCaps.maxClipPlanes = 6;
3246 mState.mCaps.maxLights = 8;
3247 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3248 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3249 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3250 mState.mCaps.minSmoothPointSize = 1.0f;
3251 mState.mCaps.maxSmoothPointSize = 1.0f;
3252 mState.mCaps.minSmoothLineWidth = 1.0f;
3253 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003254 }
3255
Luc Ferronad2ae932018-06-11 15:31:17 -04003256 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003257 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003258
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003259 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003260
Jamie Madill0f80ed82017-09-19 00:24:56 -04003261 if (getClientVersion() < ES_3_1)
3262 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003263 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003264 }
3265 else
3266 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003267 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003268 }
Geoff Lang301d1612014-07-09 10:34:37 -04003269
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003270 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003271 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003272 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003273
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003274 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3275 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003276
3277 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003278 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3279 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003280 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003281 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003282 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003283
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003284 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003285
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003286 mState.mCaps.maxSampleMaskWords =
3287 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003288
Geoff Langc287ea62016-09-16 14:46:51 -04003289 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003290 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003291 for (const auto &extensionInfo : GetExtensionInfoMap())
3292 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003293 // If the user has requested that extensions start disabled and they are requestable,
3294 // disable them.
3295 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003296 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003297 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003298 }
3299 }
3300
3301 // Generate texture caps
3302 updateCaps();
3303}
3304
3305void Context::updateCaps()
3306{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003307 mState.mCaps.compressedTextureFormats.clear();
3308 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003309
Jamie Madill7b62cf92017-11-02 15:20:49 -04003310 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003311 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003312 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003313 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003314
Geoff Lang0d8b7242015-09-09 14:56:53 -04003315 // Update the format caps based on the client version and extensions.
3316 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3317 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003318 formatCaps.texturable = formatCaps.texturable &&
3319 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3320 formatCaps.filterable = formatCaps.filterable &&
3321 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003322 formatCaps.textureAttachment =
3323 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003324 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3325 formatCaps.renderbuffer =
3326 formatCaps.renderbuffer &&
3327 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003328
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003329 // OpenGL ES does not support multisampling with non-rendererable formats
3330 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003331 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003332 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003333 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003334 {
Geoff Langd87878e2014-09-19 15:42:59 -04003335 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003336 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003337 else
3338 {
3339 // We may have limited the max samples for some required renderbuffer formats due to
3340 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3341 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3342
3343 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3344 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3345 // exception of signed and unsigned integer formats."
3346 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3347 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3348 {
3349 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003350 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003351 }
3352
3353 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003354 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003355 {
3356 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3357 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3358 // the exception that the signed and unsigned integer formats are required only to
3359 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3360 // multisamples, which must be at least one."
3361 if (formatInfo.componentType == GL_INT ||
3362 formatInfo.componentType == GL_UNSIGNED_INT)
3363 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003364 mState.mCaps.maxIntegerSamples =
3365 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003366 }
3367
3368 // GLES 3.1 section 19.3.1.
3369 if (formatCaps.texturable)
3370 {
3371 if (formatInfo.depthBits > 0)
3372 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003373 mState.mCaps.maxDepthTextureSamples =
3374 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003375 }
3376 else if (formatInfo.redBits > 0)
3377 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003378 mState.mCaps.maxColorTextureSamples =
3379 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003380 }
3381 }
3382 }
3383 }
Geoff Langd87878e2014-09-19 15:42:59 -04003384
3385 if (formatCaps.texturable && formatInfo.compressed)
3386 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003387 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003388 }
3389
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003390 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003391 }
Jamie Madill32447362017-06-28 14:53:52 -04003392
3393 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003394 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003395 {
3396 mMemoryProgramCache = nullptr;
3397 }
Corentin Walleze4477002017-12-01 14:39:58 -05003398
3399 // Compute which buffer types are allowed
3400 mValidBufferBindings.reset();
3401 mValidBufferBindings.set(BufferBinding::ElementArray);
3402 mValidBufferBindings.set(BufferBinding::Array);
3403
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003404 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003405 {
3406 mValidBufferBindings.set(BufferBinding::PixelPack);
3407 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3408 }
3409
3410 if (getClientVersion() >= ES_3_0)
3411 {
3412 mValidBufferBindings.set(BufferBinding::CopyRead);
3413 mValidBufferBindings.set(BufferBinding::CopyWrite);
3414 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3415 mValidBufferBindings.set(BufferBinding::Uniform);
3416 }
3417
3418 if (getClientVersion() >= ES_3_1)
3419 {
3420 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3421 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3422 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3423 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3424 }
jchen107ae70d82018-07-06 13:47:01 +08003425
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003426 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003427
Jamie Madillef9fcd92018-11-28 14:03:59 -05003428 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003429 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003430 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3431 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3432 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3433 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3434 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3435 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003436
Jamie Madillac66f982018-10-09 18:30:01 -04003437 // Reinitialize state cache after extension changes.
3438 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003439}
3440
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003441void Context::initWorkarounds()
3442{
Jamie Madill761b02c2017-06-23 16:27:06 -04003443 // Apply back-end workarounds.
3444 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3445
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003446 // Lose the context upon out of memory error if the application is
3447 // expecting to watch for those events.
3448 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003449
3450 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3451 {
3452 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3453 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3454 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3455 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003456}
3457
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003458bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3459{
3460 return (instanceCount == 0) || noopDraw(mode, count);
3461}
3462
Jamie Madill526392d2018-11-16 09:35:14 -05003463angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003464{
Geoff Langa8cb2872018-03-09 16:09:40 -05003465 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003466 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003468 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003469}
3470
Jamie Madill526392d2018-11-16 09:35:14 -05003471angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003472{
Geoff Langa8cb2872018-03-09 16:09:40 -05003473 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003474 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3475 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003476 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003477 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003478}
3479
Jamie Madill132d15c2018-11-30 15:25:38 -05003480ANGLE_INLINE angle::Result Context::prepareForDispatch()
3481{
3482 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3483 return syncDirtyBits(mComputeDirtyBits);
3484}
3485
Jamie Madill526392d2018-11-16 09:35:14 -05003486angle::Result Context::syncState(const State::DirtyBits &bitMask,
3487 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003488{
Geoff Langa8cb2872018-03-09 16:09:40 -05003489 ANGLE_TRY(syncDirtyObjects(objectMask));
3490 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003491 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003492}
3493
Jamie Madillc29968b2016-01-20 11:17:23 -05003494void Context::blitFramebuffer(GLint srcX0,
3495 GLint srcY0,
3496 GLint srcX1,
3497 GLint srcY1,
3498 GLint dstX0,
3499 GLint dstY0,
3500 GLint dstX1,
3501 GLint dstY1,
3502 GLbitfield mask,
3503 GLenum filter)
3504{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003505 if (mask == 0)
3506 {
3507 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3508 // buffers are copied.
3509 return;
3510 }
3511
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003512 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003513 ASSERT(drawFramebuffer);
3514
3515 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3516 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3517
Jamie Madillbc918e72018-03-08 09:47:21 -05003518 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003519
Jamie Madill4f6592f2018-11-27 16:37:45 -05003520 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003521}
Jamie Madillc29968b2016-01-20 11:17:23 -05003522
3523void Context::clear(GLbitfield mask)
3524{
Geoff Langd4fff502017-09-22 11:28:28 -04003525 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003526 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003527}
3528
3529void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3530{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003531 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003532 const FramebufferAttachment *attachment = nullptr;
3533 if (buffer == GL_DEPTH)
3534 {
3535 attachment = framebufferObject->getDepthbuffer();
3536 }
3537 if (buffer == GL_COLOR &&
3538 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3539 {
3540 attachment = framebufferObject->getColorbuffer(drawbuffer);
3541 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003542 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3543 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003544 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003545 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003546 return;
3547 }
Geoff Langd4fff502017-09-22 11:28:28 -04003548 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003549 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003550}
3551
3552void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3553{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003554 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003555 const FramebufferAttachment *attachment = nullptr;
3556 if (buffer == GL_COLOR &&
3557 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3558 {
3559 attachment = framebufferObject->getColorbuffer(drawbuffer);
3560 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003561 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3562 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003563 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003564 {
3565 return;
3566 }
Geoff Langd4fff502017-09-22 11:28:28 -04003567 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003568 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003569}
3570
3571void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3572{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003573 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003574 const FramebufferAttachment *attachment = nullptr;
3575 if (buffer == GL_STENCIL)
3576 {
3577 attachment = framebufferObject->getStencilbuffer();
3578 }
3579 if (buffer == GL_COLOR &&
3580 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3581 {
3582 attachment = framebufferObject->getColorbuffer(drawbuffer);
3583 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003584 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3585 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003586 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003587 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003588 return;
3589 }
Geoff Langd4fff502017-09-22 11:28:28 -04003590 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003591 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003592}
3593
3594void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3595{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003596 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003597 ASSERT(framebufferObject);
3598
3599 // If a buffer is not present, the clear has no effect
3600 if (framebufferObject->getDepthbuffer() == nullptr &&
3601 framebufferObject->getStencilbuffer() == nullptr)
3602 {
3603 return;
3604 }
3605
Geoff Langd4fff502017-09-22 11:28:28 -04003606 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3607 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003608}
3609
3610void Context::readPixels(GLint x,
3611 GLint y,
3612 GLsizei width,
3613 GLsizei height,
3614 GLenum format,
3615 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003616 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003617{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003618 if (width == 0 || height == 0)
3619 {
3620 return;
3621 }
3622
Jamie Madillbc918e72018-03-08 09:47:21 -05003623 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003624
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003625 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003626 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003627
3628 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003629 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003630}
3631
Brandon Jones59770802018-04-02 13:18:42 -07003632void Context::readPixelsRobust(GLint x,
3633 GLint y,
3634 GLsizei width,
3635 GLsizei height,
3636 GLenum format,
3637 GLenum type,
3638 GLsizei bufSize,
3639 GLsizei *length,
3640 GLsizei *columns,
3641 GLsizei *rows,
3642 void *pixels)
3643{
3644 readPixels(x, y, width, height, format, type, pixels);
3645}
3646
3647void Context::readnPixelsRobust(GLint x,
3648 GLint y,
3649 GLsizei width,
3650 GLsizei height,
3651 GLenum format,
3652 GLenum type,
3653 GLsizei bufSize,
3654 GLsizei *length,
3655 GLsizei *columns,
3656 GLsizei *rows,
3657 void *data)
3658{
3659 readPixels(x, y, width, height, format, type, data);
3660}
3661
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003662void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003663 GLint level,
3664 GLenum internalformat,
3665 GLint x,
3666 GLint y,
3667 GLsizei width,
3668 GLsizei height,
3669 GLint border)
3670{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003671 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003672 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003673
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 Rectangle sourceArea(x, y, width, height);
3675
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003676 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003677 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003678 ANGLE_CONTEXT_TRY(
3679 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003680}
3681
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003682void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003683 GLint level,
3684 GLint xoffset,
3685 GLint yoffset,
3686 GLint x,
3687 GLint y,
3688 GLsizei width,
3689 GLsizei height)
3690{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003691 if (width == 0 || height == 0)
3692 {
3693 return;
3694 }
3695
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003696 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003697 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003698
Jamie Madillc29968b2016-01-20 11:17:23 -05003699 Offset destOffset(xoffset, yoffset, 0);
3700 Rectangle sourceArea(x, y, width, height);
3701
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003702 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003703 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003704 ANGLE_CONTEXT_TRY(
3705 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003706}
3707
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003708void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 GLint level,
3710 GLint xoffset,
3711 GLint yoffset,
3712 GLint zoffset,
3713 GLint x,
3714 GLint y,
3715 GLsizei width,
3716 GLsizei height)
3717{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003718 if (width == 0 || height == 0)
3719 {
3720 return;
3721 }
3722
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003723 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003724 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725
Jamie Madillc29968b2016-01-20 11:17:23 -05003726 Offset destOffset(xoffset, yoffset, zoffset);
3727 Rectangle sourceArea(x, y, width, height);
3728
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003729 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003730 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003731 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3732 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003733}
3734
3735void Context::framebufferTexture2D(GLenum target,
3736 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003737 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 GLuint texture,
3739 GLint level)
3740{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003741 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003742 ASSERT(framebuffer);
3743
3744 if (texture != 0)
3745 {
3746 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003747 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003748 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 }
3750 else
3751 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003752 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003754
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003755 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003756}
3757
3758void Context::framebufferRenderbuffer(GLenum target,
3759 GLenum attachment,
3760 GLenum renderbuffertarget,
3761 GLuint renderbuffer)
3762{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003763 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003764 ASSERT(framebuffer);
3765
3766 if (renderbuffer != 0)
3767 {
3768 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003769
Jamie Madillcc129372018-04-12 09:13:18 -04003770 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003771 renderbufferObject);
3772 }
3773 else
3774 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003775 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003776 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003777
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003778 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003779}
3780
3781void Context::framebufferTextureLayer(GLenum target,
3782 GLenum attachment,
3783 GLuint texture,
3784 GLint level,
3785 GLint layer)
3786{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003787 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 ASSERT(framebuffer);
3789
3790 if (texture != 0)
3791 {
3792 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003793 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003794 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003795 }
3796 else
3797 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003798 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003799 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003800
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003801 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003802}
3803
Brandon Jones59770802018-04-02 13:18:42 -07003804void Context::framebufferTextureMultiviewLayered(GLenum target,
3805 GLenum attachment,
3806 GLuint texture,
3807 GLint level,
3808 GLint baseViewIndex,
3809 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003810{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003811 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003812 ASSERT(framebuffer);
3813
3814 if (texture != 0)
3815 {
3816 Texture *textureObj = getTexture(texture);
3817
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003818 ImageIndex index;
3819 if (textureObj->getType() == TextureType::_2DArray)
3820 {
3821 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3822 }
3823 else
3824 {
3825 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3826 ASSERT(level == 0);
3827 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3828 }
Martin Radev82ef7742017-08-08 17:44:58 +03003829 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3830 numViews, baseViewIndex);
3831 }
3832 else
3833 {
3834 framebuffer->resetAttachment(this, attachment);
3835 }
3836
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003837 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003838}
3839
Brandon Jones59770802018-04-02 13:18:42 -07003840void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3841 GLenum attachment,
3842 GLuint texture,
3843 GLint level,
3844 GLsizei numViews,
3845 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003846{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003847 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003848 ASSERT(framebuffer);
3849
3850 if (texture != 0)
3851 {
3852 Texture *textureObj = getTexture(texture);
3853
3854 ImageIndex index = ImageIndex::Make2D(level);
3855 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3856 textureObj, numViews, viewportOffsets);
3857 }
3858 else
3859 {
3860 framebuffer->resetAttachment(this, attachment);
3861 }
3862
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003863 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003864}
3865
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003866void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3867{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003868 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003869 ASSERT(framebuffer);
3870
3871 if (texture != 0)
3872 {
3873 Texture *textureObj = getTexture(texture);
3874
3875 ImageIndex index = ImageIndex::MakeFromType(
3876 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3877 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3878 }
3879 else
3880 {
3881 framebuffer->resetAttachment(this, attachment);
3882 }
3883
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003884 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003885}
3886
Jamie Madillc29968b2016-01-20 11:17:23 -05003887void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3888{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003889 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003890 ASSERT(framebuffer);
3891 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003892 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003893 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894}
3895
3896void Context::readBuffer(GLenum mode)
3897{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003898 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003899 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003900 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003901}
3902
3903void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3904{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003905 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003906 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003907
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003908 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003909 ASSERT(framebuffer);
3910
3911 // The specification isn't clear what should be done when the framebuffer isn't complete.
3912 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003913 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003914}
3915
3916void Context::invalidateFramebuffer(GLenum target,
3917 GLsizei numAttachments,
3918 const GLenum *attachments)
3919{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003920 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003921 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003922
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003923 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003924 ASSERT(framebuffer);
3925
Jamie Madill427064d2018-04-13 16:20:34 -04003926 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003927 {
Jamie Madill437fa652016-05-03 15:13:24 -04003928 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003929 }
Jamie Madill437fa652016-05-03 15:13:24 -04003930
Jamie Madill4f6592f2018-11-27 16:37:45 -05003931 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003932}
3933
3934void Context::invalidateSubFramebuffer(GLenum target,
3935 GLsizei numAttachments,
3936 const GLenum *attachments,
3937 GLint x,
3938 GLint y,
3939 GLsizei width,
3940 GLsizei height)
3941{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003942 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003943 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003944
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003945 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003946 ASSERT(framebuffer);
3947
Jamie Madill427064d2018-04-13 16:20:34 -04003948 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003949 {
Jamie Madill437fa652016-05-03 15:13:24 -04003950 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003951 }
Jamie Madill437fa652016-05-03 15:13:24 -04003952
3953 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003954 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003955}
3956
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003957void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003958 GLint level,
3959 GLint internalformat,
3960 GLsizei width,
3961 GLsizei height,
3962 GLint border,
3963 GLenum format,
3964 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003965 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003966{
Jamie Madillbc918e72018-03-08 09:47:21 -05003967 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003968
3969 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003970 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003971 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003972 internalformat, size, format, type,
3973 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003974}
3975
Brandon Jones59770802018-04-02 13:18:42 -07003976void Context::texImage2DRobust(TextureTarget target,
3977 GLint level,
3978 GLint internalformat,
3979 GLsizei width,
3980 GLsizei height,
3981 GLint border,
3982 GLenum format,
3983 GLenum type,
3984 GLsizei bufSize,
3985 const void *pixels)
3986{
3987 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3988}
3989
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003990void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003991 GLint level,
3992 GLint internalformat,
3993 GLsizei width,
3994 GLsizei height,
3995 GLsizei depth,
3996 GLint border,
3997 GLenum format,
3998 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003999 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004000{
Jamie Madillbc918e72018-03-08 09:47:21 -05004001 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004002
4003 Extents size(width, height, depth);
4004 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004005 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05004006 NonCubeTextureTypeToTarget(target), level, internalformat,
4007 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004008}
4009
Brandon Jones59770802018-04-02 13:18:42 -07004010void Context::texImage3DRobust(TextureType target,
4011 GLint level,
4012 GLint internalformat,
4013 GLsizei width,
4014 GLsizei height,
4015 GLsizei depth,
4016 GLint border,
4017 GLenum format,
4018 GLenum type,
4019 GLsizei bufSize,
4020 const void *pixels)
4021{
4022 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4023}
4024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004025void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004026 GLint level,
4027 GLint xoffset,
4028 GLint yoffset,
4029 GLsizei width,
4030 GLsizei height,
4031 GLenum format,
4032 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004033 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004034{
4035 // Zero sized uploads are valid but no-ops
4036 if (width == 0 || height == 0)
4037 {
4038 return;
4039 }
4040
Jamie Madillbc918e72018-03-08 09:47:21 -05004041 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004042
4043 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004044 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004045
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004046 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004047
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004048 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004049 level, area, format, type,
4050 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004051}
4052
Brandon Jones59770802018-04-02 13:18:42 -07004053void Context::texSubImage2DRobust(TextureTarget target,
4054 GLint level,
4055 GLint xoffset,
4056 GLint yoffset,
4057 GLsizei width,
4058 GLsizei height,
4059 GLenum format,
4060 GLenum type,
4061 GLsizei bufSize,
4062 const void *pixels)
4063{
4064 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4065}
4066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004067void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004068 GLint level,
4069 GLint xoffset,
4070 GLint yoffset,
4071 GLint zoffset,
4072 GLsizei width,
4073 GLsizei height,
4074 GLsizei depth,
4075 GLenum format,
4076 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004077 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004078{
4079 // Zero sized uploads are valid but no-ops
4080 if (width == 0 || height == 0 || depth == 0)
4081 {
4082 return;
4083 }
4084
Jamie Madillbc918e72018-03-08 09:47:21 -05004085 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004086
4087 Box area(xoffset, yoffset, zoffset, width, height, depth);
4088 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004089
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004090 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004091
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004092 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004093 NonCubeTextureTypeToTarget(target), level, area, format,
4094 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004095}
4096
Brandon Jones59770802018-04-02 13:18:42 -07004097void Context::texSubImage3DRobust(TextureType target,
4098 GLint level,
4099 GLint xoffset,
4100 GLint yoffset,
4101 GLint zoffset,
4102 GLsizei width,
4103 GLsizei height,
4104 GLsizei depth,
4105 GLenum format,
4106 GLenum type,
4107 GLsizei bufSize,
4108 const void *pixels)
4109{
4110 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4111 pixels);
4112}
4113
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004114void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004115 GLint level,
4116 GLenum internalformat,
4117 GLsizei width,
4118 GLsizei height,
4119 GLint border,
4120 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004121 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004122{
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004124
4125 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004126 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004127 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004128 internalformat, size, imageSize,
4129 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::compressedTexImage2DRobust(TextureTarget target,
4133 GLint level,
4134 GLenum internalformat,
4135 GLsizei width,
4136 GLsizei height,
4137 GLint border,
4138 GLsizei imageSize,
4139 GLsizei dataSize,
4140 const GLvoid *data)
4141{
4142 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4143}
4144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004145void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004146 GLint level,
4147 GLenum internalformat,
4148 GLsizei width,
4149 GLsizei height,
4150 GLsizei depth,
4151 GLint border,
4152 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004153 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004154{
Jamie Madillbc918e72018-03-08 09:47:21 -05004155 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004156
4157 Extents size(width, height, depth);
4158 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004159 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004160 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004161 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004162}
4163
Brandon Jones59770802018-04-02 13:18:42 -07004164void Context::compressedTexImage3DRobust(TextureType target,
4165 GLint level,
4166 GLenum internalformat,
4167 GLsizei width,
4168 GLsizei height,
4169 GLsizei depth,
4170 GLint border,
4171 GLsizei imageSize,
4172 GLsizei dataSize,
4173 const GLvoid *data)
4174{
4175 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4176 data);
4177}
4178
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004179void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004180 GLint level,
4181 GLint xoffset,
4182 GLint yoffset,
4183 GLsizei width,
4184 GLsizei height,
4185 GLenum format,
4186 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004187 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004188{
Jamie Madillbc918e72018-03-08 09:47:21 -05004189 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004190
4191 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004192 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004193 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004194 area, format, imageSize,
4195 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004196}
4197
Brandon Jones59770802018-04-02 13:18:42 -07004198void Context::compressedTexSubImage2DRobust(TextureTarget target,
4199 GLint level,
4200 GLint xoffset,
4201 GLint yoffset,
4202 GLsizei width,
4203 GLsizei height,
4204 GLenum format,
4205 GLsizei imageSize,
4206 GLsizei dataSize,
4207 const GLvoid *data)
4208{
4209 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4210 data);
4211}
4212
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004213void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004214 GLint level,
4215 GLint xoffset,
4216 GLint yoffset,
4217 GLint zoffset,
4218 GLsizei width,
4219 GLsizei height,
4220 GLsizei depth,
4221 GLenum format,
4222 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004223 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004224{
4225 // Zero sized uploads are valid but no-ops
4226 if (width == 0 || height == 0)
4227 {
4228 return;
4229 }
4230
Jamie Madillbc918e72018-03-08 09:47:21 -05004231 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004232
4233 Box area(xoffset, yoffset, zoffset, width, height, depth);
4234 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004235 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004236 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004237 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004238}
4239
Brandon Jones59770802018-04-02 13:18:42 -07004240void Context::compressedTexSubImage3DRobust(TextureType target,
4241 GLint level,
4242 GLint xoffset,
4243 GLint yoffset,
4244 GLint zoffset,
4245 GLsizei width,
4246 GLsizei height,
4247 GLsizei depth,
4248 GLenum format,
4249 GLsizei imageSize,
4250 GLsizei dataSize,
4251 const GLvoid *data)
4252{
4253 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4254 imageSize, data);
4255}
4256
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004257void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004258{
4259 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004260 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263void Context::copyTexture(GLuint sourceId,
4264 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004265 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004266 GLuint destId,
4267 GLint destLevel,
4268 GLint internalFormat,
4269 GLenum destType,
4270 GLboolean unpackFlipY,
4271 GLboolean unpackPremultiplyAlpha,
4272 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004273{
Jamie Madillbc918e72018-03-08 09:47:21 -05004274 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004275
4276 gl::Texture *sourceTexture = getTexture(sourceId);
4277 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004278 ANGLE_CONTEXT_TRY(
4279 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4280 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4281 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004282}
4283
Jamie Madill007530e2017-12-28 14:27:04 -05004284void Context::copySubTexture(GLuint sourceId,
4285 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004286 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004287 GLuint destId,
4288 GLint destLevel,
4289 GLint xoffset,
4290 GLint yoffset,
4291 GLint x,
4292 GLint y,
4293 GLsizei width,
4294 GLsizei height,
4295 GLboolean unpackFlipY,
4296 GLboolean unpackPremultiplyAlpha,
4297 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004298{
4299 // Zero sized copies are valid but no-ops
4300 if (width == 0 || height == 0)
4301 {
4302 return;
4303 }
4304
Jamie Madillbc918e72018-03-08 09:47:21 -05004305 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004306
4307 gl::Texture *sourceTexture = getTexture(sourceId);
4308 gl::Texture *destTexture = getTexture(destId);
4309 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004310 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004311 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4312 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4313 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4314 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004315}
4316
4317void Context::copyTexture3D(GLuint sourceId,
4318 GLint sourceLevel,
4319 TextureTarget destTarget,
4320 GLuint destId,
4321 GLint destLevel,
4322 GLint internalFormat,
4323 GLenum destType,
4324 GLboolean unpackFlipY,
4325 GLboolean unpackPremultiplyAlpha,
4326 GLboolean unpackUnmultiplyAlpha)
4327{
4328 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4329
4330 Texture *sourceTexture = getTexture(sourceId);
4331 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004332 ANGLE_CONTEXT_TRY(
4333 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4334 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4335 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004336}
4337
4338void Context::copySubTexture3D(GLuint sourceId,
4339 GLint sourceLevel,
4340 TextureTarget destTarget,
4341 GLuint destId,
4342 GLint destLevel,
4343 GLint xoffset,
4344 GLint yoffset,
4345 GLint zoffset,
4346 GLint x,
4347 GLint y,
4348 GLint z,
4349 GLsizei width,
4350 GLsizei height,
4351 GLsizei depth,
4352 GLboolean unpackFlipY,
4353 GLboolean unpackPremultiplyAlpha,
4354 GLboolean unpackUnmultiplyAlpha)
4355{
4356 // Zero sized copies are valid but no-ops
4357 if (width == 0 || height == 0 || depth == 0)
4358 {
4359 return;
4360 }
4361
4362 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4363
4364 Texture *sourceTexture = getTexture(sourceId);
4365 Texture *destTexture = getTexture(destId);
4366 Offset offset(xoffset, yoffset, zoffset);
4367 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004368 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4369 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4370 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4371 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004372}
4373
Jamie Madill007530e2017-12-28 14:27:04 -05004374void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004375{
Jamie Madillbc918e72018-03-08 09:47:21 -05004376 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004377
4378 gl::Texture *sourceTexture = getTexture(sourceId);
4379 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004380 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004381}
4382
Corentin Wallez336129f2017-10-17 15:55:40 -04004383void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004384{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004385 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004386 ASSERT(buffer);
4387
Geoff Lang496c02d2016-10-20 11:38:11 -07004388 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004389}
4390
Brandon Jones59770802018-04-02 13:18:42 -07004391void Context::getBufferPointervRobust(BufferBinding target,
4392 GLenum pname,
4393 GLsizei bufSize,
4394 GLsizei *length,
4395 void **params)
4396{
4397 getBufferPointerv(target, pname, params);
4398}
4399
Corentin Wallez336129f2017-10-17 15:55:40 -04004400void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004401{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004402 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004403 ASSERT(buffer);
4404
Jamie Madill7c985f52018-11-29 18:16:17 -05004405 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004406 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004407 return nullptr;
4408 }
4409
4410 return buffer->getMapPointer();
4411}
4412
Corentin Wallez336129f2017-10-17 15:55:40 -04004413GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004414{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004415 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004416 ASSERT(buffer);
4417
4418 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004419 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004420 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004421 return GL_FALSE;
4422 }
4423
4424 return result;
4425}
4426
Corentin Wallez336129f2017-10-17 15:55:40 -04004427void *Context::mapBufferRange(BufferBinding target,
4428 GLintptr offset,
4429 GLsizeiptr length,
4430 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004431{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004432 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004433 ASSERT(buffer);
4434
Jamie Madill7c985f52018-11-29 18:16:17 -05004435 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004436 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004437 return nullptr;
4438 }
4439
4440 return buffer->getMapPointer();
4441}
4442
Corentin Wallez336129f2017-10-17 15:55:40 -04004443void Context::flushMappedBufferRange(BufferBinding /*target*/,
4444 GLintptr /*offset*/,
4445 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004446{
4447 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4448}
4449
Jamie Madill526392d2018-11-16 09:35:14 -05004450angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004451{
Geoff Langa8cb2872018-03-09 16:09:40 -05004452 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004453}
4454
Jamie Madill526392d2018-11-16 09:35:14 -05004455angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004456{
Geoff Langa8cb2872018-03-09 16:09:40 -05004457 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004458}
4459
Jamie Madill526392d2018-11-16 09:35:14 -05004460angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004461{
Geoff Langa8cb2872018-03-09 16:09:40 -05004462 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004463}
4464
Jamie Madill526392d2018-11-16 09:35:14 -05004465angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004466{
4467 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4468
4469 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4470 ANGLE_TRY(syncDirtyBits());
4471
Jamie Madill7c985f52018-11-29 18:16:17 -05004472 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004473}
4474
Jiajia Qin5451d532017-11-16 17:16:34 +08004475void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4476{
4477 UNIMPLEMENTED();
4478}
4479
Jamie Madillc20ab272016-06-09 07:20:46 -07004480void Context::activeTexture(GLenum texture)
4481{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004482 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
Jamie Madill876429b2017-04-20 15:46:24 -04004485void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004486{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004487 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004490void Context::blendEquation(GLenum mode)
4491{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004492 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004493}
4494
Jamie Madillc20ab272016-06-09 07:20:46 -07004495void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4496{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004497 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498}
4499
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004500void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4501{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004502 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004503}
4504
Jamie Madillc20ab272016-06-09 07:20:46 -07004505void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4506{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004507 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
Jamie Madill876429b2017-04-20 15:46:24 -04004510void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004511{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004512 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004513}
4514
Jamie Madill876429b2017-04-20 15:46:24 -04004515void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004516{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004517 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
4520void Context::clearStencil(GLint s)
4521{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004522 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
4525void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4526{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004527 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4528 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004529}
4530
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004531void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004532{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004533 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004534}
4535
4536void Context::depthFunc(GLenum func)
4537{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004538 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004539}
4540
4541void Context::depthMask(GLboolean flag)
4542{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004543 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004544}
4545
Jamie Madill876429b2017-04-20 15:46:24 -04004546void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004547{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004548 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004549}
4550
4551void Context::disable(GLenum cap)
4552{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004553 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004554 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::disableVertexAttribArray(GLuint index)
4558{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004559 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004560 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::enable(GLenum cap)
4564{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004565 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004566 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::enableVertexAttribArray(GLuint index)
4570{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004571 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004572 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
4575void Context::frontFace(GLenum mode)
4576{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004577 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004578}
4579
4580void Context::hint(GLenum target, GLenum mode)
4581{
4582 switch (target)
4583 {
4584 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004585 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586 break;
4587
4588 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004589 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004590 break;
4591
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004592 case GL_PERSPECTIVE_CORRECTION_HINT:
4593 case GL_POINT_SMOOTH_HINT:
4594 case GL_LINE_SMOOTH_HINT:
4595 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004596 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004597 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004598 default:
4599 UNREACHABLE();
4600 return;
4601 }
4602}
4603
4604void Context::lineWidth(GLfloat width)
4605{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004606 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
4609void Context::pixelStorei(GLenum pname, GLint param)
4610{
4611 switch (pname)
4612 {
4613 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004614 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615 break;
4616
4617 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004618 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004619 break;
4620
4621 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004622 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623 break;
4624
4625 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004626 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004627 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004628 break;
4629
4630 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004631 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004632 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633 break;
4634
4635 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004636 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004637 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638 break;
4639
4640 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004641 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004642 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004643 break;
4644
4645 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004646 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004647 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648 break;
4649
4650 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004651 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004652 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653 break;
4654
4655 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004656 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004657 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658 break;
4659
4660 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004661 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004662 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663 break;
4664
4665 default:
4666 UNREACHABLE();
4667 return;
4668 }
4669}
4670
4671void Context::polygonOffset(GLfloat factor, GLfloat units)
4672{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004673 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
Jamie Madill876429b2017-04-20 15:46:24 -04004676void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004677{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004678 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004679}
4680
Jiawei Shaodb342272017-09-27 10:21:45 +08004681void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4682{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004683 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004684}
4685
Jamie Madillc20ab272016-06-09 07:20:46 -07004686void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4687{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004688 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004689}
4690
4691void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4692{
4693 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4694 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004695 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004696 }
4697
4698 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4699 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004700 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004701 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004702
4703 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704}
4705
4706void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4707{
4708 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4709 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004710 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004711 }
4712
4713 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4714 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004715 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004716 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004717
4718 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004719}
4720
4721void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4722{
4723 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4724 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004725 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004726 }
4727
4728 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4729 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004730 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004731 }
4732}
4733
4734void Context::vertexAttrib1f(GLuint index, GLfloat x)
4735{
4736 GLfloat vals[4] = {x, 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::vertexAttrib1fv(GLuint index, const GLfloat *values)
4742{
4743 GLfloat vals[4] = {values[0], 0, 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::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4749{
4750 GLfloat vals[4] = {x, y, 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::vertexAttrib2fv(GLuint index, const GLfloat *values)
4756{
4757 GLfloat vals[4] = {values[0], values[1], 0, 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::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4763{
4764 GLfloat vals[4] = {x, y, z, 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::vertexAttrib3fv(GLuint index, const GLfloat *values)
4770{
4771 GLfloat vals[4] = {values[0], values[1], values[2], 1};
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::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4777{
4778 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004779 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004780 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004781}
4782
4783void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4784{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004785 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004786 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004787}
4788
4789void Context::vertexAttribPointer(GLuint index,
4790 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004791 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004792 GLboolean normalized,
4793 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004794 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004795{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004796 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
Jamie Madill6e18a232019-01-16 13:27:14 -05004797 type, ConvertToBool(normalized), stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004798 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004799}
4800
Shao80957d92017-02-20 21:25:59 +08004801void Context::vertexAttribFormat(GLuint attribIndex,
4802 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004803 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004804 GLboolean normalized,
4805 GLuint relativeOffset)
4806{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004807 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4808 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004809 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004810}
4811
4812void Context::vertexAttribIFormat(GLuint attribIndex,
4813 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004814 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004815 GLuint relativeOffset)
4816{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004817 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004818 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004819}
4820
4821void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4822{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004823 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004824 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004825}
4826
Jiajia Qin5451d532017-11-16 17:16:34 +08004827void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004828{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004829 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004830 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004831}
4832
Jamie Madillc20ab272016-06-09 07:20:46 -07004833void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4834{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004835 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004836}
4837
4838void Context::vertexAttribIPointer(GLuint index,
4839 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004840 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004841 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004842 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004843{
Jamie Madill6e18a232019-01-16 13:27:14 -05004844 mState.setVertexAttribIPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4845 type, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004846 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004847}
4848
4849void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4850{
4851 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004852 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004853 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004854}
4855
4856void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4857{
4858 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004859 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004860 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004861}
4862
4863void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4864{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004865 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004866 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004867}
4868
4869void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4870{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004871 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004872 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004873}
4874
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004875void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4876{
4877 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004878 getState().getVertexAttribCurrentValue(index);
4879 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004880 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4881 currentValues, pname, params);
4882}
4883
Brandon Jones59770802018-04-02 13:18:42 -07004884void Context::getVertexAttribivRobust(GLuint index,
4885 GLenum pname,
4886 GLsizei bufSize,
4887 GLsizei *length,
4888 GLint *params)
4889{
4890 getVertexAttribiv(index, pname, params);
4891}
4892
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004893void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4894{
4895 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004896 getState().getVertexAttribCurrentValue(index);
4897 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004898 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4899 currentValues, pname, params);
4900}
4901
Brandon Jones59770802018-04-02 13:18:42 -07004902void Context::getVertexAttribfvRobust(GLuint index,
4903 GLenum pname,
4904 GLsizei bufSize,
4905 GLsizei *length,
4906 GLfloat *params)
4907{
4908 getVertexAttribfv(index, pname, params);
4909}
4910
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004911void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4912{
4913 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004914 getState().getVertexAttribCurrentValue(index);
4915 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004916 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4917 currentValues, pname, params);
4918}
4919
Brandon Jones59770802018-04-02 13:18:42 -07004920void Context::getVertexAttribIivRobust(GLuint index,
4921 GLenum pname,
4922 GLsizei bufSize,
4923 GLsizei *length,
4924 GLint *params)
4925{
4926 getVertexAttribIiv(index, pname, params);
4927}
4928
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004929void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4930{
4931 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004932 getState().getVertexAttribCurrentValue(index);
4933 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004934 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4935 currentValues, pname, params);
4936}
4937
Brandon Jones59770802018-04-02 13:18:42 -07004938void Context::getVertexAttribIuivRobust(GLuint index,
4939 GLenum pname,
4940 GLsizei bufSize,
4941 GLsizei *length,
4942 GLuint *params)
4943{
4944 getVertexAttribIuiv(index, pname, params);
4945}
4946
Jamie Madill876429b2017-04-20 15:46:24 -04004947void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004948{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004949 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004950 QueryVertexAttribPointerv(attrib, pname, pointer);
4951}
4952
Brandon Jones59770802018-04-02 13:18:42 -07004953void Context::getVertexAttribPointervRobust(GLuint index,
4954 GLenum pname,
4955 GLsizei bufSize,
4956 GLsizei *length,
4957 void **pointer)
4958{
4959 getVertexAttribPointerv(index, pname, pointer);
4960}
4961
Jamie Madillc20ab272016-06-09 07:20:46 -07004962void Context::debugMessageControl(GLenum source,
4963 GLenum type,
4964 GLenum severity,
4965 GLsizei count,
4966 const GLuint *ids,
4967 GLboolean enabled)
4968{
4969 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004970 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4971 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004972}
4973
4974void Context::debugMessageInsert(GLenum source,
4975 GLenum type,
4976 GLuint id,
4977 GLenum severity,
4978 GLsizei length,
4979 const GLchar *buf)
4980{
4981 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004982 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004983}
4984
4985void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4986{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004987 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004988}
4989
4990GLuint Context::getDebugMessageLog(GLuint count,
4991 GLsizei bufSize,
4992 GLenum *sources,
4993 GLenum *types,
4994 GLuint *ids,
4995 GLenum *severities,
4996 GLsizei *lengths,
4997 GLchar *messageLog)
4998{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004999 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
5000 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005001}
5002
5003void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5004{
5005 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005006 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005007 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005008}
5009
5010void Context::popDebugGroup()
5011{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005012 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005013 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005014}
5015
Corentin Wallez336129f2017-10-17 15:55:40 -04005016void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005017{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005018 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005019 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005020 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005021}
5022
Corentin Wallez336129f2017-10-17 15:55:40 -04005023void Context::bufferSubData(BufferBinding target,
5024 GLintptr offset,
5025 GLsizeiptr size,
5026 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005027{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005028 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005029 {
5030 return;
5031 }
5032
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005033 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005034 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005035 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005036}
5037
Jamie Madillef300b12016-10-07 15:12:09 -04005038void Context::attachShader(GLuint program, GLuint shader)
5039{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005040 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5041 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005042 ASSERT(programObject && shaderObject);
5043 programObject->attachShader(shaderObject);
5044}
5045
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005046const Workarounds &Context::getWorkarounds() const
5047{
5048 return mWorkarounds;
5049}
5050
Corentin Wallez336129f2017-10-17 15:55:40 -04005051void Context::copyBufferSubData(BufferBinding readTarget,
5052 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005053 GLintptr readOffset,
5054 GLintptr writeOffset,
5055 GLsizeiptr size)
5056{
5057 // if size is zero, the copy is a successful no-op
5058 if (size == 0)
5059 {
5060 return;
5061 }
5062
5063 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005064 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5065 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005066
Jamie Madill4f6592f2018-11-27 16:37:45 -05005067 ANGLE_CONTEXT_TRY(
5068 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005069}
5070
Jamie Madill01a80ee2016-11-07 12:06:18 -05005071void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5072{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005073 // Ideally we could share the program query with the validation layer if possible.
5074 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005075 ASSERT(programObject);
5076 programObject->bindAttributeLocation(index, name);
5077}
5078
Corentin Wallez336129f2017-10-17 15:55:40 -04005079void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005080{
5081 bindBufferRange(target, index, buffer, 0, 0);
5082}
5083
Corentin Wallez336129f2017-10-17 15:55:40 -04005084void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005085 GLuint index,
5086 GLuint buffer,
5087 GLintptr offset,
5088 GLsizeiptr size)
5089{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005090 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5091 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005092 if (target == BufferBinding::Uniform)
5093 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005094 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005095 mStateCache.onUniformBufferStateChange(this);
5096 }
5097 else
5098 {
5099 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005100 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005101}
5102
Jamie Madill01a80ee2016-11-07 12:06:18 -05005103void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5104{
5105 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5106 {
5107 bindReadFramebuffer(framebuffer);
5108 }
5109
5110 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5111 {
5112 bindDrawFramebuffer(framebuffer);
5113 }
5114}
5115
5116void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5117{
5118 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005119 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5120 mImplementation.get(), renderbuffer);
5121 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005122}
5123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005124void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005125 GLsizei samples,
5126 GLenum internalformat,
5127 GLsizei width,
5128 GLsizei height,
5129 GLboolean fixedsamplelocations)
5130{
5131 Extents size(width, height, 1);
5132 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005133 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5134 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005135}
5136
Olli Etuaho89664842018-08-24 14:45:36 +03005137void Context::texStorage3DMultisample(TextureType target,
5138 GLsizei samples,
5139 GLenum internalformat,
5140 GLsizei width,
5141 GLsizei height,
5142 GLsizei depth,
5143 GLboolean fixedsamplelocations)
5144{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005145 Extents size(width, height, depth);
5146 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005147 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5148 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005149}
5150
JiangYizhoubddc46b2016-12-09 09:50:51 +08005151void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5152{
JiangYizhou5b03f472017-01-09 10:22:53 +08005153 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5154 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005155 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5156 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005157
5158 switch (pname)
5159 {
5160 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005161 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005162 break;
5163 default:
5164 UNREACHABLE();
5165 }
5166}
5167
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005168void Context::getMultisamplefvRobust(GLenum pname,
5169 GLuint index,
5170 GLsizei bufSize,
5171 GLsizei *length,
5172 GLfloat *val)
5173{
5174 UNIMPLEMENTED();
5175}
5176
Jamie Madille8fb6402017-02-14 17:56:40 -05005177void Context::renderbufferStorage(GLenum target,
5178 GLenum internalformat,
5179 GLsizei width,
5180 GLsizei height)
5181{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005182 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5183 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5184
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005185 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005186 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005187}
5188
5189void Context::renderbufferStorageMultisample(GLenum target,
5190 GLsizei samples,
5191 GLenum internalformat,
5192 GLsizei width,
5193 GLsizei height)
5194{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005195 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5196 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005197
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005198 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005199 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005200 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005201}
5202
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005203void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5204{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005205 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005206 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005207}
5208
JiangYizhoue18e6392017-02-20 10:32:23 +08005209void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5210{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005211 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005212 QueryFramebufferParameteriv(framebuffer, pname, params);
5213}
5214
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005215void Context::getFramebufferParameterivRobust(GLenum target,
5216 GLenum pname,
5217 GLsizei bufSize,
5218 GLsizei *length,
5219 GLint *params)
5220{
5221 UNIMPLEMENTED();
5222}
5223
Jiajia Qin5451d532017-11-16 17:16:34 +08005224void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005225{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005226 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005227 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005228}
5229
Jamie Madilldec86232018-07-11 09:01:18 -04005230bool Context::getScratchBuffer(size_t requstedSizeBytes,
5231 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005232{
Jamie Madilldec86232018-07-11 09:01:18 -04005233 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005234}
5235
Jamie Madilldec86232018-07-11 09:01:18 -04005236bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5237 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005238{
Jamie Madilldec86232018-07-11 09:01:18 -04005239 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005240}
5241
Xinghua Cao2b396592017-03-29 15:36:04 +08005242void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5243{
5244 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5245 {
5246 return;
5247 }
5248
Xinghua Cao10a4d432017-11-28 14:46:26 +08005249 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005250 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005251}
5252
Jiajia Qin5451d532017-11-16 17:16:34 +08005253void Context::dispatchComputeIndirect(GLintptr indirect)
5254{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005255 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005256 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005257}
5258
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005259void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005260 GLsizei levels,
5261 GLenum internalFormat,
5262 GLsizei width,
5263 GLsizei height)
5264{
5265 Extents size(width, height, 1);
5266 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005267 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005268}
5269
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005270void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005271 GLsizei levels,
5272 GLenum internalFormat,
5273 GLsizei width,
5274 GLsizei height,
5275 GLsizei depth)
5276{
5277 Extents size(width, height, depth);
5278 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005279 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005280}
5281
Jiajia Qin5451d532017-11-16 17:16:34 +08005282void Context::memoryBarrier(GLbitfield barriers)
5283{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005284 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005285}
5286
5287void Context::memoryBarrierByRegion(GLbitfield barriers)
5288{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005289 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005290}
5291
Austin Eng1bf18ce2018-10-19 15:34:02 -07005292void Context::multiDrawArrays(PrimitiveMode mode,
5293 const GLint *firsts,
5294 const GLsizei *counts,
5295 GLsizei drawcount)
5296{
5297 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005298 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005299 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5300 if (hasDrawID)
5301 {
5302 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5303 {
5304 if (noopDraw(mode, counts[drawID]))
5305 {
5306 continue;
5307 }
5308 programObject->setDrawIDUniform(drawID);
5309 ANGLE_CONTEXT_TRY(
5310 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005311 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005312 }
5313 }
5314 else
5315 {
5316 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5317 {
5318 if (noopDraw(mode, counts[drawID]))
5319 {
5320 continue;
5321 }
5322 ANGLE_CONTEXT_TRY(
5323 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005324 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005325 }
5326 }
5327}
5328
5329void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5330 const GLint *firsts,
5331 const GLsizei *counts,
5332 const GLsizei *instanceCounts,
5333 GLsizei drawcount)
5334{
5335 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005336 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005337 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5338 if (hasDrawID)
5339 {
5340 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5341 {
5342 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5343 {
5344 continue;
5345 }
5346 programObject->setDrawIDUniform(drawID);
5347 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5348 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005349 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005350 }
5351 }
5352 else
5353 {
5354 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5355 {
5356 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5357 {
5358 continue;
5359 }
5360 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5361 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005362 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005363 }
5364 }
5365}
5366
5367void Context::multiDrawElements(PrimitiveMode mode,
5368 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005369 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005370 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005371 GLsizei drawcount)
5372{
5373 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005374 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005375 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5376 if (hasDrawID)
5377 {
5378 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5379 {
5380 if (noopDraw(mode, counts[drawID]))
5381 {
5382 continue;
5383 }
5384 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005385 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005386 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005387 }
5388 }
5389 else
5390 {
5391 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5392 {
5393 if (noopDraw(mode, counts[drawID]))
5394 {
5395 continue;
5396 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005397 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005398 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005399 }
5400 }
5401}
5402
5403void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5404 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005405 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005406 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005407 const GLsizei *instanceCounts,
5408 GLsizei drawcount)
5409{
5410 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005411 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005412 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5413 if (hasDrawID)
5414 {
5415 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5416 {
5417 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5418 {
5419 continue;
5420 }
5421 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005422 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005423 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005424 }
5425 }
5426 else
5427 {
5428 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5429 {
5430 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5431 {
5432 continue;
5433 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005434 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005435 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005436 }
5437 }
5438}
5439
Jeff Gilbert465d6092019-01-02 16:21:18 -08005440void Context::provokingVertex(ProvokingVertex provokeMode)
5441{
5442 mState.setProvokingVertex(provokeMode);
5443}
5444
Jamie Madillc1d770e2017-04-13 17:31:24 -04005445GLenum Context::checkFramebufferStatus(GLenum target)
5446{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005447 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005449 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450}
5451
5452void Context::compileShader(GLuint shader)
5453{
5454 Shader *shaderObject = GetValidShader(this, shader);
5455 if (!shaderObject)
5456 {
5457 return;
5458 }
5459 shaderObject->compile(this);
5460}
5461
5462void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5463{
5464 for (int i = 0; i < n; i++)
5465 {
5466 deleteBuffer(buffers[i]);
5467 }
5468}
5469
5470void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5471{
5472 for (int i = 0; i < n; i++)
5473 {
5474 if (framebuffers[i] != 0)
5475 {
5476 deleteFramebuffer(framebuffers[i]);
5477 }
5478 }
5479}
5480
5481void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5482{
5483 for (int i = 0; i < n; i++)
5484 {
5485 deleteRenderbuffer(renderbuffers[i]);
5486 }
5487}
5488
5489void Context::deleteTextures(GLsizei n, const GLuint *textures)
5490{
5491 for (int i = 0; i < n; i++)
5492 {
5493 if (textures[i] != 0)
5494 {
5495 deleteTexture(textures[i]);
5496 }
5497 }
5498}
5499
5500void Context::detachShader(GLuint program, GLuint shader)
5501{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005502 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005503 ASSERT(programObject);
5504
5505 Shader *shaderObject = getShader(shader);
5506 ASSERT(shaderObject);
5507
5508 programObject->detachShader(this, shaderObject);
5509}
5510
5511void Context::genBuffers(GLsizei n, GLuint *buffers)
5512{
5513 for (int i = 0; i < n; i++)
5514 {
5515 buffers[i] = createBuffer();
5516 }
5517}
5518
5519void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5520{
5521 for (int i = 0; i < n; i++)
5522 {
5523 framebuffers[i] = createFramebuffer();
5524 }
5525}
5526
5527void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5528{
5529 for (int i = 0; i < n; i++)
5530 {
5531 renderbuffers[i] = createRenderbuffer();
5532 }
5533}
5534
5535void Context::genTextures(GLsizei n, GLuint *textures)
5536{
5537 for (int i = 0; i < n; i++)
5538 {
5539 textures[i] = createTexture();
5540 }
5541}
5542
5543void Context::getActiveAttrib(GLuint program,
5544 GLuint index,
5545 GLsizei bufsize,
5546 GLsizei *length,
5547 GLint *size,
5548 GLenum *type,
5549 GLchar *name)
5550{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005551 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552 ASSERT(programObject);
5553 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5554}
5555
5556void Context::getActiveUniform(GLuint program,
5557 GLuint index,
5558 GLsizei bufsize,
5559 GLsizei *length,
5560 GLint *size,
5561 GLenum *type,
5562 GLchar *name)
5563{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005564 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005565 ASSERT(programObject);
5566 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5567}
5568
5569void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5570{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005571 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572 ASSERT(programObject);
5573 programObject->getAttachedShaders(maxcount, count, shaders);
5574}
5575
5576GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5577{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005578 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005579 ASSERT(programObject);
5580 return programObject->getAttributeLocation(name);
5581}
5582
5583void Context::getBooleanv(GLenum pname, GLboolean *params)
5584{
5585 GLenum nativeType;
5586 unsigned int numParams = 0;
5587 getQueryParameterInfo(pname, &nativeType, &numParams);
5588
5589 if (nativeType == GL_BOOL)
5590 {
5591 getBooleanvImpl(pname, params);
5592 }
5593 else
5594 {
5595 CastStateValues(this, nativeType, pname, numParams, params);
5596 }
5597}
5598
Brandon Jones59770802018-04-02 13:18:42 -07005599void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5600{
5601 getBooleanv(pname, params);
5602}
5603
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604void Context::getFloatv(GLenum pname, GLfloat *params)
5605{
5606 GLenum nativeType;
5607 unsigned int numParams = 0;
5608 getQueryParameterInfo(pname, &nativeType, &numParams);
5609
5610 if (nativeType == GL_FLOAT)
5611 {
5612 getFloatvImpl(pname, params);
5613 }
5614 else
5615 {
5616 CastStateValues(this, nativeType, pname, numParams, params);
5617 }
5618}
5619
Brandon Jones59770802018-04-02 13:18:42 -07005620void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5621{
5622 getFloatv(pname, params);
5623}
5624
Jamie Madillc1d770e2017-04-13 17:31:24 -04005625void Context::getIntegerv(GLenum pname, GLint *params)
5626{
5627 GLenum nativeType;
5628 unsigned int numParams = 0;
5629 getQueryParameterInfo(pname, &nativeType, &numParams);
5630
5631 if (nativeType == GL_INT)
5632 {
5633 getIntegervImpl(pname, params);
5634 }
5635 else
5636 {
5637 CastStateValues(this, nativeType, pname, numParams, params);
5638 }
5639}
5640
Brandon Jones59770802018-04-02 13:18:42 -07005641void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5642{
5643 getIntegerv(pname, data);
5644}
5645
Jamie Madillc1d770e2017-04-13 17:31:24 -04005646void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5647{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005648 // Don't resolve link if checking the link completion status.
5649 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5650 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005651 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005652 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005653}
5654
Brandon Jones59770802018-04-02 13:18:42 -07005655void Context::getProgramivRobust(GLuint program,
5656 GLenum pname,
5657 GLsizei bufSize,
5658 GLsizei *length,
5659 GLint *params)
5660{
5661 getProgramiv(program, pname, params);
5662}
5663
Jiajia Qin5451d532017-11-16 17:16:34 +08005664void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5665{
5666 UNIMPLEMENTED();
5667}
5668
Jamie Madillbe849e42017-05-02 15:49:00 -04005669void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005670{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005671 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672 ASSERT(programObject);
5673 programObject->getInfoLog(bufsize, length, infolog);
5674}
5675
Jiajia Qin5451d532017-11-16 17:16:34 +08005676void Context::getProgramPipelineInfoLog(GLuint pipeline,
5677 GLsizei bufSize,
5678 GLsizei *length,
5679 GLchar *infoLog)
5680{
5681 UNIMPLEMENTED();
5682}
5683
Jamie Madillc1d770e2017-04-13 17:31:24 -04005684void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5685{
5686 Shader *shaderObject = getShader(shader);
5687 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005688 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005689}
5690
Brandon Jones59770802018-04-02 13:18:42 -07005691void Context::getShaderivRobust(GLuint shader,
5692 GLenum pname,
5693 GLsizei bufSize,
5694 GLsizei *length,
5695 GLint *params)
5696{
5697 getShaderiv(shader, pname, params);
5698}
5699
Jamie Madillc1d770e2017-04-13 17:31:24 -04005700void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5701{
5702 Shader *shaderObject = getShader(shader);
5703 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005704 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005705}
5706
5707void Context::getShaderPrecisionFormat(GLenum shadertype,
5708 GLenum precisiontype,
5709 GLint *range,
5710 GLint *precision)
5711{
5712 // TODO(jmadill): Compute shaders.
5713
5714 switch (shadertype)
5715 {
5716 case GL_VERTEX_SHADER:
5717 switch (precisiontype)
5718 {
5719 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005720 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005721 break;
5722 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005723 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005724 break;
5725 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005726 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727 break;
5728
5729 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005730 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731 break;
5732 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005733 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005734 break;
5735 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005736 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005737 break;
5738
5739 default:
5740 UNREACHABLE();
5741 return;
5742 }
5743 break;
5744
5745 case GL_FRAGMENT_SHADER:
5746 switch (precisiontype)
5747 {
5748 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005749 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750 break;
5751 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005752 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005753 break;
5754 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005755 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756 break;
5757
5758 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005759 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005760 break;
5761 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005762 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005763 break;
5764 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005765 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005766 break;
5767
5768 default:
5769 UNREACHABLE();
5770 return;
5771 }
5772 break;
5773
5774 default:
5775 UNREACHABLE();
5776 return;
5777 }
5778}
5779
5780void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5781{
5782 Shader *shaderObject = getShader(shader);
5783 ASSERT(shaderObject);
5784 shaderObject->getSource(bufsize, length, source);
5785}
5786
5787void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5788{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005789 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005790 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005791 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792}
5793
Brandon Jones59770802018-04-02 13:18:42 -07005794void Context::getUniformfvRobust(GLuint program,
5795 GLint location,
5796 GLsizei bufSize,
5797 GLsizei *length,
5798 GLfloat *params)
5799{
5800 getUniformfv(program, location, params);
5801}
5802
Jamie Madillc1d770e2017-04-13 17:31:24 -04005803void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5804{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005805 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005806 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005807 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005808}
5809
Brandon Jones59770802018-04-02 13:18:42 -07005810void Context::getUniformivRobust(GLuint program,
5811 GLint location,
5812 GLsizei bufSize,
5813 GLsizei *length,
5814 GLint *params)
5815{
5816 getUniformiv(program, location, params);
5817}
5818
Jamie Madillc1d770e2017-04-13 17:31:24 -04005819GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5820{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005821 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005822 ASSERT(programObject);
5823 return programObject->getUniformLocation(name);
5824}
5825
5826GLboolean Context::isBuffer(GLuint buffer)
5827{
5828 if (buffer == 0)
5829 {
5830 return GL_FALSE;
5831 }
5832
5833 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5834}
5835
5836GLboolean Context::isEnabled(GLenum cap)
5837{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005838 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005839}
5840
5841GLboolean Context::isFramebuffer(GLuint framebuffer)
5842{
5843 if (framebuffer == 0)
5844 {
5845 return GL_FALSE;
5846 }
5847
5848 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5849}
5850
5851GLboolean Context::isProgram(GLuint program)
5852{
5853 if (program == 0)
5854 {
5855 return GL_FALSE;
5856 }
5857
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005858 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005859}
5860
5861GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5862{
5863 if (renderbuffer == 0)
5864 {
5865 return GL_FALSE;
5866 }
5867
5868 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5869}
5870
5871GLboolean Context::isShader(GLuint shader)
5872{
5873 if (shader == 0)
5874 {
5875 return GL_FALSE;
5876 }
5877
5878 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5879}
5880
5881GLboolean Context::isTexture(GLuint texture)
5882{
5883 if (texture == 0)
5884 {
5885 return GL_FALSE;
5886 }
5887
5888 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5889}
5890
5891void Context::linkProgram(GLuint program)
5892{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005893 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005894 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005895 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005896
5897 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5898 // don't need to worry that:
5899 // 1. Draw calls after link use the new executable code or the old one depending on the link
5900 // result.
5901 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5902 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5903 // ProgramD3D.
5904 if (programObject->isInUse())
5905 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005906 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005907 if (programObject->isLinked())
5908 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005909 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005910 }
jchen107ae70d82018-07-06 13:47:01 +08005911 mStateCache.onProgramExecutableChange(this);
5912 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005913}
5914
5915void Context::releaseShaderCompiler()
5916{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005917 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005918}
5919
5920void Context::shaderBinary(GLsizei n,
5921 const GLuint *shaders,
5922 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005923 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005924 GLsizei length)
5925{
5926 // No binary shader formats are supported.
5927 UNIMPLEMENTED();
5928}
5929
Olli Etuaho0ca09752018-09-24 11:00:50 +03005930void Context::bindFragDataLocationIndexed(GLuint program,
5931 GLuint colorNumber,
5932 GLuint index,
5933 const char *name)
5934{
5935 Program *programObject = getProgramNoResolveLink(program);
5936 programObject->bindFragmentOutputLocation(colorNumber, name);
5937 programObject->bindFragmentOutputIndex(index, name);
5938}
5939
5940void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5941{
5942 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5943}
5944
5945int Context::getFragDataIndex(GLuint program, const char *name)
5946{
5947 Program *programObject = getProgramResolveLink(program);
5948 return programObject->getFragDataIndex(name);
5949}
5950
5951int Context::getProgramResourceLocationIndex(GLuint program,
5952 GLenum programInterface,
5953 const char *name)
5954{
5955 Program *programObject = getProgramResolveLink(program);
5956 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5957 return programObject->getFragDataIndex(name);
5958}
5959
Jamie Madillc1d770e2017-04-13 17:31:24 -04005960void Context::shaderSource(GLuint shader,
5961 GLsizei count,
5962 const GLchar *const *string,
5963 const GLint *length)
5964{
5965 Shader *shaderObject = getShader(shader);
5966 ASSERT(shaderObject);
5967 shaderObject->setSource(count, string, length);
5968}
5969
5970void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5971{
5972 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5973}
5974
5975void Context::stencilMask(GLuint mask)
5976{
5977 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5978}
5979
5980void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5981{
5982 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5983}
5984
5985void Context::uniform1f(GLint location, GLfloat x)
5986{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005987 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988 program->setUniform1fv(location, 1, &x);
5989}
5990
5991void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5992{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005993 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005994 program->setUniform1fv(location, count, v);
5995}
5996
Jamie Madill7e4eff12018-08-08 15:49:26 -04005997void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005998{
Jamie Madille3e680c2018-12-03 17:49:08 -05005999 program->setUniform1iv(this, location, count, v);
6000}
6001
6002void Context::onSamplerUniformChange(size_t textureUnitIndex)
6003{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006004 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05006005 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006}
6007
Jamie Madill7e4eff12018-08-08 15:49:26 -04006008void Context::uniform1i(GLint location, GLint x)
6009{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006010 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006011}
6012
Jamie Madillc1d770e2017-04-13 17:31:24 -04006013void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6014{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006015 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016}
6017
6018void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6019{
6020 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006021 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006022 program->setUniform2fv(location, 1, xy);
6023}
6024
6025void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6026{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006027 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006028 program->setUniform2fv(location, count, v);
6029}
6030
6031void Context::uniform2i(GLint location, GLint x, GLint y)
6032{
6033 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006034 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006035 program->setUniform2iv(location, 1, xy);
6036}
6037
6038void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6039{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006040 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006041 program->setUniform2iv(location, count, v);
6042}
6043
6044void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6045{
6046 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006047 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048 program->setUniform3fv(location, 1, xyz);
6049}
6050
6051void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6052{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006053 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006054 program->setUniform3fv(location, count, v);
6055}
6056
6057void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6058{
6059 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006060 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006061 program->setUniform3iv(location, 1, xyz);
6062}
6063
6064void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6065{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006066 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006067 program->setUniform3iv(location, count, v);
6068}
6069
6070void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6071{
6072 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006073 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006074 program->setUniform4fv(location, 1, xyzw);
6075}
6076
6077void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6078{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006079 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006080 program->setUniform4fv(location, count, v);
6081}
6082
6083void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6084{
6085 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006086 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006087 program->setUniform4iv(location, 1, xyzw);
6088}
6089
6090void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6091{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006092 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006093 program->setUniform4iv(location, count, v);
6094}
6095
6096void Context::uniformMatrix2fv(GLint location,
6097 GLsizei count,
6098 GLboolean transpose,
6099 const GLfloat *value)
6100{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006101 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006102 program->setUniformMatrix2fv(location, count, transpose, value);
6103}
6104
6105void Context::uniformMatrix3fv(GLint location,
6106 GLsizei count,
6107 GLboolean transpose,
6108 const GLfloat *value)
6109{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006110 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006111 program->setUniformMatrix3fv(location, count, transpose, value);
6112}
6113
6114void Context::uniformMatrix4fv(GLint location,
6115 GLsizei count,
6116 GLboolean transpose,
6117 const GLfloat *value)
6118{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006119 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006120 program->setUniformMatrix4fv(location, count, transpose, value);
6121}
6122
6123void Context::validateProgram(GLuint program)
6124{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006125 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006126 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006127 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006128}
6129
Jiajia Qin5451d532017-11-16 17:16:34 +08006130void Context::validateProgramPipeline(GLuint pipeline)
6131{
6132 UNIMPLEMENTED();
6133}
6134
Jamie Madilld04908b2017-06-09 14:15:35 -04006135void Context::getProgramBinary(GLuint program,
6136 GLsizei bufSize,
6137 GLsizei *length,
6138 GLenum *binaryFormat,
6139 void *binary)
6140{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006141 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006142 ASSERT(programObject != nullptr);
6143
Jamie Madill4f6592f2018-11-27 16:37:45 -05006144 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006145}
6146
6147void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6148{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006149 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006150 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006151
Jamie Madill4f6592f2018-11-27 16:37:45 -05006152 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006153 if (programObject->isInUse())
6154 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006155 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006156 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006157 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006158}
6159
Jamie Madillff325f12017-08-26 15:06:05 -04006160void Context::uniform1ui(GLint location, GLuint v0)
6161{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006162 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006163 program->setUniform1uiv(location, 1, &v0);
6164}
6165
6166void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6167{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006168 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006169 const GLuint xy[] = {v0, v1};
6170 program->setUniform2uiv(location, 1, xy);
6171}
6172
6173void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6174{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006175 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006176 const GLuint xyz[] = {v0, v1, v2};
6177 program->setUniform3uiv(location, 1, xyz);
6178}
6179
6180void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6181{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006182 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006183 const GLuint xyzw[] = {v0, v1, v2, v3};
6184 program->setUniform4uiv(location, 1, xyzw);
6185}
6186
6187void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6188{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006189 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006190 program->setUniform1uiv(location, count, value);
6191}
6192void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6193{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006194 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006195 program->setUniform2uiv(location, count, value);
6196}
6197
6198void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6199{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006200 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006201 program->setUniform3uiv(location, count, value);
6202}
6203
6204void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6205{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006206 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006207 program->setUniform4uiv(location, count, value);
6208}
6209
Jamie Madillf0e04492017-08-26 15:28:42 -04006210void Context::genQueries(GLsizei n, GLuint *ids)
6211{
6212 for (GLsizei i = 0; i < n; i++)
6213 {
6214 GLuint handle = mQueryHandleAllocator.allocate();
6215 mQueryMap.assign(handle, nullptr);
6216 ids[i] = handle;
6217 }
6218}
6219
6220void Context::deleteQueries(GLsizei n, const GLuint *ids)
6221{
6222 for (int i = 0; i < n; i++)
6223 {
6224 GLuint query = ids[i];
6225
6226 Query *queryObject = nullptr;
6227 if (mQueryMap.erase(query, &queryObject))
6228 {
6229 mQueryHandleAllocator.release(query);
6230 if (queryObject)
6231 {
6232 queryObject->release(this);
6233 }
6234 }
6235 }
6236}
6237
6238GLboolean Context::isQuery(GLuint id)
6239{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006240 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006241}
6242
Jamie Madillc8c95812017-08-26 18:40:09 -04006243void Context::uniformMatrix2x3fv(GLint location,
6244 GLsizei count,
6245 GLboolean transpose,
6246 const GLfloat *value)
6247{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006248 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006249 program->setUniformMatrix2x3fv(location, count, transpose, value);
6250}
6251
6252void Context::uniformMatrix3x2fv(GLint location,
6253 GLsizei count,
6254 GLboolean transpose,
6255 const GLfloat *value)
6256{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006257 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006258 program->setUniformMatrix3x2fv(location, count, transpose, value);
6259}
6260
6261void Context::uniformMatrix2x4fv(GLint location,
6262 GLsizei count,
6263 GLboolean transpose,
6264 const GLfloat *value)
6265{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006266 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006267 program->setUniformMatrix2x4fv(location, count, transpose, value);
6268}
6269
6270void Context::uniformMatrix4x2fv(GLint location,
6271 GLsizei count,
6272 GLboolean transpose,
6273 const GLfloat *value)
6274{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006275 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006276 program->setUniformMatrix4x2fv(location, count, transpose, value);
6277}
6278
6279void Context::uniformMatrix3x4fv(GLint location,
6280 GLsizei count,
6281 GLboolean transpose,
6282 const GLfloat *value)
6283{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006284 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006285 program->setUniformMatrix3x4fv(location, count, transpose, value);
6286}
6287
6288void Context::uniformMatrix4x3fv(GLint location,
6289 GLsizei count,
6290 GLboolean transpose,
6291 const GLfloat *value)
6292{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006293 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006294 program->setUniformMatrix4x3fv(location, count, transpose, value);
6295}
6296
Jamie Madilld7576732017-08-26 18:49:50 -04006297void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6298{
6299 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6300 {
6301 GLuint vertexArray = arrays[arrayIndex];
6302
6303 if (arrays[arrayIndex] != 0)
6304 {
6305 VertexArray *vertexArrayObject = nullptr;
6306 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6307 {
6308 if (vertexArrayObject != nullptr)
6309 {
6310 detachVertexArray(vertexArray);
6311 vertexArrayObject->onDestroy(this);
6312 }
6313
6314 mVertexArrayHandleAllocator.release(vertexArray);
6315 }
6316 }
6317 }
6318}
6319
6320void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6321{
6322 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6323 {
6324 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6325 mVertexArrayMap.assign(vertexArray, nullptr);
6326 arrays[arrayIndex] = vertexArray;
6327 }
6328}
6329
6330bool Context::isVertexArray(GLuint array)
6331{
6332 if (array == 0)
6333 {
6334 return GL_FALSE;
6335 }
6336
6337 VertexArray *vao = getVertexArray(array);
6338 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6339}
6340
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006341void Context::endTransformFeedback()
6342{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006343 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006344 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006345 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006346}
6347
6348void Context::transformFeedbackVaryings(GLuint program,
6349 GLsizei count,
6350 const GLchar *const *varyings,
6351 GLenum bufferMode)
6352{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006353 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006354 ASSERT(programObject);
6355 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6356}
6357
6358void Context::getTransformFeedbackVarying(GLuint program,
6359 GLuint index,
6360 GLsizei bufSize,
6361 GLsizei *length,
6362 GLsizei *size,
6363 GLenum *type,
6364 GLchar *name)
6365{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006366 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006367 ASSERT(programObject);
6368 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6369}
6370
6371void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6372{
6373 for (int i = 0; i < n; i++)
6374 {
6375 GLuint transformFeedback = ids[i];
6376 if (transformFeedback == 0)
6377 {
6378 continue;
6379 }
6380
6381 TransformFeedback *transformFeedbackObject = nullptr;
6382 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6383 {
6384 if (transformFeedbackObject != nullptr)
6385 {
6386 detachTransformFeedback(transformFeedback);
6387 transformFeedbackObject->release(this);
6388 }
6389
6390 mTransformFeedbackHandleAllocator.release(transformFeedback);
6391 }
6392 }
6393}
6394
6395void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6396{
6397 for (int i = 0; i < n; i++)
6398 {
6399 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6400 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6401 ids[i] = transformFeedback;
6402 }
6403}
6404
6405bool Context::isTransformFeedback(GLuint id)
6406{
6407 if (id == 0)
6408 {
6409 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6410 // returns FALSE
6411 return GL_FALSE;
6412 }
6413
6414 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6415 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6416}
6417
6418void Context::pauseTransformFeedback()
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->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006422 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006423}
6424
6425void Context::resumeTransformFeedback()
6426{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006427 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006428 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006429 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006430}
6431
Jamie Madill12e957f2017-08-26 21:42:26 -04006432void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6433{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006434 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006435 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006436}
6437
Brandon Jones59770802018-04-02 13:18:42 -07006438void Context::getUniformuivRobust(GLuint program,
6439 GLint location,
6440 GLsizei bufSize,
6441 GLsizei *length,
6442 GLuint *params)
6443{
6444 getUniformuiv(program, location, params);
6445}
6446
Jamie Madill12e957f2017-08-26 21:42:26 -04006447GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6448{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006449 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006450 return programObject->getFragDataLocation(name);
6451}
6452
6453void Context::getUniformIndices(GLuint program,
6454 GLsizei uniformCount,
6455 const GLchar *const *uniformNames,
6456 GLuint *uniformIndices)
6457{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006458 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006459 if (!programObject->isLinked())
6460 {
6461 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6462 {
6463 uniformIndices[uniformId] = GL_INVALID_INDEX;
6464 }
6465 }
6466 else
6467 {
6468 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6469 {
6470 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6471 }
6472 }
6473}
6474
6475void Context::getActiveUniformsiv(GLuint program,
6476 GLsizei uniformCount,
6477 const GLuint *uniformIndices,
6478 GLenum pname,
6479 GLint *params)
6480{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006481 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006482 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6483 {
6484 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006485 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006486 }
6487}
6488
6489GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6490{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006491 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006492 return programObject->getUniformBlockIndex(uniformBlockName);
6493}
6494
6495void Context::getActiveUniformBlockiv(GLuint program,
6496 GLuint uniformBlockIndex,
6497 GLenum pname,
6498 GLint *params)
6499{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006500 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006501 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6502}
6503
Brandon Jones59770802018-04-02 13:18:42 -07006504void Context::getActiveUniformBlockivRobust(GLuint program,
6505 GLuint uniformBlockIndex,
6506 GLenum pname,
6507 GLsizei bufSize,
6508 GLsizei *length,
6509 GLint *params)
6510{
6511 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6512}
6513
Jamie Madill12e957f2017-08-26 21:42:26 -04006514void Context::getActiveUniformBlockName(GLuint program,
6515 GLuint uniformBlockIndex,
6516 GLsizei bufSize,
6517 GLsizei *length,
6518 GLchar *uniformBlockName)
6519{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006520 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006521 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6522}
6523
6524void Context::uniformBlockBinding(GLuint program,
6525 GLuint uniformBlockIndex,
6526 GLuint uniformBlockBinding)
6527{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006528 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006529 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006530
Jamie Madill956ab4d2018-10-10 16:13:03 -04006531 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006532 if (programObject->isInUse())
6533 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006534 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006535 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006536 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006537}
6538
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006539GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6540{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006541 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006542 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006543
Jamie Madill70b5bb02017-08-28 13:32:37 -04006544 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006545 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006546 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006547 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006548 return nullptr;
6549 }
6550
Jamie Madill70b5bb02017-08-28 13:32:37 -04006551 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006552}
6553
6554GLboolean Context::isSync(GLsync sync)
6555{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006556 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006557}
6558
6559GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6560{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006561 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006562
6563 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006564 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006565 {
6566 return GL_WAIT_FAILED;
6567 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006568 return result;
6569}
6570
6571void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6572{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006573 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006574 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006575}
6576
6577void Context::getInteger64v(GLenum pname, GLint64 *params)
6578{
6579 GLenum nativeType = GL_NONE;
6580 unsigned int numParams = 0;
6581 getQueryParameterInfo(pname, &nativeType, &numParams);
6582
6583 if (nativeType == GL_INT_64_ANGLEX)
6584 {
6585 getInteger64vImpl(pname, params);
6586 }
6587 else
6588 {
6589 CastStateValues(this, nativeType, pname, numParams, params);
6590 }
6591}
6592
Brandon Jones59770802018-04-02 13:18:42 -07006593void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6594{
6595 getInteger64v(pname, data);
6596}
6597
Corentin Wallez336129f2017-10-17 15:55:40 -04006598void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006599{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006600 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006601 QueryBufferParameteri64v(buffer, pname, params);
6602}
6603
Brandon Jones59770802018-04-02 13:18:42 -07006604void Context::getBufferParameteri64vRobust(BufferBinding target,
6605 GLenum pname,
6606 GLsizei bufSize,
6607 GLsizei *length,
6608 GLint64 *params)
6609{
6610 getBufferParameteri64v(target, pname, params);
6611}
6612
Jamie Madill3ef140a2017-08-26 23:11:21 -04006613void Context::genSamplers(GLsizei count, GLuint *samplers)
6614{
6615 for (int i = 0; i < count; i++)
6616 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006617 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006618 }
6619}
6620
6621void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6622{
6623 for (int i = 0; i < count; i++)
6624 {
6625 GLuint sampler = samplers[i];
6626
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006627 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006628 {
6629 detachSampler(sampler);
6630 }
6631
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006632 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006633 }
6634}
6635
6636void Context::getInternalformativ(GLenum target,
6637 GLenum internalformat,
6638 GLenum pname,
6639 GLsizei bufSize,
6640 GLint *params)
6641{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006642 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006643 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6644}
6645
Brandon Jones59770802018-04-02 13:18:42 -07006646void Context::getInternalformativRobust(GLenum target,
6647 GLenum internalformat,
6648 GLenum pname,
6649 GLsizei bufSize,
6650 GLsizei *length,
6651 GLint *params)
6652{
6653 getInternalformativ(target, internalformat, pname, bufSize, params);
6654}
6655
Jiajia Qin5451d532017-11-16 17:16:34 +08006656void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6657{
6658 programUniform1iv(program, location, 1, &v0);
6659}
6660
6661void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6662{
6663 GLint xy[2] = {v0, v1};
6664 programUniform2iv(program, location, 1, xy);
6665}
6666
6667void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6668{
6669 GLint xyz[3] = {v0, v1, v2};
6670 programUniform3iv(program, location, 1, xyz);
6671}
6672
6673void Context::programUniform4i(GLuint program,
6674 GLint location,
6675 GLint v0,
6676 GLint v1,
6677 GLint v2,
6678 GLint v3)
6679{
6680 GLint xyzw[4] = {v0, v1, v2, v3};
6681 programUniform4iv(program, location, 1, xyzw);
6682}
6683
6684void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6685{
6686 programUniform1uiv(program, location, 1, &v0);
6687}
6688
6689void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6690{
6691 GLuint xy[2] = {v0, v1};
6692 programUniform2uiv(program, location, 1, xy);
6693}
6694
6695void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6696{
6697 GLuint xyz[3] = {v0, v1, v2};
6698 programUniform3uiv(program, location, 1, xyz);
6699}
6700
6701void Context::programUniform4ui(GLuint program,
6702 GLint location,
6703 GLuint v0,
6704 GLuint v1,
6705 GLuint v2,
6706 GLuint v3)
6707{
6708 GLuint xyzw[4] = {v0, v1, v2, v3};
6709 programUniform4uiv(program, location, 1, xyzw);
6710}
6711
6712void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6713{
6714 programUniform1fv(program, location, 1, &v0);
6715}
6716
6717void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6718{
6719 GLfloat xy[2] = {v0, v1};
6720 programUniform2fv(program, location, 1, xy);
6721}
6722
6723void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6724{
6725 GLfloat xyz[3] = {v0, v1, v2};
6726 programUniform3fv(program, location, 1, xyz);
6727}
6728
6729void Context::programUniform4f(GLuint program,
6730 GLint location,
6731 GLfloat v0,
6732 GLfloat v1,
6733 GLfloat v2,
6734 GLfloat v3)
6735{
6736 GLfloat xyzw[4] = {v0, v1, v2, v3};
6737 programUniform4fv(program, location, 1, xyzw);
6738}
6739
Jamie Madill81c2e252017-09-09 23:32:46 -04006740void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6741{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006742 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006743 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006744 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006745}
6746
Jiajia Qin5451d532017-11-16 17:16:34 +08006747void Context::programUniform2iv(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->setUniform2iv(location, count, value);
6752}
6753
6754void Context::programUniform3iv(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->setUniform3iv(location, count, value);
6759}
6760
6761void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *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->setUniform4iv(location, count, value);
6766}
6767
6768void Context::programUniform1uiv(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->setUniform1uiv(location, count, value);
6773}
6774
6775void Context::programUniform2uiv(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->setUniform2uiv(location, count, value);
6780}
6781
6782void Context::programUniform3uiv(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->setUniform3uiv(location, count, value);
6787}
6788
6789void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *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->setUniform4uiv(location, count, value);
6794}
6795
6796void Context::programUniform1fv(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->setUniform1fv(location, count, value);
6801}
6802
6803void Context::programUniform2fv(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->setUniform2fv(location, count, value);
6808}
6809
6810void Context::programUniform3fv(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->setUniform3fv(location, count, value);
6815}
6816
6817void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6818{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006819 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006820 ASSERT(programObject);
6821 programObject->setUniform4fv(location, count, value);
6822}
6823
6824void Context::programUniformMatrix2fv(GLuint program,
6825 GLint location,
6826 GLsizei count,
6827 GLboolean transpose,
6828 const GLfloat *value)
6829{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006830 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006831 ASSERT(programObject);
6832 programObject->setUniformMatrix2fv(location, count, transpose, value);
6833}
6834
6835void Context::programUniformMatrix3fv(GLuint program,
6836 GLint location,
6837 GLsizei count,
6838 GLboolean transpose,
6839 const GLfloat *value)
6840{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006841 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006842 ASSERT(programObject);
6843 programObject->setUniformMatrix3fv(location, count, transpose, value);
6844}
6845
6846void Context::programUniformMatrix4fv(GLuint program,
6847 GLint location,
6848 GLsizei count,
6849 GLboolean transpose,
6850 const GLfloat *value)
6851{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006852 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006853 ASSERT(programObject);
6854 programObject->setUniformMatrix4fv(location, count, transpose, value);
6855}
6856
6857void Context::programUniformMatrix2x3fv(GLuint program,
6858 GLint location,
6859 GLsizei count,
6860 GLboolean transpose,
6861 const GLfloat *value)
6862{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006863 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006864 ASSERT(programObject);
6865 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6866}
6867
6868void Context::programUniformMatrix3x2fv(GLuint program,
6869 GLint location,
6870 GLsizei count,
6871 GLboolean transpose,
6872 const GLfloat *value)
6873{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006874 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006875 ASSERT(programObject);
6876 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6877}
6878
6879void Context::programUniformMatrix2x4fv(GLuint program,
6880 GLint location,
6881 GLsizei count,
6882 GLboolean transpose,
6883 const GLfloat *value)
6884{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006885 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006886 ASSERT(programObject);
6887 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6888}
6889
6890void Context::programUniformMatrix4x2fv(GLuint program,
6891 GLint location,
6892 GLsizei count,
6893 GLboolean transpose,
6894 const GLfloat *value)
6895{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006896 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006897 ASSERT(programObject);
6898 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6899}
6900
6901void Context::programUniformMatrix3x4fv(GLuint program,
6902 GLint location,
6903 GLsizei count,
6904 GLboolean transpose,
6905 const GLfloat *value)
6906{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006907 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006908 ASSERT(programObject);
6909 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6910}
6911
6912void Context::programUniformMatrix4x3fv(GLuint program,
6913 GLint location,
6914 GLsizei count,
6915 GLboolean transpose,
6916 const GLfloat *value)
6917{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006918 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006919 ASSERT(programObject);
6920 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6921}
6922
James Darpiniane8a93c62018-01-04 18:02:24 -08006923bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6924{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006925 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006926}
James Darpiniane8a93c62018-01-04 18:02:24 -08006927
Yunchao Hea336b902017-08-02 16:05:21 +08006928void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6929{
6930 for (int i = 0; i < count; i++)
6931 {
6932 pipelines[i] = createProgramPipeline();
6933 }
6934}
6935
6936void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6937{
6938 for (int i = 0; i < count; i++)
6939 {
6940 if (pipelines[i] != 0)
6941 {
6942 deleteProgramPipeline(pipelines[i]);
6943 }
6944 }
6945}
6946
6947GLboolean Context::isProgramPipeline(GLuint pipeline)
6948{
6949 if (pipeline == 0)
6950 {
6951 return GL_FALSE;
6952 }
6953
6954 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6955}
6956
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006957void Context::finishFenceNV(GLuint fence)
6958{
6959 FenceNV *fenceObject = getFenceNV(fence);
6960
6961 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006962 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006963}
6964
6965void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6966{
6967 FenceNV *fenceObject = getFenceNV(fence);
6968
6969 ASSERT(fenceObject && fenceObject->isSet());
6970
6971 switch (pname)
6972 {
6973 case GL_FENCE_STATUS_NV:
6974 {
6975 // GL_NV_fence spec:
6976 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6977 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6978 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6979 GLboolean status = GL_TRUE;
6980 if (fenceObject->getStatus() != GL_TRUE)
6981 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006982 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006983 }
6984 *params = status;
6985 break;
6986 }
6987
6988 case GL_FENCE_CONDITION_NV:
6989 {
6990 *params = static_cast<GLint>(fenceObject->getCondition());
6991 break;
6992 }
6993
6994 default:
6995 UNREACHABLE();
6996 }
6997}
6998
6999void Context::getTranslatedShaderSource(GLuint shader,
7000 GLsizei bufsize,
7001 GLsizei *length,
7002 GLchar *source)
7003{
7004 Shader *shaderObject = getShader(shader);
7005 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007006 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007007}
7008
7009void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7010{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007011 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007012 ASSERT(programObject);
7013
7014 programObject->getUniformfv(this, location, params);
7015}
7016
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007017void Context::getnUniformfvRobust(GLuint program,
7018 GLint location,
7019 GLsizei bufSize,
7020 GLsizei *length,
7021 GLfloat *params)
7022{
7023 UNIMPLEMENTED();
7024}
7025
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007026void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7027{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007028 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007029 ASSERT(programObject);
7030
7031 programObject->getUniformiv(this, location, params);
7032}
7033
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007034void Context::getnUniformivRobust(GLuint program,
7035 GLint location,
7036 GLsizei bufSize,
7037 GLsizei *length,
7038 GLint *params)
7039{
7040 UNIMPLEMENTED();
7041}
7042
7043void Context::getnUniformuivRobust(GLuint program,
7044 GLint location,
7045 GLsizei bufSize,
7046 GLsizei *length,
7047 GLuint *params)
7048{
7049 UNIMPLEMENTED();
7050}
7051
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007052GLboolean Context::isFenceNV(GLuint fence)
7053{
7054 FenceNV *fenceObject = getFenceNV(fence);
7055
7056 if (fenceObject == nullptr)
7057 {
7058 return GL_FALSE;
7059 }
7060
7061 // GL_NV_fence spec:
7062 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7063 // existing fence.
7064 return fenceObject->isSet();
7065}
7066
7067void Context::readnPixels(GLint x,
7068 GLint y,
7069 GLsizei width,
7070 GLsizei height,
7071 GLenum format,
7072 GLenum type,
7073 GLsizei bufSize,
7074 void *data)
7075{
7076 return readPixels(x, y, width, height, format, type, data);
7077}
7078
Jamie Madill007530e2017-12-28 14:27:04 -05007079void Context::setFenceNV(GLuint fence, GLenum condition)
7080{
7081 ASSERT(condition == GL_ALL_COMPLETED_NV);
7082
7083 FenceNV *fenceObject = getFenceNV(fence);
7084 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007085 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007086}
7087
7088GLboolean Context::testFenceNV(GLuint fence)
7089{
7090 FenceNV *fenceObject = getFenceNV(fence);
7091
7092 ASSERT(fenceObject != nullptr);
7093 ASSERT(fenceObject->isSet() == GL_TRUE);
7094
7095 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007096 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007097 {
Jamie Madill007530e2017-12-28 14:27:04 -05007098 return GL_TRUE;
7099 }
7100
7101 return result;
7102}
7103
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007104void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007105{
7106 Texture *texture = getTargetTexture(target);
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(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007109}
7110
Jamie Madillfa920eb2018-01-04 11:45:50 -05007111void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007112{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007113 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007114 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007115 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007116}
7117
Jamie Madillfa920eb2018-01-04 11:45:50 -05007118void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7119{
7120 UNIMPLEMENTED();
7121}
7122
Jamie Madill5b772312018-03-08 20:28:32 -05007123bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7124{
7125 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7126 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7127 // to the fact that it is stored internally as a float, and so would require conversion
7128 // if returned from Context::getIntegerv. Since this conversion is already implemented
7129 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7130 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7131 // application.
7132 switch (pname)
7133 {
7134 case GL_COMPRESSED_TEXTURE_FORMATS:
7135 {
7136 *type = GL_INT;
7137 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7138 return true;
7139 }
7140 case GL_SHADER_BINARY_FORMATS:
7141 {
7142 *type = GL_INT;
7143 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7144 return true;
7145 }
7146
7147 case GL_MAX_VERTEX_ATTRIBS:
7148 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7149 case GL_MAX_VARYING_VECTORS:
7150 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7151 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7152 case GL_MAX_TEXTURE_IMAGE_UNITS:
7153 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7154 case GL_MAX_RENDERBUFFER_SIZE:
7155 case GL_NUM_SHADER_BINARY_FORMATS:
7156 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7157 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007158 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7159 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007160 case GL_RENDERBUFFER_BINDING:
7161 case GL_CURRENT_PROGRAM:
7162 case GL_PACK_ALIGNMENT:
7163 case GL_UNPACK_ALIGNMENT:
7164 case GL_GENERATE_MIPMAP_HINT:
7165 case GL_RED_BITS:
7166 case GL_GREEN_BITS:
7167 case GL_BLUE_BITS:
7168 case GL_ALPHA_BITS:
7169 case GL_DEPTH_BITS:
7170 case GL_STENCIL_BITS:
7171 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7172 case GL_CULL_FACE_MODE:
7173 case GL_FRONT_FACE:
7174 case GL_ACTIVE_TEXTURE:
7175 case GL_STENCIL_FUNC:
7176 case GL_STENCIL_VALUE_MASK:
7177 case GL_STENCIL_REF:
7178 case GL_STENCIL_FAIL:
7179 case GL_STENCIL_PASS_DEPTH_FAIL:
7180 case GL_STENCIL_PASS_DEPTH_PASS:
7181 case GL_STENCIL_BACK_FUNC:
7182 case GL_STENCIL_BACK_VALUE_MASK:
7183 case GL_STENCIL_BACK_REF:
7184 case GL_STENCIL_BACK_FAIL:
7185 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7186 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7187 case GL_DEPTH_FUNC:
7188 case GL_BLEND_SRC_RGB:
7189 case GL_BLEND_SRC_ALPHA:
7190 case GL_BLEND_DST_RGB:
7191 case GL_BLEND_DST_ALPHA:
7192 case GL_BLEND_EQUATION_RGB:
7193 case GL_BLEND_EQUATION_ALPHA:
7194 case GL_STENCIL_WRITEMASK:
7195 case GL_STENCIL_BACK_WRITEMASK:
7196 case GL_STENCIL_CLEAR_VALUE:
7197 case GL_SUBPIXEL_BITS:
7198 case GL_MAX_TEXTURE_SIZE:
7199 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7200 case GL_SAMPLE_BUFFERS:
7201 case GL_SAMPLES:
7202 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7203 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7204 case GL_TEXTURE_BINDING_2D:
7205 case GL_TEXTURE_BINDING_CUBE_MAP:
7206 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7207 {
7208 *type = GL_INT;
7209 *numParams = 1;
7210 return true;
7211 }
7212 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7213 {
7214 if (!getExtensions().packReverseRowOrder)
7215 {
7216 return false;
7217 }
7218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221 }
7222 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7223 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7224 {
7225 if (!getExtensions().textureRectangle)
7226 {
7227 return false;
7228 }
7229 *type = GL_INT;
7230 *numParams = 1;
7231 return true;
7232 }
7233 case GL_MAX_DRAW_BUFFERS_EXT:
7234 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7235 {
7236 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7237 {
7238 return false;
7239 }
7240 *type = GL_INT;
7241 *numParams = 1;
7242 return true;
7243 }
7244 case GL_MAX_VIEWPORT_DIMS:
7245 {
7246 *type = GL_INT;
7247 *numParams = 2;
7248 return true;
7249 }
7250 case GL_VIEWPORT:
7251 case GL_SCISSOR_BOX:
7252 {
7253 *type = GL_INT;
7254 *numParams = 4;
7255 return true;
7256 }
7257 case GL_SHADER_COMPILER:
7258 case GL_SAMPLE_COVERAGE_INVERT:
7259 case GL_DEPTH_WRITEMASK:
7260 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7261 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7262 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7263 // bool-natural
7264 case GL_SAMPLE_COVERAGE:
7265 case GL_SCISSOR_TEST:
7266 case GL_STENCIL_TEST:
7267 case GL_DEPTH_TEST:
7268 case GL_BLEND:
7269 case GL_DITHER:
7270 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7271 {
7272 *type = GL_BOOL;
7273 *numParams = 1;
7274 return true;
7275 }
7276 case GL_COLOR_WRITEMASK:
7277 {
7278 *type = GL_BOOL;
7279 *numParams = 4;
7280 return true;
7281 }
7282 case GL_POLYGON_OFFSET_FACTOR:
7283 case GL_POLYGON_OFFSET_UNITS:
7284 case GL_SAMPLE_COVERAGE_VALUE:
7285 case GL_DEPTH_CLEAR_VALUE:
7286 case GL_LINE_WIDTH:
7287 {
7288 *type = GL_FLOAT;
7289 *numParams = 1;
7290 return true;
7291 }
7292 case GL_ALIASED_LINE_WIDTH_RANGE:
7293 case GL_ALIASED_POINT_SIZE_RANGE:
7294 case GL_DEPTH_RANGE:
7295 {
7296 *type = GL_FLOAT;
7297 *numParams = 2;
7298 return true;
7299 }
7300 case GL_COLOR_CLEAR_VALUE:
7301 case GL_BLEND_COLOR:
7302 {
7303 *type = GL_FLOAT;
7304 *numParams = 4;
7305 return true;
7306 }
7307 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7308 if (!getExtensions().textureFilterAnisotropic)
7309 {
7310 return false;
7311 }
7312 *type = GL_FLOAT;
7313 *numParams = 1;
7314 return true;
7315 case GL_TIMESTAMP_EXT:
7316 if (!getExtensions().disjointTimerQuery)
7317 {
7318 return false;
7319 }
7320 *type = GL_INT_64_ANGLEX;
7321 *numParams = 1;
7322 return true;
7323 case GL_GPU_DISJOINT_EXT:
7324 if (!getExtensions().disjointTimerQuery)
7325 {
7326 return false;
7327 }
7328 *type = GL_INT;
7329 *numParams = 1;
7330 return true;
7331 case GL_COVERAGE_MODULATION_CHROMIUM:
7332 if (!getExtensions().framebufferMixedSamples)
7333 {
7334 return false;
7335 }
7336 *type = GL_INT;
7337 *numParams = 1;
7338 return true;
7339 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7340 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7341 {
7342 return false;
7343 }
7344 *type = GL_INT;
7345 *numParams = 1;
7346 return true;
7347 }
7348
7349 if (getExtensions().debug)
7350 {
7351 switch (pname)
7352 {
7353 case GL_DEBUG_LOGGED_MESSAGES:
7354 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7355 case GL_DEBUG_GROUP_STACK_DEPTH:
7356 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7357 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7358 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7359 case GL_MAX_LABEL_LENGTH:
7360 *type = GL_INT;
7361 *numParams = 1;
7362 return true;
7363
7364 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7365 case GL_DEBUG_OUTPUT:
7366 *type = GL_BOOL;
7367 *numParams = 1;
7368 return true;
7369 }
7370 }
7371
7372 if (getExtensions().multisampleCompatibility)
7373 {
7374 switch (pname)
7375 {
7376 case GL_MULTISAMPLE_EXT:
7377 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7378 *type = GL_BOOL;
7379 *numParams = 1;
7380 return true;
7381 }
7382 }
7383
7384 if (getExtensions().pathRendering)
7385 {
7386 switch (pname)
7387 {
7388 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7389 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7390 *type = GL_FLOAT;
7391 *numParams = 16;
7392 return true;
7393 }
7394 }
7395
7396 if (getExtensions().bindGeneratesResource)
7397 {
7398 switch (pname)
7399 {
7400 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7401 *type = GL_BOOL;
7402 *numParams = 1;
7403 return true;
7404 }
7405 }
7406
7407 if (getExtensions().clientArrays)
7408 {
7409 switch (pname)
7410 {
7411 case GL_CLIENT_ARRAYS_ANGLE:
7412 *type = GL_BOOL;
7413 *numParams = 1;
7414 return true;
7415 }
7416 }
7417
7418 if (getExtensions().sRGBWriteControl)
7419 {
7420 switch (pname)
7421 {
7422 case GL_FRAMEBUFFER_SRGB_EXT:
7423 *type = GL_BOOL;
7424 *numParams = 1;
7425 return true;
7426 }
7427 }
7428
7429 if (getExtensions().robustResourceInitialization &&
7430 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7431 {
7432 *type = GL_BOOL;
7433 *numParams = 1;
7434 return true;
7435 }
7436
7437 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7438 {
7439 *type = GL_BOOL;
7440 *numParams = 1;
7441 return true;
7442 }
7443
jchen1082af6202018-06-22 10:59:52 +08007444 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7445 {
7446 *type = GL_INT;
7447 *numParams = 1;
7448 return true;
7449 }
7450
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007451 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7452 {
7453 *type = GL_INT;
7454 *numParams = 1;
7455 return true;
7456 }
7457
Jamie Madill5b772312018-03-08 20:28:32 -05007458 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7459 switch (pname)
7460 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007461 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007462 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7463 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7464 {
7465 return false;
7466 }
7467 *type = GL_INT;
7468 *numParams = 1;
7469 return true;
7470
7471 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7472 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7473 {
7474 return false;
7475 }
7476 *type = GL_INT;
7477 *numParams = 1;
7478 return true;
7479
7480 case GL_PROGRAM_BINARY_FORMATS_OES:
7481 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7482 {
7483 return false;
7484 }
7485 *type = GL_INT;
7486 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7487 return true;
7488
7489 case GL_PACK_ROW_LENGTH:
7490 case GL_PACK_SKIP_ROWS:
7491 case GL_PACK_SKIP_PIXELS:
7492 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7493 {
7494 return false;
7495 }
7496 *type = GL_INT;
7497 *numParams = 1;
7498 return true;
7499 case GL_UNPACK_ROW_LENGTH:
7500 case GL_UNPACK_SKIP_ROWS:
7501 case GL_UNPACK_SKIP_PIXELS:
7502 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7503 {
7504 return false;
7505 }
7506 *type = GL_INT;
7507 *numParams = 1;
7508 return true;
7509 case GL_VERTEX_ARRAY_BINDING:
7510 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7511 {
7512 return false;
7513 }
7514 *type = GL_INT;
7515 *numParams = 1;
7516 return true;
7517 case GL_PIXEL_PACK_BUFFER_BINDING:
7518 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7519 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7520 {
7521 return false;
7522 }
7523 *type = GL_INT;
7524 *numParams = 1;
7525 return true;
7526 case GL_MAX_SAMPLES:
7527 {
7528 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7529 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7530 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7531 {
7532 return false;
7533 }
7534 *type = GL_INT;
7535 *numParams = 1;
7536 return true;
7537
7538 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7539 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7540 {
7541 return false;
7542 }
7543 *type = GL_INT;
7544 *numParams = 1;
7545 return true;
7546 }
7547 }
7548
7549 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7550 {
7551 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7552 {
7553 return false;
7554 }
7555 *type = GL_INT;
7556 *numParams = 1;
7557 return true;
7558 }
7559
7560 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7561 {
7562 *type = GL_INT;
7563 *numParams = 1;
7564 return true;
7565 }
7566
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007567 if (getClientVersion() < Version(2, 0))
7568 {
7569 switch (pname)
7570 {
7571 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007572 case GL_CLIENT_ACTIVE_TEXTURE:
7573 case GL_MATRIX_MODE:
7574 case GL_MAX_TEXTURE_UNITS:
7575 case GL_MAX_MODELVIEW_STACK_DEPTH:
7576 case GL_MAX_PROJECTION_STACK_DEPTH:
7577 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007578 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007579 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007580 case GL_VERTEX_ARRAY_STRIDE:
7581 case GL_NORMAL_ARRAY_STRIDE:
7582 case GL_COLOR_ARRAY_STRIDE:
7583 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7584 case GL_VERTEX_ARRAY_SIZE:
7585 case GL_COLOR_ARRAY_SIZE:
7586 case GL_TEXTURE_COORD_ARRAY_SIZE:
7587 case GL_VERTEX_ARRAY_TYPE:
7588 case GL_NORMAL_ARRAY_TYPE:
7589 case GL_COLOR_ARRAY_TYPE:
7590 case GL_TEXTURE_COORD_ARRAY_TYPE:
7591 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7592 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7593 case GL_COLOR_ARRAY_BUFFER_BINDING:
7594 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7595 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7596 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7597 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007598 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007599 case GL_MODELVIEW_STACK_DEPTH:
7600 case GL_PROJECTION_STACK_DEPTH:
7601 case GL_TEXTURE_STACK_DEPTH:
7602 case GL_LOGIC_OP_MODE:
7603 case GL_BLEND_SRC:
7604 case GL_BLEND_DST:
7605 case GL_PERSPECTIVE_CORRECTION_HINT:
7606 case GL_POINT_SMOOTH_HINT:
7607 case GL_LINE_SMOOTH_HINT:
7608 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007609 *type = GL_INT;
7610 *numParams = 1;
7611 return true;
7612 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007613 case GL_FOG_DENSITY:
7614 case GL_FOG_START:
7615 case GL_FOG_END:
7616 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007617 case GL_POINT_SIZE:
7618 case GL_POINT_SIZE_MIN:
7619 case GL_POINT_SIZE_MAX:
7620 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007621 *type = GL_FLOAT;
7622 *numParams = 1;
7623 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007624 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007625 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007626 *type = GL_FLOAT;
7627 *numParams = 2;
7628 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007629 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007630 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007631 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007632 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007633 *type = GL_FLOAT;
7634 *numParams = 4;
7635 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007636 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007637 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007638 *type = GL_FLOAT;
7639 *numParams = 3;
7640 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007641 case GL_MODELVIEW_MATRIX:
7642 case GL_PROJECTION_MATRIX:
7643 case GL_TEXTURE_MATRIX:
7644 *type = GL_FLOAT;
7645 *numParams = 16;
7646 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007647 case GL_LIGHT_MODEL_TWO_SIDE:
7648 *type = GL_BOOL;
7649 *numParams = 1;
7650 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007651 }
7652 }
7653
Jamie Madill5b772312018-03-08 20:28:32 -05007654 if (getClientVersion() < Version(3, 0))
7655 {
7656 return false;
7657 }
7658
7659 // Check for ES3.0+ parameter names
7660 switch (pname)
7661 {
7662 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7663 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7664 case GL_UNIFORM_BUFFER_BINDING:
7665 case GL_TRANSFORM_FEEDBACK_BINDING:
7666 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7667 case GL_COPY_READ_BUFFER_BINDING:
7668 case GL_COPY_WRITE_BUFFER_BINDING:
7669 case GL_SAMPLER_BINDING:
7670 case GL_READ_BUFFER:
7671 case GL_TEXTURE_BINDING_3D:
7672 case GL_TEXTURE_BINDING_2D_ARRAY:
7673 case GL_MAX_3D_TEXTURE_SIZE:
7674 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7675 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7676 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7677 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7678 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7679 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7680 case GL_MAX_VARYING_COMPONENTS:
7681 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7682 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7683 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7684 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7685 case GL_NUM_EXTENSIONS:
7686 case GL_MAJOR_VERSION:
7687 case GL_MINOR_VERSION:
7688 case GL_MAX_ELEMENTS_INDICES:
7689 case GL_MAX_ELEMENTS_VERTICES:
7690 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7691 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7692 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7693 case GL_UNPACK_IMAGE_HEIGHT:
7694 case GL_UNPACK_SKIP_IMAGES:
7695 {
7696 *type = GL_INT;
7697 *numParams = 1;
7698 return true;
7699 }
7700
7701 case GL_MAX_ELEMENT_INDEX:
7702 case GL_MAX_UNIFORM_BLOCK_SIZE:
7703 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7704 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7705 case GL_MAX_SERVER_WAIT_TIMEOUT:
7706 {
7707 *type = GL_INT_64_ANGLEX;
7708 *numParams = 1;
7709 return true;
7710 }
7711
7712 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7713 case GL_TRANSFORM_FEEDBACK_PAUSED:
7714 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7715 case GL_RASTERIZER_DISCARD:
7716 {
7717 *type = GL_BOOL;
7718 *numParams = 1;
7719 return true;
7720 }
7721
7722 case GL_MAX_TEXTURE_LOD_BIAS:
7723 {
7724 *type = GL_FLOAT;
7725 *numParams = 1;
7726 return true;
7727 }
7728 }
7729
7730 if (getExtensions().requestExtension)
7731 {
7732 switch (pname)
7733 {
7734 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7735 *type = GL_INT;
7736 *numParams = 1;
7737 return true;
7738 }
7739 }
7740
Yizhou Jiang7818a852018-09-06 15:02:04 +08007741 if (getExtensions().textureMultisample)
7742 {
7743 switch (pname)
7744 {
7745 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7746 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7747 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7748 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007749 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007750 *type = GL_INT;
7751 *numParams = 1;
7752 return true;
7753 }
7754 }
7755
Jamie Madill5b772312018-03-08 20:28:32 -05007756 if (getClientVersion() < Version(3, 1))
7757 {
7758 return false;
7759 }
7760
7761 switch (pname)
7762 {
7763 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7764 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7765 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7766 case GL_MAX_FRAMEBUFFER_WIDTH:
7767 case GL_MAX_FRAMEBUFFER_HEIGHT:
7768 case GL_MAX_FRAMEBUFFER_SAMPLES:
7769 case GL_MAX_SAMPLE_MASK_WORDS:
7770 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7771 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7772 case GL_MAX_INTEGER_SAMPLES:
7773 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7774 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7775 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7776 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7777 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7778 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7779 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7780 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7781 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7782 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7783 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7784 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7785 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7786 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7787 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7788 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7789 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7790 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7791 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7792 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7793 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7794 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7795 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7796 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7797 case GL_MAX_UNIFORM_LOCATIONS:
7798 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7799 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7800 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7801 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7802 case GL_MAX_IMAGE_UNITS:
7803 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7804 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7805 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7806 case GL_SHADER_STORAGE_BUFFER_BINDING:
7807 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7808 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007809 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007810 *type = GL_INT;
7811 *numParams = 1;
7812 return true;
7813 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7814 *type = GL_INT_64_ANGLEX;
7815 *numParams = 1;
7816 return true;
7817 case GL_SAMPLE_MASK:
7818 *type = GL_BOOL;
7819 *numParams = 1;
7820 return true;
7821 }
7822
7823 if (getExtensions().geometryShader)
7824 {
7825 switch (pname)
7826 {
7827 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7828 case GL_LAYER_PROVOKING_VERTEX_EXT:
7829 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7830 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7831 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7832 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7833 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7834 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7835 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7836 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7837 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7838 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7839 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7840 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7841 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7842 *type = GL_INT;
7843 *numParams = 1;
7844 return true;
7845 }
7846 }
7847
7848 return false;
7849}
7850
7851bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7852{
7853 if (getClientVersion() < Version(3, 0))
7854 {
7855 return false;
7856 }
7857
7858 switch (target)
7859 {
7860 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7861 case GL_UNIFORM_BUFFER_BINDING:
7862 {
7863 *type = GL_INT;
7864 *numParams = 1;
7865 return true;
7866 }
7867 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7868 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7869 case GL_UNIFORM_BUFFER_START:
7870 case GL_UNIFORM_BUFFER_SIZE:
7871 {
7872 *type = GL_INT_64_ANGLEX;
7873 *numParams = 1;
7874 return true;
7875 }
7876 }
7877
7878 if (getClientVersion() < Version(3, 1))
7879 {
7880 return false;
7881 }
7882
7883 switch (target)
7884 {
7885 case GL_IMAGE_BINDING_LAYERED:
7886 {
7887 *type = GL_BOOL;
7888 *numParams = 1;
7889 return true;
7890 }
7891 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7892 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7893 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7894 case GL_SHADER_STORAGE_BUFFER_BINDING:
7895 case GL_VERTEX_BINDING_BUFFER:
7896 case GL_VERTEX_BINDING_DIVISOR:
7897 case GL_VERTEX_BINDING_OFFSET:
7898 case GL_VERTEX_BINDING_STRIDE:
7899 case GL_SAMPLE_MASK_VALUE:
7900 case GL_IMAGE_BINDING_NAME:
7901 case GL_IMAGE_BINDING_LEVEL:
7902 case GL_IMAGE_BINDING_LAYER:
7903 case GL_IMAGE_BINDING_ACCESS:
7904 case GL_IMAGE_BINDING_FORMAT:
7905 {
7906 *type = GL_INT;
7907 *numParams = 1;
7908 return true;
7909 }
7910 case GL_ATOMIC_COUNTER_BUFFER_START:
7911 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7912 case GL_SHADER_STORAGE_BUFFER_START:
7913 case GL_SHADER_STORAGE_BUFFER_SIZE:
7914 {
7915 *type = GL_INT_64_ANGLEX;
7916 *numParams = 1;
7917 return true;
7918 }
7919 }
7920
7921 return false;
7922}
7923
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007924Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007925{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007926 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007927}
7928
7929Shader *Context::getShader(GLuint handle) const
7930{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007931 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007932}
7933
Jamie Madill5b772312018-03-08 20:28:32 -05007934bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7935{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007936 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007937}
7938
7939bool Context::isFramebufferGenerated(GLuint framebuffer) const
7940{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007941 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007942}
7943
7944bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7945{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007946 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007947}
7948
7949bool Context::usingDisplayTextureShareGroup() const
7950{
7951 return mDisplayTextureShareGroup;
7952}
7953
7954GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7955{
7956 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7957 internalformat == GL_DEPTH_STENCIL
7958 ? GL_DEPTH24_STENCIL8
7959 : internalformat;
7960}
7961
jchen1082af6202018-06-22 10:59:52 +08007962void Context::maxShaderCompilerThreads(GLuint count)
7963{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007964 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7965 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007966 // A count of zero specifies a request for no parallel compiling or linking.
7967 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7968 {
7969 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7970 }
7971 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007972}
7973
Jamie Madill2eb65032018-07-30 10:25:57 -04007974bool Context::isGLES1() const
7975{
7976 return mState.getClientVersion() < Version(2, 0);
7977}
7978
Jamie Madilla11819d2018-07-30 10:26:01 -04007979void Context::onSubjectStateChange(const Context *context,
7980 angle::SubjectIndex index,
7981 angle::SubjectMessage message)
7982{
Jamie Madilla11819d2018-07-30 10:26:01 -04007983 switch (index)
7984 {
7985 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007986 switch (message)
7987 {
7988 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007989 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007990 mStateCache.onVertexArrayBufferContentsChange(this);
7991 break;
7992 case angle::SubjectMessage::RESOURCE_MAPPED:
7993 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7994 case angle::SubjectMessage::BINDING_CHANGED:
7995 mStateCache.onVertexArrayBufferStateChange(this);
7996 break;
7997 default:
7998 break;
7999 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008000 break;
8001
8002 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008003 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8004 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008005 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04008006 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008007 break;
8008
8009 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008010 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8011 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008012 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008013 }
8014 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008015 break;
8016
8017 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008018 if (index < kTextureMaxSubjectIndex)
8019 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008020 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008021 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008022 }
Jamie Madille25b8002018-09-20 13:39:49 -04008023 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008024 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008025 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008026 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008027 }
Jamie Madille25b8002018-09-20 13:39:49 -04008028 else
8029 {
8030 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008031 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008032 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008033 break;
8034 }
8035}
8036
Jamie Madill6b873dd2018-07-12 23:56:30 -04008037// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008038ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008039
8040ErrorSet::~ErrorSet() = default;
8041
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008042void ErrorSet::handleError(GLenum errorCode,
8043 const char *message,
8044 const char *file,
8045 const char *function,
8046 unsigned int line)
8047{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008048 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8049 {
8050 mContext->markContextLost();
8051 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008052
Jamie Madill4f6592f2018-11-27 16:37:45 -05008053 std::stringstream errorStream;
8054 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8055 << line << ". " << message;
8056
Geoff Lang7139b432018-12-14 16:57:28 -05008057 std::string formattedMessage = errorStream.str();
8058
8059 // Always log a warning, this function is only called on unexpected internal errors.
8060 WARN() << formattedMessage;
8061
Jamie Madill4f6592f2018-11-27 16:37:45 -05008062 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008063 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008064}
8065
Jamie Madilla139f012018-10-10 16:13:03 -04008066void ErrorSet::validationError(GLenum errorCode, const char *message)
8067{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008068 ASSERT(errorCode != GL_NO_ERROR);
8069 mErrors.insert(errorCode);
8070
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008071 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8072 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008073}
8074
Jamie Madill6b873dd2018-07-12 23:56:30 -04008075bool ErrorSet::empty() const
8076{
8077 return mErrors.empty();
8078}
8079
8080GLenum ErrorSet::popError()
8081{
8082 ASSERT(!empty());
8083 GLenum error = *mErrors.begin();
8084 mErrors.erase(mErrors.begin());
8085 return error;
8086}
Jamie Madilldc358af2018-07-31 11:22:13 -04008087
8088// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008089StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008090 : mCachedHasAnyEnabledClientAttrib(false),
8091 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008092 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008093 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008094 mCachedBasicDrawElementsError(kInvalidPointer),
8095 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008096{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008097
8098StateCache::~StateCache() = default;
8099
Jamie Madillac66f982018-10-09 18:30:01 -04008100void StateCache::initialize(Context *context)
8101{
8102 updateValidDrawModes(context);
8103 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008104 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008105 updateBasicDrawStatesError();
8106 updateBasicDrawElementsError();
Jamie Madillc8c7d402019-01-16 13:27:15 -05008107 updateVertexAttribTypesValidation(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008108}
8109
Jamie Madilldc358af2018-07-31 11:22:13 -04008110void StateCache::updateActiveAttribsMask(Context *context)
8111{
8112 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008113 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008114
8115 if (!isGLES1 && !glState.getProgram())
8116 {
8117 mCachedActiveBufferedAttribsMask = AttributesMask();
8118 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008119 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008120 return;
8121 }
8122
8123 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8124 : glState.getProgram()->getActiveAttribLocationsMask();
8125
8126 const VertexArray *vao = glState.getVertexArray();
8127 ASSERT(vao);
8128
8129 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8130 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008131 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008132
Jamie Madill0a17e482018-08-31 17:19:11 -04008133 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8134 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008135 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008136 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8137}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008138
8139void StateCache::updateVertexElementLimits(Context *context)
8140{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008141 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008142
8143 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8144 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8145
8146 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8147 // If there are no buffered attributes then we should not limit the draw call count.
8148 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8149 {
8150 return;
8151 }
8152
8153 const auto &vertexAttribs = vao->getVertexAttributes();
8154 const auto &vertexBindings = vao->getVertexBindings();
8155
8156 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8157 {
8158 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008159
8160 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8161 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008162 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008163
8164 GLint64 limit = attrib.getCachedElementLimit();
8165 if (binding.getDivisor() > 0)
8166 {
8167 mCachedInstancedVertexElementLimit =
8168 std::min(mCachedInstancedVertexElementLimit, limit);
8169 }
8170 else
8171 {
8172 mCachedNonInstancedVertexElementLimit =
8173 std::min(mCachedNonInstancedVertexElementLimit, limit);
8174 }
8175 }
8176}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008177
Jamie Madilld84b6732018-09-06 15:54:35 -04008178void StateCache::updateBasicDrawStatesError()
8179{
8180 mCachedBasicDrawStatesError = kInvalidPointer;
8181}
8182
Jamie Madill1e853262018-12-21 09:07:38 -05008183void StateCache::updateBasicDrawElementsError()
8184{
8185 mCachedBasicDrawElementsError = kInvalidPointer;
8186}
8187
Jamie Madilld84b6732018-09-06 15:54:35 -04008188intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8189{
8190 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8191 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8192 return mCachedBasicDrawStatesError;
8193}
8194
Jamie Madill1e853262018-12-21 09:07:38 -05008195intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8196{
8197 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8198 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8199 return mCachedBasicDrawElementsError;
8200}
8201
Jamie Madillc43cdad2018-08-08 15:49:25 -04008202void StateCache::onVertexArrayBindingChange(Context *context)
8203{
8204 updateActiveAttribsMask(context);
8205 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008206 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008207}
8208
8209void StateCache::onProgramExecutableChange(Context *context)
8210{
8211 updateActiveAttribsMask(context);
8212 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008213 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008214 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008215}
8216
Jamie Madilld84b6732018-09-06 15:54:35 -04008217void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008218{
8219 updateVertexElementLimits(context);
8220}
8221
Jamie Madilld84b6732018-09-06 15:54:35 -04008222void StateCache::onVertexArrayBufferContentsChange(Context *context)
8223{
8224 updateVertexElementLimits(context);
8225 updateBasicDrawStatesError();
8226}
8227
Jamie Madillc43cdad2018-08-08 15:49:25 -04008228void StateCache::onVertexArrayStateChange(Context *context)
8229{
8230 updateActiveAttribsMask(context);
8231 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008232 updateBasicDrawStatesError();
8233}
8234
8235void StateCache::onVertexArrayBufferStateChange(Context *context)
8236{
8237 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008238 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008239}
8240
8241void StateCache::onGLES1ClientStateChange(Context *context)
8242{
8243 updateActiveAttribsMask(context);
8244}
Jamie Madilld84b6732018-09-06 15:54:35 -04008245
8246void StateCache::onDrawFramebufferChange(Context *context)
8247{
8248 updateBasicDrawStatesError();
8249}
8250
8251void StateCache::onContextCapChange(Context *context)
8252{
8253 updateBasicDrawStatesError();
8254}
8255
8256void StateCache::onStencilStateChange(Context *context)
8257{
8258 updateBasicDrawStatesError();
8259}
8260
8261void StateCache::onDefaultVertexAttributeChange(Context *context)
8262{
8263 updateBasicDrawStatesError();
8264}
8265
8266void StateCache::onActiveTextureChange(Context *context)
8267{
8268 updateBasicDrawStatesError();
8269}
8270
8271void StateCache::onQueryChange(Context *context)
8272{
8273 updateBasicDrawStatesError();
8274}
8275
Jamie Madill3a256222018-12-08 09:56:39 -05008276void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008277{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008278 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008279 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008280 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008281 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008282}
8283
8284void StateCache::onUniformBufferStateChange(Context *context)
8285{
8286 updateBasicDrawStatesError();
8287}
8288
Jamie Madill9b025062018-12-12 15:44:12 -05008289void StateCache::setValidDrawModes(bool pointsOK,
8290 bool linesOK,
8291 bool trisOK,
8292 bool lineAdjOK,
8293 bool triAdjOK)
8294{
8295 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8296 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8297 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8298 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8299 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8300 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8301 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8302 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8303 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8304 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8305 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8306}
8307
Jamie Madill526a6f62018-09-12 11:03:05 -04008308void StateCache::updateValidDrawModes(Context *context)
8309{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008310 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008311 Program *program = state.getProgram();
8312
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008313 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008314 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008315 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8316
Jamie Madill9b025062018-12-12 15:44:12 -05008317 // ES Spec 3.0 validation text:
8318 // When transform feedback is active and not paused, all geometric primitives generated must
8319 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8320 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8321 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8322 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8323 // active and not paused, regardless of mode. Any primitive type may be used while transform
8324 // feedback is paused.
8325 if (!context->getExtensions().geometryShader)
8326 {
8327 mCachedValidDrawModes.fill(false);
8328 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8329 return;
8330 }
8331
8332 // EXT_geometry_shader validation text:
8333 // When transform feedback is active and not paused, all geometric primitives generated must
8334 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8335 // geometry shader is active, the type of primitive emitted by that shader is used instead
8336 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8337 // Any primitive type may be used while transform feedback is paused.
8338 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8339 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8340 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8341
8342 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8343 return;
8344 }
8345
Jamie Madill526a6f62018-09-12 11:03:05 -04008346 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8347 {
Jamie Madill752d2202018-11-27 13:29:48 -05008348 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008349 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008350 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008351
Jamie Madill9b025062018-12-12 15:44:12 -05008352 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8353 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008354
Jamie Madill9b025062018-12-12 15:44:12 -05008355 bool pointsOK = gsMode == PrimitiveMode::Points;
8356 bool linesOK = gsMode == PrimitiveMode::Lines;
8357 bool trisOK = gsMode == PrimitiveMode::Triangles;
8358 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8359 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8360
8361 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008362}
Jamie Madillac66f982018-10-09 18:30:01 -04008363
8364void StateCache::updateValidBindTextureTypes(Context *context)
8365{
8366 const Extensions &exts = context->getExtensions();
8367 bool isGLES3 = context->getClientMajorVersion() >= 3;
8368 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8369
8370 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008371 {TextureType::_2D, true},
8372 {TextureType::_2DArray, isGLES3},
8373 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8374 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8375 {TextureType::_3D, isGLES3},
8376 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8377 {TextureType::Rectangle, exts.textureRectangle},
8378 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008379 }};
8380}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008381
8382void StateCache::updateValidDrawElementsTypes(Context *context)
8383{
8384 bool supportsUint =
8385 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8386
8387 mCachedValidDrawElementsTypes = {{
8388 {DrawElementsType::UnsignedByte, true},
8389 {DrawElementsType::UnsignedShort, true},
8390 {DrawElementsType::UnsignedInt, supportsUint},
8391 }};
8392}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008393
8394void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8395{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008396 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008397 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8398}
Jamie Madillc8c7d402019-01-16 13:27:15 -05008399
8400void StateCache::updateVertexAttribTypesValidation(Context *context)
8401{
8402 if (context->getClientMajorVersion() <= 2)
8403 {
8404 mCachedVertexAttribTypesValidation = {{
8405 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8406 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8407 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8408 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8409 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8410 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8411 }};
8412 }
8413 else
8414 {
8415 mCachedVertexAttribTypesValidation = {{
8416 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8417 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8418 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8419 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8420 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8421 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8422 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8423 {VertexAttribType::HalfFloat, VertexAttribTypeCase::Valid},
8424 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8425 {VertexAttribType::Int2101010, VertexAttribTypeCase::ValidSize4Only},
8426 {VertexAttribType::UnsignedInt2101010, VertexAttribTypeCase::ValidSize4Only},
8427 }};
8428
8429 mCachedIntegerVertexAttribTypesValidation = {{
8430 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8431 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8432 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8433 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8434 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8435 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8436 }};
8437 }
8438}
Jamie Madillc29968b2016-01-20 11:17:23 -05008439} // namespace gl