blob: fd288b1dd2e85b9dbed302350904ad511c0179ea [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 Wallez3adcf1e2019-01-16 00:40:38 +0000538 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800539 zeroTexture.set(this, nullptr);
540 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400541 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
Jamie Madill2f348d22017-06-05 10:50:59 -0400543 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500544
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500545 mState.reset(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400546
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500547 mState.mBufferManager->release(this);
548 mState.mShaderProgramManager->release(this);
549 mState.mTextureManager->release(this);
550 mState.mRenderbufferManager->release(this);
551 mState.mSamplerManager->release(this);
552 mState.mSyncManager->release(this);
553 mState.mPathManager->release(this);
554 mState.mFramebufferManager->release(this);
555 mState.mProgramPipelineManager->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400556
jchen107ae70d82018-07-06 13:47:01 +0800557 mThreadPool.reset();
558
Jamie Madill76e471e2017-10-21 09:56:01 -0400559 mImplementation->onDestroy(this);
560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000562}
563
Jamie Madillb980c562018-11-27 11:34:27 -0500564Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500565
Geoff Lang75359662018-04-11 01:42:27 -0400566void Context::setLabel(EGLLabelKHR label)
567{
568 mLabel = label;
569}
570
571EGLLabelKHR Context::getLabel() const
572{
573 return mLabel;
574}
575
Jamie Madill4928b7c2017-06-20 12:57:39 -0400576egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000577{
Jamie Madill61e16b42017-06-19 11:13:23 -0400578 mCurrentDisplay = display;
579
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000580 if (!mHasBeenCurrent)
581 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400582 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500584 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400585 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586
Corentin Wallezc295e512017-01-27 17:47:50 -0500587 int width = 0;
588 int height = 0;
589 if (surface != nullptr)
590 {
591 width = surface->getWidth();
592 height = surface->getHeight();
593 }
594
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500595 mState.setViewportParams(0, 0, width, height);
596 mState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597
598 mHasBeenCurrent = true;
599 }
600
Jamie Madill1b94d432015-08-07 13:23:23 -0400601 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500602 mState.setAllDirtyBits();
603 mState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400604
Jamie Madill4928b7c2017-06-20 12:57:39 -0400605 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500606
607 Framebuffer *newDefault = nullptr;
608 if (surface != nullptr)
609 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400610 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500611 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400612 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500613 }
614 else
615 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400616 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500617 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000618
Corentin Wallez37c39792015-08-20 14:19:46 -0400619 // Update default framebuffer, the binding of the previous default
620 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400621 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500622 mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
623 if (mState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400624 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400625 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400626 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500627 if (mState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400628 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400629 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400630 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400631 }
Ian Ewell292f0052016-02-04 10:37:32 -0500632
Jamie Madill32643ce2018-10-19 11:38:03 -0400633 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500634 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635}
636
Jamie Madill4928b7c2017-06-20 12:57:39 -0400637egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400638{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500639 gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400640
Geoff Langbf7b95d2018-05-01 16:48:21 -0400641 // Remove the default framebuffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500642 if (mState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500643 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500644 mState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400645 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400647
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500648 if (mState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500649 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500650 mState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400651 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500652 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400653
654 if (defaultFramebuffer)
655 {
656 defaultFramebuffer->onDestroy(this);
657 delete defaultFramebuffer;
658 }
659
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500660 mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500661
662 if (mCurrentSurface)
663 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500665 mCurrentSurface = nullptr;
666 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400667
668 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400669}
670
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671GLuint Context::createBuffer()
672{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500673 return mState.mBufferManager->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676GLuint Context::createProgram()
677{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500678 return mState.mShaderProgramManager->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
Jiawei Shao385b3e02018-03-21 09:43:28 +0800681GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500683 return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
684 type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687GLuint Context::createTexture()
688{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500689 return mState.mTextureManager->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692GLuint Context::createRenderbuffer()
693{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500694 return mState.mRenderbufferManager->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
Jamie Madill13951342018-09-30 15:24:28 -0400697void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
698{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500699 ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400700}
701
Brandon Jones59770802018-04-02 13:18:42 -0700702GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300703{
Jamie Madill13951342018-09-30 15:24:28 -0400704 GLuint created = 0;
705 tryGenPaths(range, &created);
706 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300707}
708
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000709// Returns an unused framebuffer name
710GLuint Context::createFramebuffer()
711{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500712 return mState.mFramebufferManager->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713}
714
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500715void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500717 for (int i = 0; i < n; i++)
718 {
719 GLuint handle = mFenceNVHandleAllocator.allocate();
720 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
721 fences[i] = handle;
722 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723}
724
Yunchao Hea336b902017-08-02 16:05:21 +0800725GLuint Context::createProgramPipeline()
726{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500727 return mState.mProgramPipelineManager->createProgramPipeline();
Yunchao Hea336b902017-08-02 16:05:21 +0800728}
729
Jiawei Shao385b3e02018-03-21 09:43:28 +0800730GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800731{
732 UNIMPLEMENTED();
733 return 0u;
734}
735
James Darpinian4d9d4832018-03-13 12:43:28 -0700736void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000737{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500738 Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
James Darpinian4d9d4832018-03-13 12:43:28 -0700739 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000740 {
741 detachBuffer(buffer);
742 }
Jamie Madill893ab082014-05-16 16:56:10 -0400743
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500744 mState.mBufferManager->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000745}
746
747void Context::deleteShader(GLuint shader)
748{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500749 mState.mShaderProgramManager->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000750}
751
752void Context::deleteProgram(GLuint program)
753{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500754 mState.mShaderProgramManager->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000755}
756
757void Context::deleteTexture(GLuint texture)
758{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500759 if (mState.mTextureManager->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760 {
761 detachTexture(texture);
762 }
763
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500764 mState.mTextureManager->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000765}
766
767void Context::deleteRenderbuffer(GLuint renderbuffer)
768{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500769 if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770 {
771 detachRenderbuffer(renderbuffer);
772 }
Jamie Madill893ab082014-05-16 16:56:10 -0400773
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500774 mState.mRenderbufferManager->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000775}
776
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400777void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400778{
779 // The spec specifies the underlying Fence object is not deleted until all current
780 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
781 // and since our API is currently designed for being called from a single thread, we can delete
782 // the fence immediately.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500783 mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400784}
785
Yunchao Hea336b902017-08-02 16:05:21 +0800786void Context::deleteProgramPipeline(GLuint pipeline)
787{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500788 if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
Yunchao Hea336b902017-08-02 16:05:21 +0800789 {
790 detachProgramPipeline(pipeline);
791 }
792
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500793 mState.mProgramPipelineManager->deleteObject(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +0800794}
795
Sami Väisänene45e53b2016-05-25 10:36:04 +0300796void Context::deletePaths(GLuint first, GLsizei range)
797{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500798 mState.mPathManager->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300799}
800
Brandon Jones59770802018-04-02 13:18:42 -0700801bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300802{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500803 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300804 if (pathObj == nullptr)
805 return false;
806
807 return pathObj->hasPathData();
808}
809
Brandon Jones59770802018-04-02 13:18:42 -0700810bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300811{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500812 return mState.mPathManager->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300813}
814
Brandon Jones59770802018-04-02 13:18:42 -0700815void Context::pathCommands(GLuint path,
816 GLsizei numCommands,
817 const GLubyte *commands,
818 GLsizei numCoords,
819 GLenum coordType,
820 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300821{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500822 auto *pathObject = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823
Jamie Madill4f6592f2018-11-27 16:37:45 -0500824 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825}
826
Jamie Madill007530e2017-12-28 14:27:04 -0500827void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300828{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500829 Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300830
831 switch (pname)
832 {
833 case GL_PATH_STROKE_WIDTH_CHROMIUM:
834 pathObj->setStrokeWidth(value);
835 break;
836 case GL_PATH_END_CAPS_CHROMIUM:
837 pathObj->setEndCaps(static_cast<GLenum>(value));
838 break;
839 case GL_PATH_JOIN_STYLE_CHROMIUM:
840 pathObj->setJoinStyle(static_cast<GLenum>(value));
841 break;
842 case GL_PATH_MITER_LIMIT_CHROMIUM:
843 pathObj->setMiterLimit(value);
844 break;
845 case GL_PATH_STROKE_BOUND_CHROMIUM:
846 pathObj->setStrokeBound(value);
847 break;
848 default:
849 UNREACHABLE();
850 break;
851 }
852}
853
Jamie Madill007530e2017-12-28 14:27:04 -0500854void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855{
Jamie Madill007530e2017-12-28 14:27:04 -0500856 // TODO(jmadill): Should use proper clamping/casting.
857 pathParameterf(path, pname, static_cast<GLfloat>(value));
858}
859
860void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
861{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500862 const Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300863
864 switch (pname)
865 {
866 case GL_PATH_STROKE_WIDTH_CHROMIUM:
867 *value = pathObj->getStrokeWidth();
868 break;
869 case GL_PATH_END_CAPS_CHROMIUM:
870 *value = static_cast<GLfloat>(pathObj->getEndCaps());
871 break;
872 case GL_PATH_JOIN_STYLE_CHROMIUM:
873 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
874 break;
875 case GL_PATH_MITER_LIMIT_CHROMIUM:
876 *value = pathObj->getMiterLimit();
877 break;
878 case GL_PATH_STROKE_BOUND_CHROMIUM:
879 *value = pathObj->getStrokeBound();
880 break;
881 default:
882 UNREACHABLE();
883 break;
884 }
885}
886
Jamie Madill007530e2017-12-28 14:27:04 -0500887void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
888{
889 GLfloat val = 0.0f;
890 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
891 if (value)
892 *value = static_cast<GLint>(val);
893}
894
Brandon Jones59770802018-04-02 13:18:42 -0700895void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300896{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500897 mState.setPathStencilFunc(func, ref, mask);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300898}
899
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000900void Context::deleteFramebuffer(GLuint framebuffer)
901{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500902 if (mState.mFramebufferManager->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000903 {
904 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000905 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500906
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500907 mState.mFramebufferManager->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000908}
909
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500910void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000911{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500912 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000913 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500914 GLuint fence = fences[i];
915
916 FenceNV *fenceObject = nullptr;
917 if (mFenceNVMap.erase(fence, &fenceObject))
918 {
919 mFenceNVHandleAllocator.release(fence);
920 delete fenceObject;
921 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000922 }
923}
924
Geoff Lang70d0f492015-12-10 17:45:46 -0500925Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000926{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500927 return mState.mBufferManager->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000928}
929
Geoff Lang70d0f492015-12-10 17:45:46 -0500930Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000931{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500932 return mState.mRenderbufferManager->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000933}
934
Jamie Madill70b5bb02017-08-28 13:32:37 -0400935Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400936{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500937 return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400938}
939
Jamie Madill57a89722013-07-02 11:57:03 -0400940VertexArray *Context::getVertexArray(GLuint handle) const
941{
Jamie Madill96a483b2017-06-27 16:49:21 -0400942 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400943}
944
Jamie Madilldc356042013-07-19 16:36:57 -0400945Sampler *Context::getSampler(GLuint handle) const
946{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500947 return mState.mSamplerManager->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400948}
949
Geoff Langc8058452014-02-03 12:04:11 -0500950TransformFeedback *Context::getTransformFeedback(GLuint handle) const
951{
Jamie Madill96a483b2017-06-27 16:49:21 -0400952 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500953}
954
Yunchao Hea336b902017-08-02 16:05:21 +0800955ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
956{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500957 return mState.mProgramPipelineManager->getProgramPipeline(handle);
Yunchao Hea336b902017-08-02 16:05:21 +0800958}
959
Geoff Lang75359662018-04-11 01:42:27 -0400960gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500961{
962 switch (identifier)
963 {
964 case GL_BUFFER:
965 return getBuffer(name);
966 case GL_SHADER:
967 return getShader(name);
968 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -0400969 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -0500970 case GL_VERTEX_ARRAY:
971 return getVertexArray(name);
972 case GL_QUERY:
973 return getQuery(name);
974 case GL_TRANSFORM_FEEDBACK:
975 return getTransformFeedback(name);
976 case GL_SAMPLER:
977 return getSampler(name);
978 case GL_TEXTURE:
979 return getTexture(name);
980 case GL_RENDERBUFFER:
981 return getRenderbuffer(name);
982 case GL_FRAMEBUFFER:
983 return getFramebuffer(name);
984 default:
985 UNREACHABLE();
986 return nullptr;
987 }
988}
989
Geoff Lang75359662018-04-11 01:42:27 -0400990gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500991{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400992 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500993}
994
Martin Radev9d901792016-07-15 15:58:58 +0300995void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
996{
Geoff Lang75359662018-04-11 01:42:27 -0400997 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300998 ASSERT(object != nullptr);
999
1000 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001001 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001002
1003 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1004 // specified object is active until we do this.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001005 mState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001006}
1007
1008void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1009{
Geoff Lang75359662018-04-11 01:42:27 -04001010 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001011 ASSERT(object != nullptr);
1012
1013 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001014 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001015}
1016
1017void Context::getObjectLabel(GLenum identifier,
1018 GLuint name,
1019 GLsizei bufSize,
1020 GLsizei *length,
1021 GLchar *label) const
1022{
Geoff Lang75359662018-04-11 01:42:27 -04001023 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001024 ASSERT(object != nullptr);
1025
1026 const std::string &objectLabel = object->getLabel();
1027 GetObjectLabelBase(objectLabel, bufSize, length, label);
1028}
1029
1030void Context::getObjectPtrLabel(const void *ptr,
1031 GLsizei bufSize,
1032 GLsizei *length,
1033 GLchar *label) const
1034{
Geoff Lang75359662018-04-11 01:42:27 -04001035 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001036 ASSERT(object != nullptr);
1037
1038 const std::string &objectLabel = object->getLabel();
1039 GetObjectLabelBase(objectLabel, bufSize, length, label);
1040}
1041
Jamie Madilldc356042013-07-19 16:36:57 -04001042bool Context::isSampler(GLuint samplerName) const
1043{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001044 return mState.mSamplerManager->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001045}
1046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001047void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001049 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001050
Jamie Madilldedd7b92014-11-05 16:30:36 -05001051 if (handle == 0)
1052 {
1053 texture = mZeroTextures[target].get();
1054 }
1055 else
1056 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001057 texture =
1058 mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001059 }
1060
1061 ASSERT(texture);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001062 mState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001063 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001064}
1065
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001066void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001067{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001068 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1069 mImplementation.get(), mState.mCaps, framebufferHandle);
1070 mState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001071 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001072}
1073
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001074void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001076 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1077 mImplementation.get(), mState.mCaps, framebufferHandle);
1078 mState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001079 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001080 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081}
1082
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001083void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001084{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001085 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001086 mState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001087 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001088 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001089}
1090
Shao80957d92017-02-20 21:25:59 +08001091void Context::bindVertexBuffer(GLuint bindingIndex,
1092 GLuint bufferHandle,
1093 GLintptr offset,
1094 GLsizei stride)
1095{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001096 Buffer *buffer =
1097 mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
1098 mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001099 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001100}
1101
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001102void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001103{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001104 ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001105 Sampler *sampler =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001106 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
1107 mState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001108 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001109}
1110
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001111void Context::bindImageTexture(GLuint unit,
1112 GLuint texture,
1113 GLint level,
1114 GLboolean layered,
1115 GLint layer,
1116 GLenum access,
1117 GLenum format)
1118{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001119 Texture *tex = mState.mTextureManager->getTexture(texture);
1120 mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001121}
1122
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001123void Context::useProgram(GLuint program)
1124{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001125 ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001126 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001127}
1128
Jiajia Qin5451d532017-11-16 17:16:34 +08001129void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1130{
1131 UNIMPLEMENTED();
1132}
1133
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001134void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001135{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001136 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001137 TransformFeedback *transformFeedback =
1138 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001139 mState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001140}
1141
Yunchao Hea336b902017-08-02 16:05:21 +08001142void Context::bindProgramPipeline(GLuint pipelineHandle)
1143{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001144 ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
1145 mImplementation.get(), pipelineHandle);
1146 mState.setProgramPipelineBinding(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08001147}
1148
Corentin Wallezad3ae902018-03-09 13:40:42 -05001149void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001152 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153
Geoff Lang5aad9672014-09-08 11:10:42 -04001154 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001155 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001156
1157 // set query as active for specified target only if begin succeeded
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001158 mState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001159 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160}
1161
Corentin Wallezad3ae902018-03-09 13:40:42 -05001162void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001164 Query *queryObject = mState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001165 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166
Jamie Madill4f6592f2018-11-27 16:37:45 -05001167 // Intentionally don't call try here. We don't want an early return.
1168 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169
Geoff Lang5aad9672014-09-08 11:10:42 -04001170 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001171 mState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001172 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173}
1174
Corentin Wallezad3ae902018-03-09 13:40:42 -05001175void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001177 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178
1179 Query *queryObject = getQuery(id, true, target);
1180 ASSERT(queryObject);
1181
Jamie Madill4f6592f2018-11-27 16:37:45 -05001182 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001183}
1184
Corentin Wallezad3ae902018-03-09 13:40:42 -05001185void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186{
1187 switch (pname)
1188 {
1189 case GL_CURRENT_QUERY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001190 params[0] = mState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191 break;
1192 case GL_QUERY_COUNTER_BITS_EXT:
1193 switch (target)
1194 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001195 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001196 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1197 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001198 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199 params[0] = getExtensions().queryCounterBitsTimestamp;
1200 break;
1201 default:
1202 UNREACHABLE();
1203 params[0] = 0;
1204 break;
1205 }
1206 break;
1207 default:
1208 UNREACHABLE();
1209 return;
1210 }
1211}
1212
Corentin Wallezad3ae902018-03-09 13:40:42 -05001213void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001214 GLenum pname,
1215 GLsizei bufSize,
1216 GLsizei *length,
1217 GLint *params)
1218{
1219 getQueryiv(target, pname, params);
1220}
1221
Geoff Lang2186c382016-10-14 10:54:54 -04001222void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001224 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225}
1226
Brandon Jones59770802018-04-02 13:18:42 -07001227void Context::getQueryObjectivRobust(GLuint id,
1228 GLenum pname,
1229 GLsizei bufSize,
1230 GLsizei *length,
1231 GLint *params)
1232{
1233 getQueryObjectiv(id, pname, params);
1234}
1235
Geoff Lang2186c382016-10-14 10:54:54 -04001236void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001237{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001238 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239}
1240
Brandon Jones59770802018-04-02 13:18:42 -07001241void Context::getQueryObjectuivRobust(GLuint id,
1242 GLenum pname,
1243 GLsizei bufSize,
1244 GLsizei *length,
1245 GLuint *params)
1246{
1247 getQueryObjectuiv(id, pname, params);
1248}
1249
Geoff Lang2186c382016-10-14 10:54:54 -04001250void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001251{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001252 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001253}
1254
Brandon Jones59770802018-04-02 13:18:42 -07001255void Context::getQueryObjecti64vRobust(GLuint id,
1256 GLenum pname,
1257 GLsizei bufSize,
1258 GLsizei *length,
1259 GLint64 *params)
1260{
1261 getQueryObjecti64v(id, pname, params);
1262}
1263
Geoff Lang2186c382016-10-14 10:54:54 -04001264void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001265{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001266 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267}
1268
Brandon Jones59770802018-04-02 13:18:42 -07001269void Context::getQueryObjectui64vRobust(GLuint id,
1270 GLenum pname,
1271 GLsizei bufSize,
1272 GLsizei *length,
1273 GLuint64 *params)
1274{
1275 getQueryObjectui64v(id, pname, params);
1276}
1277
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001278Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001280 return mState.mFramebufferManager->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281}
1282
Jamie Madill2f348d22017-06-05 10:50:59 -04001283FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284{
Jamie Madill96a483b2017-06-27 16:49:21 -04001285 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286}
1287
Corentin Wallezad3ae902018-03-09 13:40:42 -05001288Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289{
Jamie Madill96a483b2017-06-27 16:49:21 -04001290 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001292 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001294
1295 Query *query = mQueryMap.query(handle);
1296 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001297 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001298 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001299 query = new Query(mImplementation->createQuery(type), handle);
1300 query->addRef();
1301 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001302 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001303 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001304}
1305
Geoff Lang70d0f492015-12-10 17:45:46 -05001306Query *Context::getQuery(GLuint handle) const
1307{
Jamie Madill96a483b2017-06-27 16:49:21 -04001308 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001309}
1310
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001311Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001312{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001313 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001314 return mState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001315}
1316
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001317Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001319 return mState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320}
1321
Geoff Lang492a7e42014-11-05 13:27:06 -05001322Compiler *Context::getCompiler() const
1323{
Jamie Madill2f348d22017-06-05 10:50:59 -04001324 if (mCompiler.get() == nullptr)
1325 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001326 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001327 }
1328 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001329}
1330
Jamie Madillc1d770e2017-04-13 17:31:24 -04001331void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332{
1333 switch (pname)
1334 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001335 case GL_SHADER_COMPILER:
1336 *params = GL_TRUE;
1337 break;
1338 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1339 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1340 break;
Jeff Gilbert465d6092019-01-02 16:21:18 -08001341
Jamie Madill231c7f52017-04-26 13:45:37 -04001342 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001343 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001344 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346}
1347
Jamie Madillc1d770e2017-04-13 17:31:24 -04001348void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349{
Shannon Woods53a94a82014-06-24 15:20:36 -04001350 // Queries about context capabilities and maximums are answered by Context.
1351 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001352 switch (pname)
1353 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001355 params[0] = mState.mCaps.minAliasedLineWidth;
1356 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001359 params[0] = mState.mCaps.minAliasedPointSize;
1360 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001361 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001362 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001363 params[0] = mState.mCaps.minSmoothPointSize;
1364 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001365 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001366 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001367 params[0] = mState.mCaps.minSmoothLineWidth;
1368 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001369 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001371 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1372 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 break;
1374 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001375 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001376 break;
1377
1378 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1379 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1380 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001381 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1382 // GLES1 constants for modelview/projection matrix.
1383 if (getClientVersion() < Version(2, 0))
1384 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001385 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001386 }
1387 else
1388 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001389 ASSERT(mState.mExtensions.pathRendering);
1390 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001391 memcpy(params, m, 16 * sizeof(GLfloat));
1392 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001394 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001395
Jamie Madill231c7f52017-04-26 13:45:37 -04001396 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001397 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001398 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001399 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400}
1401
Jamie Madillc1d770e2017-04-13 17:31:24 -04001402void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001403{
Shannon Woods53a94a82014-06-24 15:20:36 -04001404 // Queries about context capabilities and maximums are answered by Context.
1405 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001406
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001407 switch (pname)
1408 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001410 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 break;
1412 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001413 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 break;
1415 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001416 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 break;
1418 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001419 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001420 break;
1421 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001422 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 break;
1424 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001425 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001426 break;
1427 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001428 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001429 break;
1430 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001431 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 break;
1433 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001434 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 break;
1436 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001437 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 break;
1439 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001440 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001441 break;
1442 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001443 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001444 break;
1445 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001446 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 case GL_SUBPIXEL_BITS:
1449 *params = 4;
1450 break;
1451 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001452 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001454 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001455 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001456 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001457 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001458 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001459 break;
1460 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001461 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 break;
1463 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001464 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001465 break;
1466 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001467 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001470 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 break;
1472 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001473 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001476 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001479 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 break;
1481 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001482 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001483 break;
1484 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001485 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 break;
1487 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001488 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 break;
1490 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001491 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001492 break;
1493 case GL_MAJOR_VERSION:
1494 *params = getClientVersion().major;
1495 break;
1496 case GL_MINOR_VERSION:
1497 *params = getClientVersion().minor;
1498 break;
1499 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001500 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001501 break;
1502 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001503 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 break;
1505 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001506 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001507 break;
1508 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001509 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001510 break;
1511 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001512 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 break;
1514 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001515 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001516 break;
1517 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001518 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001519 break;
1520 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001521 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001522 params[0] = mState.mCaps.maxViewportWidth;
1523 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001524 }
1525 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001526 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001527 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1528 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001529 break;
1530 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1531 *params = mResetStrategy;
1532 break;
1533 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001534 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001535 break;
1536 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001537 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1538 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001539 break;
1540 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001541 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001544 std::copy(mState.mCaps.programBinaryFormats.begin(),
1545 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001546 break;
1547 case GL_NUM_EXTENSIONS:
1548 *params = static_cast<GLint>(mExtensionStrings.size());
1549 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001550
Geoff Lang38f24ee2018-10-01 13:04:59 -04001551 // GL_ANGLE_request_extension
1552 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1553 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1554 break;
1555
Jamie Madill231c7f52017-04-26 13:45:37 -04001556 // GL_KHR_debug
1557 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001558 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001559 break;
1560 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001561 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001562 break;
1563 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001564 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 break;
1566 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001567 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001568 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001569
Martin Radeve5285d22017-07-14 16:23:53 +03001570 // GL_ANGLE_multiview
1571 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001572 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001573 break;
1574
Jamie Madill231c7f52017-04-26 13:45:37 -04001575 // GL_EXT_disjoint_timer_query
1576 case GL_GPU_DISJOINT_EXT:
1577 *params = mImplementation->getGPUDisjoint();
1578 break;
1579 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001580 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001583 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001584 break;
1585 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001586 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001587 break;
1588 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001589 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001592 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001595 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001598 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001601 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001604 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001607 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001610 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001613 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001614 break;
1615 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001616 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 break;
1618 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001619 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001620 break;
1621 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001622 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001625 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001628 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001631 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001634 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001637 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001640 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001643 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001646 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001649 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001652 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001655 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001658 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001661 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001664 *params = static_cast<GLint>(
1665 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001668 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001671 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001674 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001677 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001680 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001683 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001686 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001689 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001692 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001695 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001698 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001701 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001703
1704 // GL_EXT_geometry_shader
1705 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001706 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001707 break;
1708 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001709 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001710 break;
1711 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001712 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001713 break;
1714 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001715 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001716 break;
1717 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001718 *params = static_cast<GLint>(
1719 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001720 break;
1721 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001722 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001725 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001728 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001731 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001734 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001735 break;
1736 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001737 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001738 break;
1739 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001740 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001741 break;
1742 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001743 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001744 break;
1745 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001746 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001747 break;
1748 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001749 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001751 // GLES1 emulation: Caps queries
1752 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001753 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001754 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001755 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001756 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001757 break;
1758 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001759 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001760 break;
1761 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001762 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001763 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001764 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001765 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001766 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001767 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001768 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001769 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001770 // GLES1 emulation: Vertex attribute queries
1771 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1772 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1773 case GL_COLOR_ARRAY_BUFFER_BINDING:
1774 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1775 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1776 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1777 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1778 break;
1779 case GL_VERTEX_ARRAY_STRIDE:
1780 case GL_NORMAL_ARRAY_STRIDE:
1781 case GL_COLOR_ARRAY_STRIDE:
1782 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1783 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1784 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1785 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1786 break;
1787 case GL_VERTEX_ARRAY_SIZE:
1788 case GL_COLOR_ARRAY_SIZE:
1789 case GL_TEXTURE_COORD_ARRAY_SIZE:
1790 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1791 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1792 break;
1793 case GL_VERTEX_ARRAY_TYPE:
1794 case GL_COLOR_ARRAY_TYPE:
1795 case GL_NORMAL_ARRAY_TYPE:
1796 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1797 case GL_TEXTURE_COORD_ARRAY_TYPE:
1798 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1799 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1800 break;
1801
jchen1082af6202018-06-22 10:59:52 +08001802 // GL_KHR_parallel_shader_compile
1803 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001804 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001805 break;
1806
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001807 // GL_EXT_blend_func_extended
1808 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001809 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001810 break;
1811
Jamie Madill231c7f52017-04-26 13:45:37 -04001812 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001813 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001814 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001815 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001816}
1817
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001818void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001819{
Shannon Woods53a94a82014-06-24 15:20:36 -04001820 // Queries about context capabilities and maximums are answered by Context.
1821 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001822 switch (pname)
1823 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001824 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001825 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001826 break;
1827 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001828 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001829 break;
1830 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001831 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001832 break;
1833 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001834 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001835 break;
1836 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001837 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001838 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001839
Jamie Madill231c7f52017-04-26 13:45:37 -04001840 // GL_EXT_disjoint_timer_query
1841 case GL_TIMESTAMP_EXT:
1842 *params = mImplementation->getTimestamp();
1843 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001844
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001846 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 break;
1848 default:
1849 UNREACHABLE();
1850 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001851 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001852}
1853
Geoff Lang70d0f492015-12-10 17:45:46 -05001854void Context::getPointerv(GLenum pname, void **params) const
1855{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001856 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001857}
1858
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001859void Context::getPointervRobustANGLERobust(GLenum pname,
1860 GLsizei bufSize,
1861 GLsizei *length,
1862 void **params)
1863{
1864 UNIMPLEMENTED();
1865}
1866
Martin Radev66fb8202016-07-28 11:45:20 +03001867void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001868{
Shannon Woods53a94a82014-06-24 15:20:36 -04001869 // Queries about context capabilities and maximums are answered by Context.
1870 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001871
1872 GLenum nativeType;
1873 unsigned int numParams;
1874 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1875 ASSERT(queryStatus);
1876
1877 if (nativeType == GL_INT)
1878 {
1879 switch (target)
1880 {
1881 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1882 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001883 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001884 break;
1885 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1886 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001887 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001888 break;
1889 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001890 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001891 }
1892 }
1893 else
1894 {
1895 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1896 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001897}
1898
Brandon Jones59770802018-04-02 13:18:42 -07001899void Context::getIntegeri_vRobust(GLenum target,
1900 GLuint index,
1901 GLsizei bufSize,
1902 GLsizei *length,
1903 GLint *data)
1904{
1905 getIntegeri_v(target, index, data);
1906}
1907
Martin Radev66fb8202016-07-28 11:45:20 +03001908void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001909{
Shannon Woods53a94a82014-06-24 15:20:36 -04001910 // Queries about context capabilities and maximums are answered by Context.
1911 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001912
1913 GLenum nativeType;
1914 unsigned int numParams;
1915 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1916 ASSERT(queryStatus);
1917
1918 if (nativeType == GL_INT_64_ANGLEX)
1919 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001920 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001921 }
1922 else
1923 {
1924 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1925 }
1926}
1927
Brandon Jones59770802018-04-02 13:18:42 -07001928void Context::getInteger64i_vRobust(GLenum target,
1929 GLuint index,
1930 GLsizei bufSize,
1931 GLsizei *length,
1932 GLint64 *data)
1933{
1934 getInteger64i_v(target, index, data);
1935}
1936
Martin Radev66fb8202016-07-28 11:45:20 +03001937void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1938{
1939 // Queries about context capabilities and maximums are answered by Context.
1940 // Queries about current GL state values are answered by State.
1941
1942 GLenum nativeType;
1943 unsigned int numParams;
1944 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1945 ASSERT(queryStatus);
1946
1947 if (nativeType == GL_BOOL)
1948 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001949 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001950 }
1951 else
1952 {
1953 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1954 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001955}
1956
Brandon Jones59770802018-04-02 13:18:42 -07001957void Context::getBooleani_vRobust(GLenum target,
1958 GLuint index,
1959 GLsizei bufSize,
1960 GLsizei *length,
1961 GLboolean *data)
1962{
1963 getBooleani_v(target, index, data);
1964}
1965
Corentin Wallez336129f2017-10-17 15:55:40 -04001966void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001967{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001968 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001969 QueryBufferParameteriv(buffer, pname, params);
1970}
1971
Brandon Jones59770802018-04-02 13:18:42 -07001972void Context::getBufferParameterivRobust(BufferBinding target,
1973 GLenum pname,
1974 GLsizei bufSize,
1975 GLsizei *length,
1976 GLint *params)
1977{
1978 getBufferParameteriv(target, pname, params);
1979}
1980
He Yunchao010e4db2017-03-03 14:22:06 +08001981void Context::getFramebufferAttachmentParameteriv(GLenum target,
1982 GLenum attachment,
1983 GLenum pname,
1984 GLint *params)
1985{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001986 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001987 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001988}
1989
Brandon Jones59770802018-04-02 13:18:42 -07001990void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1991 GLenum attachment,
1992 GLenum pname,
1993 GLsizei bufSize,
1994 GLsizei *length,
1995 GLint *params)
1996{
1997 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1998}
1999
He Yunchao010e4db2017-03-03 14:22:06 +08002000void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2001{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002002 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08002003 QueryRenderbufferiv(this, renderbuffer, pname, params);
2004}
2005
Brandon Jones59770802018-04-02 13:18:42 -07002006void Context::getRenderbufferParameterivRobust(GLenum target,
2007 GLenum pname,
2008 GLsizei bufSize,
2009 GLsizei *length,
2010 GLint *params)
2011{
2012 getRenderbufferParameteriv(target, pname, params);
2013}
2014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002015void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002016{
Till Rathmannb8543632018-10-02 19:46:14 +02002017 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002018 QueryTexParameterfv(texture, pname, params);
2019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::getTexParameterfvRobust(TextureType target,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 GLsizei *length,
2025 GLfloat *params)
2026{
2027 getTexParameterfv(target, pname, params);
2028}
2029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002030void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002031{
Till Rathmannb8543632018-10-02 19:46:14 +02002032 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002033 QueryTexParameteriv(texture, pname, params);
2034}
Jiajia Qin5451d532017-11-16 17:16:34 +08002035
Till Rathmannb8543632018-10-02 19:46:14 +02002036void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2037{
2038 const Texture *const texture = getTargetTexture(target);
2039 QueryTexParameterIiv(texture, pname, params);
2040}
2041
2042void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2043{
2044 const Texture *const texture = getTargetTexture(target);
2045 QueryTexParameterIuiv(texture, pname, params);
2046}
2047
Brandon Jones59770802018-04-02 13:18:42 -07002048void Context::getTexParameterivRobust(TextureType target,
2049 GLenum pname,
2050 GLsizei bufSize,
2051 GLsizei *length,
2052 GLint *params)
2053{
2054 getTexParameteriv(target, pname, params);
2055}
2056
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002057void Context::getTexParameterIivRobust(TextureType target,
2058 GLenum pname,
2059 GLsizei bufSize,
2060 GLsizei *length,
2061 GLint *params)
2062{
2063 UNIMPLEMENTED();
2064}
2065
2066void Context::getTexParameterIuivRobust(TextureType target,
2067 GLenum pname,
2068 GLsizei bufSize,
2069 GLsizei *length,
2070 GLuint *params)
2071{
2072 UNIMPLEMENTED();
2073}
2074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002075void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002076{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002077 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002078 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002079}
2080
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002081void Context::getTexLevelParameterivRobust(TextureTarget target,
2082 GLint level,
2083 GLenum pname,
2084 GLsizei bufSize,
2085 GLsizei *length,
2086 GLint *params)
2087{
2088 UNIMPLEMENTED();
2089}
2090
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002091void Context::getTexLevelParameterfv(TextureTarget target,
2092 GLint level,
2093 GLenum pname,
2094 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002095{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002097 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002098}
2099
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002100void Context::getTexLevelParameterfvRobust(TextureTarget target,
2101 GLint level,
2102 GLenum pname,
2103 GLsizei bufSize,
2104 GLsizei *length,
2105 GLfloat *params)
2106{
2107 UNIMPLEMENTED();
2108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002111{
Till Rathmannb8543632018-10-02 19:46:14 +02002112 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002113 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002114}
2115
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002116void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002117{
Till Rathmannb8543632018-10-02 19:46:14 +02002118 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002119 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002120}
2121
Brandon Jones59770802018-04-02 13:18:42 -07002122void Context::texParameterfvRobust(TextureType target,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 const GLfloat *params)
2126{
2127 texParameterfv(target, pname, params);
2128}
2129
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002130void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002131{
Till Rathmannb8543632018-10-02 19:46:14 +02002132 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002133 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002134}
2135
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002136void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002137{
Till Rathmannb8543632018-10-02 19:46:14 +02002138 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002139 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002140}
2141
Till Rathmannb8543632018-10-02 19:46:14 +02002142void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2143{
2144 Texture *const texture = getTargetTexture(target);
2145 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002146}
2147
2148void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2149{
2150 Texture *const texture = getTargetTexture(target);
2151 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002152}
2153
Brandon Jones59770802018-04-02 13:18:42 -07002154void Context::texParameterivRobust(TextureType target,
2155 GLenum pname,
2156 GLsizei bufSize,
2157 const GLint *params)
2158{
2159 texParameteriv(target, pname, params);
2160}
2161
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002162void Context::texParameterIivRobust(TextureType target,
2163 GLenum pname,
2164 GLsizei bufSize,
2165 const GLint *params)
2166{
2167 UNIMPLEMENTED();
2168}
2169
2170void Context::texParameterIuivRobust(TextureType target,
2171 GLenum pname,
2172 GLsizei bufSize,
2173 const GLuint *params)
2174{
2175 UNIMPLEMENTED();
2176}
2177
Jamie Madill493f9572018-05-24 19:52:15 -04002178void Context::drawArraysInstanced(PrimitiveMode mode,
2179 GLint first,
2180 GLsizei count,
2181 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002182{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002183 // No-op if count draws no primitives for given mode
2184 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002185 {
2186 return;
2187 }
2188
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002189 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002190 ANGLE_CONTEXT_TRY(
2191 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002192 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002193}
2194
Jamie Madill493f9572018-05-24 19:52:15 -04002195void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002196 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002197 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002198 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002199 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002200{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002201 // No-op if count draws no primitives for given mode
2202 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002203 {
2204 return;
2205 }
2206
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002207 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002208 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002209 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002210}
2211
Jamie Madill493f9572018-05-24 19:52:15 -04002212void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002213 GLuint start,
2214 GLuint end,
2215 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002216 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002217 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002218{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002219 // No-op if count draws no primitives for given mode
2220 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002221 {
2222 return;
2223 }
2224
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002225 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002226 ANGLE_CONTEXT_TRY(
2227 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228}
2229
Jamie Madill493f9572018-05-24 19:52:15 -04002230void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002231{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002232 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002233 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002234}
2235
Jamie Madill8dc27f92018-11-29 11:45:44 -05002236void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002237{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002238 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002239 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002240}
2241
Jamie Madill675fe712016-12-19 13:07:54 -05002242void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002243{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002244 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002245}
2246
Jamie Madill675fe712016-12-19 13:07:54 -05002247void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002248{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002249 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250}
2251
Austin Kinross6ee1e782015-05-29 17:05:37 -07002252void Context::insertEventMarker(GLsizei length, const char *marker)
2253{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002254 ASSERT(mImplementation);
2255 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002256}
2257
2258void Context::pushGroupMarker(GLsizei length, const char *marker)
2259{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002260 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002261
2262 if (marker == nullptr)
2263 {
2264 // From the EXT_debug_marker spec,
2265 // "If <marker> is null then an empty string is pushed on the stack."
2266 mImplementation->pushGroupMarker(length, "");
2267 }
2268 else
2269 {
2270 mImplementation->pushGroupMarker(length, marker);
2271 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002272}
2273
2274void Context::popGroupMarker()
2275{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002276 ASSERT(mImplementation);
2277 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002278}
2279
Geoff Langd8605522016-04-13 10:19:12 -04002280void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2281{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002282 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002283 ASSERT(programObject);
2284
2285 programObject->bindUniformLocation(location, name);
2286}
2287
Brandon Jones59770802018-04-02 13:18:42 -07002288void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002289{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002290 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002291}
2292
Brandon Jones59770802018-04-02 13:18:42 -07002293void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002294{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002295 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002296}
2297
Brandon Jones59770802018-04-02 13:18:42 -07002298void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002299{
2300 GLfloat I[16];
2301 angle::Matrix<GLfloat>::setToIdentity(I);
2302
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002303 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002304}
2305
2306void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2307{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002308 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002309 if (!pathObj)
2310 return;
2311
Geoff Lang9bf86f02018-07-26 11:46:34 -04002312 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002313
2314 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2315}
2316
2317void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2318{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002319 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002320 if (!pathObj)
2321 return;
2322
Geoff Lang9bf86f02018-07-26 11:46:34 -04002323 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002324
2325 mImplementation->stencilStrokePath(pathObj, reference, mask);
2326}
2327
2328void Context::coverFillPath(GLuint path, GLenum coverMode)
2329{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002330 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002331 if (!pathObj)
2332 return;
2333
Geoff Lang9bf86f02018-07-26 11:46:34 -04002334 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002335
2336 mImplementation->coverFillPath(pathObj, coverMode);
2337}
2338
2339void Context::coverStrokePath(GLuint path, GLenum coverMode)
2340{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002341 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002342 if (!pathObj)
2343 return;
2344
Geoff Lang9bf86f02018-07-26 11:46:34 -04002345 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002346
2347 mImplementation->coverStrokePath(pathObj, coverMode);
2348}
2349
2350void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2351{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002352 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002353 if (!pathObj)
2354 return;
2355
Geoff Lang9bf86f02018-07-26 11:46:34 -04002356 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357
2358 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2359}
2360
2361void Context::stencilThenCoverStrokePath(GLuint path,
2362 GLint reference,
2363 GLuint mask,
2364 GLenum coverMode)
2365{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002366 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002367 if (!pathObj)
2368 return;
2369
Geoff Lang9bf86f02018-07-26 11:46:34 -04002370 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002371
2372 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2373}
2374
Sami Väisänend59ca052016-06-21 16:10:00 +03002375void Context::coverFillPathInstanced(GLsizei numPaths,
2376 GLenum pathNameType,
2377 const void *paths,
2378 GLuint pathBase,
2379 GLenum coverMode,
2380 GLenum transformType,
2381 const GLfloat *transformValues)
2382{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002383 const auto &pathObjects =
2384 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002385
Geoff Lang9bf86f02018-07-26 11:46:34 -04002386 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2389}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002390
Sami Väisänend59ca052016-06-21 16:10:00 +03002391void Context::coverStrokePathInstanced(GLsizei numPaths,
2392 GLenum pathNameType,
2393 const void *paths,
2394 GLuint pathBase,
2395 GLenum coverMode,
2396 GLenum transformType,
2397 const GLfloat *transformValues)
2398{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002399 const auto &pathObjects =
2400 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002401
2402 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002403 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002404
2405 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2406 transformValues);
2407}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002408
Sami Väisänend59ca052016-06-21 16:10:00 +03002409void Context::stencilFillPathInstanced(GLsizei numPaths,
2410 GLenum pathNameType,
2411 const void *paths,
2412 GLuint pathBase,
2413 GLenum fillMode,
2414 GLuint mask,
2415 GLenum transformType,
2416 const GLfloat *transformValues)
2417{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002418 const auto &pathObjects =
2419 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002420
2421 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002422 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
2424 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2425 transformValues);
2426}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002427
Sami Väisänend59ca052016-06-21 16:10:00 +03002428void Context::stencilStrokePathInstanced(GLsizei numPaths,
2429 GLenum pathNameType,
2430 const void *paths,
2431 GLuint pathBase,
2432 GLint reference,
2433 GLuint mask,
2434 GLenum transformType,
2435 const GLfloat *transformValues)
2436{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002437 const auto &pathObjects =
2438 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002439
Geoff Lang9bf86f02018-07-26 11:46:34 -04002440 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2443 transformValues);
2444}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002445
Sami Väisänend59ca052016-06-21 16:10:00 +03002446void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2447 GLenum pathNameType,
2448 const void *paths,
2449 GLuint pathBase,
2450 GLenum fillMode,
2451 GLuint mask,
2452 GLenum coverMode,
2453 GLenum transformType,
2454 const GLfloat *transformValues)
2455{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002456 const auto &pathObjects =
2457 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002458
Geoff Lang9bf86f02018-07-26 11:46:34 -04002459 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002460
2461 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2462 transformType, transformValues);
2463}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002464
Sami Väisänend59ca052016-06-21 16:10:00 +03002465void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2466 GLenum pathNameType,
2467 const void *paths,
2468 GLuint pathBase,
2469 GLint reference,
2470 GLuint mask,
2471 GLenum coverMode,
2472 GLenum transformType,
2473 const GLfloat *transformValues)
2474{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002475 const auto &pathObjects =
2476 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002477
Geoff Lang9bf86f02018-07-26 11:46:34 -04002478 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002479
2480 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2481 transformType, transformValues);
2482}
2483
Sami Väisänen46eaa942016-06-29 10:26:37 +03002484void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2485{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002486 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002487
2488 programObject->bindFragmentInputLocation(location, name);
2489}
2490
2491void Context::programPathFragmentInputGen(GLuint program,
2492 GLint location,
2493 GLenum genMode,
2494 GLint components,
2495 const GLfloat *coeffs)
2496{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002497 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002498
jchen103fd614d2018-08-13 12:21:58 +08002499 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002500}
2501
jchen1015015f72017-03-16 13:54:21 +08002502GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2503{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002504 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002505 return QueryProgramResourceIndex(programObject, programInterface, name);
2506}
2507
jchen10fd7c3b52017-03-21 15:36:03 +08002508void Context::getProgramResourceName(GLuint program,
2509 GLenum programInterface,
2510 GLuint index,
2511 GLsizei bufSize,
2512 GLsizei *length,
2513 GLchar *name)
2514{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002515 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002516 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2517}
2518
jchen10191381f2017-04-11 13:59:04 +08002519GLint Context::getProgramResourceLocation(GLuint program,
2520 GLenum programInterface,
2521 const GLchar *name)
2522{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002523 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002524 return QueryProgramResourceLocation(programObject, programInterface, name);
2525}
2526
jchen10880683b2017-04-12 16:21:55 +08002527void Context::getProgramResourceiv(GLuint program,
2528 GLenum programInterface,
2529 GLuint index,
2530 GLsizei propCount,
2531 const GLenum *props,
2532 GLsizei bufSize,
2533 GLsizei *length,
2534 GLint *params)
2535{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002536 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002537 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2538 length, params);
2539}
2540
jchen10d9cd7b72017-08-30 15:04:25 +08002541void Context::getProgramInterfaceiv(GLuint program,
2542 GLenum programInterface,
2543 GLenum pname,
2544 GLint *params)
2545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002546 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002547 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2548}
2549
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002550void Context::getProgramInterfaceivRobust(GLuint program,
2551 GLenum programInterface,
2552 GLenum pname,
2553 GLsizei bufSize,
2554 GLsizei *length,
2555 GLint *params)
2556{
2557 UNIMPLEMENTED();
2558}
2559
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002560void Context::handleError(GLenum errorCode,
2561 const char *message,
2562 const char *file,
2563 const char *function,
2564 unsigned int line)
2565{
2566 mErrors.handleError(errorCode, message, file, function, line);
2567}
2568
Jamie Madilla139f012018-10-10 16:13:03 -04002569void Context::validationError(GLenum errorCode, const char *message)
2570{
2571 mErrors.validationError(errorCode, message);
2572}
2573
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574// Get one of the recorded errors and clear its flag, if any.
2575// [OpenGL ES 2.0.24] section 2.5 page 13.
2576GLenum Context::getError()
2577{
Geoff Langda5777c2014-07-11 09:52:58 -04002578 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002579 {
Geoff Langda5777c2014-07-11 09:52:58 -04002580 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581 }
Geoff Langda5777c2014-07-11 09:52:58 -04002582 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002584 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002586}
2587
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002589void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590{
2591 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002592 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002593 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002594 mContextLostForced = true;
2595 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002596 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002597}
2598
Jamie Madillfa920eb2018-01-04 11:45:50 -05002599GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002600{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601 // Even if the application doesn't want to know about resets, we want to know
2602 // as it will allow us to skip all the calls.
2603 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002604 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002605 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002606 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002608 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002609
2610 // EXT_robustness, section 2.6: If the reset notification behavior is
2611 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2612 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2613 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 }
2615
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2617 // status should be returned at least once, and GL_NO_ERROR should be returned
2618 // once the device has finished resetting.
2619 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002620 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621 ASSERT(mResetStatus == GL_NO_ERROR);
2622 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002623
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
2628 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002629 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002631 // If markContextLost was used to mark the context lost then
2632 // assume that is not recoverable, and continue to report the
2633 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 mResetStatus = mImplementation->getResetStatus();
2635 }
Jamie Madill893ab082014-05-16 16:56:10 -04002636
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638}
2639
2640bool Context::isResetNotificationEnabled()
2641{
2642 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2643}
2644
Corentin Walleze3b10e82015-05-20 11:06:25 -04002645const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002646{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002647 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002648}
2649
2650EGLenum Context::getClientType() const
2651{
2652 return mClientType;
2653}
2654
2655EGLenum Context::getRenderBuffer() const
2656{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002657 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002658 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002659 {
2660 return EGL_NONE;
2661 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002662
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002663 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002664 ASSERT(backAttachment != nullptr);
2665 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002666}
2667
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002668VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002669{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002670 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002671 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2672 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002673 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002674 vertexArray =
2675 new VertexArray(mImplementation.get(), vertexArrayHandle,
2676 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002677
Jamie Madill96a483b2017-06-27 16:49:21 -04002678 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002679 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002680
2681 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002682}
2683
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002684TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002685{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002686 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002687 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2688 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002689 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002690 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002691 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002692 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002693 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002694 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002695
2696 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002697}
2698
2699bool Context::isVertexArrayGenerated(GLuint vertexArray)
2700{
Jamie Madill96a483b2017-06-27 16:49:21 -04002701 ASSERT(mVertexArrayMap.contains(0));
2702 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002703}
2704
2705bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2706{
Jamie Madill96a483b2017-06-27 16:49:21 -04002707 ASSERT(mTransformFeedbackMap.contains(0));
2708 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002709}
2710
Shannon Woods53a94a82014-06-24 15:20:36 -04002711void Context::detachTexture(GLuint texture)
2712{
2713 // Simple pass-through to State's detachTexture method, as textures do not require
2714 // allocation map management either here or in the resource manager at detach time.
2715 // Zero textures are held by the Context, and we don't attempt to request them from
2716 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002717 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002718}
2719
James Darpinian4d9d4832018-03-13 12:43:28 -07002720void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002721{
Yuly Novikov5807a532015-12-03 13:01:22 -05002722 // Simple pass-through to State's detachBuffer method, since
2723 // only buffer attachments to container objects that are bound to the current context
2724 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002725
Yuly Novikov5807a532015-12-03 13:01:22 -05002726 // [OpenGL ES 3.2] section 5.1.2 page 45:
2727 // Attachments to unbound container objects, such as
2728 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2729 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002730 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002731}
2732
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002733void Context::detachFramebuffer(GLuint framebuffer)
2734{
Shannon Woods53a94a82014-06-24 15:20:36 -04002735 // Framebuffer detachment is handled by Context, because 0 is a valid
2736 // Framebuffer object, and a pointer to it must be passed from Context
2737 // to State at binding time.
2738
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002739 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002740 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2741 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2742 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002743
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002744 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002745 {
2746 bindReadFramebuffer(0);
2747 }
2748
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002749 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002750 {
2751 bindDrawFramebuffer(0);
2752 }
2753}
2754
2755void Context::detachRenderbuffer(GLuint renderbuffer)
2756{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002757 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002758}
2759
Jamie Madill57a89722013-07-02 11:57:03 -04002760void Context::detachVertexArray(GLuint vertexArray)
2761{
Jamie Madill77a72f62015-04-14 11:18:32 -04002762 // Vertex array detachment is handled by Context, because 0 is a valid
2763 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002764 // binding time.
2765
Jamie Madill57a89722013-07-02 11:57:03 -04002766 // [OpenGL ES 3.0.2] section 2.10 page 43:
2767 // If a vertex array object that is currently bound is deleted, the binding
2768 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002769 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002770 {
2771 bindVertexArray(0);
2772 }
2773}
2774
Geoff Langc8058452014-02-03 12:04:11 -05002775void Context::detachTransformFeedback(GLuint transformFeedback)
2776{
Corentin Walleza2257da2016-04-19 16:43:12 -04002777 // Transform feedback detachment is handled by Context, because 0 is a valid
2778 // transform feedback, and a pointer to it must be passed from Context to State at
2779 // binding time.
2780
2781 // The OpenGL specification doesn't mention what should happen when the currently bound
2782 // transform feedback object is deleted. Since it is a container object, we treat it like
2783 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002784 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002785 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002786 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002787 }
Geoff Langc8058452014-02-03 12:04:11 -05002788}
2789
Jamie Madilldc356042013-07-19 16:36:57 -04002790void Context::detachSampler(GLuint sampler)
2791{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002792 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002793}
2794
Yunchao Hea336b902017-08-02 16:05:21 +08002795void Context::detachProgramPipeline(GLuint pipeline)
2796{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002797 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002798}
2799
Jamie Madill3ef140a2017-08-26 23:11:21 -04002800void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002802 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002803 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002804}
2805
Jamie Madille29d1672013-07-19 16:36:57 -04002806void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2807{
Till Rathmannb8543632018-10-02 19:46:14 +02002808 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002809 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002810 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002811}
Jamie Madille29d1672013-07-19 16:36:57 -04002812
Geoff Langc1984ed2016-10-07 12:41:00 -04002813void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2814{
Till Rathmannb8543632018-10-02 19:46:14 +02002815 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002816 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002817 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002818}
2819
Till Rathmannb8543632018-10-02 19:46:14 +02002820void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2821{
2822 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002823 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002824 SetSamplerParameterIiv(this, samplerObject, pname, param);
2825}
2826
2827void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2828{
2829 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002830 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002831 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2832}
2833
Brandon Jones59770802018-04-02 13:18:42 -07002834void Context::samplerParameterivRobust(GLuint sampler,
2835 GLenum pname,
2836 GLsizei bufSize,
2837 const GLint *param)
2838{
2839 samplerParameteriv(sampler, pname, param);
2840}
2841
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002842void Context::samplerParameterIivRobust(GLuint sampler,
2843 GLenum pname,
2844 GLsizei bufSize,
2845 const GLint *param)
2846{
2847 UNIMPLEMENTED();
2848}
2849
2850void Context::samplerParameterIuivRobust(GLuint sampler,
2851 GLenum pname,
2852 GLsizei bufSize,
2853 const GLuint *param)
2854{
2855 UNIMPLEMENTED();
2856}
2857
Jamie Madille29d1672013-07-19 16:36:57 -04002858void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2859{
Till Rathmannb8543632018-10-02 19:46:14 +02002860 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002861 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002862 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002863}
2864
Geoff Langc1984ed2016-10-07 12:41:00 -04002865void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002866{
Till Rathmannb8543632018-10-02 19:46:14 +02002867 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002868 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002869 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002870}
2871
Brandon Jones59770802018-04-02 13:18:42 -07002872void Context::samplerParameterfvRobust(GLuint sampler,
2873 GLenum pname,
2874 GLsizei bufSize,
2875 const GLfloat *param)
2876{
2877 samplerParameterfv(sampler, pname, param);
2878}
2879
Geoff Langc1984ed2016-10-07 12:41:00 -04002880void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002881{
Till Rathmannb8543632018-10-02 19:46:14 +02002882 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002883 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002884 QuerySamplerParameteriv(samplerObject, pname, params);
2885}
Jamie Madill9675b802013-07-19 16:36:59 -04002886
Till Rathmannb8543632018-10-02 19:46:14 +02002887void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2888{
2889 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002890 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002891 QuerySamplerParameterIiv(samplerObject, pname, params);
2892}
2893
2894void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2895{
2896 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002897 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002898 QuerySamplerParameterIuiv(samplerObject, pname, params);
2899}
2900
Brandon Jones59770802018-04-02 13:18:42 -07002901void Context::getSamplerParameterivRobust(GLuint sampler,
2902 GLenum pname,
2903 GLsizei bufSize,
2904 GLsizei *length,
2905 GLint *params)
2906{
2907 getSamplerParameteriv(sampler, pname, params);
2908}
2909
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002910void Context::getSamplerParameterIivRobust(GLuint sampler,
2911 GLenum pname,
2912 GLsizei bufSize,
2913 GLsizei *length,
2914 GLint *params)
2915{
2916 UNIMPLEMENTED();
2917}
2918
2919void Context::getSamplerParameterIuivRobust(GLuint sampler,
2920 GLenum pname,
2921 GLsizei bufSize,
2922 GLsizei *length,
2923 GLuint *params)
2924{
2925 UNIMPLEMENTED();
2926}
2927
Geoff Langc1984ed2016-10-07 12:41:00 -04002928void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2929{
Till Rathmannb8543632018-10-02 19:46:14 +02002930 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002931 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002932 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002933}
2934
Brandon Jones59770802018-04-02 13:18:42 -07002935void Context::getSamplerParameterfvRobust(GLuint sampler,
2936 GLenum pname,
2937 GLsizei bufSize,
2938 GLsizei *length,
2939 GLfloat *params)
2940{
2941 getSamplerParameterfv(sampler, pname, params);
2942}
2943
Olli Etuahof0fee072016-03-30 15:11:58 +03002944void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2945{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002946 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002947 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002948}
2949
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002950void Context::initRendererString()
2951{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002952 std::ostringstream rendererString;
2953 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002954 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002955 rendererString << ")";
2956
Geoff Langcec35902014-04-16 10:52:36 -04002957 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002958}
2959
Geoff Langc339c4e2016-11-29 10:37:36 -05002960void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002961{
Geoff Langc339c4e2016-11-29 10:37:36 -05002962 const Version &clientVersion = getClientVersion();
2963
2964 std::ostringstream versionString;
2965 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2966 << ANGLE_VERSION_STRING << ")";
2967 mVersionString = MakeStaticString(versionString.str());
2968
2969 std::ostringstream shadingLanguageVersionString;
2970 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2971 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2972 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2973 << ")";
2974 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002975}
2976
Geoff Langcec35902014-04-16 10:52:36 -04002977void Context::initExtensionStrings()
2978{
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2980 std::ostringstream combinedStringStream;
2981 std::copy(strings.begin(), strings.end(),
2982 std::ostream_iterator<const char *>(combinedStringStream, " "));
2983 return MakeStaticString(combinedStringStream.str());
2984 };
2985
2986 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002987 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002988 {
2989 mExtensionStrings.push_back(MakeStaticString(extensionString));
2990 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002991 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002992
Geoff Langc339c4e2016-11-29 10:37:36 -05002993 mRequestableExtensionStrings.clear();
2994 for (const auto &extensionInfo : GetExtensionInfoMap())
2995 {
2996 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002997 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002998 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 {
3000 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3001 }
3002 }
3003 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003004}
3005
Geoff Langc339c4e2016-11-29 10:37:36 -05003006const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003007{
Geoff Langc339c4e2016-11-29 10:37:36 -05003008 switch (name)
3009 {
3010 case GL_VENDOR:
3011 return reinterpret_cast<const GLubyte *>("Google Inc.");
3012
3013 case GL_RENDERER:
3014 return reinterpret_cast<const GLubyte *>(mRendererString);
3015
3016 case GL_VERSION:
3017 return reinterpret_cast<const GLubyte *>(mVersionString);
3018
3019 case GL_SHADING_LANGUAGE_VERSION:
3020 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3021
3022 case GL_EXTENSIONS:
3023 return reinterpret_cast<const GLubyte *>(mExtensionString);
3024
3025 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3026 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3027
3028 default:
3029 UNREACHABLE();
3030 return nullptr;
3031 }
Geoff Langcec35902014-04-16 10:52:36 -04003032}
3033
Geoff Langc339c4e2016-11-29 10:37:36 -05003034const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003035{
Geoff Langc339c4e2016-11-29 10:37:36 -05003036 switch (name)
3037 {
3038 case GL_EXTENSIONS:
3039 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3040
3041 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3042 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3043
3044 default:
3045 UNREACHABLE();
3046 return nullptr;
3047 }
Geoff Langcec35902014-04-16 10:52:36 -04003048}
3049
3050size_t Context::getExtensionStringCount() const
3051{
3052 return mExtensionStrings.size();
3053}
3054
Geoff Lang111a99e2017-10-17 10:58:41 -04003055bool Context::isExtensionRequestable(const char *name)
3056{
3057 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3058 auto extension = extensionInfos.find(name);
3059
Geoff Lang111a99e2017-10-17 10:58:41 -04003060 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003061 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003062}
3063
Geoff Langc339c4e2016-11-29 10:37:36 -05003064void Context::requestExtension(const char *name)
3065{
3066 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3067 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3068 const auto &extension = extensionInfos.at(name);
3069 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003070 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003071
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003072 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003073 {
3074 // Extension already enabled
3075 return;
3076 }
3077
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003078 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003079 updateCaps();
3080 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003081
Jamie Madill2f348d22017-06-05 10:50:59 -04003082 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3083 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003084
Jamie Madill81c2e252017-09-09 23:32:46 -04003085 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3086 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003087 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003088 for (auto &zeroTexture : mZeroTextures)
3089 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003090 if (zeroTexture.get() != nullptr)
3091 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003092 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003093 }
Geoff Lang9aded172017-04-05 11:07:56 -04003094 }
3095
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003096 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003097}
3098
3099size_t Context::getRequestableExtensionStringCount() const
3100{
3101 return mRequestableExtensionStrings.size();
3102}
3103
Jamie Madill493f9572018-05-24 19:52:15 -04003104void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003105{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003106 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003107 ASSERT(transformFeedback != nullptr);
3108 ASSERT(!transformFeedback->isPaused());
3109
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003110 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003111 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003112}
3113
3114bool Context::hasActiveTransformFeedback(GLuint program) const
3115{
3116 for (auto pair : mTransformFeedbackMap)
3117 {
3118 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3119 {
3120 return true;
3121 }
3122 }
3123 return false;
3124}
3125
Geoff Lang33f11fb2018-05-07 13:42:47 -04003126Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003127{
3128 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3129
jchen1082af6202018-06-22 10:59:52 +08003130 // Explicitly enable GL_KHR_parallel_shader_compile
3131 supportedExtensions.parallelShaderCompile = true;
3132
Geoff Langb0f917f2017-12-05 13:41:54 -05003133 if (getClientVersion() < ES_2_0)
3134 {
3135 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003136 supportedExtensions.pointSizeArray = true;
3137 supportedExtensions.textureCubeMap = true;
3138 supportedExtensions.pointSprite = true;
3139 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003140 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003141 }
3142
3143 if (getClientVersion() < ES_3_0)
3144 {
3145 // Disable ES3+ extensions
3146 supportedExtensions.colorBufferFloat = false;
3147 supportedExtensions.eglImageExternalEssl3 = false;
3148 supportedExtensions.textureNorm16 = false;
3149 supportedExtensions.multiview = false;
3150 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003151 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003152 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003153
3154 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3155 if (!supportedExtensions.sRGB)
3156 {
3157 supportedExtensions.textureSRGBDecode = false;
3158 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003159 }
3160
3161 if (getClientVersion() < ES_3_1)
3162 {
3163 // Disable ES3.1+ extensions
3164 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003165
3166 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3167 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003168 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003169 }
3170
3171 if (getClientVersion() > ES_2_0)
3172 {
3173 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3174 // supportedExtensions.sRGB = false;
3175 }
3176
3177 // Some extensions are always available because they are implemented in the GL layer.
3178 supportedExtensions.bindUniformLocation = true;
3179 supportedExtensions.vertexArrayObject = true;
3180 supportedExtensions.bindGeneratesResource = true;
3181 supportedExtensions.clientArrays = true;
3182 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003183 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003184
3185 // Enable the no error extension if the context was created with the flag.
3186 supportedExtensions.noError = mSkipValidation;
3187
3188 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003189 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003190
3191 // Explicitly enable GL_KHR_debug
3192 supportedExtensions.debug = true;
3193 supportedExtensions.maxDebugMessageLength = 1024;
3194 supportedExtensions.maxDebugLoggedMessages = 1024;
3195 supportedExtensions.maxDebugGroupStackDepth = 1024;
3196 supportedExtensions.maxLabelLength = 1024;
3197
3198 // Explicitly enable GL_ANGLE_robust_client_memory
3199 supportedExtensions.robustClientMemory = true;
3200
3201 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003202 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003203
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003204 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3205 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003206 supportedExtensions.robustBufferAccessBehavior =
3207 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3208
3209 // Enable the cache control query unconditionally.
3210 supportedExtensions.programCacheControl = true;
3211
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003212 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003213 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003214 {
3215 // GL_ANGLE_explicit_context_gles1
3216 supportedExtensions.explicitContextGles1 = true;
3217 // GL_ANGLE_explicit_context
3218 supportedExtensions.explicitContext = true;
3219 }
3220
Geoff Lang79b91402018-10-04 15:11:30 -04003221 supportedExtensions.memorySize = true;
3222
Geoff Langb0f917f2017-12-05 13:41:54 -05003223 return supportedExtensions;
3224}
3225
Geoff Lang33f11fb2018-05-07 13:42:47 -04003226void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003227{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003228 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003229
Geoff Lang33f11fb2018-05-07 13:42:47 -04003230 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003231 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003232
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003233 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003234
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003235 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3236 if (getClientVersion() < Version(2, 0))
3237 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003238 mState.mCaps.maxMultitextureUnits = 4;
3239 mState.mCaps.maxClipPlanes = 6;
3240 mState.mCaps.maxLights = 8;
3241 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3242 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3244 mState.mCaps.minSmoothPointSize = 1.0f;
3245 mState.mCaps.maxSmoothPointSize = 1.0f;
3246 mState.mCaps.minSmoothLineWidth = 1.0f;
3247 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003248 }
3249
Luc Ferronad2ae932018-06-11 15:31:17 -04003250 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003251 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003252
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003253 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003254
Jamie Madill0f80ed82017-09-19 00:24:56 -04003255 if (getClientVersion() < ES_3_1)
3256 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003257 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003258 }
3259 else
3260 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003261 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003262 }
Geoff Lang301d1612014-07-09 10:34:37 -04003263
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003264 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003265 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003266 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003267
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003268 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3269 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003270
3271 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003272 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3273 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003274 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003275 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003276 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003277
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003278 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003279
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003280 mState.mCaps.maxSampleMaskWords =
3281 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003282
Geoff Langc287ea62016-09-16 14:46:51 -04003283 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003284 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003285 for (const auto &extensionInfo : GetExtensionInfoMap())
3286 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003287 // If the user has requested that extensions start disabled and they are requestable,
3288 // disable them.
3289 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003290 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003291 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003292 }
3293 }
3294
3295 // Generate texture caps
3296 updateCaps();
3297}
3298
3299void Context::updateCaps()
3300{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003301 mState.mCaps.compressedTextureFormats.clear();
3302 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003303
Jamie Madill7b62cf92017-11-02 15:20:49 -04003304 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003305 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003306 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003307 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003308
Geoff Lang0d8b7242015-09-09 14:56:53 -04003309 // Update the format caps based on the client version and extensions.
3310 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3311 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003312 formatCaps.texturable = formatCaps.texturable &&
3313 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3314 formatCaps.filterable = formatCaps.filterable &&
3315 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003316 formatCaps.textureAttachment =
3317 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003318 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3319 formatCaps.renderbuffer =
3320 formatCaps.renderbuffer &&
3321 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003322
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003323 // OpenGL ES does not support multisampling with non-rendererable formats
3324 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003325 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003326 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003327 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003328 {
Geoff Langd87878e2014-09-19 15:42:59 -04003329 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003330 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003331 else
3332 {
3333 // We may have limited the max samples for some required renderbuffer formats due to
3334 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3335 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3336
3337 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3338 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3339 // exception of signed and unsigned integer formats."
3340 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3341 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3342 {
3343 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003344 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003345 }
3346
3347 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003348 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003349 {
3350 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3351 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3352 // the exception that the signed and unsigned integer formats are required only to
3353 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3354 // multisamples, which must be at least one."
3355 if (formatInfo.componentType == GL_INT ||
3356 formatInfo.componentType == GL_UNSIGNED_INT)
3357 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003358 mState.mCaps.maxIntegerSamples =
3359 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003360 }
3361
3362 // GLES 3.1 section 19.3.1.
3363 if (formatCaps.texturable)
3364 {
3365 if (formatInfo.depthBits > 0)
3366 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003367 mState.mCaps.maxDepthTextureSamples =
3368 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003369 }
3370 else if (formatInfo.redBits > 0)
3371 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003372 mState.mCaps.maxColorTextureSamples =
3373 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003374 }
3375 }
3376 }
3377 }
Geoff Langd87878e2014-09-19 15:42:59 -04003378
3379 if (formatCaps.texturable && formatInfo.compressed)
3380 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003381 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003382 }
3383
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003384 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003385 }
Jamie Madill32447362017-06-28 14:53:52 -04003386
3387 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003388 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003389 {
3390 mMemoryProgramCache = nullptr;
3391 }
Corentin Walleze4477002017-12-01 14:39:58 -05003392
3393 // Compute which buffer types are allowed
3394 mValidBufferBindings.reset();
3395 mValidBufferBindings.set(BufferBinding::ElementArray);
3396 mValidBufferBindings.set(BufferBinding::Array);
3397
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003398 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003399 {
3400 mValidBufferBindings.set(BufferBinding::PixelPack);
3401 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3402 }
3403
3404 if (getClientVersion() >= ES_3_0)
3405 {
3406 mValidBufferBindings.set(BufferBinding::CopyRead);
3407 mValidBufferBindings.set(BufferBinding::CopyWrite);
3408 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3409 mValidBufferBindings.set(BufferBinding::Uniform);
3410 }
3411
3412 if (getClientVersion() >= ES_3_1)
3413 {
3414 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3415 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3416 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3417 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3418 }
jchen107ae70d82018-07-06 13:47:01 +08003419
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003420 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003421
Jamie Madillef9fcd92018-11-28 14:03:59 -05003422 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003423 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003424 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3425 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3426 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3427 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3429 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003430
Jamie Madillac66f982018-10-09 18:30:01 -04003431 // Reinitialize state cache after extension changes.
3432 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003433}
3434
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003435void Context::initWorkarounds()
3436{
Jamie Madill761b02c2017-06-23 16:27:06 -04003437 // Apply back-end workarounds.
3438 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3439
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003440 // Lose the context upon out of memory error if the application is
3441 // expecting to watch for those events.
3442 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003443
3444 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3445 {
3446 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3447 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3448 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3449 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003450}
3451
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003452bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3453{
3454 return (instanceCount == 0) || noopDraw(mode, count);
3455}
3456
Jamie Madill526392d2018-11-16 09:35:14 -05003457angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003458{
Geoff Langa8cb2872018-03-09 16:09:40 -05003459 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003460 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003461 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003462 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003463}
3464
Jamie Madill526392d2018-11-16 09:35:14 -05003465angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003466{
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003468 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3469 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003470 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003471 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003472}
3473
Jamie Madill132d15c2018-11-30 15:25:38 -05003474ANGLE_INLINE angle::Result Context::prepareForDispatch()
3475{
3476 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3477 return syncDirtyBits(mComputeDirtyBits);
3478}
3479
Jamie Madill526392d2018-11-16 09:35:14 -05003480angle::Result Context::syncState(const State::DirtyBits &bitMask,
3481 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003482{
Geoff Langa8cb2872018-03-09 16:09:40 -05003483 ANGLE_TRY(syncDirtyObjects(objectMask));
3484 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003485 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003486}
3487
Jamie Madillc29968b2016-01-20 11:17:23 -05003488void Context::blitFramebuffer(GLint srcX0,
3489 GLint srcY0,
3490 GLint srcX1,
3491 GLint srcY1,
3492 GLint dstX0,
3493 GLint dstY0,
3494 GLint dstX1,
3495 GLint dstY1,
3496 GLbitfield mask,
3497 GLenum filter)
3498{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003499 if (mask == 0)
3500 {
3501 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3502 // buffers are copied.
3503 return;
3504 }
3505
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003506 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003507 ASSERT(drawFramebuffer);
3508
3509 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3510 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3511
Jamie Madillbc918e72018-03-08 09:47:21 -05003512 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003513
Jamie Madill4f6592f2018-11-27 16:37:45 -05003514 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003515}
Jamie Madillc29968b2016-01-20 11:17:23 -05003516
3517void Context::clear(GLbitfield mask)
3518{
Geoff Langd4fff502017-09-22 11:28:28 -04003519 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003520 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003521}
3522
3523void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3524{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003525 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003526 const FramebufferAttachment *attachment = nullptr;
3527 if (buffer == GL_DEPTH)
3528 {
3529 attachment = framebufferObject->getDepthbuffer();
3530 }
3531 if (buffer == GL_COLOR &&
3532 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3533 {
3534 attachment = framebufferObject->getColorbuffer(drawbuffer);
3535 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003536 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3537 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003538 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003539 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003540 return;
3541 }
Geoff Langd4fff502017-09-22 11:28:28 -04003542 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003543 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003544}
3545
3546void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3547{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003548 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003549 const FramebufferAttachment *attachment = nullptr;
3550 if (buffer == GL_COLOR &&
3551 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3552 {
3553 attachment = framebufferObject->getColorbuffer(drawbuffer);
3554 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003555 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3556 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003557 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003558 {
3559 return;
3560 }
Geoff Langd4fff502017-09-22 11:28:28 -04003561 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003562 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003563}
3564
3565void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3566{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003567 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003568 const FramebufferAttachment *attachment = nullptr;
3569 if (buffer == GL_STENCIL)
3570 {
3571 attachment = framebufferObject->getStencilbuffer();
3572 }
3573 if (buffer == GL_COLOR &&
3574 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3575 {
3576 attachment = framebufferObject->getColorbuffer(drawbuffer);
3577 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003578 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3579 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003580 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003581 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003582 return;
3583 }
Geoff Langd4fff502017-09-22 11:28:28 -04003584 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003585 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003586}
3587
3588void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3589{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003590 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003591 ASSERT(framebufferObject);
3592
3593 // If a buffer is not present, the clear has no effect
3594 if (framebufferObject->getDepthbuffer() == nullptr &&
3595 framebufferObject->getStencilbuffer() == nullptr)
3596 {
3597 return;
3598 }
3599
Geoff Langd4fff502017-09-22 11:28:28 -04003600 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3601 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003602}
3603
3604void Context::readPixels(GLint x,
3605 GLint y,
3606 GLsizei width,
3607 GLsizei height,
3608 GLenum format,
3609 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003610 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003611{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003612 if (width == 0 || height == 0)
3613 {
3614 return;
3615 }
3616
Jamie Madillbc918e72018-03-08 09:47:21 -05003617 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003618
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003619 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003620 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003621
3622 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003623 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003624}
3625
Brandon Jones59770802018-04-02 13:18:42 -07003626void Context::readPixelsRobust(GLint x,
3627 GLint y,
3628 GLsizei width,
3629 GLsizei height,
3630 GLenum format,
3631 GLenum type,
3632 GLsizei bufSize,
3633 GLsizei *length,
3634 GLsizei *columns,
3635 GLsizei *rows,
3636 void *pixels)
3637{
3638 readPixels(x, y, width, height, format, type, pixels);
3639}
3640
3641void Context::readnPixelsRobust(GLint x,
3642 GLint y,
3643 GLsizei width,
3644 GLsizei height,
3645 GLenum format,
3646 GLenum type,
3647 GLsizei bufSize,
3648 GLsizei *length,
3649 GLsizei *columns,
3650 GLsizei *rows,
3651 void *data)
3652{
3653 readPixels(x, y, width, height, format, type, data);
3654}
3655
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003656void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003657 GLint level,
3658 GLenum internalformat,
3659 GLint x,
3660 GLint y,
3661 GLsizei width,
3662 GLsizei height,
3663 GLint border)
3664{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003665 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003666 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003667
Jamie Madillc29968b2016-01-20 11:17:23 -05003668 Rectangle sourceArea(x, y, width, height);
3669
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003670 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003671 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003672 ANGLE_CONTEXT_TRY(
3673 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003674}
3675
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003676void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003677 GLint level,
3678 GLint xoffset,
3679 GLint yoffset,
3680 GLint x,
3681 GLint y,
3682 GLsizei width,
3683 GLsizei height)
3684{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003685 if (width == 0 || height == 0)
3686 {
3687 return;
3688 }
3689
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003690 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003691 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003692
Jamie Madillc29968b2016-01-20 11:17:23 -05003693 Offset destOffset(xoffset, yoffset, 0);
3694 Rectangle sourceArea(x, y, width, height);
3695
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003696 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003697 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003698 ANGLE_CONTEXT_TRY(
3699 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003700}
3701
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003702void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003703 GLint level,
3704 GLint xoffset,
3705 GLint yoffset,
3706 GLint zoffset,
3707 GLint x,
3708 GLint y,
3709 GLsizei width,
3710 GLsizei height)
3711{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003712 if (width == 0 || height == 0)
3713 {
3714 return;
3715 }
3716
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003717 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003718 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003719
Jamie Madillc29968b2016-01-20 11:17:23 -05003720 Offset destOffset(xoffset, yoffset, zoffset);
3721 Rectangle sourceArea(x, y, width, height);
3722
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003723 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003724 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003725 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3726 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003727}
3728
3729void Context::framebufferTexture2D(GLenum target,
3730 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003731 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 GLuint texture,
3733 GLint level)
3734{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003735 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003736 ASSERT(framebuffer);
3737
3738 if (texture != 0)
3739 {
3740 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003741 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003742 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003743 }
3744 else
3745 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003746 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003747 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003748
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003749 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750}
3751
3752void Context::framebufferRenderbuffer(GLenum target,
3753 GLenum attachment,
3754 GLenum renderbuffertarget,
3755 GLuint renderbuffer)
3756{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003757 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 ASSERT(framebuffer);
3759
3760 if (renderbuffer != 0)
3761 {
3762 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003763
Jamie Madillcc129372018-04-12 09:13:18 -04003764 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003765 renderbufferObject);
3766 }
3767 else
3768 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003769 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003770 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003771
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003772 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003773}
3774
3775void Context::framebufferTextureLayer(GLenum target,
3776 GLenum attachment,
3777 GLuint texture,
3778 GLint level,
3779 GLint layer)
3780{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003781 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003782 ASSERT(framebuffer);
3783
3784 if (texture != 0)
3785 {
3786 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003787 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003788 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003789 }
3790 else
3791 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003792 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003793 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003794
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003795 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796}
3797
Brandon Jones59770802018-04-02 13:18:42 -07003798void Context::framebufferTextureMultiviewLayered(GLenum target,
3799 GLenum attachment,
3800 GLuint texture,
3801 GLint level,
3802 GLint baseViewIndex,
3803 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003804{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003805 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003806 ASSERT(framebuffer);
3807
3808 if (texture != 0)
3809 {
3810 Texture *textureObj = getTexture(texture);
3811
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003812 ImageIndex index;
3813 if (textureObj->getType() == TextureType::_2DArray)
3814 {
3815 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3816 }
3817 else
3818 {
3819 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3820 ASSERT(level == 0);
3821 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3822 }
Martin Radev82ef7742017-08-08 17:44:58 +03003823 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3824 numViews, baseViewIndex);
3825 }
3826 else
3827 {
3828 framebuffer->resetAttachment(this, attachment);
3829 }
3830
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003831 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003832}
3833
Brandon Jones59770802018-04-02 13:18:42 -07003834void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3835 GLenum attachment,
3836 GLuint texture,
3837 GLint level,
3838 GLsizei numViews,
3839 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003840{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003841 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003842 ASSERT(framebuffer);
3843
3844 if (texture != 0)
3845 {
3846 Texture *textureObj = getTexture(texture);
3847
3848 ImageIndex index = ImageIndex::Make2D(level);
3849 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3850 textureObj, numViews, viewportOffsets);
3851 }
3852 else
3853 {
3854 framebuffer->resetAttachment(this, attachment);
3855 }
3856
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003857 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003858}
3859
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003860void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3861{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003862 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003863 ASSERT(framebuffer);
3864
3865 if (texture != 0)
3866 {
3867 Texture *textureObj = getTexture(texture);
3868
3869 ImageIndex index = ImageIndex::MakeFromType(
3870 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3871 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3872 }
3873 else
3874 {
3875 framebuffer->resetAttachment(this, attachment);
3876 }
3877
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003878 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003879}
3880
Jamie Madillc29968b2016-01-20 11:17:23 -05003881void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3882{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003883 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003884 ASSERT(framebuffer);
3885 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003886 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003887 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003888}
3889
3890void Context::readBuffer(GLenum mode)
3891{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003892 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003893 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003894 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003895}
3896
3897void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3898{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003899 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003900 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003901
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003902 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003903 ASSERT(framebuffer);
3904
3905 // The specification isn't clear what should be done when the framebuffer isn't complete.
3906 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003907 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003908}
3909
3910void Context::invalidateFramebuffer(GLenum target,
3911 GLsizei numAttachments,
3912 const GLenum *attachments)
3913{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003914 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003915 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003916
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003917 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003918 ASSERT(framebuffer);
3919
Jamie Madill427064d2018-04-13 16:20:34 -04003920 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003921 {
Jamie Madill437fa652016-05-03 15:13:24 -04003922 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003923 }
Jamie Madill437fa652016-05-03 15:13:24 -04003924
Jamie Madill4f6592f2018-11-27 16:37:45 -05003925 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003926}
3927
3928void Context::invalidateSubFramebuffer(GLenum target,
3929 GLsizei numAttachments,
3930 const GLenum *attachments,
3931 GLint x,
3932 GLint y,
3933 GLsizei width,
3934 GLsizei height)
3935{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003936 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003937 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003938
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003939 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003940 ASSERT(framebuffer);
3941
Jamie Madill427064d2018-04-13 16:20:34 -04003942 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003943 {
Jamie Madill437fa652016-05-03 15:13:24 -04003944 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003945 }
Jamie Madill437fa652016-05-03 15:13:24 -04003946
3947 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003948 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003949}
3950
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003951void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003952 GLint level,
3953 GLint internalformat,
3954 GLsizei width,
3955 GLsizei height,
3956 GLint border,
3957 GLenum format,
3958 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003959 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003960{
Jamie Madillbc918e72018-03-08 09:47:21 -05003961 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003962
3963 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003964 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003965 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003966 internalformat, size, format, type,
3967 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003968}
3969
Brandon Jones59770802018-04-02 13:18:42 -07003970void Context::texImage2DRobust(TextureTarget target,
3971 GLint level,
3972 GLint internalformat,
3973 GLsizei width,
3974 GLsizei height,
3975 GLint border,
3976 GLenum format,
3977 GLenum type,
3978 GLsizei bufSize,
3979 const void *pixels)
3980{
3981 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3982}
3983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003984void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003985 GLint level,
3986 GLint internalformat,
3987 GLsizei width,
3988 GLsizei height,
3989 GLsizei depth,
3990 GLint border,
3991 GLenum format,
3992 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003993 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003994{
Jamie Madillbc918e72018-03-08 09:47:21 -05003995 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003996
3997 Extents size(width, height, depth);
3998 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003999 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05004000 NonCubeTextureTypeToTarget(target), level, internalformat,
4001 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004002}
4003
Brandon Jones59770802018-04-02 13:18:42 -07004004void Context::texImage3DRobust(TextureType target,
4005 GLint level,
4006 GLint internalformat,
4007 GLsizei width,
4008 GLsizei height,
4009 GLsizei depth,
4010 GLint border,
4011 GLenum format,
4012 GLenum type,
4013 GLsizei bufSize,
4014 const void *pixels)
4015{
4016 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4017}
4018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004019void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004020 GLint level,
4021 GLint xoffset,
4022 GLint yoffset,
4023 GLsizei width,
4024 GLsizei height,
4025 GLenum format,
4026 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004027 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004028{
4029 // Zero sized uploads are valid but no-ops
4030 if (width == 0 || height == 0)
4031 {
4032 return;
4033 }
4034
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004036
4037 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004038 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004039
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004040 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004041
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004042 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004043 level, area, format, type,
4044 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004045}
4046
Brandon Jones59770802018-04-02 13:18:42 -07004047void Context::texSubImage2DRobust(TextureTarget target,
4048 GLint level,
4049 GLint xoffset,
4050 GLint yoffset,
4051 GLsizei width,
4052 GLsizei height,
4053 GLenum format,
4054 GLenum type,
4055 GLsizei bufSize,
4056 const void *pixels)
4057{
4058 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4059}
4060
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004061void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004062 GLint level,
4063 GLint xoffset,
4064 GLint yoffset,
4065 GLint zoffset,
4066 GLsizei width,
4067 GLsizei height,
4068 GLsizei depth,
4069 GLenum format,
4070 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004071 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004072{
4073 // Zero sized uploads are valid but no-ops
4074 if (width == 0 || height == 0 || depth == 0)
4075 {
4076 return;
4077 }
4078
Jamie Madillbc918e72018-03-08 09:47:21 -05004079 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004080
4081 Box area(xoffset, yoffset, zoffset, width, height, depth);
4082 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004083
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004084 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004085
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004086 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004087 NonCubeTextureTypeToTarget(target), level, area, format,
4088 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004089}
4090
Brandon Jones59770802018-04-02 13:18:42 -07004091void Context::texSubImage3DRobust(TextureType target,
4092 GLint level,
4093 GLint xoffset,
4094 GLint yoffset,
4095 GLint zoffset,
4096 GLsizei width,
4097 GLsizei height,
4098 GLsizei depth,
4099 GLenum format,
4100 GLenum type,
4101 GLsizei bufSize,
4102 const void *pixels)
4103{
4104 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4105 pixels);
4106}
4107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004108void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004109 GLint level,
4110 GLenum internalformat,
4111 GLsizei width,
4112 GLsizei height,
4113 GLint border,
4114 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004115 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004116{
Jamie Madillbc918e72018-03-08 09:47:21 -05004117 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004118
4119 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004120 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004121 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004122 internalformat, size, imageSize,
4123 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004124}
4125
Brandon Jones59770802018-04-02 13:18:42 -07004126void Context::compressedTexImage2DRobust(TextureTarget target,
4127 GLint level,
4128 GLenum internalformat,
4129 GLsizei width,
4130 GLsizei height,
4131 GLint border,
4132 GLsizei imageSize,
4133 GLsizei dataSize,
4134 const GLvoid *data)
4135{
4136 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4137}
4138
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004139void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004140 GLint level,
4141 GLenum internalformat,
4142 GLsizei width,
4143 GLsizei height,
4144 GLsizei depth,
4145 GLint border,
4146 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004147 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004148{
Jamie Madillbc918e72018-03-08 09:47:21 -05004149 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004150
4151 Extents size(width, height, depth);
4152 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004153 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004154 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004155 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004156}
4157
Brandon Jones59770802018-04-02 13:18:42 -07004158void Context::compressedTexImage3DRobust(TextureType target,
4159 GLint level,
4160 GLenum internalformat,
4161 GLsizei width,
4162 GLsizei height,
4163 GLsizei depth,
4164 GLint border,
4165 GLsizei imageSize,
4166 GLsizei dataSize,
4167 const GLvoid *data)
4168{
4169 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4170 data);
4171}
4172
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004173void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004174 GLint level,
4175 GLint xoffset,
4176 GLint yoffset,
4177 GLsizei width,
4178 GLsizei height,
4179 GLenum format,
4180 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004181 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004182{
Jamie Madillbc918e72018-03-08 09:47:21 -05004183 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004184
4185 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004186 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004187 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004188 area, format, imageSize,
4189 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004190}
4191
Brandon Jones59770802018-04-02 13:18:42 -07004192void Context::compressedTexSubImage2DRobust(TextureTarget target,
4193 GLint level,
4194 GLint xoffset,
4195 GLint yoffset,
4196 GLsizei width,
4197 GLsizei height,
4198 GLenum format,
4199 GLsizei imageSize,
4200 GLsizei dataSize,
4201 const GLvoid *data)
4202{
4203 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4204 data);
4205}
4206
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004207void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004208 GLint level,
4209 GLint xoffset,
4210 GLint yoffset,
4211 GLint zoffset,
4212 GLsizei width,
4213 GLsizei height,
4214 GLsizei depth,
4215 GLenum format,
4216 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004217 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004218{
4219 // Zero sized uploads are valid but no-ops
4220 if (width == 0 || height == 0)
4221 {
4222 return;
4223 }
4224
Jamie Madillbc918e72018-03-08 09:47:21 -05004225 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004226
4227 Box area(xoffset, yoffset, zoffset, width, height, depth);
4228 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004229 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004230 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004231 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004232}
4233
Brandon Jones59770802018-04-02 13:18:42 -07004234void Context::compressedTexSubImage3DRobust(TextureType target,
4235 GLint level,
4236 GLint xoffset,
4237 GLint yoffset,
4238 GLint zoffset,
4239 GLsizei width,
4240 GLsizei height,
4241 GLsizei depth,
4242 GLenum format,
4243 GLsizei imageSize,
4244 GLsizei dataSize,
4245 const GLvoid *data)
4246{
4247 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4248 imageSize, data);
4249}
4250
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004251void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004252{
4253 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004254 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004255}
4256
Jamie Madill007530e2017-12-28 14:27:04 -05004257void Context::copyTexture(GLuint sourceId,
4258 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004259 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004260 GLuint destId,
4261 GLint destLevel,
4262 GLint internalFormat,
4263 GLenum destType,
4264 GLboolean unpackFlipY,
4265 GLboolean unpackPremultiplyAlpha,
4266 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004267{
Jamie Madillbc918e72018-03-08 09:47:21 -05004268 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004269
4270 gl::Texture *sourceTexture = getTexture(sourceId);
4271 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004272 ANGLE_CONTEXT_TRY(
4273 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4274 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4275 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004276}
4277
Jamie Madill007530e2017-12-28 14:27:04 -05004278void Context::copySubTexture(GLuint sourceId,
4279 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004280 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004281 GLuint destId,
4282 GLint destLevel,
4283 GLint xoffset,
4284 GLint yoffset,
4285 GLint x,
4286 GLint y,
4287 GLsizei width,
4288 GLsizei height,
4289 GLboolean unpackFlipY,
4290 GLboolean unpackPremultiplyAlpha,
4291 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004292{
4293 // Zero sized copies are valid but no-ops
4294 if (width == 0 || height == 0)
4295 {
4296 return;
4297 }
4298
Jamie Madillbc918e72018-03-08 09:47:21 -05004299 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004300
4301 gl::Texture *sourceTexture = getTexture(sourceId);
4302 gl::Texture *destTexture = getTexture(destId);
4303 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004304 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004305 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4306 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4307 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4308 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004309}
4310
4311void Context::copyTexture3D(GLuint sourceId,
4312 GLint sourceLevel,
4313 TextureTarget destTarget,
4314 GLuint destId,
4315 GLint destLevel,
4316 GLint internalFormat,
4317 GLenum destType,
4318 GLboolean unpackFlipY,
4319 GLboolean unpackPremultiplyAlpha,
4320 GLboolean unpackUnmultiplyAlpha)
4321{
4322 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4323
4324 Texture *sourceTexture = getTexture(sourceId);
4325 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004326 ANGLE_CONTEXT_TRY(
4327 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4328 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4329 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004330}
4331
4332void Context::copySubTexture3D(GLuint sourceId,
4333 GLint sourceLevel,
4334 TextureTarget destTarget,
4335 GLuint destId,
4336 GLint destLevel,
4337 GLint xoffset,
4338 GLint yoffset,
4339 GLint zoffset,
4340 GLint x,
4341 GLint y,
4342 GLint z,
4343 GLsizei width,
4344 GLsizei height,
4345 GLsizei depth,
4346 GLboolean unpackFlipY,
4347 GLboolean unpackPremultiplyAlpha,
4348 GLboolean unpackUnmultiplyAlpha)
4349{
4350 // Zero sized copies are valid but no-ops
4351 if (width == 0 || height == 0 || depth == 0)
4352 {
4353 return;
4354 }
4355
4356 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4357
4358 Texture *sourceTexture = getTexture(sourceId);
4359 Texture *destTexture = getTexture(destId);
4360 Offset offset(xoffset, yoffset, zoffset);
4361 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004362 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4363 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4364 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4365 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004366}
4367
Jamie Madill007530e2017-12-28 14:27:04 -05004368void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004369{
Jamie Madillbc918e72018-03-08 09:47:21 -05004370 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004371
4372 gl::Texture *sourceTexture = getTexture(sourceId);
4373 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004374 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004375}
4376
Corentin Wallez336129f2017-10-17 15:55:40 -04004377void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004378{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004379 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004380 ASSERT(buffer);
4381
Geoff Lang496c02d2016-10-20 11:38:11 -07004382 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004383}
4384
Brandon Jones59770802018-04-02 13:18:42 -07004385void Context::getBufferPointervRobust(BufferBinding target,
4386 GLenum pname,
4387 GLsizei bufSize,
4388 GLsizei *length,
4389 void **params)
4390{
4391 getBufferPointerv(target, pname, params);
4392}
4393
Corentin Wallez336129f2017-10-17 15:55:40 -04004394void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004395{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004396 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004397 ASSERT(buffer);
4398
Jamie Madill7c985f52018-11-29 18:16:17 -05004399 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004400 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004401 return nullptr;
4402 }
4403
4404 return buffer->getMapPointer();
4405}
4406
Corentin Wallez336129f2017-10-17 15:55:40 -04004407GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004408{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004409 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004410 ASSERT(buffer);
4411
4412 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004413 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004414 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004415 return GL_FALSE;
4416 }
4417
4418 return result;
4419}
4420
Corentin Wallez336129f2017-10-17 15:55:40 -04004421void *Context::mapBufferRange(BufferBinding target,
4422 GLintptr offset,
4423 GLsizeiptr length,
4424 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004425{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004426 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004427 ASSERT(buffer);
4428
Jamie Madill7c985f52018-11-29 18:16:17 -05004429 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004430 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004431 return nullptr;
4432 }
4433
4434 return buffer->getMapPointer();
4435}
4436
Corentin Wallez336129f2017-10-17 15:55:40 -04004437void Context::flushMappedBufferRange(BufferBinding /*target*/,
4438 GLintptr /*offset*/,
4439 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004440{
4441 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4442}
4443
Jamie Madill526392d2018-11-16 09:35:14 -05004444angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004445{
Geoff Langa8cb2872018-03-09 16:09:40 -05004446 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004447}
4448
Jamie Madill526392d2018-11-16 09:35:14 -05004449angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004450{
Geoff Langa8cb2872018-03-09 16:09:40 -05004451 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004452}
4453
Jamie Madill526392d2018-11-16 09:35:14 -05004454angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004455{
Geoff Langa8cb2872018-03-09 16:09:40 -05004456 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004457}
4458
Jamie Madill526392d2018-11-16 09:35:14 -05004459angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004460{
4461 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4462
4463 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4464 ANGLE_TRY(syncDirtyBits());
4465
Jamie Madill7c985f52018-11-29 18:16:17 -05004466 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004467}
4468
Jiajia Qin5451d532017-11-16 17:16:34 +08004469void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4470{
4471 UNIMPLEMENTED();
4472}
4473
Jamie Madillc20ab272016-06-09 07:20:46 -07004474void Context::activeTexture(GLenum texture)
4475{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004476 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
Jamie Madill876429b2017-04-20 15:46:24 -04004479void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004480{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004481 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004482}
4483
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004484void Context::blendEquation(GLenum mode)
4485{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004486 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004487}
4488
Jamie Madillc20ab272016-06-09 07:20:46 -07004489void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4490{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004491 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004492}
4493
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004494void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4495{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004496 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004497}
4498
Jamie Madillc20ab272016-06-09 07:20:46 -07004499void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4500{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004501 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
Jamie Madill876429b2017-04-20 15:46:24 -04004504void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004505{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004506 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
Jamie Madill876429b2017-04-20 15:46:24 -04004509void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004510{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004511 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::clearStencil(GLint s)
4515{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004516 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4520{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004521 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4522 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004525void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004526{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004527 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004528}
4529
4530void Context::depthFunc(GLenum func)
4531{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004532 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533}
4534
4535void Context::depthMask(GLboolean flag)
4536{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004537 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004538}
4539
Jamie Madill876429b2017-04-20 15:46:24 -04004540void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004541{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004542 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004543}
4544
4545void Context::disable(GLenum cap)
4546{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004547 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004548 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004549}
4550
4551void Context::disableVertexAttribArray(GLuint index)
4552{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004553 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004554 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::enable(GLenum cap)
4558{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004559 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004560 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::enableVertexAttribArray(GLuint index)
4564{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004565 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004566 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::frontFace(GLenum mode)
4570{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004571 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572}
4573
4574void Context::hint(GLenum target, GLenum mode)
4575{
4576 switch (target)
4577 {
4578 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004579 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580 break;
4581
4582 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004583 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004584 break;
4585
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004586 case GL_PERSPECTIVE_CORRECTION_HINT:
4587 case GL_POINT_SMOOTH_HINT:
4588 case GL_LINE_SMOOTH_HINT:
4589 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004590 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004591 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004592 default:
4593 UNREACHABLE();
4594 return;
4595 }
4596}
4597
4598void Context::lineWidth(GLfloat width)
4599{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004600 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
4603void Context::pixelStorei(GLenum pname, GLint param)
4604{
4605 switch (pname)
4606 {
4607 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004608 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609 break;
4610
4611 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004612 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613 break;
4614
4615 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004616 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617 break;
4618
4619 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004620 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004621 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004622 break;
4623
4624 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004625 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004626 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004627 break;
4628
4629 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004630 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004631 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004632 break;
4633
4634 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004635 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004636 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004637 break;
4638
4639 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004640 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004641 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642 break;
4643
4644 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004645 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004646 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004647 break;
4648
4649 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004650 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004651 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652 break;
4653
4654 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004655 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004656 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657 break;
4658
4659 default:
4660 UNREACHABLE();
4661 return;
4662 }
4663}
4664
4665void Context::polygonOffset(GLfloat factor, GLfloat units)
4666{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004667 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
Jamie Madill876429b2017-04-20 15:46:24 -04004670void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004671{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004672 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
Jiawei Shaodb342272017-09-27 10:21:45 +08004675void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4676{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004677 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004678}
4679
Jamie Madillc20ab272016-06-09 07:20:46 -07004680void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4681{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004682 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4686{
4687 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4688 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004689 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004690 }
4691
4692 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4693 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004694 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004696
4697 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
4700void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4701{
4702 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4703 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004704 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004705 }
4706
4707 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4708 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004709 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004711
4712 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713}
4714
4715void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4716{
4717 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4718 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004719 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004720 }
4721
4722 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4723 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004724 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004725 }
4726}
4727
4728void Context::vertexAttrib1f(GLuint index, GLfloat x)
4729{
4730 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004731 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004732 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733}
4734
4735void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4736{
4737 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004738 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004739 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004740}
4741
4742void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4743{
4744 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004745 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004746 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004747}
4748
4749void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4750{
4751 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004752 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004753 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004754}
4755
4756void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4757{
4758 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004759 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004760 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004761}
4762
4763void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4764{
4765 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004766 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768}
4769
4770void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4771{
4772 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004773 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004774 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004775}
4776
4777void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4778{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004779 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004780 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004781}
4782
4783void Context::vertexAttribPointer(GLuint index,
4784 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004785 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004786 GLboolean normalized,
4787 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004788 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004789{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004790 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
Jamie Madill6e18a232019-01-16 13:27:14 -05004791 type, ConvertToBool(normalized), stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004792 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004793}
4794
Shao80957d92017-02-20 21:25:59 +08004795void Context::vertexAttribFormat(GLuint attribIndex,
4796 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004797 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004798 GLboolean normalized,
4799 GLuint relativeOffset)
4800{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004801 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4802 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004803 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004804}
4805
4806void Context::vertexAttribIFormat(GLuint attribIndex,
4807 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004808 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004809 GLuint relativeOffset)
4810{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004811 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004812 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004813}
4814
4815void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4816{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004817 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004818 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004819}
4820
Jiajia Qin5451d532017-11-16 17:16:34 +08004821void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004822{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004823 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004824 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004825}
4826
Jamie Madillc20ab272016-06-09 07:20:46 -07004827void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4828{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004829 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004830}
4831
4832void Context::vertexAttribIPointer(GLuint index,
4833 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004834 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004835 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004836 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004837{
Jamie Madill6e18a232019-01-16 13:27:14 -05004838 mState.setVertexAttribIPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4839 type, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004840 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004841}
4842
4843void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4844{
4845 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004846 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004847 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004848}
4849
4850void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4851{
4852 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004853 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004854 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004855}
4856
4857void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4858{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004859 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004860 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004861}
4862
4863void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4864{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004865 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004866 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004867}
4868
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004869void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4870{
4871 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004872 getState().getVertexAttribCurrentValue(index);
4873 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004874 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4875 currentValues, pname, params);
4876}
4877
Brandon Jones59770802018-04-02 13:18:42 -07004878void Context::getVertexAttribivRobust(GLuint index,
4879 GLenum pname,
4880 GLsizei bufSize,
4881 GLsizei *length,
4882 GLint *params)
4883{
4884 getVertexAttribiv(index, pname, params);
4885}
4886
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004887void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4888{
4889 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004890 getState().getVertexAttribCurrentValue(index);
4891 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004892 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4893 currentValues, pname, params);
4894}
4895
Brandon Jones59770802018-04-02 13:18:42 -07004896void Context::getVertexAttribfvRobust(GLuint index,
4897 GLenum pname,
4898 GLsizei bufSize,
4899 GLsizei *length,
4900 GLfloat *params)
4901{
4902 getVertexAttribfv(index, pname, params);
4903}
4904
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004905void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4906{
4907 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004908 getState().getVertexAttribCurrentValue(index);
4909 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004910 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4911 currentValues, pname, params);
4912}
4913
Brandon Jones59770802018-04-02 13:18:42 -07004914void Context::getVertexAttribIivRobust(GLuint index,
4915 GLenum pname,
4916 GLsizei bufSize,
4917 GLsizei *length,
4918 GLint *params)
4919{
4920 getVertexAttribIiv(index, pname, params);
4921}
4922
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004923void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4924{
4925 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004926 getState().getVertexAttribCurrentValue(index);
4927 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004928 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4929 currentValues, pname, params);
4930}
4931
Brandon Jones59770802018-04-02 13:18:42 -07004932void Context::getVertexAttribIuivRobust(GLuint index,
4933 GLenum pname,
4934 GLsizei bufSize,
4935 GLsizei *length,
4936 GLuint *params)
4937{
4938 getVertexAttribIuiv(index, pname, params);
4939}
4940
Jamie Madill876429b2017-04-20 15:46:24 -04004941void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004942{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004943 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004944 QueryVertexAttribPointerv(attrib, pname, pointer);
4945}
4946
Brandon Jones59770802018-04-02 13:18:42 -07004947void Context::getVertexAttribPointervRobust(GLuint index,
4948 GLenum pname,
4949 GLsizei bufSize,
4950 GLsizei *length,
4951 void **pointer)
4952{
4953 getVertexAttribPointerv(index, pname, pointer);
4954}
4955
Jamie Madillc20ab272016-06-09 07:20:46 -07004956void Context::debugMessageControl(GLenum source,
4957 GLenum type,
4958 GLenum severity,
4959 GLsizei count,
4960 const GLuint *ids,
4961 GLboolean enabled)
4962{
4963 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004964 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4965 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004966}
4967
4968void Context::debugMessageInsert(GLenum source,
4969 GLenum type,
4970 GLuint id,
4971 GLenum severity,
4972 GLsizei length,
4973 const GLchar *buf)
4974{
4975 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004976 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004977}
4978
4979void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4980{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004981 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004982}
4983
4984GLuint Context::getDebugMessageLog(GLuint count,
4985 GLsizei bufSize,
4986 GLenum *sources,
4987 GLenum *types,
4988 GLuint *ids,
4989 GLenum *severities,
4990 GLsizei *lengths,
4991 GLchar *messageLog)
4992{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004993 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
4994 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004995}
4996
4997void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4998{
4999 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005000 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005001 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005002}
5003
5004void Context::popDebugGroup()
5005{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005006 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005007 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005008}
5009
Corentin Wallez336129f2017-10-17 15:55:40 -04005010void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005011{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005012 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005013 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005014 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005015}
5016
Corentin Wallez336129f2017-10-17 15:55:40 -04005017void Context::bufferSubData(BufferBinding target,
5018 GLintptr offset,
5019 GLsizeiptr size,
5020 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005021{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005022 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005023 {
5024 return;
5025 }
5026
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005027 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005028 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005029 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005030}
5031
Jamie Madillef300b12016-10-07 15:12:09 -04005032void Context::attachShader(GLuint program, GLuint shader)
5033{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005034 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5035 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005036 ASSERT(programObject && shaderObject);
5037 programObject->attachShader(shaderObject);
5038}
5039
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005040const Workarounds &Context::getWorkarounds() const
5041{
5042 return mWorkarounds;
5043}
5044
Corentin Wallez336129f2017-10-17 15:55:40 -04005045void Context::copyBufferSubData(BufferBinding readTarget,
5046 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005047 GLintptr readOffset,
5048 GLintptr writeOffset,
5049 GLsizeiptr size)
5050{
5051 // if size is zero, the copy is a successful no-op
5052 if (size == 0)
5053 {
5054 return;
5055 }
5056
5057 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005058 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5059 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005060
Jamie Madill4f6592f2018-11-27 16:37:45 -05005061 ANGLE_CONTEXT_TRY(
5062 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005063}
5064
Jamie Madill01a80ee2016-11-07 12:06:18 -05005065void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5066{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005067 // Ideally we could share the program query with the validation layer if possible.
5068 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005069 ASSERT(programObject);
5070 programObject->bindAttributeLocation(index, name);
5071}
5072
Corentin Wallez336129f2017-10-17 15:55:40 -04005073void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005074{
5075 bindBufferRange(target, index, buffer, 0, 0);
5076}
5077
Corentin Wallez336129f2017-10-17 15:55:40 -04005078void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005079 GLuint index,
5080 GLuint buffer,
5081 GLintptr offset,
5082 GLsizeiptr size)
5083{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005084 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5085 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005086 if (target == BufferBinding::Uniform)
5087 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005088 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005089 mStateCache.onUniformBufferStateChange(this);
5090 }
5091 else
5092 {
5093 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005094 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005095}
5096
Jamie Madill01a80ee2016-11-07 12:06:18 -05005097void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5098{
5099 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5100 {
5101 bindReadFramebuffer(framebuffer);
5102 }
5103
5104 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5105 {
5106 bindDrawFramebuffer(framebuffer);
5107 }
5108}
5109
5110void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5111{
5112 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005113 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5114 mImplementation.get(), renderbuffer);
5115 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005116}
5117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005118void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005119 GLsizei samples,
5120 GLenum internalformat,
5121 GLsizei width,
5122 GLsizei height,
5123 GLboolean fixedsamplelocations)
5124{
5125 Extents size(width, height, 1);
5126 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005127 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5128 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005129}
5130
Olli Etuaho89664842018-08-24 14:45:36 +03005131void Context::texStorage3DMultisample(TextureType target,
5132 GLsizei samples,
5133 GLenum internalformat,
5134 GLsizei width,
5135 GLsizei height,
5136 GLsizei depth,
5137 GLboolean fixedsamplelocations)
5138{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005139 Extents size(width, height, depth);
5140 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005141 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5142 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005143}
5144
JiangYizhoubddc46b2016-12-09 09:50:51 +08005145void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5146{
JiangYizhou5b03f472017-01-09 10:22:53 +08005147 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5148 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005149 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5150 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005151
5152 switch (pname)
5153 {
5154 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005155 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005156 break;
5157 default:
5158 UNREACHABLE();
5159 }
5160}
5161
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005162void Context::getMultisamplefvRobust(GLenum pname,
5163 GLuint index,
5164 GLsizei bufSize,
5165 GLsizei *length,
5166 GLfloat *val)
5167{
5168 UNIMPLEMENTED();
5169}
5170
Jamie Madille8fb6402017-02-14 17:56:40 -05005171void Context::renderbufferStorage(GLenum target,
5172 GLenum internalformat,
5173 GLsizei width,
5174 GLsizei height)
5175{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005176 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5177 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5178
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005179 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005180 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005181}
5182
5183void Context::renderbufferStorageMultisample(GLenum target,
5184 GLsizei samples,
5185 GLenum internalformat,
5186 GLsizei width,
5187 GLsizei height)
5188{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005189 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5190 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005191
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005192 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005193 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005194 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005195}
5196
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005197void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5198{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005199 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005200 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005201}
5202
JiangYizhoue18e6392017-02-20 10:32:23 +08005203void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5204{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005205 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005206 QueryFramebufferParameteriv(framebuffer, pname, params);
5207}
5208
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005209void Context::getFramebufferParameterivRobust(GLenum target,
5210 GLenum pname,
5211 GLsizei bufSize,
5212 GLsizei *length,
5213 GLint *params)
5214{
5215 UNIMPLEMENTED();
5216}
5217
Jiajia Qin5451d532017-11-16 17:16:34 +08005218void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005219{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005220 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005221 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005222}
5223
Jamie Madilldec86232018-07-11 09:01:18 -04005224bool Context::getScratchBuffer(size_t requstedSizeBytes,
5225 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005226{
Jamie Madilldec86232018-07-11 09:01:18 -04005227 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005228}
5229
Jamie Madilldec86232018-07-11 09:01:18 -04005230bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5231 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005232{
Jamie Madilldec86232018-07-11 09:01:18 -04005233 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005234}
5235
Xinghua Cao2b396592017-03-29 15:36:04 +08005236void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5237{
5238 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5239 {
5240 return;
5241 }
5242
Xinghua Cao10a4d432017-11-28 14:46:26 +08005243 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005244 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005245}
5246
Jiajia Qin5451d532017-11-16 17:16:34 +08005247void Context::dispatchComputeIndirect(GLintptr indirect)
5248{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005249 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005250 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005251}
5252
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005253void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005254 GLsizei levels,
5255 GLenum internalFormat,
5256 GLsizei width,
5257 GLsizei height)
5258{
5259 Extents size(width, height, 1);
5260 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005261 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005262}
5263
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005264void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005265 GLsizei levels,
5266 GLenum internalFormat,
5267 GLsizei width,
5268 GLsizei height,
5269 GLsizei depth)
5270{
5271 Extents size(width, height, depth);
5272 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005273 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005274}
5275
Jiajia Qin5451d532017-11-16 17:16:34 +08005276void Context::memoryBarrier(GLbitfield barriers)
5277{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005278 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005279}
5280
5281void Context::memoryBarrierByRegion(GLbitfield barriers)
5282{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005283 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005284}
5285
Austin Eng1bf18ce2018-10-19 15:34:02 -07005286void Context::multiDrawArrays(PrimitiveMode mode,
5287 const GLint *firsts,
5288 const GLsizei *counts,
5289 GLsizei drawcount)
5290{
5291 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005292 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005293 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5294 if (hasDrawID)
5295 {
5296 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5297 {
5298 if (noopDraw(mode, counts[drawID]))
5299 {
5300 continue;
5301 }
5302 programObject->setDrawIDUniform(drawID);
5303 ANGLE_CONTEXT_TRY(
5304 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005305 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005306 }
5307 }
5308 else
5309 {
5310 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5311 {
5312 if (noopDraw(mode, counts[drawID]))
5313 {
5314 continue;
5315 }
5316 ANGLE_CONTEXT_TRY(
5317 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005318 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005319 }
5320 }
5321}
5322
5323void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5324 const GLint *firsts,
5325 const GLsizei *counts,
5326 const GLsizei *instanceCounts,
5327 GLsizei drawcount)
5328{
5329 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005330 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005331 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5332 if (hasDrawID)
5333 {
5334 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5335 {
5336 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5337 {
5338 continue;
5339 }
5340 programObject->setDrawIDUniform(drawID);
5341 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5342 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005343 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005344 }
5345 }
5346 else
5347 {
5348 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5349 {
5350 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5351 {
5352 continue;
5353 }
5354 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5355 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005356 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005357 }
5358 }
5359}
5360
5361void Context::multiDrawElements(PrimitiveMode mode,
5362 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005363 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005364 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005365 GLsizei drawcount)
5366{
5367 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005368 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005369 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5370 if (hasDrawID)
5371 {
5372 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5373 {
5374 if (noopDraw(mode, counts[drawID]))
5375 {
5376 continue;
5377 }
5378 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005379 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005380 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005381 }
5382 }
5383 else
5384 {
5385 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5386 {
5387 if (noopDraw(mode, counts[drawID]))
5388 {
5389 continue;
5390 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005391 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005392 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005393 }
5394 }
5395}
5396
5397void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5398 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005399 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005400 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005401 const GLsizei *instanceCounts,
5402 GLsizei drawcount)
5403{
5404 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005405 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005406 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5407 if (hasDrawID)
5408 {
5409 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5410 {
5411 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5412 {
5413 continue;
5414 }
5415 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005416 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005417 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005418 }
5419 }
5420 else
5421 {
5422 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5423 {
5424 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5425 {
5426 continue;
5427 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005428 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005429 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005430 }
5431 }
5432}
5433
Jeff Gilbert465d6092019-01-02 16:21:18 -08005434void Context::provokingVertex(ProvokingVertex provokeMode)
5435{
5436 mState.setProvokingVertex(provokeMode);
5437}
5438
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439GLenum Context::checkFramebufferStatus(GLenum target)
5440{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005441 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005442 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005443 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444}
5445
5446void Context::compileShader(GLuint shader)
5447{
5448 Shader *shaderObject = GetValidShader(this, shader);
5449 if (!shaderObject)
5450 {
5451 return;
5452 }
5453 shaderObject->compile(this);
5454}
5455
5456void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5457{
5458 for (int i = 0; i < n; i++)
5459 {
5460 deleteBuffer(buffers[i]);
5461 }
5462}
5463
5464void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5465{
5466 for (int i = 0; i < n; i++)
5467 {
5468 if (framebuffers[i] != 0)
5469 {
5470 deleteFramebuffer(framebuffers[i]);
5471 }
5472 }
5473}
5474
5475void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5476{
5477 for (int i = 0; i < n; i++)
5478 {
5479 deleteRenderbuffer(renderbuffers[i]);
5480 }
5481}
5482
5483void Context::deleteTextures(GLsizei n, const GLuint *textures)
5484{
5485 for (int i = 0; i < n; i++)
5486 {
5487 if (textures[i] != 0)
5488 {
5489 deleteTexture(textures[i]);
5490 }
5491 }
5492}
5493
5494void Context::detachShader(GLuint program, GLuint shader)
5495{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005496 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005497 ASSERT(programObject);
5498
5499 Shader *shaderObject = getShader(shader);
5500 ASSERT(shaderObject);
5501
5502 programObject->detachShader(this, shaderObject);
5503}
5504
5505void Context::genBuffers(GLsizei n, GLuint *buffers)
5506{
5507 for (int i = 0; i < n; i++)
5508 {
5509 buffers[i] = createBuffer();
5510 }
5511}
5512
5513void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5514{
5515 for (int i = 0; i < n; i++)
5516 {
5517 framebuffers[i] = createFramebuffer();
5518 }
5519}
5520
5521void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5522{
5523 for (int i = 0; i < n; i++)
5524 {
5525 renderbuffers[i] = createRenderbuffer();
5526 }
5527}
5528
5529void Context::genTextures(GLsizei n, GLuint *textures)
5530{
5531 for (int i = 0; i < n; i++)
5532 {
5533 textures[i] = createTexture();
5534 }
5535}
5536
5537void Context::getActiveAttrib(GLuint program,
5538 GLuint index,
5539 GLsizei bufsize,
5540 GLsizei *length,
5541 GLint *size,
5542 GLenum *type,
5543 GLchar *name)
5544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005545 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546 ASSERT(programObject);
5547 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5548}
5549
5550void Context::getActiveUniform(GLuint program,
5551 GLuint index,
5552 GLsizei bufsize,
5553 GLsizei *length,
5554 GLint *size,
5555 GLenum *type,
5556 GLchar *name)
5557{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005558 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005559 ASSERT(programObject);
5560 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5561}
5562
5563void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5564{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005565 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005566 ASSERT(programObject);
5567 programObject->getAttachedShaders(maxcount, count, shaders);
5568}
5569
5570GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5571{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005572 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573 ASSERT(programObject);
5574 return programObject->getAttributeLocation(name);
5575}
5576
5577void Context::getBooleanv(GLenum pname, GLboolean *params)
5578{
5579 GLenum nativeType;
5580 unsigned int numParams = 0;
5581 getQueryParameterInfo(pname, &nativeType, &numParams);
5582
5583 if (nativeType == GL_BOOL)
5584 {
5585 getBooleanvImpl(pname, params);
5586 }
5587 else
5588 {
5589 CastStateValues(this, nativeType, pname, numParams, params);
5590 }
5591}
5592
Brandon Jones59770802018-04-02 13:18:42 -07005593void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5594{
5595 getBooleanv(pname, params);
5596}
5597
Jamie Madillc1d770e2017-04-13 17:31:24 -04005598void Context::getFloatv(GLenum pname, GLfloat *params)
5599{
5600 GLenum nativeType;
5601 unsigned int numParams = 0;
5602 getQueryParameterInfo(pname, &nativeType, &numParams);
5603
5604 if (nativeType == GL_FLOAT)
5605 {
5606 getFloatvImpl(pname, params);
5607 }
5608 else
5609 {
5610 CastStateValues(this, nativeType, pname, numParams, params);
5611 }
5612}
5613
Brandon Jones59770802018-04-02 13:18:42 -07005614void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5615{
5616 getFloatv(pname, params);
5617}
5618
Jamie Madillc1d770e2017-04-13 17:31:24 -04005619void Context::getIntegerv(GLenum pname, GLint *params)
5620{
5621 GLenum nativeType;
5622 unsigned int numParams = 0;
5623 getQueryParameterInfo(pname, &nativeType, &numParams);
5624
5625 if (nativeType == GL_INT)
5626 {
5627 getIntegervImpl(pname, params);
5628 }
5629 else
5630 {
5631 CastStateValues(this, nativeType, pname, numParams, params);
5632 }
5633}
5634
Brandon Jones59770802018-04-02 13:18:42 -07005635void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5636{
5637 getIntegerv(pname, data);
5638}
5639
Jamie Madillc1d770e2017-04-13 17:31:24 -04005640void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5641{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005642 // Don't resolve link if checking the link completion status.
5643 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5644 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005645 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005646 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005647}
5648
Brandon Jones59770802018-04-02 13:18:42 -07005649void Context::getProgramivRobust(GLuint program,
5650 GLenum pname,
5651 GLsizei bufSize,
5652 GLsizei *length,
5653 GLint *params)
5654{
5655 getProgramiv(program, pname, params);
5656}
5657
Jiajia Qin5451d532017-11-16 17:16:34 +08005658void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5659{
5660 UNIMPLEMENTED();
5661}
5662
Jamie Madillbe849e42017-05-02 15:49:00 -04005663void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005665 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005666 ASSERT(programObject);
5667 programObject->getInfoLog(bufsize, length, infolog);
5668}
5669
Jiajia Qin5451d532017-11-16 17:16:34 +08005670void Context::getProgramPipelineInfoLog(GLuint pipeline,
5671 GLsizei bufSize,
5672 GLsizei *length,
5673 GLchar *infoLog)
5674{
5675 UNIMPLEMENTED();
5676}
5677
Jamie Madillc1d770e2017-04-13 17:31:24 -04005678void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5679{
5680 Shader *shaderObject = getShader(shader);
5681 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005682 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005683}
5684
Brandon Jones59770802018-04-02 13:18:42 -07005685void Context::getShaderivRobust(GLuint shader,
5686 GLenum pname,
5687 GLsizei bufSize,
5688 GLsizei *length,
5689 GLint *params)
5690{
5691 getShaderiv(shader, pname, params);
5692}
5693
Jamie Madillc1d770e2017-04-13 17:31:24 -04005694void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5695{
5696 Shader *shaderObject = getShader(shader);
5697 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005698 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005699}
5700
5701void Context::getShaderPrecisionFormat(GLenum shadertype,
5702 GLenum precisiontype,
5703 GLint *range,
5704 GLint *precision)
5705{
5706 // TODO(jmadill): Compute shaders.
5707
5708 switch (shadertype)
5709 {
5710 case GL_VERTEX_SHADER:
5711 switch (precisiontype)
5712 {
5713 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005714 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715 break;
5716 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005717 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005718 break;
5719 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005720 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005721 break;
5722
5723 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005724 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725 break;
5726 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005727 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728 break;
5729 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005730 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731 break;
5732
5733 default:
5734 UNREACHABLE();
5735 return;
5736 }
5737 break;
5738
5739 case GL_FRAGMENT_SHADER:
5740 switch (precisiontype)
5741 {
5742 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005743 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744 break;
5745 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005746 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005747 break;
5748 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005749 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750 break;
5751
5752 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005753 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005754 break;
5755 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005756 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005757 break;
5758 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005759 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005760 break;
5761
5762 default:
5763 UNREACHABLE();
5764 return;
5765 }
5766 break;
5767
5768 default:
5769 UNREACHABLE();
5770 return;
5771 }
5772}
5773
5774void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5775{
5776 Shader *shaderObject = getShader(shader);
5777 ASSERT(shaderObject);
5778 shaderObject->getSource(bufsize, length, source);
5779}
5780
5781void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5782{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005783 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005784 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005785 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005786}
5787
Brandon Jones59770802018-04-02 13:18:42 -07005788void Context::getUniformfvRobust(GLuint program,
5789 GLint location,
5790 GLsizei bufSize,
5791 GLsizei *length,
5792 GLfloat *params)
5793{
5794 getUniformfv(program, location, params);
5795}
5796
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5798{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005799 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005800 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005801 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005802}
5803
Brandon Jones59770802018-04-02 13:18:42 -07005804void Context::getUniformivRobust(GLuint program,
5805 GLint location,
5806 GLsizei bufSize,
5807 GLsizei *length,
5808 GLint *params)
5809{
5810 getUniformiv(program, location, params);
5811}
5812
Jamie Madillc1d770e2017-04-13 17:31:24 -04005813GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5814{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005815 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005816 ASSERT(programObject);
5817 return programObject->getUniformLocation(name);
5818}
5819
5820GLboolean Context::isBuffer(GLuint buffer)
5821{
5822 if (buffer == 0)
5823 {
5824 return GL_FALSE;
5825 }
5826
5827 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5828}
5829
5830GLboolean Context::isEnabled(GLenum cap)
5831{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005832 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005833}
5834
5835GLboolean Context::isFramebuffer(GLuint framebuffer)
5836{
5837 if (framebuffer == 0)
5838 {
5839 return GL_FALSE;
5840 }
5841
5842 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5843}
5844
5845GLboolean Context::isProgram(GLuint program)
5846{
5847 if (program == 0)
5848 {
5849 return GL_FALSE;
5850 }
5851
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005852 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005853}
5854
5855GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5856{
5857 if (renderbuffer == 0)
5858 {
5859 return GL_FALSE;
5860 }
5861
5862 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5863}
5864
5865GLboolean Context::isShader(GLuint shader)
5866{
5867 if (shader == 0)
5868 {
5869 return GL_FALSE;
5870 }
5871
5872 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5873}
5874
5875GLboolean Context::isTexture(GLuint texture)
5876{
5877 if (texture == 0)
5878 {
5879 return GL_FALSE;
5880 }
5881
5882 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5883}
5884
5885void Context::linkProgram(GLuint program)
5886{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005887 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005888 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005889 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005890
5891 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5892 // don't need to worry that:
5893 // 1. Draw calls after link use the new executable code or the old one depending on the link
5894 // result.
5895 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5896 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5897 // ProgramD3D.
5898 if (programObject->isInUse())
5899 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005900 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005901 if (programObject->isLinked())
5902 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005903 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005904 }
jchen107ae70d82018-07-06 13:47:01 +08005905 mStateCache.onProgramExecutableChange(this);
5906 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005907}
5908
5909void Context::releaseShaderCompiler()
5910{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005911 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912}
5913
5914void Context::shaderBinary(GLsizei n,
5915 const GLuint *shaders,
5916 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005917 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005918 GLsizei length)
5919{
5920 // No binary shader formats are supported.
5921 UNIMPLEMENTED();
5922}
5923
Olli Etuaho0ca09752018-09-24 11:00:50 +03005924void Context::bindFragDataLocationIndexed(GLuint program,
5925 GLuint colorNumber,
5926 GLuint index,
5927 const char *name)
5928{
5929 Program *programObject = getProgramNoResolveLink(program);
5930 programObject->bindFragmentOutputLocation(colorNumber, name);
5931 programObject->bindFragmentOutputIndex(index, name);
5932}
5933
5934void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5935{
5936 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5937}
5938
5939int Context::getFragDataIndex(GLuint program, const char *name)
5940{
5941 Program *programObject = getProgramResolveLink(program);
5942 return programObject->getFragDataIndex(name);
5943}
5944
5945int Context::getProgramResourceLocationIndex(GLuint program,
5946 GLenum programInterface,
5947 const char *name)
5948{
5949 Program *programObject = getProgramResolveLink(program);
5950 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5951 return programObject->getFragDataIndex(name);
5952}
5953
Jamie Madillc1d770e2017-04-13 17:31:24 -04005954void Context::shaderSource(GLuint shader,
5955 GLsizei count,
5956 const GLchar *const *string,
5957 const GLint *length)
5958{
5959 Shader *shaderObject = getShader(shader);
5960 ASSERT(shaderObject);
5961 shaderObject->setSource(count, string, length);
5962}
5963
5964void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5965{
5966 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5967}
5968
5969void Context::stencilMask(GLuint mask)
5970{
5971 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5972}
5973
5974void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5975{
5976 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5977}
5978
5979void Context::uniform1f(GLint location, GLfloat x)
5980{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005981 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005982 program->setUniform1fv(location, 1, &x);
5983}
5984
5985void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5986{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005987 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005988 program->setUniform1fv(location, count, v);
5989}
5990
Jamie Madill7e4eff12018-08-08 15:49:26 -04005991void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005992{
Jamie Madille3e680c2018-12-03 17:49:08 -05005993 program->setUniform1iv(this, location, count, v);
5994}
5995
5996void Context::onSamplerUniformChange(size_t textureUnitIndex)
5997{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005998 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05005999 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006000}
6001
Jamie Madill7e4eff12018-08-08 15:49:26 -04006002void Context::uniform1i(GLint location, GLint x)
6003{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006004 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006005}
6006
Jamie Madillc1d770e2017-04-13 17:31:24 -04006007void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6008{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006009 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006010}
6011
6012void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6013{
6014 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006015 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016 program->setUniform2fv(location, 1, xy);
6017}
6018
6019void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6020{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006021 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006022 program->setUniform2fv(location, count, v);
6023}
6024
6025void Context::uniform2i(GLint location, GLint x, GLint y)
6026{
6027 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006028 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006029 program->setUniform2iv(location, 1, xy);
6030}
6031
6032void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6033{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006034 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006035 program->setUniform2iv(location, count, v);
6036}
6037
6038void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6039{
6040 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006041 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006042 program->setUniform3fv(location, 1, xyz);
6043}
6044
6045void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6046{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006047 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006048 program->setUniform3fv(location, count, v);
6049}
6050
6051void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6052{
6053 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006054 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006055 program->setUniform3iv(location, 1, xyz);
6056}
6057
6058void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6059{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006060 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006061 program->setUniform3iv(location, count, v);
6062}
6063
6064void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6065{
6066 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006067 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006068 program->setUniform4fv(location, 1, xyzw);
6069}
6070
6071void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6072{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006073 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006074 program->setUniform4fv(location, count, v);
6075}
6076
6077void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6078{
6079 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006080 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006081 program->setUniform4iv(location, 1, xyzw);
6082}
6083
6084void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6085{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006086 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006087 program->setUniform4iv(location, count, v);
6088}
6089
6090void Context::uniformMatrix2fv(GLint location,
6091 GLsizei count,
6092 GLboolean transpose,
6093 const GLfloat *value)
6094{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006095 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006096 program->setUniformMatrix2fv(location, count, transpose, value);
6097}
6098
6099void Context::uniformMatrix3fv(GLint location,
6100 GLsizei count,
6101 GLboolean transpose,
6102 const GLfloat *value)
6103{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006104 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006105 program->setUniformMatrix3fv(location, count, transpose, value);
6106}
6107
6108void Context::uniformMatrix4fv(GLint location,
6109 GLsizei count,
6110 GLboolean transpose,
6111 const GLfloat *value)
6112{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006113 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006114 program->setUniformMatrix4fv(location, count, transpose, value);
6115}
6116
6117void Context::validateProgram(GLuint program)
6118{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006119 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006120 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006121 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006122}
6123
Jiajia Qin5451d532017-11-16 17:16:34 +08006124void Context::validateProgramPipeline(GLuint pipeline)
6125{
6126 UNIMPLEMENTED();
6127}
6128
Jamie Madilld04908b2017-06-09 14:15:35 -04006129void Context::getProgramBinary(GLuint program,
6130 GLsizei bufSize,
6131 GLsizei *length,
6132 GLenum *binaryFormat,
6133 void *binary)
6134{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006135 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006136 ASSERT(programObject != nullptr);
6137
Jamie Madill4f6592f2018-11-27 16:37:45 -05006138 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006139}
6140
6141void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6142{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006143 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006144 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006145
Jamie Madill4f6592f2018-11-27 16:37:45 -05006146 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006147 if (programObject->isInUse())
6148 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006149 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006150 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006151 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006152}
6153
Jamie Madillff325f12017-08-26 15:06:05 -04006154void Context::uniform1ui(GLint location, GLuint v0)
6155{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006156 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006157 program->setUniform1uiv(location, 1, &v0);
6158}
6159
6160void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6161{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006162 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006163 const GLuint xy[] = {v0, v1};
6164 program->setUniform2uiv(location, 1, xy);
6165}
6166
6167void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6168{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006169 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006170 const GLuint xyz[] = {v0, v1, v2};
6171 program->setUniform3uiv(location, 1, xyz);
6172}
6173
6174void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6175{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006176 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006177 const GLuint xyzw[] = {v0, v1, v2, v3};
6178 program->setUniform4uiv(location, 1, xyzw);
6179}
6180
6181void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6182{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006183 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006184 program->setUniform1uiv(location, count, value);
6185}
6186void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6187{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006188 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006189 program->setUniform2uiv(location, count, value);
6190}
6191
6192void Context::uniform3uiv(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->setUniform3uiv(location, count, value);
6196}
6197
6198void Context::uniform4uiv(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->setUniform4uiv(location, count, value);
6202}
6203
Jamie Madillf0e04492017-08-26 15:28:42 -04006204void Context::genQueries(GLsizei n, GLuint *ids)
6205{
6206 for (GLsizei i = 0; i < n; i++)
6207 {
6208 GLuint handle = mQueryHandleAllocator.allocate();
6209 mQueryMap.assign(handle, nullptr);
6210 ids[i] = handle;
6211 }
6212}
6213
6214void Context::deleteQueries(GLsizei n, const GLuint *ids)
6215{
6216 for (int i = 0; i < n; i++)
6217 {
6218 GLuint query = ids[i];
6219
6220 Query *queryObject = nullptr;
6221 if (mQueryMap.erase(query, &queryObject))
6222 {
6223 mQueryHandleAllocator.release(query);
6224 if (queryObject)
6225 {
6226 queryObject->release(this);
6227 }
6228 }
6229 }
6230}
6231
6232GLboolean Context::isQuery(GLuint id)
6233{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006234 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006235}
6236
Jamie Madillc8c95812017-08-26 18:40:09 -04006237void Context::uniformMatrix2x3fv(GLint location,
6238 GLsizei count,
6239 GLboolean transpose,
6240 const GLfloat *value)
6241{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006242 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006243 program->setUniformMatrix2x3fv(location, count, transpose, value);
6244}
6245
6246void Context::uniformMatrix3x2fv(GLint location,
6247 GLsizei count,
6248 GLboolean transpose,
6249 const GLfloat *value)
6250{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006251 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006252 program->setUniformMatrix3x2fv(location, count, transpose, value);
6253}
6254
6255void Context::uniformMatrix2x4fv(GLint location,
6256 GLsizei count,
6257 GLboolean transpose,
6258 const GLfloat *value)
6259{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006260 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006261 program->setUniformMatrix2x4fv(location, count, transpose, value);
6262}
6263
6264void Context::uniformMatrix4x2fv(GLint location,
6265 GLsizei count,
6266 GLboolean transpose,
6267 const GLfloat *value)
6268{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006269 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006270 program->setUniformMatrix4x2fv(location, count, transpose, value);
6271}
6272
6273void Context::uniformMatrix3x4fv(GLint location,
6274 GLsizei count,
6275 GLboolean transpose,
6276 const GLfloat *value)
6277{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006278 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006279 program->setUniformMatrix3x4fv(location, count, transpose, value);
6280}
6281
6282void Context::uniformMatrix4x3fv(GLint location,
6283 GLsizei count,
6284 GLboolean transpose,
6285 const GLfloat *value)
6286{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006287 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006288 program->setUniformMatrix4x3fv(location, count, transpose, value);
6289}
6290
Jamie Madilld7576732017-08-26 18:49:50 -04006291void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6292{
6293 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6294 {
6295 GLuint vertexArray = arrays[arrayIndex];
6296
6297 if (arrays[arrayIndex] != 0)
6298 {
6299 VertexArray *vertexArrayObject = nullptr;
6300 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6301 {
6302 if (vertexArrayObject != nullptr)
6303 {
6304 detachVertexArray(vertexArray);
6305 vertexArrayObject->onDestroy(this);
6306 }
6307
6308 mVertexArrayHandleAllocator.release(vertexArray);
6309 }
6310 }
6311 }
6312}
6313
6314void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6315{
6316 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6317 {
6318 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6319 mVertexArrayMap.assign(vertexArray, nullptr);
6320 arrays[arrayIndex] = vertexArray;
6321 }
6322}
6323
6324bool Context::isVertexArray(GLuint array)
6325{
6326 if (array == 0)
6327 {
6328 return GL_FALSE;
6329 }
6330
6331 VertexArray *vao = getVertexArray(array);
6332 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6333}
6334
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006335void Context::endTransformFeedback()
6336{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006337 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006338 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006339 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006340}
6341
6342void Context::transformFeedbackVaryings(GLuint program,
6343 GLsizei count,
6344 const GLchar *const *varyings,
6345 GLenum bufferMode)
6346{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006347 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006348 ASSERT(programObject);
6349 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6350}
6351
6352void Context::getTransformFeedbackVarying(GLuint program,
6353 GLuint index,
6354 GLsizei bufSize,
6355 GLsizei *length,
6356 GLsizei *size,
6357 GLenum *type,
6358 GLchar *name)
6359{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006360 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006361 ASSERT(programObject);
6362 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6363}
6364
6365void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6366{
6367 for (int i = 0; i < n; i++)
6368 {
6369 GLuint transformFeedback = ids[i];
6370 if (transformFeedback == 0)
6371 {
6372 continue;
6373 }
6374
6375 TransformFeedback *transformFeedbackObject = nullptr;
6376 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6377 {
6378 if (transformFeedbackObject != nullptr)
6379 {
6380 detachTransformFeedback(transformFeedback);
6381 transformFeedbackObject->release(this);
6382 }
6383
6384 mTransformFeedbackHandleAllocator.release(transformFeedback);
6385 }
6386 }
6387}
6388
6389void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6390{
6391 for (int i = 0; i < n; i++)
6392 {
6393 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6394 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6395 ids[i] = transformFeedback;
6396 }
6397}
6398
6399bool Context::isTransformFeedback(GLuint id)
6400{
6401 if (id == 0)
6402 {
6403 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6404 // returns FALSE
6405 return GL_FALSE;
6406 }
6407
6408 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6409 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6410}
6411
6412void Context::pauseTransformFeedback()
6413{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006414 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006415 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006416 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006417}
6418
6419void Context::resumeTransformFeedback()
6420{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006421 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006422 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006423 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006424}
6425
Jamie Madill12e957f2017-08-26 21:42:26 -04006426void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6427{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006428 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006429 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006430}
6431
Brandon Jones59770802018-04-02 13:18:42 -07006432void Context::getUniformuivRobust(GLuint program,
6433 GLint location,
6434 GLsizei bufSize,
6435 GLsizei *length,
6436 GLuint *params)
6437{
6438 getUniformuiv(program, location, params);
6439}
6440
Jamie Madill12e957f2017-08-26 21:42:26 -04006441GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6442{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006443 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006444 return programObject->getFragDataLocation(name);
6445}
6446
6447void Context::getUniformIndices(GLuint program,
6448 GLsizei uniformCount,
6449 const GLchar *const *uniformNames,
6450 GLuint *uniformIndices)
6451{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006452 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006453 if (!programObject->isLinked())
6454 {
6455 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6456 {
6457 uniformIndices[uniformId] = GL_INVALID_INDEX;
6458 }
6459 }
6460 else
6461 {
6462 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6463 {
6464 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6465 }
6466 }
6467}
6468
6469void Context::getActiveUniformsiv(GLuint program,
6470 GLsizei uniformCount,
6471 const GLuint *uniformIndices,
6472 GLenum pname,
6473 GLint *params)
6474{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006475 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006476 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6477 {
6478 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006479 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006480 }
6481}
6482
6483GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6484{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006485 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006486 return programObject->getUniformBlockIndex(uniformBlockName);
6487}
6488
6489void Context::getActiveUniformBlockiv(GLuint program,
6490 GLuint uniformBlockIndex,
6491 GLenum pname,
6492 GLint *params)
6493{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006494 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006495 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6496}
6497
Brandon Jones59770802018-04-02 13:18:42 -07006498void Context::getActiveUniformBlockivRobust(GLuint program,
6499 GLuint uniformBlockIndex,
6500 GLenum pname,
6501 GLsizei bufSize,
6502 GLsizei *length,
6503 GLint *params)
6504{
6505 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6506}
6507
Jamie Madill12e957f2017-08-26 21:42:26 -04006508void Context::getActiveUniformBlockName(GLuint program,
6509 GLuint uniformBlockIndex,
6510 GLsizei bufSize,
6511 GLsizei *length,
6512 GLchar *uniformBlockName)
6513{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006514 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006515 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6516}
6517
6518void Context::uniformBlockBinding(GLuint program,
6519 GLuint uniformBlockIndex,
6520 GLuint uniformBlockBinding)
6521{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006522 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006523 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006524
Jamie Madill956ab4d2018-10-10 16:13:03 -04006525 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006526 if (programObject->isInUse())
6527 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006528 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006529 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006530 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006531}
6532
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006533GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6534{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006535 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006536 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006537
Jamie Madill70b5bb02017-08-28 13:32:37 -04006538 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006539 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006540 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006541 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006542 return nullptr;
6543 }
6544
Jamie Madill70b5bb02017-08-28 13:32:37 -04006545 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006546}
6547
6548GLboolean Context::isSync(GLsync sync)
6549{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006550 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006551}
6552
6553GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6554{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006555 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006556
6557 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006558 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006559 {
6560 return GL_WAIT_FAILED;
6561 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006562 return result;
6563}
6564
6565void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6566{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006567 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006568 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006569}
6570
6571void Context::getInteger64v(GLenum pname, GLint64 *params)
6572{
6573 GLenum nativeType = GL_NONE;
6574 unsigned int numParams = 0;
6575 getQueryParameterInfo(pname, &nativeType, &numParams);
6576
6577 if (nativeType == GL_INT_64_ANGLEX)
6578 {
6579 getInteger64vImpl(pname, params);
6580 }
6581 else
6582 {
6583 CastStateValues(this, nativeType, pname, numParams, params);
6584 }
6585}
6586
Brandon Jones59770802018-04-02 13:18:42 -07006587void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6588{
6589 getInteger64v(pname, data);
6590}
6591
Corentin Wallez336129f2017-10-17 15:55:40 -04006592void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006593{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006594 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006595 QueryBufferParameteri64v(buffer, pname, params);
6596}
6597
Brandon Jones59770802018-04-02 13:18:42 -07006598void Context::getBufferParameteri64vRobust(BufferBinding target,
6599 GLenum pname,
6600 GLsizei bufSize,
6601 GLsizei *length,
6602 GLint64 *params)
6603{
6604 getBufferParameteri64v(target, pname, params);
6605}
6606
Jamie Madill3ef140a2017-08-26 23:11:21 -04006607void Context::genSamplers(GLsizei count, GLuint *samplers)
6608{
6609 for (int i = 0; i < count; i++)
6610 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006611 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006612 }
6613}
6614
6615void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6616{
6617 for (int i = 0; i < count; i++)
6618 {
6619 GLuint sampler = samplers[i];
6620
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006621 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006622 {
6623 detachSampler(sampler);
6624 }
6625
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006626 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006627 }
6628}
6629
6630void Context::getInternalformativ(GLenum target,
6631 GLenum internalformat,
6632 GLenum pname,
6633 GLsizei bufSize,
6634 GLint *params)
6635{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006636 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006637 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6638}
6639
Brandon Jones59770802018-04-02 13:18:42 -07006640void Context::getInternalformativRobust(GLenum target,
6641 GLenum internalformat,
6642 GLenum pname,
6643 GLsizei bufSize,
6644 GLsizei *length,
6645 GLint *params)
6646{
6647 getInternalformativ(target, internalformat, pname, bufSize, params);
6648}
6649
Jiajia Qin5451d532017-11-16 17:16:34 +08006650void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6651{
6652 programUniform1iv(program, location, 1, &v0);
6653}
6654
6655void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6656{
6657 GLint xy[2] = {v0, v1};
6658 programUniform2iv(program, location, 1, xy);
6659}
6660
6661void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6662{
6663 GLint xyz[3] = {v0, v1, v2};
6664 programUniform3iv(program, location, 1, xyz);
6665}
6666
6667void Context::programUniform4i(GLuint program,
6668 GLint location,
6669 GLint v0,
6670 GLint v1,
6671 GLint v2,
6672 GLint v3)
6673{
6674 GLint xyzw[4] = {v0, v1, v2, v3};
6675 programUniform4iv(program, location, 1, xyzw);
6676}
6677
6678void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6679{
6680 programUniform1uiv(program, location, 1, &v0);
6681}
6682
6683void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6684{
6685 GLuint xy[2] = {v0, v1};
6686 programUniform2uiv(program, location, 1, xy);
6687}
6688
6689void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6690{
6691 GLuint xyz[3] = {v0, v1, v2};
6692 programUniform3uiv(program, location, 1, xyz);
6693}
6694
6695void Context::programUniform4ui(GLuint program,
6696 GLint location,
6697 GLuint v0,
6698 GLuint v1,
6699 GLuint v2,
6700 GLuint v3)
6701{
6702 GLuint xyzw[4] = {v0, v1, v2, v3};
6703 programUniform4uiv(program, location, 1, xyzw);
6704}
6705
6706void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6707{
6708 programUniform1fv(program, location, 1, &v0);
6709}
6710
6711void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6712{
6713 GLfloat xy[2] = {v0, v1};
6714 programUniform2fv(program, location, 1, xy);
6715}
6716
6717void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6718{
6719 GLfloat xyz[3] = {v0, v1, v2};
6720 programUniform3fv(program, location, 1, xyz);
6721}
6722
6723void Context::programUniform4f(GLuint program,
6724 GLint location,
6725 GLfloat v0,
6726 GLfloat v1,
6727 GLfloat v2,
6728 GLfloat v3)
6729{
6730 GLfloat xyzw[4] = {v0, v1, v2, v3};
6731 programUniform4fv(program, location, 1, xyzw);
6732}
6733
Jamie Madill81c2e252017-09-09 23:32:46 -04006734void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6735{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006736 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006737 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006738 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006739}
6740
Jiajia Qin5451d532017-11-16 17:16:34 +08006741void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6742{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006743 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006744 ASSERT(programObject);
6745 programObject->setUniform2iv(location, count, value);
6746}
6747
6748void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6749{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006750 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006751 ASSERT(programObject);
6752 programObject->setUniform3iv(location, count, value);
6753}
6754
6755void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6756{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006757 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006758 ASSERT(programObject);
6759 programObject->setUniform4iv(location, count, value);
6760}
6761
6762void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6763{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006764 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006765 ASSERT(programObject);
6766 programObject->setUniform1uiv(location, count, value);
6767}
6768
6769void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6770{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006771 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006772 ASSERT(programObject);
6773 programObject->setUniform2uiv(location, count, value);
6774}
6775
6776void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6777{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006778 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006779 ASSERT(programObject);
6780 programObject->setUniform3uiv(location, count, value);
6781}
6782
6783void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6784{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006785 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006786 ASSERT(programObject);
6787 programObject->setUniform4uiv(location, count, value);
6788}
6789
6790void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6791{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006792 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006793 ASSERT(programObject);
6794 programObject->setUniform1fv(location, count, value);
6795}
6796
6797void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6798{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006799 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006800 ASSERT(programObject);
6801 programObject->setUniform2fv(location, count, value);
6802}
6803
6804void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6805{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006806 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006807 ASSERT(programObject);
6808 programObject->setUniform3fv(location, count, value);
6809}
6810
6811void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6812{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006813 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006814 ASSERT(programObject);
6815 programObject->setUniform4fv(location, count, value);
6816}
6817
6818void Context::programUniformMatrix2fv(GLuint program,
6819 GLint location,
6820 GLsizei count,
6821 GLboolean transpose,
6822 const GLfloat *value)
6823{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006824 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006825 ASSERT(programObject);
6826 programObject->setUniformMatrix2fv(location, count, transpose, value);
6827}
6828
6829void Context::programUniformMatrix3fv(GLuint program,
6830 GLint location,
6831 GLsizei count,
6832 GLboolean transpose,
6833 const GLfloat *value)
6834{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006835 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006836 ASSERT(programObject);
6837 programObject->setUniformMatrix3fv(location, count, transpose, value);
6838}
6839
6840void Context::programUniformMatrix4fv(GLuint program,
6841 GLint location,
6842 GLsizei count,
6843 GLboolean transpose,
6844 const GLfloat *value)
6845{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006846 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006847 ASSERT(programObject);
6848 programObject->setUniformMatrix4fv(location, count, transpose, value);
6849}
6850
6851void Context::programUniformMatrix2x3fv(GLuint program,
6852 GLint location,
6853 GLsizei count,
6854 GLboolean transpose,
6855 const GLfloat *value)
6856{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006857 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006858 ASSERT(programObject);
6859 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6860}
6861
6862void Context::programUniformMatrix3x2fv(GLuint program,
6863 GLint location,
6864 GLsizei count,
6865 GLboolean transpose,
6866 const GLfloat *value)
6867{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006868 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006869 ASSERT(programObject);
6870 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6871}
6872
6873void Context::programUniformMatrix2x4fv(GLuint program,
6874 GLint location,
6875 GLsizei count,
6876 GLboolean transpose,
6877 const GLfloat *value)
6878{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006879 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006880 ASSERT(programObject);
6881 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6882}
6883
6884void Context::programUniformMatrix4x2fv(GLuint program,
6885 GLint location,
6886 GLsizei count,
6887 GLboolean transpose,
6888 const GLfloat *value)
6889{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006890 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006891 ASSERT(programObject);
6892 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6893}
6894
6895void Context::programUniformMatrix3x4fv(GLuint program,
6896 GLint location,
6897 GLsizei count,
6898 GLboolean transpose,
6899 const GLfloat *value)
6900{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006901 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006902 ASSERT(programObject);
6903 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6904}
6905
6906void Context::programUniformMatrix4x3fv(GLuint program,
6907 GLint location,
6908 GLsizei count,
6909 GLboolean transpose,
6910 const GLfloat *value)
6911{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006912 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006913 ASSERT(programObject);
6914 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6915}
6916
James Darpiniane8a93c62018-01-04 18:02:24 -08006917bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6918{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006919 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006920}
James Darpiniane8a93c62018-01-04 18:02:24 -08006921
Yunchao Hea336b902017-08-02 16:05:21 +08006922void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6923{
6924 for (int i = 0; i < count; i++)
6925 {
6926 pipelines[i] = createProgramPipeline();
6927 }
6928}
6929
6930void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6931{
6932 for (int i = 0; i < count; i++)
6933 {
6934 if (pipelines[i] != 0)
6935 {
6936 deleteProgramPipeline(pipelines[i]);
6937 }
6938 }
6939}
6940
6941GLboolean Context::isProgramPipeline(GLuint pipeline)
6942{
6943 if (pipeline == 0)
6944 {
6945 return GL_FALSE;
6946 }
6947
6948 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6949}
6950
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006951void Context::finishFenceNV(GLuint fence)
6952{
6953 FenceNV *fenceObject = getFenceNV(fence);
6954
6955 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006956 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006957}
6958
6959void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6960{
6961 FenceNV *fenceObject = getFenceNV(fence);
6962
6963 ASSERT(fenceObject && fenceObject->isSet());
6964
6965 switch (pname)
6966 {
6967 case GL_FENCE_STATUS_NV:
6968 {
6969 // GL_NV_fence spec:
6970 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6971 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6972 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6973 GLboolean status = GL_TRUE;
6974 if (fenceObject->getStatus() != GL_TRUE)
6975 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006976 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006977 }
6978 *params = status;
6979 break;
6980 }
6981
6982 case GL_FENCE_CONDITION_NV:
6983 {
6984 *params = static_cast<GLint>(fenceObject->getCondition());
6985 break;
6986 }
6987
6988 default:
6989 UNREACHABLE();
6990 }
6991}
6992
6993void Context::getTranslatedShaderSource(GLuint shader,
6994 GLsizei bufsize,
6995 GLsizei *length,
6996 GLchar *source)
6997{
6998 Shader *shaderObject = getShader(shader);
6999 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007000 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007001}
7002
7003void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7004{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007005 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007006 ASSERT(programObject);
7007
7008 programObject->getUniformfv(this, location, params);
7009}
7010
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007011void Context::getnUniformfvRobust(GLuint program,
7012 GLint location,
7013 GLsizei bufSize,
7014 GLsizei *length,
7015 GLfloat *params)
7016{
7017 UNIMPLEMENTED();
7018}
7019
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007020void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7021{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007022 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007023 ASSERT(programObject);
7024
7025 programObject->getUniformiv(this, location, params);
7026}
7027
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007028void Context::getnUniformivRobust(GLuint program,
7029 GLint location,
7030 GLsizei bufSize,
7031 GLsizei *length,
7032 GLint *params)
7033{
7034 UNIMPLEMENTED();
7035}
7036
7037void Context::getnUniformuivRobust(GLuint program,
7038 GLint location,
7039 GLsizei bufSize,
7040 GLsizei *length,
7041 GLuint *params)
7042{
7043 UNIMPLEMENTED();
7044}
7045
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007046GLboolean Context::isFenceNV(GLuint fence)
7047{
7048 FenceNV *fenceObject = getFenceNV(fence);
7049
7050 if (fenceObject == nullptr)
7051 {
7052 return GL_FALSE;
7053 }
7054
7055 // GL_NV_fence spec:
7056 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7057 // existing fence.
7058 return fenceObject->isSet();
7059}
7060
7061void Context::readnPixels(GLint x,
7062 GLint y,
7063 GLsizei width,
7064 GLsizei height,
7065 GLenum format,
7066 GLenum type,
7067 GLsizei bufSize,
7068 void *data)
7069{
7070 return readPixels(x, y, width, height, format, type, data);
7071}
7072
Jamie Madill007530e2017-12-28 14:27:04 -05007073void Context::setFenceNV(GLuint fence, GLenum condition)
7074{
7075 ASSERT(condition == GL_ALL_COMPLETED_NV);
7076
7077 FenceNV *fenceObject = getFenceNV(fence);
7078 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007079 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007080}
7081
7082GLboolean Context::testFenceNV(GLuint fence)
7083{
7084 FenceNV *fenceObject = getFenceNV(fence);
7085
7086 ASSERT(fenceObject != nullptr);
7087 ASSERT(fenceObject->isSet() == GL_TRUE);
7088
7089 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007090 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007091 {
Jamie Madill007530e2017-12-28 14:27:04 -05007092 return GL_TRUE;
7093 }
7094
7095 return result;
7096}
7097
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007098void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007099{
7100 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007101 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007102 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007103}
7104
Jamie Madillfa920eb2018-01-04 11:45:50 -05007105void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007106{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007107 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007108 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007109 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007110}
7111
Jamie Madillfa920eb2018-01-04 11:45:50 -05007112void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7113{
7114 UNIMPLEMENTED();
7115}
7116
Jamie Madill5b772312018-03-08 20:28:32 -05007117bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7118{
7119 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7120 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7121 // to the fact that it is stored internally as a float, and so would require conversion
7122 // if returned from Context::getIntegerv. Since this conversion is already implemented
7123 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7124 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7125 // application.
7126 switch (pname)
7127 {
7128 case GL_COMPRESSED_TEXTURE_FORMATS:
7129 {
7130 *type = GL_INT;
7131 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7132 return true;
7133 }
7134 case GL_SHADER_BINARY_FORMATS:
7135 {
7136 *type = GL_INT;
7137 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7138 return true;
7139 }
7140
7141 case GL_MAX_VERTEX_ATTRIBS:
7142 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7143 case GL_MAX_VARYING_VECTORS:
7144 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7145 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7146 case GL_MAX_TEXTURE_IMAGE_UNITS:
7147 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7148 case GL_MAX_RENDERBUFFER_SIZE:
7149 case GL_NUM_SHADER_BINARY_FORMATS:
7150 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7151 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007152 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7153 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007154 case GL_RENDERBUFFER_BINDING:
7155 case GL_CURRENT_PROGRAM:
7156 case GL_PACK_ALIGNMENT:
7157 case GL_UNPACK_ALIGNMENT:
7158 case GL_GENERATE_MIPMAP_HINT:
7159 case GL_RED_BITS:
7160 case GL_GREEN_BITS:
7161 case GL_BLUE_BITS:
7162 case GL_ALPHA_BITS:
7163 case GL_DEPTH_BITS:
7164 case GL_STENCIL_BITS:
7165 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7166 case GL_CULL_FACE_MODE:
7167 case GL_FRONT_FACE:
7168 case GL_ACTIVE_TEXTURE:
7169 case GL_STENCIL_FUNC:
7170 case GL_STENCIL_VALUE_MASK:
7171 case GL_STENCIL_REF:
7172 case GL_STENCIL_FAIL:
7173 case GL_STENCIL_PASS_DEPTH_FAIL:
7174 case GL_STENCIL_PASS_DEPTH_PASS:
7175 case GL_STENCIL_BACK_FUNC:
7176 case GL_STENCIL_BACK_VALUE_MASK:
7177 case GL_STENCIL_BACK_REF:
7178 case GL_STENCIL_BACK_FAIL:
7179 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7180 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7181 case GL_DEPTH_FUNC:
7182 case GL_BLEND_SRC_RGB:
7183 case GL_BLEND_SRC_ALPHA:
7184 case GL_BLEND_DST_RGB:
7185 case GL_BLEND_DST_ALPHA:
7186 case GL_BLEND_EQUATION_RGB:
7187 case GL_BLEND_EQUATION_ALPHA:
7188 case GL_STENCIL_WRITEMASK:
7189 case GL_STENCIL_BACK_WRITEMASK:
7190 case GL_STENCIL_CLEAR_VALUE:
7191 case GL_SUBPIXEL_BITS:
7192 case GL_MAX_TEXTURE_SIZE:
7193 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7194 case GL_SAMPLE_BUFFERS:
7195 case GL_SAMPLES:
7196 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7197 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7198 case GL_TEXTURE_BINDING_2D:
7199 case GL_TEXTURE_BINDING_CUBE_MAP:
7200 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7201 {
7202 *type = GL_INT;
7203 *numParams = 1;
7204 return true;
7205 }
7206 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7207 {
7208 if (!getExtensions().packReverseRowOrder)
7209 {
7210 return false;
7211 }
7212 *type = GL_INT;
7213 *numParams = 1;
7214 return true;
7215 }
7216 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7217 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7218 {
7219 if (!getExtensions().textureRectangle)
7220 {
7221 return false;
7222 }
7223 *type = GL_INT;
7224 *numParams = 1;
7225 return true;
7226 }
7227 case GL_MAX_DRAW_BUFFERS_EXT:
7228 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7229 {
7230 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7231 {
7232 return false;
7233 }
7234 *type = GL_INT;
7235 *numParams = 1;
7236 return true;
7237 }
7238 case GL_MAX_VIEWPORT_DIMS:
7239 {
7240 *type = GL_INT;
7241 *numParams = 2;
7242 return true;
7243 }
7244 case GL_VIEWPORT:
7245 case GL_SCISSOR_BOX:
7246 {
7247 *type = GL_INT;
7248 *numParams = 4;
7249 return true;
7250 }
7251 case GL_SHADER_COMPILER:
7252 case GL_SAMPLE_COVERAGE_INVERT:
7253 case GL_DEPTH_WRITEMASK:
7254 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7255 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7256 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7257 // bool-natural
7258 case GL_SAMPLE_COVERAGE:
7259 case GL_SCISSOR_TEST:
7260 case GL_STENCIL_TEST:
7261 case GL_DEPTH_TEST:
7262 case GL_BLEND:
7263 case GL_DITHER:
7264 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7265 {
7266 *type = GL_BOOL;
7267 *numParams = 1;
7268 return true;
7269 }
7270 case GL_COLOR_WRITEMASK:
7271 {
7272 *type = GL_BOOL;
7273 *numParams = 4;
7274 return true;
7275 }
7276 case GL_POLYGON_OFFSET_FACTOR:
7277 case GL_POLYGON_OFFSET_UNITS:
7278 case GL_SAMPLE_COVERAGE_VALUE:
7279 case GL_DEPTH_CLEAR_VALUE:
7280 case GL_LINE_WIDTH:
7281 {
7282 *type = GL_FLOAT;
7283 *numParams = 1;
7284 return true;
7285 }
7286 case GL_ALIASED_LINE_WIDTH_RANGE:
7287 case GL_ALIASED_POINT_SIZE_RANGE:
7288 case GL_DEPTH_RANGE:
7289 {
7290 *type = GL_FLOAT;
7291 *numParams = 2;
7292 return true;
7293 }
7294 case GL_COLOR_CLEAR_VALUE:
7295 case GL_BLEND_COLOR:
7296 {
7297 *type = GL_FLOAT;
7298 *numParams = 4;
7299 return true;
7300 }
7301 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7302 if (!getExtensions().textureFilterAnisotropic)
7303 {
7304 return false;
7305 }
7306 *type = GL_FLOAT;
7307 *numParams = 1;
7308 return true;
7309 case GL_TIMESTAMP_EXT:
7310 if (!getExtensions().disjointTimerQuery)
7311 {
7312 return false;
7313 }
7314 *type = GL_INT_64_ANGLEX;
7315 *numParams = 1;
7316 return true;
7317 case GL_GPU_DISJOINT_EXT:
7318 if (!getExtensions().disjointTimerQuery)
7319 {
7320 return false;
7321 }
7322 *type = GL_INT;
7323 *numParams = 1;
7324 return true;
7325 case GL_COVERAGE_MODULATION_CHROMIUM:
7326 if (!getExtensions().framebufferMixedSamples)
7327 {
7328 return false;
7329 }
7330 *type = GL_INT;
7331 *numParams = 1;
7332 return true;
7333 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7334 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7335 {
7336 return false;
7337 }
7338 *type = GL_INT;
7339 *numParams = 1;
7340 return true;
7341 }
7342
7343 if (getExtensions().debug)
7344 {
7345 switch (pname)
7346 {
7347 case GL_DEBUG_LOGGED_MESSAGES:
7348 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7349 case GL_DEBUG_GROUP_STACK_DEPTH:
7350 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7351 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7352 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7353 case GL_MAX_LABEL_LENGTH:
7354 *type = GL_INT;
7355 *numParams = 1;
7356 return true;
7357
7358 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7359 case GL_DEBUG_OUTPUT:
7360 *type = GL_BOOL;
7361 *numParams = 1;
7362 return true;
7363 }
7364 }
7365
7366 if (getExtensions().multisampleCompatibility)
7367 {
7368 switch (pname)
7369 {
7370 case GL_MULTISAMPLE_EXT:
7371 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7372 *type = GL_BOOL;
7373 *numParams = 1;
7374 return true;
7375 }
7376 }
7377
7378 if (getExtensions().pathRendering)
7379 {
7380 switch (pname)
7381 {
7382 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7383 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7384 *type = GL_FLOAT;
7385 *numParams = 16;
7386 return true;
7387 }
7388 }
7389
7390 if (getExtensions().bindGeneratesResource)
7391 {
7392 switch (pname)
7393 {
7394 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7395 *type = GL_BOOL;
7396 *numParams = 1;
7397 return true;
7398 }
7399 }
7400
7401 if (getExtensions().clientArrays)
7402 {
7403 switch (pname)
7404 {
7405 case GL_CLIENT_ARRAYS_ANGLE:
7406 *type = GL_BOOL;
7407 *numParams = 1;
7408 return true;
7409 }
7410 }
7411
7412 if (getExtensions().sRGBWriteControl)
7413 {
7414 switch (pname)
7415 {
7416 case GL_FRAMEBUFFER_SRGB_EXT:
7417 *type = GL_BOOL;
7418 *numParams = 1;
7419 return true;
7420 }
7421 }
7422
7423 if (getExtensions().robustResourceInitialization &&
7424 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7425 {
7426 *type = GL_BOOL;
7427 *numParams = 1;
7428 return true;
7429 }
7430
7431 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7432 {
7433 *type = GL_BOOL;
7434 *numParams = 1;
7435 return true;
7436 }
7437
jchen1082af6202018-06-22 10:59:52 +08007438 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7439 {
7440 *type = GL_INT;
7441 *numParams = 1;
7442 return true;
7443 }
7444
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007445 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7446 {
7447 *type = GL_INT;
7448 *numParams = 1;
7449 return true;
7450 }
7451
Jamie Madill5b772312018-03-08 20:28:32 -05007452 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7453 switch (pname)
7454 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007455 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007456 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7457 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7458 {
7459 return false;
7460 }
7461 *type = GL_INT;
7462 *numParams = 1;
7463 return true;
7464
7465 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7466 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7467 {
7468 return false;
7469 }
7470 *type = GL_INT;
7471 *numParams = 1;
7472 return true;
7473
7474 case GL_PROGRAM_BINARY_FORMATS_OES:
7475 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7476 {
7477 return false;
7478 }
7479 *type = GL_INT;
7480 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7481 return true;
7482
7483 case GL_PACK_ROW_LENGTH:
7484 case GL_PACK_SKIP_ROWS:
7485 case GL_PACK_SKIP_PIXELS:
7486 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7487 {
7488 return false;
7489 }
7490 *type = GL_INT;
7491 *numParams = 1;
7492 return true;
7493 case GL_UNPACK_ROW_LENGTH:
7494 case GL_UNPACK_SKIP_ROWS:
7495 case GL_UNPACK_SKIP_PIXELS:
7496 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7497 {
7498 return false;
7499 }
7500 *type = GL_INT;
7501 *numParams = 1;
7502 return true;
7503 case GL_VERTEX_ARRAY_BINDING:
7504 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7505 {
7506 return false;
7507 }
7508 *type = GL_INT;
7509 *numParams = 1;
7510 return true;
7511 case GL_PIXEL_PACK_BUFFER_BINDING:
7512 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7513 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7514 {
7515 return false;
7516 }
7517 *type = GL_INT;
7518 *numParams = 1;
7519 return true;
7520 case GL_MAX_SAMPLES:
7521 {
7522 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7523 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7524 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7525 {
7526 return false;
7527 }
7528 *type = GL_INT;
7529 *numParams = 1;
7530 return true;
7531
7532 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7533 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7534 {
7535 return false;
7536 }
7537 *type = GL_INT;
7538 *numParams = 1;
7539 return true;
7540 }
7541 }
7542
7543 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7544 {
7545 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7546 {
7547 return false;
7548 }
7549 *type = GL_INT;
7550 *numParams = 1;
7551 return true;
7552 }
7553
7554 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7555 {
7556 *type = GL_INT;
7557 *numParams = 1;
7558 return true;
7559 }
7560
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007561 if (getClientVersion() < Version(2, 0))
7562 {
7563 switch (pname)
7564 {
7565 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007566 case GL_CLIENT_ACTIVE_TEXTURE:
7567 case GL_MATRIX_MODE:
7568 case GL_MAX_TEXTURE_UNITS:
7569 case GL_MAX_MODELVIEW_STACK_DEPTH:
7570 case GL_MAX_PROJECTION_STACK_DEPTH:
7571 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007572 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007573 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007574 case GL_VERTEX_ARRAY_STRIDE:
7575 case GL_NORMAL_ARRAY_STRIDE:
7576 case GL_COLOR_ARRAY_STRIDE:
7577 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7578 case GL_VERTEX_ARRAY_SIZE:
7579 case GL_COLOR_ARRAY_SIZE:
7580 case GL_TEXTURE_COORD_ARRAY_SIZE:
7581 case GL_VERTEX_ARRAY_TYPE:
7582 case GL_NORMAL_ARRAY_TYPE:
7583 case GL_COLOR_ARRAY_TYPE:
7584 case GL_TEXTURE_COORD_ARRAY_TYPE:
7585 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7586 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7587 case GL_COLOR_ARRAY_BUFFER_BINDING:
7588 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7589 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7590 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7591 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007592 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007593 case GL_MODELVIEW_STACK_DEPTH:
7594 case GL_PROJECTION_STACK_DEPTH:
7595 case GL_TEXTURE_STACK_DEPTH:
7596 case GL_LOGIC_OP_MODE:
7597 case GL_BLEND_SRC:
7598 case GL_BLEND_DST:
7599 case GL_PERSPECTIVE_CORRECTION_HINT:
7600 case GL_POINT_SMOOTH_HINT:
7601 case GL_LINE_SMOOTH_HINT:
7602 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007603 *type = GL_INT;
7604 *numParams = 1;
7605 return true;
7606 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007607 case GL_FOG_DENSITY:
7608 case GL_FOG_START:
7609 case GL_FOG_END:
7610 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007611 case GL_POINT_SIZE:
7612 case GL_POINT_SIZE_MIN:
7613 case GL_POINT_SIZE_MAX:
7614 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007615 *type = GL_FLOAT;
7616 *numParams = 1;
7617 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007618 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007619 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007620 *type = GL_FLOAT;
7621 *numParams = 2;
7622 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007623 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007624 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007625 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007626 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007627 *type = GL_FLOAT;
7628 *numParams = 4;
7629 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007630 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007631 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007632 *type = GL_FLOAT;
7633 *numParams = 3;
7634 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007635 case GL_MODELVIEW_MATRIX:
7636 case GL_PROJECTION_MATRIX:
7637 case GL_TEXTURE_MATRIX:
7638 *type = GL_FLOAT;
7639 *numParams = 16;
7640 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007641 case GL_LIGHT_MODEL_TWO_SIDE:
7642 *type = GL_BOOL;
7643 *numParams = 1;
7644 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007645 }
7646 }
7647
Jamie Madill5b772312018-03-08 20:28:32 -05007648 if (getClientVersion() < Version(3, 0))
7649 {
7650 return false;
7651 }
7652
7653 // Check for ES3.0+ parameter names
7654 switch (pname)
7655 {
7656 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7657 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7658 case GL_UNIFORM_BUFFER_BINDING:
7659 case GL_TRANSFORM_FEEDBACK_BINDING:
7660 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7661 case GL_COPY_READ_BUFFER_BINDING:
7662 case GL_COPY_WRITE_BUFFER_BINDING:
7663 case GL_SAMPLER_BINDING:
7664 case GL_READ_BUFFER:
7665 case GL_TEXTURE_BINDING_3D:
7666 case GL_TEXTURE_BINDING_2D_ARRAY:
7667 case GL_MAX_3D_TEXTURE_SIZE:
7668 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7669 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7670 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7671 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7672 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7673 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7674 case GL_MAX_VARYING_COMPONENTS:
7675 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7676 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7677 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7678 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7679 case GL_NUM_EXTENSIONS:
7680 case GL_MAJOR_VERSION:
7681 case GL_MINOR_VERSION:
7682 case GL_MAX_ELEMENTS_INDICES:
7683 case GL_MAX_ELEMENTS_VERTICES:
7684 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7685 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7686 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7687 case GL_UNPACK_IMAGE_HEIGHT:
7688 case GL_UNPACK_SKIP_IMAGES:
7689 {
7690 *type = GL_INT;
7691 *numParams = 1;
7692 return true;
7693 }
7694
7695 case GL_MAX_ELEMENT_INDEX:
7696 case GL_MAX_UNIFORM_BLOCK_SIZE:
7697 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7698 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7699 case GL_MAX_SERVER_WAIT_TIMEOUT:
7700 {
7701 *type = GL_INT_64_ANGLEX;
7702 *numParams = 1;
7703 return true;
7704 }
7705
7706 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7707 case GL_TRANSFORM_FEEDBACK_PAUSED:
7708 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7709 case GL_RASTERIZER_DISCARD:
7710 {
7711 *type = GL_BOOL;
7712 *numParams = 1;
7713 return true;
7714 }
7715
7716 case GL_MAX_TEXTURE_LOD_BIAS:
7717 {
7718 *type = GL_FLOAT;
7719 *numParams = 1;
7720 return true;
7721 }
7722 }
7723
7724 if (getExtensions().requestExtension)
7725 {
7726 switch (pname)
7727 {
7728 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7729 *type = GL_INT;
7730 *numParams = 1;
7731 return true;
7732 }
7733 }
7734
Yizhou Jiang7818a852018-09-06 15:02:04 +08007735 if (getExtensions().textureMultisample)
7736 {
7737 switch (pname)
7738 {
7739 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7740 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7741 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7742 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007743 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007744 *type = GL_INT;
7745 *numParams = 1;
7746 return true;
7747 }
7748 }
7749
Jamie Madill5b772312018-03-08 20:28:32 -05007750 if (getClientVersion() < Version(3, 1))
7751 {
7752 return false;
7753 }
7754
7755 switch (pname)
7756 {
7757 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7758 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7759 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7760 case GL_MAX_FRAMEBUFFER_WIDTH:
7761 case GL_MAX_FRAMEBUFFER_HEIGHT:
7762 case GL_MAX_FRAMEBUFFER_SAMPLES:
7763 case GL_MAX_SAMPLE_MASK_WORDS:
7764 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7765 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7766 case GL_MAX_INTEGER_SAMPLES:
7767 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7768 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7769 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7770 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7771 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7772 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7773 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7774 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7775 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7776 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7777 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7778 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7779 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7780 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7781 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7782 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7783 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7784 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7785 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7786 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7787 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7788 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7789 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7790 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7791 case GL_MAX_UNIFORM_LOCATIONS:
7792 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7793 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7794 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7795 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7796 case GL_MAX_IMAGE_UNITS:
7797 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7798 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7799 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7800 case GL_SHADER_STORAGE_BUFFER_BINDING:
7801 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7802 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007803 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007804 *type = GL_INT;
7805 *numParams = 1;
7806 return true;
7807 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7808 *type = GL_INT_64_ANGLEX;
7809 *numParams = 1;
7810 return true;
7811 case GL_SAMPLE_MASK:
7812 *type = GL_BOOL;
7813 *numParams = 1;
7814 return true;
7815 }
7816
7817 if (getExtensions().geometryShader)
7818 {
7819 switch (pname)
7820 {
7821 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7822 case GL_LAYER_PROVOKING_VERTEX_EXT:
7823 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7824 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7825 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7826 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7827 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7828 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7829 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7830 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7831 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7832 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7833 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7834 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7835 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7836 *type = GL_INT;
7837 *numParams = 1;
7838 return true;
7839 }
7840 }
7841
7842 return false;
7843}
7844
7845bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7846{
7847 if (getClientVersion() < Version(3, 0))
7848 {
7849 return false;
7850 }
7851
7852 switch (target)
7853 {
7854 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7855 case GL_UNIFORM_BUFFER_BINDING:
7856 {
7857 *type = GL_INT;
7858 *numParams = 1;
7859 return true;
7860 }
7861 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7862 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7863 case GL_UNIFORM_BUFFER_START:
7864 case GL_UNIFORM_BUFFER_SIZE:
7865 {
7866 *type = GL_INT_64_ANGLEX;
7867 *numParams = 1;
7868 return true;
7869 }
7870 }
7871
7872 if (getClientVersion() < Version(3, 1))
7873 {
7874 return false;
7875 }
7876
7877 switch (target)
7878 {
7879 case GL_IMAGE_BINDING_LAYERED:
7880 {
7881 *type = GL_BOOL;
7882 *numParams = 1;
7883 return true;
7884 }
7885 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7886 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7887 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7888 case GL_SHADER_STORAGE_BUFFER_BINDING:
7889 case GL_VERTEX_BINDING_BUFFER:
7890 case GL_VERTEX_BINDING_DIVISOR:
7891 case GL_VERTEX_BINDING_OFFSET:
7892 case GL_VERTEX_BINDING_STRIDE:
7893 case GL_SAMPLE_MASK_VALUE:
7894 case GL_IMAGE_BINDING_NAME:
7895 case GL_IMAGE_BINDING_LEVEL:
7896 case GL_IMAGE_BINDING_LAYER:
7897 case GL_IMAGE_BINDING_ACCESS:
7898 case GL_IMAGE_BINDING_FORMAT:
7899 {
7900 *type = GL_INT;
7901 *numParams = 1;
7902 return true;
7903 }
7904 case GL_ATOMIC_COUNTER_BUFFER_START:
7905 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7906 case GL_SHADER_STORAGE_BUFFER_START:
7907 case GL_SHADER_STORAGE_BUFFER_SIZE:
7908 {
7909 *type = GL_INT_64_ANGLEX;
7910 *numParams = 1;
7911 return true;
7912 }
7913 }
7914
7915 return false;
7916}
7917
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007918Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007919{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007920 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007921}
7922
7923Shader *Context::getShader(GLuint handle) const
7924{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007925 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007926}
7927
Jamie Madill5b772312018-03-08 20:28:32 -05007928bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7929{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007930 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007931}
7932
7933bool Context::isFramebufferGenerated(GLuint framebuffer) const
7934{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007935 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007936}
7937
7938bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7939{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007940 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007941}
7942
7943bool Context::usingDisplayTextureShareGroup() const
7944{
7945 return mDisplayTextureShareGroup;
7946}
7947
7948GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7949{
7950 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7951 internalformat == GL_DEPTH_STENCIL
7952 ? GL_DEPTH24_STENCIL8
7953 : internalformat;
7954}
7955
jchen1082af6202018-06-22 10:59:52 +08007956void Context::maxShaderCompilerThreads(GLuint count)
7957{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007958 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7959 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007960 // A count of zero specifies a request for no parallel compiling or linking.
7961 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7962 {
7963 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7964 }
7965 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007966}
7967
Jamie Madill2eb65032018-07-30 10:25:57 -04007968bool Context::isGLES1() const
7969{
7970 return mState.getClientVersion() < Version(2, 0);
7971}
7972
Jamie Madilla11819d2018-07-30 10:26:01 -04007973void Context::onSubjectStateChange(const Context *context,
7974 angle::SubjectIndex index,
7975 angle::SubjectMessage message)
7976{
Jamie Madilla11819d2018-07-30 10:26:01 -04007977 switch (index)
7978 {
7979 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007980 switch (message)
7981 {
7982 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007983 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007984 mStateCache.onVertexArrayBufferContentsChange(this);
7985 break;
7986 case angle::SubjectMessage::RESOURCE_MAPPED:
7987 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7988 case angle::SubjectMessage::BINDING_CHANGED:
7989 mStateCache.onVertexArrayBufferStateChange(this);
7990 break;
7991 default:
7992 break;
7993 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007994 break;
7995
7996 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007997 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7998 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007999 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04008000 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008001 break;
8002
8003 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008004 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8005 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008006 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008007 }
8008 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008009 break;
8010
8011 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008012 if (index < kTextureMaxSubjectIndex)
8013 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008014 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008015 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008016 }
Jamie Madille25b8002018-09-20 13:39:49 -04008017 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008018 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008019 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008020 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008021 }
Jamie Madille25b8002018-09-20 13:39:49 -04008022 else
8023 {
8024 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008025 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008026 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008027 break;
8028 }
8029}
8030
Jamie Madill6b873dd2018-07-12 23:56:30 -04008031// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008032ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008033
8034ErrorSet::~ErrorSet() = default;
8035
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008036void ErrorSet::handleError(GLenum errorCode,
8037 const char *message,
8038 const char *file,
8039 const char *function,
8040 unsigned int line)
8041{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008042 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8043 {
8044 mContext->markContextLost();
8045 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008046
Jamie Madill4f6592f2018-11-27 16:37:45 -05008047 std::stringstream errorStream;
8048 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8049 << line << ". " << message;
8050
Geoff Lang7139b432018-12-14 16:57:28 -05008051 std::string formattedMessage = errorStream.str();
8052
8053 // Always log a warning, this function is only called on unexpected internal errors.
8054 WARN() << formattedMessage;
8055
Jamie Madill4f6592f2018-11-27 16:37:45 -05008056 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008057 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008058}
8059
Jamie Madilla139f012018-10-10 16:13:03 -04008060void ErrorSet::validationError(GLenum errorCode, const char *message)
8061{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008062 ASSERT(errorCode != GL_NO_ERROR);
8063 mErrors.insert(errorCode);
8064
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008065 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8066 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008067}
8068
Jamie Madill6b873dd2018-07-12 23:56:30 -04008069bool ErrorSet::empty() const
8070{
8071 return mErrors.empty();
8072}
8073
8074GLenum ErrorSet::popError()
8075{
8076 ASSERT(!empty());
8077 GLenum error = *mErrors.begin();
8078 mErrors.erase(mErrors.begin());
8079 return error;
8080}
Jamie Madilldc358af2018-07-31 11:22:13 -04008081
8082// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008083StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008084 : mCachedHasAnyEnabledClientAttrib(false),
8085 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008086 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008087 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008088 mCachedBasicDrawElementsError(kInvalidPointer),
8089 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008090{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008091
8092StateCache::~StateCache() = default;
8093
Jamie Madillac66f982018-10-09 18:30:01 -04008094void StateCache::initialize(Context *context)
8095{
8096 updateValidDrawModes(context);
8097 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008098 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008099 updateBasicDrawStatesError();
8100 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008101}
8102
Jamie Madilldc358af2018-07-31 11:22:13 -04008103void StateCache::updateActiveAttribsMask(Context *context)
8104{
8105 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008106 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008107
8108 if (!isGLES1 && !glState.getProgram())
8109 {
8110 mCachedActiveBufferedAttribsMask = AttributesMask();
8111 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008112 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008113 return;
8114 }
8115
8116 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8117 : glState.getProgram()->getActiveAttribLocationsMask();
8118
8119 const VertexArray *vao = glState.getVertexArray();
8120 ASSERT(vao);
8121
8122 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8123 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008124 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008125
Jamie Madill0a17e482018-08-31 17:19:11 -04008126 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8127 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008128 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008129 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8130}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008131
8132void StateCache::updateVertexElementLimits(Context *context)
8133{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008134 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008135
8136 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8137 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8138
8139 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8140 // If there are no buffered attributes then we should not limit the draw call count.
8141 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8142 {
8143 return;
8144 }
8145
8146 const auto &vertexAttribs = vao->getVertexAttributes();
8147 const auto &vertexBindings = vao->getVertexBindings();
8148
8149 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8150 {
8151 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008152
8153 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8154 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008155 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008156
8157 GLint64 limit = attrib.getCachedElementLimit();
8158 if (binding.getDivisor() > 0)
8159 {
8160 mCachedInstancedVertexElementLimit =
8161 std::min(mCachedInstancedVertexElementLimit, limit);
8162 }
8163 else
8164 {
8165 mCachedNonInstancedVertexElementLimit =
8166 std::min(mCachedNonInstancedVertexElementLimit, limit);
8167 }
8168 }
8169}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008170
Jamie Madilld84b6732018-09-06 15:54:35 -04008171void StateCache::updateBasicDrawStatesError()
8172{
8173 mCachedBasicDrawStatesError = kInvalidPointer;
8174}
8175
Jamie Madill1e853262018-12-21 09:07:38 -05008176void StateCache::updateBasicDrawElementsError()
8177{
8178 mCachedBasicDrawElementsError = kInvalidPointer;
8179}
8180
Jamie Madilld84b6732018-09-06 15:54:35 -04008181intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8182{
8183 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8184 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8185 return mCachedBasicDrawStatesError;
8186}
8187
Jamie Madill1e853262018-12-21 09:07:38 -05008188intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8189{
8190 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8191 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8192 return mCachedBasicDrawElementsError;
8193}
8194
Jamie Madillc43cdad2018-08-08 15:49:25 -04008195void StateCache::onVertexArrayBindingChange(Context *context)
8196{
8197 updateActiveAttribsMask(context);
8198 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008199 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008200}
8201
8202void StateCache::onProgramExecutableChange(Context *context)
8203{
8204 updateActiveAttribsMask(context);
8205 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008206 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008207 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008208}
8209
Jamie Madilld84b6732018-09-06 15:54:35 -04008210void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008211{
8212 updateVertexElementLimits(context);
8213}
8214
Jamie Madilld84b6732018-09-06 15:54:35 -04008215void StateCache::onVertexArrayBufferContentsChange(Context *context)
8216{
8217 updateVertexElementLimits(context);
8218 updateBasicDrawStatesError();
8219}
8220
Jamie Madillc43cdad2018-08-08 15:49:25 -04008221void StateCache::onVertexArrayStateChange(Context *context)
8222{
8223 updateActiveAttribsMask(context);
8224 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008225 updateBasicDrawStatesError();
8226}
8227
8228void StateCache::onVertexArrayBufferStateChange(Context *context)
8229{
8230 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008231 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008232}
8233
8234void StateCache::onGLES1ClientStateChange(Context *context)
8235{
8236 updateActiveAttribsMask(context);
8237}
Jamie Madilld84b6732018-09-06 15:54:35 -04008238
8239void StateCache::onDrawFramebufferChange(Context *context)
8240{
8241 updateBasicDrawStatesError();
8242}
8243
8244void StateCache::onContextCapChange(Context *context)
8245{
8246 updateBasicDrawStatesError();
8247}
8248
8249void StateCache::onStencilStateChange(Context *context)
8250{
8251 updateBasicDrawStatesError();
8252}
8253
8254void StateCache::onDefaultVertexAttributeChange(Context *context)
8255{
8256 updateBasicDrawStatesError();
8257}
8258
8259void StateCache::onActiveTextureChange(Context *context)
8260{
8261 updateBasicDrawStatesError();
8262}
8263
8264void StateCache::onQueryChange(Context *context)
8265{
8266 updateBasicDrawStatesError();
8267}
8268
Jamie Madill3a256222018-12-08 09:56:39 -05008269void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008270{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008271 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008272 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008273 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008274 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008275}
8276
8277void StateCache::onUniformBufferStateChange(Context *context)
8278{
8279 updateBasicDrawStatesError();
8280}
8281
Jamie Madill9b025062018-12-12 15:44:12 -05008282void StateCache::setValidDrawModes(bool pointsOK,
8283 bool linesOK,
8284 bool trisOK,
8285 bool lineAdjOK,
8286 bool triAdjOK)
8287{
8288 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8289 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8290 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8291 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8292 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8293 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8294 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8295 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8296 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8297 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8298 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8299}
8300
Jamie Madill526a6f62018-09-12 11:03:05 -04008301void StateCache::updateValidDrawModes(Context *context)
8302{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008303 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008304 Program *program = state.getProgram();
8305
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008306 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008307 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008308 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8309
Jamie Madill9b025062018-12-12 15:44:12 -05008310 // ES Spec 3.0 validation text:
8311 // When transform feedback is active and not paused, all geometric primitives generated must
8312 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8313 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8314 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8315 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8316 // active and not paused, regardless of mode. Any primitive type may be used while transform
8317 // feedback is paused.
8318 if (!context->getExtensions().geometryShader)
8319 {
8320 mCachedValidDrawModes.fill(false);
8321 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8322 return;
8323 }
8324
8325 // EXT_geometry_shader validation text:
8326 // When transform feedback is active and not paused, all geometric primitives generated must
8327 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8328 // geometry shader is active, the type of primitive emitted by that shader is used instead
8329 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8330 // Any primitive type may be used while transform feedback is paused.
8331 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8332 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8333 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8334
8335 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8336 return;
8337 }
8338
Jamie Madill526a6f62018-09-12 11:03:05 -04008339 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8340 {
Jamie Madill752d2202018-11-27 13:29:48 -05008341 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008342 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008343 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008344
Jamie Madill9b025062018-12-12 15:44:12 -05008345 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8346 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008347
Jamie Madill9b025062018-12-12 15:44:12 -05008348 bool pointsOK = gsMode == PrimitiveMode::Points;
8349 bool linesOK = gsMode == PrimitiveMode::Lines;
8350 bool trisOK = gsMode == PrimitiveMode::Triangles;
8351 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8352 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8353
8354 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008355}
Jamie Madillac66f982018-10-09 18:30:01 -04008356
8357void StateCache::updateValidBindTextureTypes(Context *context)
8358{
8359 const Extensions &exts = context->getExtensions();
8360 bool isGLES3 = context->getClientMajorVersion() >= 3;
8361 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8362
8363 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008364 {TextureType::_2D, true},
8365 {TextureType::_2DArray, isGLES3},
8366 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8367 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8368 {TextureType::_3D, isGLES3},
8369 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8370 {TextureType::Rectangle, exts.textureRectangle},
8371 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008372 }};
8373}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008374
8375void StateCache::updateValidDrawElementsTypes(Context *context)
8376{
8377 bool supportsUint =
8378 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8379
8380 mCachedValidDrawElementsTypes = {{
8381 {DrawElementsType::UnsignedByte, true},
8382 {DrawElementsType::UnsignedShort, true},
8383 {DrawElementsType::UnsignedInt, supportsUint},
8384 }};
8385}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008386
8387void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8388{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008389 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008390 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8391}
Jamie Madillc29968b2016-01-20 11:17:23 -05008392} // namespace gl