blob: 0ffd4b51091abd63c42d9c4ea5180460167f1b69 [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)),
Jamie Madilld51fbe32019-01-25 15:03:39 -0500309 mBufferAccessValidationEnabled(false),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400310 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400311 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400312 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
313 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
314 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400315 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800316 mZeroFilledBuffer(1000u),
317 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000318{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400319 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
320 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
321 {
322 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
323 }
Jamie Madille25b8002018-09-20 13:39:49 -0400324
325 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
326 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
327 {
328 mSamplerObserverBindings.emplace_back(this, samplerIndex);
329 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400330}
Jamie Madill5b772312018-03-08 20:28:32 -0500331
Geoff Lang33f11fb2018-05-07 13:42:47 -0400332void Context::initialize()
333{
334 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400335
Geoff Lang33f11fb2018-05-07 13:42:47 -0400336 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700337 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400338
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500339 mState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100340
Shannon Woods53a94a82014-06-24 15:20:36 -0400341 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400342
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000343 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400344 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000345 // and cube map texture state vectors respectively associated with them.
346 // In order that access to these initial textures not be lost, they are treated as texture
347 // objects all of whose names are 0.
348
Corentin Wallez99d492c2018-02-27 15:17:10 -0500349 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800350 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500351
Corentin Wallez99d492c2018-02-27 15:17:10 -0500352 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800353 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400354
Geoff Langeb66a6e2016-10-31 13:06:12 -0400355 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400356 {
357 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500358 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800359 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400360
Corentin Wallez99d492c2018-02-27 15:17:10 -0500361 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800362 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400363 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800364 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400365 {
366 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500367 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800368 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800369 }
370 if (getClientVersion() >= Version(3, 1))
371 {
Olli Etuahod310a432018-08-24 15:40:23 +0300372 Texture *zeroTexture2DMultisampleArray =
373 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
374 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800375
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500376 for (unsigned int i = 0; i < mState.mCaps.maxAtomicCounterBufferBindings; i++)
Jiajia Qin6eafb042016-12-27 17:04:07 +0800377 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800378 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800379 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800380
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500381 for (unsigned int i = 0; i < mState.mCaps.maxShaderStorageBufferBindings; i++)
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800382 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400383 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800384 }
Geoff Lang3b573612016-10-31 14:08:10 -0400385 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000386
Geoff Langb0f917f2017-12-05 13:41:54 -0500387 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400388 {
389 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400392 }
393
Geoff Langb0f917f2017-12-05 13:41:54 -0500394 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400395 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500396 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800397 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400398 }
399
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500400 mState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500401
Jamie Madill57a89722013-07-02 11:57:03 -0400402 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000403
Geoff Langeb66a6e2016-10-31 13:06:12 -0400404 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400405 {
406 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
407 // In the initial state, a default transform feedback object is bound and treated as
408 // a transform feedback object with a name of zero. That object is bound any time
409 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400410 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400411 }
Geoff Langc8058452014-02-03 12:04:11 -0500412
Corentin Wallez336129f2017-10-17 15:55:40 -0400413 for (auto type : angle::AllEnums<BufferBinding>())
414 {
415 bindBuffer(type, 0);
416 }
417
418 bindRenderbuffer(GL_RENDERBUFFER, 0);
419
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500420 for (unsigned int i = 0; i < mState.mCaps.maxUniformBufferBindings; i++)
Corentin Wallez336129f2017-10-17 15:55:40 -0400421 {
422 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
423 }
424
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700425 // Initialize GLES1 renderer if appropriate.
426 if (getClientVersion() < Version(2, 0))
427 {
428 mGLES1Renderer.reset(new GLES1Renderer());
429 }
430
Jamie Madillad9f24e2016-02-12 09:27:24 -0500431 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400432 mAllDirtyBits.set();
433
Geoff Lang9bf86f02018-07-26 11:46:34 -0400434 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
435 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500436 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400437 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400438 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400439
440 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
441 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500442 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400443 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400444
Jamie Madillc67323a2017-11-02 23:11:41 -0400445 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500446 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500447 // No dirty objects.
448
449 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400450 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500451 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400452 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500453 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
454
455 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
456 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
457 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
458 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
459 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
460 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
461 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
462 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
463 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
464 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
465 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400466 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500467 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
468
469 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
470 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700471 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400472 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
473 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500474 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
475 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400476
Xinghua Cao10a4d432017-11-28 14:46:26 +0800477 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800478 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
479 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800480 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
481 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
482 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
483 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800484 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800485 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500486 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400487 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400488 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800489
Jamie Madill4f6592f2018-11-27 16:37:45 -0500490 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491}
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700495 if (mGLES1Renderer)
496 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500497 mGLES1Renderer->onDestroy(this, &mState);
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700498 }
499
Jamie Madille7b3fe22018-04-05 09:42:46 -0400500 ANGLE_TRY(releaseSurface(display));
501
Corentin Wallez80b24112015-08-25 16:41:57 -0400502 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400504 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400506 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507
Corentin Wallez80b24112015-08-25 16:41:57 -0400508 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400510 if (query.second != nullptr)
511 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400513 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400515 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000516
Corentin Wallez80b24112015-08-25 16:41:57 -0400517 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400518 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 if (vertexArray.second)
520 {
521 vertexArray.second->onDestroy(this);
522 }
Jamie Madill57a89722013-07-02 11:57:03 -0400523 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400524 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400525
Corentin Wallez80b24112015-08-25 16:41:57 -0400526 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500527 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500528 if (transformFeedback.second != nullptr)
529 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500530 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500531 }
Geoff Langc8058452014-02-03 12:04:11 -0500532 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400533 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500534
Jamie Madill5b772312018-03-08 20:28:32 -0500535 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400536 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800537 if (zeroTexture.get() != nullptr)
538 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800539 zeroTexture.set(this, nullptr);
540 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400541 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
Jamie Madill2f348d22017-06-05 10:50:59 -0400543 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500544
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500545 mState.reset(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400546
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500547 mState.mBufferManager->release(this);
548 mState.mShaderProgramManager->release(this);
549 mState.mTextureManager->release(this);
550 mState.mRenderbufferManager->release(this);
551 mState.mSamplerManager->release(this);
552 mState.mSyncManager->release(this);
553 mState.mPathManager->release(this);
554 mState.mFramebufferManager->release(this);
555 mState.mProgramPipelineManager->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400556
jchen107ae70d82018-07-06 13:47:01 +0800557 mThreadPool.reset();
558
Jamie Madill76e471e2017-10-21 09:56:01 -0400559 mImplementation->onDestroy(this);
560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000562}
563
Jamie Madillb980c562018-11-27 11:34:27 -0500564Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500565
Geoff Lang75359662018-04-11 01:42:27 -0400566void Context::setLabel(EGLLabelKHR label)
567{
568 mLabel = label;
569}
570
571EGLLabelKHR Context::getLabel() const
572{
573 return mLabel;
574}
575
Jamie Madill4928b7c2017-06-20 12:57:39 -0400576egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000577{
Jamie Madill61e16b42017-06-19 11:13:23 -0400578 mCurrentDisplay = display;
579
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000580 if (!mHasBeenCurrent)
581 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400582 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500584 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400585 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586
Corentin Wallezc295e512017-01-27 17:47:50 -0500587 int width = 0;
588 int height = 0;
589 if (surface != nullptr)
590 {
591 width = surface->getWidth();
592 height = surface->getHeight();
593 }
594
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500595 mState.setViewportParams(0, 0, width, height);
596 mState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597
598 mHasBeenCurrent = true;
599 }
600
Jamie Madill1b94d432015-08-07 13:23:23 -0400601 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500602 mState.setAllDirtyBits();
603 mState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400604
Jamie Madill4928b7c2017-06-20 12:57:39 -0400605 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500606
607 Framebuffer *newDefault = nullptr;
608 if (surface != nullptr)
609 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400610 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500611 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400612 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500613 }
614 else
615 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400616 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500617 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000618
Corentin Wallez37c39792015-08-20 14:19:46 -0400619 // Update default framebuffer, the binding of the previous default
620 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400621 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500622 mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
623 if (mState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400624 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400625 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400626 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500627 if (mState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400628 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400629 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400630 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400631 }
Ian Ewell292f0052016-02-04 10:37:32 -0500632
Jamie Madill32643ce2018-10-19 11:38:03 -0400633 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500634 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635}
636
Jamie Madill4928b7c2017-06-20 12:57:39 -0400637egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400638{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500639 gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400640
Geoff Langbf7b95d2018-05-01 16:48:21 -0400641 // Remove the default framebuffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500642 if (mState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500643 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500644 mState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400645 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400647
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500648 if (mState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500649 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500650 mState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400651 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500652 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400653
654 if (defaultFramebuffer)
655 {
656 defaultFramebuffer->onDestroy(this);
657 delete defaultFramebuffer;
658 }
659
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500660 mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500661
662 if (mCurrentSurface)
663 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500665 mCurrentSurface = nullptr;
666 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400667
668 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400669}
670
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671GLuint Context::createBuffer()
672{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500673 return mState.mBufferManager->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676GLuint Context::createProgram()
677{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500678 return mState.mShaderProgramManager->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
Jiawei Shao385b3e02018-03-21 09:43:28 +0800681GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500683 return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
684 type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687GLuint Context::createTexture()
688{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500689 return mState.mTextureManager->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692GLuint Context::createRenderbuffer()
693{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500694 return mState.mRenderbufferManager->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
Jamie Madill13951342018-09-30 15:24:28 -0400697void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
698{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500699 ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400700}
701
Brandon Jones59770802018-04-02 13:18:42 -0700702GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300703{
Jamie Madill13951342018-09-30 15:24:28 -0400704 GLuint created = 0;
705 tryGenPaths(range, &created);
706 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300707}
708
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000709// Returns an unused framebuffer name
710GLuint Context::createFramebuffer()
711{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500712 return mState.mFramebufferManager->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713}
714
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500715void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500717 for (int i = 0; i < n; i++)
718 {
719 GLuint handle = mFenceNVHandleAllocator.allocate();
720 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
721 fences[i] = handle;
722 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723}
724
Yunchao Hea336b902017-08-02 16:05:21 +0800725GLuint Context::createProgramPipeline()
726{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500727 return mState.mProgramPipelineManager->createProgramPipeline();
Yunchao Hea336b902017-08-02 16:05:21 +0800728}
729
Jiawei Shao385b3e02018-03-21 09:43:28 +0800730GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800731{
732 UNIMPLEMENTED();
733 return 0u;
734}
735
James Darpinian4d9d4832018-03-13 12:43:28 -0700736void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000737{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500738 Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
James Darpinian4d9d4832018-03-13 12:43:28 -0700739 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000740 {
741 detachBuffer(buffer);
742 }
Jamie Madill893ab082014-05-16 16:56:10 -0400743
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500744 mState.mBufferManager->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000745}
746
747void Context::deleteShader(GLuint shader)
748{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500749 mState.mShaderProgramManager->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000750}
751
752void Context::deleteProgram(GLuint program)
753{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500754 mState.mShaderProgramManager->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000755}
756
757void Context::deleteTexture(GLuint texture)
758{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500759 if (mState.mTextureManager->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760 {
761 detachTexture(texture);
762 }
763
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500764 mState.mTextureManager->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000765}
766
767void Context::deleteRenderbuffer(GLuint renderbuffer)
768{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500769 if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770 {
771 detachRenderbuffer(renderbuffer);
772 }
Jamie Madill893ab082014-05-16 16:56:10 -0400773
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500774 mState.mRenderbufferManager->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000775}
776
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400777void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400778{
779 // The spec specifies the underlying Fence object is not deleted until all current
780 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
781 // and since our API is currently designed for being called from a single thread, we can delete
782 // the fence immediately.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500783 mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400784}
785
Yunchao Hea336b902017-08-02 16:05:21 +0800786void Context::deleteProgramPipeline(GLuint pipeline)
787{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500788 if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
Yunchao Hea336b902017-08-02 16:05:21 +0800789 {
790 detachProgramPipeline(pipeline);
791 }
792
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500793 mState.mProgramPipelineManager->deleteObject(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +0800794}
795
Sami Väisänene45e53b2016-05-25 10:36:04 +0300796void Context::deletePaths(GLuint first, GLsizei range)
797{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500798 mState.mPathManager->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300799}
800
Brandon Jones59770802018-04-02 13:18:42 -0700801bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300802{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500803 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300804 if (pathObj == nullptr)
805 return false;
806
807 return pathObj->hasPathData();
808}
809
Brandon Jones59770802018-04-02 13:18:42 -0700810bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300811{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500812 return mState.mPathManager->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300813}
814
Brandon Jones59770802018-04-02 13:18:42 -0700815void Context::pathCommands(GLuint path,
816 GLsizei numCommands,
817 const GLubyte *commands,
818 GLsizei numCoords,
819 GLenum coordType,
820 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300821{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500822 auto *pathObject = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823
Jamie Madill4f6592f2018-11-27 16:37:45 -0500824 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825}
826
Jamie Madill007530e2017-12-28 14:27:04 -0500827void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300828{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500829 Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300830
831 switch (pname)
832 {
833 case GL_PATH_STROKE_WIDTH_CHROMIUM:
834 pathObj->setStrokeWidth(value);
835 break;
836 case GL_PATH_END_CAPS_CHROMIUM:
837 pathObj->setEndCaps(static_cast<GLenum>(value));
838 break;
839 case GL_PATH_JOIN_STYLE_CHROMIUM:
840 pathObj->setJoinStyle(static_cast<GLenum>(value));
841 break;
842 case GL_PATH_MITER_LIMIT_CHROMIUM:
843 pathObj->setMiterLimit(value);
844 break;
845 case GL_PATH_STROKE_BOUND_CHROMIUM:
846 pathObj->setStrokeBound(value);
847 break;
848 default:
849 UNREACHABLE();
850 break;
851 }
852}
853
Jamie Madill007530e2017-12-28 14:27:04 -0500854void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855{
Jamie Madill007530e2017-12-28 14:27:04 -0500856 // TODO(jmadill): Should use proper clamping/casting.
857 pathParameterf(path, pname, static_cast<GLfloat>(value));
858}
859
860void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
861{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500862 const Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300863
864 switch (pname)
865 {
866 case GL_PATH_STROKE_WIDTH_CHROMIUM:
867 *value = pathObj->getStrokeWidth();
868 break;
869 case GL_PATH_END_CAPS_CHROMIUM:
870 *value = static_cast<GLfloat>(pathObj->getEndCaps());
871 break;
872 case GL_PATH_JOIN_STYLE_CHROMIUM:
873 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
874 break;
875 case GL_PATH_MITER_LIMIT_CHROMIUM:
876 *value = pathObj->getMiterLimit();
877 break;
878 case GL_PATH_STROKE_BOUND_CHROMIUM:
879 *value = pathObj->getStrokeBound();
880 break;
881 default:
882 UNREACHABLE();
883 break;
884 }
885}
886
Jamie Madill007530e2017-12-28 14:27:04 -0500887void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
888{
889 GLfloat val = 0.0f;
890 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
891 if (value)
892 *value = static_cast<GLint>(val);
893}
894
Brandon Jones59770802018-04-02 13:18:42 -0700895void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300896{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500897 mState.setPathStencilFunc(func, ref, mask);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300898}
899
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000900void Context::deleteFramebuffer(GLuint framebuffer)
901{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500902 if (mState.mFramebufferManager->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000903 {
904 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000905 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500906
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500907 mState.mFramebufferManager->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000908}
909
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500910void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000911{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500912 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000913 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500914 GLuint fence = fences[i];
915
916 FenceNV *fenceObject = nullptr;
917 if (mFenceNVMap.erase(fence, &fenceObject))
918 {
919 mFenceNVHandleAllocator.release(fence);
920 delete fenceObject;
921 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000922 }
923}
924
Geoff Lang70d0f492015-12-10 17:45:46 -0500925Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000926{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500927 return mState.mBufferManager->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000928}
929
Geoff Lang70d0f492015-12-10 17:45:46 -0500930Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000931{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500932 return mState.mRenderbufferManager->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000933}
934
Jamie Madill70b5bb02017-08-28 13:32:37 -0400935Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400936{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500937 return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400938}
939
Jamie Madill57a89722013-07-02 11:57:03 -0400940VertexArray *Context::getVertexArray(GLuint handle) const
941{
Jamie Madill96a483b2017-06-27 16:49:21 -0400942 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400943}
944
Jamie Madilldc356042013-07-19 16:36:57 -0400945Sampler *Context::getSampler(GLuint handle) const
946{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500947 return mState.mSamplerManager->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400948}
949
Geoff Langc8058452014-02-03 12:04:11 -0500950TransformFeedback *Context::getTransformFeedback(GLuint handle) const
951{
Jamie Madill96a483b2017-06-27 16:49:21 -0400952 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500953}
954
Yunchao Hea336b902017-08-02 16:05:21 +0800955ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
956{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500957 return mState.mProgramPipelineManager->getProgramPipeline(handle);
Yunchao Hea336b902017-08-02 16:05:21 +0800958}
959
Geoff Lang75359662018-04-11 01:42:27 -0400960gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500961{
962 switch (identifier)
963 {
964 case GL_BUFFER:
965 return getBuffer(name);
966 case GL_SHADER:
967 return getShader(name);
968 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -0400969 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -0500970 case GL_VERTEX_ARRAY:
971 return getVertexArray(name);
972 case GL_QUERY:
973 return getQuery(name);
974 case GL_TRANSFORM_FEEDBACK:
975 return getTransformFeedback(name);
976 case GL_SAMPLER:
977 return getSampler(name);
978 case GL_TEXTURE:
979 return getTexture(name);
980 case GL_RENDERBUFFER:
981 return getRenderbuffer(name);
982 case GL_FRAMEBUFFER:
983 return getFramebuffer(name);
984 default:
985 UNREACHABLE();
986 return nullptr;
987 }
988}
989
Geoff Lang75359662018-04-11 01:42:27 -0400990gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500991{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400992 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500993}
994
Martin Radev9d901792016-07-15 15:58:58 +0300995void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
996{
Geoff Lang75359662018-04-11 01:42:27 -0400997 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300998 ASSERT(object != nullptr);
999
1000 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001001 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001002
1003 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1004 // specified object is active until we do this.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001005 mState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001006}
1007
1008void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1009{
Geoff Lang75359662018-04-11 01:42:27 -04001010 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001011 ASSERT(object != nullptr);
1012
1013 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001014 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001015}
1016
1017void Context::getObjectLabel(GLenum identifier,
1018 GLuint name,
1019 GLsizei bufSize,
1020 GLsizei *length,
1021 GLchar *label) const
1022{
Geoff Lang75359662018-04-11 01:42:27 -04001023 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001024 ASSERT(object != nullptr);
1025
1026 const std::string &objectLabel = object->getLabel();
1027 GetObjectLabelBase(objectLabel, bufSize, length, label);
1028}
1029
1030void Context::getObjectPtrLabel(const void *ptr,
1031 GLsizei bufSize,
1032 GLsizei *length,
1033 GLchar *label) const
1034{
Geoff Lang75359662018-04-11 01:42:27 -04001035 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001036 ASSERT(object != nullptr);
1037
1038 const std::string &objectLabel = object->getLabel();
1039 GetObjectLabelBase(objectLabel, bufSize, length, label);
1040}
1041
Jamie Madilldc356042013-07-19 16:36:57 -04001042bool Context::isSampler(GLuint samplerName) const
1043{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001044 return mState.mSamplerManager->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001045}
1046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001047void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001049 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001050
Jamie Madilldedd7b92014-11-05 16:30:36 -05001051 if (handle == 0)
1052 {
1053 texture = mZeroTextures[target].get();
1054 }
1055 else
1056 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001057 texture =
1058 mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001059 }
1060
1061 ASSERT(texture);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001062 mState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001063 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001064}
1065
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001066void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001067{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001068 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1069 mImplementation.get(), mState.mCaps, framebufferHandle);
1070 mState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001071 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001072}
1073
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001074void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001076 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1077 mImplementation.get(), mState.mCaps, framebufferHandle);
1078 mState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001079 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001080 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081}
1082
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001083void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001084{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001085 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001086 mState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001087 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001088 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001089}
1090
Shao80957d92017-02-20 21:25:59 +08001091void Context::bindVertexBuffer(GLuint bindingIndex,
1092 GLuint bufferHandle,
1093 GLintptr offset,
1094 GLsizei stride)
1095{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001096 Buffer *buffer =
1097 mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
1098 mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001099 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001100}
1101
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001102void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001103{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001104 ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001105 Sampler *sampler =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001106 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
1107 mState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001108 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001109}
1110
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001111void Context::bindImageTexture(GLuint unit,
1112 GLuint texture,
1113 GLint level,
1114 GLboolean layered,
1115 GLint layer,
1116 GLenum access,
1117 GLenum format)
1118{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001119 Texture *tex = mState.mTextureManager->getTexture(texture);
1120 mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001121}
1122
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001123void Context::useProgram(GLuint program)
1124{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001125 ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001126 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001127}
1128
Jiajia Qin5451d532017-11-16 17:16:34 +08001129void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1130{
1131 UNIMPLEMENTED();
1132}
1133
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001134void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001135{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001136 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001137 TransformFeedback *transformFeedback =
1138 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001139 mState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001140}
1141
Yunchao Hea336b902017-08-02 16:05:21 +08001142void Context::bindProgramPipeline(GLuint pipelineHandle)
1143{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001144 ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
1145 mImplementation.get(), pipelineHandle);
1146 mState.setProgramPipelineBinding(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08001147}
1148
Corentin Wallezad3ae902018-03-09 13:40:42 -05001149void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001152 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153
Geoff Lang5aad9672014-09-08 11:10:42 -04001154 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001155 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001156
1157 // set query as active for specified target only if begin succeeded
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001158 mState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001159 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160}
1161
Corentin Wallezad3ae902018-03-09 13:40:42 -05001162void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001164 Query *queryObject = mState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001165 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166
Jamie Madill4f6592f2018-11-27 16:37:45 -05001167 // Intentionally don't call try here. We don't want an early return.
1168 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169
Geoff Lang5aad9672014-09-08 11:10:42 -04001170 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001171 mState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001172 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173}
1174
Corentin Wallezad3ae902018-03-09 13:40:42 -05001175void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001177 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178
1179 Query *queryObject = getQuery(id, true, target);
1180 ASSERT(queryObject);
1181
Jamie Madill4f6592f2018-11-27 16:37:45 -05001182 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001183}
1184
Corentin Wallezad3ae902018-03-09 13:40:42 -05001185void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186{
1187 switch (pname)
1188 {
1189 case GL_CURRENT_QUERY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001190 params[0] = mState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191 break;
1192 case GL_QUERY_COUNTER_BITS_EXT:
1193 switch (target)
1194 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001195 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001196 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1197 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001198 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199 params[0] = getExtensions().queryCounterBitsTimestamp;
1200 break;
1201 default:
1202 UNREACHABLE();
1203 params[0] = 0;
1204 break;
1205 }
1206 break;
1207 default:
1208 UNREACHABLE();
1209 return;
1210 }
1211}
1212
Corentin Wallezad3ae902018-03-09 13:40:42 -05001213void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001214 GLenum pname,
1215 GLsizei bufSize,
1216 GLsizei *length,
1217 GLint *params)
1218{
1219 getQueryiv(target, pname, params);
1220}
1221
Geoff Lang2186c382016-10-14 10:54:54 -04001222void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001224 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225}
1226
Brandon Jones59770802018-04-02 13:18:42 -07001227void Context::getQueryObjectivRobust(GLuint id,
1228 GLenum pname,
1229 GLsizei bufSize,
1230 GLsizei *length,
1231 GLint *params)
1232{
1233 getQueryObjectiv(id, pname, params);
1234}
1235
Geoff Lang2186c382016-10-14 10:54:54 -04001236void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001237{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001238 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239}
1240
Brandon Jones59770802018-04-02 13:18:42 -07001241void Context::getQueryObjectuivRobust(GLuint id,
1242 GLenum pname,
1243 GLsizei bufSize,
1244 GLsizei *length,
1245 GLuint *params)
1246{
1247 getQueryObjectuiv(id, pname, params);
1248}
1249
Geoff Lang2186c382016-10-14 10:54:54 -04001250void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001251{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001252 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001253}
1254
Brandon Jones59770802018-04-02 13:18:42 -07001255void Context::getQueryObjecti64vRobust(GLuint id,
1256 GLenum pname,
1257 GLsizei bufSize,
1258 GLsizei *length,
1259 GLint64 *params)
1260{
1261 getQueryObjecti64v(id, pname, params);
1262}
1263
Geoff Lang2186c382016-10-14 10:54:54 -04001264void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001265{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001266 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267}
1268
Brandon Jones59770802018-04-02 13:18:42 -07001269void Context::getQueryObjectui64vRobust(GLuint id,
1270 GLenum pname,
1271 GLsizei bufSize,
1272 GLsizei *length,
1273 GLuint64 *params)
1274{
1275 getQueryObjectui64v(id, pname, params);
1276}
1277
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001278Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001280 return mState.mFramebufferManager->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281}
1282
Jamie Madill2f348d22017-06-05 10:50:59 -04001283FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284{
Jamie Madill96a483b2017-06-27 16:49:21 -04001285 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286}
1287
Corentin Wallezad3ae902018-03-09 13:40:42 -05001288Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289{
Jamie Madill96a483b2017-06-27 16:49:21 -04001290 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001292 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001294
1295 Query *query = mQueryMap.query(handle);
1296 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001297 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001298 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001299 query = new Query(mImplementation->createQuery(type), handle);
1300 query->addRef();
1301 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001302 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001303 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001304}
1305
Geoff Lang70d0f492015-12-10 17:45:46 -05001306Query *Context::getQuery(GLuint handle) const
1307{
Jamie Madill96a483b2017-06-27 16:49:21 -04001308 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001309}
1310
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001311Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001312{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001313 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001314 return mState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001315}
1316
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001317Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001319 return mState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320}
1321
Geoff Lang492a7e42014-11-05 13:27:06 -05001322Compiler *Context::getCompiler() const
1323{
Jamie Madill2f348d22017-06-05 10:50:59 -04001324 if (mCompiler.get() == nullptr)
1325 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001326 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001327 }
1328 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001329}
1330
Jamie Madillc1d770e2017-04-13 17:31:24 -04001331void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332{
1333 switch (pname)
1334 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001335 case GL_SHADER_COMPILER:
1336 *params = GL_TRUE;
1337 break;
1338 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1339 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1340 break;
Jeff Gilbert465d6092019-01-02 16:21:18 -08001341
Jamie Madill231c7f52017-04-26 13:45:37 -04001342 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001343 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001344 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346}
1347
Jamie Madillc1d770e2017-04-13 17:31:24 -04001348void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349{
Shannon Woods53a94a82014-06-24 15:20:36 -04001350 // Queries about context capabilities and maximums are answered by Context.
1351 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001352 switch (pname)
1353 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001355 params[0] = mState.mCaps.minAliasedLineWidth;
1356 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001359 params[0] = mState.mCaps.minAliasedPointSize;
1360 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001361 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001362 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001363 params[0] = mState.mCaps.minSmoothPointSize;
1364 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001365 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001366 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001367 params[0] = mState.mCaps.minSmoothLineWidth;
1368 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001369 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001371 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1372 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 break;
1374 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001375 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001376 break;
1377
1378 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1379 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1380 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001381 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1382 // GLES1 constants for modelview/projection matrix.
1383 if (getClientVersion() < Version(2, 0))
1384 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001385 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001386 }
1387 else
1388 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001389 ASSERT(mState.mExtensions.pathRendering);
1390 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001391 memcpy(params, m, 16 * sizeof(GLfloat));
1392 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001394 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001395
Jamie Madill231c7f52017-04-26 13:45:37 -04001396 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001397 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001398 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001399 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400}
1401
Jamie Madillc1d770e2017-04-13 17:31:24 -04001402void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001403{
Shannon Woods53a94a82014-06-24 15:20:36 -04001404 // Queries about context capabilities and maximums are answered by Context.
1405 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001406
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001407 switch (pname)
1408 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001410 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 break;
1412 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001413 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 break;
1415 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001416 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 break;
1418 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001419 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001420 break;
1421 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001422 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 break;
1424 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001425 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001426 break;
1427 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001428 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001429 break;
1430 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001431 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 break;
1433 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001434 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 break;
1436 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001437 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 break;
1439 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001440 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001441 break;
1442 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001443 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001444 break;
1445 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001446 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 case GL_SUBPIXEL_BITS:
1449 *params = 4;
1450 break;
1451 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001452 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001454 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001455 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001456 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001457 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001458 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001459 break;
1460 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001461 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 break;
1463 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001464 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001465 break;
1466 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001467 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001470 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 break;
1472 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001473 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001476 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001479 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 break;
1481 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001482 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001483 break;
1484 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001485 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 break;
1487 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001488 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 break;
1490 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001491 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001492 break;
1493 case GL_MAJOR_VERSION:
1494 *params = getClientVersion().major;
1495 break;
1496 case GL_MINOR_VERSION:
1497 *params = getClientVersion().minor;
1498 break;
1499 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001500 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001501 break;
1502 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001503 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 break;
1505 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001506 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001507 break;
1508 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001509 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001510 break;
1511 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001512 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 break;
1514 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001515 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001516 break;
1517 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001518 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001519 break;
1520 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001521 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001522 params[0] = mState.mCaps.maxViewportWidth;
1523 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001524 }
1525 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001526 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001527 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1528 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001529 break;
1530 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1531 *params = mResetStrategy;
1532 break;
1533 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001534 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001535 break;
1536 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001537 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1538 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001539 break;
1540 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001541 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001544 std::copy(mState.mCaps.programBinaryFormats.begin(),
1545 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001546 break;
1547 case GL_NUM_EXTENSIONS:
1548 *params = static_cast<GLint>(mExtensionStrings.size());
1549 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001550
Geoff Lang38f24ee2018-10-01 13:04:59 -04001551 // GL_ANGLE_request_extension
1552 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1553 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1554 break;
1555
Jamie Madill231c7f52017-04-26 13:45:37 -04001556 // GL_KHR_debug
1557 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001558 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001559 break;
1560 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001561 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001562 break;
1563 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001564 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 break;
1566 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001567 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001568 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001569
Martin Radeve5285d22017-07-14 16:23:53 +03001570 // GL_ANGLE_multiview
1571 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001572 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001573 break;
1574
Jamie Madill231c7f52017-04-26 13:45:37 -04001575 // GL_EXT_disjoint_timer_query
1576 case GL_GPU_DISJOINT_EXT:
1577 *params = mImplementation->getGPUDisjoint();
1578 break;
1579 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001580 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001583 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001584 break;
1585 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001586 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001587 break;
1588 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001589 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001592 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001595 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001598 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001601 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001604 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001607 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001610 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001613 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001614 break;
1615 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001616 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 break;
1618 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001619 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001620 break;
1621 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001622 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001625 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001628 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001631 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001634 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001637 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001640 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001643 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001646 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001649 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001652 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001655 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001658 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001661 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001664 *params = static_cast<GLint>(
1665 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001668 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001671 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001674 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001677 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001680 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001683 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001686 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001689 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001692 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001695 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001698 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001701 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001703
1704 // GL_EXT_geometry_shader
1705 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001706 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001707 break;
1708 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001709 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001710 break;
1711 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001712 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001713 break;
1714 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001715 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001716 break;
1717 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001718 *params = static_cast<GLint>(
1719 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001720 break;
1721 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001722 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001725 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001728 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001731 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001734 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001735 break;
1736 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001737 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001738 break;
1739 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001740 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001741 break;
1742 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001743 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001744 break;
1745 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001746 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001747 break;
1748 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001749 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001751 // GLES1 emulation: Caps queries
1752 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001753 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001754 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001755 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001756 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001757 break;
1758 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001759 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001760 break;
1761 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001762 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001763 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001764 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001765 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001766 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001767 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001768 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001769 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001770 // GLES1 emulation: Vertex attribute queries
1771 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1772 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1773 case GL_COLOR_ARRAY_BUFFER_BINDING:
1774 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1775 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1776 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1777 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1778 break;
1779 case GL_VERTEX_ARRAY_STRIDE:
1780 case GL_NORMAL_ARRAY_STRIDE:
1781 case GL_COLOR_ARRAY_STRIDE:
1782 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1783 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1784 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1785 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1786 break;
1787 case GL_VERTEX_ARRAY_SIZE:
1788 case GL_COLOR_ARRAY_SIZE:
1789 case GL_TEXTURE_COORD_ARRAY_SIZE:
1790 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1791 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1792 break;
1793 case GL_VERTEX_ARRAY_TYPE:
1794 case GL_COLOR_ARRAY_TYPE:
1795 case GL_NORMAL_ARRAY_TYPE:
1796 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1797 case GL_TEXTURE_COORD_ARRAY_TYPE:
1798 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1799 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1800 break;
1801
jchen1082af6202018-06-22 10:59:52 +08001802 // GL_KHR_parallel_shader_compile
1803 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001804 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001805 break;
1806
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001807 // GL_EXT_blend_func_extended
1808 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001809 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001810 break;
1811
Jamie Madill231c7f52017-04-26 13:45:37 -04001812 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001813 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001814 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001815 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001816}
1817
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001818void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001819{
Shannon Woods53a94a82014-06-24 15:20:36 -04001820 // Queries about context capabilities and maximums are answered by Context.
1821 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001822 switch (pname)
1823 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001824 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001825 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001826 break;
1827 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001828 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001829 break;
1830 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001831 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001832 break;
1833 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001834 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001835 break;
1836 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001837 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001838 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001839
Jamie Madill231c7f52017-04-26 13:45:37 -04001840 // GL_EXT_disjoint_timer_query
1841 case GL_TIMESTAMP_EXT:
1842 *params = mImplementation->getTimestamp();
1843 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001844
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001846 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 break;
1848 default:
1849 UNREACHABLE();
1850 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001851 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001852}
1853
Geoff Lang70d0f492015-12-10 17:45:46 -05001854void Context::getPointerv(GLenum pname, void **params) const
1855{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001856 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001857}
1858
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001859void Context::getPointervRobustANGLERobust(GLenum pname,
1860 GLsizei bufSize,
1861 GLsizei *length,
1862 void **params)
1863{
1864 UNIMPLEMENTED();
1865}
1866
Martin Radev66fb8202016-07-28 11:45:20 +03001867void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001868{
Shannon Woods53a94a82014-06-24 15:20:36 -04001869 // Queries about context capabilities and maximums are answered by Context.
1870 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001871
1872 GLenum nativeType;
1873 unsigned int numParams;
1874 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1875 ASSERT(queryStatus);
1876
1877 if (nativeType == GL_INT)
1878 {
1879 switch (target)
1880 {
1881 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1882 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001883 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001884 break;
1885 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1886 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001887 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001888 break;
1889 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001890 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001891 }
1892 }
1893 else
1894 {
1895 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1896 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001897}
1898
Brandon Jones59770802018-04-02 13:18:42 -07001899void Context::getIntegeri_vRobust(GLenum target,
1900 GLuint index,
1901 GLsizei bufSize,
1902 GLsizei *length,
1903 GLint *data)
1904{
1905 getIntegeri_v(target, index, data);
1906}
1907
Martin Radev66fb8202016-07-28 11:45:20 +03001908void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001909{
Shannon Woods53a94a82014-06-24 15:20:36 -04001910 // Queries about context capabilities and maximums are answered by Context.
1911 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001912
1913 GLenum nativeType;
1914 unsigned int numParams;
1915 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1916 ASSERT(queryStatus);
1917
1918 if (nativeType == GL_INT_64_ANGLEX)
1919 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001920 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001921 }
1922 else
1923 {
1924 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1925 }
1926}
1927
Brandon Jones59770802018-04-02 13:18:42 -07001928void Context::getInteger64i_vRobust(GLenum target,
1929 GLuint index,
1930 GLsizei bufSize,
1931 GLsizei *length,
1932 GLint64 *data)
1933{
1934 getInteger64i_v(target, index, data);
1935}
1936
Martin Radev66fb8202016-07-28 11:45:20 +03001937void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1938{
1939 // Queries about context capabilities and maximums are answered by Context.
1940 // Queries about current GL state values are answered by State.
1941
1942 GLenum nativeType;
1943 unsigned int numParams;
1944 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1945 ASSERT(queryStatus);
1946
1947 if (nativeType == GL_BOOL)
1948 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001949 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001950 }
1951 else
1952 {
1953 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1954 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001955}
1956
Brandon Jones59770802018-04-02 13:18:42 -07001957void Context::getBooleani_vRobust(GLenum target,
1958 GLuint index,
1959 GLsizei bufSize,
1960 GLsizei *length,
1961 GLboolean *data)
1962{
1963 getBooleani_v(target, index, data);
1964}
1965
Corentin Wallez336129f2017-10-17 15:55:40 -04001966void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001967{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001968 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001969 QueryBufferParameteriv(buffer, pname, params);
1970}
1971
Brandon Jones59770802018-04-02 13:18:42 -07001972void Context::getBufferParameterivRobust(BufferBinding target,
1973 GLenum pname,
1974 GLsizei bufSize,
1975 GLsizei *length,
1976 GLint *params)
1977{
1978 getBufferParameteriv(target, pname, params);
1979}
1980
He Yunchao010e4db2017-03-03 14:22:06 +08001981void Context::getFramebufferAttachmentParameteriv(GLenum target,
1982 GLenum attachment,
1983 GLenum pname,
1984 GLint *params)
1985{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001986 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001987 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001988}
1989
Brandon Jones59770802018-04-02 13:18:42 -07001990void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1991 GLenum attachment,
1992 GLenum pname,
1993 GLsizei bufSize,
1994 GLsizei *length,
1995 GLint *params)
1996{
1997 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1998}
1999
He Yunchao010e4db2017-03-03 14:22:06 +08002000void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2001{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002002 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08002003 QueryRenderbufferiv(this, renderbuffer, pname, params);
2004}
2005
Brandon Jones59770802018-04-02 13:18:42 -07002006void Context::getRenderbufferParameterivRobust(GLenum target,
2007 GLenum pname,
2008 GLsizei bufSize,
2009 GLsizei *length,
2010 GLint *params)
2011{
2012 getRenderbufferParameteriv(target, pname, params);
2013}
2014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002015void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002016{
Till Rathmannb8543632018-10-02 19:46:14 +02002017 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002018 QueryTexParameterfv(texture, pname, params);
2019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::getTexParameterfvRobust(TextureType target,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 GLsizei *length,
2025 GLfloat *params)
2026{
2027 getTexParameterfv(target, pname, params);
2028}
2029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002030void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002031{
Till Rathmannb8543632018-10-02 19:46:14 +02002032 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002033 QueryTexParameteriv(texture, pname, params);
2034}
Jiajia Qin5451d532017-11-16 17:16:34 +08002035
Till Rathmannb8543632018-10-02 19:46:14 +02002036void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2037{
2038 const Texture *const texture = getTargetTexture(target);
2039 QueryTexParameterIiv(texture, pname, params);
2040}
2041
2042void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2043{
2044 const Texture *const texture = getTargetTexture(target);
2045 QueryTexParameterIuiv(texture, pname, params);
2046}
2047
Brandon Jones59770802018-04-02 13:18:42 -07002048void Context::getTexParameterivRobust(TextureType target,
2049 GLenum pname,
2050 GLsizei bufSize,
2051 GLsizei *length,
2052 GLint *params)
2053{
2054 getTexParameteriv(target, pname, params);
2055}
2056
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002057void Context::getTexParameterIivRobust(TextureType target,
2058 GLenum pname,
2059 GLsizei bufSize,
2060 GLsizei *length,
2061 GLint *params)
2062{
2063 UNIMPLEMENTED();
2064}
2065
2066void Context::getTexParameterIuivRobust(TextureType target,
2067 GLenum pname,
2068 GLsizei bufSize,
2069 GLsizei *length,
2070 GLuint *params)
2071{
2072 UNIMPLEMENTED();
2073}
2074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002075void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002076{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002077 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002078 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002079}
2080
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002081void Context::getTexLevelParameterivRobust(TextureTarget target,
2082 GLint level,
2083 GLenum pname,
2084 GLsizei bufSize,
2085 GLsizei *length,
2086 GLint *params)
2087{
2088 UNIMPLEMENTED();
2089}
2090
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002091void Context::getTexLevelParameterfv(TextureTarget target,
2092 GLint level,
2093 GLenum pname,
2094 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002095{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002097 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002098}
2099
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002100void Context::getTexLevelParameterfvRobust(TextureTarget target,
2101 GLint level,
2102 GLenum pname,
2103 GLsizei bufSize,
2104 GLsizei *length,
2105 GLfloat *params)
2106{
2107 UNIMPLEMENTED();
2108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002111{
Till Rathmannb8543632018-10-02 19:46:14 +02002112 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002113 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002114}
2115
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002116void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002117{
Till Rathmannb8543632018-10-02 19:46:14 +02002118 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002119 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002120}
2121
Brandon Jones59770802018-04-02 13:18:42 -07002122void Context::texParameterfvRobust(TextureType target,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 const GLfloat *params)
2126{
2127 texParameterfv(target, pname, params);
2128}
2129
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002130void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002131{
Till Rathmannb8543632018-10-02 19:46:14 +02002132 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002133 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002134}
2135
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002136void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002137{
Till Rathmannb8543632018-10-02 19:46:14 +02002138 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002139 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002140}
2141
Till Rathmannb8543632018-10-02 19:46:14 +02002142void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2143{
2144 Texture *const texture = getTargetTexture(target);
2145 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002146}
2147
2148void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2149{
2150 Texture *const texture = getTargetTexture(target);
2151 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002152}
2153
Brandon Jones59770802018-04-02 13:18:42 -07002154void Context::texParameterivRobust(TextureType target,
2155 GLenum pname,
2156 GLsizei bufSize,
2157 const GLint *params)
2158{
2159 texParameteriv(target, pname, params);
2160}
2161
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002162void Context::texParameterIivRobust(TextureType target,
2163 GLenum pname,
2164 GLsizei bufSize,
2165 const GLint *params)
2166{
2167 UNIMPLEMENTED();
2168}
2169
2170void Context::texParameterIuivRobust(TextureType target,
2171 GLenum pname,
2172 GLsizei bufSize,
2173 const GLuint *params)
2174{
2175 UNIMPLEMENTED();
2176}
2177
Jamie Madill493f9572018-05-24 19:52:15 -04002178void Context::drawArraysInstanced(PrimitiveMode mode,
2179 GLint first,
2180 GLsizei count,
2181 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002182{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002183 // No-op if count draws no primitives for given mode
2184 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002185 {
2186 return;
2187 }
2188
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002189 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002190 ANGLE_CONTEXT_TRY(
2191 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002192 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002193}
2194
Jamie Madill493f9572018-05-24 19:52:15 -04002195void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002196 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002197 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002198 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002199 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002200{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002201 // No-op if count draws no primitives for given mode
2202 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002203 {
2204 return;
2205 }
2206
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002207 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002208 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002209 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002210}
2211
Jamie Madill493f9572018-05-24 19:52:15 -04002212void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002213 GLuint start,
2214 GLuint end,
2215 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002216 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002217 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002218{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002219 // No-op if count draws no primitives for given mode
2220 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002221 {
2222 return;
2223 }
2224
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002225 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002226 ANGLE_CONTEXT_TRY(
2227 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228}
2229
Jamie Madill493f9572018-05-24 19:52:15 -04002230void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002231{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002232 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002233 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002234}
2235
Jamie Madill8dc27f92018-11-29 11:45:44 -05002236void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002237{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002238 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002239 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002240}
2241
Jamie Madill675fe712016-12-19 13:07:54 -05002242void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002243{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002244 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002245}
2246
Jamie Madill675fe712016-12-19 13:07:54 -05002247void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002248{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002249 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250}
2251
Austin Kinross6ee1e782015-05-29 17:05:37 -07002252void Context::insertEventMarker(GLsizei length, const char *marker)
2253{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002254 ASSERT(mImplementation);
2255 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002256}
2257
2258void Context::pushGroupMarker(GLsizei length, const char *marker)
2259{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002260 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002261
2262 if (marker == nullptr)
2263 {
2264 // From the EXT_debug_marker spec,
2265 // "If <marker> is null then an empty string is pushed on the stack."
2266 mImplementation->pushGroupMarker(length, "");
2267 }
2268 else
2269 {
2270 mImplementation->pushGroupMarker(length, marker);
2271 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002272}
2273
2274void Context::popGroupMarker()
2275{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002276 ASSERT(mImplementation);
2277 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002278}
2279
Geoff Langd8605522016-04-13 10:19:12 -04002280void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2281{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002282 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002283 ASSERT(programObject);
2284
2285 programObject->bindUniformLocation(location, name);
2286}
2287
Brandon Jones59770802018-04-02 13:18:42 -07002288void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002289{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002290 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002291}
2292
Brandon Jones59770802018-04-02 13:18:42 -07002293void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002294{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002295 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002296}
2297
Brandon Jones59770802018-04-02 13:18:42 -07002298void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002299{
2300 GLfloat I[16];
2301 angle::Matrix<GLfloat>::setToIdentity(I);
2302
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002303 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002304}
2305
2306void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2307{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002308 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002309 if (!pathObj)
2310 return;
2311
Geoff Lang9bf86f02018-07-26 11:46:34 -04002312 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002313
2314 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2315}
2316
2317void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2318{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002319 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002320 if (!pathObj)
2321 return;
2322
Geoff Lang9bf86f02018-07-26 11:46:34 -04002323 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002324
2325 mImplementation->stencilStrokePath(pathObj, reference, mask);
2326}
2327
2328void Context::coverFillPath(GLuint path, GLenum coverMode)
2329{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002330 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002331 if (!pathObj)
2332 return;
2333
Geoff Lang9bf86f02018-07-26 11:46:34 -04002334 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002335
2336 mImplementation->coverFillPath(pathObj, coverMode);
2337}
2338
2339void Context::coverStrokePath(GLuint path, GLenum coverMode)
2340{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002341 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002342 if (!pathObj)
2343 return;
2344
Geoff Lang9bf86f02018-07-26 11:46:34 -04002345 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002346
2347 mImplementation->coverStrokePath(pathObj, coverMode);
2348}
2349
2350void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2351{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002352 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002353 if (!pathObj)
2354 return;
2355
Geoff Lang9bf86f02018-07-26 11:46:34 -04002356 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357
2358 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2359}
2360
2361void Context::stencilThenCoverStrokePath(GLuint path,
2362 GLint reference,
2363 GLuint mask,
2364 GLenum coverMode)
2365{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002366 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002367 if (!pathObj)
2368 return;
2369
Geoff Lang9bf86f02018-07-26 11:46:34 -04002370 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002371
2372 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2373}
2374
Sami Väisänend59ca052016-06-21 16:10:00 +03002375void Context::coverFillPathInstanced(GLsizei numPaths,
2376 GLenum pathNameType,
2377 const void *paths,
2378 GLuint pathBase,
2379 GLenum coverMode,
2380 GLenum transformType,
2381 const GLfloat *transformValues)
2382{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002383 const auto &pathObjects =
2384 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002385
Geoff Lang9bf86f02018-07-26 11:46:34 -04002386 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2389}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002390
Sami Väisänend59ca052016-06-21 16:10:00 +03002391void Context::coverStrokePathInstanced(GLsizei numPaths,
2392 GLenum pathNameType,
2393 const void *paths,
2394 GLuint pathBase,
2395 GLenum coverMode,
2396 GLenum transformType,
2397 const GLfloat *transformValues)
2398{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002399 const auto &pathObjects =
2400 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002401
2402 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002403 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002404
2405 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2406 transformValues);
2407}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002408
Sami Väisänend59ca052016-06-21 16:10:00 +03002409void Context::stencilFillPathInstanced(GLsizei numPaths,
2410 GLenum pathNameType,
2411 const void *paths,
2412 GLuint pathBase,
2413 GLenum fillMode,
2414 GLuint mask,
2415 GLenum transformType,
2416 const GLfloat *transformValues)
2417{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002418 const auto &pathObjects =
2419 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002420
2421 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002422 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
2424 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2425 transformValues);
2426}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002427
Sami Väisänend59ca052016-06-21 16:10:00 +03002428void Context::stencilStrokePathInstanced(GLsizei numPaths,
2429 GLenum pathNameType,
2430 const void *paths,
2431 GLuint pathBase,
2432 GLint reference,
2433 GLuint mask,
2434 GLenum transformType,
2435 const GLfloat *transformValues)
2436{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002437 const auto &pathObjects =
2438 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002439
Geoff Lang9bf86f02018-07-26 11:46:34 -04002440 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2443 transformValues);
2444}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002445
Sami Väisänend59ca052016-06-21 16:10:00 +03002446void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2447 GLenum pathNameType,
2448 const void *paths,
2449 GLuint pathBase,
2450 GLenum fillMode,
2451 GLuint mask,
2452 GLenum coverMode,
2453 GLenum transformType,
2454 const GLfloat *transformValues)
2455{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002456 const auto &pathObjects =
2457 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002458
Geoff Lang9bf86f02018-07-26 11:46:34 -04002459 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002460
2461 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2462 transformType, transformValues);
2463}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002464
Sami Väisänend59ca052016-06-21 16:10:00 +03002465void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2466 GLenum pathNameType,
2467 const void *paths,
2468 GLuint pathBase,
2469 GLint reference,
2470 GLuint mask,
2471 GLenum coverMode,
2472 GLenum transformType,
2473 const GLfloat *transformValues)
2474{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002475 const auto &pathObjects =
2476 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002477
Geoff Lang9bf86f02018-07-26 11:46:34 -04002478 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002479
2480 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2481 transformType, transformValues);
2482}
2483
Sami Väisänen46eaa942016-06-29 10:26:37 +03002484void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2485{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002486 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002487
2488 programObject->bindFragmentInputLocation(location, name);
2489}
2490
2491void Context::programPathFragmentInputGen(GLuint program,
2492 GLint location,
2493 GLenum genMode,
2494 GLint components,
2495 const GLfloat *coeffs)
2496{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002497 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002498
jchen103fd614d2018-08-13 12:21:58 +08002499 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002500}
2501
jchen1015015f72017-03-16 13:54:21 +08002502GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2503{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002504 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002505 return QueryProgramResourceIndex(programObject, programInterface, name);
2506}
2507
jchen10fd7c3b52017-03-21 15:36:03 +08002508void Context::getProgramResourceName(GLuint program,
2509 GLenum programInterface,
2510 GLuint index,
2511 GLsizei bufSize,
2512 GLsizei *length,
2513 GLchar *name)
2514{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002515 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002516 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2517}
2518
jchen10191381f2017-04-11 13:59:04 +08002519GLint Context::getProgramResourceLocation(GLuint program,
2520 GLenum programInterface,
2521 const GLchar *name)
2522{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002523 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002524 return QueryProgramResourceLocation(programObject, programInterface, name);
2525}
2526
jchen10880683b2017-04-12 16:21:55 +08002527void Context::getProgramResourceiv(GLuint program,
2528 GLenum programInterface,
2529 GLuint index,
2530 GLsizei propCount,
2531 const GLenum *props,
2532 GLsizei bufSize,
2533 GLsizei *length,
2534 GLint *params)
2535{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002536 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002537 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2538 length, params);
2539}
2540
jchen10d9cd7b72017-08-30 15:04:25 +08002541void Context::getProgramInterfaceiv(GLuint program,
2542 GLenum programInterface,
2543 GLenum pname,
2544 GLint *params)
2545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002546 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002547 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2548}
2549
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002550void Context::getProgramInterfaceivRobust(GLuint program,
2551 GLenum programInterface,
2552 GLenum pname,
2553 GLsizei bufSize,
2554 GLsizei *length,
2555 GLint *params)
2556{
2557 UNIMPLEMENTED();
2558}
2559
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002560void Context::handleError(GLenum errorCode,
2561 const char *message,
2562 const char *file,
2563 const char *function,
2564 unsigned int line)
2565{
2566 mErrors.handleError(errorCode, message, file, function, line);
2567}
2568
Jamie Madilla139f012018-10-10 16:13:03 -04002569void Context::validationError(GLenum errorCode, const char *message)
2570{
2571 mErrors.validationError(errorCode, message);
2572}
2573
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574// Get one of the recorded errors and clear its flag, if any.
2575// [OpenGL ES 2.0.24] section 2.5 page 13.
2576GLenum Context::getError()
2577{
Geoff Langda5777c2014-07-11 09:52:58 -04002578 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002579 {
Geoff Langda5777c2014-07-11 09:52:58 -04002580 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581 }
Geoff Langda5777c2014-07-11 09:52:58 -04002582 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002584 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002586}
2587
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002589void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590{
2591 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002592 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002593 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002594 mContextLostForced = true;
2595 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002596 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002597}
2598
Jamie Madillfa920eb2018-01-04 11:45:50 -05002599GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002600{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601 // Even if the application doesn't want to know about resets, we want to know
2602 // as it will allow us to skip all the calls.
2603 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002604 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002605 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002606 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002608 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002609
2610 // EXT_robustness, section 2.6: If the reset notification behavior is
2611 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2612 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2613 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 }
2615
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2617 // status should be returned at least once, and GL_NO_ERROR should be returned
2618 // once the device has finished resetting.
2619 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002620 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621 ASSERT(mResetStatus == GL_NO_ERROR);
2622 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002623
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
2628 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002629 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002631 // If markContextLost was used to mark the context lost then
2632 // assume that is not recoverable, and continue to report the
2633 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 mResetStatus = mImplementation->getResetStatus();
2635 }
Jamie Madill893ab082014-05-16 16:56:10 -04002636
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638}
2639
2640bool Context::isResetNotificationEnabled()
2641{
2642 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2643}
2644
Corentin Walleze3b10e82015-05-20 11:06:25 -04002645const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002646{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002647 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002648}
2649
2650EGLenum Context::getClientType() const
2651{
2652 return mClientType;
2653}
2654
2655EGLenum Context::getRenderBuffer() const
2656{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002657 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002658 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002659 {
2660 return EGL_NONE;
2661 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002662
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002663 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002664 ASSERT(backAttachment != nullptr);
2665 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002666}
2667
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002668VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002669{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002670 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002671 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2672 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002673 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002674 vertexArray =
2675 new VertexArray(mImplementation.get(), vertexArrayHandle,
2676 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002677
Jamie Madill96a483b2017-06-27 16:49:21 -04002678 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002679 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002680
2681 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002682}
2683
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002684TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002685{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002686 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002687 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2688 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002689 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002690 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002691 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002692 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002693 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002694 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002695
2696 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002697}
2698
2699bool Context::isVertexArrayGenerated(GLuint vertexArray)
2700{
Jamie Madill96a483b2017-06-27 16:49:21 -04002701 ASSERT(mVertexArrayMap.contains(0));
2702 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002703}
2704
2705bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2706{
Jamie Madill96a483b2017-06-27 16:49:21 -04002707 ASSERT(mTransformFeedbackMap.contains(0));
2708 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002709}
2710
Shannon Woods53a94a82014-06-24 15:20:36 -04002711void Context::detachTexture(GLuint texture)
2712{
2713 // Simple pass-through to State's detachTexture method, as textures do not require
2714 // allocation map management either here or in the resource manager at detach time.
2715 // Zero textures are held by the Context, and we don't attempt to request them from
2716 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002717 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002718}
2719
James Darpinian4d9d4832018-03-13 12:43:28 -07002720void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002721{
Yuly Novikov5807a532015-12-03 13:01:22 -05002722 // Simple pass-through to State's detachBuffer method, since
2723 // only buffer attachments to container objects that are bound to the current context
2724 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002725
Yuly Novikov5807a532015-12-03 13:01:22 -05002726 // [OpenGL ES 3.2] section 5.1.2 page 45:
2727 // Attachments to unbound container objects, such as
2728 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2729 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002730 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002731}
2732
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002733void Context::detachFramebuffer(GLuint framebuffer)
2734{
Shannon Woods53a94a82014-06-24 15:20:36 -04002735 // Framebuffer detachment is handled by Context, because 0 is a valid
2736 // Framebuffer object, and a pointer to it must be passed from Context
2737 // to State at binding time.
2738
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002739 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002740 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2741 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2742 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002743
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002744 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002745 {
2746 bindReadFramebuffer(0);
2747 }
2748
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002749 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002750 {
2751 bindDrawFramebuffer(0);
2752 }
2753}
2754
2755void Context::detachRenderbuffer(GLuint renderbuffer)
2756{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002757 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002758}
2759
Jamie Madill57a89722013-07-02 11:57:03 -04002760void Context::detachVertexArray(GLuint vertexArray)
2761{
Jamie Madill77a72f62015-04-14 11:18:32 -04002762 // Vertex array detachment is handled by Context, because 0 is a valid
2763 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002764 // binding time.
2765
Jamie Madill57a89722013-07-02 11:57:03 -04002766 // [OpenGL ES 3.0.2] section 2.10 page 43:
2767 // If a vertex array object that is currently bound is deleted, the binding
2768 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002769 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002770 {
2771 bindVertexArray(0);
2772 }
2773}
2774
Geoff Langc8058452014-02-03 12:04:11 -05002775void Context::detachTransformFeedback(GLuint transformFeedback)
2776{
Corentin Walleza2257da2016-04-19 16:43:12 -04002777 // Transform feedback detachment is handled by Context, because 0 is a valid
2778 // transform feedback, and a pointer to it must be passed from Context to State at
2779 // binding time.
2780
2781 // The OpenGL specification doesn't mention what should happen when the currently bound
2782 // transform feedback object is deleted. Since it is a container object, we treat it like
2783 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002784 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002785 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002786 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002787 }
Geoff Langc8058452014-02-03 12:04:11 -05002788}
2789
Jamie Madilldc356042013-07-19 16:36:57 -04002790void Context::detachSampler(GLuint sampler)
2791{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002792 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002793}
2794
Yunchao Hea336b902017-08-02 16:05:21 +08002795void Context::detachProgramPipeline(GLuint pipeline)
2796{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002797 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002798}
2799
Jamie Madill3ef140a2017-08-26 23:11:21 -04002800void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002802 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002803 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002804}
2805
Jamie Madille29d1672013-07-19 16:36:57 -04002806void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2807{
Till Rathmannb8543632018-10-02 19:46:14 +02002808 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002809 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002810 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002811}
Jamie Madille29d1672013-07-19 16:36:57 -04002812
Geoff Langc1984ed2016-10-07 12:41:00 -04002813void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2814{
Till Rathmannb8543632018-10-02 19:46:14 +02002815 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002816 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002817 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002818}
2819
Till Rathmannb8543632018-10-02 19:46:14 +02002820void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2821{
2822 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002823 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002824 SetSamplerParameterIiv(this, samplerObject, pname, param);
2825}
2826
2827void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2828{
2829 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002830 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002831 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2832}
2833
Brandon Jones59770802018-04-02 13:18:42 -07002834void Context::samplerParameterivRobust(GLuint sampler,
2835 GLenum pname,
2836 GLsizei bufSize,
2837 const GLint *param)
2838{
2839 samplerParameteriv(sampler, pname, param);
2840}
2841
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002842void Context::samplerParameterIivRobust(GLuint sampler,
2843 GLenum pname,
2844 GLsizei bufSize,
2845 const GLint *param)
2846{
2847 UNIMPLEMENTED();
2848}
2849
2850void Context::samplerParameterIuivRobust(GLuint sampler,
2851 GLenum pname,
2852 GLsizei bufSize,
2853 const GLuint *param)
2854{
2855 UNIMPLEMENTED();
2856}
2857
Jamie Madille29d1672013-07-19 16:36:57 -04002858void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2859{
Till Rathmannb8543632018-10-02 19:46:14 +02002860 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002861 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002862 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002863}
2864
Geoff Langc1984ed2016-10-07 12:41:00 -04002865void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002866{
Till Rathmannb8543632018-10-02 19:46:14 +02002867 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002868 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002869 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002870}
2871
Brandon Jones59770802018-04-02 13:18:42 -07002872void Context::samplerParameterfvRobust(GLuint sampler,
2873 GLenum pname,
2874 GLsizei bufSize,
2875 const GLfloat *param)
2876{
2877 samplerParameterfv(sampler, pname, param);
2878}
2879
Geoff Langc1984ed2016-10-07 12:41:00 -04002880void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002881{
Till Rathmannb8543632018-10-02 19:46:14 +02002882 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002883 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002884 QuerySamplerParameteriv(samplerObject, pname, params);
2885}
Jamie Madill9675b802013-07-19 16:36:59 -04002886
Till Rathmannb8543632018-10-02 19:46:14 +02002887void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2888{
2889 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002890 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002891 QuerySamplerParameterIiv(samplerObject, pname, params);
2892}
2893
2894void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2895{
2896 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002897 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002898 QuerySamplerParameterIuiv(samplerObject, pname, params);
2899}
2900
Brandon Jones59770802018-04-02 13:18:42 -07002901void Context::getSamplerParameterivRobust(GLuint sampler,
2902 GLenum pname,
2903 GLsizei bufSize,
2904 GLsizei *length,
2905 GLint *params)
2906{
2907 getSamplerParameteriv(sampler, pname, params);
2908}
2909
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002910void Context::getSamplerParameterIivRobust(GLuint sampler,
2911 GLenum pname,
2912 GLsizei bufSize,
2913 GLsizei *length,
2914 GLint *params)
2915{
2916 UNIMPLEMENTED();
2917}
2918
2919void Context::getSamplerParameterIuivRobust(GLuint sampler,
2920 GLenum pname,
2921 GLsizei bufSize,
2922 GLsizei *length,
2923 GLuint *params)
2924{
2925 UNIMPLEMENTED();
2926}
2927
Geoff Langc1984ed2016-10-07 12:41:00 -04002928void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2929{
Till Rathmannb8543632018-10-02 19:46:14 +02002930 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002931 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002932 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002933}
2934
Brandon Jones59770802018-04-02 13:18:42 -07002935void Context::getSamplerParameterfvRobust(GLuint sampler,
2936 GLenum pname,
2937 GLsizei bufSize,
2938 GLsizei *length,
2939 GLfloat *params)
2940{
2941 getSamplerParameterfv(sampler, pname, params);
2942}
2943
Olli Etuahof0fee072016-03-30 15:11:58 +03002944void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2945{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002946 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002947 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002948}
2949
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002950void Context::initRendererString()
2951{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002952 std::ostringstream rendererString;
2953 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002954 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002955 rendererString << ")";
2956
Geoff Langcec35902014-04-16 10:52:36 -04002957 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002958}
2959
Geoff Langc339c4e2016-11-29 10:37:36 -05002960void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002961{
Geoff Langc339c4e2016-11-29 10:37:36 -05002962 const Version &clientVersion = getClientVersion();
2963
2964 std::ostringstream versionString;
2965 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2966 << ANGLE_VERSION_STRING << ")";
2967 mVersionString = MakeStaticString(versionString.str());
2968
2969 std::ostringstream shadingLanguageVersionString;
2970 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2971 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2972 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2973 << ")";
2974 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002975}
2976
Geoff Langcec35902014-04-16 10:52:36 -04002977void Context::initExtensionStrings()
2978{
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2980 std::ostringstream combinedStringStream;
2981 std::copy(strings.begin(), strings.end(),
2982 std::ostream_iterator<const char *>(combinedStringStream, " "));
2983 return MakeStaticString(combinedStringStream.str());
2984 };
2985
2986 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002987 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002988 {
2989 mExtensionStrings.push_back(MakeStaticString(extensionString));
2990 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002991 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002992
Geoff Langc339c4e2016-11-29 10:37:36 -05002993 mRequestableExtensionStrings.clear();
2994 for (const auto &extensionInfo : GetExtensionInfoMap())
2995 {
2996 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002997 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002998 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 {
3000 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3001 }
3002 }
3003 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003004}
3005
Geoff Langc339c4e2016-11-29 10:37:36 -05003006const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003007{
Geoff Langc339c4e2016-11-29 10:37:36 -05003008 switch (name)
3009 {
3010 case GL_VENDOR:
3011 return reinterpret_cast<const GLubyte *>("Google Inc.");
3012
3013 case GL_RENDERER:
3014 return reinterpret_cast<const GLubyte *>(mRendererString);
3015
3016 case GL_VERSION:
3017 return reinterpret_cast<const GLubyte *>(mVersionString);
3018
3019 case GL_SHADING_LANGUAGE_VERSION:
3020 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3021
3022 case GL_EXTENSIONS:
3023 return reinterpret_cast<const GLubyte *>(mExtensionString);
3024
3025 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3026 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3027
3028 default:
3029 UNREACHABLE();
3030 return nullptr;
3031 }
Geoff Langcec35902014-04-16 10:52:36 -04003032}
3033
Geoff Langc339c4e2016-11-29 10:37:36 -05003034const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003035{
Geoff Langc339c4e2016-11-29 10:37:36 -05003036 switch (name)
3037 {
3038 case GL_EXTENSIONS:
3039 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3040
3041 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3042 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3043
3044 default:
3045 UNREACHABLE();
3046 return nullptr;
3047 }
Geoff Langcec35902014-04-16 10:52:36 -04003048}
3049
3050size_t Context::getExtensionStringCount() const
3051{
3052 return mExtensionStrings.size();
3053}
3054
Geoff Lang111a99e2017-10-17 10:58:41 -04003055bool Context::isExtensionRequestable(const char *name)
3056{
3057 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3058 auto extension = extensionInfos.find(name);
3059
Geoff Lang111a99e2017-10-17 10:58:41 -04003060 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003061 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003062}
3063
Geoff Langc339c4e2016-11-29 10:37:36 -05003064void Context::requestExtension(const char *name)
3065{
3066 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3067 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3068 const auto &extension = extensionInfos.at(name);
3069 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003070 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003071
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003072 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003073 {
3074 // Extension already enabled
3075 return;
3076 }
3077
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003078 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003079 updateCaps();
3080 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003081
Jamie Madill2f348d22017-06-05 10:50:59 -04003082 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3083 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003084
Jamie Madill81c2e252017-09-09 23:32:46 -04003085 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3086 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003087 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003088 for (auto &zeroTexture : mZeroTextures)
3089 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003090 if (zeroTexture.get() != nullptr)
3091 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003092 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003093 }
Geoff Lang9aded172017-04-05 11:07:56 -04003094 }
3095
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003096 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003097}
3098
3099size_t Context::getRequestableExtensionStringCount() const
3100{
3101 return mRequestableExtensionStrings.size();
3102}
3103
Jamie Madill493f9572018-05-24 19:52:15 -04003104void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003105{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003106 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003107 ASSERT(transformFeedback != nullptr);
3108 ASSERT(!transformFeedback->isPaused());
3109
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003110 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003111 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003112}
3113
3114bool Context::hasActiveTransformFeedback(GLuint program) const
3115{
3116 for (auto pair : mTransformFeedbackMap)
3117 {
3118 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3119 {
3120 return true;
3121 }
3122 }
3123 return false;
3124}
3125
Geoff Lang33f11fb2018-05-07 13:42:47 -04003126Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003127{
3128 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3129
jchen1082af6202018-06-22 10:59:52 +08003130 // Explicitly enable GL_KHR_parallel_shader_compile
3131 supportedExtensions.parallelShaderCompile = true;
3132
Geoff Langb0f917f2017-12-05 13:41:54 -05003133 if (getClientVersion() < ES_2_0)
3134 {
3135 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003136 supportedExtensions.pointSizeArray = true;
3137 supportedExtensions.textureCubeMap = true;
3138 supportedExtensions.pointSprite = true;
3139 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003140 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003141 }
3142
3143 if (getClientVersion() < ES_3_0)
3144 {
3145 // Disable ES3+ extensions
3146 supportedExtensions.colorBufferFloat = false;
3147 supportedExtensions.eglImageExternalEssl3 = false;
3148 supportedExtensions.textureNorm16 = false;
3149 supportedExtensions.multiview = false;
3150 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003151 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003152 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003153
3154 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3155 if (!supportedExtensions.sRGB)
3156 {
3157 supportedExtensions.textureSRGBDecode = false;
3158 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003159 }
3160
3161 if (getClientVersion() < ES_3_1)
3162 {
3163 // Disable ES3.1+ extensions
3164 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003165
3166 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3167 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003168 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003169 }
3170
3171 if (getClientVersion() > ES_2_0)
3172 {
3173 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3174 // supportedExtensions.sRGB = false;
3175 }
3176
3177 // Some extensions are always available because they are implemented in the GL layer.
3178 supportedExtensions.bindUniformLocation = true;
3179 supportedExtensions.vertexArrayObject = true;
3180 supportedExtensions.bindGeneratesResource = true;
3181 supportedExtensions.clientArrays = true;
3182 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003183 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003184
3185 // Enable the no error extension if the context was created with the flag.
3186 supportedExtensions.noError = mSkipValidation;
3187
3188 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003189 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003190
3191 // Explicitly enable GL_KHR_debug
3192 supportedExtensions.debug = true;
3193 supportedExtensions.maxDebugMessageLength = 1024;
3194 supportedExtensions.maxDebugLoggedMessages = 1024;
3195 supportedExtensions.maxDebugGroupStackDepth = 1024;
3196 supportedExtensions.maxLabelLength = 1024;
3197
3198 // Explicitly enable GL_ANGLE_robust_client_memory
3199 supportedExtensions.robustClientMemory = true;
3200
3201 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003202 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003203
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003204 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3205 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003206 supportedExtensions.robustBufferAccessBehavior =
3207 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3208
3209 // Enable the cache control query unconditionally.
3210 supportedExtensions.programCacheControl = true;
3211
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003212 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003213 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003214 {
3215 // GL_ANGLE_explicit_context_gles1
3216 supportedExtensions.explicitContextGles1 = true;
3217 // GL_ANGLE_explicit_context
3218 supportedExtensions.explicitContext = true;
3219 }
3220
Shahbaz Youssefi5313c8a2019-01-14 17:02:52 -05003221 // If EGL_KHR_fence_sync is not enabled, don't expose GL_OES_EGL_sync.
3222 ASSERT(mCurrentDisplay);
3223 if (!mCurrentDisplay->getExtensions().fenceSync)
3224 {
3225 supportedExtensions.eglSync = false;
3226 }
3227
Geoff Lang79b91402018-10-04 15:11:30 -04003228 supportedExtensions.memorySize = true;
3229
Geoff Langb0f917f2017-12-05 13:41:54 -05003230 return supportedExtensions;
3231}
3232
Geoff Lang33f11fb2018-05-07 13:42:47 -04003233void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003234{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003235 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003236
Geoff Lang33f11fb2018-05-07 13:42:47 -04003237 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003238 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003239
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003240 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003241
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003242 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3243 if (getClientVersion() < Version(2, 0))
3244 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003245 mState.mCaps.maxMultitextureUnits = 4;
3246 mState.mCaps.maxClipPlanes = 6;
3247 mState.mCaps.maxLights = 8;
3248 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3249 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3250 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3251 mState.mCaps.minSmoothPointSize = 1.0f;
3252 mState.mCaps.maxSmoothPointSize = 1.0f;
3253 mState.mCaps.minSmoothLineWidth = 1.0f;
3254 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003255 }
3256
Luc Ferronad2ae932018-06-11 15:31:17 -04003257 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003258 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003259
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003260 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003261
Jamie Madill0f80ed82017-09-19 00:24:56 -04003262 if (getClientVersion() < ES_3_1)
3263 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003264 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003265 }
3266 else
3267 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003268 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003269 }
Geoff Lang301d1612014-07-09 10:34:37 -04003270
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003271 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003272 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003273 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003274
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003275 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3276 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003277
3278 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003279 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3280 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003281 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003282 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003283 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003284
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003285 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003286
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003287 mState.mCaps.maxSampleMaskWords =
3288 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003289
Geoff Langc287ea62016-09-16 14:46:51 -04003290 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003291 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003292 for (const auto &extensionInfo : GetExtensionInfoMap())
3293 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003294 // If the user has requested that extensions start disabled and they are requestable,
3295 // disable them.
3296 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003297 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003298 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003299 }
3300 }
3301
3302 // Generate texture caps
3303 updateCaps();
3304}
3305
3306void Context::updateCaps()
3307{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003308 mState.mCaps.compressedTextureFormats.clear();
3309 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003310
Jamie Madill7b62cf92017-11-02 15:20:49 -04003311 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003312 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003313 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003314 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003315
Geoff Lang0d8b7242015-09-09 14:56:53 -04003316 // Update the format caps based on the client version and extensions.
3317 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3318 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003319 formatCaps.texturable = formatCaps.texturable &&
3320 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3321 formatCaps.filterable = formatCaps.filterable &&
3322 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003323 formatCaps.textureAttachment =
3324 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003325 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3326 formatCaps.renderbuffer =
3327 formatCaps.renderbuffer &&
3328 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003329
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003330 // OpenGL ES does not support multisampling with non-rendererable formats
3331 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003332 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003333 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003334 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003335 {
Geoff Langd87878e2014-09-19 15:42:59 -04003336 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003337 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003338 else
3339 {
3340 // We may have limited the max samples for some required renderbuffer formats due to
3341 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3342 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3343
3344 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3345 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3346 // exception of signed and unsigned integer formats."
3347 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3348 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3349 {
3350 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003351 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003352 }
3353
3354 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003355 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003356 {
3357 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3358 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3359 // the exception that the signed and unsigned integer formats are required only to
3360 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3361 // multisamples, which must be at least one."
3362 if (formatInfo.componentType == GL_INT ||
3363 formatInfo.componentType == GL_UNSIGNED_INT)
3364 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003365 mState.mCaps.maxIntegerSamples =
3366 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003367 }
3368
3369 // GLES 3.1 section 19.3.1.
3370 if (formatCaps.texturable)
3371 {
3372 if (formatInfo.depthBits > 0)
3373 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003374 mState.mCaps.maxDepthTextureSamples =
3375 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003376 }
3377 else if (formatInfo.redBits > 0)
3378 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003379 mState.mCaps.maxColorTextureSamples =
3380 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003381 }
3382 }
3383 }
3384 }
Geoff Langd87878e2014-09-19 15:42:59 -04003385
3386 if (formatCaps.texturable && formatInfo.compressed)
3387 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003388 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003389 }
3390
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003391 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003392 }
Jamie Madill32447362017-06-28 14:53:52 -04003393
3394 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003395 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003396 {
3397 mMemoryProgramCache = nullptr;
3398 }
Corentin Walleze4477002017-12-01 14:39:58 -05003399
3400 // Compute which buffer types are allowed
3401 mValidBufferBindings.reset();
3402 mValidBufferBindings.set(BufferBinding::ElementArray);
3403 mValidBufferBindings.set(BufferBinding::Array);
3404
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003405 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003406 {
3407 mValidBufferBindings.set(BufferBinding::PixelPack);
3408 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3409 }
3410
3411 if (getClientVersion() >= ES_3_0)
3412 {
3413 mValidBufferBindings.set(BufferBinding::CopyRead);
3414 mValidBufferBindings.set(BufferBinding::CopyWrite);
3415 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3416 mValidBufferBindings.set(BufferBinding::Uniform);
3417 }
3418
3419 if (getClientVersion() >= ES_3_1)
3420 {
3421 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3422 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3423 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3424 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3425 }
jchen107ae70d82018-07-06 13:47:01 +08003426
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003427 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003428
Jamie Madillef9fcd92018-11-28 14:03:59 -05003429 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003430 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003431 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3432 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3433 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3434 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3435 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3436 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003437
Jamie Madilld51fbe32019-01-25 15:03:39 -05003438 // We need to validate buffer bounds if we are in a WebGL or robust access context and the
3439 // back-end does not support robust buffer access behaviour.
3440 if (!mSupportedExtensions.robustBufferAccessBehavior && (mState.isWebGL() || mRobustAccess))
3441 {
3442 mBufferAccessValidationEnabled = true;
3443 }
3444
Jamie Madillac66f982018-10-09 18:30:01 -04003445 // Reinitialize state cache after extension changes.
3446 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003447}
3448
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003449void Context::initWorkarounds()
3450{
Jamie Madill761b02c2017-06-23 16:27:06 -04003451 // Apply back-end workarounds.
3452 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3453
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003454 // Lose the context upon out of memory error if the application is
3455 // expecting to watch for those events.
3456 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003457
3458 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3459 {
3460 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3461 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3462 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3463 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003464}
3465
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003466bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3467{
3468 return (instanceCount == 0) || noopDraw(mode, count);
3469}
3470
Jamie Madill526392d2018-11-16 09:35:14 -05003471angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003472{
Geoff Langa8cb2872018-03-09 16:09:40 -05003473 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003474 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003475 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003476 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003477}
3478
Jamie Madill526392d2018-11-16 09:35:14 -05003479angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003480{
Geoff Langa8cb2872018-03-09 16:09:40 -05003481 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003482 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3483 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003484 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003485 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003486}
3487
Jamie Madill132d15c2018-11-30 15:25:38 -05003488ANGLE_INLINE angle::Result Context::prepareForDispatch()
3489{
3490 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3491 return syncDirtyBits(mComputeDirtyBits);
3492}
3493
Jamie Madill526392d2018-11-16 09:35:14 -05003494angle::Result Context::syncState(const State::DirtyBits &bitMask,
3495 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003496{
Geoff Langa8cb2872018-03-09 16:09:40 -05003497 ANGLE_TRY(syncDirtyObjects(objectMask));
3498 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003499 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003500}
3501
Jamie Madillc29968b2016-01-20 11:17:23 -05003502void Context::blitFramebuffer(GLint srcX0,
3503 GLint srcY0,
3504 GLint srcX1,
3505 GLint srcY1,
3506 GLint dstX0,
3507 GLint dstY0,
3508 GLint dstX1,
3509 GLint dstY1,
3510 GLbitfield mask,
3511 GLenum filter)
3512{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003513 if (mask == 0)
3514 {
3515 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3516 // buffers are copied.
3517 return;
3518 }
3519
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003520 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003521 ASSERT(drawFramebuffer);
3522
3523 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3524 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3525
Jamie Madillbc918e72018-03-08 09:47:21 -05003526 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003527
Jamie Madill4f6592f2018-11-27 16:37:45 -05003528 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003529}
Jamie Madillc29968b2016-01-20 11:17:23 -05003530
3531void Context::clear(GLbitfield mask)
3532{
Geoff Langd4fff502017-09-22 11:28:28 -04003533 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003534 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003535}
3536
3537void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3538{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003539 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003540 const FramebufferAttachment *attachment = nullptr;
3541 if (buffer == GL_DEPTH)
3542 {
3543 attachment = framebufferObject->getDepthbuffer();
3544 }
3545 if (buffer == GL_COLOR &&
3546 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3547 {
3548 attachment = framebufferObject->getColorbuffer(drawbuffer);
3549 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003550 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3551 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003552 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003553 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003554 return;
3555 }
Geoff Langd4fff502017-09-22 11:28:28 -04003556 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003557 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003558}
3559
3560void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3561{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003562 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003563 const FramebufferAttachment *attachment = nullptr;
3564 if (buffer == GL_COLOR &&
3565 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3566 {
3567 attachment = framebufferObject->getColorbuffer(drawbuffer);
3568 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003569 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3570 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003571 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003572 {
3573 return;
3574 }
Geoff Langd4fff502017-09-22 11:28:28 -04003575 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003576 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003577}
3578
3579void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3580{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003581 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003582 const FramebufferAttachment *attachment = nullptr;
3583 if (buffer == GL_STENCIL)
3584 {
3585 attachment = framebufferObject->getStencilbuffer();
3586 }
3587 if (buffer == GL_COLOR &&
3588 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3589 {
3590 attachment = framebufferObject->getColorbuffer(drawbuffer);
3591 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003592 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3593 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003594 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003595 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003596 return;
3597 }
Geoff Langd4fff502017-09-22 11:28:28 -04003598 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003599 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003600}
3601
3602void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3603{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003604 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003605 ASSERT(framebufferObject);
3606
3607 // If a buffer is not present, the clear has no effect
3608 if (framebufferObject->getDepthbuffer() == nullptr &&
3609 framebufferObject->getStencilbuffer() == nullptr)
3610 {
3611 return;
3612 }
3613
Geoff Langd4fff502017-09-22 11:28:28 -04003614 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3615 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003616}
3617
3618void Context::readPixels(GLint x,
3619 GLint y,
3620 GLsizei width,
3621 GLsizei height,
3622 GLenum format,
3623 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003624 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003625{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003626 if (width == 0 || height == 0)
3627 {
3628 return;
3629 }
3630
Jamie Madillbc918e72018-03-08 09:47:21 -05003631 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003632
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003633 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003634 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003635
3636 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003637 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003638}
3639
Brandon Jones59770802018-04-02 13:18:42 -07003640void Context::readPixelsRobust(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 *pixels)
3651{
3652 readPixels(x, y, width, height, format, type, pixels);
3653}
3654
3655void Context::readnPixelsRobust(GLint x,
3656 GLint y,
3657 GLsizei width,
3658 GLsizei height,
3659 GLenum format,
3660 GLenum type,
3661 GLsizei bufSize,
3662 GLsizei *length,
3663 GLsizei *columns,
3664 GLsizei *rows,
3665 void *data)
3666{
3667 readPixels(x, y, width, height, format, type, data);
3668}
3669
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003670void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003671 GLint level,
3672 GLenum internalformat,
3673 GLint x,
3674 GLint y,
3675 GLsizei width,
3676 GLsizei height,
3677 GLint border)
3678{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003679 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003680 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003681
Jamie Madillc29968b2016-01-20 11:17:23 -05003682 Rectangle sourceArea(x, y, width, height);
3683
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003684 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003685 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003686 ANGLE_CONTEXT_TRY(
3687 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003688}
3689
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003690void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003691 GLint level,
3692 GLint xoffset,
3693 GLint yoffset,
3694 GLint x,
3695 GLint y,
3696 GLsizei width,
3697 GLsizei height)
3698{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003699 if (width == 0 || height == 0)
3700 {
3701 return;
3702 }
3703
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003704 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003705 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003706
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 Offset destOffset(xoffset, yoffset, 0);
3708 Rectangle sourceArea(x, y, width, height);
3709
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003710 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003711 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003712 ANGLE_CONTEXT_TRY(
3713 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003714}
3715
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003716void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003717 GLint level,
3718 GLint xoffset,
3719 GLint yoffset,
3720 GLint zoffset,
3721 GLint x,
3722 GLint y,
3723 GLsizei width,
3724 GLsizei height)
3725{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003726 if (width == 0 || height == 0)
3727 {
3728 return;
3729 }
3730
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003731 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003732 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003733
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 Offset destOffset(xoffset, yoffset, zoffset);
3735 Rectangle sourceArea(x, y, width, height);
3736
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003737 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003738 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003739 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3740 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003741}
3742
3743void Context::framebufferTexture2D(GLenum target,
3744 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003745 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 GLuint texture,
3747 GLint level)
3748{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003749 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 ASSERT(framebuffer);
3751
3752 if (texture != 0)
3753 {
3754 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003755 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003756 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 }
3758 else
3759 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003760 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003761 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003762
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003763 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003764}
3765
3766void Context::framebufferRenderbuffer(GLenum target,
3767 GLenum attachment,
3768 GLenum renderbuffertarget,
3769 GLuint renderbuffer)
3770{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003771 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003772 ASSERT(framebuffer);
3773
3774 if (renderbuffer != 0)
3775 {
3776 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003777
Jamie Madillcc129372018-04-12 09:13:18 -04003778 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003779 renderbufferObject);
3780 }
3781 else
3782 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003783 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003784 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003785
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003786 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003787}
3788
3789void Context::framebufferTextureLayer(GLenum target,
3790 GLenum attachment,
3791 GLuint texture,
3792 GLint level,
3793 GLint layer)
3794{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003795 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796 ASSERT(framebuffer);
3797
3798 if (texture != 0)
3799 {
3800 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003801 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003802 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003803 }
3804 else
3805 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003806 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003807 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003808
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003809 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003810}
3811
Brandon Jones59770802018-04-02 13:18:42 -07003812void Context::framebufferTextureMultiviewLayered(GLenum target,
3813 GLenum attachment,
3814 GLuint texture,
3815 GLint level,
3816 GLint baseViewIndex,
3817 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003818{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003819 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003820 ASSERT(framebuffer);
3821
3822 if (texture != 0)
3823 {
3824 Texture *textureObj = getTexture(texture);
3825
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003826 ImageIndex index;
3827 if (textureObj->getType() == TextureType::_2DArray)
3828 {
3829 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3830 }
3831 else
3832 {
3833 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3834 ASSERT(level == 0);
3835 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3836 }
Martin Radev82ef7742017-08-08 17:44:58 +03003837 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3838 numViews, baseViewIndex);
3839 }
3840 else
3841 {
3842 framebuffer->resetAttachment(this, attachment);
3843 }
3844
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003845 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003846}
3847
Brandon Jones59770802018-04-02 13:18:42 -07003848void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3849 GLenum attachment,
3850 GLuint texture,
3851 GLint level,
3852 GLsizei numViews,
3853 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003854{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003855 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003856 ASSERT(framebuffer);
3857
3858 if (texture != 0)
3859 {
3860 Texture *textureObj = getTexture(texture);
3861
3862 ImageIndex index = ImageIndex::Make2D(level);
3863 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3864 textureObj, numViews, viewportOffsets);
3865 }
3866 else
3867 {
3868 framebuffer->resetAttachment(this, attachment);
3869 }
3870
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003871 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003872}
3873
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003874void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3875{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003876 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003877 ASSERT(framebuffer);
3878
3879 if (texture != 0)
3880 {
3881 Texture *textureObj = getTexture(texture);
3882
3883 ImageIndex index = ImageIndex::MakeFromType(
3884 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3885 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3886 }
3887 else
3888 {
3889 framebuffer->resetAttachment(this, attachment);
3890 }
3891
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003892 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003893}
3894
Jamie Madillc29968b2016-01-20 11:17:23 -05003895void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3896{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003897 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003898 ASSERT(framebuffer);
3899 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003900 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003901 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003902}
3903
3904void Context::readBuffer(GLenum mode)
3905{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003906 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003907 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003908 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003909}
3910
3911void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, 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
3919 // The specification isn't clear what should be done when the framebuffer isn't complete.
3920 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003921 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003922}
3923
3924void Context::invalidateFramebuffer(GLenum target,
3925 GLsizei numAttachments,
3926 const GLenum *attachments)
3927{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003928 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003929 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003930
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003931 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003932 ASSERT(framebuffer);
3933
Jamie Madill427064d2018-04-13 16:20:34 -04003934 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003935 {
Jamie Madill437fa652016-05-03 15:13:24 -04003936 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003937 }
Jamie Madill437fa652016-05-03 15:13:24 -04003938
Jamie Madill4f6592f2018-11-27 16:37:45 -05003939 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003940}
3941
3942void Context::invalidateSubFramebuffer(GLenum target,
3943 GLsizei numAttachments,
3944 const GLenum *attachments,
3945 GLint x,
3946 GLint y,
3947 GLsizei width,
3948 GLsizei height)
3949{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003950 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003951 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003952
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003953 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003954 ASSERT(framebuffer);
3955
Jamie Madill427064d2018-04-13 16:20:34 -04003956 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003957 {
Jamie Madill437fa652016-05-03 15:13:24 -04003958 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003959 }
Jamie Madill437fa652016-05-03 15:13:24 -04003960
3961 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003962 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003963}
3964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003966 GLint level,
3967 GLint internalformat,
3968 GLsizei width,
3969 GLsizei height,
3970 GLint border,
3971 GLenum format,
3972 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003973 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003974{
Jamie Madillbc918e72018-03-08 09:47:21 -05003975 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003976
3977 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003978 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003979 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003980 internalformat, size, format, type,
3981 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003982}
3983
Brandon Jones59770802018-04-02 13:18:42 -07003984void Context::texImage2DRobust(TextureTarget target,
3985 GLint level,
3986 GLint internalformat,
3987 GLsizei width,
3988 GLsizei height,
3989 GLint border,
3990 GLenum format,
3991 GLenum type,
3992 GLsizei bufSize,
3993 const void *pixels)
3994{
3995 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3996}
3997
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003998void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003999 GLint level,
4000 GLint internalformat,
4001 GLsizei width,
4002 GLsizei height,
4003 GLsizei depth,
4004 GLint border,
4005 GLenum format,
4006 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004007 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004008{
Jamie Madillbc918e72018-03-08 09:47:21 -05004009 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004010
4011 Extents size(width, height, depth);
4012 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004013 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05004014 NonCubeTextureTypeToTarget(target), level, internalformat,
4015 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004016}
4017
Brandon Jones59770802018-04-02 13:18:42 -07004018void Context::texImage3DRobust(TextureType target,
4019 GLint level,
4020 GLint internalformat,
4021 GLsizei width,
4022 GLsizei height,
4023 GLsizei depth,
4024 GLint border,
4025 GLenum format,
4026 GLenum type,
4027 GLsizei bufSize,
4028 const void *pixels)
4029{
4030 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4031}
4032
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004033void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004034 GLint level,
4035 GLint xoffset,
4036 GLint yoffset,
4037 GLsizei width,
4038 GLsizei height,
4039 GLenum format,
4040 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004041 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004042{
4043 // Zero sized uploads are valid but no-ops
4044 if (width == 0 || height == 0)
4045 {
4046 return;
4047 }
4048
Jamie Madillbc918e72018-03-08 09:47:21 -05004049 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004050
4051 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004052 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004053
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004054 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004055
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004056 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004057 level, area, format, type,
4058 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004059}
4060
Brandon Jones59770802018-04-02 13:18:42 -07004061void Context::texSubImage2DRobust(TextureTarget target,
4062 GLint level,
4063 GLint xoffset,
4064 GLint yoffset,
4065 GLsizei width,
4066 GLsizei height,
4067 GLenum format,
4068 GLenum type,
4069 GLsizei bufSize,
4070 const void *pixels)
4071{
4072 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4073}
4074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004075void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004076 GLint level,
4077 GLint xoffset,
4078 GLint yoffset,
4079 GLint zoffset,
4080 GLsizei width,
4081 GLsizei height,
4082 GLsizei depth,
4083 GLenum format,
4084 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004085 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004086{
4087 // Zero sized uploads are valid but no-ops
4088 if (width == 0 || height == 0 || depth == 0)
4089 {
4090 return;
4091 }
4092
Jamie Madillbc918e72018-03-08 09:47:21 -05004093 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004094
4095 Box area(xoffset, yoffset, zoffset, width, height, depth);
4096 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004097
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004098 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004099
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004100 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004101 NonCubeTextureTypeToTarget(target), level, area, format,
4102 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004103}
4104
Brandon Jones59770802018-04-02 13:18:42 -07004105void Context::texSubImage3DRobust(TextureType target,
4106 GLint level,
4107 GLint xoffset,
4108 GLint yoffset,
4109 GLint zoffset,
4110 GLsizei width,
4111 GLsizei height,
4112 GLsizei depth,
4113 GLenum format,
4114 GLenum type,
4115 GLsizei bufSize,
4116 const void *pixels)
4117{
4118 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4119 pixels);
4120}
4121
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004122void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004123 GLint level,
4124 GLenum internalformat,
4125 GLsizei width,
4126 GLsizei height,
4127 GLint border,
4128 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004129 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004130{
Jamie Madillbc918e72018-03-08 09:47:21 -05004131 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004132
4133 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004134 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004135 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004136 internalformat, size, imageSize,
4137 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004138}
4139
Brandon Jones59770802018-04-02 13:18:42 -07004140void Context::compressedTexImage2DRobust(TextureTarget target,
4141 GLint level,
4142 GLenum internalformat,
4143 GLsizei width,
4144 GLsizei height,
4145 GLint border,
4146 GLsizei imageSize,
4147 GLsizei dataSize,
4148 const GLvoid *data)
4149{
4150 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4151}
4152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004153void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004154 GLint level,
4155 GLenum internalformat,
4156 GLsizei width,
4157 GLsizei height,
4158 GLsizei depth,
4159 GLint border,
4160 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004161 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004162{
Jamie Madillbc918e72018-03-08 09:47:21 -05004163 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004164
4165 Extents size(width, height, depth);
4166 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004167 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004168 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004169 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004170}
4171
Brandon Jones59770802018-04-02 13:18:42 -07004172void Context::compressedTexImage3DRobust(TextureType target,
4173 GLint level,
4174 GLenum internalformat,
4175 GLsizei width,
4176 GLsizei height,
4177 GLsizei depth,
4178 GLint border,
4179 GLsizei imageSize,
4180 GLsizei dataSize,
4181 const GLvoid *data)
4182{
4183 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4184 data);
4185}
4186
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004187void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004188 GLint level,
4189 GLint xoffset,
4190 GLint yoffset,
4191 GLsizei width,
4192 GLsizei height,
4193 GLenum format,
4194 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004195 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004196{
Jamie Madillbc918e72018-03-08 09:47:21 -05004197 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004198
4199 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004200 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004201 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004202 area, format, imageSize,
4203 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004204}
4205
Brandon Jones59770802018-04-02 13:18:42 -07004206void Context::compressedTexSubImage2DRobust(TextureTarget target,
4207 GLint level,
4208 GLint xoffset,
4209 GLint yoffset,
4210 GLsizei width,
4211 GLsizei height,
4212 GLenum format,
4213 GLsizei imageSize,
4214 GLsizei dataSize,
4215 const GLvoid *data)
4216{
4217 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4218 data);
4219}
4220
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004221void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004222 GLint level,
4223 GLint xoffset,
4224 GLint yoffset,
4225 GLint zoffset,
4226 GLsizei width,
4227 GLsizei height,
4228 GLsizei depth,
4229 GLenum format,
4230 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004231 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004232{
4233 // Zero sized uploads are valid but no-ops
4234 if (width == 0 || height == 0)
4235 {
4236 return;
4237 }
4238
Jamie Madillbc918e72018-03-08 09:47:21 -05004239 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004240
4241 Box area(xoffset, yoffset, zoffset, width, height, depth);
4242 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004243 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004244 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004245 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004246}
4247
Brandon Jones59770802018-04-02 13:18:42 -07004248void Context::compressedTexSubImage3DRobust(TextureType target,
4249 GLint level,
4250 GLint xoffset,
4251 GLint yoffset,
4252 GLint zoffset,
4253 GLsizei width,
4254 GLsizei height,
4255 GLsizei depth,
4256 GLenum format,
4257 GLsizei imageSize,
4258 GLsizei dataSize,
4259 const GLvoid *data)
4260{
4261 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4262 imageSize, data);
4263}
4264
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004265void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004266{
4267 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004268 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004269}
4270
Jamie Madill007530e2017-12-28 14:27:04 -05004271void Context::copyTexture(GLuint sourceId,
4272 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004273 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004274 GLuint destId,
4275 GLint destLevel,
4276 GLint internalFormat,
4277 GLenum destType,
4278 GLboolean unpackFlipY,
4279 GLboolean unpackPremultiplyAlpha,
4280 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004281{
Jamie Madillbc918e72018-03-08 09:47:21 -05004282 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004283
4284 gl::Texture *sourceTexture = getTexture(sourceId);
4285 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004286 ANGLE_CONTEXT_TRY(
4287 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4288 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4289 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004290}
4291
Jamie Madill007530e2017-12-28 14:27:04 -05004292void Context::copySubTexture(GLuint sourceId,
4293 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004294 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004295 GLuint destId,
4296 GLint destLevel,
4297 GLint xoffset,
4298 GLint yoffset,
4299 GLint x,
4300 GLint y,
4301 GLsizei width,
4302 GLsizei height,
4303 GLboolean unpackFlipY,
4304 GLboolean unpackPremultiplyAlpha,
4305 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004306{
4307 // Zero sized copies are valid but no-ops
4308 if (width == 0 || height == 0)
4309 {
4310 return;
4311 }
4312
Jamie Madillbc918e72018-03-08 09:47:21 -05004313 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004314
4315 gl::Texture *sourceTexture = getTexture(sourceId);
4316 gl::Texture *destTexture = getTexture(destId);
4317 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004318 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004319 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4320 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4321 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4322 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004323}
4324
4325void Context::copyTexture3D(GLuint sourceId,
4326 GLint sourceLevel,
4327 TextureTarget destTarget,
4328 GLuint destId,
4329 GLint destLevel,
4330 GLint internalFormat,
4331 GLenum destType,
4332 GLboolean unpackFlipY,
4333 GLboolean unpackPremultiplyAlpha,
4334 GLboolean unpackUnmultiplyAlpha)
4335{
4336 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4337
4338 Texture *sourceTexture = getTexture(sourceId);
4339 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004340 ANGLE_CONTEXT_TRY(
4341 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4342 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4343 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004344}
4345
4346void Context::copySubTexture3D(GLuint sourceId,
4347 GLint sourceLevel,
4348 TextureTarget destTarget,
4349 GLuint destId,
4350 GLint destLevel,
4351 GLint xoffset,
4352 GLint yoffset,
4353 GLint zoffset,
4354 GLint x,
4355 GLint y,
4356 GLint z,
4357 GLsizei width,
4358 GLsizei height,
4359 GLsizei depth,
4360 GLboolean unpackFlipY,
4361 GLboolean unpackPremultiplyAlpha,
4362 GLboolean unpackUnmultiplyAlpha)
4363{
4364 // Zero sized copies are valid but no-ops
4365 if (width == 0 || height == 0 || depth == 0)
4366 {
4367 return;
4368 }
4369
4370 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4371
4372 Texture *sourceTexture = getTexture(sourceId);
4373 Texture *destTexture = getTexture(destId);
4374 Offset offset(xoffset, yoffset, zoffset);
4375 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004376 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4377 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4378 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4379 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004380}
4381
Jamie Madill007530e2017-12-28 14:27:04 -05004382void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004383{
Jamie Madillbc918e72018-03-08 09:47:21 -05004384 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004385
4386 gl::Texture *sourceTexture = getTexture(sourceId);
4387 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004388 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004389}
4390
Corentin Wallez336129f2017-10-17 15:55:40 -04004391void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004392{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004393 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004394 ASSERT(buffer);
4395
Geoff Lang496c02d2016-10-20 11:38:11 -07004396 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004397}
4398
Brandon Jones59770802018-04-02 13:18:42 -07004399void Context::getBufferPointervRobust(BufferBinding target,
4400 GLenum pname,
4401 GLsizei bufSize,
4402 GLsizei *length,
4403 void **params)
4404{
4405 getBufferPointerv(target, pname, params);
4406}
4407
Corentin Wallez336129f2017-10-17 15:55:40 -04004408void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004409{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004410 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004411 ASSERT(buffer);
4412
Jamie Madill7c985f52018-11-29 18:16:17 -05004413 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004414 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004415 return nullptr;
4416 }
4417
4418 return buffer->getMapPointer();
4419}
4420
Corentin Wallez336129f2017-10-17 15:55:40 -04004421GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004422{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004423 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004424 ASSERT(buffer);
4425
4426 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004427 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004428 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004429 return GL_FALSE;
4430 }
4431
4432 return result;
4433}
4434
Corentin Wallez336129f2017-10-17 15:55:40 -04004435void *Context::mapBufferRange(BufferBinding target,
4436 GLintptr offset,
4437 GLsizeiptr length,
4438 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004439{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004440 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004441 ASSERT(buffer);
4442
Jamie Madill7c985f52018-11-29 18:16:17 -05004443 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004444 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004445 return nullptr;
4446 }
4447
4448 return buffer->getMapPointer();
4449}
4450
Corentin Wallez336129f2017-10-17 15:55:40 -04004451void Context::flushMappedBufferRange(BufferBinding /*target*/,
4452 GLintptr /*offset*/,
4453 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004454{
4455 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4456}
4457
Jamie Madill526392d2018-11-16 09:35:14 -05004458angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004459{
Geoff Langa8cb2872018-03-09 16:09:40 -05004460 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004461}
4462
Jamie Madill526392d2018-11-16 09:35:14 -05004463angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004464{
Geoff Langa8cb2872018-03-09 16:09:40 -05004465 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004466}
4467
Jamie Madill526392d2018-11-16 09:35:14 -05004468angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004469{
Geoff Langa8cb2872018-03-09 16:09:40 -05004470 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004471}
4472
Jamie Madill526392d2018-11-16 09:35:14 -05004473angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004474{
4475 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4476
4477 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4478 ANGLE_TRY(syncDirtyBits());
4479
Jamie Madill7c985f52018-11-29 18:16:17 -05004480 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004481}
4482
Jiajia Qin5451d532017-11-16 17:16:34 +08004483void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4484{
4485 UNIMPLEMENTED();
4486}
4487
Jamie Madillc20ab272016-06-09 07:20:46 -07004488void Context::activeTexture(GLenum texture)
4489{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004490 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004491}
4492
Jamie Madill876429b2017-04-20 15:46:24 -04004493void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004494{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004495 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004498void Context::blendEquation(GLenum mode)
4499{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004500 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004501}
4502
Jamie Madillc20ab272016-06-09 07:20:46 -07004503void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4504{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004505 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004508void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4509{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004510 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004511}
4512
Jamie Madillc20ab272016-06-09 07:20:46 -07004513void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4514{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004515 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
Jamie Madill876429b2017-04-20 15:46:24 -04004518void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004519{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004520 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004521}
4522
Jamie Madill876429b2017-04-20 15:46:24 -04004523void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004524{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004525 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004526}
4527
4528void Context::clearStencil(GLint s)
4529{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004530 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004531}
4532
4533void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4534{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004535 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4536 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004539void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004540{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004541 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::depthFunc(GLenum func)
4545{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004546 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004547}
4548
4549void Context::depthMask(GLboolean flag)
4550{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004551 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004552}
4553
Jamie Madill876429b2017-04-20 15:46:24 -04004554void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004555{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004556 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004557}
4558
4559void Context::disable(GLenum cap)
4560{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004561 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004562 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::disableVertexAttribArray(GLuint index)
4566{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004567 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004568 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::enable(GLenum cap)
4572{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004573 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004574 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::enableVertexAttribArray(GLuint index)
4578{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004579 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004580 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::frontFace(GLenum mode)
4584{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004585 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
4588void Context::hint(GLenum target, GLenum mode)
4589{
4590 switch (target)
4591 {
4592 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004593 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004594 break;
4595
4596 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004597 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598 break;
4599
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004600 case GL_PERSPECTIVE_CORRECTION_HINT:
4601 case GL_POINT_SMOOTH_HINT:
4602 case GL_LINE_SMOOTH_HINT:
4603 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004604 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004605 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004606 default:
4607 UNREACHABLE();
4608 return;
4609 }
4610}
4611
4612void Context::lineWidth(GLfloat width)
4613{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004614 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615}
4616
4617void Context::pixelStorei(GLenum pname, GLint param)
4618{
4619 switch (pname)
4620 {
4621 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004622 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623 break;
4624
4625 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004626 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004627 break;
4628
4629 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004630 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631 break;
4632
4633 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004634 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004635 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636 break;
4637
4638 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004639 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004640 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004641 break;
4642
4643 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004644 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004645 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646 break;
4647
4648 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004649 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004650 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004651 break;
4652
4653 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004654 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004655 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656 break;
4657
4658 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004659 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004660 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004661 break;
4662
4663 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004664 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004665 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004666 break;
4667
4668 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004669 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004670 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004671 break;
4672
4673 default:
4674 UNREACHABLE();
4675 return;
4676 }
4677}
4678
4679void Context::polygonOffset(GLfloat factor, GLfloat units)
4680{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004681 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
Jamie Madill876429b2017-04-20 15:46:24 -04004684void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004685{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004686 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004687}
4688
Jiawei Shaodb342272017-09-27 10:21:45 +08004689void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4690{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004691 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004692}
4693
Jamie Madillc20ab272016-06-09 07:20:46 -07004694void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4695{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004696 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4700{
4701 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4702 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004703 mState.setStencilParams(func, ref, 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.setStencilBackParams(func, ref, 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::stencilMaskSeparate(GLenum face, GLuint mask)
4715{
4716 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4717 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004718 mState.setStencilWritemask(mask);
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.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004724 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004725
4726 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004727}
4728
4729void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4730{
4731 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4732 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004733 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004734 }
4735
4736 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4737 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004738 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004739 }
4740}
4741
4742void Context::vertexAttrib1f(GLuint index, GLfloat x)
4743{
4744 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004745 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004746 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004747}
4748
4749void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4750{
4751 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004752 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004753 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004754}
4755
4756void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4757{
4758 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004759 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004760 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004761}
4762
4763void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4764{
4765 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004766 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768}
4769
4770void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4771{
4772 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004773 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004774 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004775}
4776
4777void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4778{
4779 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004780 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004781 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004782}
4783
4784void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4785{
4786 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004787 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004788 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004789}
4790
4791void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4792{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004793 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004794 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004795}
4796
4797void Context::vertexAttribPointer(GLuint index,
4798 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004799 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004800 GLboolean normalized,
4801 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004802 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004803{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004804 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
Jamie Madill6e18a232019-01-16 13:27:14 -05004805 type, ConvertToBool(normalized), stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004806 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004807}
4808
Shao80957d92017-02-20 21:25:59 +08004809void Context::vertexAttribFormat(GLuint attribIndex,
4810 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004811 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004812 GLboolean normalized,
4813 GLuint relativeOffset)
4814{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004815 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4816 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004817 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004818}
4819
4820void Context::vertexAttribIFormat(GLuint attribIndex,
4821 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004822 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004823 GLuint relativeOffset)
4824{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004825 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004826 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004827}
4828
4829void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4830{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004831 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004832 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004833}
4834
Jiajia Qin5451d532017-11-16 17:16:34 +08004835void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004836{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004837 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004838 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004839}
4840
Jamie Madillc20ab272016-06-09 07:20:46 -07004841void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4842{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004843 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004844}
4845
4846void Context::vertexAttribIPointer(GLuint index,
4847 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004848 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004849 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004850 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004851{
Jamie Madill6e18a232019-01-16 13:27:14 -05004852 mState.setVertexAttribIPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4853 type, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004854 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004855}
4856
4857void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4858{
4859 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004860 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004861 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004862}
4863
4864void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4865{
4866 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004867 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004868 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004869}
4870
4871void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4872{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004873 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004874 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004875}
4876
4877void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4878{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004879 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004880 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004881}
4882
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004883void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4884{
4885 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004886 getState().getVertexAttribCurrentValue(index);
4887 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004888 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4889 currentValues, pname, params);
4890}
4891
Brandon Jones59770802018-04-02 13:18:42 -07004892void Context::getVertexAttribivRobust(GLuint index,
4893 GLenum pname,
4894 GLsizei bufSize,
4895 GLsizei *length,
4896 GLint *params)
4897{
4898 getVertexAttribiv(index, pname, params);
4899}
4900
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004901void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4902{
4903 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004904 getState().getVertexAttribCurrentValue(index);
4905 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004906 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4907 currentValues, pname, params);
4908}
4909
Brandon Jones59770802018-04-02 13:18:42 -07004910void Context::getVertexAttribfvRobust(GLuint index,
4911 GLenum pname,
4912 GLsizei bufSize,
4913 GLsizei *length,
4914 GLfloat *params)
4915{
4916 getVertexAttribfv(index, pname, params);
4917}
4918
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004919void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4920{
4921 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004922 getState().getVertexAttribCurrentValue(index);
4923 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004924 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4925 currentValues, pname, params);
4926}
4927
Brandon Jones59770802018-04-02 13:18:42 -07004928void Context::getVertexAttribIivRobust(GLuint index,
4929 GLenum pname,
4930 GLsizei bufSize,
4931 GLsizei *length,
4932 GLint *params)
4933{
4934 getVertexAttribIiv(index, pname, params);
4935}
4936
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004937void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4938{
4939 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004940 getState().getVertexAttribCurrentValue(index);
4941 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004942 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4943 currentValues, pname, params);
4944}
4945
Brandon Jones59770802018-04-02 13:18:42 -07004946void Context::getVertexAttribIuivRobust(GLuint index,
4947 GLenum pname,
4948 GLsizei bufSize,
4949 GLsizei *length,
4950 GLuint *params)
4951{
4952 getVertexAttribIuiv(index, pname, params);
4953}
4954
Jamie Madill876429b2017-04-20 15:46:24 -04004955void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004956{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004957 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004958 QueryVertexAttribPointerv(attrib, pname, pointer);
4959}
4960
Brandon Jones59770802018-04-02 13:18:42 -07004961void Context::getVertexAttribPointervRobust(GLuint index,
4962 GLenum pname,
4963 GLsizei bufSize,
4964 GLsizei *length,
4965 void **pointer)
4966{
4967 getVertexAttribPointerv(index, pname, pointer);
4968}
4969
Jamie Madillc20ab272016-06-09 07:20:46 -07004970void Context::debugMessageControl(GLenum source,
4971 GLenum type,
4972 GLenum severity,
4973 GLsizei count,
4974 const GLuint *ids,
4975 GLboolean enabled)
4976{
4977 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004978 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4979 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004980}
4981
4982void Context::debugMessageInsert(GLenum source,
4983 GLenum type,
4984 GLuint id,
4985 GLenum severity,
4986 GLsizei length,
4987 const GLchar *buf)
4988{
4989 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004990 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004991}
4992
4993void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4994{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004995 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004996}
4997
4998GLuint Context::getDebugMessageLog(GLuint count,
4999 GLsizei bufSize,
5000 GLenum *sources,
5001 GLenum *types,
5002 GLuint *ids,
5003 GLenum *severities,
5004 GLsizei *lengths,
5005 GLchar *messageLog)
5006{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005007 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
5008 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005009}
5010
5011void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5012{
5013 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005014 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005015 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005016}
5017
5018void Context::popDebugGroup()
5019{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005020 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005021 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005022}
5023
Corentin Wallez336129f2017-10-17 15:55:40 -04005024void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005025{
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->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005029}
5030
Corentin Wallez336129f2017-10-17 15:55:40 -04005031void Context::bufferSubData(BufferBinding target,
5032 GLintptr offset,
5033 GLsizeiptr size,
5034 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005035{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005036 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005037 {
5038 return;
5039 }
5040
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005041 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005042 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005043 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005044}
5045
Jamie Madillef300b12016-10-07 15:12:09 -04005046void Context::attachShader(GLuint program, GLuint shader)
5047{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005048 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5049 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005050 ASSERT(programObject && shaderObject);
5051 programObject->attachShader(shaderObject);
5052}
5053
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005054const Workarounds &Context::getWorkarounds() const
5055{
5056 return mWorkarounds;
5057}
5058
Corentin Wallez336129f2017-10-17 15:55:40 -04005059void Context::copyBufferSubData(BufferBinding readTarget,
5060 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005061 GLintptr readOffset,
5062 GLintptr writeOffset,
5063 GLsizeiptr size)
5064{
5065 // if size is zero, the copy is a successful no-op
5066 if (size == 0)
5067 {
5068 return;
5069 }
5070
5071 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005072 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5073 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005074
Jamie Madill4f6592f2018-11-27 16:37:45 -05005075 ANGLE_CONTEXT_TRY(
5076 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005077}
5078
Jamie Madill01a80ee2016-11-07 12:06:18 -05005079void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5080{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005081 // Ideally we could share the program query with the validation layer if possible.
5082 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005083 ASSERT(programObject);
5084 programObject->bindAttributeLocation(index, name);
5085}
5086
Corentin Wallez336129f2017-10-17 15:55:40 -04005087void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005088{
5089 bindBufferRange(target, index, buffer, 0, 0);
5090}
5091
Corentin Wallez336129f2017-10-17 15:55:40 -04005092void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005093 GLuint index,
5094 GLuint buffer,
5095 GLintptr offset,
5096 GLsizeiptr size)
5097{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005098 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5099 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005100 if (target == BufferBinding::Uniform)
5101 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005102 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005103 mStateCache.onUniformBufferStateChange(this);
5104 }
5105 else
5106 {
5107 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005108 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005109}
5110
Jamie Madill01a80ee2016-11-07 12:06:18 -05005111void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5112{
5113 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5114 {
5115 bindReadFramebuffer(framebuffer);
5116 }
5117
5118 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5119 {
5120 bindDrawFramebuffer(framebuffer);
5121 }
5122}
5123
5124void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5125{
5126 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005127 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5128 mImplementation.get(), renderbuffer);
5129 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005130}
5131
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005132void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005133 GLsizei samples,
5134 GLenum internalformat,
5135 GLsizei width,
5136 GLsizei height,
5137 GLboolean fixedsamplelocations)
5138{
5139 Extents size(width, height, 1);
5140 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005141 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5142 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005143}
5144
Olli Etuaho89664842018-08-24 14:45:36 +03005145void Context::texStorage3DMultisample(TextureType target,
5146 GLsizei samples,
5147 GLenum internalformat,
5148 GLsizei width,
5149 GLsizei height,
5150 GLsizei depth,
5151 GLboolean fixedsamplelocations)
5152{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005153 Extents size(width, height, depth);
5154 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005155 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5156 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005157}
5158
JiangYizhoubddc46b2016-12-09 09:50:51 +08005159void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5160{
JiangYizhou5b03f472017-01-09 10:22:53 +08005161 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5162 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005163 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5164 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005165
5166 switch (pname)
5167 {
5168 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005169 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005170 break;
5171 default:
5172 UNREACHABLE();
5173 }
5174}
5175
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005176void Context::getMultisamplefvRobust(GLenum pname,
5177 GLuint index,
5178 GLsizei bufSize,
5179 GLsizei *length,
5180 GLfloat *val)
5181{
5182 UNIMPLEMENTED();
5183}
5184
Jamie Madille8fb6402017-02-14 17:56:40 -05005185void Context::renderbufferStorage(GLenum target,
5186 GLenum internalformat,
5187 GLsizei width,
5188 GLsizei height)
5189{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005190 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5191 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5192
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005193 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005194 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005195}
5196
5197void Context::renderbufferStorageMultisample(GLenum target,
5198 GLsizei samples,
5199 GLenum internalformat,
5200 GLsizei width,
5201 GLsizei height)
5202{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005203 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5204 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005205
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005206 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005207 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005208 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005209}
5210
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005211void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5212{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005213 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005214 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005215}
5216
JiangYizhoue18e6392017-02-20 10:32:23 +08005217void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5218{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005219 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005220 QueryFramebufferParameteriv(framebuffer, pname, params);
5221}
5222
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005223void Context::getFramebufferParameterivRobust(GLenum target,
5224 GLenum pname,
5225 GLsizei bufSize,
5226 GLsizei *length,
5227 GLint *params)
5228{
5229 UNIMPLEMENTED();
5230}
5231
Jiajia Qin5451d532017-11-16 17:16:34 +08005232void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005233{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005234 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005235 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005236}
5237
Jamie Madilldec86232018-07-11 09:01:18 -04005238bool Context::getScratchBuffer(size_t requstedSizeBytes,
5239 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005240{
Jamie Madilldec86232018-07-11 09:01:18 -04005241 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005242}
5243
Jamie Madilldec86232018-07-11 09:01:18 -04005244bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5245 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005246{
Jamie Madilldec86232018-07-11 09:01:18 -04005247 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005248}
5249
Xinghua Cao2b396592017-03-29 15:36:04 +08005250void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5251{
5252 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5253 {
5254 return;
5255 }
5256
Xinghua Cao10a4d432017-11-28 14:46:26 +08005257 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005258 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005259}
5260
Jiajia Qin5451d532017-11-16 17:16:34 +08005261void Context::dispatchComputeIndirect(GLintptr indirect)
5262{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005263 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005264 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005265}
5266
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005267void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005268 GLsizei levels,
5269 GLenum internalFormat,
5270 GLsizei width,
5271 GLsizei height)
5272{
5273 Extents size(width, height, 1);
5274 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005275 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005276}
5277
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005278void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005279 GLsizei levels,
5280 GLenum internalFormat,
5281 GLsizei width,
5282 GLsizei height,
5283 GLsizei depth)
5284{
5285 Extents size(width, height, depth);
5286 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005287 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005288}
5289
Jiajia Qin5451d532017-11-16 17:16:34 +08005290void Context::memoryBarrier(GLbitfield barriers)
5291{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005292 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005293}
5294
5295void Context::memoryBarrierByRegion(GLbitfield barriers)
5296{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005297 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005298}
5299
Austin Eng1bf18ce2018-10-19 15:34:02 -07005300void Context::multiDrawArrays(PrimitiveMode mode,
5301 const GLint *firsts,
5302 const GLsizei *counts,
5303 GLsizei drawcount)
5304{
5305 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005306 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005307 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5308 if (hasDrawID)
5309 {
5310 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5311 {
5312 if (noopDraw(mode, counts[drawID]))
5313 {
5314 continue;
5315 }
5316 programObject->setDrawIDUniform(drawID);
5317 ANGLE_CONTEXT_TRY(
5318 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005319 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005320 }
5321 }
5322 else
5323 {
5324 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5325 {
5326 if (noopDraw(mode, counts[drawID]))
5327 {
5328 continue;
5329 }
5330 ANGLE_CONTEXT_TRY(
5331 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005332 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005333 }
5334 }
5335}
5336
5337void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5338 const GLint *firsts,
5339 const GLsizei *counts,
5340 const GLsizei *instanceCounts,
5341 GLsizei drawcount)
5342{
5343 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005344 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005345 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5346 if (hasDrawID)
5347 {
5348 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5349 {
5350 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5351 {
5352 continue;
5353 }
5354 programObject->setDrawIDUniform(drawID);
5355 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5356 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005357 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005358 }
5359 }
5360 else
5361 {
5362 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5363 {
5364 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5365 {
5366 continue;
5367 }
5368 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5369 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005370 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005371 }
5372 }
5373}
5374
5375void Context::multiDrawElements(PrimitiveMode mode,
5376 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005377 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005378 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005379 GLsizei drawcount)
5380{
5381 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005382 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005383 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5384 if (hasDrawID)
5385 {
5386 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5387 {
5388 if (noopDraw(mode, counts[drawID]))
5389 {
5390 continue;
5391 }
5392 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005393 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005394 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005395 }
5396 }
5397 else
5398 {
5399 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5400 {
5401 if (noopDraw(mode, counts[drawID]))
5402 {
5403 continue;
5404 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005405 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005406 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005407 }
5408 }
5409}
5410
5411void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5412 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005413 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005414 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005415 const GLsizei *instanceCounts,
5416 GLsizei drawcount)
5417{
5418 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005419 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005420 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5421 if (hasDrawID)
5422 {
5423 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5424 {
5425 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5426 {
5427 continue;
5428 }
5429 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005430 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005431 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005432 }
5433 }
5434 else
5435 {
5436 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5437 {
5438 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5439 {
5440 continue;
5441 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005442 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005443 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005444 }
5445 }
5446}
5447
Jeff Gilbert465d6092019-01-02 16:21:18 -08005448void Context::provokingVertex(ProvokingVertex provokeMode)
5449{
5450 mState.setProvokingVertex(provokeMode);
5451}
5452
Jamie Madillc1d770e2017-04-13 17:31:24 -04005453GLenum Context::checkFramebufferStatus(GLenum target)
5454{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005455 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005456 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005457 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005458}
5459
5460void Context::compileShader(GLuint shader)
5461{
5462 Shader *shaderObject = GetValidShader(this, shader);
5463 if (!shaderObject)
5464 {
5465 return;
5466 }
5467 shaderObject->compile(this);
5468}
5469
5470void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5471{
5472 for (int i = 0; i < n; i++)
5473 {
5474 deleteBuffer(buffers[i]);
5475 }
5476}
5477
5478void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5479{
5480 for (int i = 0; i < n; i++)
5481 {
5482 if (framebuffers[i] != 0)
5483 {
5484 deleteFramebuffer(framebuffers[i]);
5485 }
5486 }
5487}
5488
5489void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5490{
5491 for (int i = 0; i < n; i++)
5492 {
5493 deleteRenderbuffer(renderbuffers[i]);
5494 }
5495}
5496
5497void Context::deleteTextures(GLsizei n, const GLuint *textures)
5498{
5499 for (int i = 0; i < n; i++)
5500 {
5501 if (textures[i] != 0)
5502 {
5503 deleteTexture(textures[i]);
5504 }
5505 }
5506}
5507
5508void Context::detachShader(GLuint program, GLuint shader)
5509{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005510 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005511 ASSERT(programObject);
5512
5513 Shader *shaderObject = getShader(shader);
5514 ASSERT(shaderObject);
5515
5516 programObject->detachShader(this, shaderObject);
5517}
5518
5519void Context::genBuffers(GLsizei n, GLuint *buffers)
5520{
5521 for (int i = 0; i < n; i++)
5522 {
5523 buffers[i] = createBuffer();
5524 }
5525}
5526
5527void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5528{
5529 for (int i = 0; i < n; i++)
5530 {
5531 framebuffers[i] = createFramebuffer();
5532 }
5533}
5534
5535void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5536{
5537 for (int i = 0; i < n; i++)
5538 {
5539 renderbuffers[i] = createRenderbuffer();
5540 }
5541}
5542
5543void Context::genTextures(GLsizei n, GLuint *textures)
5544{
5545 for (int i = 0; i < n; i++)
5546 {
5547 textures[i] = createTexture();
5548 }
5549}
5550
5551void Context::getActiveAttrib(GLuint program,
5552 GLuint index,
5553 GLsizei bufsize,
5554 GLsizei *length,
5555 GLint *size,
5556 GLenum *type,
5557 GLchar *name)
5558{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005559 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005560 ASSERT(programObject);
5561 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5562}
5563
5564void Context::getActiveUniform(GLuint program,
5565 GLuint index,
5566 GLsizei bufsize,
5567 GLsizei *length,
5568 GLint *size,
5569 GLenum *type,
5570 GLchar *name)
5571{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005572 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573 ASSERT(programObject);
5574 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5575}
5576
5577void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5578{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005579 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005580 ASSERT(programObject);
5581 programObject->getAttachedShaders(maxcount, count, shaders);
5582}
5583
5584GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5585{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005586 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005587 ASSERT(programObject);
5588 return programObject->getAttributeLocation(name);
5589}
5590
5591void Context::getBooleanv(GLenum pname, GLboolean *params)
5592{
5593 GLenum nativeType;
5594 unsigned int numParams = 0;
5595 getQueryParameterInfo(pname, &nativeType, &numParams);
5596
5597 if (nativeType == GL_BOOL)
5598 {
5599 getBooleanvImpl(pname, params);
5600 }
5601 else
5602 {
5603 CastStateValues(this, nativeType, pname, numParams, params);
5604 }
5605}
5606
Brandon Jones59770802018-04-02 13:18:42 -07005607void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5608{
5609 getBooleanv(pname, params);
5610}
5611
Jamie Madillc1d770e2017-04-13 17:31:24 -04005612void Context::getFloatv(GLenum pname, GLfloat *params)
5613{
5614 GLenum nativeType;
5615 unsigned int numParams = 0;
5616 getQueryParameterInfo(pname, &nativeType, &numParams);
5617
5618 if (nativeType == GL_FLOAT)
5619 {
5620 getFloatvImpl(pname, params);
5621 }
5622 else
5623 {
5624 CastStateValues(this, nativeType, pname, numParams, params);
5625 }
5626}
5627
Brandon Jones59770802018-04-02 13:18:42 -07005628void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5629{
5630 getFloatv(pname, params);
5631}
5632
Jamie Madillc1d770e2017-04-13 17:31:24 -04005633void Context::getIntegerv(GLenum pname, GLint *params)
5634{
5635 GLenum nativeType;
5636 unsigned int numParams = 0;
5637 getQueryParameterInfo(pname, &nativeType, &numParams);
5638
5639 if (nativeType == GL_INT)
5640 {
5641 getIntegervImpl(pname, params);
5642 }
5643 else
5644 {
5645 CastStateValues(this, nativeType, pname, numParams, params);
5646 }
5647}
5648
Brandon Jones59770802018-04-02 13:18:42 -07005649void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5650{
5651 getIntegerv(pname, data);
5652}
5653
Jamie Madillc1d770e2017-04-13 17:31:24 -04005654void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5655{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005656 // Don't resolve link if checking the link completion status.
5657 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5658 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005659 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005660 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005661}
5662
Brandon Jones59770802018-04-02 13:18:42 -07005663void Context::getProgramivRobust(GLuint program,
5664 GLenum pname,
5665 GLsizei bufSize,
5666 GLsizei *length,
5667 GLint *params)
5668{
5669 getProgramiv(program, pname, params);
5670}
5671
Jiajia Qin5451d532017-11-16 17:16:34 +08005672void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5673{
5674 UNIMPLEMENTED();
5675}
5676
Jamie Madillbe849e42017-05-02 15:49:00 -04005677void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005678{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005679 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005680 ASSERT(programObject);
5681 programObject->getInfoLog(bufsize, length, infolog);
5682}
5683
Jiajia Qin5451d532017-11-16 17:16:34 +08005684void Context::getProgramPipelineInfoLog(GLuint pipeline,
5685 GLsizei bufSize,
5686 GLsizei *length,
5687 GLchar *infoLog)
5688{
5689 UNIMPLEMENTED();
5690}
5691
Jamie Madillc1d770e2017-04-13 17:31:24 -04005692void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5693{
5694 Shader *shaderObject = getShader(shader);
5695 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005696 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005697}
5698
Brandon Jones59770802018-04-02 13:18:42 -07005699void Context::getShaderivRobust(GLuint shader,
5700 GLenum pname,
5701 GLsizei bufSize,
5702 GLsizei *length,
5703 GLint *params)
5704{
5705 getShaderiv(shader, pname, params);
5706}
5707
Jamie Madillc1d770e2017-04-13 17:31:24 -04005708void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5709{
5710 Shader *shaderObject = getShader(shader);
5711 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005712 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005713}
5714
5715void Context::getShaderPrecisionFormat(GLenum shadertype,
5716 GLenum precisiontype,
5717 GLint *range,
5718 GLint *precision)
5719{
5720 // TODO(jmadill): Compute shaders.
5721
5722 switch (shadertype)
5723 {
5724 case GL_VERTEX_SHADER:
5725 switch (precisiontype)
5726 {
5727 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005728 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005729 break;
5730 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005731 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005732 break;
5733 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005734 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005735 break;
5736
5737 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005738 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739 break;
5740 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005741 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005742 break;
5743 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005744 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005745 break;
5746
5747 default:
5748 UNREACHABLE();
5749 return;
5750 }
5751 break;
5752
5753 case GL_FRAGMENT_SHADER:
5754 switch (precisiontype)
5755 {
5756 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005757 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005758 break;
5759 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005760 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005761 break;
5762 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005763 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005764 break;
5765
5766 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005767 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005768 break;
5769 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005770 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005771 break;
5772 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005773 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005774 break;
5775
5776 default:
5777 UNREACHABLE();
5778 return;
5779 }
5780 break;
5781
5782 default:
5783 UNREACHABLE();
5784 return;
5785 }
5786}
5787
5788void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5789{
5790 Shader *shaderObject = getShader(shader);
5791 ASSERT(shaderObject);
5792 shaderObject->getSource(bufsize, length, source);
5793}
5794
5795void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5796{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005797 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005798 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005799 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005800}
5801
Brandon Jones59770802018-04-02 13:18:42 -07005802void Context::getUniformfvRobust(GLuint program,
5803 GLint location,
5804 GLsizei bufSize,
5805 GLsizei *length,
5806 GLfloat *params)
5807{
5808 getUniformfv(program, location, params);
5809}
5810
Jamie Madillc1d770e2017-04-13 17:31:24 -04005811void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5812{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005813 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005814 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005815 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005816}
5817
Brandon Jones59770802018-04-02 13:18:42 -07005818void Context::getUniformivRobust(GLuint program,
5819 GLint location,
5820 GLsizei bufSize,
5821 GLsizei *length,
5822 GLint *params)
5823{
5824 getUniformiv(program, location, params);
5825}
5826
Jamie Madillc1d770e2017-04-13 17:31:24 -04005827GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5828{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005829 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005830 ASSERT(programObject);
5831 return programObject->getUniformLocation(name);
5832}
5833
5834GLboolean Context::isBuffer(GLuint buffer)
5835{
5836 if (buffer == 0)
5837 {
5838 return GL_FALSE;
5839 }
5840
5841 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5842}
5843
5844GLboolean Context::isEnabled(GLenum cap)
5845{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005846 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005847}
5848
5849GLboolean Context::isFramebuffer(GLuint framebuffer)
5850{
5851 if (framebuffer == 0)
5852 {
5853 return GL_FALSE;
5854 }
5855
5856 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5857}
5858
5859GLboolean Context::isProgram(GLuint program)
5860{
5861 if (program == 0)
5862 {
5863 return GL_FALSE;
5864 }
5865
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005866 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005867}
5868
5869GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5870{
5871 if (renderbuffer == 0)
5872 {
5873 return GL_FALSE;
5874 }
5875
5876 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5877}
5878
5879GLboolean Context::isShader(GLuint shader)
5880{
5881 if (shader == 0)
5882 {
5883 return GL_FALSE;
5884 }
5885
5886 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5887}
5888
5889GLboolean Context::isTexture(GLuint texture)
5890{
5891 if (texture == 0)
5892 {
5893 return GL_FALSE;
5894 }
5895
5896 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5897}
5898
5899void Context::linkProgram(GLuint program)
5900{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005901 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005902 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005903 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005904
5905 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5906 // don't need to worry that:
5907 // 1. Draw calls after link use the new executable code or the old one depending on the link
5908 // result.
5909 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5910 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5911 // ProgramD3D.
5912 if (programObject->isInUse())
5913 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005914 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005915 if (programObject->isLinked())
5916 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005917 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005918 }
jchen107ae70d82018-07-06 13:47:01 +08005919 mStateCache.onProgramExecutableChange(this);
5920 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005921}
5922
5923void Context::releaseShaderCompiler()
5924{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005925 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005926}
5927
5928void Context::shaderBinary(GLsizei n,
5929 const GLuint *shaders,
5930 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005931 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005932 GLsizei length)
5933{
5934 // No binary shader formats are supported.
5935 UNIMPLEMENTED();
5936}
5937
Olli Etuaho0ca09752018-09-24 11:00:50 +03005938void Context::bindFragDataLocationIndexed(GLuint program,
5939 GLuint colorNumber,
5940 GLuint index,
5941 const char *name)
5942{
5943 Program *programObject = getProgramNoResolveLink(program);
5944 programObject->bindFragmentOutputLocation(colorNumber, name);
5945 programObject->bindFragmentOutputIndex(index, name);
5946}
5947
5948void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5949{
5950 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5951}
5952
5953int Context::getFragDataIndex(GLuint program, const char *name)
5954{
5955 Program *programObject = getProgramResolveLink(program);
5956 return programObject->getFragDataIndex(name);
5957}
5958
5959int Context::getProgramResourceLocationIndex(GLuint program,
5960 GLenum programInterface,
5961 const char *name)
5962{
5963 Program *programObject = getProgramResolveLink(program);
5964 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5965 return programObject->getFragDataIndex(name);
5966}
5967
Jamie Madillc1d770e2017-04-13 17:31:24 -04005968void Context::shaderSource(GLuint shader,
5969 GLsizei count,
5970 const GLchar *const *string,
5971 const GLint *length)
5972{
5973 Shader *shaderObject = getShader(shader);
5974 ASSERT(shaderObject);
5975 shaderObject->setSource(count, string, length);
5976}
5977
5978void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5979{
5980 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5981}
5982
5983void Context::stencilMask(GLuint mask)
5984{
5985 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5986}
5987
5988void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5989{
5990 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5991}
5992
5993void Context::uniform1f(GLint location, GLfloat x)
5994{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005995 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005996 program->setUniform1fv(location, 1, &x);
5997}
5998
5999void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6000{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006001 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006002 program->setUniform1fv(location, count, v);
6003}
6004
Jamie Madill7e4eff12018-08-08 15:49:26 -04006005void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006006{
Jamie Madille3e680c2018-12-03 17:49:08 -05006007 program->setUniform1iv(this, location, count, v);
6008}
6009
6010void Context::onSamplerUniformChange(size_t textureUnitIndex)
6011{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006012 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05006013 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006014}
6015
Jamie Madill7e4eff12018-08-08 15:49:26 -04006016void Context::uniform1i(GLint location, GLint x)
6017{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006018 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006019}
6020
Jamie Madillc1d770e2017-04-13 17:31:24 -04006021void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6022{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006023 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006024}
6025
6026void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6027{
6028 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006029 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006030 program->setUniform2fv(location, 1, xy);
6031}
6032
6033void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6034{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006035 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006036 program->setUniform2fv(location, count, v);
6037}
6038
6039void Context::uniform2i(GLint location, GLint x, GLint y)
6040{
6041 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006042 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043 program->setUniform2iv(location, 1, xy);
6044}
6045
6046void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6047{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006048 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006049 program->setUniform2iv(location, count, v);
6050}
6051
6052void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6053{
6054 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006055 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006056 program->setUniform3fv(location, 1, xyz);
6057}
6058
6059void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6060{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006061 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006062 program->setUniform3fv(location, count, v);
6063}
6064
6065void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6066{
6067 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006068 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006069 program->setUniform3iv(location, 1, xyz);
6070}
6071
6072void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6073{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006074 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006075 program->setUniform3iv(location, count, v);
6076}
6077
6078void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6079{
6080 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006081 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006082 program->setUniform4fv(location, 1, xyzw);
6083}
6084
6085void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6086{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006087 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006088 program->setUniform4fv(location, count, v);
6089}
6090
6091void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6092{
6093 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006094 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006095 program->setUniform4iv(location, 1, xyzw);
6096}
6097
6098void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6099{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006100 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006101 program->setUniform4iv(location, count, v);
6102}
6103
6104void Context::uniformMatrix2fv(GLint location,
6105 GLsizei count,
6106 GLboolean transpose,
6107 const GLfloat *value)
6108{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006109 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006110 program->setUniformMatrix2fv(location, count, transpose, value);
6111}
6112
6113void Context::uniformMatrix3fv(GLint location,
6114 GLsizei count,
6115 GLboolean transpose,
6116 const GLfloat *value)
6117{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006118 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006119 program->setUniformMatrix3fv(location, count, transpose, value);
6120}
6121
6122void Context::uniformMatrix4fv(GLint location,
6123 GLsizei count,
6124 GLboolean transpose,
6125 const GLfloat *value)
6126{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006127 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006128 program->setUniformMatrix4fv(location, count, transpose, value);
6129}
6130
6131void Context::validateProgram(GLuint program)
6132{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006133 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006134 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006135 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006136}
6137
Jiajia Qin5451d532017-11-16 17:16:34 +08006138void Context::validateProgramPipeline(GLuint pipeline)
6139{
6140 UNIMPLEMENTED();
6141}
6142
Jamie Madilld04908b2017-06-09 14:15:35 -04006143void Context::getProgramBinary(GLuint program,
6144 GLsizei bufSize,
6145 GLsizei *length,
6146 GLenum *binaryFormat,
6147 void *binary)
6148{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006149 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006150 ASSERT(programObject != nullptr);
6151
Jamie Madill4f6592f2018-11-27 16:37:45 -05006152 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006153}
6154
6155void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6156{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006157 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006158 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006159
Jamie Madill4f6592f2018-11-27 16:37:45 -05006160 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006161 if (programObject->isInUse())
6162 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006163 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006164 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006165 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006166}
6167
Jamie Madillff325f12017-08-26 15:06:05 -04006168void Context::uniform1ui(GLint location, GLuint v0)
6169{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006170 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006171 program->setUniform1uiv(location, 1, &v0);
6172}
6173
6174void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6175{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006176 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006177 const GLuint xy[] = {v0, v1};
6178 program->setUniform2uiv(location, 1, xy);
6179}
6180
6181void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6182{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006183 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006184 const GLuint xyz[] = {v0, v1, v2};
6185 program->setUniform3uiv(location, 1, xyz);
6186}
6187
6188void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6189{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006190 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006191 const GLuint xyzw[] = {v0, v1, v2, v3};
6192 program->setUniform4uiv(location, 1, xyzw);
6193}
6194
6195void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6196{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006197 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006198 program->setUniform1uiv(location, count, value);
6199}
6200void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6201{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006202 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006203 program->setUniform2uiv(location, count, value);
6204}
6205
6206void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6207{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006208 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006209 program->setUniform3uiv(location, count, value);
6210}
6211
6212void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6213{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006214 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006215 program->setUniform4uiv(location, count, value);
6216}
6217
Jamie Madillf0e04492017-08-26 15:28:42 -04006218void Context::genQueries(GLsizei n, GLuint *ids)
6219{
6220 for (GLsizei i = 0; i < n; i++)
6221 {
6222 GLuint handle = mQueryHandleAllocator.allocate();
6223 mQueryMap.assign(handle, nullptr);
6224 ids[i] = handle;
6225 }
6226}
6227
6228void Context::deleteQueries(GLsizei n, const GLuint *ids)
6229{
6230 for (int i = 0; i < n; i++)
6231 {
6232 GLuint query = ids[i];
6233
6234 Query *queryObject = nullptr;
6235 if (mQueryMap.erase(query, &queryObject))
6236 {
6237 mQueryHandleAllocator.release(query);
6238 if (queryObject)
6239 {
6240 queryObject->release(this);
6241 }
6242 }
6243 }
6244}
6245
6246GLboolean Context::isQuery(GLuint id)
6247{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006248 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006249}
6250
Jamie Madillc8c95812017-08-26 18:40:09 -04006251void Context::uniformMatrix2x3fv(GLint location,
6252 GLsizei count,
6253 GLboolean transpose,
6254 const GLfloat *value)
6255{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006256 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006257 program->setUniformMatrix2x3fv(location, count, transpose, value);
6258}
6259
6260void Context::uniformMatrix3x2fv(GLint location,
6261 GLsizei count,
6262 GLboolean transpose,
6263 const GLfloat *value)
6264{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006265 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006266 program->setUniformMatrix3x2fv(location, count, transpose, value);
6267}
6268
6269void Context::uniformMatrix2x4fv(GLint location,
6270 GLsizei count,
6271 GLboolean transpose,
6272 const GLfloat *value)
6273{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006274 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006275 program->setUniformMatrix2x4fv(location, count, transpose, value);
6276}
6277
6278void Context::uniformMatrix4x2fv(GLint location,
6279 GLsizei count,
6280 GLboolean transpose,
6281 const GLfloat *value)
6282{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006283 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006284 program->setUniformMatrix4x2fv(location, count, transpose, value);
6285}
6286
6287void Context::uniformMatrix3x4fv(GLint location,
6288 GLsizei count,
6289 GLboolean transpose,
6290 const GLfloat *value)
6291{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006292 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006293 program->setUniformMatrix3x4fv(location, count, transpose, value);
6294}
6295
6296void Context::uniformMatrix4x3fv(GLint location,
6297 GLsizei count,
6298 GLboolean transpose,
6299 const GLfloat *value)
6300{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006301 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006302 program->setUniformMatrix4x3fv(location, count, transpose, value);
6303}
6304
Jamie Madilld7576732017-08-26 18:49:50 -04006305void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6306{
6307 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6308 {
6309 GLuint vertexArray = arrays[arrayIndex];
6310
6311 if (arrays[arrayIndex] != 0)
6312 {
6313 VertexArray *vertexArrayObject = nullptr;
6314 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6315 {
6316 if (vertexArrayObject != nullptr)
6317 {
6318 detachVertexArray(vertexArray);
6319 vertexArrayObject->onDestroy(this);
6320 }
6321
6322 mVertexArrayHandleAllocator.release(vertexArray);
6323 }
6324 }
6325 }
6326}
6327
6328void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6329{
6330 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6331 {
6332 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6333 mVertexArrayMap.assign(vertexArray, nullptr);
6334 arrays[arrayIndex] = vertexArray;
6335 }
6336}
6337
6338bool Context::isVertexArray(GLuint array)
6339{
6340 if (array == 0)
6341 {
6342 return GL_FALSE;
6343 }
6344
6345 VertexArray *vao = getVertexArray(array);
6346 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6347}
6348
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006349void Context::endTransformFeedback()
6350{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006351 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006352 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006353 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006354}
6355
6356void Context::transformFeedbackVaryings(GLuint program,
6357 GLsizei count,
6358 const GLchar *const *varyings,
6359 GLenum bufferMode)
6360{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006361 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006362 ASSERT(programObject);
6363 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6364}
6365
6366void Context::getTransformFeedbackVarying(GLuint program,
6367 GLuint index,
6368 GLsizei bufSize,
6369 GLsizei *length,
6370 GLsizei *size,
6371 GLenum *type,
6372 GLchar *name)
6373{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006374 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006375 ASSERT(programObject);
6376 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6377}
6378
6379void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6380{
6381 for (int i = 0; i < n; i++)
6382 {
6383 GLuint transformFeedback = ids[i];
6384 if (transformFeedback == 0)
6385 {
6386 continue;
6387 }
6388
6389 TransformFeedback *transformFeedbackObject = nullptr;
6390 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6391 {
6392 if (transformFeedbackObject != nullptr)
6393 {
6394 detachTransformFeedback(transformFeedback);
6395 transformFeedbackObject->release(this);
6396 }
6397
6398 mTransformFeedbackHandleAllocator.release(transformFeedback);
6399 }
6400 }
6401}
6402
6403void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6404{
6405 for (int i = 0; i < n; i++)
6406 {
6407 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6408 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6409 ids[i] = transformFeedback;
6410 }
6411}
6412
6413bool Context::isTransformFeedback(GLuint id)
6414{
6415 if (id == 0)
6416 {
6417 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6418 // returns FALSE
6419 return GL_FALSE;
6420 }
6421
6422 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6423 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6424}
6425
6426void Context::pauseTransformFeedback()
6427{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006428 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006429 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006430 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006431}
6432
6433void Context::resumeTransformFeedback()
6434{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006435 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006436 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006437 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006438}
6439
Jamie Madill12e957f2017-08-26 21:42:26 -04006440void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6441{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006442 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006443 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006444}
6445
Brandon Jones59770802018-04-02 13:18:42 -07006446void Context::getUniformuivRobust(GLuint program,
6447 GLint location,
6448 GLsizei bufSize,
6449 GLsizei *length,
6450 GLuint *params)
6451{
6452 getUniformuiv(program, location, params);
6453}
6454
Jamie Madill12e957f2017-08-26 21:42:26 -04006455GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6456{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006457 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006458 return programObject->getFragDataLocation(name);
6459}
6460
6461void Context::getUniformIndices(GLuint program,
6462 GLsizei uniformCount,
6463 const GLchar *const *uniformNames,
6464 GLuint *uniformIndices)
6465{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006466 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006467 if (!programObject->isLinked())
6468 {
6469 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6470 {
6471 uniformIndices[uniformId] = GL_INVALID_INDEX;
6472 }
6473 }
6474 else
6475 {
6476 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6477 {
6478 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6479 }
6480 }
6481}
6482
6483void Context::getActiveUniformsiv(GLuint program,
6484 GLsizei uniformCount,
6485 const GLuint *uniformIndices,
6486 GLenum pname,
6487 GLint *params)
6488{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006489 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006490 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6491 {
6492 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006493 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006494 }
6495}
6496
6497GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6498{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006499 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006500 return programObject->getUniformBlockIndex(uniformBlockName);
6501}
6502
6503void Context::getActiveUniformBlockiv(GLuint program,
6504 GLuint uniformBlockIndex,
6505 GLenum pname,
6506 GLint *params)
6507{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006508 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006509 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6510}
6511
Brandon Jones59770802018-04-02 13:18:42 -07006512void Context::getActiveUniformBlockivRobust(GLuint program,
6513 GLuint uniformBlockIndex,
6514 GLenum pname,
6515 GLsizei bufSize,
6516 GLsizei *length,
6517 GLint *params)
6518{
6519 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6520}
6521
Jamie Madill12e957f2017-08-26 21:42:26 -04006522void Context::getActiveUniformBlockName(GLuint program,
6523 GLuint uniformBlockIndex,
6524 GLsizei bufSize,
6525 GLsizei *length,
6526 GLchar *uniformBlockName)
6527{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006528 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006529 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6530}
6531
6532void Context::uniformBlockBinding(GLuint program,
6533 GLuint uniformBlockIndex,
6534 GLuint uniformBlockBinding)
6535{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006536 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006537 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006538
Jamie Madill956ab4d2018-10-10 16:13:03 -04006539 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006540 if (programObject->isInUse())
6541 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006542 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006543 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006544 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006545}
6546
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006547GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6548{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006549 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006550 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006551
Jamie Madill70b5bb02017-08-28 13:32:37 -04006552 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006553 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006554 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006555 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006556 return nullptr;
6557 }
6558
Jamie Madill70b5bb02017-08-28 13:32:37 -04006559 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006560}
6561
6562GLboolean Context::isSync(GLsync sync)
6563{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006564 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006565}
6566
6567GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6568{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006569 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006570
6571 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006572 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006573 {
6574 return GL_WAIT_FAILED;
6575 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006576 return result;
6577}
6578
6579void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6580{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006581 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006582 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006583}
6584
6585void Context::getInteger64v(GLenum pname, GLint64 *params)
6586{
6587 GLenum nativeType = GL_NONE;
6588 unsigned int numParams = 0;
6589 getQueryParameterInfo(pname, &nativeType, &numParams);
6590
6591 if (nativeType == GL_INT_64_ANGLEX)
6592 {
6593 getInteger64vImpl(pname, params);
6594 }
6595 else
6596 {
6597 CastStateValues(this, nativeType, pname, numParams, params);
6598 }
6599}
6600
Brandon Jones59770802018-04-02 13:18:42 -07006601void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6602{
6603 getInteger64v(pname, data);
6604}
6605
Corentin Wallez336129f2017-10-17 15:55:40 -04006606void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006607{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006608 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006609 QueryBufferParameteri64v(buffer, pname, params);
6610}
6611
Brandon Jones59770802018-04-02 13:18:42 -07006612void Context::getBufferParameteri64vRobust(BufferBinding target,
6613 GLenum pname,
6614 GLsizei bufSize,
6615 GLsizei *length,
6616 GLint64 *params)
6617{
6618 getBufferParameteri64v(target, pname, params);
6619}
6620
Jamie Madill3ef140a2017-08-26 23:11:21 -04006621void Context::genSamplers(GLsizei count, GLuint *samplers)
6622{
6623 for (int i = 0; i < count; i++)
6624 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006625 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006626 }
6627}
6628
6629void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6630{
6631 for (int i = 0; i < count; i++)
6632 {
6633 GLuint sampler = samplers[i];
6634
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006635 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006636 {
6637 detachSampler(sampler);
6638 }
6639
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006640 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006641 }
6642}
6643
6644void Context::getInternalformativ(GLenum target,
6645 GLenum internalformat,
6646 GLenum pname,
6647 GLsizei bufSize,
6648 GLint *params)
6649{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006650 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006651 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6652}
6653
Brandon Jones59770802018-04-02 13:18:42 -07006654void Context::getInternalformativRobust(GLenum target,
6655 GLenum internalformat,
6656 GLenum pname,
6657 GLsizei bufSize,
6658 GLsizei *length,
6659 GLint *params)
6660{
6661 getInternalformativ(target, internalformat, pname, bufSize, params);
6662}
6663
Jiajia Qin5451d532017-11-16 17:16:34 +08006664void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6665{
6666 programUniform1iv(program, location, 1, &v0);
6667}
6668
6669void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6670{
6671 GLint xy[2] = {v0, v1};
6672 programUniform2iv(program, location, 1, xy);
6673}
6674
6675void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6676{
6677 GLint xyz[3] = {v0, v1, v2};
6678 programUniform3iv(program, location, 1, xyz);
6679}
6680
6681void Context::programUniform4i(GLuint program,
6682 GLint location,
6683 GLint v0,
6684 GLint v1,
6685 GLint v2,
6686 GLint v3)
6687{
6688 GLint xyzw[4] = {v0, v1, v2, v3};
6689 programUniform4iv(program, location, 1, xyzw);
6690}
6691
6692void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6693{
6694 programUniform1uiv(program, location, 1, &v0);
6695}
6696
6697void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6698{
6699 GLuint xy[2] = {v0, v1};
6700 programUniform2uiv(program, location, 1, xy);
6701}
6702
6703void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6704{
6705 GLuint xyz[3] = {v0, v1, v2};
6706 programUniform3uiv(program, location, 1, xyz);
6707}
6708
6709void Context::programUniform4ui(GLuint program,
6710 GLint location,
6711 GLuint v0,
6712 GLuint v1,
6713 GLuint v2,
6714 GLuint v3)
6715{
6716 GLuint xyzw[4] = {v0, v1, v2, v3};
6717 programUniform4uiv(program, location, 1, xyzw);
6718}
6719
6720void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6721{
6722 programUniform1fv(program, location, 1, &v0);
6723}
6724
6725void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6726{
6727 GLfloat xy[2] = {v0, v1};
6728 programUniform2fv(program, location, 1, xy);
6729}
6730
6731void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6732{
6733 GLfloat xyz[3] = {v0, v1, v2};
6734 programUniform3fv(program, location, 1, xyz);
6735}
6736
6737void Context::programUniform4f(GLuint program,
6738 GLint location,
6739 GLfloat v0,
6740 GLfloat v1,
6741 GLfloat v2,
6742 GLfloat v3)
6743{
6744 GLfloat xyzw[4] = {v0, v1, v2, v3};
6745 programUniform4fv(program, location, 1, xyzw);
6746}
6747
Jamie Madill81c2e252017-09-09 23:32:46 -04006748void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6749{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006750 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006751 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006752 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006753}
6754
Jiajia Qin5451d532017-11-16 17:16:34 +08006755void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6756{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006757 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006758 ASSERT(programObject);
6759 programObject->setUniform2iv(location, count, value);
6760}
6761
6762void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6763{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006764 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006765 ASSERT(programObject);
6766 programObject->setUniform3iv(location, count, value);
6767}
6768
6769void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6770{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006771 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006772 ASSERT(programObject);
6773 programObject->setUniform4iv(location, count, value);
6774}
6775
6776void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6777{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006778 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006779 ASSERT(programObject);
6780 programObject->setUniform1uiv(location, count, value);
6781}
6782
6783void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6784{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006785 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006786 ASSERT(programObject);
6787 programObject->setUniform2uiv(location, count, value);
6788}
6789
6790void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6791{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006792 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006793 ASSERT(programObject);
6794 programObject->setUniform3uiv(location, count, value);
6795}
6796
6797void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6798{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006799 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006800 ASSERT(programObject);
6801 programObject->setUniform4uiv(location, count, value);
6802}
6803
6804void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6805{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006806 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006807 ASSERT(programObject);
6808 programObject->setUniform1fv(location, count, value);
6809}
6810
6811void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6812{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006813 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006814 ASSERT(programObject);
6815 programObject->setUniform2fv(location, count, value);
6816}
6817
6818void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6819{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006820 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006821 ASSERT(programObject);
6822 programObject->setUniform3fv(location, count, value);
6823}
6824
6825void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6826{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006827 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006828 ASSERT(programObject);
6829 programObject->setUniform4fv(location, count, value);
6830}
6831
6832void Context::programUniformMatrix2fv(GLuint program,
6833 GLint location,
6834 GLsizei count,
6835 GLboolean transpose,
6836 const GLfloat *value)
6837{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006838 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006839 ASSERT(programObject);
6840 programObject->setUniformMatrix2fv(location, count, transpose, value);
6841}
6842
6843void Context::programUniformMatrix3fv(GLuint program,
6844 GLint location,
6845 GLsizei count,
6846 GLboolean transpose,
6847 const GLfloat *value)
6848{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006849 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006850 ASSERT(programObject);
6851 programObject->setUniformMatrix3fv(location, count, transpose, value);
6852}
6853
6854void Context::programUniformMatrix4fv(GLuint program,
6855 GLint location,
6856 GLsizei count,
6857 GLboolean transpose,
6858 const GLfloat *value)
6859{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006860 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006861 ASSERT(programObject);
6862 programObject->setUniformMatrix4fv(location, count, transpose, value);
6863}
6864
6865void Context::programUniformMatrix2x3fv(GLuint program,
6866 GLint location,
6867 GLsizei count,
6868 GLboolean transpose,
6869 const GLfloat *value)
6870{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006871 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006872 ASSERT(programObject);
6873 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6874}
6875
6876void Context::programUniformMatrix3x2fv(GLuint program,
6877 GLint location,
6878 GLsizei count,
6879 GLboolean transpose,
6880 const GLfloat *value)
6881{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006882 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006883 ASSERT(programObject);
6884 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6885}
6886
6887void Context::programUniformMatrix2x4fv(GLuint program,
6888 GLint location,
6889 GLsizei count,
6890 GLboolean transpose,
6891 const GLfloat *value)
6892{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006893 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006894 ASSERT(programObject);
6895 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6896}
6897
6898void Context::programUniformMatrix4x2fv(GLuint program,
6899 GLint location,
6900 GLsizei count,
6901 GLboolean transpose,
6902 const GLfloat *value)
6903{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006904 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006905 ASSERT(programObject);
6906 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6907}
6908
6909void Context::programUniformMatrix3x4fv(GLuint program,
6910 GLint location,
6911 GLsizei count,
6912 GLboolean transpose,
6913 const GLfloat *value)
6914{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006915 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006916 ASSERT(programObject);
6917 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6918}
6919
6920void Context::programUniformMatrix4x3fv(GLuint program,
6921 GLint location,
6922 GLsizei count,
6923 GLboolean transpose,
6924 const GLfloat *value)
6925{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006926 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006927 ASSERT(programObject);
6928 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6929}
6930
James Darpiniane8a93c62018-01-04 18:02:24 -08006931bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6932{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006933 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006934}
James Darpiniane8a93c62018-01-04 18:02:24 -08006935
Yunchao Hea336b902017-08-02 16:05:21 +08006936void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6937{
6938 for (int i = 0; i < count; i++)
6939 {
6940 pipelines[i] = createProgramPipeline();
6941 }
6942}
6943
6944void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6945{
6946 for (int i = 0; i < count; i++)
6947 {
6948 if (pipelines[i] != 0)
6949 {
6950 deleteProgramPipeline(pipelines[i]);
6951 }
6952 }
6953}
6954
6955GLboolean Context::isProgramPipeline(GLuint pipeline)
6956{
6957 if (pipeline == 0)
6958 {
6959 return GL_FALSE;
6960 }
6961
6962 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6963}
6964
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006965void Context::finishFenceNV(GLuint fence)
6966{
6967 FenceNV *fenceObject = getFenceNV(fence);
6968
6969 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006970 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006971}
6972
6973void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6974{
6975 FenceNV *fenceObject = getFenceNV(fence);
6976
6977 ASSERT(fenceObject && fenceObject->isSet());
6978
6979 switch (pname)
6980 {
6981 case GL_FENCE_STATUS_NV:
6982 {
6983 // GL_NV_fence spec:
6984 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6985 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6986 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6987 GLboolean status = GL_TRUE;
6988 if (fenceObject->getStatus() != GL_TRUE)
6989 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006990 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006991 }
6992 *params = status;
6993 break;
6994 }
6995
6996 case GL_FENCE_CONDITION_NV:
6997 {
6998 *params = static_cast<GLint>(fenceObject->getCondition());
6999 break;
7000 }
7001
7002 default:
7003 UNREACHABLE();
7004 }
7005}
7006
7007void Context::getTranslatedShaderSource(GLuint shader,
7008 GLsizei bufsize,
7009 GLsizei *length,
7010 GLchar *source)
7011{
7012 Shader *shaderObject = getShader(shader);
7013 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007014 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007015}
7016
7017void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7018{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007019 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007020 ASSERT(programObject);
7021
7022 programObject->getUniformfv(this, location, params);
7023}
7024
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007025void Context::getnUniformfvRobust(GLuint program,
7026 GLint location,
7027 GLsizei bufSize,
7028 GLsizei *length,
7029 GLfloat *params)
7030{
7031 UNIMPLEMENTED();
7032}
7033
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007034void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7035{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007036 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007037 ASSERT(programObject);
7038
7039 programObject->getUniformiv(this, location, params);
7040}
7041
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007042void Context::getnUniformivRobust(GLuint program,
7043 GLint location,
7044 GLsizei bufSize,
7045 GLsizei *length,
7046 GLint *params)
7047{
7048 UNIMPLEMENTED();
7049}
7050
7051void Context::getnUniformuivRobust(GLuint program,
7052 GLint location,
7053 GLsizei bufSize,
7054 GLsizei *length,
7055 GLuint *params)
7056{
7057 UNIMPLEMENTED();
7058}
7059
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007060GLboolean Context::isFenceNV(GLuint fence)
7061{
7062 FenceNV *fenceObject = getFenceNV(fence);
7063
7064 if (fenceObject == nullptr)
7065 {
7066 return GL_FALSE;
7067 }
7068
7069 // GL_NV_fence spec:
7070 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7071 // existing fence.
7072 return fenceObject->isSet();
7073}
7074
7075void Context::readnPixels(GLint x,
7076 GLint y,
7077 GLsizei width,
7078 GLsizei height,
7079 GLenum format,
7080 GLenum type,
7081 GLsizei bufSize,
7082 void *data)
7083{
7084 return readPixels(x, y, width, height, format, type, data);
7085}
7086
Jamie Madill007530e2017-12-28 14:27:04 -05007087void Context::setFenceNV(GLuint fence, GLenum condition)
7088{
7089 ASSERT(condition == GL_ALL_COMPLETED_NV);
7090
7091 FenceNV *fenceObject = getFenceNV(fence);
7092 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007093 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007094}
7095
7096GLboolean Context::testFenceNV(GLuint fence)
7097{
7098 FenceNV *fenceObject = getFenceNV(fence);
7099
7100 ASSERT(fenceObject != nullptr);
7101 ASSERT(fenceObject->isSet() == GL_TRUE);
7102
7103 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007104 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007105 {
Jamie Madill007530e2017-12-28 14:27:04 -05007106 return GL_TRUE;
7107 }
7108
7109 return result;
7110}
7111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007112void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007113{
7114 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007115 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007116 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007117}
7118
Jamie Madillfa920eb2018-01-04 11:45:50 -05007119void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007120{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007121 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007122 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007123 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007124}
7125
Jamie Madillfa920eb2018-01-04 11:45:50 -05007126void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7127{
7128 UNIMPLEMENTED();
7129}
7130
Jamie Madill5b772312018-03-08 20:28:32 -05007131bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7132{
7133 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7134 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7135 // to the fact that it is stored internally as a float, and so would require conversion
7136 // if returned from Context::getIntegerv. Since this conversion is already implemented
7137 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7138 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7139 // application.
7140 switch (pname)
7141 {
7142 case GL_COMPRESSED_TEXTURE_FORMATS:
7143 {
7144 *type = GL_INT;
7145 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7146 return true;
7147 }
7148 case GL_SHADER_BINARY_FORMATS:
7149 {
7150 *type = GL_INT;
7151 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7152 return true;
7153 }
7154
7155 case GL_MAX_VERTEX_ATTRIBS:
7156 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7157 case GL_MAX_VARYING_VECTORS:
7158 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7159 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7160 case GL_MAX_TEXTURE_IMAGE_UNITS:
7161 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7162 case GL_MAX_RENDERBUFFER_SIZE:
7163 case GL_NUM_SHADER_BINARY_FORMATS:
7164 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7165 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007166 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7167 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007168 case GL_RENDERBUFFER_BINDING:
7169 case GL_CURRENT_PROGRAM:
7170 case GL_PACK_ALIGNMENT:
7171 case GL_UNPACK_ALIGNMENT:
7172 case GL_GENERATE_MIPMAP_HINT:
7173 case GL_RED_BITS:
7174 case GL_GREEN_BITS:
7175 case GL_BLUE_BITS:
7176 case GL_ALPHA_BITS:
7177 case GL_DEPTH_BITS:
7178 case GL_STENCIL_BITS:
7179 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7180 case GL_CULL_FACE_MODE:
7181 case GL_FRONT_FACE:
7182 case GL_ACTIVE_TEXTURE:
7183 case GL_STENCIL_FUNC:
7184 case GL_STENCIL_VALUE_MASK:
7185 case GL_STENCIL_REF:
7186 case GL_STENCIL_FAIL:
7187 case GL_STENCIL_PASS_DEPTH_FAIL:
7188 case GL_STENCIL_PASS_DEPTH_PASS:
7189 case GL_STENCIL_BACK_FUNC:
7190 case GL_STENCIL_BACK_VALUE_MASK:
7191 case GL_STENCIL_BACK_REF:
7192 case GL_STENCIL_BACK_FAIL:
7193 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7194 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7195 case GL_DEPTH_FUNC:
7196 case GL_BLEND_SRC_RGB:
7197 case GL_BLEND_SRC_ALPHA:
7198 case GL_BLEND_DST_RGB:
7199 case GL_BLEND_DST_ALPHA:
7200 case GL_BLEND_EQUATION_RGB:
7201 case GL_BLEND_EQUATION_ALPHA:
7202 case GL_STENCIL_WRITEMASK:
7203 case GL_STENCIL_BACK_WRITEMASK:
7204 case GL_STENCIL_CLEAR_VALUE:
7205 case GL_SUBPIXEL_BITS:
7206 case GL_MAX_TEXTURE_SIZE:
7207 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7208 case GL_SAMPLE_BUFFERS:
7209 case GL_SAMPLES:
7210 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7211 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7212 case GL_TEXTURE_BINDING_2D:
7213 case GL_TEXTURE_BINDING_CUBE_MAP:
7214 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7215 {
7216 *type = GL_INT;
7217 *numParams = 1;
7218 return true;
7219 }
7220 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7221 {
7222 if (!getExtensions().packReverseRowOrder)
7223 {
7224 return false;
7225 }
7226 *type = GL_INT;
7227 *numParams = 1;
7228 return true;
7229 }
7230 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7231 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7232 {
7233 if (!getExtensions().textureRectangle)
7234 {
7235 return false;
7236 }
7237 *type = GL_INT;
7238 *numParams = 1;
7239 return true;
7240 }
7241 case GL_MAX_DRAW_BUFFERS_EXT:
7242 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7243 {
7244 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7245 {
7246 return false;
7247 }
7248 *type = GL_INT;
7249 *numParams = 1;
7250 return true;
7251 }
7252 case GL_MAX_VIEWPORT_DIMS:
7253 {
7254 *type = GL_INT;
7255 *numParams = 2;
7256 return true;
7257 }
7258 case GL_VIEWPORT:
7259 case GL_SCISSOR_BOX:
7260 {
7261 *type = GL_INT;
7262 *numParams = 4;
7263 return true;
7264 }
7265 case GL_SHADER_COMPILER:
7266 case GL_SAMPLE_COVERAGE_INVERT:
7267 case GL_DEPTH_WRITEMASK:
7268 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7269 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7270 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7271 // bool-natural
7272 case GL_SAMPLE_COVERAGE:
7273 case GL_SCISSOR_TEST:
7274 case GL_STENCIL_TEST:
7275 case GL_DEPTH_TEST:
7276 case GL_BLEND:
7277 case GL_DITHER:
7278 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7279 {
7280 *type = GL_BOOL;
7281 *numParams = 1;
7282 return true;
7283 }
7284 case GL_COLOR_WRITEMASK:
7285 {
7286 *type = GL_BOOL;
7287 *numParams = 4;
7288 return true;
7289 }
7290 case GL_POLYGON_OFFSET_FACTOR:
7291 case GL_POLYGON_OFFSET_UNITS:
7292 case GL_SAMPLE_COVERAGE_VALUE:
7293 case GL_DEPTH_CLEAR_VALUE:
7294 case GL_LINE_WIDTH:
7295 {
7296 *type = GL_FLOAT;
7297 *numParams = 1;
7298 return true;
7299 }
7300 case GL_ALIASED_LINE_WIDTH_RANGE:
7301 case GL_ALIASED_POINT_SIZE_RANGE:
7302 case GL_DEPTH_RANGE:
7303 {
7304 *type = GL_FLOAT;
7305 *numParams = 2;
7306 return true;
7307 }
7308 case GL_COLOR_CLEAR_VALUE:
7309 case GL_BLEND_COLOR:
7310 {
7311 *type = GL_FLOAT;
7312 *numParams = 4;
7313 return true;
7314 }
7315 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7316 if (!getExtensions().textureFilterAnisotropic)
7317 {
7318 return false;
7319 }
7320 *type = GL_FLOAT;
7321 *numParams = 1;
7322 return true;
7323 case GL_TIMESTAMP_EXT:
7324 if (!getExtensions().disjointTimerQuery)
7325 {
7326 return false;
7327 }
7328 *type = GL_INT_64_ANGLEX;
7329 *numParams = 1;
7330 return true;
7331 case GL_GPU_DISJOINT_EXT:
7332 if (!getExtensions().disjointTimerQuery)
7333 {
7334 return false;
7335 }
7336 *type = GL_INT;
7337 *numParams = 1;
7338 return true;
7339 case GL_COVERAGE_MODULATION_CHROMIUM:
7340 if (!getExtensions().framebufferMixedSamples)
7341 {
7342 return false;
7343 }
7344 *type = GL_INT;
7345 *numParams = 1;
7346 return true;
7347 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7348 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7349 {
7350 return false;
7351 }
7352 *type = GL_INT;
7353 *numParams = 1;
7354 return true;
7355 }
7356
7357 if (getExtensions().debug)
7358 {
7359 switch (pname)
7360 {
7361 case GL_DEBUG_LOGGED_MESSAGES:
7362 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7363 case GL_DEBUG_GROUP_STACK_DEPTH:
7364 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7365 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7366 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7367 case GL_MAX_LABEL_LENGTH:
7368 *type = GL_INT;
7369 *numParams = 1;
7370 return true;
7371
7372 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7373 case GL_DEBUG_OUTPUT:
7374 *type = GL_BOOL;
7375 *numParams = 1;
7376 return true;
7377 }
7378 }
7379
7380 if (getExtensions().multisampleCompatibility)
7381 {
7382 switch (pname)
7383 {
7384 case GL_MULTISAMPLE_EXT:
7385 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7386 *type = GL_BOOL;
7387 *numParams = 1;
7388 return true;
7389 }
7390 }
7391
7392 if (getExtensions().pathRendering)
7393 {
7394 switch (pname)
7395 {
7396 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7397 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7398 *type = GL_FLOAT;
7399 *numParams = 16;
7400 return true;
7401 }
7402 }
7403
7404 if (getExtensions().bindGeneratesResource)
7405 {
7406 switch (pname)
7407 {
7408 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7409 *type = GL_BOOL;
7410 *numParams = 1;
7411 return true;
7412 }
7413 }
7414
7415 if (getExtensions().clientArrays)
7416 {
7417 switch (pname)
7418 {
7419 case GL_CLIENT_ARRAYS_ANGLE:
7420 *type = GL_BOOL;
7421 *numParams = 1;
7422 return true;
7423 }
7424 }
7425
7426 if (getExtensions().sRGBWriteControl)
7427 {
7428 switch (pname)
7429 {
7430 case GL_FRAMEBUFFER_SRGB_EXT:
7431 *type = GL_BOOL;
7432 *numParams = 1;
7433 return true;
7434 }
7435 }
7436
7437 if (getExtensions().robustResourceInitialization &&
7438 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7439 {
7440 *type = GL_BOOL;
7441 *numParams = 1;
7442 return true;
7443 }
7444
7445 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7446 {
7447 *type = GL_BOOL;
7448 *numParams = 1;
7449 return true;
7450 }
7451
jchen1082af6202018-06-22 10:59:52 +08007452 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7453 {
7454 *type = GL_INT;
7455 *numParams = 1;
7456 return true;
7457 }
7458
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007459 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7460 {
7461 *type = GL_INT;
7462 *numParams = 1;
7463 return true;
7464 }
7465
Jamie Madill5b772312018-03-08 20:28:32 -05007466 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7467 switch (pname)
7468 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007469 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007470 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7471 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7472 {
7473 return false;
7474 }
7475 *type = GL_INT;
7476 *numParams = 1;
7477 return true;
7478
7479 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7480 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7481 {
7482 return false;
7483 }
7484 *type = GL_INT;
7485 *numParams = 1;
7486 return true;
7487
7488 case GL_PROGRAM_BINARY_FORMATS_OES:
7489 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7490 {
7491 return false;
7492 }
7493 *type = GL_INT;
7494 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7495 return true;
7496
7497 case GL_PACK_ROW_LENGTH:
7498 case GL_PACK_SKIP_ROWS:
7499 case GL_PACK_SKIP_PIXELS:
7500 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7501 {
7502 return false;
7503 }
7504 *type = GL_INT;
7505 *numParams = 1;
7506 return true;
7507 case GL_UNPACK_ROW_LENGTH:
7508 case GL_UNPACK_SKIP_ROWS:
7509 case GL_UNPACK_SKIP_PIXELS:
7510 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7511 {
7512 return false;
7513 }
7514 *type = GL_INT;
7515 *numParams = 1;
7516 return true;
7517 case GL_VERTEX_ARRAY_BINDING:
7518 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7519 {
7520 return false;
7521 }
7522 *type = GL_INT;
7523 *numParams = 1;
7524 return true;
7525 case GL_PIXEL_PACK_BUFFER_BINDING:
7526 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7527 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7528 {
7529 return false;
7530 }
7531 *type = GL_INT;
7532 *numParams = 1;
7533 return true;
7534 case GL_MAX_SAMPLES:
7535 {
7536 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7537 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7538 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7539 {
7540 return false;
7541 }
7542 *type = GL_INT;
7543 *numParams = 1;
7544 return true;
7545
7546 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7547 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7548 {
7549 return false;
7550 }
7551 *type = GL_INT;
7552 *numParams = 1;
7553 return true;
7554 }
7555 }
7556
7557 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7558 {
7559 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7560 {
7561 return false;
7562 }
7563 *type = GL_INT;
7564 *numParams = 1;
7565 return true;
7566 }
7567
7568 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7569 {
7570 *type = GL_INT;
7571 *numParams = 1;
7572 return true;
7573 }
7574
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007575 if (getClientVersion() < Version(2, 0))
7576 {
7577 switch (pname)
7578 {
7579 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007580 case GL_CLIENT_ACTIVE_TEXTURE:
7581 case GL_MATRIX_MODE:
7582 case GL_MAX_TEXTURE_UNITS:
7583 case GL_MAX_MODELVIEW_STACK_DEPTH:
7584 case GL_MAX_PROJECTION_STACK_DEPTH:
7585 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007586 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007587 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007588 case GL_VERTEX_ARRAY_STRIDE:
7589 case GL_NORMAL_ARRAY_STRIDE:
7590 case GL_COLOR_ARRAY_STRIDE:
7591 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7592 case GL_VERTEX_ARRAY_SIZE:
7593 case GL_COLOR_ARRAY_SIZE:
7594 case GL_TEXTURE_COORD_ARRAY_SIZE:
7595 case GL_VERTEX_ARRAY_TYPE:
7596 case GL_NORMAL_ARRAY_TYPE:
7597 case GL_COLOR_ARRAY_TYPE:
7598 case GL_TEXTURE_COORD_ARRAY_TYPE:
7599 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7600 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7601 case GL_COLOR_ARRAY_BUFFER_BINDING:
7602 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7603 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7604 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7605 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007606 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007607 case GL_MODELVIEW_STACK_DEPTH:
7608 case GL_PROJECTION_STACK_DEPTH:
7609 case GL_TEXTURE_STACK_DEPTH:
7610 case GL_LOGIC_OP_MODE:
7611 case GL_BLEND_SRC:
7612 case GL_BLEND_DST:
7613 case GL_PERSPECTIVE_CORRECTION_HINT:
7614 case GL_POINT_SMOOTH_HINT:
7615 case GL_LINE_SMOOTH_HINT:
7616 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007617 *type = GL_INT;
7618 *numParams = 1;
7619 return true;
7620 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007621 case GL_FOG_DENSITY:
7622 case GL_FOG_START:
7623 case GL_FOG_END:
7624 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007625 case GL_POINT_SIZE:
7626 case GL_POINT_SIZE_MIN:
7627 case GL_POINT_SIZE_MAX:
7628 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007629 *type = GL_FLOAT;
7630 *numParams = 1;
7631 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007632 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007633 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007634 *type = GL_FLOAT;
7635 *numParams = 2;
7636 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007637 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007638 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007639 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007640 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007641 *type = GL_FLOAT;
7642 *numParams = 4;
7643 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007644 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007645 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007646 *type = GL_FLOAT;
7647 *numParams = 3;
7648 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007649 case GL_MODELVIEW_MATRIX:
7650 case GL_PROJECTION_MATRIX:
7651 case GL_TEXTURE_MATRIX:
7652 *type = GL_FLOAT;
7653 *numParams = 16;
7654 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007655 case GL_LIGHT_MODEL_TWO_SIDE:
7656 *type = GL_BOOL;
7657 *numParams = 1;
7658 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007659 }
7660 }
7661
Jamie Madill5b772312018-03-08 20:28:32 -05007662 if (getClientVersion() < Version(3, 0))
7663 {
7664 return false;
7665 }
7666
7667 // Check for ES3.0+ parameter names
7668 switch (pname)
7669 {
7670 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7671 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7672 case GL_UNIFORM_BUFFER_BINDING:
7673 case GL_TRANSFORM_FEEDBACK_BINDING:
7674 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7675 case GL_COPY_READ_BUFFER_BINDING:
7676 case GL_COPY_WRITE_BUFFER_BINDING:
7677 case GL_SAMPLER_BINDING:
7678 case GL_READ_BUFFER:
7679 case GL_TEXTURE_BINDING_3D:
7680 case GL_TEXTURE_BINDING_2D_ARRAY:
7681 case GL_MAX_3D_TEXTURE_SIZE:
7682 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7683 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7684 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7685 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7686 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7687 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7688 case GL_MAX_VARYING_COMPONENTS:
7689 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7690 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7691 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7692 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7693 case GL_NUM_EXTENSIONS:
7694 case GL_MAJOR_VERSION:
7695 case GL_MINOR_VERSION:
7696 case GL_MAX_ELEMENTS_INDICES:
7697 case GL_MAX_ELEMENTS_VERTICES:
7698 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7699 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7700 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7701 case GL_UNPACK_IMAGE_HEIGHT:
7702 case GL_UNPACK_SKIP_IMAGES:
7703 {
7704 *type = GL_INT;
7705 *numParams = 1;
7706 return true;
7707 }
7708
7709 case GL_MAX_ELEMENT_INDEX:
7710 case GL_MAX_UNIFORM_BLOCK_SIZE:
7711 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7712 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7713 case GL_MAX_SERVER_WAIT_TIMEOUT:
7714 {
7715 *type = GL_INT_64_ANGLEX;
7716 *numParams = 1;
7717 return true;
7718 }
7719
7720 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7721 case GL_TRANSFORM_FEEDBACK_PAUSED:
7722 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7723 case GL_RASTERIZER_DISCARD:
7724 {
7725 *type = GL_BOOL;
7726 *numParams = 1;
7727 return true;
7728 }
7729
7730 case GL_MAX_TEXTURE_LOD_BIAS:
7731 {
7732 *type = GL_FLOAT;
7733 *numParams = 1;
7734 return true;
7735 }
7736 }
7737
7738 if (getExtensions().requestExtension)
7739 {
7740 switch (pname)
7741 {
7742 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7743 *type = GL_INT;
7744 *numParams = 1;
7745 return true;
7746 }
7747 }
7748
Yizhou Jiang7818a852018-09-06 15:02:04 +08007749 if (getExtensions().textureMultisample)
7750 {
7751 switch (pname)
7752 {
7753 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7754 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7755 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7756 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007757 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007758 *type = GL_INT;
7759 *numParams = 1;
7760 return true;
7761 }
7762 }
7763
Jamie Madill5b772312018-03-08 20:28:32 -05007764 if (getClientVersion() < Version(3, 1))
7765 {
7766 return false;
7767 }
7768
7769 switch (pname)
7770 {
7771 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7772 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7773 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7774 case GL_MAX_FRAMEBUFFER_WIDTH:
7775 case GL_MAX_FRAMEBUFFER_HEIGHT:
7776 case GL_MAX_FRAMEBUFFER_SAMPLES:
7777 case GL_MAX_SAMPLE_MASK_WORDS:
7778 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7779 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7780 case GL_MAX_INTEGER_SAMPLES:
7781 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7782 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7783 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7784 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7785 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7786 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7787 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7788 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7789 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7790 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7791 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7792 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7793 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7794 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7795 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7796 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7797 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7798 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7799 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7800 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7801 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7802 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7803 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7804 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7805 case GL_MAX_UNIFORM_LOCATIONS:
7806 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7807 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7808 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7809 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7810 case GL_MAX_IMAGE_UNITS:
7811 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7812 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7813 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7814 case GL_SHADER_STORAGE_BUFFER_BINDING:
7815 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7816 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007817 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007818 *type = GL_INT;
7819 *numParams = 1;
7820 return true;
7821 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7822 *type = GL_INT_64_ANGLEX;
7823 *numParams = 1;
7824 return true;
7825 case GL_SAMPLE_MASK:
7826 *type = GL_BOOL;
7827 *numParams = 1;
7828 return true;
7829 }
7830
7831 if (getExtensions().geometryShader)
7832 {
7833 switch (pname)
7834 {
7835 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7836 case GL_LAYER_PROVOKING_VERTEX_EXT:
7837 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7838 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7839 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7840 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7841 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7842 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7843 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7844 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7845 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7846 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7847 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7848 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7849 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7850 *type = GL_INT;
7851 *numParams = 1;
7852 return true;
7853 }
7854 }
7855
7856 return false;
7857}
7858
7859bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7860{
7861 if (getClientVersion() < Version(3, 0))
7862 {
7863 return false;
7864 }
7865
7866 switch (target)
7867 {
7868 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7869 case GL_UNIFORM_BUFFER_BINDING:
7870 {
7871 *type = GL_INT;
7872 *numParams = 1;
7873 return true;
7874 }
7875 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7876 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7877 case GL_UNIFORM_BUFFER_START:
7878 case GL_UNIFORM_BUFFER_SIZE:
7879 {
7880 *type = GL_INT_64_ANGLEX;
7881 *numParams = 1;
7882 return true;
7883 }
7884 }
7885
7886 if (getClientVersion() < Version(3, 1))
7887 {
7888 return false;
7889 }
7890
7891 switch (target)
7892 {
7893 case GL_IMAGE_BINDING_LAYERED:
7894 {
7895 *type = GL_BOOL;
7896 *numParams = 1;
7897 return true;
7898 }
7899 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7900 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7901 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7902 case GL_SHADER_STORAGE_BUFFER_BINDING:
7903 case GL_VERTEX_BINDING_BUFFER:
7904 case GL_VERTEX_BINDING_DIVISOR:
7905 case GL_VERTEX_BINDING_OFFSET:
7906 case GL_VERTEX_BINDING_STRIDE:
7907 case GL_SAMPLE_MASK_VALUE:
7908 case GL_IMAGE_BINDING_NAME:
7909 case GL_IMAGE_BINDING_LEVEL:
7910 case GL_IMAGE_BINDING_LAYER:
7911 case GL_IMAGE_BINDING_ACCESS:
7912 case GL_IMAGE_BINDING_FORMAT:
7913 {
7914 *type = GL_INT;
7915 *numParams = 1;
7916 return true;
7917 }
7918 case GL_ATOMIC_COUNTER_BUFFER_START:
7919 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7920 case GL_SHADER_STORAGE_BUFFER_START:
7921 case GL_SHADER_STORAGE_BUFFER_SIZE:
7922 {
7923 *type = GL_INT_64_ANGLEX;
7924 *numParams = 1;
7925 return true;
7926 }
7927 }
7928
7929 return false;
7930}
7931
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007932Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007933{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007934 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007935}
7936
7937Shader *Context::getShader(GLuint handle) const
7938{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007939 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007940}
7941
Jamie Madill5b772312018-03-08 20:28:32 -05007942bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7943{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007944 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007945}
7946
7947bool Context::isFramebufferGenerated(GLuint framebuffer) const
7948{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007949 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007950}
7951
7952bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7953{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007954 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007955}
7956
7957bool Context::usingDisplayTextureShareGroup() const
7958{
7959 return mDisplayTextureShareGroup;
7960}
7961
7962GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7963{
7964 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7965 internalformat == GL_DEPTH_STENCIL
7966 ? GL_DEPTH24_STENCIL8
7967 : internalformat;
7968}
7969
jchen1082af6202018-06-22 10:59:52 +08007970void Context::maxShaderCompilerThreads(GLuint count)
7971{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007972 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7973 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007974 // A count of zero specifies a request for no parallel compiling or linking.
7975 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7976 {
7977 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7978 }
7979 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007980}
7981
Jamie Madill2eb65032018-07-30 10:25:57 -04007982bool Context::isGLES1() const
7983{
7984 return mState.getClientVersion() < Version(2, 0);
7985}
7986
Jamie Madilla11819d2018-07-30 10:26:01 -04007987void Context::onSubjectStateChange(const Context *context,
7988 angle::SubjectIndex index,
7989 angle::SubjectMessage message)
7990{
Jamie Madilla11819d2018-07-30 10:26:01 -04007991 switch (index)
7992 {
7993 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007994 switch (message)
7995 {
7996 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007997 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007998 mStateCache.onVertexArrayBufferContentsChange(this);
7999 break;
8000 case angle::SubjectMessage::RESOURCE_MAPPED:
8001 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8002 case angle::SubjectMessage::BINDING_CHANGED:
8003 mStateCache.onVertexArrayBufferStateChange(this);
8004 break;
8005 default:
8006 break;
8007 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008008 break;
8009
8010 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008011 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8012 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008013 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04008014 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008015 break;
8016
8017 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008018 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8019 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008020 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008021 }
8022 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008023 break;
8024
8025 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008026 if (index < kTextureMaxSubjectIndex)
8027 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008028 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008029 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008030 }
Jamie Madille25b8002018-09-20 13:39:49 -04008031 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008032 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008033 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008034 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008035 }
Jamie Madille25b8002018-09-20 13:39:49 -04008036 else
8037 {
8038 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008039 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008040 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008041 break;
8042 }
8043}
8044
Jamie Madill6b873dd2018-07-12 23:56:30 -04008045// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008046ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008047
8048ErrorSet::~ErrorSet() = default;
8049
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008050void ErrorSet::handleError(GLenum errorCode,
8051 const char *message,
8052 const char *file,
8053 const char *function,
8054 unsigned int line)
8055{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008056 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8057 {
8058 mContext->markContextLost();
8059 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008060
Jamie Madill4f6592f2018-11-27 16:37:45 -05008061 std::stringstream errorStream;
8062 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8063 << line << ". " << message;
8064
Geoff Lang7139b432018-12-14 16:57:28 -05008065 std::string formattedMessage = errorStream.str();
8066
8067 // Always log a warning, this function is only called on unexpected internal errors.
8068 WARN() << formattedMessage;
8069
Jamie Madill4f6592f2018-11-27 16:37:45 -05008070 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008071 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008072}
8073
Jamie Madilla139f012018-10-10 16:13:03 -04008074void ErrorSet::validationError(GLenum errorCode, const char *message)
8075{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008076 ASSERT(errorCode != GL_NO_ERROR);
8077 mErrors.insert(errorCode);
8078
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008079 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8080 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008081}
8082
Jamie Madill6b873dd2018-07-12 23:56:30 -04008083bool ErrorSet::empty() const
8084{
8085 return mErrors.empty();
8086}
8087
8088GLenum ErrorSet::popError()
8089{
8090 ASSERT(!empty());
8091 GLenum error = *mErrors.begin();
8092 mErrors.erase(mErrors.begin());
8093 return error;
8094}
Jamie Madilldc358af2018-07-31 11:22:13 -04008095
8096// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008097StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008098 : mCachedHasAnyEnabledClientAttrib(false),
8099 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008100 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008101 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008102 mCachedBasicDrawElementsError(kInvalidPointer),
8103 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008104{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008105
8106StateCache::~StateCache() = default;
8107
Jamie Madilld51fbe32019-01-25 15:03:39 -05008108ANGLE_INLINE void StateCache::updateVertexElementLimits(Context *context)
8109{
8110 if (context->isBufferAccessValidationEnabled())
8111 {
8112 updateVertexElementLimitsImpl(context);
8113 }
8114}
8115
Jamie Madillac66f982018-10-09 18:30:01 -04008116void StateCache::initialize(Context *context)
8117{
8118 updateValidDrawModes(context);
8119 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008120 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008121 updateBasicDrawStatesError();
8122 updateBasicDrawElementsError();
Jamie Madillc8c7d402019-01-16 13:27:15 -05008123 updateVertexAttribTypesValidation(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008124}
8125
Jamie Madilldc358af2018-07-31 11:22:13 -04008126void StateCache::updateActiveAttribsMask(Context *context)
8127{
8128 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008129 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008130
8131 if (!isGLES1 && !glState.getProgram())
8132 {
8133 mCachedActiveBufferedAttribsMask = AttributesMask();
8134 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008135 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008136 return;
8137 }
8138
8139 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8140 : glState.getProgram()->getActiveAttribLocationsMask();
8141
8142 const VertexArray *vao = glState.getVertexArray();
8143 ASSERT(vao);
8144
8145 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8146 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008147 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008148
Jamie Madill0a17e482018-08-31 17:19:11 -04008149 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8150 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008151 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008152 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8153}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008154
Jamie Madilld51fbe32019-01-25 15:03:39 -05008155void StateCache::updateVertexElementLimitsImpl(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008156{
Jamie Madilld51fbe32019-01-25 15:03:39 -05008157 ASSERT(context->isBufferAccessValidationEnabled());
8158
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008159 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008160
8161 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8162 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8163
8164 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8165 // If there are no buffered attributes then we should not limit the draw call count.
8166 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8167 {
8168 return;
8169 }
8170
8171 const auto &vertexAttribs = vao->getVertexAttributes();
8172 const auto &vertexBindings = vao->getVertexBindings();
8173
8174 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8175 {
8176 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008177
8178 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8179 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008180 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008181
8182 GLint64 limit = attrib.getCachedElementLimit();
8183 if (binding.getDivisor() > 0)
8184 {
8185 mCachedInstancedVertexElementLimit =
8186 std::min(mCachedInstancedVertexElementLimit, limit);
8187 }
8188 else
8189 {
8190 mCachedNonInstancedVertexElementLimit =
8191 std::min(mCachedNonInstancedVertexElementLimit, limit);
8192 }
8193 }
8194}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008195
Jamie Madilld84b6732018-09-06 15:54:35 -04008196void StateCache::updateBasicDrawStatesError()
8197{
8198 mCachedBasicDrawStatesError = kInvalidPointer;
8199}
8200
Jamie Madill1e853262018-12-21 09:07:38 -05008201void StateCache::updateBasicDrawElementsError()
8202{
8203 mCachedBasicDrawElementsError = kInvalidPointer;
8204}
8205
Jamie Madilld84b6732018-09-06 15:54:35 -04008206intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8207{
8208 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8209 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8210 return mCachedBasicDrawStatesError;
8211}
8212
Jamie Madill1e853262018-12-21 09:07:38 -05008213intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8214{
8215 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8216 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8217 return mCachedBasicDrawElementsError;
8218}
8219
Jamie Madillc43cdad2018-08-08 15:49:25 -04008220void StateCache::onVertexArrayBindingChange(Context *context)
8221{
8222 updateActiveAttribsMask(context);
8223 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008224 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008225}
8226
8227void StateCache::onProgramExecutableChange(Context *context)
8228{
8229 updateActiveAttribsMask(context);
8230 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008231 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008232 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008233}
8234
Jamie Madilld84b6732018-09-06 15:54:35 -04008235void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008236{
8237 updateVertexElementLimits(context);
8238}
8239
Jamie Madilld84b6732018-09-06 15:54:35 -04008240void StateCache::onVertexArrayBufferContentsChange(Context *context)
8241{
8242 updateVertexElementLimits(context);
8243 updateBasicDrawStatesError();
8244}
8245
Jamie Madillc43cdad2018-08-08 15:49:25 -04008246void StateCache::onVertexArrayStateChange(Context *context)
8247{
8248 updateActiveAttribsMask(context);
8249 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008250 updateBasicDrawStatesError();
8251}
8252
8253void StateCache::onVertexArrayBufferStateChange(Context *context)
8254{
8255 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008256 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008257}
8258
8259void StateCache::onGLES1ClientStateChange(Context *context)
8260{
8261 updateActiveAttribsMask(context);
8262}
Jamie Madilld84b6732018-09-06 15:54:35 -04008263
8264void StateCache::onDrawFramebufferChange(Context *context)
8265{
8266 updateBasicDrawStatesError();
8267}
8268
8269void StateCache::onContextCapChange(Context *context)
8270{
8271 updateBasicDrawStatesError();
8272}
8273
8274void StateCache::onStencilStateChange(Context *context)
8275{
8276 updateBasicDrawStatesError();
8277}
8278
8279void StateCache::onDefaultVertexAttributeChange(Context *context)
8280{
8281 updateBasicDrawStatesError();
8282}
8283
8284void StateCache::onActiveTextureChange(Context *context)
8285{
8286 updateBasicDrawStatesError();
8287}
8288
8289void StateCache::onQueryChange(Context *context)
8290{
8291 updateBasicDrawStatesError();
8292}
8293
Jamie Madill3a256222018-12-08 09:56:39 -05008294void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008295{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008296 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008297 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008298 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008299 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008300}
8301
8302void StateCache::onUniformBufferStateChange(Context *context)
8303{
8304 updateBasicDrawStatesError();
8305}
8306
Jamie Madill9b025062018-12-12 15:44:12 -05008307void StateCache::setValidDrawModes(bool pointsOK,
8308 bool linesOK,
8309 bool trisOK,
8310 bool lineAdjOK,
8311 bool triAdjOK)
8312{
8313 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8314 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8315 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8316 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8317 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8318 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8319 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8320 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8321 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8322 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8323 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8324}
8325
Jamie Madill526a6f62018-09-12 11:03:05 -04008326void StateCache::updateValidDrawModes(Context *context)
8327{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008328 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008329 Program *program = state.getProgram();
8330
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008331 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008332 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008333 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8334
Jamie Madill9b025062018-12-12 15:44:12 -05008335 // ES Spec 3.0 validation text:
8336 // When transform feedback is active and not paused, all geometric primitives generated must
8337 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8338 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8339 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8340 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8341 // active and not paused, regardless of mode. Any primitive type may be used while transform
8342 // feedback is paused.
8343 if (!context->getExtensions().geometryShader)
8344 {
8345 mCachedValidDrawModes.fill(false);
8346 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8347 return;
8348 }
8349
8350 // EXT_geometry_shader validation text:
8351 // When transform feedback is active and not paused, all geometric primitives generated must
8352 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8353 // geometry shader is active, the type of primitive emitted by that shader is used instead
8354 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8355 // Any primitive type may be used while transform feedback is paused.
8356 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8357 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8358 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8359
8360 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8361 return;
8362 }
8363
Jamie Madill526a6f62018-09-12 11:03:05 -04008364 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8365 {
Jamie Madill752d2202018-11-27 13:29:48 -05008366 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008367 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008368 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008369
Jamie Madill9b025062018-12-12 15:44:12 -05008370 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8371 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008372
Jamie Madill9b025062018-12-12 15:44:12 -05008373 bool pointsOK = gsMode == PrimitiveMode::Points;
8374 bool linesOK = gsMode == PrimitiveMode::Lines;
8375 bool trisOK = gsMode == PrimitiveMode::Triangles;
8376 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8377 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8378
8379 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008380}
Jamie Madillac66f982018-10-09 18:30:01 -04008381
8382void StateCache::updateValidBindTextureTypes(Context *context)
8383{
8384 const Extensions &exts = context->getExtensions();
8385 bool isGLES3 = context->getClientMajorVersion() >= 3;
8386 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8387
8388 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008389 {TextureType::_2D, true},
8390 {TextureType::_2DArray, isGLES3},
8391 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8392 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8393 {TextureType::_3D, isGLES3},
8394 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8395 {TextureType::Rectangle, exts.textureRectangle},
8396 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008397 }};
8398}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008399
8400void StateCache::updateValidDrawElementsTypes(Context *context)
8401{
8402 bool supportsUint =
8403 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8404
8405 mCachedValidDrawElementsTypes = {{
8406 {DrawElementsType::UnsignedByte, true},
8407 {DrawElementsType::UnsignedShort, true},
8408 {DrawElementsType::UnsignedInt, supportsUint},
8409 }};
8410}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008411
8412void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8413{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008414 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008415 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8416}
Jamie Madillc8c7d402019-01-16 13:27:15 -05008417
8418void StateCache::updateVertexAttribTypesValidation(Context *context)
8419{
8420 if (context->getClientMajorVersion() <= 2)
8421 {
8422 mCachedVertexAttribTypesValidation = {{
8423 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8424 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8425 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8426 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8427 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8428 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8429 }};
8430 }
8431 else
8432 {
8433 mCachedVertexAttribTypesValidation = {{
8434 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8435 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8436 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8437 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8438 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8439 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8440 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8441 {VertexAttribType::HalfFloat, VertexAttribTypeCase::Valid},
8442 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8443 {VertexAttribType::Int2101010, VertexAttribTypeCase::ValidSize4Only},
8444 {VertexAttribType::UnsignedInt2101010, VertexAttribTypeCase::ValidSize4Only},
8445 }};
8446
8447 mCachedIntegerVertexAttribTypesValidation = {{
8448 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8449 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8450 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8451 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8452 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8453 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8454 }};
8455 }
8456}
Jamie Madillc29968b2016-01-20 11:17:23 -05008457} // namespace gl