blob: 545a0acefc6f6fbc20fe6a2e5d1c471330053523 [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;
1341 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001342 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001343 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345}
1346
Jamie Madillc1d770e2017-04-13 17:31:24 -04001347void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348{
Shannon Woods53a94a82014-06-24 15:20:36 -04001349 // Queries about context capabilities and maximums are answered by Context.
1350 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351 switch (pname)
1352 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001353 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001354 params[0] = mState.mCaps.minAliasedLineWidth;
1355 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001358 params[0] = mState.mCaps.minAliasedPointSize;
1359 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001361 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001362 params[0] = mState.mCaps.minSmoothPointSize;
1363 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001364 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001365 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001366 params[0] = mState.mCaps.minSmoothLineWidth;
1367 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001368 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001369 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001370 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1371 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 break;
1373 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001374 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 break;
1376
1377 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1378 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1379 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001380 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1381 // GLES1 constants for modelview/projection matrix.
1382 if (getClientVersion() < Version(2, 0))
1383 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001384 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001385 }
1386 else
1387 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001388 ASSERT(mState.mExtensions.pathRendering);
1389 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001390 memcpy(params, m, 16 * sizeof(GLfloat));
1391 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001393 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001394
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001396 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001398 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001399}
1400
Jamie Madillc1d770e2017-04-13 17:31:24 -04001401void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001402{
Shannon Woods53a94a82014-06-24 15:20:36 -04001403 // Queries about context capabilities and maximums are answered by Context.
1404 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001405
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001406 switch (pname)
1407 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001408 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001409 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 break;
1411 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001412 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 break;
1414 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001415 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 break;
1417 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001418 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001421 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001424 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001425 break;
1426 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001427 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001428 break;
1429 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001430 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001431 break;
1432 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001433 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001434 break;
1435 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001436 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001437 break;
1438 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001439 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001440 break;
1441 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001442 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001443 break;
1444 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001445 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 case GL_SUBPIXEL_BITS:
1448 *params = 4;
1449 break;
1450 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001451 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001453 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001454 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001455 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001457 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001458 break;
1459 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001460 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001461 break;
1462 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001463 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001464 break;
1465 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001466 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001467 break;
1468 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001469 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 break;
1471 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001472 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001473 break;
1474 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001475 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001476 break;
1477 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001478 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 break;
1480 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001481 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001482 break;
1483 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001484 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001485 break;
1486 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001487 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001488 break;
1489 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001490 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001491 break;
1492 case GL_MAJOR_VERSION:
1493 *params = getClientVersion().major;
1494 break;
1495 case GL_MINOR_VERSION:
1496 *params = getClientVersion().minor;
1497 break;
1498 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001499 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001500 break;
1501 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001502 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001503 break;
1504 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001505 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001506 break;
1507 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001508 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001509 break;
1510 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001511 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 break;
1513 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001514 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001515 break;
1516 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001517 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001518 break;
1519 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001520 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001521 params[0] = mState.mCaps.maxViewportWidth;
1522 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001523 }
1524 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001526 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1527 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001528 break;
1529 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1530 *params = mResetStrategy;
1531 break;
1532 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001533 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001536 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1537 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001538 break;
1539 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001540 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001541 break;
1542 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001543 std::copy(mState.mCaps.programBinaryFormats.begin(),
1544 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 break;
1546 case GL_NUM_EXTENSIONS:
1547 *params = static_cast<GLint>(mExtensionStrings.size());
1548 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001549
Geoff Lang38f24ee2018-10-01 13:04:59 -04001550 // GL_ANGLE_request_extension
1551 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1552 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1553 break;
1554
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 // GL_KHR_debug
1556 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001557 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001560 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001561 break;
1562 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001563 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 break;
1565 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001566 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001568
Martin Radeve5285d22017-07-14 16:23:53 +03001569 // GL_ANGLE_multiview
1570 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001571 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001572 break;
1573
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 // GL_EXT_disjoint_timer_query
1575 case GL_GPU_DISJOINT_EXT:
1576 *params = mImplementation->getGPUDisjoint();
1577 break;
1578 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001579 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001580 break;
1581 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001582 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 break;
1584 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001585 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001586 break;
1587 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001588 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 break;
1590 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001591 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 break;
1593 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001594 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001595 break;
1596 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001597 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001598 break;
1599 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001600 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001601 break;
1602 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001603 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 break;
1605 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001606 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001609 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001610 break;
1611 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001612 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 break;
1614 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001615 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 break;
1617 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001618 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001619 break;
1620 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001621 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 break;
1623 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001624 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 break;
1626 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001627 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 break;
1629 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001630 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001631 break;
1632 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001633 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001634 break;
1635 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001636 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001637 break;
1638 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001639 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001640 break;
1641 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001642 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001643 break;
1644 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001645 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 break;
1647 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001648 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001651 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001654 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001657 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001660 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001663 *params = static_cast<GLint>(
1664 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001667 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001670 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 break;
1672 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001673 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 break;
1675 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001676 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001677 break;
1678 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001679 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 break;
1681 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001682 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 break;
1684 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001685 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001686 break;
1687 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001688 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001689 break;
1690 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001691 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 break;
1693 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001694 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001695 break;
1696 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001697 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001698 break;
1699 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001700 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001702
1703 // GL_EXT_geometry_shader
1704 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001705 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001706 break;
1707 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001708 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001709 break;
1710 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001711 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001712 break;
1713 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001714 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001715 break;
1716 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001717 *params = static_cast<GLint>(
1718 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001719 break;
1720 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001721 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001722 break;
1723 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001724 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001725 break;
1726 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001727 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001728 break;
1729 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001730 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001731 break;
1732 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001733 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001734 break;
1735 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001736 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001737 break;
1738 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001739 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001740 break;
1741 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001742 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001743 break;
1744 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001745 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001746 break;
1747 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001748 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001749 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001750 // GLES1 emulation: Caps queries
1751 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001752 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001753 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001754 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001755 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001756 break;
1757 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001758 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001759 break;
1760 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001761 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001762 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001763 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001764 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001765 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001766 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001767 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001768 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001769 // GLES1 emulation: Vertex attribute queries
1770 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1771 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1772 case GL_COLOR_ARRAY_BUFFER_BINDING:
1773 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1774 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1775 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1776 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1777 break;
1778 case GL_VERTEX_ARRAY_STRIDE:
1779 case GL_NORMAL_ARRAY_STRIDE:
1780 case GL_COLOR_ARRAY_STRIDE:
1781 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1782 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1783 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1784 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1785 break;
1786 case GL_VERTEX_ARRAY_SIZE:
1787 case GL_COLOR_ARRAY_SIZE:
1788 case GL_TEXTURE_COORD_ARRAY_SIZE:
1789 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1790 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1791 break;
1792 case GL_VERTEX_ARRAY_TYPE:
1793 case GL_COLOR_ARRAY_TYPE:
1794 case GL_NORMAL_ARRAY_TYPE:
1795 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1796 case GL_TEXTURE_COORD_ARRAY_TYPE:
1797 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1798 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1799 break;
1800
jchen1082af6202018-06-22 10:59:52 +08001801 // GL_KHR_parallel_shader_compile
1802 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001803 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001804 break;
1805
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001806 // GL_EXT_blend_func_extended
1807 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001808 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001809 break;
1810
Jamie Madill231c7f52017-04-26 13:45:37 -04001811 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001812 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001813 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001814 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001815}
1816
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001817void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001818{
Shannon Woods53a94a82014-06-24 15:20:36 -04001819 // Queries about context capabilities and maximums are answered by Context.
1820 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001821 switch (pname)
1822 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001824 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 break;
1826 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001827 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001828 break;
1829 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001830 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001831 break;
1832 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001833 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001834 break;
1835 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001836 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001837 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001838
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 // GL_EXT_disjoint_timer_query
1840 case GL_TIMESTAMP_EXT:
1841 *params = mImplementation->getTimestamp();
1842 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001843
Jamie Madill231c7f52017-04-26 13:45:37 -04001844 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001845 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001846 break;
1847 default:
1848 UNREACHABLE();
1849 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001850 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001851}
1852
Geoff Lang70d0f492015-12-10 17:45:46 -05001853void Context::getPointerv(GLenum pname, void **params) const
1854{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001855 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001856}
1857
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001858void Context::getPointervRobustANGLERobust(GLenum pname,
1859 GLsizei bufSize,
1860 GLsizei *length,
1861 void **params)
1862{
1863 UNIMPLEMENTED();
1864}
1865
Martin Radev66fb8202016-07-28 11:45:20 +03001866void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001867{
Shannon Woods53a94a82014-06-24 15:20:36 -04001868 // Queries about context capabilities and maximums are answered by Context.
1869 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001870
1871 GLenum nativeType;
1872 unsigned int numParams;
1873 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1874 ASSERT(queryStatus);
1875
1876 if (nativeType == GL_INT)
1877 {
1878 switch (target)
1879 {
1880 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1881 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001882 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001883 break;
1884 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1885 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001886 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001887 break;
1888 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001889 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001890 }
1891 }
1892 else
1893 {
1894 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1895 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001896}
1897
Brandon Jones59770802018-04-02 13:18:42 -07001898void Context::getIntegeri_vRobust(GLenum target,
1899 GLuint index,
1900 GLsizei bufSize,
1901 GLsizei *length,
1902 GLint *data)
1903{
1904 getIntegeri_v(target, index, data);
1905}
1906
Martin Radev66fb8202016-07-28 11:45:20 +03001907void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001908{
Shannon Woods53a94a82014-06-24 15:20:36 -04001909 // Queries about context capabilities and maximums are answered by Context.
1910 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001911
1912 GLenum nativeType;
1913 unsigned int numParams;
1914 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1915 ASSERT(queryStatus);
1916
1917 if (nativeType == GL_INT_64_ANGLEX)
1918 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001919 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001920 }
1921 else
1922 {
1923 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1924 }
1925}
1926
Brandon Jones59770802018-04-02 13:18:42 -07001927void Context::getInteger64i_vRobust(GLenum target,
1928 GLuint index,
1929 GLsizei bufSize,
1930 GLsizei *length,
1931 GLint64 *data)
1932{
1933 getInteger64i_v(target, index, data);
1934}
1935
Martin Radev66fb8202016-07-28 11:45:20 +03001936void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1937{
1938 // Queries about context capabilities and maximums are answered by Context.
1939 // Queries about current GL state values are answered by State.
1940
1941 GLenum nativeType;
1942 unsigned int numParams;
1943 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1944 ASSERT(queryStatus);
1945
1946 if (nativeType == GL_BOOL)
1947 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001948 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001949 }
1950 else
1951 {
1952 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1953 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001954}
1955
Brandon Jones59770802018-04-02 13:18:42 -07001956void Context::getBooleani_vRobust(GLenum target,
1957 GLuint index,
1958 GLsizei bufSize,
1959 GLsizei *length,
1960 GLboolean *data)
1961{
1962 getBooleani_v(target, index, data);
1963}
1964
Corentin Wallez336129f2017-10-17 15:55:40 -04001965void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001966{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001967 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001968 QueryBufferParameteriv(buffer, pname, params);
1969}
1970
Brandon Jones59770802018-04-02 13:18:42 -07001971void Context::getBufferParameterivRobust(BufferBinding target,
1972 GLenum pname,
1973 GLsizei bufSize,
1974 GLsizei *length,
1975 GLint *params)
1976{
1977 getBufferParameteriv(target, pname, params);
1978}
1979
He Yunchao010e4db2017-03-03 14:22:06 +08001980void Context::getFramebufferAttachmentParameteriv(GLenum target,
1981 GLenum attachment,
1982 GLenum pname,
1983 GLint *params)
1984{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001985 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001986 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001987}
1988
Brandon Jones59770802018-04-02 13:18:42 -07001989void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1990 GLenum attachment,
1991 GLenum pname,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLint *params)
1995{
1996 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1997}
1998
He Yunchao010e4db2017-03-03 14:22:06 +08001999void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2000{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002001 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08002002 QueryRenderbufferiv(this, renderbuffer, pname, params);
2003}
2004
Brandon Jones59770802018-04-02 13:18:42 -07002005void Context::getRenderbufferParameterivRobust(GLenum target,
2006 GLenum pname,
2007 GLsizei bufSize,
2008 GLsizei *length,
2009 GLint *params)
2010{
2011 getRenderbufferParameteriv(target, pname, params);
2012}
2013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002014void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002015{
Till Rathmannb8543632018-10-02 19:46:14 +02002016 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002017 QueryTexParameterfv(texture, pname, params);
2018}
2019
Brandon Jones59770802018-04-02 13:18:42 -07002020void Context::getTexParameterfvRobust(TextureType target,
2021 GLenum pname,
2022 GLsizei bufSize,
2023 GLsizei *length,
2024 GLfloat *params)
2025{
2026 getTexParameterfv(target, pname, params);
2027}
2028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002029void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002030{
Till Rathmannb8543632018-10-02 19:46:14 +02002031 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002032 QueryTexParameteriv(texture, pname, params);
2033}
Jiajia Qin5451d532017-11-16 17:16:34 +08002034
Till Rathmannb8543632018-10-02 19:46:14 +02002035void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2036{
2037 const Texture *const texture = getTargetTexture(target);
2038 QueryTexParameterIiv(texture, pname, params);
2039}
2040
2041void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2042{
2043 const Texture *const texture = getTargetTexture(target);
2044 QueryTexParameterIuiv(texture, pname, params);
2045}
2046
Brandon Jones59770802018-04-02 13:18:42 -07002047void Context::getTexParameterivRobust(TextureType target,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 GLsizei *length,
2051 GLint *params)
2052{
2053 getTexParameteriv(target, pname, params);
2054}
2055
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002056void Context::getTexParameterIivRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLint *params)
2061{
2062 UNIMPLEMENTED();
2063}
2064
2065void Context::getTexParameterIuivRobust(TextureType target,
2066 GLenum pname,
2067 GLsizei bufSize,
2068 GLsizei *length,
2069 GLuint *params)
2070{
2071 UNIMPLEMENTED();
2072}
2073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002074void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002075{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002076 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002077 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002078}
2079
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002080void Context::getTexLevelParameterivRobust(TextureTarget target,
2081 GLint level,
2082 GLenum pname,
2083 GLsizei bufSize,
2084 GLsizei *length,
2085 GLint *params)
2086{
2087 UNIMPLEMENTED();
2088}
2089
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002090void Context::getTexLevelParameterfv(TextureTarget target,
2091 GLint level,
2092 GLenum pname,
2093 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002094{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002095 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002096 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002097}
2098
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002099void Context::getTexLevelParameterfvRobust(TextureTarget target,
2100 GLint level,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 GLsizei *length,
2104 GLfloat *params)
2105{
2106 UNIMPLEMENTED();
2107}
2108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002109void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002110{
Till Rathmannb8543632018-10-02 19:46:14 +02002111 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002112 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002113}
2114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002116{
Till Rathmannb8543632018-10-02 19:46:14 +02002117 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002118 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002119}
2120
Brandon Jones59770802018-04-02 13:18:42 -07002121void Context::texParameterfvRobust(TextureType target,
2122 GLenum pname,
2123 GLsizei bufSize,
2124 const GLfloat *params)
2125{
2126 texParameterfv(target, pname, params);
2127}
2128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002129void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002130{
Till Rathmannb8543632018-10-02 19:46:14 +02002131 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002132 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002133}
2134
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002135void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002136{
Till Rathmannb8543632018-10-02 19:46:14 +02002137 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002138 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002139}
2140
Till Rathmannb8543632018-10-02 19:46:14 +02002141void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2142{
2143 Texture *const texture = getTargetTexture(target);
2144 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002145}
2146
2147void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2148{
2149 Texture *const texture = getTargetTexture(target);
2150 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002151}
2152
Brandon Jones59770802018-04-02 13:18:42 -07002153void Context::texParameterivRobust(TextureType target,
2154 GLenum pname,
2155 GLsizei bufSize,
2156 const GLint *params)
2157{
2158 texParameteriv(target, pname, params);
2159}
2160
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002161void Context::texParameterIivRobust(TextureType target,
2162 GLenum pname,
2163 GLsizei bufSize,
2164 const GLint *params)
2165{
2166 UNIMPLEMENTED();
2167}
2168
2169void Context::texParameterIuivRobust(TextureType target,
2170 GLenum pname,
2171 GLsizei bufSize,
2172 const GLuint *params)
2173{
2174 UNIMPLEMENTED();
2175}
2176
Jamie Madill493f9572018-05-24 19:52:15 -04002177void Context::drawArraysInstanced(PrimitiveMode mode,
2178 GLint first,
2179 GLsizei count,
2180 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002181{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002182 // No-op if count draws no primitives for given mode
2183 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002184 {
2185 return;
2186 }
2187
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002188 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002189 ANGLE_CONTEXT_TRY(
2190 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002191 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002192}
2193
Jamie Madill493f9572018-05-24 19:52:15 -04002194void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002195 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002196 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002197 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002198 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002199{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002200 // No-op if count draws no primitives for given mode
2201 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002202 {
2203 return;
2204 }
2205
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002206 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002207 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002208 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002209}
2210
Jamie Madill493f9572018-05-24 19:52:15 -04002211void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002212 GLuint start,
2213 GLuint end,
2214 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002215 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002216 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002217{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002218 // No-op if count draws no primitives for given mode
2219 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002220 {
2221 return;
2222 }
2223
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002224 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002225 ANGLE_CONTEXT_TRY(
2226 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227}
2228
Jamie Madill493f9572018-05-24 19:52:15 -04002229void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002230{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002231 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002232 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002233}
2234
Jamie Madill8dc27f92018-11-29 11:45:44 -05002235void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002236{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002237 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002238 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002239}
2240
Jamie Madill675fe712016-12-19 13:07:54 -05002241void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002243 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002244}
2245
Jamie Madill675fe712016-12-19 13:07:54 -05002246void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002247{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002248 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002249}
2250
Austin Kinross6ee1e782015-05-29 17:05:37 -07002251void Context::insertEventMarker(GLsizei length, const char *marker)
2252{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002253 ASSERT(mImplementation);
2254 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002255}
2256
2257void Context::pushGroupMarker(GLsizei length, const char *marker)
2258{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002259 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002260
2261 if (marker == nullptr)
2262 {
2263 // From the EXT_debug_marker spec,
2264 // "If <marker> is null then an empty string is pushed on the stack."
2265 mImplementation->pushGroupMarker(length, "");
2266 }
2267 else
2268 {
2269 mImplementation->pushGroupMarker(length, marker);
2270 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002271}
2272
2273void Context::popGroupMarker()
2274{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002275 ASSERT(mImplementation);
2276 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002277}
2278
Geoff Langd8605522016-04-13 10:19:12 -04002279void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2280{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002281 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002282 ASSERT(programObject);
2283
2284 programObject->bindUniformLocation(location, name);
2285}
2286
Brandon Jones59770802018-04-02 13:18:42 -07002287void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002288{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002289 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002290}
2291
Brandon Jones59770802018-04-02 13:18:42 -07002292void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002293{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002294 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002295}
2296
Brandon Jones59770802018-04-02 13:18:42 -07002297void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002298{
2299 GLfloat I[16];
2300 angle::Matrix<GLfloat>::setToIdentity(I);
2301
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002302 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002303}
2304
2305void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2306{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002307 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002308 if (!pathObj)
2309 return;
2310
Geoff Lang9bf86f02018-07-26 11:46:34 -04002311 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002312
2313 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2314}
2315
2316void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2317{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002318 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002319 if (!pathObj)
2320 return;
2321
Geoff Lang9bf86f02018-07-26 11:46:34 -04002322 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002323
2324 mImplementation->stencilStrokePath(pathObj, reference, mask);
2325}
2326
2327void Context::coverFillPath(GLuint path, GLenum coverMode)
2328{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002329 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002330 if (!pathObj)
2331 return;
2332
Geoff Lang9bf86f02018-07-26 11:46:34 -04002333 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002334
2335 mImplementation->coverFillPath(pathObj, coverMode);
2336}
2337
2338void Context::coverStrokePath(GLuint path, GLenum coverMode)
2339{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002340 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002341 if (!pathObj)
2342 return;
2343
Geoff Lang9bf86f02018-07-26 11:46:34 -04002344 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002345
2346 mImplementation->coverStrokePath(pathObj, coverMode);
2347}
2348
2349void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2350{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002351 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352 if (!pathObj)
2353 return;
2354
Geoff Lang9bf86f02018-07-26 11:46:34 -04002355 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002356
2357 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2358}
2359
2360void Context::stencilThenCoverStrokePath(GLuint path,
2361 GLint reference,
2362 GLuint mask,
2363 GLenum coverMode)
2364{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002365 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002366 if (!pathObj)
2367 return;
2368
Geoff Lang9bf86f02018-07-26 11:46:34 -04002369 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370
2371 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2372}
2373
Sami Väisänend59ca052016-06-21 16:10:00 +03002374void Context::coverFillPathInstanced(GLsizei numPaths,
2375 GLenum pathNameType,
2376 const void *paths,
2377 GLuint pathBase,
2378 GLenum coverMode,
2379 GLenum transformType,
2380 const GLfloat *transformValues)
2381{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002382 const auto &pathObjects =
2383 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002384
Geoff Lang9bf86f02018-07-26 11:46:34 -04002385 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002386
2387 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2388}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002389
Sami Väisänend59ca052016-06-21 16:10:00 +03002390void Context::coverStrokePathInstanced(GLsizei numPaths,
2391 GLenum pathNameType,
2392 const void *paths,
2393 GLuint pathBase,
2394 GLenum coverMode,
2395 GLenum transformType,
2396 const GLfloat *transformValues)
2397{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002398 const auto &pathObjects =
2399 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002400
2401 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002402 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002403
2404 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2405 transformValues);
2406}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002407
Sami Väisänend59ca052016-06-21 16:10:00 +03002408void Context::stencilFillPathInstanced(GLsizei numPaths,
2409 GLenum pathNameType,
2410 const void *paths,
2411 GLuint pathBase,
2412 GLenum fillMode,
2413 GLuint mask,
2414 GLenum transformType,
2415 const GLfloat *transformValues)
2416{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002417 const auto &pathObjects =
2418 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002419
2420 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002421 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002422
2423 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2424 transformValues);
2425}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002426
Sami Väisänend59ca052016-06-21 16:10:00 +03002427void Context::stencilStrokePathInstanced(GLsizei numPaths,
2428 GLenum pathNameType,
2429 const void *paths,
2430 GLuint pathBase,
2431 GLint reference,
2432 GLuint mask,
2433 GLenum transformType,
2434 const GLfloat *transformValues)
2435{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002436 const auto &pathObjects =
2437 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002438
Geoff Lang9bf86f02018-07-26 11:46:34 -04002439 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002440
2441 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2442 transformValues);
2443}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002444
Sami Väisänend59ca052016-06-21 16:10:00 +03002445void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2446 GLenum pathNameType,
2447 const void *paths,
2448 GLuint pathBase,
2449 GLenum fillMode,
2450 GLuint mask,
2451 GLenum coverMode,
2452 GLenum transformType,
2453 const GLfloat *transformValues)
2454{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002455 const auto &pathObjects =
2456 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002457
Geoff Lang9bf86f02018-07-26 11:46:34 -04002458 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
2460 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2461 transformType, transformValues);
2462}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002463
Sami Väisänend59ca052016-06-21 16:10:00 +03002464void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2465 GLenum pathNameType,
2466 const void *paths,
2467 GLuint pathBase,
2468 GLint reference,
2469 GLuint mask,
2470 GLenum coverMode,
2471 GLenum transformType,
2472 const GLfloat *transformValues)
2473{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002474 const auto &pathObjects =
2475 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
Geoff Lang9bf86f02018-07-26 11:46:34 -04002477 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
2479 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2480 transformType, transformValues);
2481}
2482
Sami Väisänen46eaa942016-06-29 10:26:37 +03002483void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2484{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002485 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002486
2487 programObject->bindFragmentInputLocation(location, name);
2488}
2489
2490void Context::programPathFragmentInputGen(GLuint program,
2491 GLint location,
2492 GLenum genMode,
2493 GLint components,
2494 const GLfloat *coeffs)
2495{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002496 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002497
jchen103fd614d2018-08-13 12:21:58 +08002498 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002499}
2500
jchen1015015f72017-03-16 13:54:21 +08002501GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2502{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002503 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002504 return QueryProgramResourceIndex(programObject, programInterface, name);
2505}
2506
jchen10fd7c3b52017-03-21 15:36:03 +08002507void Context::getProgramResourceName(GLuint program,
2508 GLenum programInterface,
2509 GLuint index,
2510 GLsizei bufSize,
2511 GLsizei *length,
2512 GLchar *name)
2513{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002514 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002515 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2516}
2517
jchen10191381f2017-04-11 13:59:04 +08002518GLint Context::getProgramResourceLocation(GLuint program,
2519 GLenum programInterface,
2520 const GLchar *name)
2521{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002522 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002523 return QueryProgramResourceLocation(programObject, programInterface, name);
2524}
2525
jchen10880683b2017-04-12 16:21:55 +08002526void Context::getProgramResourceiv(GLuint program,
2527 GLenum programInterface,
2528 GLuint index,
2529 GLsizei propCount,
2530 const GLenum *props,
2531 GLsizei bufSize,
2532 GLsizei *length,
2533 GLint *params)
2534{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002535 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002536 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2537 length, params);
2538}
2539
jchen10d9cd7b72017-08-30 15:04:25 +08002540void Context::getProgramInterfaceiv(GLuint program,
2541 GLenum programInterface,
2542 GLenum pname,
2543 GLint *params)
2544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002545 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002546 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2547}
2548
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002549void Context::getProgramInterfaceivRobust(GLuint program,
2550 GLenum programInterface,
2551 GLenum pname,
2552 GLsizei bufSize,
2553 GLsizei *length,
2554 GLint *params)
2555{
2556 UNIMPLEMENTED();
2557}
2558
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002559void Context::handleError(GLenum errorCode,
2560 const char *message,
2561 const char *file,
2562 const char *function,
2563 unsigned int line)
2564{
2565 mErrors.handleError(errorCode, message, file, function, line);
2566}
2567
Jamie Madilla139f012018-10-10 16:13:03 -04002568void Context::validationError(GLenum errorCode, const char *message)
2569{
2570 mErrors.validationError(errorCode, message);
2571}
2572
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002573// Get one of the recorded errors and clear its flag, if any.
2574// [OpenGL ES 2.0.24] section 2.5 page 13.
2575GLenum Context::getError()
2576{
Geoff Langda5777c2014-07-11 09:52:58 -04002577 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002578 {
Geoff Langda5777c2014-07-11 09:52:58 -04002579 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580 }
Geoff Langda5777c2014-07-11 09:52:58 -04002581 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002582 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002583 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585}
2586
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002587// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002588void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002589{
2590 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002591 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002592 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002593 mContextLostForced = true;
2594 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002595 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002596}
2597
Jamie Madillfa920eb2018-01-04 11:45:50 -05002598GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002599{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002600 // Even if the application doesn't want to know about resets, we want to know
2601 // as it will allow us to skip all the calls.
2602 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002604 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002605 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002606 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002607 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608
2609 // EXT_robustness, section 2.6: If the reset notification behavior is
2610 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2611 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2612 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613 }
2614
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2616 // status should be returned at least once, and GL_NO_ERROR should be returned
2617 // once the device has finished resetting.
2618 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 ASSERT(mResetStatus == GL_NO_ERROR);
2621 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002622
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002623 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002625 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002626 }
2627 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002628 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002629 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002630 // If markContextLost was used to mark the context lost then
2631 // assume that is not recoverable, and continue to report the
2632 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 mResetStatus = mImplementation->getResetStatus();
2634 }
Jamie Madill893ab082014-05-16 16:56:10 -04002635
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637}
2638
2639bool Context::isResetNotificationEnabled()
2640{
2641 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2642}
2643
Corentin Walleze3b10e82015-05-20 11:06:25 -04002644const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002645{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002646 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002647}
2648
2649EGLenum Context::getClientType() const
2650{
2651 return mClientType;
2652}
2653
2654EGLenum Context::getRenderBuffer() const
2655{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002656 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002657 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002658 {
2659 return EGL_NONE;
2660 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002661
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002662 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002663 ASSERT(backAttachment != nullptr);
2664 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002665}
2666
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002667VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002668{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002669 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002670 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2671 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002672 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002673 vertexArray =
2674 new VertexArray(mImplementation.get(), vertexArrayHandle,
2675 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676
Jamie Madill96a483b2017-06-27 16:49:21 -04002677 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002678 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002679
2680 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002681}
2682
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002683TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002684{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002685 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2687 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002688 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002689 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002690 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002691 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002692 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002693 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002694
2695 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002696}
2697
2698bool Context::isVertexArrayGenerated(GLuint vertexArray)
2699{
Jamie Madill96a483b2017-06-27 16:49:21 -04002700 ASSERT(mVertexArrayMap.contains(0));
2701 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002702}
2703
2704bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2705{
Jamie Madill96a483b2017-06-27 16:49:21 -04002706 ASSERT(mTransformFeedbackMap.contains(0));
2707 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002708}
2709
Shannon Woods53a94a82014-06-24 15:20:36 -04002710void Context::detachTexture(GLuint texture)
2711{
2712 // Simple pass-through to State's detachTexture method, as textures do not require
2713 // allocation map management either here or in the resource manager at detach time.
2714 // Zero textures are held by the Context, and we don't attempt to request them from
2715 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002716 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002717}
2718
James Darpinian4d9d4832018-03-13 12:43:28 -07002719void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002720{
Yuly Novikov5807a532015-12-03 13:01:22 -05002721 // Simple pass-through to State's detachBuffer method, since
2722 // only buffer attachments to container objects that are bound to the current context
2723 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002724
Yuly Novikov5807a532015-12-03 13:01:22 -05002725 // [OpenGL ES 3.2] section 5.1.2 page 45:
2726 // Attachments to unbound container objects, such as
2727 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2728 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002729 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730}
2731
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732void Context::detachFramebuffer(GLuint framebuffer)
2733{
Shannon Woods53a94a82014-06-24 15:20:36 -04002734 // Framebuffer detachment is handled by Context, because 0 is a valid
2735 // Framebuffer object, and a pointer to it must be passed from Context
2736 // to State at binding time.
2737
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002738 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002739 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2740 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2741 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002742
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002743 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744 {
2745 bindReadFramebuffer(0);
2746 }
2747
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002748 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749 {
2750 bindDrawFramebuffer(0);
2751 }
2752}
2753
2754void Context::detachRenderbuffer(GLuint renderbuffer)
2755{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002756 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002757}
2758
Jamie Madill57a89722013-07-02 11:57:03 -04002759void Context::detachVertexArray(GLuint vertexArray)
2760{
Jamie Madill77a72f62015-04-14 11:18:32 -04002761 // Vertex array detachment is handled by Context, because 0 is a valid
2762 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002763 // binding time.
2764
Jamie Madill57a89722013-07-02 11:57:03 -04002765 // [OpenGL ES 3.0.2] section 2.10 page 43:
2766 // If a vertex array object that is currently bound is deleted, the binding
2767 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002768 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002769 {
2770 bindVertexArray(0);
2771 }
2772}
2773
Geoff Langc8058452014-02-03 12:04:11 -05002774void Context::detachTransformFeedback(GLuint transformFeedback)
2775{
Corentin Walleza2257da2016-04-19 16:43:12 -04002776 // Transform feedback detachment is handled by Context, because 0 is a valid
2777 // transform feedback, and a pointer to it must be passed from Context to State at
2778 // binding time.
2779
2780 // The OpenGL specification doesn't mention what should happen when the currently bound
2781 // transform feedback object is deleted. Since it is a container object, we treat it like
2782 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002783 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002784 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002785 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002786 }
Geoff Langc8058452014-02-03 12:04:11 -05002787}
2788
Jamie Madilldc356042013-07-19 16:36:57 -04002789void Context::detachSampler(GLuint sampler)
2790{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002791 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002792}
2793
Yunchao Hea336b902017-08-02 16:05:21 +08002794void Context::detachProgramPipeline(GLuint pipeline)
2795{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002796 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002797}
2798
Jamie Madill3ef140a2017-08-26 23:11:21 -04002799void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002801 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002802 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803}
2804
Jamie Madille29d1672013-07-19 16:36:57 -04002805void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2806{
Till Rathmannb8543632018-10-02 19:46:14 +02002807 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002808 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002809 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002810}
Jamie Madille29d1672013-07-19 16:36:57 -04002811
Geoff Langc1984ed2016-10-07 12:41:00 -04002812void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2813{
Till Rathmannb8543632018-10-02 19:46:14 +02002814 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002815 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002816 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002817}
2818
Till Rathmannb8543632018-10-02 19:46:14 +02002819void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2820{
2821 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002822 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002823 SetSamplerParameterIiv(this, samplerObject, pname, param);
2824}
2825
2826void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2827{
2828 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002829 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002830 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2831}
2832
Brandon Jones59770802018-04-02 13:18:42 -07002833void Context::samplerParameterivRobust(GLuint sampler,
2834 GLenum pname,
2835 GLsizei bufSize,
2836 const GLint *param)
2837{
2838 samplerParameteriv(sampler, pname, param);
2839}
2840
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002841void Context::samplerParameterIivRobust(GLuint sampler,
2842 GLenum pname,
2843 GLsizei bufSize,
2844 const GLint *param)
2845{
2846 UNIMPLEMENTED();
2847}
2848
2849void Context::samplerParameterIuivRobust(GLuint sampler,
2850 GLenum pname,
2851 GLsizei bufSize,
2852 const GLuint *param)
2853{
2854 UNIMPLEMENTED();
2855}
2856
Jamie Madille29d1672013-07-19 16:36:57 -04002857void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2858{
Till Rathmannb8543632018-10-02 19:46:14 +02002859 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002860 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002861 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002862}
2863
Geoff Langc1984ed2016-10-07 12:41:00 -04002864void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002865{
Till Rathmannb8543632018-10-02 19:46:14 +02002866 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002867 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002868 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002869}
2870
Brandon Jones59770802018-04-02 13:18:42 -07002871void Context::samplerParameterfvRobust(GLuint sampler,
2872 GLenum pname,
2873 GLsizei bufSize,
2874 const GLfloat *param)
2875{
2876 samplerParameterfv(sampler, pname, param);
2877}
2878
Geoff Langc1984ed2016-10-07 12:41:00 -04002879void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002880{
Till Rathmannb8543632018-10-02 19:46:14 +02002881 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002882 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002883 QuerySamplerParameteriv(samplerObject, pname, params);
2884}
Jamie Madill9675b802013-07-19 16:36:59 -04002885
Till Rathmannb8543632018-10-02 19:46:14 +02002886void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2887{
2888 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002889 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002890 QuerySamplerParameterIiv(samplerObject, pname, params);
2891}
2892
2893void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2894{
2895 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002896 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002897 QuerySamplerParameterIuiv(samplerObject, pname, params);
2898}
2899
Brandon Jones59770802018-04-02 13:18:42 -07002900void Context::getSamplerParameterivRobust(GLuint sampler,
2901 GLenum pname,
2902 GLsizei bufSize,
2903 GLsizei *length,
2904 GLint *params)
2905{
2906 getSamplerParameteriv(sampler, pname, params);
2907}
2908
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002909void Context::getSamplerParameterIivRobust(GLuint sampler,
2910 GLenum pname,
2911 GLsizei bufSize,
2912 GLsizei *length,
2913 GLint *params)
2914{
2915 UNIMPLEMENTED();
2916}
2917
2918void Context::getSamplerParameterIuivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLuint *params)
2923{
2924 UNIMPLEMENTED();
2925}
2926
Geoff Langc1984ed2016-10-07 12:41:00 -04002927void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2928{
Till Rathmannb8543632018-10-02 19:46:14 +02002929 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002930 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002931 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002932}
2933
Brandon Jones59770802018-04-02 13:18:42 -07002934void Context::getSamplerParameterfvRobust(GLuint sampler,
2935 GLenum pname,
2936 GLsizei bufSize,
2937 GLsizei *length,
2938 GLfloat *params)
2939{
2940 getSamplerParameterfv(sampler, pname, params);
2941}
2942
Olli Etuahof0fee072016-03-30 15:11:58 +03002943void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2944{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002945 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002946 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002947}
2948
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002949void Context::initRendererString()
2950{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002951 std::ostringstream rendererString;
2952 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002953 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002954 rendererString << ")";
2955
Geoff Langcec35902014-04-16 10:52:36 -04002956 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002957}
2958
Geoff Langc339c4e2016-11-29 10:37:36 -05002959void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002960{
Geoff Langc339c4e2016-11-29 10:37:36 -05002961 const Version &clientVersion = getClientVersion();
2962
2963 std::ostringstream versionString;
2964 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2965 << ANGLE_VERSION_STRING << ")";
2966 mVersionString = MakeStaticString(versionString.str());
2967
2968 std::ostringstream shadingLanguageVersionString;
2969 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2970 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2971 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2972 << ")";
2973 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002974}
2975
Geoff Langcec35902014-04-16 10:52:36 -04002976void Context::initExtensionStrings()
2977{
Geoff Langc339c4e2016-11-29 10:37:36 -05002978 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2979 std::ostringstream combinedStringStream;
2980 std::copy(strings.begin(), strings.end(),
2981 std::ostream_iterator<const char *>(combinedStringStream, " "));
2982 return MakeStaticString(combinedStringStream.str());
2983 };
2984
2985 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002986 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002987 {
2988 mExtensionStrings.push_back(MakeStaticString(extensionString));
2989 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002990 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002991
Geoff Langc339c4e2016-11-29 10:37:36 -05002992 mRequestableExtensionStrings.clear();
2993 for (const auto &extensionInfo : GetExtensionInfoMap())
2994 {
2995 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002996 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002997 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002998 {
2999 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3000 }
3001 }
3002 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003003}
3004
Geoff Langc339c4e2016-11-29 10:37:36 -05003005const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003006{
Geoff Langc339c4e2016-11-29 10:37:36 -05003007 switch (name)
3008 {
3009 case GL_VENDOR:
3010 return reinterpret_cast<const GLubyte *>("Google Inc.");
3011
3012 case GL_RENDERER:
3013 return reinterpret_cast<const GLubyte *>(mRendererString);
3014
3015 case GL_VERSION:
3016 return reinterpret_cast<const GLubyte *>(mVersionString);
3017
3018 case GL_SHADING_LANGUAGE_VERSION:
3019 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3020
3021 case GL_EXTENSIONS:
3022 return reinterpret_cast<const GLubyte *>(mExtensionString);
3023
3024 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3025 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3026
3027 default:
3028 UNREACHABLE();
3029 return nullptr;
3030 }
Geoff Langcec35902014-04-16 10:52:36 -04003031}
3032
Geoff Langc339c4e2016-11-29 10:37:36 -05003033const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003034{
Geoff Langc339c4e2016-11-29 10:37:36 -05003035 switch (name)
3036 {
3037 case GL_EXTENSIONS:
3038 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3039
3040 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3041 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3042
3043 default:
3044 UNREACHABLE();
3045 return nullptr;
3046 }
Geoff Langcec35902014-04-16 10:52:36 -04003047}
3048
3049size_t Context::getExtensionStringCount() const
3050{
3051 return mExtensionStrings.size();
3052}
3053
Geoff Lang111a99e2017-10-17 10:58:41 -04003054bool Context::isExtensionRequestable(const char *name)
3055{
3056 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3057 auto extension = extensionInfos.find(name);
3058
Geoff Lang111a99e2017-10-17 10:58:41 -04003059 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003060 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003061}
3062
Geoff Langc339c4e2016-11-29 10:37:36 -05003063void Context::requestExtension(const char *name)
3064{
3065 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3066 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3067 const auto &extension = extensionInfos.at(name);
3068 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003069 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003070
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003071 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003072 {
3073 // Extension already enabled
3074 return;
3075 }
3076
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003077 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003078 updateCaps();
3079 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003080
Jamie Madill2f348d22017-06-05 10:50:59 -04003081 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3082 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003083
Jamie Madill81c2e252017-09-09 23:32:46 -04003084 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3085 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003086 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003087 for (auto &zeroTexture : mZeroTextures)
3088 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003089 if (zeroTexture.get() != nullptr)
3090 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003091 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003092 }
Geoff Lang9aded172017-04-05 11:07:56 -04003093 }
3094
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003095 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003096}
3097
3098size_t Context::getRequestableExtensionStringCount() const
3099{
3100 return mRequestableExtensionStrings.size();
3101}
3102
Jamie Madill493f9572018-05-24 19:52:15 -04003103void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003104{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003105 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003106 ASSERT(transformFeedback != nullptr);
3107 ASSERT(!transformFeedback->isPaused());
3108
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003109 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003110 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003111}
3112
3113bool Context::hasActiveTransformFeedback(GLuint program) const
3114{
3115 for (auto pair : mTransformFeedbackMap)
3116 {
3117 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3118 {
3119 return true;
3120 }
3121 }
3122 return false;
3123}
3124
Geoff Lang33f11fb2018-05-07 13:42:47 -04003125Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003126{
3127 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3128
jchen1082af6202018-06-22 10:59:52 +08003129 // Explicitly enable GL_KHR_parallel_shader_compile
3130 supportedExtensions.parallelShaderCompile = true;
3131
Geoff Langb0f917f2017-12-05 13:41:54 -05003132 if (getClientVersion() < ES_2_0)
3133 {
3134 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003135 supportedExtensions.pointSizeArray = true;
3136 supportedExtensions.textureCubeMap = true;
3137 supportedExtensions.pointSprite = true;
3138 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003139 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003140 }
3141
3142 if (getClientVersion() < ES_3_0)
3143 {
3144 // Disable ES3+ extensions
3145 supportedExtensions.colorBufferFloat = false;
3146 supportedExtensions.eglImageExternalEssl3 = false;
3147 supportedExtensions.textureNorm16 = false;
3148 supportedExtensions.multiview = false;
3149 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003150 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003151 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003152
3153 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3154 if (!supportedExtensions.sRGB)
3155 {
3156 supportedExtensions.textureSRGBDecode = false;
3157 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003158 }
3159
3160 if (getClientVersion() < ES_3_1)
3161 {
3162 // Disable ES3.1+ extensions
3163 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003164
3165 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3166 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003167 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003168 }
3169
3170 if (getClientVersion() > ES_2_0)
3171 {
3172 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3173 // supportedExtensions.sRGB = false;
3174 }
3175
3176 // Some extensions are always available because they are implemented in the GL layer.
3177 supportedExtensions.bindUniformLocation = true;
3178 supportedExtensions.vertexArrayObject = true;
3179 supportedExtensions.bindGeneratesResource = true;
3180 supportedExtensions.clientArrays = true;
3181 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003182 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003183
3184 // Enable the no error extension if the context was created with the flag.
3185 supportedExtensions.noError = mSkipValidation;
3186
3187 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003188 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003189
3190 // Explicitly enable GL_KHR_debug
3191 supportedExtensions.debug = true;
3192 supportedExtensions.maxDebugMessageLength = 1024;
3193 supportedExtensions.maxDebugLoggedMessages = 1024;
3194 supportedExtensions.maxDebugGroupStackDepth = 1024;
3195 supportedExtensions.maxLabelLength = 1024;
3196
3197 // Explicitly enable GL_ANGLE_robust_client_memory
3198 supportedExtensions.robustClientMemory = true;
3199
3200 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003201 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003202
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003203 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3204 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003205 supportedExtensions.robustBufferAccessBehavior =
3206 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3207
3208 // Enable the cache control query unconditionally.
3209 supportedExtensions.programCacheControl = true;
3210
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003211 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003212 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003213 {
3214 // GL_ANGLE_explicit_context_gles1
3215 supportedExtensions.explicitContextGles1 = true;
3216 // GL_ANGLE_explicit_context
3217 supportedExtensions.explicitContext = true;
3218 }
3219
Geoff Lang79b91402018-10-04 15:11:30 -04003220 supportedExtensions.memorySize = true;
3221
Geoff Langb0f917f2017-12-05 13:41:54 -05003222 return supportedExtensions;
3223}
3224
Geoff Lang33f11fb2018-05-07 13:42:47 -04003225void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003226{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003227 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003228
Geoff Lang33f11fb2018-05-07 13:42:47 -04003229 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003230 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003231
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003232 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003233
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003234 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3235 if (getClientVersion() < Version(2, 0))
3236 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003237 mState.mCaps.maxMultitextureUnits = 4;
3238 mState.mCaps.maxClipPlanes = 6;
3239 mState.mCaps.maxLights = 8;
3240 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3241 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3242 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mState.mCaps.minSmoothPointSize = 1.0f;
3244 mState.mCaps.maxSmoothPointSize = 1.0f;
3245 mState.mCaps.minSmoothLineWidth = 1.0f;
3246 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003247 }
3248
Luc Ferronad2ae932018-06-11 15:31:17 -04003249 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003250 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003251
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003252 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003253
Jamie Madill0f80ed82017-09-19 00:24:56 -04003254 if (getClientVersion() < ES_3_1)
3255 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003256 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003257 }
3258 else
3259 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003260 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003261 }
Geoff Lang301d1612014-07-09 10:34:37 -04003262
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003263 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003264 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003265 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003266
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003267 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3268 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003269
3270 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003271 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3272 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003273 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003274 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003276
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003277 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003278
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003279 mState.mCaps.maxSampleMaskWords =
3280 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003281
Geoff Langc287ea62016-09-16 14:46:51 -04003282 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003283 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003284 for (const auto &extensionInfo : GetExtensionInfoMap())
3285 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003286 // If the user has requested that extensions start disabled and they are requestable,
3287 // disable them.
3288 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003289 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003290 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003291 }
3292 }
3293
3294 // Generate texture caps
3295 updateCaps();
3296}
3297
3298void Context::updateCaps()
3299{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003300 mState.mCaps.compressedTextureFormats.clear();
3301 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003302
Jamie Madill7b62cf92017-11-02 15:20:49 -04003303 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003304 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003305 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003306 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003307
Geoff Lang0d8b7242015-09-09 14:56:53 -04003308 // Update the format caps based on the client version and extensions.
3309 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3310 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003311 formatCaps.texturable = formatCaps.texturable &&
3312 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3313 formatCaps.filterable = formatCaps.filterable &&
3314 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003315 formatCaps.textureAttachment =
3316 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003317 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3318 formatCaps.renderbuffer =
3319 formatCaps.renderbuffer &&
3320 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003321
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003322 // OpenGL ES does not support multisampling with non-rendererable formats
3323 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003324 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003325 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003326 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003327 {
Geoff Langd87878e2014-09-19 15:42:59 -04003328 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003329 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003330 else
3331 {
3332 // We may have limited the max samples for some required renderbuffer formats due to
3333 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3334 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3335
3336 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3337 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3338 // exception of signed and unsigned integer formats."
3339 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3340 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3341 {
3342 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003343 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003344 }
3345
3346 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003347 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003348 {
3349 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3350 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3351 // the exception that the signed and unsigned integer formats are required only to
3352 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3353 // multisamples, which must be at least one."
3354 if (formatInfo.componentType == GL_INT ||
3355 formatInfo.componentType == GL_UNSIGNED_INT)
3356 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003357 mState.mCaps.maxIntegerSamples =
3358 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003359 }
3360
3361 // GLES 3.1 section 19.3.1.
3362 if (formatCaps.texturable)
3363 {
3364 if (formatInfo.depthBits > 0)
3365 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003366 mState.mCaps.maxDepthTextureSamples =
3367 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003368 }
3369 else if (formatInfo.redBits > 0)
3370 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003371 mState.mCaps.maxColorTextureSamples =
3372 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003373 }
3374 }
3375 }
3376 }
Geoff Langd87878e2014-09-19 15:42:59 -04003377
3378 if (formatCaps.texturable && formatInfo.compressed)
3379 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003380 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003381 }
3382
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003383 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003384 }
Jamie Madill32447362017-06-28 14:53:52 -04003385
3386 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003387 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003388 {
3389 mMemoryProgramCache = nullptr;
3390 }
Corentin Walleze4477002017-12-01 14:39:58 -05003391
3392 // Compute which buffer types are allowed
3393 mValidBufferBindings.reset();
3394 mValidBufferBindings.set(BufferBinding::ElementArray);
3395 mValidBufferBindings.set(BufferBinding::Array);
3396
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003397 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003398 {
3399 mValidBufferBindings.set(BufferBinding::PixelPack);
3400 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3401 }
3402
3403 if (getClientVersion() >= ES_3_0)
3404 {
3405 mValidBufferBindings.set(BufferBinding::CopyRead);
3406 mValidBufferBindings.set(BufferBinding::CopyWrite);
3407 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3408 mValidBufferBindings.set(BufferBinding::Uniform);
3409 }
3410
3411 if (getClientVersion() >= ES_3_1)
3412 {
3413 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3414 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3415 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3416 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3417 }
jchen107ae70d82018-07-06 13:47:01 +08003418
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003419 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003420
Jamie Madillef9fcd92018-11-28 14:03:59 -05003421 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003422 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003423 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3424 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3425 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3427 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003429
Jamie Madillac66f982018-10-09 18:30:01 -04003430 // Reinitialize state cache after extension changes.
3431 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003432}
3433
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003434void Context::initWorkarounds()
3435{
Jamie Madill761b02c2017-06-23 16:27:06 -04003436 // Apply back-end workarounds.
3437 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3438
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003439 // Lose the context upon out of memory error if the application is
3440 // expecting to watch for those events.
3441 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003442
3443 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3444 {
3445 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3446 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3447 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3448 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003449}
3450
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003451bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3452{
3453 return (instanceCount == 0) || noopDraw(mode, count);
3454}
3455
Jamie Madill526392d2018-11-16 09:35:14 -05003456angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003457{
Geoff Langa8cb2872018-03-09 16:09:40 -05003458 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003459 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003460 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003461 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003462}
3463
Jamie Madill526392d2018-11-16 09:35:14 -05003464angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003465{
Geoff Langa8cb2872018-03-09 16:09:40 -05003466 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003467 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3468 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003469 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003470 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003471}
3472
Jamie Madill132d15c2018-11-30 15:25:38 -05003473ANGLE_INLINE angle::Result Context::prepareForDispatch()
3474{
3475 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3476 return syncDirtyBits(mComputeDirtyBits);
3477}
3478
Jamie Madill526392d2018-11-16 09:35:14 -05003479angle::Result Context::syncState(const State::DirtyBits &bitMask,
3480 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003481{
Geoff Langa8cb2872018-03-09 16:09:40 -05003482 ANGLE_TRY(syncDirtyObjects(objectMask));
3483 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003484 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003485}
3486
Jamie Madillc29968b2016-01-20 11:17:23 -05003487void Context::blitFramebuffer(GLint srcX0,
3488 GLint srcY0,
3489 GLint srcX1,
3490 GLint srcY1,
3491 GLint dstX0,
3492 GLint dstY0,
3493 GLint dstX1,
3494 GLint dstY1,
3495 GLbitfield mask,
3496 GLenum filter)
3497{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003498 if (mask == 0)
3499 {
3500 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3501 // buffers are copied.
3502 return;
3503 }
3504
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003505 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003506 ASSERT(drawFramebuffer);
3507
3508 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3509 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3510
Jamie Madillbc918e72018-03-08 09:47:21 -05003511 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003512
Jamie Madill4f6592f2018-11-27 16:37:45 -05003513 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003514}
Jamie Madillc29968b2016-01-20 11:17:23 -05003515
3516void Context::clear(GLbitfield mask)
3517{
Geoff Langd4fff502017-09-22 11:28:28 -04003518 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003519 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003520}
3521
3522void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3523{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003524 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003525 const FramebufferAttachment *attachment = nullptr;
3526 if (buffer == GL_DEPTH)
3527 {
3528 attachment = framebufferObject->getDepthbuffer();
3529 }
3530 if (buffer == GL_COLOR &&
3531 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3532 {
3533 attachment = framebufferObject->getColorbuffer(drawbuffer);
3534 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003535 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3536 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003537 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003538 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003539 return;
3540 }
Geoff Langd4fff502017-09-22 11:28:28 -04003541 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003542 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
3545void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3546{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003547 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003548 const FramebufferAttachment *attachment = nullptr;
3549 if (buffer == GL_COLOR &&
3550 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3551 {
3552 attachment = framebufferObject->getColorbuffer(drawbuffer);
3553 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003554 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3555 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003556 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003557 {
3558 return;
3559 }
Geoff Langd4fff502017-09-22 11:28:28 -04003560 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003561 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003562}
3563
3564void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3565{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003566 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003567 const FramebufferAttachment *attachment = nullptr;
3568 if (buffer == GL_STENCIL)
3569 {
3570 attachment = framebufferObject->getStencilbuffer();
3571 }
3572 if (buffer == GL_COLOR &&
3573 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3574 {
3575 attachment = framebufferObject->getColorbuffer(drawbuffer);
3576 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003577 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3578 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003579 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003580 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003581 return;
3582 }
Geoff Langd4fff502017-09-22 11:28:28 -04003583 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003584 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003585}
3586
3587void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3588{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003589 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 ASSERT(framebufferObject);
3591
3592 // If a buffer is not present, the clear has no effect
3593 if (framebufferObject->getDepthbuffer() == nullptr &&
3594 framebufferObject->getStencilbuffer() == nullptr)
3595 {
3596 return;
3597 }
3598
Geoff Langd4fff502017-09-22 11:28:28 -04003599 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3600 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003601}
3602
3603void Context::readPixels(GLint x,
3604 GLint y,
3605 GLsizei width,
3606 GLsizei height,
3607 GLenum format,
3608 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003609 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003610{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003611 if (width == 0 || height == 0)
3612 {
3613 return;
3614 }
3615
Jamie Madillbc918e72018-03-08 09:47:21 -05003616 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003617
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003618 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003619 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003620
3621 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003622 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003623}
3624
Brandon Jones59770802018-04-02 13:18:42 -07003625void Context::readPixelsRobust(GLint x,
3626 GLint y,
3627 GLsizei width,
3628 GLsizei height,
3629 GLenum format,
3630 GLenum type,
3631 GLsizei bufSize,
3632 GLsizei *length,
3633 GLsizei *columns,
3634 GLsizei *rows,
3635 void *pixels)
3636{
3637 readPixels(x, y, width, height, format, type, pixels);
3638}
3639
3640void Context::readnPixelsRobust(GLint x,
3641 GLint y,
3642 GLsizei width,
3643 GLsizei height,
3644 GLenum format,
3645 GLenum type,
3646 GLsizei bufSize,
3647 GLsizei *length,
3648 GLsizei *columns,
3649 GLsizei *rows,
3650 void *data)
3651{
3652 readPixels(x, y, width, height, format, type, data);
3653}
3654
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003655void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 GLint level,
3657 GLenum internalformat,
3658 GLint x,
3659 GLint y,
3660 GLsizei width,
3661 GLsizei height,
3662 GLint border)
3663{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003664 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003665 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003666
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 Rectangle sourceArea(x, y, width, height);
3668
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003669 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003670 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003671 ANGLE_CONTEXT_TRY(
3672 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003673}
3674
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003675void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 GLint level,
3677 GLint xoffset,
3678 GLint yoffset,
3679 GLint x,
3680 GLint y,
3681 GLsizei width,
3682 GLsizei height)
3683{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003684 if (width == 0 || height == 0)
3685 {
3686 return;
3687 }
3688
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003689 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003690 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691
Jamie Madillc29968b2016-01-20 11:17:23 -05003692 Offset destOffset(xoffset, yoffset, 0);
3693 Rectangle sourceArea(x, y, width, height);
3694
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003695 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003696 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003697 ANGLE_CONTEXT_TRY(
3698 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003699}
3700
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003701void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 GLint level,
3703 GLint xoffset,
3704 GLint yoffset,
3705 GLint zoffset,
3706 GLint x,
3707 GLint y,
3708 GLsizei width,
3709 GLsizei height)
3710{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003711 if (width == 0 || height == 0)
3712 {
3713 return;
3714 }
3715
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003716 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003717 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003718
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 Offset destOffset(xoffset, yoffset, zoffset);
3720 Rectangle sourceArea(x, y, width, height);
3721
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003722 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003723 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003724 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3725 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003726}
3727
3728void Context::framebufferTexture2D(GLenum target,
3729 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003730 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003731 GLuint texture,
3732 GLint level)
3733{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003734 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 ASSERT(framebuffer);
3736
3737 if (texture != 0)
3738 {
3739 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003740 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003741 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003742 }
3743 else
3744 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003745 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003748 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003749}
3750
3751void Context::framebufferRenderbuffer(GLenum target,
3752 GLenum attachment,
3753 GLenum renderbuffertarget,
3754 GLuint renderbuffer)
3755{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003756 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 ASSERT(framebuffer);
3758
3759 if (renderbuffer != 0)
3760 {
3761 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003762
Jamie Madillcc129372018-04-12 09:13:18 -04003763 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003764 renderbufferObject);
3765 }
3766 else
3767 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003768 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003769 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003771 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003772}
3773
3774void Context::framebufferTextureLayer(GLenum target,
3775 GLenum attachment,
3776 GLuint texture,
3777 GLint level,
3778 GLint layer)
3779{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003780 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781 ASSERT(framebuffer);
3782
3783 if (texture != 0)
3784 {
3785 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003786 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003787 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 }
3789 else
3790 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003791 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003792 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003793
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003794 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003795}
3796
Brandon Jones59770802018-04-02 13:18:42 -07003797void Context::framebufferTextureMultiviewLayered(GLenum target,
3798 GLenum attachment,
3799 GLuint texture,
3800 GLint level,
3801 GLint baseViewIndex,
3802 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003803{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003804 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003805 ASSERT(framebuffer);
3806
3807 if (texture != 0)
3808 {
3809 Texture *textureObj = getTexture(texture);
3810
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003811 ImageIndex index;
3812 if (textureObj->getType() == TextureType::_2DArray)
3813 {
3814 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3815 }
3816 else
3817 {
3818 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3819 ASSERT(level == 0);
3820 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3821 }
Martin Radev82ef7742017-08-08 17:44:58 +03003822 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3823 numViews, baseViewIndex);
3824 }
3825 else
3826 {
3827 framebuffer->resetAttachment(this, attachment);
3828 }
3829
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003830 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003831}
3832
Brandon Jones59770802018-04-02 13:18:42 -07003833void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3834 GLenum attachment,
3835 GLuint texture,
3836 GLint level,
3837 GLsizei numViews,
3838 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003839{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003840 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003841 ASSERT(framebuffer);
3842
3843 if (texture != 0)
3844 {
3845 Texture *textureObj = getTexture(texture);
3846
3847 ImageIndex index = ImageIndex::Make2D(level);
3848 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3849 textureObj, numViews, viewportOffsets);
3850 }
3851 else
3852 {
3853 framebuffer->resetAttachment(this, attachment);
3854 }
3855
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003856 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003857}
3858
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003859void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3860{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003861 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003862 ASSERT(framebuffer);
3863
3864 if (texture != 0)
3865 {
3866 Texture *textureObj = getTexture(texture);
3867
3868 ImageIndex index = ImageIndex::MakeFromType(
3869 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3870 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3871 }
3872 else
3873 {
3874 framebuffer->resetAttachment(this, attachment);
3875 }
3876
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003877 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003878}
3879
Jamie Madillc29968b2016-01-20 11:17:23 -05003880void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3881{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003882 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003883 ASSERT(framebuffer);
3884 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003885 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003886 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003887}
3888
3889void Context::readBuffer(GLenum mode)
3890{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003891 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003892 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003893 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894}
3895
3896void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3897{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003898 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003899 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003900
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003901 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003902 ASSERT(framebuffer);
3903
3904 // The specification isn't clear what should be done when the framebuffer isn't complete.
3905 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003906 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003907}
3908
3909void Context::invalidateFramebuffer(GLenum target,
3910 GLsizei numAttachments,
3911 const GLenum *attachments)
3912{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003913 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003914 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003915
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003916 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003917 ASSERT(framebuffer);
3918
Jamie Madill427064d2018-04-13 16:20:34 -04003919 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003920 {
Jamie Madill437fa652016-05-03 15:13:24 -04003921 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003922 }
Jamie Madill437fa652016-05-03 15:13:24 -04003923
Jamie Madill4f6592f2018-11-27 16:37:45 -05003924 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003925}
3926
3927void Context::invalidateSubFramebuffer(GLenum target,
3928 GLsizei numAttachments,
3929 const GLenum *attachments,
3930 GLint x,
3931 GLint y,
3932 GLsizei width,
3933 GLsizei height)
3934{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003935 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003936 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003937
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003938 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003939 ASSERT(framebuffer);
3940
Jamie Madill427064d2018-04-13 16:20:34 -04003941 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003942 {
Jamie Madill437fa652016-05-03 15:13:24 -04003943 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003944 }
Jamie Madill437fa652016-05-03 15:13:24 -04003945
3946 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003947 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003948}
3949
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003950void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003951 GLint level,
3952 GLint internalformat,
3953 GLsizei width,
3954 GLsizei height,
3955 GLint border,
3956 GLenum format,
3957 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003958 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003959{
Jamie Madillbc918e72018-03-08 09:47:21 -05003960 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003961
3962 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003963 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003964 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003965 internalformat, size, format, type,
3966 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003967}
3968
Brandon Jones59770802018-04-02 13:18:42 -07003969void Context::texImage2DRobust(TextureTarget target,
3970 GLint level,
3971 GLint internalformat,
3972 GLsizei width,
3973 GLsizei height,
3974 GLint border,
3975 GLenum format,
3976 GLenum type,
3977 GLsizei bufSize,
3978 const void *pixels)
3979{
3980 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3981}
3982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003983void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003984 GLint level,
3985 GLint internalformat,
3986 GLsizei width,
3987 GLsizei height,
3988 GLsizei depth,
3989 GLint border,
3990 GLenum format,
3991 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003992 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003993{
Jamie Madillbc918e72018-03-08 09:47:21 -05003994 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003995
3996 Extents size(width, height, depth);
3997 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003998 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05003999 NonCubeTextureTypeToTarget(target), level, internalformat,
4000 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004001}
4002
Brandon Jones59770802018-04-02 13:18:42 -07004003void Context::texImage3DRobust(TextureType target,
4004 GLint level,
4005 GLint internalformat,
4006 GLsizei width,
4007 GLsizei height,
4008 GLsizei depth,
4009 GLint border,
4010 GLenum format,
4011 GLenum type,
4012 GLsizei bufSize,
4013 const void *pixels)
4014{
4015 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4016}
4017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004018void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004019 GLint level,
4020 GLint xoffset,
4021 GLint yoffset,
4022 GLsizei width,
4023 GLsizei height,
4024 GLenum format,
4025 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004026 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004027{
4028 // Zero sized uploads are valid but no-ops
4029 if (width == 0 || height == 0)
4030 {
4031 return;
4032 }
4033
Jamie Madillbc918e72018-03-08 09:47:21 -05004034 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004035
4036 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004037 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004038
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004039 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004040
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004041 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004042 level, area, format, type,
4043 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004044}
4045
Brandon Jones59770802018-04-02 13:18:42 -07004046void Context::texSubImage2DRobust(TextureTarget target,
4047 GLint level,
4048 GLint xoffset,
4049 GLint yoffset,
4050 GLsizei width,
4051 GLsizei height,
4052 GLenum format,
4053 GLenum type,
4054 GLsizei bufSize,
4055 const void *pixels)
4056{
4057 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4058}
4059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004060void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004061 GLint level,
4062 GLint xoffset,
4063 GLint yoffset,
4064 GLint zoffset,
4065 GLsizei width,
4066 GLsizei height,
4067 GLsizei depth,
4068 GLenum format,
4069 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004070 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004071{
4072 // Zero sized uploads are valid but no-ops
4073 if (width == 0 || height == 0 || depth == 0)
4074 {
4075 return;
4076 }
4077
Jamie Madillbc918e72018-03-08 09:47:21 -05004078 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004079
4080 Box area(xoffset, yoffset, zoffset, width, height, depth);
4081 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004082
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004083 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004084
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004085 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004086 NonCubeTextureTypeToTarget(target), level, area, format,
4087 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004088}
4089
Brandon Jones59770802018-04-02 13:18:42 -07004090void Context::texSubImage3DRobust(TextureType target,
4091 GLint level,
4092 GLint xoffset,
4093 GLint yoffset,
4094 GLint zoffset,
4095 GLsizei width,
4096 GLsizei height,
4097 GLsizei depth,
4098 GLenum format,
4099 GLenum type,
4100 GLsizei bufSize,
4101 const void *pixels)
4102{
4103 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4104 pixels);
4105}
4106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004107void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004108 GLint level,
4109 GLenum internalformat,
4110 GLsizei width,
4111 GLsizei height,
4112 GLint border,
4113 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004114 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004115{
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004117
4118 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004119 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004120 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004121 internalformat, size, imageSize,
4122 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004123}
4124
Brandon Jones59770802018-04-02 13:18:42 -07004125void Context::compressedTexImage2DRobust(TextureTarget target,
4126 GLint level,
4127 GLenum internalformat,
4128 GLsizei width,
4129 GLsizei height,
4130 GLint border,
4131 GLsizei imageSize,
4132 GLsizei dataSize,
4133 const GLvoid *data)
4134{
4135 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4136}
4137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004138void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004139 GLint level,
4140 GLenum internalformat,
4141 GLsizei width,
4142 GLsizei height,
4143 GLsizei depth,
4144 GLint border,
4145 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004146 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004147{
Jamie Madillbc918e72018-03-08 09:47:21 -05004148 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004149
4150 Extents size(width, height, depth);
4151 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004152 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004153 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004154 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004155}
4156
Brandon Jones59770802018-04-02 13:18:42 -07004157void Context::compressedTexImage3DRobust(TextureType target,
4158 GLint level,
4159 GLenum internalformat,
4160 GLsizei width,
4161 GLsizei height,
4162 GLsizei depth,
4163 GLint border,
4164 GLsizei imageSize,
4165 GLsizei dataSize,
4166 const GLvoid *data)
4167{
4168 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4169 data);
4170}
4171
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004172void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004173 GLint level,
4174 GLint xoffset,
4175 GLint yoffset,
4176 GLsizei width,
4177 GLsizei height,
4178 GLenum format,
4179 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004180 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004181{
Jamie Madillbc918e72018-03-08 09:47:21 -05004182 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004183
4184 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004185 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004186 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004187 area, format, imageSize,
4188 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004189}
4190
Brandon Jones59770802018-04-02 13:18:42 -07004191void Context::compressedTexSubImage2DRobust(TextureTarget target,
4192 GLint level,
4193 GLint xoffset,
4194 GLint yoffset,
4195 GLsizei width,
4196 GLsizei height,
4197 GLenum format,
4198 GLsizei imageSize,
4199 GLsizei dataSize,
4200 const GLvoid *data)
4201{
4202 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4203 data);
4204}
4205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004206void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004207 GLint level,
4208 GLint xoffset,
4209 GLint yoffset,
4210 GLint zoffset,
4211 GLsizei width,
4212 GLsizei height,
4213 GLsizei depth,
4214 GLenum format,
4215 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004216 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004217{
4218 // Zero sized uploads are valid but no-ops
4219 if (width == 0 || height == 0)
4220 {
4221 return;
4222 }
4223
Jamie Madillbc918e72018-03-08 09:47:21 -05004224 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004225
4226 Box area(xoffset, yoffset, zoffset, width, height, depth);
4227 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004228 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004229 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004230 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004231}
4232
Brandon Jones59770802018-04-02 13:18:42 -07004233void Context::compressedTexSubImage3DRobust(TextureType target,
4234 GLint level,
4235 GLint xoffset,
4236 GLint yoffset,
4237 GLint zoffset,
4238 GLsizei width,
4239 GLsizei height,
4240 GLsizei depth,
4241 GLenum format,
4242 GLsizei imageSize,
4243 GLsizei dataSize,
4244 const GLvoid *data)
4245{
4246 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4247 imageSize, data);
4248}
4249
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004250void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004251{
4252 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004253 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004254}
4255
Jamie Madill007530e2017-12-28 14:27:04 -05004256void Context::copyTexture(GLuint sourceId,
4257 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004258 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004259 GLuint destId,
4260 GLint destLevel,
4261 GLint internalFormat,
4262 GLenum destType,
4263 GLboolean unpackFlipY,
4264 GLboolean unpackPremultiplyAlpha,
4265 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004266{
Jamie Madillbc918e72018-03-08 09:47:21 -05004267 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004268
4269 gl::Texture *sourceTexture = getTexture(sourceId);
4270 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004271 ANGLE_CONTEXT_TRY(
4272 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4273 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4274 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004275}
4276
Jamie Madill007530e2017-12-28 14:27:04 -05004277void Context::copySubTexture(GLuint sourceId,
4278 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004279 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004280 GLuint destId,
4281 GLint destLevel,
4282 GLint xoffset,
4283 GLint yoffset,
4284 GLint x,
4285 GLint y,
4286 GLsizei width,
4287 GLsizei height,
4288 GLboolean unpackFlipY,
4289 GLboolean unpackPremultiplyAlpha,
4290 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004291{
4292 // Zero sized copies are valid but no-ops
4293 if (width == 0 || height == 0)
4294 {
4295 return;
4296 }
4297
Jamie Madillbc918e72018-03-08 09:47:21 -05004298 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004299
4300 gl::Texture *sourceTexture = getTexture(sourceId);
4301 gl::Texture *destTexture = getTexture(destId);
4302 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004303 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004304 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4305 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4306 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4307 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004308}
4309
4310void Context::copyTexture3D(GLuint sourceId,
4311 GLint sourceLevel,
4312 TextureTarget destTarget,
4313 GLuint destId,
4314 GLint destLevel,
4315 GLint internalFormat,
4316 GLenum destType,
4317 GLboolean unpackFlipY,
4318 GLboolean unpackPremultiplyAlpha,
4319 GLboolean unpackUnmultiplyAlpha)
4320{
4321 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4322
4323 Texture *sourceTexture = getTexture(sourceId);
4324 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004325 ANGLE_CONTEXT_TRY(
4326 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4327 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4328 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004329}
4330
4331void Context::copySubTexture3D(GLuint sourceId,
4332 GLint sourceLevel,
4333 TextureTarget destTarget,
4334 GLuint destId,
4335 GLint destLevel,
4336 GLint xoffset,
4337 GLint yoffset,
4338 GLint zoffset,
4339 GLint x,
4340 GLint y,
4341 GLint z,
4342 GLsizei width,
4343 GLsizei height,
4344 GLsizei depth,
4345 GLboolean unpackFlipY,
4346 GLboolean unpackPremultiplyAlpha,
4347 GLboolean unpackUnmultiplyAlpha)
4348{
4349 // Zero sized copies are valid but no-ops
4350 if (width == 0 || height == 0 || depth == 0)
4351 {
4352 return;
4353 }
4354
4355 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4356
4357 Texture *sourceTexture = getTexture(sourceId);
4358 Texture *destTexture = getTexture(destId);
4359 Offset offset(xoffset, yoffset, zoffset);
4360 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004361 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4362 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4363 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4364 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004365}
4366
Jamie Madill007530e2017-12-28 14:27:04 -05004367void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004368{
Jamie Madillbc918e72018-03-08 09:47:21 -05004369 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004370
4371 gl::Texture *sourceTexture = getTexture(sourceId);
4372 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004373 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004374}
4375
Corentin Wallez336129f2017-10-17 15:55:40 -04004376void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004377{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004378 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004379 ASSERT(buffer);
4380
Geoff Lang496c02d2016-10-20 11:38:11 -07004381 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004382}
4383
Brandon Jones59770802018-04-02 13:18:42 -07004384void Context::getBufferPointervRobust(BufferBinding target,
4385 GLenum pname,
4386 GLsizei bufSize,
4387 GLsizei *length,
4388 void **params)
4389{
4390 getBufferPointerv(target, pname, params);
4391}
4392
Corentin Wallez336129f2017-10-17 15:55:40 -04004393void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004394{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004395 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004396 ASSERT(buffer);
4397
Jamie Madill7c985f52018-11-29 18:16:17 -05004398 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004399 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004400 return nullptr;
4401 }
4402
4403 return buffer->getMapPointer();
4404}
4405
Corentin Wallez336129f2017-10-17 15:55:40 -04004406GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004407{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004408 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004409 ASSERT(buffer);
4410
4411 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004412 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004413 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004414 return GL_FALSE;
4415 }
4416
4417 return result;
4418}
4419
Corentin Wallez336129f2017-10-17 15:55:40 -04004420void *Context::mapBufferRange(BufferBinding target,
4421 GLintptr offset,
4422 GLsizeiptr length,
4423 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004424{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004425 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004426 ASSERT(buffer);
4427
Jamie Madill7c985f52018-11-29 18:16:17 -05004428 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004429 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004430 return nullptr;
4431 }
4432
4433 return buffer->getMapPointer();
4434}
4435
Corentin Wallez336129f2017-10-17 15:55:40 -04004436void Context::flushMappedBufferRange(BufferBinding /*target*/,
4437 GLintptr /*offset*/,
4438 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004439{
4440 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4441}
4442
Jamie Madill526392d2018-11-16 09:35:14 -05004443angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004444{
Geoff Langa8cb2872018-03-09 16:09:40 -05004445 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004446}
4447
Jamie Madill526392d2018-11-16 09:35:14 -05004448angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004449{
Geoff Langa8cb2872018-03-09 16:09:40 -05004450 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004451}
4452
Jamie Madill526392d2018-11-16 09:35:14 -05004453angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004454{
Geoff Langa8cb2872018-03-09 16:09:40 -05004455 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004456}
4457
Jamie Madill526392d2018-11-16 09:35:14 -05004458angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004459{
4460 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4461
4462 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4463 ANGLE_TRY(syncDirtyBits());
4464
Jamie Madill7c985f52018-11-29 18:16:17 -05004465 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004466}
4467
Jiajia Qin5451d532017-11-16 17:16:34 +08004468void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4469{
4470 UNIMPLEMENTED();
4471}
4472
Jamie Madillc20ab272016-06-09 07:20:46 -07004473void Context::activeTexture(GLenum texture)
4474{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004475 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476}
4477
Jamie Madill876429b2017-04-20 15:46:24 -04004478void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004479{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004480 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004483void Context::blendEquation(GLenum mode)
4484{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004485 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004486}
4487
Jamie Madillc20ab272016-06-09 07:20:46 -07004488void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4489{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004490 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004491}
4492
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004493void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4494{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004495 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004496}
4497
Jamie Madillc20ab272016-06-09 07:20:46 -07004498void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4499{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004500 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
Jamie Madill876429b2017-04-20 15:46:24 -04004503void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004504{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004505 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
Jamie Madill876429b2017-04-20 15:46:24 -04004508void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004509{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004510 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::clearStencil(GLint s)
4514{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004515 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
4518void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4519{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004520 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4521 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004524void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004525{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004526 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527}
4528
4529void Context::depthFunc(GLenum func)
4530{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004531 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532}
4533
4534void Context::depthMask(GLboolean flag)
4535{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004536 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
Jamie Madill876429b2017-04-20 15:46:24 -04004539void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004540{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004541 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::disable(GLenum cap)
4545{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004546 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004547 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
4550void Context::disableVertexAttribArray(GLuint index)
4551{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004552 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004553 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554}
4555
4556void Context::enable(GLenum cap)
4557{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004558 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004559 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560}
4561
4562void Context::enableVertexAttribArray(GLuint index)
4563{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004564 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004565 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566}
4567
4568void Context::frontFace(GLenum mode)
4569{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004570 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571}
4572
4573void Context::hint(GLenum target, GLenum mode)
4574{
4575 switch (target)
4576 {
4577 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004578 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579 break;
4580
4581 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004582 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004583 break;
4584
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004585 case GL_PERSPECTIVE_CORRECTION_HINT:
4586 case GL_POINT_SMOOTH_HINT:
4587 case GL_LINE_SMOOTH_HINT:
4588 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004589 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004590 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004591 default:
4592 UNREACHABLE();
4593 return;
4594 }
4595}
4596
4597void Context::lineWidth(GLfloat width)
4598{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004599 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
4602void Context::pixelStorei(GLenum pname, GLint param)
4603{
4604 switch (pname)
4605 {
4606 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004607 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608 break;
4609
4610 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004611 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612 break;
4613
4614 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004615 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616 break;
4617
4618 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004619 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004620 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621 break;
4622
4623 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004624 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004625 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626 break;
4627
4628 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004629 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004630 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631 break;
4632
4633 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004634 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004635 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636 break;
4637
4638 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004639 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004640 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004641 break;
4642
4643 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004644 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004645 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646 break;
4647
4648 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004649 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004650 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004651 break;
4652
4653 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004654 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004655 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656 break;
4657
4658 default:
4659 UNREACHABLE();
4660 return;
4661 }
4662}
4663
4664void Context::polygonOffset(GLfloat factor, GLfloat units)
4665{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004666 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
Jamie Madill876429b2017-04-20 15:46:24 -04004669void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004670{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004671 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004672}
4673
Jiawei Shaodb342272017-09-27 10:21:45 +08004674void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4675{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004676 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004677}
4678
Jamie Madillc20ab272016-06-09 07:20:46 -07004679void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4680{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004681 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4685{
4686 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4687 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004688 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004689 }
4690
4691 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4692 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004693 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004695
4696 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4700{
4701 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4702 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004703 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704 }
4705
4706 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4707 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004708 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004710
4711 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712}
4713
4714void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4715{
4716 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4717 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004718 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004719 }
4720
4721 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4722 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004723 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004724 }
4725}
4726
4727void Context::vertexAttrib1f(GLuint index, GLfloat x)
4728{
4729 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004730 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004731 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004732}
4733
4734void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4735{
4736 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004737 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004738 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004739}
4740
4741void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4742{
4743 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004744 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004745 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4749{
4750 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004751 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004752 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
4755void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4756{
4757 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004758 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004759 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004760}
4761
4762void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4763{
4764 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004765 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004766 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004767}
4768
4769void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4770{
4771 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004772 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004773 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004774}
4775
4776void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4777{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004778 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004779 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
4782void Context::vertexAttribPointer(GLuint index,
4783 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004784 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004785 GLboolean normalized,
4786 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004787 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004788{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004789 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4790 type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004791 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004792}
4793
Shao80957d92017-02-20 21:25:59 +08004794void Context::vertexAttribFormat(GLuint attribIndex,
4795 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004796 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004797 GLboolean normalized,
4798 GLuint relativeOffset)
4799{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004800 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4801 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004802 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004803}
4804
4805void Context::vertexAttribIFormat(GLuint attribIndex,
4806 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004807 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004808 GLuint relativeOffset)
4809{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004810 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004811 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004812}
4813
4814void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4815{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004816 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004817 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004818}
4819
Jiajia Qin5451d532017-11-16 17:16:34 +08004820void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004821{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004822 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004823 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004824}
4825
Jamie Madillc20ab272016-06-09 07:20:46 -07004826void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4827{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004828 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004829}
4830
4831void Context::vertexAttribIPointer(GLuint index,
4832 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004833 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004834 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004835 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004836{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004837 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4838 type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004839 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004840}
4841
4842void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4843{
4844 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004845 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004846 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004847}
4848
4849void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4850{
4851 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004852 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004853 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004854}
4855
4856void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4857{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004858 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004859 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004860}
4861
4862void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4863{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004864 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004865 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004866}
4867
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004868void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4869{
4870 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004871 getState().getVertexAttribCurrentValue(index);
4872 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004873 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4874 currentValues, pname, params);
4875}
4876
Brandon Jones59770802018-04-02 13:18:42 -07004877void Context::getVertexAttribivRobust(GLuint index,
4878 GLenum pname,
4879 GLsizei bufSize,
4880 GLsizei *length,
4881 GLint *params)
4882{
4883 getVertexAttribiv(index, pname, params);
4884}
4885
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004886void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4887{
4888 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004889 getState().getVertexAttribCurrentValue(index);
4890 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004891 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4892 currentValues, pname, params);
4893}
4894
Brandon Jones59770802018-04-02 13:18:42 -07004895void Context::getVertexAttribfvRobust(GLuint index,
4896 GLenum pname,
4897 GLsizei bufSize,
4898 GLsizei *length,
4899 GLfloat *params)
4900{
4901 getVertexAttribfv(index, pname, params);
4902}
4903
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004904void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4905{
4906 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004907 getState().getVertexAttribCurrentValue(index);
4908 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004909 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4910 currentValues, pname, params);
4911}
4912
Brandon Jones59770802018-04-02 13:18:42 -07004913void Context::getVertexAttribIivRobust(GLuint index,
4914 GLenum pname,
4915 GLsizei bufSize,
4916 GLsizei *length,
4917 GLint *params)
4918{
4919 getVertexAttribIiv(index, pname, params);
4920}
4921
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004922void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4923{
4924 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004925 getState().getVertexAttribCurrentValue(index);
4926 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004927 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4928 currentValues, pname, params);
4929}
4930
Brandon Jones59770802018-04-02 13:18:42 -07004931void Context::getVertexAttribIuivRobust(GLuint index,
4932 GLenum pname,
4933 GLsizei bufSize,
4934 GLsizei *length,
4935 GLuint *params)
4936{
4937 getVertexAttribIuiv(index, pname, params);
4938}
4939
Jamie Madill876429b2017-04-20 15:46:24 -04004940void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004941{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004942 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004943 QueryVertexAttribPointerv(attrib, pname, pointer);
4944}
4945
Brandon Jones59770802018-04-02 13:18:42 -07004946void Context::getVertexAttribPointervRobust(GLuint index,
4947 GLenum pname,
4948 GLsizei bufSize,
4949 GLsizei *length,
4950 void **pointer)
4951{
4952 getVertexAttribPointerv(index, pname, pointer);
4953}
4954
Jamie Madillc20ab272016-06-09 07:20:46 -07004955void Context::debugMessageControl(GLenum source,
4956 GLenum type,
4957 GLenum severity,
4958 GLsizei count,
4959 const GLuint *ids,
4960 GLboolean enabled)
4961{
4962 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004963 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4964 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004965}
4966
4967void Context::debugMessageInsert(GLenum source,
4968 GLenum type,
4969 GLuint id,
4970 GLenum severity,
4971 GLsizei length,
4972 const GLchar *buf)
4973{
4974 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004975 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004976}
4977
4978void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4979{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004980 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004981}
4982
4983GLuint Context::getDebugMessageLog(GLuint count,
4984 GLsizei bufSize,
4985 GLenum *sources,
4986 GLenum *types,
4987 GLuint *ids,
4988 GLenum *severities,
4989 GLsizei *lengths,
4990 GLchar *messageLog)
4991{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004992 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
4993 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004994}
4995
4996void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4997{
4998 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004999 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005000 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005001}
5002
5003void Context::popDebugGroup()
5004{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005005 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005006 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005007}
5008
Corentin Wallez336129f2017-10-17 15:55:40 -04005009void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005010{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005011 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005012 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005013 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005014}
5015
Corentin Wallez336129f2017-10-17 15:55:40 -04005016void Context::bufferSubData(BufferBinding target,
5017 GLintptr offset,
5018 GLsizeiptr size,
5019 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005020{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005021 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005022 {
5023 return;
5024 }
5025
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005026 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005027 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005028 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005029}
5030
Jamie Madillef300b12016-10-07 15:12:09 -04005031void Context::attachShader(GLuint program, GLuint shader)
5032{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005033 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5034 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005035 ASSERT(programObject && shaderObject);
5036 programObject->attachShader(shaderObject);
5037}
5038
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005039const Workarounds &Context::getWorkarounds() const
5040{
5041 return mWorkarounds;
5042}
5043
Corentin Wallez336129f2017-10-17 15:55:40 -04005044void Context::copyBufferSubData(BufferBinding readTarget,
5045 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005046 GLintptr readOffset,
5047 GLintptr writeOffset,
5048 GLsizeiptr size)
5049{
5050 // if size is zero, the copy is a successful no-op
5051 if (size == 0)
5052 {
5053 return;
5054 }
5055
5056 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005057 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5058 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005059
Jamie Madill4f6592f2018-11-27 16:37:45 -05005060 ANGLE_CONTEXT_TRY(
5061 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005062}
5063
Jamie Madill01a80ee2016-11-07 12:06:18 -05005064void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5065{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005066 // Ideally we could share the program query with the validation layer if possible.
5067 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005068 ASSERT(programObject);
5069 programObject->bindAttributeLocation(index, name);
5070}
5071
Corentin Wallez336129f2017-10-17 15:55:40 -04005072void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005073{
5074 bindBufferRange(target, index, buffer, 0, 0);
5075}
5076
Corentin Wallez336129f2017-10-17 15:55:40 -04005077void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005078 GLuint index,
5079 GLuint buffer,
5080 GLintptr offset,
5081 GLsizeiptr size)
5082{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005083 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5084 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005085 if (target == BufferBinding::Uniform)
5086 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005087 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005088 mStateCache.onUniformBufferStateChange(this);
5089 }
5090 else
5091 {
5092 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005093 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005094}
5095
Jamie Madill01a80ee2016-11-07 12:06:18 -05005096void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5097{
5098 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5099 {
5100 bindReadFramebuffer(framebuffer);
5101 }
5102
5103 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5104 {
5105 bindDrawFramebuffer(framebuffer);
5106 }
5107}
5108
5109void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5110{
5111 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005112 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5113 mImplementation.get(), renderbuffer);
5114 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005115}
5116
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005117void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005118 GLsizei samples,
5119 GLenum internalformat,
5120 GLsizei width,
5121 GLsizei height,
5122 GLboolean fixedsamplelocations)
5123{
5124 Extents size(width, height, 1);
5125 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005126 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5127 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005128}
5129
Olli Etuaho89664842018-08-24 14:45:36 +03005130void Context::texStorage3DMultisample(TextureType target,
5131 GLsizei samples,
5132 GLenum internalformat,
5133 GLsizei width,
5134 GLsizei height,
5135 GLsizei depth,
5136 GLboolean fixedsamplelocations)
5137{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005138 Extents size(width, height, depth);
5139 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005140 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5141 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005142}
5143
JiangYizhoubddc46b2016-12-09 09:50:51 +08005144void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5145{
JiangYizhou5b03f472017-01-09 10:22:53 +08005146 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5147 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005148 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5149 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005150
5151 switch (pname)
5152 {
5153 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005154 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005155 break;
5156 default:
5157 UNREACHABLE();
5158 }
5159}
5160
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005161void Context::getMultisamplefvRobust(GLenum pname,
5162 GLuint index,
5163 GLsizei bufSize,
5164 GLsizei *length,
5165 GLfloat *val)
5166{
5167 UNIMPLEMENTED();
5168}
5169
Jamie Madille8fb6402017-02-14 17:56:40 -05005170void Context::renderbufferStorage(GLenum target,
5171 GLenum internalformat,
5172 GLsizei width,
5173 GLsizei height)
5174{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005175 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5176 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5177
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005178 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005179 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005180}
5181
5182void Context::renderbufferStorageMultisample(GLenum target,
5183 GLsizei samples,
5184 GLenum internalformat,
5185 GLsizei width,
5186 GLsizei height)
5187{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005188 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5189 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005190
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005191 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005192 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005193 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005194}
5195
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005196void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5197{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005198 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005199 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005200}
5201
JiangYizhoue18e6392017-02-20 10:32:23 +08005202void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5203{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005204 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005205 QueryFramebufferParameteriv(framebuffer, pname, params);
5206}
5207
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005208void Context::getFramebufferParameterivRobust(GLenum target,
5209 GLenum pname,
5210 GLsizei bufSize,
5211 GLsizei *length,
5212 GLint *params)
5213{
5214 UNIMPLEMENTED();
5215}
5216
Jiajia Qin5451d532017-11-16 17:16:34 +08005217void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005218{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005219 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005220 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005221}
5222
Jamie Madilldec86232018-07-11 09:01:18 -04005223bool Context::getScratchBuffer(size_t requstedSizeBytes,
5224 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005225{
Jamie Madilldec86232018-07-11 09:01:18 -04005226 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005227}
5228
Jamie Madilldec86232018-07-11 09:01:18 -04005229bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5230 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005231{
Jamie Madilldec86232018-07-11 09:01:18 -04005232 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005233}
5234
Xinghua Cao2b396592017-03-29 15:36:04 +08005235void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5236{
5237 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5238 {
5239 return;
5240 }
5241
Xinghua Cao10a4d432017-11-28 14:46:26 +08005242 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005243 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005244}
5245
Jiajia Qin5451d532017-11-16 17:16:34 +08005246void Context::dispatchComputeIndirect(GLintptr indirect)
5247{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005248 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005249 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005250}
5251
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005252void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005253 GLsizei levels,
5254 GLenum internalFormat,
5255 GLsizei width,
5256 GLsizei height)
5257{
5258 Extents size(width, height, 1);
5259 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005260 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005261}
5262
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005263void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005264 GLsizei levels,
5265 GLenum internalFormat,
5266 GLsizei width,
5267 GLsizei height,
5268 GLsizei depth)
5269{
5270 Extents size(width, height, depth);
5271 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005272 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005273}
5274
Jiajia Qin5451d532017-11-16 17:16:34 +08005275void Context::memoryBarrier(GLbitfield barriers)
5276{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005277 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005278}
5279
5280void Context::memoryBarrierByRegion(GLbitfield barriers)
5281{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005282 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005283}
5284
Austin Eng1bf18ce2018-10-19 15:34:02 -07005285void Context::multiDrawArrays(PrimitiveMode mode,
5286 const GLint *firsts,
5287 const GLsizei *counts,
5288 GLsizei drawcount)
5289{
5290 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005291 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005292 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5293 if (hasDrawID)
5294 {
5295 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5296 {
5297 if (noopDraw(mode, counts[drawID]))
5298 {
5299 continue;
5300 }
5301 programObject->setDrawIDUniform(drawID);
5302 ANGLE_CONTEXT_TRY(
5303 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005304 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005305 }
5306 }
5307 else
5308 {
5309 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5310 {
5311 if (noopDraw(mode, counts[drawID]))
5312 {
5313 continue;
5314 }
5315 ANGLE_CONTEXT_TRY(
5316 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005317 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005318 }
5319 }
5320}
5321
5322void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5323 const GLint *firsts,
5324 const GLsizei *counts,
5325 const GLsizei *instanceCounts,
5326 GLsizei drawcount)
5327{
5328 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005329 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005330 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5331 if (hasDrawID)
5332 {
5333 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5334 {
5335 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5336 {
5337 continue;
5338 }
5339 programObject->setDrawIDUniform(drawID);
5340 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5341 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005342 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005343 }
5344 }
5345 else
5346 {
5347 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5348 {
5349 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5350 {
5351 continue;
5352 }
5353 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5354 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005355 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005356 }
5357 }
5358}
5359
5360void Context::multiDrawElements(PrimitiveMode mode,
5361 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005362 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005363 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005364 GLsizei drawcount)
5365{
5366 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005367 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005368 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5369 if (hasDrawID)
5370 {
5371 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5372 {
5373 if (noopDraw(mode, counts[drawID]))
5374 {
5375 continue;
5376 }
5377 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005378 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005379 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005380 }
5381 }
5382 else
5383 {
5384 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5385 {
5386 if (noopDraw(mode, counts[drawID]))
5387 {
5388 continue;
5389 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005390 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005391 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005392 }
5393 }
5394}
5395
5396void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5397 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005398 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005399 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005400 const GLsizei *instanceCounts,
5401 GLsizei drawcount)
5402{
5403 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005404 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005405 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5406 if (hasDrawID)
5407 {
5408 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5409 {
5410 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5411 {
5412 continue;
5413 }
5414 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005415 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005416 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005417 }
5418 }
5419 else
5420 {
5421 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5422 {
5423 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5424 {
5425 continue;
5426 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005427 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005428 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005429 }
5430 }
5431}
5432
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433GLenum Context::checkFramebufferStatus(GLenum target)
5434{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005435 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005436 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005437 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005438}
5439
5440void Context::compileShader(GLuint shader)
5441{
5442 Shader *shaderObject = GetValidShader(this, shader);
5443 if (!shaderObject)
5444 {
5445 return;
5446 }
5447 shaderObject->compile(this);
5448}
5449
5450void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5451{
5452 for (int i = 0; i < n; i++)
5453 {
5454 deleteBuffer(buffers[i]);
5455 }
5456}
5457
5458void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5459{
5460 for (int i = 0; i < n; i++)
5461 {
5462 if (framebuffers[i] != 0)
5463 {
5464 deleteFramebuffer(framebuffers[i]);
5465 }
5466 }
5467}
5468
5469void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5470{
5471 for (int i = 0; i < n; i++)
5472 {
5473 deleteRenderbuffer(renderbuffers[i]);
5474 }
5475}
5476
5477void Context::deleteTextures(GLsizei n, const GLuint *textures)
5478{
5479 for (int i = 0; i < n; i++)
5480 {
5481 if (textures[i] != 0)
5482 {
5483 deleteTexture(textures[i]);
5484 }
5485 }
5486}
5487
5488void Context::detachShader(GLuint program, GLuint shader)
5489{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005490 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491 ASSERT(programObject);
5492
5493 Shader *shaderObject = getShader(shader);
5494 ASSERT(shaderObject);
5495
5496 programObject->detachShader(this, shaderObject);
5497}
5498
5499void Context::genBuffers(GLsizei n, GLuint *buffers)
5500{
5501 for (int i = 0; i < n; i++)
5502 {
5503 buffers[i] = createBuffer();
5504 }
5505}
5506
5507void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5508{
5509 for (int i = 0; i < n; i++)
5510 {
5511 framebuffers[i] = createFramebuffer();
5512 }
5513}
5514
5515void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5516{
5517 for (int i = 0; i < n; i++)
5518 {
5519 renderbuffers[i] = createRenderbuffer();
5520 }
5521}
5522
5523void Context::genTextures(GLsizei n, GLuint *textures)
5524{
5525 for (int i = 0; i < n; i++)
5526 {
5527 textures[i] = createTexture();
5528 }
5529}
5530
5531void Context::getActiveAttrib(GLuint program,
5532 GLuint index,
5533 GLsizei bufsize,
5534 GLsizei *length,
5535 GLint *size,
5536 GLenum *type,
5537 GLchar *name)
5538{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005539 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005540 ASSERT(programObject);
5541 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5542}
5543
5544void Context::getActiveUniform(GLuint program,
5545 GLuint index,
5546 GLsizei bufsize,
5547 GLsizei *length,
5548 GLint *size,
5549 GLenum *type,
5550 GLchar *name)
5551{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005552 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005553 ASSERT(programObject);
5554 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5555}
5556
5557void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5558{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005559 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005560 ASSERT(programObject);
5561 programObject->getAttachedShaders(maxcount, count, shaders);
5562}
5563
5564GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5565{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005566 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005567 ASSERT(programObject);
5568 return programObject->getAttributeLocation(name);
5569}
5570
5571void Context::getBooleanv(GLenum pname, GLboolean *params)
5572{
5573 GLenum nativeType;
5574 unsigned int numParams = 0;
5575 getQueryParameterInfo(pname, &nativeType, &numParams);
5576
5577 if (nativeType == GL_BOOL)
5578 {
5579 getBooleanvImpl(pname, params);
5580 }
5581 else
5582 {
5583 CastStateValues(this, nativeType, pname, numParams, params);
5584 }
5585}
5586
Brandon Jones59770802018-04-02 13:18:42 -07005587void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5588{
5589 getBooleanv(pname, params);
5590}
5591
Jamie Madillc1d770e2017-04-13 17:31:24 -04005592void Context::getFloatv(GLenum pname, GLfloat *params)
5593{
5594 GLenum nativeType;
5595 unsigned int numParams = 0;
5596 getQueryParameterInfo(pname, &nativeType, &numParams);
5597
5598 if (nativeType == GL_FLOAT)
5599 {
5600 getFloatvImpl(pname, params);
5601 }
5602 else
5603 {
5604 CastStateValues(this, nativeType, pname, numParams, params);
5605 }
5606}
5607
Brandon Jones59770802018-04-02 13:18:42 -07005608void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5609{
5610 getFloatv(pname, params);
5611}
5612
Jamie Madillc1d770e2017-04-13 17:31:24 -04005613void Context::getIntegerv(GLenum pname, GLint *params)
5614{
5615 GLenum nativeType;
5616 unsigned int numParams = 0;
5617 getQueryParameterInfo(pname, &nativeType, &numParams);
5618
5619 if (nativeType == GL_INT)
5620 {
5621 getIntegervImpl(pname, params);
5622 }
5623 else
5624 {
5625 CastStateValues(this, nativeType, pname, numParams, params);
5626 }
5627}
5628
Brandon Jones59770802018-04-02 13:18:42 -07005629void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5630{
5631 getIntegerv(pname, data);
5632}
5633
Jamie Madillc1d770e2017-04-13 17:31:24 -04005634void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5635{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005636 // Don't resolve link if checking the link completion status.
5637 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5638 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005639 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005640 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005641}
5642
Brandon Jones59770802018-04-02 13:18:42 -07005643void Context::getProgramivRobust(GLuint program,
5644 GLenum pname,
5645 GLsizei bufSize,
5646 GLsizei *length,
5647 GLint *params)
5648{
5649 getProgramiv(program, pname, params);
5650}
5651
Jiajia Qin5451d532017-11-16 17:16:34 +08005652void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5653{
5654 UNIMPLEMENTED();
5655}
5656
Jamie Madillbe849e42017-05-02 15:49:00 -04005657void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005658{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005659 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005660 ASSERT(programObject);
5661 programObject->getInfoLog(bufsize, length, infolog);
5662}
5663
Jiajia Qin5451d532017-11-16 17:16:34 +08005664void Context::getProgramPipelineInfoLog(GLuint pipeline,
5665 GLsizei bufSize,
5666 GLsizei *length,
5667 GLchar *infoLog)
5668{
5669 UNIMPLEMENTED();
5670}
5671
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5673{
5674 Shader *shaderObject = getShader(shader);
5675 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005676 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005677}
5678
Brandon Jones59770802018-04-02 13:18:42 -07005679void Context::getShaderivRobust(GLuint shader,
5680 GLenum pname,
5681 GLsizei bufSize,
5682 GLsizei *length,
5683 GLint *params)
5684{
5685 getShaderiv(shader, pname, params);
5686}
5687
Jamie Madillc1d770e2017-04-13 17:31:24 -04005688void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5689{
5690 Shader *shaderObject = getShader(shader);
5691 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005692 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005693}
5694
5695void Context::getShaderPrecisionFormat(GLenum shadertype,
5696 GLenum precisiontype,
5697 GLint *range,
5698 GLint *precision)
5699{
5700 // TODO(jmadill): Compute shaders.
5701
5702 switch (shadertype)
5703 {
5704 case GL_VERTEX_SHADER:
5705 switch (precisiontype)
5706 {
5707 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005708 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005709 break;
5710 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005711 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005712 break;
5713 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005714 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005715 break;
5716
5717 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005718 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005719 break;
5720 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005721 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722 break;
5723 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005724 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725 break;
5726
5727 default:
5728 UNREACHABLE();
5729 return;
5730 }
5731 break;
5732
5733 case GL_FRAGMENT_SHADER:
5734 switch (precisiontype)
5735 {
5736 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005737 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005738 break;
5739 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005740 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741 break;
5742 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005743 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744 break;
5745
5746 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005747 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748 break;
5749 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005750 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751 break;
5752 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005753 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005754 break;
5755
5756 default:
5757 UNREACHABLE();
5758 return;
5759 }
5760 break;
5761
5762 default:
5763 UNREACHABLE();
5764 return;
5765 }
5766}
5767
5768void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5769{
5770 Shader *shaderObject = getShader(shader);
5771 ASSERT(shaderObject);
5772 shaderObject->getSource(bufsize, length, source);
5773}
5774
5775void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5776{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005777 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005778 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005779 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005780}
5781
Brandon Jones59770802018-04-02 13:18:42 -07005782void Context::getUniformfvRobust(GLuint program,
5783 GLint location,
5784 GLsizei bufSize,
5785 GLsizei *length,
5786 GLfloat *params)
5787{
5788 getUniformfv(program, location, params);
5789}
5790
Jamie Madillc1d770e2017-04-13 17:31:24 -04005791void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5792{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005793 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005794 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005795 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796}
5797
Brandon Jones59770802018-04-02 13:18:42 -07005798void Context::getUniformivRobust(GLuint program,
5799 GLint location,
5800 GLsizei bufSize,
5801 GLsizei *length,
5802 GLint *params)
5803{
5804 getUniformiv(program, location, params);
5805}
5806
Jamie Madillc1d770e2017-04-13 17:31:24 -04005807GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5808{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005809 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005810 ASSERT(programObject);
5811 return programObject->getUniformLocation(name);
5812}
5813
5814GLboolean Context::isBuffer(GLuint buffer)
5815{
5816 if (buffer == 0)
5817 {
5818 return GL_FALSE;
5819 }
5820
5821 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5822}
5823
5824GLboolean Context::isEnabled(GLenum cap)
5825{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005826 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005827}
5828
5829GLboolean Context::isFramebuffer(GLuint framebuffer)
5830{
5831 if (framebuffer == 0)
5832 {
5833 return GL_FALSE;
5834 }
5835
5836 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5837}
5838
5839GLboolean Context::isProgram(GLuint program)
5840{
5841 if (program == 0)
5842 {
5843 return GL_FALSE;
5844 }
5845
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005846 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005847}
5848
5849GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5850{
5851 if (renderbuffer == 0)
5852 {
5853 return GL_FALSE;
5854 }
5855
5856 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5857}
5858
5859GLboolean Context::isShader(GLuint shader)
5860{
5861 if (shader == 0)
5862 {
5863 return GL_FALSE;
5864 }
5865
5866 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5867}
5868
5869GLboolean Context::isTexture(GLuint texture)
5870{
5871 if (texture == 0)
5872 {
5873 return GL_FALSE;
5874 }
5875
5876 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5877}
5878
5879void Context::linkProgram(GLuint program)
5880{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005881 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005882 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005883 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005884
5885 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5886 // don't need to worry that:
5887 // 1. Draw calls after link use the new executable code or the old one depending on the link
5888 // result.
5889 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5890 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5891 // ProgramD3D.
5892 if (programObject->isInUse())
5893 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005894 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005895 if (programObject->isLinked())
5896 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005897 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005898 }
jchen107ae70d82018-07-06 13:47:01 +08005899 mStateCache.onProgramExecutableChange(this);
5900 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901}
5902
5903void Context::releaseShaderCompiler()
5904{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005905 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005906}
5907
5908void Context::shaderBinary(GLsizei n,
5909 const GLuint *shaders,
5910 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005911 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005912 GLsizei length)
5913{
5914 // No binary shader formats are supported.
5915 UNIMPLEMENTED();
5916}
5917
Olli Etuaho0ca09752018-09-24 11:00:50 +03005918void Context::bindFragDataLocationIndexed(GLuint program,
5919 GLuint colorNumber,
5920 GLuint index,
5921 const char *name)
5922{
5923 Program *programObject = getProgramNoResolveLink(program);
5924 programObject->bindFragmentOutputLocation(colorNumber, name);
5925 programObject->bindFragmentOutputIndex(index, name);
5926}
5927
5928void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5929{
5930 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5931}
5932
5933int Context::getFragDataIndex(GLuint program, const char *name)
5934{
5935 Program *programObject = getProgramResolveLink(program);
5936 return programObject->getFragDataIndex(name);
5937}
5938
5939int Context::getProgramResourceLocationIndex(GLuint program,
5940 GLenum programInterface,
5941 const char *name)
5942{
5943 Program *programObject = getProgramResolveLink(program);
5944 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5945 return programObject->getFragDataIndex(name);
5946}
5947
Jamie Madillc1d770e2017-04-13 17:31:24 -04005948void Context::shaderSource(GLuint shader,
5949 GLsizei count,
5950 const GLchar *const *string,
5951 const GLint *length)
5952{
5953 Shader *shaderObject = getShader(shader);
5954 ASSERT(shaderObject);
5955 shaderObject->setSource(count, string, length);
5956}
5957
5958void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5959{
5960 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5961}
5962
5963void Context::stencilMask(GLuint mask)
5964{
5965 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5966}
5967
5968void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5969{
5970 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5971}
5972
5973void Context::uniform1f(GLint location, GLfloat x)
5974{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005975 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005976 program->setUniform1fv(location, 1, &x);
5977}
5978
5979void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5980{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005981 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005982 program->setUniform1fv(location, count, v);
5983}
5984
Jamie Madill7e4eff12018-08-08 15:49:26 -04005985void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005986{
Jamie Madille3e680c2018-12-03 17:49:08 -05005987 program->setUniform1iv(this, location, count, v);
5988}
5989
5990void Context::onSamplerUniformChange(size_t textureUnitIndex)
5991{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005992 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05005993 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005994}
5995
Jamie Madill7e4eff12018-08-08 15:49:26 -04005996void Context::uniform1i(GLint location, GLint x)
5997{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005998 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04005999}
6000
Jamie Madillc1d770e2017-04-13 17:31:24 -04006001void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6002{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006003 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006004}
6005
6006void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6007{
6008 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006009 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006010 program->setUniform2fv(location, 1, xy);
6011}
6012
6013void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6014{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006015 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016 program->setUniform2fv(location, count, v);
6017}
6018
6019void Context::uniform2i(GLint location, GLint x, GLint y)
6020{
6021 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006022 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006023 program->setUniform2iv(location, 1, xy);
6024}
6025
6026void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6027{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006028 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006029 program->setUniform2iv(location, count, v);
6030}
6031
6032void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6033{
6034 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006035 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006036 program->setUniform3fv(location, 1, xyz);
6037}
6038
6039void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6040{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006041 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006042 program->setUniform3fv(location, count, v);
6043}
6044
6045void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6046{
6047 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006048 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006049 program->setUniform3iv(location, 1, xyz);
6050}
6051
6052void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6053{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006054 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006055 program->setUniform3iv(location, count, v);
6056}
6057
6058void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6059{
6060 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006061 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006062 program->setUniform4fv(location, 1, xyzw);
6063}
6064
6065void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6066{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006067 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006068 program->setUniform4fv(location, count, v);
6069}
6070
6071void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6072{
6073 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006074 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006075 program->setUniform4iv(location, 1, xyzw);
6076}
6077
6078void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6079{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006080 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006081 program->setUniform4iv(location, count, v);
6082}
6083
6084void Context::uniformMatrix2fv(GLint location,
6085 GLsizei count,
6086 GLboolean transpose,
6087 const GLfloat *value)
6088{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006089 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006090 program->setUniformMatrix2fv(location, count, transpose, value);
6091}
6092
6093void Context::uniformMatrix3fv(GLint location,
6094 GLsizei count,
6095 GLboolean transpose,
6096 const GLfloat *value)
6097{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006098 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006099 program->setUniformMatrix3fv(location, count, transpose, value);
6100}
6101
6102void Context::uniformMatrix4fv(GLint location,
6103 GLsizei count,
6104 GLboolean transpose,
6105 const GLfloat *value)
6106{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006107 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006108 program->setUniformMatrix4fv(location, count, transpose, value);
6109}
6110
6111void Context::validateProgram(GLuint program)
6112{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006113 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006114 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006115 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006116}
6117
Jiajia Qin5451d532017-11-16 17:16:34 +08006118void Context::validateProgramPipeline(GLuint pipeline)
6119{
6120 UNIMPLEMENTED();
6121}
6122
Jamie Madilld04908b2017-06-09 14:15:35 -04006123void Context::getProgramBinary(GLuint program,
6124 GLsizei bufSize,
6125 GLsizei *length,
6126 GLenum *binaryFormat,
6127 void *binary)
6128{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006129 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006130 ASSERT(programObject != nullptr);
6131
Jamie Madill4f6592f2018-11-27 16:37:45 -05006132 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006133}
6134
6135void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6136{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006137 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006138 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006139
Jamie Madill4f6592f2018-11-27 16:37:45 -05006140 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006141 if (programObject->isInUse())
6142 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006143 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006144 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006145 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006146}
6147
Jamie Madillff325f12017-08-26 15:06:05 -04006148void Context::uniform1ui(GLint location, GLuint v0)
6149{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006150 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006151 program->setUniform1uiv(location, 1, &v0);
6152}
6153
6154void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6155{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006156 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006157 const GLuint xy[] = {v0, v1};
6158 program->setUniform2uiv(location, 1, xy);
6159}
6160
6161void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6162{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006163 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006164 const GLuint xyz[] = {v0, v1, v2};
6165 program->setUniform3uiv(location, 1, xyz);
6166}
6167
6168void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6169{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006170 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006171 const GLuint xyzw[] = {v0, v1, v2, v3};
6172 program->setUniform4uiv(location, 1, xyzw);
6173}
6174
6175void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6176{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006177 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006178 program->setUniform1uiv(location, count, value);
6179}
6180void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6181{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006182 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006183 program->setUniform2uiv(location, count, value);
6184}
6185
6186void Context::uniform3uiv(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->setUniform3uiv(location, count, value);
6190}
6191
6192void Context::uniform4uiv(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->setUniform4uiv(location, count, value);
6196}
6197
Jamie Madillf0e04492017-08-26 15:28:42 -04006198void Context::genQueries(GLsizei n, GLuint *ids)
6199{
6200 for (GLsizei i = 0; i < n; i++)
6201 {
6202 GLuint handle = mQueryHandleAllocator.allocate();
6203 mQueryMap.assign(handle, nullptr);
6204 ids[i] = handle;
6205 }
6206}
6207
6208void Context::deleteQueries(GLsizei n, const GLuint *ids)
6209{
6210 for (int i = 0; i < n; i++)
6211 {
6212 GLuint query = ids[i];
6213
6214 Query *queryObject = nullptr;
6215 if (mQueryMap.erase(query, &queryObject))
6216 {
6217 mQueryHandleAllocator.release(query);
6218 if (queryObject)
6219 {
6220 queryObject->release(this);
6221 }
6222 }
6223 }
6224}
6225
6226GLboolean Context::isQuery(GLuint id)
6227{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006228 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006229}
6230
Jamie Madillc8c95812017-08-26 18:40:09 -04006231void Context::uniformMatrix2x3fv(GLint location,
6232 GLsizei count,
6233 GLboolean transpose,
6234 const GLfloat *value)
6235{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006236 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006237 program->setUniformMatrix2x3fv(location, count, transpose, value);
6238}
6239
6240void Context::uniformMatrix3x2fv(GLint location,
6241 GLsizei count,
6242 GLboolean transpose,
6243 const GLfloat *value)
6244{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006245 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006246 program->setUniformMatrix3x2fv(location, count, transpose, value);
6247}
6248
6249void Context::uniformMatrix2x4fv(GLint location,
6250 GLsizei count,
6251 GLboolean transpose,
6252 const GLfloat *value)
6253{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006254 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006255 program->setUniformMatrix2x4fv(location, count, transpose, value);
6256}
6257
6258void Context::uniformMatrix4x2fv(GLint location,
6259 GLsizei count,
6260 GLboolean transpose,
6261 const GLfloat *value)
6262{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006263 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006264 program->setUniformMatrix4x2fv(location, count, transpose, value);
6265}
6266
6267void Context::uniformMatrix3x4fv(GLint location,
6268 GLsizei count,
6269 GLboolean transpose,
6270 const GLfloat *value)
6271{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006272 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006273 program->setUniformMatrix3x4fv(location, count, transpose, value);
6274}
6275
6276void Context::uniformMatrix4x3fv(GLint location,
6277 GLsizei count,
6278 GLboolean transpose,
6279 const GLfloat *value)
6280{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006281 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006282 program->setUniformMatrix4x3fv(location, count, transpose, value);
6283}
6284
Jamie Madilld7576732017-08-26 18:49:50 -04006285void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6286{
6287 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6288 {
6289 GLuint vertexArray = arrays[arrayIndex];
6290
6291 if (arrays[arrayIndex] != 0)
6292 {
6293 VertexArray *vertexArrayObject = nullptr;
6294 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6295 {
6296 if (vertexArrayObject != nullptr)
6297 {
6298 detachVertexArray(vertexArray);
6299 vertexArrayObject->onDestroy(this);
6300 }
6301
6302 mVertexArrayHandleAllocator.release(vertexArray);
6303 }
6304 }
6305 }
6306}
6307
6308void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6309{
6310 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6311 {
6312 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6313 mVertexArrayMap.assign(vertexArray, nullptr);
6314 arrays[arrayIndex] = vertexArray;
6315 }
6316}
6317
6318bool Context::isVertexArray(GLuint array)
6319{
6320 if (array == 0)
6321 {
6322 return GL_FALSE;
6323 }
6324
6325 VertexArray *vao = getVertexArray(array);
6326 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6327}
6328
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006329void Context::endTransformFeedback()
6330{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006331 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006332 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006333 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006334}
6335
6336void Context::transformFeedbackVaryings(GLuint program,
6337 GLsizei count,
6338 const GLchar *const *varyings,
6339 GLenum bufferMode)
6340{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006341 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006342 ASSERT(programObject);
6343 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6344}
6345
6346void Context::getTransformFeedbackVarying(GLuint program,
6347 GLuint index,
6348 GLsizei bufSize,
6349 GLsizei *length,
6350 GLsizei *size,
6351 GLenum *type,
6352 GLchar *name)
6353{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006354 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006355 ASSERT(programObject);
6356 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6357}
6358
6359void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6360{
6361 for (int i = 0; i < n; i++)
6362 {
6363 GLuint transformFeedback = ids[i];
6364 if (transformFeedback == 0)
6365 {
6366 continue;
6367 }
6368
6369 TransformFeedback *transformFeedbackObject = nullptr;
6370 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6371 {
6372 if (transformFeedbackObject != nullptr)
6373 {
6374 detachTransformFeedback(transformFeedback);
6375 transformFeedbackObject->release(this);
6376 }
6377
6378 mTransformFeedbackHandleAllocator.release(transformFeedback);
6379 }
6380 }
6381}
6382
6383void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6384{
6385 for (int i = 0; i < n; i++)
6386 {
6387 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6388 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6389 ids[i] = transformFeedback;
6390 }
6391}
6392
6393bool Context::isTransformFeedback(GLuint id)
6394{
6395 if (id == 0)
6396 {
6397 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6398 // returns FALSE
6399 return GL_FALSE;
6400 }
6401
6402 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6403 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6404}
6405
6406void Context::pauseTransformFeedback()
6407{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006408 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006409 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006410 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006411}
6412
6413void Context::resumeTransformFeedback()
6414{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006415 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006416 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006417 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006418}
6419
Jamie Madill12e957f2017-08-26 21:42:26 -04006420void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6421{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006422 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006423 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006424}
6425
Brandon Jones59770802018-04-02 13:18:42 -07006426void Context::getUniformuivRobust(GLuint program,
6427 GLint location,
6428 GLsizei bufSize,
6429 GLsizei *length,
6430 GLuint *params)
6431{
6432 getUniformuiv(program, location, params);
6433}
6434
Jamie Madill12e957f2017-08-26 21:42:26 -04006435GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6436{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006437 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006438 return programObject->getFragDataLocation(name);
6439}
6440
6441void Context::getUniformIndices(GLuint program,
6442 GLsizei uniformCount,
6443 const GLchar *const *uniformNames,
6444 GLuint *uniformIndices)
6445{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006446 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006447 if (!programObject->isLinked())
6448 {
6449 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6450 {
6451 uniformIndices[uniformId] = GL_INVALID_INDEX;
6452 }
6453 }
6454 else
6455 {
6456 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6457 {
6458 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6459 }
6460 }
6461}
6462
6463void Context::getActiveUniformsiv(GLuint program,
6464 GLsizei uniformCount,
6465 const GLuint *uniformIndices,
6466 GLenum pname,
6467 GLint *params)
6468{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006469 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006470 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6471 {
6472 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006473 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006474 }
6475}
6476
6477GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6478{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006479 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006480 return programObject->getUniformBlockIndex(uniformBlockName);
6481}
6482
6483void Context::getActiveUniformBlockiv(GLuint program,
6484 GLuint uniformBlockIndex,
6485 GLenum pname,
6486 GLint *params)
6487{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006488 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006489 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6490}
6491
Brandon Jones59770802018-04-02 13:18:42 -07006492void Context::getActiveUniformBlockivRobust(GLuint program,
6493 GLuint uniformBlockIndex,
6494 GLenum pname,
6495 GLsizei bufSize,
6496 GLsizei *length,
6497 GLint *params)
6498{
6499 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6500}
6501
Jamie Madill12e957f2017-08-26 21:42:26 -04006502void Context::getActiveUniformBlockName(GLuint program,
6503 GLuint uniformBlockIndex,
6504 GLsizei bufSize,
6505 GLsizei *length,
6506 GLchar *uniformBlockName)
6507{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006508 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006509 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6510}
6511
6512void Context::uniformBlockBinding(GLuint program,
6513 GLuint uniformBlockIndex,
6514 GLuint uniformBlockBinding)
6515{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006516 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006517 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006518
Jamie Madill956ab4d2018-10-10 16:13:03 -04006519 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006520 if (programObject->isInUse())
6521 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006522 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006523 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006524 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006525}
6526
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006527GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6528{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006529 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006530 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006531
Jamie Madill70b5bb02017-08-28 13:32:37 -04006532 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006533 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006534 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006535 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006536 return nullptr;
6537 }
6538
Jamie Madill70b5bb02017-08-28 13:32:37 -04006539 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006540}
6541
6542GLboolean Context::isSync(GLsync sync)
6543{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006544 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006545}
6546
6547GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6548{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006549 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006550
6551 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006552 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006553 {
6554 return GL_WAIT_FAILED;
6555 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006556 return result;
6557}
6558
6559void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6560{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006561 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006562 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006563}
6564
6565void Context::getInteger64v(GLenum pname, GLint64 *params)
6566{
6567 GLenum nativeType = GL_NONE;
6568 unsigned int numParams = 0;
6569 getQueryParameterInfo(pname, &nativeType, &numParams);
6570
6571 if (nativeType == GL_INT_64_ANGLEX)
6572 {
6573 getInteger64vImpl(pname, params);
6574 }
6575 else
6576 {
6577 CastStateValues(this, nativeType, pname, numParams, params);
6578 }
6579}
6580
Brandon Jones59770802018-04-02 13:18:42 -07006581void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6582{
6583 getInteger64v(pname, data);
6584}
6585
Corentin Wallez336129f2017-10-17 15:55:40 -04006586void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006587{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006588 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006589 QueryBufferParameteri64v(buffer, pname, params);
6590}
6591
Brandon Jones59770802018-04-02 13:18:42 -07006592void Context::getBufferParameteri64vRobust(BufferBinding target,
6593 GLenum pname,
6594 GLsizei bufSize,
6595 GLsizei *length,
6596 GLint64 *params)
6597{
6598 getBufferParameteri64v(target, pname, params);
6599}
6600
Jamie Madill3ef140a2017-08-26 23:11:21 -04006601void Context::genSamplers(GLsizei count, GLuint *samplers)
6602{
6603 for (int i = 0; i < count; i++)
6604 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006605 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006606 }
6607}
6608
6609void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6610{
6611 for (int i = 0; i < count; i++)
6612 {
6613 GLuint sampler = samplers[i];
6614
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006615 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006616 {
6617 detachSampler(sampler);
6618 }
6619
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006620 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006621 }
6622}
6623
6624void Context::getInternalformativ(GLenum target,
6625 GLenum internalformat,
6626 GLenum pname,
6627 GLsizei bufSize,
6628 GLint *params)
6629{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006630 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006631 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6632}
6633
Brandon Jones59770802018-04-02 13:18:42 -07006634void Context::getInternalformativRobust(GLenum target,
6635 GLenum internalformat,
6636 GLenum pname,
6637 GLsizei bufSize,
6638 GLsizei *length,
6639 GLint *params)
6640{
6641 getInternalformativ(target, internalformat, pname, bufSize, params);
6642}
6643
Jiajia Qin5451d532017-11-16 17:16:34 +08006644void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6645{
6646 programUniform1iv(program, location, 1, &v0);
6647}
6648
6649void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6650{
6651 GLint xy[2] = {v0, v1};
6652 programUniform2iv(program, location, 1, xy);
6653}
6654
6655void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6656{
6657 GLint xyz[3] = {v0, v1, v2};
6658 programUniform3iv(program, location, 1, xyz);
6659}
6660
6661void Context::programUniform4i(GLuint program,
6662 GLint location,
6663 GLint v0,
6664 GLint v1,
6665 GLint v2,
6666 GLint v3)
6667{
6668 GLint xyzw[4] = {v0, v1, v2, v3};
6669 programUniform4iv(program, location, 1, xyzw);
6670}
6671
6672void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6673{
6674 programUniform1uiv(program, location, 1, &v0);
6675}
6676
6677void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6678{
6679 GLuint xy[2] = {v0, v1};
6680 programUniform2uiv(program, location, 1, xy);
6681}
6682
6683void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6684{
6685 GLuint xyz[3] = {v0, v1, v2};
6686 programUniform3uiv(program, location, 1, xyz);
6687}
6688
6689void Context::programUniform4ui(GLuint program,
6690 GLint location,
6691 GLuint v0,
6692 GLuint v1,
6693 GLuint v2,
6694 GLuint v3)
6695{
6696 GLuint xyzw[4] = {v0, v1, v2, v3};
6697 programUniform4uiv(program, location, 1, xyzw);
6698}
6699
6700void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6701{
6702 programUniform1fv(program, location, 1, &v0);
6703}
6704
6705void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6706{
6707 GLfloat xy[2] = {v0, v1};
6708 programUniform2fv(program, location, 1, xy);
6709}
6710
6711void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6712{
6713 GLfloat xyz[3] = {v0, v1, v2};
6714 programUniform3fv(program, location, 1, xyz);
6715}
6716
6717void Context::programUniform4f(GLuint program,
6718 GLint location,
6719 GLfloat v0,
6720 GLfloat v1,
6721 GLfloat v2,
6722 GLfloat v3)
6723{
6724 GLfloat xyzw[4] = {v0, v1, v2, v3};
6725 programUniform4fv(program, location, 1, xyzw);
6726}
6727
Jamie Madill81c2e252017-09-09 23:32:46 -04006728void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6729{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006730 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006731 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006732 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006733}
6734
Jiajia Qin5451d532017-11-16 17:16:34 +08006735void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6736{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006737 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006738 ASSERT(programObject);
6739 programObject->setUniform2iv(location, count, value);
6740}
6741
6742void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6743{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006744 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006745 ASSERT(programObject);
6746 programObject->setUniform3iv(location, count, value);
6747}
6748
6749void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6750{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006751 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006752 ASSERT(programObject);
6753 programObject->setUniform4iv(location, count, value);
6754}
6755
6756void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6757{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006758 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006759 ASSERT(programObject);
6760 programObject->setUniform1uiv(location, count, value);
6761}
6762
6763void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6764{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006765 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006766 ASSERT(programObject);
6767 programObject->setUniform2uiv(location, count, value);
6768}
6769
6770void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6771{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006772 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006773 ASSERT(programObject);
6774 programObject->setUniform3uiv(location, count, value);
6775}
6776
6777void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6778{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006779 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006780 ASSERT(programObject);
6781 programObject->setUniform4uiv(location, count, value);
6782}
6783
6784void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6785{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006786 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006787 ASSERT(programObject);
6788 programObject->setUniform1fv(location, count, value);
6789}
6790
6791void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6792{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006793 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006794 ASSERT(programObject);
6795 programObject->setUniform2fv(location, count, value);
6796}
6797
6798void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6799{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006800 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006801 ASSERT(programObject);
6802 programObject->setUniform3fv(location, count, value);
6803}
6804
6805void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6806{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006807 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006808 ASSERT(programObject);
6809 programObject->setUniform4fv(location, count, value);
6810}
6811
6812void Context::programUniformMatrix2fv(GLuint program,
6813 GLint location,
6814 GLsizei count,
6815 GLboolean transpose,
6816 const GLfloat *value)
6817{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006818 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006819 ASSERT(programObject);
6820 programObject->setUniformMatrix2fv(location, count, transpose, value);
6821}
6822
6823void Context::programUniformMatrix3fv(GLuint program,
6824 GLint location,
6825 GLsizei count,
6826 GLboolean transpose,
6827 const GLfloat *value)
6828{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006829 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006830 ASSERT(programObject);
6831 programObject->setUniformMatrix3fv(location, count, transpose, value);
6832}
6833
6834void Context::programUniformMatrix4fv(GLuint program,
6835 GLint location,
6836 GLsizei count,
6837 GLboolean transpose,
6838 const GLfloat *value)
6839{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006840 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006841 ASSERT(programObject);
6842 programObject->setUniformMatrix4fv(location, count, transpose, value);
6843}
6844
6845void Context::programUniformMatrix2x3fv(GLuint program,
6846 GLint location,
6847 GLsizei count,
6848 GLboolean transpose,
6849 const GLfloat *value)
6850{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006851 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006852 ASSERT(programObject);
6853 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6854}
6855
6856void Context::programUniformMatrix3x2fv(GLuint program,
6857 GLint location,
6858 GLsizei count,
6859 GLboolean transpose,
6860 const GLfloat *value)
6861{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006862 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006863 ASSERT(programObject);
6864 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6865}
6866
6867void Context::programUniformMatrix2x4fv(GLuint program,
6868 GLint location,
6869 GLsizei count,
6870 GLboolean transpose,
6871 const GLfloat *value)
6872{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006873 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006874 ASSERT(programObject);
6875 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6876}
6877
6878void Context::programUniformMatrix4x2fv(GLuint program,
6879 GLint location,
6880 GLsizei count,
6881 GLboolean transpose,
6882 const GLfloat *value)
6883{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006884 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006885 ASSERT(programObject);
6886 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6887}
6888
6889void Context::programUniformMatrix3x4fv(GLuint program,
6890 GLint location,
6891 GLsizei count,
6892 GLboolean transpose,
6893 const GLfloat *value)
6894{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006895 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006896 ASSERT(programObject);
6897 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6898}
6899
6900void Context::programUniformMatrix4x3fv(GLuint program,
6901 GLint location,
6902 GLsizei count,
6903 GLboolean transpose,
6904 const GLfloat *value)
6905{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006906 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006907 ASSERT(programObject);
6908 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6909}
6910
James Darpiniane8a93c62018-01-04 18:02:24 -08006911bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6912{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006913 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006914}
James Darpiniane8a93c62018-01-04 18:02:24 -08006915
Yunchao Hea336b902017-08-02 16:05:21 +08006916void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6917{
6918 for (int i = 0; i < count; i++)
6919 {
6920 pipelines[i] = createProgramPipeline();
6921 }
6922}
6923
6924void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6925{
6926 for (int i = 0; i < count; i++)
6927 {
6928 if (pipelines[i] != 0)
6929 {
6930 deleteProgramPipeline(pipelines[i]);
6931 }
6932 }
6933}
6934
6935GLboolean Context::isProgramPipeline(GLuint pipeline)
6936{
6937 if (pipeline == 0)
6938 {
6939 return GL_FALSE;
6940 }
6941
6942 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6943}
6944
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006945void Context::finishFenceNV(GLuint fence)
6946{
6947 FenceNV *fenceObject = getFenceNV(fence);
6948
6949 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006950 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006951}
6952
6953void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6954{
6955 FenceNV *fenceObject = getFenceNV(fence);
6956
6957 ASSERT(fenceObject && fenceObject->isSet());
6958
6959 switch (pname)
6960 {
6961 case GL_FENCE_STATUS_NV:
6962 {
6963 // GL_NV_fence spec:
6964 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6965 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6966 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6967 GLboolean status = GL_TRUE;
6968 if (fenceObject->getStatus() != GL_TRUE)
6969 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006970 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006971 }
6972 *params = status;
6973 break;
6974 }
6975
6976 case GL_FENCE_CONDITION_NV:
6977 {
6978 *params = static_cast<GLint>(fenceObject->getCondition());
6979 break;
6980 }
6981
6982 default:
6983 UNREACHABLE();
6984 }
6985}
6986
6987void Context::getTranslatedShaderSource(GLuint shader,
6988 GLsizei bufsize,
6989 GLsizei *length,
6990 GLchar *source)
6991{
6992 Shader *shaderObject = getShader(shader);
6993 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006994 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006995}
6996
6997void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6998{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006999 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007000 ASSERT(programObject);
7001
7002 programObject->getUniformfv(this, location, params);
7003}
7004
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007005void Context::getnUniformfvRobust(GLuint program,
7006 GLint location,
7007 GLsizei bufSize,
7008 GLsizei *length,
7009 GLfloat *params)
7010{
7011 UNIMPLEMENTED();
7012}
7013
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007014void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7015{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007016 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007017 ASSERT(programObject);
7018
7019 programObject->getUniformiv(this, location, params);
7020}
7021
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007022void Context::getnUniformivRobust(GLuint program,
7023 GLint location,
7024 GLsizei bufSize,
7025 GLsizei *length,
7026 GLint *params)
7027{
7028 UNIMPLEMENTED();
7029}
7030
7031void Context::getnUniformuivRobust(GLuint program,
7032 GLint location,
7033 GLsizei bufSize,
7034 GLsizei *length,
7035 GLuint *params)
7036{
7037 UNIMPLEMENTED();
7038}
7039
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007040GLboolean Context::isFenceNV(GLuint fence)
7041{
7042 FenceNV *fenceObject = getFenceNV(fence);
7043
7044 if (fenceObject == nullptr)
7045 {
7046 return GL_FALSE;
7047 }
7048
7049 // GL_NV_fence spec:
7050 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7051 // existing fence.
7052 return fenceObject->isSet();
7053}
7054
7055void Context::readnPixels(GLint x,
7056 GLint y,
7057 GLsizei width,
7058 GLsizei height,
7059 GLenum format,
7060 GLenum type,
7061 GLsizei bufSize,
7062 void *data)
7063{
7064 return readPixels(x, y, width, height, format, type, data);
7065}
7066
Jamie Madill007530e2017-12-28 14:27:04 -05007067void Context::setFenceNV(GLuint fence, GLenum condition)
7068{
7069 ASSERT(condition == GL_ALL_COMPLETED_NV);
7070
7071 FenceNV *fenceObject = getFenceNV(fence);
7072 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007073 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007074}
7075
7076GLboolean Context::testFenceNV(GLuint fence)
7077{
7078 FenceNV *fenceObject = getFenceNV(fence);
7079
7080 ASSERT(fenceObject != nullptr);
7081 ASSERT(fenceObject->isSet() == GL_TRUE);
7082
7083 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007084 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007085 {
Jamie Madill007530e2017-12-28 14:27:04 -05007086 return GL_TRUE;
7087 }
7088
7089 return result;
7090}
7091
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007092void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007093{
7094 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007095 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007096 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007097}
7098
Jamie Madillfa920eb2018-01-04 11:45:50 -05007099void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007100{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007101 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007102 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007103 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007104}
7105
Jamie Madillfa920eb2018-01-04 11:45:50 -05007106void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7107{
7108 UNIMPLEMENTED();
7109}
7110
Jamie Madill5b772312018-03-08 20:28:32 -05007111bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7112{
7113 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7114 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7115 // to the fact that it is stored internally as a float, and so would require conversion
7116 // if returned from Context::getIntegerv. Since this conversion is already implemented
7117 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7118 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7119 // application.
7120 switch (pname)
7121 {
7122 case GL_COMPRESSED_TEXTURE_FORMATS:
7123 {
7124 *type = GL_INT;
7125 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7126 return true;
7127 }
7128 case GL_SHADER_BINARY_FORMATS:
7129 {
7130 *type = GL_INT;
7131 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7132 return true;
7133 }
7134
7135 case GL_MAX_VERTEX_ATTRIBS:
7136 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7137 case GL_MAX_VARYING_VECTORS:
7138 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7139 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7140 case GL_MAX_TEXTURE_IMAGE_UNITS:
7141 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7142 case GL_MAX_RENDERBUFFER_SIZE:
7143 case GL_NUM_SHADER_BINARY_FORMATS:
7144 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7145 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007146 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7147 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007148 case GL_RENDERBUFFER_BINDING:
7149 case GL_CURRENT_PROGRAM:
7150 case GL_PACK_ALIGNMENT:
7151 case GL_UNPACK_ALIGNMENT:
7152 case GL_GENERATE_MIPMAP_HINT:
7153 case GL_RED_BITS:
7154 case GL_GREEN_BITS:
7155 case GL_BLUE_BITS:
7156 case GL_ALPHA_BITS:
7157 case GL_DEPTH_BITS:
7158 case GL_STENCIL_BITS:
7159 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7160 case GL_CULL_FACE_MODE:
7161 case GL_FRONT_FACE:
7162 case GL_ACTIVE_TEXTURE:
7163 case GL_STENCIL_FUNC:
7164 case GL_STENCIL_VALUE_MASK:
7165 case GL_STENCIL_REF:
7166 case GL_STENCIL_FAIL:
7167 case GL_STENCIL_PASS_DEPTH_FAIL:
7168 case GL_STENCIL_PASS_DEPTH_PASS:
7169 case GL_STENCIL_BACK_FUNC:
7170 case GL_STENCIL_BACK_VALUE_MASK:
7171 case GL_STENCIL_BACK_REF:
7172 case GL_STENCIL_BACK_FAIL:
7173 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7174 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7175 case GL_DEPTH_FUNC:
7176 case GL_BLEND_SRC_RGB:
7177 case GL_BLEND_SRC_ALPHA:
7178 case GL_BLEND_DST_RGB:
7179 case GL_BLEND_DST_ALPHA:
7180 case GL_BLEND_EQUATION_RGB:
7181 case GL_BLEND_EQUATION_ALPHA:
7182 case GL_STENCIL_WRITEMASK:
7183 case GL_STENCIL_BACK_WRITEMASK:
7184 case GL_STENCIL_CLEAR_VALUE:
7185 case GL_SUBPIXEL_BITS:
7186 case GL_MAX_TEXTURE_SIZE:
7187 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7188 case GL_SAMPLE_BUFFERS:
7189 case GL_SAMPLES:
7190 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7191 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7192 case GL_TEXTURE_BINDING_2D:
7193 case GL_TEXTURE_BINDING_CUBE_MAP:
7194 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7195 {
7196 *type = GL_INT;
7197 *numParams = 1;
7198 return true;
7199 }
7200 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7201 {
7202 if (!getExtensions().packReverseRowOrder)
7203 {
7204 return false;
7205 }
7206 *type = GL_INT;
7207 *numParams = 1;
7208 return true;
7209 }
7210 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7211 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7212 {
7213 if (!getExtensions().textureRectangle)
7214 {
7215 return false;
7216 }
7217 *type = GL_INT;
7218 *numParams = 1;
7219 return true;
7220 }
7221 case GL_MAX_DRAW_BUFFERS_EXT:
7222 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7223 {
7224 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7225 {
7226 return false;
7227 }
7228 *type = GL_INT;
7229 *numParams = 1;
7230 return true;
7231 }
7232 case GL_MAX_VIEWPORT_DIMS:
7233 {
7234 *type = GL_INT;
7235 *numParams = 2;
7236 return true;
7237 }
7238 case GL_VIEWPORT:
7239 case GL_SCISSOR_BOX:
7240 {
7241 *type = GL_INT;
7242 *numParams = 4;
7243 return true;
7244 }
7245 case GL_SHADER_COMPILER:
7246 case GL_SAMPLE_COVERAGE_INVERT:
7247 case GL_DEPTH_WRITEMASK:
7248 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7249 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7250 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7251 // bool-natural
7252 case GL_SAMPLE_COVERAGE:
7253 case GL_SCISSOR_TEST:
7254 case GL_STENCIL_TEST:
7255 case GL_DEPTH_TEST:
7256 case GL_BLEND:
7257 case GL_DITHER:
7258 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7259 {
7260 *type = GL_BOOL;
7261 *numParams = 1;
7262 return true;
7263 }
7264 case GL_COLOR_WRITEMASK:
7265 {
7266 *type = GL_BOOL;
7267 *numParams = 4;
7268 return true;
7269 }
7270 case GL_POLYGON_OFFSET_FACTOR:
7271 case GL_POLYGON_OFFSET_UNITS:
7272 case GL_SAMPLE_COVERAGE_VALUE:
7273 case GL_DEPTH_CLEAR_VALUE:
7274 case GL_LINE_WIDTH:
7275 {
7276 *type = GL_FLOAT;
7277 *numParams = 1;
7278 return true;
7279 }
7280 case GL_ALIASED_LINE_WIDTH_RANGE:
7281 case GL_ALIASED_POINT_SIZE_RANGE:
7282 case GL_DEPTH_RANGE:
7283 {
7284 *type = GL_FLOAT;
7285 *numParams = 2;
7286 return true;
7287 }
7288 case GL_COLOR_CLEAR_VALUE:
7289 case GL_BLEND_COLOR:
7290 {
7291 *type = GL_FLOAT;
7292 *numParams = 4;
7293 return true;
7294 }
7295 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7296 if (!getExtensions().textureFilterAnisotropic)
7297 {
7298 return false;
7299 }
7300 *type = GL_FLOAT;
7301 *numParams = 1;
7302 return true;
7303 case GL_TIMESTAMP_EXT:
7304 if (!getExtensions().disjointTimerQuery)
7305 {
7306 return false;
7307 }
7308 *type = GL_INT_64_ANGLEX;
7309 *numParams = 1;
7310 return true;
7311 case GL_GPU_DISJOINT_EXT:
7312 if (!getExtensions().disjointTimerQuery)
7313 {
7314 return false;
7315 }
7316 *type = GL_INT;
7317 *numParams = 1;
7318 return true;
7319 case GL_COVERAGE_MODULATION_CHROMIUM:
7320 if (!getExtensions().framebufferMixedSamples)
7321 {
7322 return false;
7323 }
7324 *type = GL_INT;
7325 *numParams = 1;
7326 return true;
7327 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7328 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7329 {
7330 return false;
7331 }
7332 *type = GL_INT;
7333 *numParams = 1;
7334 return true;
7335 }
7336
7337 if (getExtensions().debug)
7338 {
7339 switch (pname)
7340 {
7341 case GL_DEBUG_LOGGED_MESSAGES:
7342 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7343 case GL_DEBUG_GROUP_STACK_DEPTH:
7344 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7345 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7346 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7347 case GL_MAX_LABEL_LENGTH:
7348 *type = GL_INT;
7349 *numParams = 1;
7350 return true;
7351
7352 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7353 case GL_DEBUG_OUTPUT:
7354 *type = GL_BOOL;
7355 *numParams = 1;
7356 return true;
7357 }
7358 }
7359
7360 if (getExtensions().multisampleCompatibility)
7361 {
7362 switch (pname)
7363 {
7364 case GL_MULTISAMPLE_EXT:
7365 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7366 *type = GL_BOOL;
7367 *numParams = 1;
7368 return true;
7369 }
7370 }
7371
7372 if (getExtensions().pathRendering)
7373 {
7374 switch (pname)
7375 {
7376 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7377 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7378 *type = GL_FLOAT;
7379 *numParams = 16;
7380 return true;
7381 }
7382 }
7383
7384 if (getExtensions().bindGeneratesResource)
7385 {
7386 switch (pname)
7387 {
7388 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7389 *type = GL_BOOL;
7390 *numParams = 1;
7391 return true;
7392 }
7393 }
7394
7395 if (getExtensions().clientArrays)
7396 {
7397 switch (pname)
7398 {
7399 case GL_CLIENT_ARRAYS_ANGLE:
7400 *type = GL_BOOL;
7401 *numParams = 1;
7402 return true;
7403 }
7404 }
7405
7406 if (getExtensions().sRGBWriteControl)
7407 {
7408 switch (pname)
7409 {
7410 case GL_FRAMEBUFFER_SRGB_EXT:
7411 *type = GL_BOOL;
7412 *numParams = 1;
7413 return true;
7414 }
7415 }
7416
7417 if (getExtensions().robustResourceInitialization &&
7418 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7419 {
7420 *type = GL_BOOL;
7421 *numParams = 1;
7422 return true;
7423 }
7424
7425 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7426 {
7427 *type = GL_BOOL;
7428 *numParams = 1;
7429 return true;
7430 }
7431
jchen1082af6202018-06-22 10:59:52 +08007432 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7433 {
7434 *type = GL_INT;
7435 *numParams = 1;
7436 return true;
7437 }
7438
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007439 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7440 {
7441 *type = GL_INT;
7442 *numParams = 1;
7443 return true;
7444 }
7445
Jamie Madill5b772312018-03-08 20:28:32 -05007446 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7447 switch (pname)
7448 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007449 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007450 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7451 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7452 {
7453 return false;
7454 }
7455 *type = GL_INT;
7456 *numParams = 1;
7457 return true;
7458
7459 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7460 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7461 {
7462 return false;
7463 }
7464 *type = GL_INT;
7465 *numParams = 1;
7466 return true;
7467
7468 case GL_PROGRAM_BINARY_FORMATS_OES:
7469 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7470 {
7471 return false;
7472 }
7473 *type = GL_INT;
7474 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7475 return true;
7476
7477 case GL_PACK_ROW_LENGTH:
7478 case GL_PACK_SKIP_ROWS:
7479 case GL_PACK_SKIP_PIXELS:
7480 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7481 {
7482 return false;
7483 }
7484 *type = GL_INT;
7485 *numParams = 1;
7486 return true;
7487 case GL_UNPACK_ROW_LENGTH:
7488 case GL_UNPACK_SKIP_ROWS:
7489 case GL_UNPACK_SKIP_PIXELS:
7490 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7491 {
7492 return false;
7493 }
7494 *type = GL_INT;
7495 *numParams = 1;
7496 return true;
7497 case GL_VERTEX_ARRAY_BINDING:
7498 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7499 {
7500 return false;
7501 }
7502 *type = GL_INT;
7503 *numParams = 1;
7504 return true;
7505 case GL_PIXEL_PACK_BUFFER_BINDING:
7506 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7507 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7508 {
7509 return false;
7510 }
7511 *type = GL_INT;
7512 *numParams = 1;
7513 return true;
7514 case GL_MAX_SAMPLES:
7515 {
7516 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7517 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7518 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7519 {
7520 return false;
7521 }
7522 *type = GL_INT;
7523 *numParams = 1;
7524 return true;
7525
7526 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7527 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7528 {
7529 return false;
7530 }
7531 *type = GL_INT;
7532 *numParams = 1;
7533 return true;
7534 }
7535 }
7536
7537 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7538 {
7539 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7540 {
7541 return false;
7542 }
7543 *type = GL_INT;
7544 *numParams = 1;
7545 return true;
7546 }
7547
7548 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7549 {
7550 *type = GL_INT;
7551 *numParams = 1;
7552 return true;
7553 }
7554
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007555 if (getClientVersion() < Version(2, 0))
7556 {
7557 switch (pname)
7558 {
7559 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007560 case GL_CLIENT_ACTIVE_TEXTURE:
7561 case GL_MATRIX_MODE:
7562 case GL_MAX_TEXTURE_UNITS:
7563 case GL_MAX_MODELVIEW_STACK_DEPTH:
7564 case GL_MAX_PROJECTION_STACK_DEPTH:
7565 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007566 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007567 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007568 case GL_VERTEX_ARRAY_STRIDE:
7569 case GL_NORMAL_ARRAY_STRIDE:
7570 case GL_COLOR_ARRAY_STRIDE:
7571 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7572 case GL_VERTEX_ARRAY_SIZE:
7573 case GL_COLOR_ARRAY_SIZE:
7574 case GL_TEXTURE_COORD_ARRAY_SIZE:
7575 case GL_VERTEX_ARRAY_TYPE:
7576 case GL_NORMAL_ARRAY_TYPE:
7577 case GL_COLOR_ARRAY_TYPE:
7578 case GL_TEXTURE_COORD_ARRAY_TYPE:
7579 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7580 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7581 case GL_COLOR_ARRAY_BUFFER_BINDING:
7582 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7583 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7584 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7585 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007586 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007587 case GL_MODELVIEW_STACK_DEPTH:
7588 case GL_PROJECTION_STACK_DEPTH:
7589 case GL_TEXTURE_STACK_DEPTH:
7590 case GL_LOGIC_OP_MODE:
7591 case GL_BLEND_SRC:
7592 case GL_BLEND_DST:
7593 case GL_PERSPECTIVE_CORRECTION_HINT:
7594 case GL_POINT_SMOOTH_HINT:
7595 case GL_LINE_SMOOTH_HINT:
7596 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007597 *type = GL_INT;
7598 *numParams = 1;
7599 return true;
7600 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007601 case GL_FOG_DENSITY:
7602 case GL_FOG_START:
7603 case GL_FOG_END:
7604 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007605 case GL_POINT_SIZE:
7606 case GL_POINT_SIZE_MIN:
7607 case GL_POINT_SIZE_MAX:
7608 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007609 *type = GL_FLOAT;
7610 *numParams = 1;
7611 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007612 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007613 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007614 *type = GL_FLOAT;
7615 *numParams = 2;
7616 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007617 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007618 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007619 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007620 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007621 *type = GL_FLOAT;
7622 *numParams = 4;
7623 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007624 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007625 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007626 *type = GL_FLOAT;
7627 *numParams = 3;
7628 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007629 case GL_MODELVIEW_MATRIX:
7630 case GL_PROJECTION_MATRIX:
7631 case GL_TEXTURE_MATRIX:
7632 *type = GL_FLOAT;
7633 *numParams = 16;
7634 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007635 case GL_LIGHT_MODEL_TWO_SIDE:
7636 *type = GL_BOOL;
7637 *numParams = 1;
7638 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007639 }
7640 }
7641
Jamie Madill5b772312018-03-08 20:28:32 -05007642 if (getClientVersion() < Version(3, 0))
7643 {
7644 return false;
7645 }
7646
7647 // Check for ES3.0+ parameter names
7648 switch (pname)
7649 {
7650 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7651 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7652 case GL_UNIFORM_BUFFER_BINDING:
7653 case GL_TRANSFORM_FEEDBACK_BINDING:
7654 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7655 case GL_COPY_READ_BUFFER_BINDING:
7656 case GL_COPY_WRITE_BUFFER_BINDING:
7657 case GL_SAMPLER_BINDING:
7658 case GL_READ_BUFFER:
7659 case GL_TEXTURE_BINDING_3D:
7660 case GL_TEXTURE_BINDING_2D_ARRAY:
7661 case GL_MAX_3D_TEXTURE_SIZE:
7662 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7663 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7664 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7665 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7666 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7667 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7668 case GL_MAX_VARYING_COMPONENTS:
7669 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7670 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7671 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7672 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7673 case GL_NUM_EXTENSIONS:
7674 case GL_MAJOR_VERSION:
7675 case GL_MINOR_VERSION:
7676 case GL_MAX_ELEMENTS_INDICES:
7677 case GL_MAX_ELEMENTS_VERTICES:
7678 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7679 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7680 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7681 case GL_UNPACK_IMAGE_HEIGHT:
7682 case GL_UNPACK_SKIP_IMAGES:
7683 {
7684 *type = GL_INT;
7685 *numParams = 1;
7686 return true;
7687 }
7688
7689 case GL_MAX_ELEMENT_INDEX:
7690 case GL_MAX_UNIFORM_BLOCK_SIZE:
7691 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7692 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7693 case GL_MAX_SERVER_WAIT_TIMEOUT:
7694 {
7695 *type = GL_INT_64_ANGLEX;
7696 *numParams = 1;
7697 return true;
7698 }
7699
7700 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7701 case GL_TRANSFORM_FEEDBACK_PAUSED:
7702 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7703 case GL_RASTERIZER_DISCARD:
7704 {
7705 *type = GL_BOOL;
7706 *numParams = 1;
7707 return true;
7708 }
7709
7710 case GL_MAX_TEXTURE_LOD_BIAS:
7711 {
7712 *type = GL_FLOAT;
7713 *numParams = 1;
7714 return true;
7715 }
7716 }
7717
7718 if (getExtensions().requestExtension)
7719 {
7720 switch (pname)
7721 {
7722 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7723 *type = GL_INT;
7724 *numParams = 1;
7725 return true;
7726 }
7727 }
7728
Yizhou Jiang7818a852018-09-06 15:02:04 +08007729 if (getExtensions().textureMultisample)
7730 {
7731 switch (pname)
7732 {
7733 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7734 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7735 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7736 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007737 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007738 *type = GL_INT;
7739 *numParams = 1;
7740 return true;
7741 }
7742 }
7743
Jamie Madill5b772312018-03-08 20:28:32 -05007744 if (getClientVersion() < Version(3, 1))
7745 {
7746 return false;
7747 }
7748
7749 switch (pname)
7750 {
7751 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7752 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7753 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7754 case GL_MAX_FRAMEBUFFER_WIDTH:
7755 case GL_MAX_FRAMEBUFFER_HEIGHT:
7756 case GL_MAX_FRAMEBUFFER_SAMPLES:
7757 case GL_MAX_SAMPLE_MASK_WORDS:
7758 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7759 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7760 case GL_MAX_INTEGER_SAMPLES:
7761 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7762 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7763 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7764 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7765 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7766 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7767 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7768 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7769 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7770 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7771 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7772 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7773 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7774 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7775 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7776 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7777 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7778 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7779 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7780 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7781 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7782 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7783 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7784 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7785 case GL_MAX_UNIFORM_LOCATIONS:
7786 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7787 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7788 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7789 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7790 case GL_MAX_IMAGE_UNITS:
7791 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7792 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7793 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7794 case GL_SHADER_STORAGE_BUFFER_BINDING:
7795 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7796 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007797 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007798 *type = GL_INT;
7799 *numParams = 1;
7800 return true;
7801 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7802 *type = GL_INT_64_ANGLEX;
7803 *numParams = 1;
7804 return true;
7805 case GL_SAMPLE_MASK:
7806 *type = GL_BOOL;
7807 *numParams = 1;
7808 return true;
7809 }
7810
7811 if (getExtensions().geometryShader)
7812 {
7813 switch (pname)
7814 {
7815 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7816 case GL_LAYER_PROVOKING_VERTEX_EXT:
7817 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7818 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7819 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7820 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7821 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7822 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7823 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7824 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7825 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7826 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7827 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7828 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7829 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7830 *type = GL_INT;
7831 *numParams = 1;
7832 return true;
7833 }
7834 }
7835
7836 return false;
7837}
7838
7839bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7840{
7841 if (getClientVersion() < Version(3, 0))
7842 {
7843 return false;
7844 }
7845
7846 switch (target)
7847 {
7848 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7849 case GL_UNIFORM_BUFFER_BINDING:
7850 {
7851 *type = GL_INT;
7852 *numParams = 1;
7853 return true;
7854 }
7855 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7856 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7857 case GL_UNIFORM_BUFFER_START:
7858 case GL_UNIFORM_BUFFER_SIZE:
7859 {
7860 *type = GL_INT_64_ANGLEX;
7861 *numParams = 1;
7862 return true;
7863 }
7864 }
7865
7866 if (getClientVersion() < Version(3, 1))
7867 {
7868 return false;
7869 }
7870
7871 switch (target)
7872 {
7873 case GL_IMAGE_BINDING_LAYERED:
7874 {
7875 *type = GL_BOOL;
7876 *numParams = 1;
7877 return true;
7878 }
7879 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7880 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7881 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7882 case GL_SHADER_STORAGE_BUFFER_BINDING:
7883 case GL_VERTEX_BINDING_BUFFER:
7884 case GL_VERTEX_BINDING_DIVISOR:
7885 case GL_VERTEX_BINDING_OFFSET:
7886 case GL_VERTEX_BINDING_STRIDE:
7887 case GL_SAMPLE_MASK_VALUE:
7888 case GL_IMAGE_BINDING_NAME:
7889 case GL_IMAGE_BINDING_LEVEL:
7890 case GL_IMAGE_BINDING_LAYER:
7891 case GL_IMAGE_BINDING_ACCESS:
7892 case GL_IMAGE_BINDING_FORMAT:
7893 {
7894 *type = GL_INT;
7895 *numParams = 1;
7896 return true;
7897 }
7898 case GL_ATOMIC_COUNTER_BUFFER_START:
7899 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7900 case GL_SHADER_STORAGE_BUFFER_START:
7901 case GL_SHADER_STORAGE_BUFFER_SIZE:
7902 {
7903 *type = GL_INT_64_ANGLEX;
7904 *numParams = 1;
7905 return true;
7906 }
7907 }
7908
7909 return false;
7910}
7911
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007912Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007913{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007914 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007915}
7916
7917Shader *Context::getShader(GLuint handle) const
7918{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007919 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007920}
7921
Jamie Madill5b772312018-03-08 20:28:32 -05007922bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7923{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007924 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007925}
7926
7927bool Context::isFramebufferGenerated(GLuint framebuffer) const
7928{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007929 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007930}
7931
7932bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7933{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007934 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007935}
7936
7937bool Context::usingDisplayTextureShareGroup() const
7938{
7939 return mDisplayTextureShareGroup;
7940}
7941
7942GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7943{
7944 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7945 internalformat == GL_DEPTH_STENCIL
7946 ? GL_DEPTH24_STENCIL8
7947 : internalformat;
7948}
7949
jchen1082af6202018-06-22 10:59:52 +08007950void Context::maxShaderCompilerThreads(GLuint count)
7951{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007952 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7953 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007954 // A count of zero specifies a request for no parallel compiling or linking.
7955 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7956 {
7957 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7958 }
7959 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007960}
7961
Jamie Madill2eb65032018-07-30 10:25:57 -04007962bool Context::isGLES1() const
7963{
7964 return mState.getClientVersion() < Version(2, 0);
7965}
7966
Jamie Madilla11819d2018-07-30 10:26:01 -04007967void Context::onSubjectStateChange(const Context *context,
7968 angle::SubjectIndex index,
7969 angle::SubjectMessage message)
7970{
Jamie Madilla11819d2018-07-30 10:26:01 -04007971 switch (index)
7972 {
7973 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007974 switch (message)
7975 {
7976 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007977 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007978 mStateCache.onVertexArrayBufferContentsChange(this);
7979 break;
7980 case angle::SubjectMessage::RESOURCE_MAPPED:
7981 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7982 case angle::SubjectMessage::BINDING_CHANGED:
7983 mStateCache.onVertexArrayBufferStateChange(this);
7984 break;
7985 default:
7986 break;
7987 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007988 break;
7989
7990 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007991 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7992 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007993 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04007994 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007995 break;
7996
7997 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007998 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7999 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008000 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008001 }
8002 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008003 break;
8004
8005 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008006 if (index < kTextureMaxSubjectIndex)
8007 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008008 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008009 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008010 }
Jamie Madille25b8002018-09-20 13:39:49 -04008011 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008012 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008013 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008014 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008015 }
Jamie Madille25b8002018-09-20 13:39:49 -04008016 else
8017 {
8018 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008019 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008020 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008021 break;
8022 }
8023}
8024
Jamie Madill6b873dd2018-07-12 23:56:30 -04008025// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008026ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008027
8028ErrorSet::~ErrorSet() = default;
8029
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008030void ErrorSet::handleError(GLenum errorCode,
8031 const char *message,
8032 const char *file,
8033 const char *function,
8034 unsigned int line)
8035{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008036 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8037 {
8038 mContext->markContextLost();
8039 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008040
Jamie Madill4f6592f2018-11-27 16:37:45 -05008041 std::stringstream errorStream;
8042 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8043 << line << ". " << message;
8044
Geoff Lang7139b432018-12-14 16:57:28 -05008045 std::string formattedMessage = errorStream.str();
8046
8047 // Always log a warning, this function is only called on unexpected internal errors.
8048 WARN() << formattedMessage;
8049
Jamie Madill4f6592f2018-11-27 16:37:45 -05008050 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008051 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008052}
8053
Jamie Madilla139f012018-10-10 16:13:03 -04008054void ErrorSet::validationError(GLenum errorCode, const char *message)
8055{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008056 ASSERT(errorCode != GL_NO_ERROR);
8057 mErrors.insert(errorCode);
8058
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008059 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8060 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008061}
8062
Jamie Madill6b873dd2018-07-12 23:56:30 -04008063bool ErrorSet::empty() const
8064{
8065 return mErrors.empty();
8066}
8067
8068GLenum ErrorSet::popError()
8069{
8070 ASSERT(!empty());
8071 GLenum error = *mErrors.begin();
8072 mErrors.erase(mErrors.begin());
8073 return error;
8074}
Jamie Madilldc358af2018-07-31 11:22:13 -04008075
8076// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008077StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008078 : mCachedHasAnyEnabledClientAttrib(false),
8079 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008080 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008081 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008082 mCachedBasicDrawElementsError(kInvalidPointer),
8083 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008084{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008085
8086StateCache::~StateCache() = default;
8087
Jamie Madillac66f982018-10-09 18:30:01 -04008088void StateCache::initialize(Context *context)
8089{
8090 updateValidDrawModes(context);
8091 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008092 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008093 updateBasicDrawStatesError();
8094 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008095}
8096
Jamie Madilldc358af2018-07-31 11:22:13 -04008097void StateCache::updateActiveAttribsMask(Context *context)
8098{
8099 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008100 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008101
8102 if (!isGLES1 && !glState.getProgram())
8103 {
8104 mCachedActiveBufferedAttribsMask = AttributesMask();
8105 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008106 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008107 return;
8108 }
8109
8110 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8111 : glState.getProgram()->getActiveAttribLocationsMask();
8112
8113 const VertexArray *vao = glState.getVertexArray();
8114 ASSERT(vao);
8115
8116 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8117 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008118 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008119
Jamie Madill0a17e482018-08-31 17:19:11 -04008120 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8121 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008122 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008123 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8124}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008125
8126void StateCache::updateVertexElementLimits(Context *context)
8127{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008128 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008129
8130 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8131 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8132
8133 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8134 // If there are no buffered attributes then we should not limit the draw call count.
8135 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8136 {
8137 return;
8138 }
8139
8140 const auto &vertexAttribs = vao->getVertexAttributes();
8141 const auto &vertexBindings = vao->getVertexBindings();
8142
8143 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8144 {
8145 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008146
8147 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8148 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008149 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008150
8151 GLint64 limit = attrib.getCachedElementLimit();
8152 if (binding.getDivisor() > 0)
8153 {
8154 mCachedInstancedVertexElementLimit =
8155 std::min(mCachedInstancedVertexElementLimit, limit);
8156 }
8157 else
8158 {
8159 mCachedNonInstancedVertexElementLimit =
8160 std::min(mCachedNonInstancedVertexElementLimit, limit);
8161 }
8162 }
8163}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008164
Jamie Madilld84b6732018-09-06 15:54:35 -04008165void StateCache::updateBasicDrawStatesError()
8166{
8167 mCachedBasicDrawStatesError = kInvalidPointer;
8168}
8169
Jamie Madill1e853262018-12-21 09:07:38 -05008170void StateCache::updateBasicDrawElementsError()
8171{
8172 mCachedBasicDrawElementsError = kInvalidPointer;
8173}
8174
Jamie Madilld84b6732018-09-06 15:54:35 -04008175intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8176{
8177 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8178 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8179 return mCachedBasicDrawStatesError;
8180}
8181
Jamie Madill1e853262018-12-21 09:07:38 -05008182intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8183{
8184 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8185 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8186 return mCachedBasicDrawElementsError;
8187}
8188
Jamie Madillc43cdad2018-08-08 15:49:25 -04008189void StateCache::onVertexArrayBindingChange(Context *context)
8190{
8191 updateActiveAttribsMask(context);
8192 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008193 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008194}
8195
8196void StateCache::onProgramExecutableChange(Context *context)
8197{
8198 updateActiveAttribsMask(context);
8199 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008200 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008201 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008202}
8203
Jamie Madilld84b6732018-09-06 15:54:35 -04008204void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008205{
8206 updateVertexElementLimits(context);
8207}
8208
Jamie Madilld84b6732018-09-06 15:54:35 -04008209void StateCache::onVertexArrayBufferContentsChange(Context *context)
8210{
8211 updateVertexElementLimits(context);
8212 updateBasicDrawStatesError();
8213}
8214
Jamie Madillc43cdad2018-08-08 15:49:25 -04008215void StateCache::onVertexArrayStateChange(Context *context)
8216{
8217 updateActiveAttribsMask(context);
8218 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008219 updateBasicDrawStatesError();
8220}
8221
8222void StateCache::onVertexArrayBufferStateChange(Context *context)
8223{
8224 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008225 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008226}
8227
8228void StateCache::onGLES1ClientStateChange(Context *context)
8229{
8230 updateActiveAttribsMask(context);
8231}
Jamie Madilld84b6732018-09-06 15:54:35 -04008232
8233void StateCache::onDrawFramebufferChange(Context *context)
8234{
8235 updateBasicDrawStatesError();
8236}
8237
8238void StateCache::onContextCapChange(Context *context)
8239{
8240 updateBasicDrawStatesError();
8241}
8242
8243void StateCache::onStencilStateChange(Context *context)
8244{
8245 updateBasicDrawStatesError();
8246}
8247
8248void StateCache::onDefaultVertexAttributeChange(Context *context)
8249{
8250 updateBasicDrawStatesError();
8251}
8252
8253void StateCache::onActiveTextureChange(Context *context)
8254{
8255 updateBasicDrawStatesError();
8256}
8257
8258void StateCache::onQueryChange(Context *context)
8259{
8260 updateBasicDrawStatesError();
8261}
8262
Jamie Madill3a256222018-12-08 09:56:39 -05008263void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008264{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008265 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008266 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008267 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008268 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008269}
8270
8271void StateCache::onUniformBufferStateChange(Context *context)
8272{
8273 updateBasicDrawStatesError();
8274}
8275
Jamie Madill9b025062018-12-12 15:44:12 -05008276void StateCache::setValidDrawModes(bool pointsOK,
8277 bool linesOK,
8278 bool trisOK,
8279 bool lineAdjOK,
8280 bool triAdjOK)
8281{
8282 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8283 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8284 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8285 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8286 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8287 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8288 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8289 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8290 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8291 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8292 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8293}
8294
Jamie Madill526a6f62018-09-12 11:03:05 -04008295void StateCache::updateValidDrawModes(Context *context)
8296{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008297 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008298 Program *program = state.getProgram();
8299
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008300 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008301 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008302 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8303
Jamie Madill9b025062018-12-12 15:44:12 -05008304 // ES Spec 3.0 validation text:
8305 // When transform feedback is active and not paused, all geometric primitives generated must
8306 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8307 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8308 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8309 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8310 // active and not paused, regardless of mode. Any primitive type may be used while transform
8311 // feedback is paused.
8312 if (!context->getExtensions().geometryShader)
8313 {
8314 mCachedValidDrawModes.fill(false);
8315 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8316 return;
8317 }
8318
8319 // EXT_geometry_shader validation text:
8320 // When transform feedback is active and not paused, all geometric primitives generated must
8321 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8322 // geometry shader is active, the type of primitive emitted by that shader is used instead
8323 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8324 // Any primitive type may be used while transform feedback is paused.
8325 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8326 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8327 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8328
8329 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8330 return;
8331 }
8332
Jamie Madill526a6f62018-09-12 11:03:05 -04008333 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8334 {
Jamie Madill752d2202018-11-27 13:29:48 -05008335 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008336 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008337 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008338
Jamie Madill9b025062018-12-12 15:44:12 -05008339 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8340 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008341
Jamie Madill9b025062018-12-12 15:44:12 -05008342 bool pointsOK = gsMode == PrimitiveMode::Points;
8343 bool linesOK = gsMode == PrimitiveMode::Lines;
8344 bool trisOK = gsMode == PrimitiveMode::Triangles;
8345 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8346 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8347
8348 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008349}
Jamie Madillac66f982018-10-09 18:30:01 -04008350
8351void StateCache::updateValidBindTextureTypes(Context *context)
8352{
8353 const Extensions &exts = context->getExtensions();
8354 bool isGLES3 = context->getClientMajorVersion() >= 3;
8355 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8356
8357 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008358 {TextureType::_2D, true},
8359 {TextureType::_2DArray, isGLES3},
8360 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8361 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8362 {TextureType::_3D, isGLES3},
8363 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8364 {TextureType::Rectangle, exts.textureRectangle},
8365 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008366 }};
8367}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008368
8369void StateCache::updateValidDrawElementsTypes(Context *context)
8370{
8371 bool supportsUint =
8372 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8373
8374 mCachedValidDrawElementsTypes = {{
8375 {DrawElementsType::UnsignedByte, true},
8376 {DrawElementsType::UnsignedShort, true},
8377 {DrawElementsType::UnsignedInt, supportsUint},
8378 }};
8379}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008380
8381void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8382{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008383 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008384 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8385}
Jamie Madillc29968b2016-01-20 11:17:23 -05008386} // namespace gl