blob: d99c09e08006e30dc34e29e04e6826caad3c9cda [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"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Jamie Madill09463932018-04-04 05:26:59 -0400132void MarkTransformFeedbackBufferUsage(const gl::Context *context,
133 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700134 GLsizei count,
135 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400136{
Geoff Lang1a683462015-09-29 15:09:59 -0400137 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400138 {
Jamie Madill09463932018-04-04 05:26:59 -0400139 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400140 }
141}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500142
143// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300144EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500145{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400146 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147}
148
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
150{
151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
152}
153
Geoff Langeb66a6e2016-10-31 13:06:12 -0400154gl::Version GetClientVersion(const egl::AttributeMap &attribs)
155{
156 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
157}
158
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500159GLenum GetResetStrategy(const egl::AttributeMap &attribs)
160{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800161 EGLAttrib attrib =
162 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500163 switch (attrib)
164 {
165 case EGL_NO_RESET_NOTIFICATION:
166 return GL_NO_RESET_NOTIFICATION_EXT;
167 case EGL_LOSE_CONTEXT_ON_RESET:
168 return GL_LOSE_CONTEXT_ON_RESET_EXT;
169 default:
170 UNREACHABLE();
171 return GL_NONE;
172 }
173}
174
175bool GetRobustAccess(const egl::AttributeMap &attribs)
176{
Geoff Lang077f20a2016-11-01 10:08:02 -0400177 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
178 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
179 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500180}
181
182bool GetDebug(const egl::AttributeMap &attribs)
183{
Geoff Lang077f20a2016-11-01 10:08:02 -0400184 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
185 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetNoError(const egl::AttributeMap &attribs)
189{
190 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
191}
192
Geoff Langc287ea62016-09-16 14:46:51 -0400193bool GetWebGLContext(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400198bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
199{
200 // If the context is WebGL, extensions are disabled by default
201 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
202 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
203}
204
Geoff Langf41a7152016-09-19 15:11:17 -0400205bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
206{
207 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
208}
209
Geoff Langfeb8c682017-02-13 16:07:35 -0500210bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langb433e872017-10-05 14:01:47 -0400215bool GetRobustResourceInit(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
218}
219
Martin Radev9d901792016-07-15 15:58:58 +0300220std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
221{
222 std::string labelName;
223 if (label != nullptr)
224 {
225 size_t labelLength = length < 0 ? strlen(label) : length;
226 labelName = std::string(label, labelLength);
227 }
228 return labelName;
229}
230
231void GetObjectLabelBase(const std::string &objectLabel,
232 GLsizei bufSize,
233 GLsizei *length,
234 GLchar *label)
235{
236 size_t writeLength = objectLabel.length();
237 if (label != nullptr && bufSize > 0)
238 {
239 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
240 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
241 label[writeLength] = '\0';
242 }
243
244 if (length != nullptr)
245 {
246 *length = static_cast<GLsizei>(writeLength);
247 }
248}
249
Jamie Madill0f80ed82017-09-19 00:24:56 -0400250template <typename CapT, typename MaxT>
251void LimitCap(CapT *cap, MaxT maximum)
252{
253 *cap = std::min(*cap, static_cast<CapT>(maximum));
254}
255
Geoff Langf6db0982015-08-25 13:04:00 -0400256} // anonymous namespace
257
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000258namespace gl
259{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000260
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400261Context::Context(rx::EGLImplFactory *implFactory,
262 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400263 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500264 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400265 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500266 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400267 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500268 : mState(reinterpret_cast<ContextID>(this),
269 shareContext ? &shareContext->mState : nullptr,
270 shareTextures,
271 GetClientVersion(attribs),
272 &mGLState,
273 mCaps,
274 mTextureCaps,
275 mExtensions,
276 mLimitations),
277 mSkipValidation(GetNoError(attribs)),
278 mDisplayTextureShareGroup(shareTextures != nullptr),
279 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700280 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400281 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400282 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500283 mClientType(EGL_OPENGL_ES_API),
284 mHasBeenCurrent(false),
285 mContextLost(false),
286 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700287 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500288 mResetStrategy(GetResetStrategy(attribs)),
289 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400290 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
291 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500292 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500293 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400294 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400295 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400296 mScratchBuffer(1000u),
297 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000298{
Jamie Madill5b772312018-03-08 20:28:32 -0500299 // Needed to solve a Clang warning of unused variables.
300 UNUSED_VARIABLE(mSavedArgsType);
301 UNUSED_VARIABLE(mParamsBuffer);
302
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400303 mImplementation->setMemoryProgramCache(memoryProgramCache);
304
Geoff Langb433e872017-10-05 14:01:47 -0400305 bool robustResourceInit = GetRobustResourceInit(attribs);
306 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700307 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400308
Jamie Madill4928b7c2017-06-20 12:57:39 -0400309 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400310 GetClientArraysEnabled(attribs), robustResourceInit,
311 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100312
Shannon Woods53a94a82014-06-24 15:20:36 -0400313 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400316 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // and cube map texture state vectors respectively associated with them.
318 // In order that access to these initial textures not be lost, they are treated as texture
319 // objects all of whose names are 0.
320
Corentin Wallez99d492c2018-02-27 15:17:10 -0500321 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800322 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500323
Corentin Wallez99d492c2018-02-27 15:17:10 -0500324 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800325 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400326
Geoff Langeb66a6e2016-10-31 13:06:12 -0400327 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400328 {
329 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335 }
Geoff Lang3b573612016-10-31 14:08:10 -0400336 if (getClientVersion() >= Version(3, 1))
337 {
338 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800341
Jiajia Qin6eafb042016-12-27 17:04:07 +0800342 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
343 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800344 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800345 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800346
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800347 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
348 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400349 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800350 }
Geoff Lang3b573612016-10-31 14:08:10 -0400351 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352
Geoff Langb0f917f2017-12-05 13:41:54 -0500353 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400354 {
355 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500356 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800357 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400358 }
359
Geoff Langb0f917f2017-12-05 13:41:54 -0500360 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400361 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500362 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800363 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400364 }
365
Jamie Madill4928b7c2017-06-20 12:57:39 -0400366 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500367
Jamie Madill57a89722013-07-02 11:57:03 -0400368 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000369
Geoff Langeb66a6e2016-10-31 13:06:12 -0400370 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400371 {
372 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
373 // In the initial state, a default transform feedback object is bound and treated as
374 // a transform feedback object with a name of zero. That object is bound any time
375 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400376 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400377 }
Geoff Langc8058452014-02-03 12:04:11 -0500378
Corentin Wallez336129f2017-10-17 15:55:40 -0400379 for (auto type : angle::AllEnums<BufferBinding>())
380 {
381 bindBuffer(type, 0);
382 }
383
384 bindRenderbuffer(GL_RENDERBUFFER, 0);
385
386 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
387 {
388 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
389 }
390
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500394 // No dirty objects.
395
396 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
400
401 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
404 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
408 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
412 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
413
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700416 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400419
Xinghua Cao10a4d432017-11-28 14:46:26 +0800420 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
421 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
422 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
423 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
424 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
425 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800426 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800427 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800428
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400429 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430}
431
Jamie Madill4928b7c2017-06-20 12:57:39 -0400432egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433{
Jamie Madille7b3fe22018-04-05 09:42:46 -0400434 // Delete the Surface first to trigger a finish() in Vulkan.
435 SafeDelete(mSurfacelessFramebuffer);
436
437 ANGLE_TRY(releaseSurface(display));
438
Corentin Wallez80b24112015-08-25 16:41:57 -0400439 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000442 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400443 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444
Corentin Wallez80b24112015-08-25 16:41:57 -0400445 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400447 if (query.second != nullptr)
448 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400449 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400450 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000451 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400452 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000453
Corentin Wallez80b24112015-08-25 16:41:57 -0400454 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400455 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400456 if (vertexArray.second)
457 {
458 vertexArray.second->onDestroy(this);
459 }
Jamie Madill57a89722013-07-02 11:57:03 -0400460 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400461 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400462
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500464 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500465 if (transformFeedback.second != nullptr)
466 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500467 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500468 }
Geoff Langc8058452014-02-03 12:04:11 -0500469 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400470 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500471
Jamie Madill5b772312018-03-08 20:28:32 -0500472 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400473 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800474 if (zeroTexture.get() != nullptr)
475 {
476 ANGLE_TRY(zeroTexture->onDestroy(this));
477 zeroTexture.set(this, nullptr);
478 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400479 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000480
Jamie Madill2f348d22017-06-05 10:50:59 -0400481 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500482
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483 mGLState.reset(this);
484
Jamie Madill6c1f6712017-02-14 19:08:04 -0500485 mState.mBuffers->release(this);
486 mState.mShaderPrograms->release(this);
487 mState.mTextures->release(this);
488 mState.mRenderbuffers->release(this);
489 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400490 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500491 mState.mPaths->release(this);
492 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800493 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494
Jamie Madill76e471e2017-10-21 09:56:01 -0400495 mImplementation->onDestroy(this);
496
Jamie Madill4928b7c2017-06-20 12:57:39 -0400497 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498}
499
Jamie Madill70ee0f62017-02-06 16:04:20 -0500500Context::~Context()
501{
502}
503
Jamie Madill4928b7c2017-06-20 12:57:39 -0400504egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505{
Jamie Madill61e16b42017-06-19 11:13:23 -0400506 mCurrentDisplay = display;
507
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508 if (!mHasBeenCurrent)
509 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500511 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400512 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
Corentin Wallezc295e512017-01-27 17:47:50 -0500514 int width = 0;
515 int height = 0;
516 if (surface != nullptr)
517 {
518 width = surface->getWidth();
519 height = surface->getHeight();
520 }
521
522 mGLState.setViewportParams(0, 0, width, height);
523 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000524
525 mHasBeenCurrent = true;
526 }
527
Jamie Madill1b94d432015-08-07 13:23:23 -0400528 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700529 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400530 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400531
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500533
534 Framebuffer *newDefault = nullptr;
535 if (surface != nullptr)
536 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500538 mCurrentSurface = surface;
539 newDefault = surface->getDefaultFramebuffer();
540 }
541 else
542 {
543 if (mSurfacelessFramebuffer == nullptr)
544 {
545 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
546 }
547
548 newDefault = mSurfacelessFramebuffer;
549 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000550
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 // Update default framebuffer, the binding of the previous default
552 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400553 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700554 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700556 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700560 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500562 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400563 }
Ian Ewell292f0052016-02-04 10:37:32 -0500564
565 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 mImplementation->onMakeCurrent(this);
567 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000568}
569
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400571{
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500573 Framebuffer *currentDefault = nullptr;
574 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400575 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500576 currentDefault = mCurrentSurface->getDefaultFramebuffer();
577 }
578 else if (mSurfacelessFramebuffer != nullptr)
579 {
580 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400581 }
582
Corentin Wallezc295e512017-01-27 17:47:50 -0500583 if (mGLState.getReadFramebuffer() == currentDefault)
584 {
585 mGLState.setReadFramebufferBinding(nullptr);
586 }
587 if (mGLState.getDrawFramebuffer() == currentDefault)
588 {
589 mGLState.setDrawFramebufferBinding(nullptr);
590 }
591 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
592
593 if (mCurrentSurface)
594 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400595 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500596 mCurrentSurface = nullptr;
597 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400598
599 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400600}
601
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602GLuint Context::createBuffer()
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createProgram()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
Jiawei Shao385b3e02018-03-21 09:43:28 +0800612GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
617GLuint Context::createTexture()
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620}
621
622GLuint Context::createRenderbuffer()
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625}
626
Brandon Jones59770802018-04-02 13:18:42 -0700627GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300628{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500629 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300630 if (resultOrError.isError())
631 {
632 handleError(resultOrError.getError());
633 return 0;
634 }
635 return resultOrError.getResult();
636}
637
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638// Returns an unused framebuffer name
639GLuint Context::createFramebuffer()
640{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500641 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500644void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500646 for (int i = 0; i < n; i++)
647 {
648 GLuint handle = mFenceNVHandleAllocator.allocate();
649 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
650 fences[i] = handle;
651 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652}
653
Yunchao Hea336b902017-08-02 16:05:21 +0800654GLuint Context::createProgramPipeline()
655{
656 return mState.mPipelines->createProgramPipeline();
657}
658
Jiawei Shao385b3e02018-03-21 09:43:28 +0800659GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800660{
661 UNIMPLEMENTED();
662 return 0u;
663}
664
James Darpinian4d9d4832018-03-13 12:43:28 -0700665void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666{
James Darpinian4d9d4832018-03-13 12:43:28 -0700667 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
668 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669 {
670 detachBuffer(buffer);
671 }
Jamie Madill893ab082014-05-16 16:56:10 -0400672
James Darpinian4d9d4832018-03-13 12:43:28 -0700673 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676void Context::deleteShader(GLuint shader)
677{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteProgram(GLuint program)
682{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500683 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686void Context::deleteTexture(GLuint texture)
687{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500688 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689 {
690 detachTexture(texture);
691 }
692
Jamie Madill6c1f6712017-02-14 19:08:04 -0500693 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694}
695
696void Context::deleteRenderbuffer(GLuint renderbuffer)
697{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500698 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699 {
700 detachRenderbuffer(renderbuffer);
701 }
Jamie Madill893ab082014-05-16 16:56:10 -0400702
Jamie Madill6c1f6712017-02-14 19:08:04 -0500703 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704}
705
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400706void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400707{
708 // The spec specifies the underlying Fence object is not deleted until all current
709 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
710 // and since our API is currently designed for being called from a single thread, we can delete
711 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400712 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400713}
714
Yunchao Hea336b902017-08-02 16:05:21 +0800715void Context::deleteProgramPipeline(GLuint pipeline)
716{
717 if (mState.mPipelines->getProgramPipeline(pipeline))
718 {
719 detachProgramPipeline(pipeline);
720 }
721
722 mState.mPipelines->deleteObject(this, pipeline);
723}
724
Sami Väisänene45e53b2016-05-25 10:36:04 +0300725void Context::deletePaths(GLuint first, GLsizei range)
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728}
729
Brandon Jones59770802018-04-02 13:18:42 -0700730bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300733 if (pathObj == nullptr)
734 return false;
735
736 return pathObj->hasPathData();
737}
738
Brandon Jones59770802018-04-02 13:18:42 -0700739bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300740{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500741 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742}
743
Brandon Jones59770802018-04-02 13:18:42 -0700744void Context::pathCommands(GLuint path,
745 GLsizei numCommands,
746 const GLubyte *commands,
747 GLsizei numCoords,
748 GLenum coordType,
749 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500751 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752
753 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
754}
755
Jamie Madill007530e2017-12-28 14:27:04 -0500756void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Jamie Madill007530e2017-12-28 14:27:04 -0500758 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759
760 switch (pname)
761 {
762 case GL_PATH_STROKE_WIDTH_CHROMIUM:
763 pathObj->setStrokeWidth(value);
764 break;
765 case GL_PATH_END_CAPS_CHROMIUM:
766 pathObj->setEndCaps(static_cast<GLenum>(value));
767 break;
768 case GL_PATH_JOIN_STYLE_CHROMIUM:
769 pathObj->setJoinStyle(static_cast<GLenum>(value));
770 break;
771 case GL_PATH_MITER_LIMIT_CHROMIUM:
772 pathObj->setMiterLimit(value);
773 break;
774 case GL_PATH_STROKE_BOUND_CHROMIUM:
775 pathObj->setStrokeBound(value);
776 break;
777 default:
778 UNREACHABLE();
779 break;
780 }
781}
782
Jamie Madill007530e2017-12-28 14:27:04 -0500783void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300784{
Jamie Madill007530e2017-12-28 14:27:04 -0500785 // TODO(jmadill): Should use proper clamping/casting.
786 pathParameterf(path, pname, static_cast<GLfloat>(value));
787}
788
789void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
790{
791 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300792
793 switch (pname)
794 {
795 case GL_PATH_STROKE_WIDTH_CHROMIUM:
796 *value = pathObj->getStrokeWidth();
797 break;
798 case GL_PATH_END_CAPS_CHROMIUM:
799 *value = static_cast<GLfloat>(pathObj->getEndCaps());
800 break;
801 case GL_PATH_JOIN_STYLE_CHROMIUM:
802 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
803 break;
804 case GL_PATH_MITER_LIMIT_CHROMIUM:
805 *value = pathObj->getMiterLimit();
806 break;
807 case GL_PATH_STROKE_BOUND_CHROMIUM:
808 *value = pathObj->getStrokeBound();
809 break;
810 default:
811 UNREACHABLE();
812 break;
813 }
814}
815
Jamie Madill007530e2017-12-28 14:27:04 -0500816void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
817{
818 GLfloat val = 0.0f;
819 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
820 if (value)
821 *value = static_cast<GLint>(val);
822}
823
Brandon Jones59770802018-04-02 13:18:42 -0700824void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825{
826 mGLState.setPathStencilFunc(func, ref, mask);
827}
828
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829void Context::deleteFramebuffer(GLuint framebuffer)
830{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500831 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832 {
833 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500835
Jamie Madill6c1f6712017-02-14 19:08:04 -0500836 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837}
838
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500839void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500841 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500843 GLuint fence = fences[i];
844
845 FenceNV *fenceObject = nullptr;
846 if (mFenceNVMap.erase(fence, &fenceObject))
847 {
848 mFenceNVHandleAllocator.release(fence);
849 delete fenceObject;
850 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
852}
853
Geoff Lang70d0f492015-12-10 17:45:46 -0500854Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Jamie Madill570f7c82014-07-03 10:38:54 -0400859Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Geoff Lang70d0f492015-12-10 17:45:46 -0500864Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867}
868
Jamie Madill70b5bb02017-08-28 13:32:37 -0400869Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400870{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400871 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400872}
873
Jamie Madill57a89722013-07-02 11:57:03 -0400874VertexArray *Context::getVertexArray(GLuint handle) const
875{
Jamie Madill96a483b2017-06-27 16:49:21 -0400876 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400877}
878
Jamie Madilldc356042013-07-19 16:36:57 -0400879Sampler *Context::getSampler(GLuint handle) const
880{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500881 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400882}
883
Geoff Langc8058452014-02-03 12:04:11 -0500884TransformFeedback *Context::getTransformFeedback(GLuint handle) const
885{
Jamie Madill96a483b2017-06-27 16:49:21 -0400886 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500887}
888
Yunchao Hea336b902017-08-02 16:05:21 +0800889ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
890{
891 return mState.mPipelines->getProgramPipeline(handle);
892}
893
Geoff Lang70d0f492015-12-10 17:45:46 -0500894LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
895{
896 switch (identifier)
897 {
898 case GL_BUFFER:
899 return getBuffer(name);
900 case GL_SHADER:
901 return getShader(name);
902 case GL_PROGRAM:
903 return getProgram(name);
904 case GL_VERTEX_ARRAY:
905 return getVertexArray(name);
906 case GL_QUERY:
907 return getQuery(name);
908 case GL_TRANSFORM_FEEDBACK:
909 return getTransformFeedback(name);
910 case GL_SAMPLER:
911 return getSampler(name);
912 case GL_TEXTURE:
913 return getTexture(name);
914 case GL_RENDERBUFFER:
915 return getRenderbuffer(name);
916 case GL_FRAMEBUFFER:
917 return getFramebuffer(name);
918 default:
919 UNREACHABLE();
920 return nullptr;
921 }
922}
923
924LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
925{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400926 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500927}
928
Martin Radev9d901792016-07-15 15:58:58 +0300929void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
930{
931 LabeledObject *object = getLabeledObject(identifier, name);
932 ASSERT(object != nullptr);
933
934 std::string labelName = GetObjectLabelFromPointer(length, label);
935 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400936
937 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
938 // specified object is active until we do this.
939 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300940}
941
942void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
943{
944 LabeledObject *object = getLabeledObjectFromPtr(ptr);
945 ASSERT(object != nullptr);
946
947 std::string labelName = GetObjectLabelFromPointer(length, label);
948 object->setLabel(labelName);
949}
950
951void Context::getObjectLabel(GLenum identifier,
952 GLuint name,
953 GLsizei bufSize,
954 GLsizei *length,
955 GLchar *label) const
956{
957 LabeledObject *object = getLabeledObject(identifier, name);
958 ASSERT(object != nullptr);
959
960 const std::string &objectLabel = object->getLabel();
961 GetObjectLabelBase(objectLabel, bufSize, length, label);
962}
963
964void Context::getObjectPtrLabel(const void *ptr,
965 GLsizei bufSize,
966 GLsizei *length,
967 GLchar *label) const
968{
969 LabeledObject *object = getLabeledObjectFromPtr(ptr);
970 ASSERT(object != nullptr);
971
972 const std::string &objectLabel = object->getLabel();
973 GetObjectLabelBase(objectLabel, bufSize, length, label);
974}
975
Jamie Madilldc356042013-07-19 16:36:57 -0400976bool Context::isSampler(GLuint samplerName) const
977{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500978 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400979}
980
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800981void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000982{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500983 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984
Jamie Madilldedd7b92014-11-05 16:30:36 -0500985 if (handle == 0)
986 {
987 texture = mZeroTextures[target].get();
988 }
989 else
990 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500991 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500992 }
993
994 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400995 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000996}
997
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500998void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001000 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1001 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001002 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001003}
1004
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001005void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001006{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001007 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1008 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001009 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010}
1011
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001012void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001013{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001014 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001015 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001016}
1017
Shao80957d92017-02-20 21:25:59 +08001018void Context::bindVertexBuffer(GLuint bindingIndex,
1019 GLuint bufferHandle,
1020 GLintptr offset,
1021 GLsizei stride)
1022{
1023 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001024 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001025}
1026
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001027void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001028{
Geoff Lang76b10c92014-09-05 16:28:14 -04001029 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001030 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001031 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001032 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001033}
1034
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001035void Context::bindImageTexture(GLuint unit,
1036 GLuint texture,
1037 GLint level,
1038 GLboolean layered,
1039 GLint layer,
1040 GLenum access,
1041 GLenum format)
1042{
1043 Texture *tex = mState.mTextures->getTexture(texture);
1044 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1045}
1046
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001047void Context::useProgram(GLuint program)
1048{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001049 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001050}
1051
Jiajia Qin5451d532017-11-16 17:16:34 +08001052void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1053{
1054 UNIMPLEMENTED();
1055}
1056
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001057void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001058{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001059 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001060 TransformFeedback *transformFeedback =
1061 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001062 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001063}
1064
Yunchao Hea336b902017-08-02 16:05:21 +08001065void Context::bindProgramPipeline(GLuint pipelineHandle)
1066{
1067 ProgramPipeline *pipeline =
1068 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1069 mGLState.setProgramPipelineBinding(this, pipeline);
1070}
1071
Jamie Madillf0e04492017-08-26 15:28:42 -04001072void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001075 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076
Geoff Lang5aad9672014-09-08 11:10:42 -04001077 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001078 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001079
1080 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001081 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082}
1083
Jamie Madillf0e04492017-08-26 15:28:42 -04001084void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001085{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001086 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001087 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088
Jamie Madillf0e04492017-08-26 15:28:42 -04001089 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090
Geoff Lang5aad9672014-09-08 11:10:42 -04001091 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001092 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093}
1094
Jamie Madillf0e04492017-08-26 15:28:42 -04001095void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001096{
1097 ASSERT(target == GL_TIMESTAMP_EXT);
1098
1099 Query *queryObject = getQuery(id, true, target);
1100 ASSERT(queryObject);
1101
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001103}
1104
1105void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1106{
1107 switch (pname)
1108 {
1109 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001110 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111 break;
1112 case GL_QUERY_COUNTER_BITS_EXT:
1113 switch (target)
1114 {
1115 case GL_TIME_ELAPSED_EXT:
1116 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1117 break;
1118 case GL_TIMESTAMP_EXT:
1119 params[0] = getExtensions().queryCounterBitsTimestamp;
1120 break;
1121 default:
1122 UNREACHABLE();
1123 params[0] = 0;
1124 break;
1125 }
1126 break;
1127 default:
1128 UNREACHABLE();
1129 return;
1130 }
1131}
1132
Brandon Jones59770802018-04-02 13:18:42 -07001133void Context::getQueryivRobust(GLenum target,
1134 GLenum pname,
1135 GLsizei bufSize,
1136 GLsizei *length,
1137 GLint *params)
1138{
1139 getQueryiv(target, pname, params);
1140}
1141
Geoff Lang2186c382016-10-14 10:54:54 -04001142void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001143{
Geoff Lang2186c382016-10-14 10:54:54 -04001144 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001145}
1146
Brandon Jones59770802018-04-02 13:18:42 -07001147void Context::getQueryObjectivRobust(GLuint id,
1148 GLenum pname,
1149 GLsizei bufSize,
1150 GLsizei *length,
1151 GLint *params)
1152{
1153 getQueryObjectiv(id, pname, params);
1154}
1155
Geoff Lang2186c382016-10-14 10:54:54 -04001156void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001157{
Geoff Lang2186c382016-10-14 10:54:54 -04001158 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001159}
1160
Brandon Jones59770802018-04-02 13:18:42 -07001161void Context::getQueryObjectuivRobust(GLuint id,
1162 GLenum pname,
1163 GLsizei bufSize,
1164 GLsizei *length,
1165 GLuint *params)
1166{
1167 getQueryObjectuiv(id, pname, params);
1168}
1169
Geoff Lang2186c382016-10-14 10:54:54 -04001170void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001171{
Geoff Lang2186c382016-10-14 10:54:54 -04001172 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173}
1174
Brandon Jones59770802018-04-02 13:18:42 -07001175void Context::getQueryObjecti64vRobust(GLuint id,
1176 GLenum pname,
1177 GLsizei bufSize,
1178 GLsizei *length,
1179 GLint64 *params)
1180{
1181 getQueryObjecti64v(id, pname, params);
1182}
1183
Geoff Lang2186c382016-10-14 10:54:54 -04001184void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185{
Geoff Lang2186c382016-10-14 10:54:54 -04001186 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187}
1188
Brandon Jones59770802018-04-02 13:18:42 -07001189void Context::getQueryObjectui64vRobust(GLuint id,
1190 GLenum pname,
1191 GLsizei bufSize,
1192 GLsizei *length,
1193 GLuint64 *params)
1194{
1195 getQueryObjectui64v(id, pname, params);
1196}
1197
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001198Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001200 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201}
1202
Jamie Madill2f348d22017-06-05 10:50:59 -04001203FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001204{
Jamie Madill96a483b2017-06-27 16:49:21 -04001205 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206}
1207
Jamie Madill2f348d22017-06-05 10:50:59 -04001208Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
Jamie Madill96a483b2017-06-27 16:49:21 -04001210 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001212 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001214
1215 Query *query = mQueryMap.query(handle);
1216 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001218 query = new Query(mImplementation->createQuery(type), handle);
1219 query->addRef();
1220 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001222 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223}
1224
Geoff Lang70d0f492015-12-10 17:45:46 -05001225Query *Context::getQuery(GLuint handle) const
1226{
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001228}
1229
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001230Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001231{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001232 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1233 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001234}
1235
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001236Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001238 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239}
1240
Geoff Lang492a7e42014-11-05 13:27:06 -05001241Compiler *Context::getCompiler() const
1242{
Jamie Madill2f348d22017-06-05 10:50:59 -04001243 if (mCompiler.get() == nullptr)
1244 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001245 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001246 }
1247 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001248}
1249
Jamie Madillc1d770e2017-04-13 17:31:24 -04001250void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251{
1252 switch (pname)
1253 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001254 case GL_SHADER_COMPILER:
1255 *params = GL_TRUE;
1256 break;
1257 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1258 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1259 break;
1260 default:
1261 mGLState.getBooleanv(pname, params);
1262 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001263 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264}
1265
Jamie Madillc1d770e2017-04-13 17:31:24 -04001266void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001267{
Shannon Woods53a94a82014-06-24 15:20:36 -04001268 // Queries about context capabilities and maximums are answered by Context.
1269 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001270 switch (pname)
1271 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001272 case GL_ALIASED_LINE_WIDTH_RANGE:
1273 params[0] = mCaps.minAliasedLineWidth;
1274 params[1] = mCaps.maxAliasedLineWidth;
1275 break;
1276 case GL_ALIASED_POINT_SIZE_RANGE:
1277 params[0] = mCaps.minAliasedPointSize;
1278 params[1] = mCaps.maxAliasedPointSize;
1279 break;
1280 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1281 ASSERT(mExtensions.textureFilterAnisotropic);
1282 *params = mExtensions.maxTextureAnisotropy;
1283 break;
1284 case GL_MAX_TEXTURE_LOD_BIAS:
1285 *params = mCaps.maxLODBias;
1286 break;
1287
1288 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1289 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1290 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001291 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1292 // GLES1 constants for modelview/projection matrix.
1293 if (getClientVersion() < Version(2, 0))
1294 {
1295 mGLState.getFloatv(pname, params);
1296 }
1297 else
1298 {
1299 ASSERT(mExtensions.pathRendering);
1300 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1301 memcpy(params, m, 16 * sizeof(GLfloat));
1302 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001303 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001304 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001305
Jamie Madill231c7f52017-04-26 13:45:37 -04001306 default:
1307 mGLState.getFloatv(pname, params);
1308 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001309 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310}
1311
Jamie Madillc1d770e2017-04-13 17:31:24 -04001312void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001313{
Shannon Woods53a94a82014-06-24 15:20:36 -04001314 // Queries about context capabilities and maximums are answered by Context.
1315 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001316
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317 switch (pname)
1318 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001319 case GL_MAX_VERTEX_ATTRIBS:
1320 *params = mCaps.maxVertexAttributes;
1321 break;
1322 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1323 *params = mCaps.maxVertexUniformVectors;
1324 break;
1325 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1326 *params = mCaps.maxVertexUniformComponents;
1327 break;
1328 case GL_MAX_VARYING_VECTORS:
1329 *params = mCaps.maxVaryingVectors;
1330 break;
1331 case GL_MAX_VARYING_COMPONENTS:
1332 *params = mCaps.maxVertexOutputComponents;
1333 break;
1334 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1335 *params = mCaps.maxCombinedTextureImageUnits;
1336 break;
1337 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1338 *params = mCaps.maxVertexTextureImageUnits;
1339 break;
1340 case GL_MAX_TEXTURE_IMAGE_UNITS:
1341 *params = mCaps.maxTextureImageUnits;
1342 break;
1343 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1344 *params = mCaps.maxFragmentUniformVectors;
1345 break;
1346 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1347 *params = mCaps.maxFragmentUniformComponents;
1348 break;
1349 case GL_MAX_RENDERBUFFER_SIZE:
1350 *params = mCaps.maxRenderbufferSize;
1351 break;
1352 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1353 *params = mCaps.maxColorAttachments;
1354 break;
1355 case GL_MAX_DRAW_BUFFERS_EXT:
1356 *params = mCaps.maxDrawBuffers;
1357 break;
1358 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1359 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1360 case GL_SUBPIXEL_BITS:
1361 *params = 4;
1362 break;
1363 case GL_MAX_TEXTURE_SIZE:
1364 *params = mCaps.max2DTextureSize;
1365 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001366 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1367 *params = mCaps.maxRectangleTextureSize;
1368 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001369 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1370 *params = mCaps.maxCubeMapTextureSize;
1371 break;
1372 case GL_MAX_3D_TEXTURE_SIZE:
1373 *params = mCaps.max3DTextureSize;
1374 break;
1375 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1376 *params = mCaps.maxArrayTextureLayers;
1377 break;
1378 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1379 *params = mCaps.uniformBufferOffsetAlignment;
1380 break;
1381 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1382 *params = mCaps.maxUniformBufferBindings;
1383 break;
1384 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1385 *params = mCaps.maxVertexUniformBlocks;
1386 break;
1387 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1388 *params = mCaps.maxFragmentUniformBlocks;
1389 break;
1390 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1391 *params = mCaps.maxCombinedTextureImageUnits;
1392 break;
1393 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1394 *params = mCaps.maxVertexOutputComponents;
1395 break;
1396 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1397 *params = mCaps.maxFragmentInputComponents;
1398 break;
1399 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1400 *params = mCaps.minProgramTexelOffset;
1401 break;
1402 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1403 *params = mCaps.maxProgramTexelOffset;
1404 break;
1405 case GL_MAJOR_VERSION:
1406 *params = getClientVersion().major;
1407 break;
1408 case GL_MINOR_VERSION:
1409 *params = getClientVersion().minor;
1410 break;
1411 case GL_MAX_ELEMENTS_INDICES:
1412 *params = mCaps.maxElementsIndices;
1413 break;
1414 case GL_MAX_ELEMENTS_VERTICES:
1415 *params = mCaps.maxElementsVertices;
1416 break;
1417 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1418 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1419 break;
1420 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1421 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1422 break;
1423 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1424 *params = mCaps.maxTransformFeedbackSeparateComponents;
1425 break;
1426 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1427 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1428 break;
1429 case GL_MAX_SAMPLES_ANGLE:
1430 *params = mCaps.maxSamples;
1431 break;
1432 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001433 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001434 params[0] = mCaps.maxViewportWidth;
1435 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001436 }
1437 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 case GL_COMPRESSED_TEXTURE_FORMATS:
1439 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1440 params);
1441 break;
1442 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1443 *params = mResetStrategy;
1444 break;
1445 case GL_NUM_SHADER_BINARY_FORMATS:
1446 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1447 break;
1448 case GL_SHADER_BINARY_FORMATS:
1449 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1450 break;
1451 case GL_NUM_PROGRAM_BINARY_FORMATS:
1452 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1453 break;
1454 case GL_PROGRAM_BINARY_FORMATS:
1455 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1456 break;
1457 case GL_NUM_EXTENSIONS:
1458 *params = static_cast<GLint>(mExtensionStrings.size());
1459 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001460
Jamie Madill231c7f52017-04-26 13:45:37 -04001461 // GL_KHR_debug
1462 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1463 *params = mExtensions.maxDebugMessageLength;
1464 break;
1465 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1466 *params = mExtensions.maxDebugLoggedMessages;
1467 break;
1468 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1469 *params = mExtensions.maxDebugGroupStackDepth;
1470 break;
1471 case GL_MAX_LABEL_LENGTH:
1472 *params = mExtensions.maxLabelLength;
1473 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001474
Martin Radeve5285d22017-07-14 16:23:53 +03001475 // GL_ANGLE_multiview
1476 case GL_MAX_VIEWS_ANGLE:
1477 *params = mExtensions.maxViews;
1478 break;
1479
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 // GL_EXT_disjoint_timer_query
1481 case GL_GPU_DISJOINT_EXT:
1482 *params = mImplementation->getGPUDisjoint();
1483 break;
1484 case GL_MAX_FRAMEBUFFER_WIDTH:
1485 *params = mCaps.maxFramebufferWidth;
1486 break;
1487 case GL_MAX_FRAMEBUFFER_HEIGHT:
1488 *params = mCaps.maxFramebufferHeight;
1489 break;
1490 case GL_MAX_FRAMEBUFFER_SAMPLES:
1491 *params = mCaps.maxFramebufferSamples;
1492 break;
1493 case GL_MAX_SAMPLE_MASK_WORDS:
1494 *params = mCaps.maxSampleMaskWords;
1495 break;
1496 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1497 *params = mCaps.maxColorTextureSamples;
1498 break;
1499 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1500 *params = mCaps.maxDepthTextureSamples;
1501 break;
1502 case GL_MAX_INTEGER_SAMPLES:
1503 *params = mCaps.maxIntegerSamples;
1504 break;
1505 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1506 *params = mCaps.maxVertexAttribRelativeOffset;
1507 break;
1508 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1509 *params = mCaps.maxVertexAttribBindings;
1510 break;
1511 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1512 *params = mCaps.maxVertexAttribStride;
1513 break;
1514 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1515 *params = mCaps.maxVertexAtomicCounterBuffers;
1516 break;
1517 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1518 *params = mCaps.maxVertexAtomicCounters;
1519 break;
1520 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1521 *params = mCaps.maxVertexImageUniforms;
1522 break;
1523 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1524 *params = mCaps.maxVertexShaderStorageBlocks;
1525 break;
1526 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1527 *params = mCaps.maxFragmentAtomicCounterBuffers;
1528 break;
1529 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1530 *params = mCaps.maxFragmentAtomicCounters;
1531 break;
1532 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1533 *params = mCaps.maxFragmentImageUniforms;
1534 break;
1535 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1536 *params = mCaps.maxFragmentShaderStorageBlocks;
1537 break;
1538 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1539 *params = mCaps.minProgramTextureGatherOffset;
1540 break;
1541 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1542 *params = mCaps.maxProgramTextureGatherOffset;
1543 break;
1544 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1545 *params = mCaps.maxComputeWorkGroupInvocations;
1546 break;
1547 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1548 *params = mCaps.maxComputeUniformBlocks;
1549 break;
1550 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1551 *params = mCaps.maxComputeTextureImageUnits;
1552 break;
1553 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1554 *params = mCaps.maxComputeSharedMemorySize;
1555 break;
1556 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1557 *params = mCaps.maxComputeUniformComponents;
1558 break;
1559 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1560 *params = mCaps.maxComputeAtomicCounterBuffers;
1561 break;
1562 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1563 *params = mCaps.maxComputeAtomicCounters;
1564 break;
1565 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1566 *params = mCaps.maxComputeImageUniforms;
1567 break;
1568 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1569 *params = mCaps.maxCombinedComputeUniformComponents;
1570 break;
1571 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1572 *params = mCaps.maxComputeShaderStorageBlocks;
1573 break;
1574 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1575 *params = mCaps.maxCombinedShaderOutputResources;
1576 break;
1577 case GL_MAX_UNIFORM_LOCATIONS:
1578 *params = mCaps.maxUniformLocations;
1579 break;
1580 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1581 *params = mCaps.maxAtomicCounterBufferBindings;
1582 break;
1583 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1584 *params = mCaps.maxAtomicCounterBufferSize;
1585 break;
1586 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1587 *params = mCaps.maxCombinedAtomicCounterBuffers;
1588 break;
1589 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1590 *params = mCaps.maxCombinedAtomicCounters;
1591 break;
1592 case GL_MAX_IMAGE_UNITS:
1593 *params = mCaps.maxImageUnits;
1594 break;
1595 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1596 *params = mCaps.maxCombinedImageUniforms;
1597 break;
1598 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1599 *params = mCaps.maxShaderStorageBufferBindings;
1600 break;
1601 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1602 *params = mCaps.maxCombinedShaderStorageBlocks;
1603 break;
1604 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1605 *params = mCaps.shaderStorageBufferOffsetAlignment;
1606 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001607
1608 // GL_EXT_geometry_shader
1609 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1610 *params = mCaps.maxFramebufferLayers;
1611 break;
1612 case GL_LAYER_PROVOKING_VERTEX_EXT:
1613 *params = mCaps.layerProvokingVertex;
1614 break;
1615 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1616 *params = mCaps.maxGeometryUniformComponents;
1617 break;
1618 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1619 *params = mCaps.maxGeometryUniformBlocks;
1620 break;
1621 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1622 *params = mCaps.maxCombinedGeometryUniformComponents;
1623 break;
1624 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1625 *params = mCaps.maxGeometryInputComponents;
1626 break;
1627 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1628 *params = mCaps.maxGeometryOutputComponents;
1629 break;
1630 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1631 *params = mCaps.maxGeometryOutputVertices;
1632 break;
1633 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1634 *params = mCaps.maxGeometryTotalOutputComponents;
1635 break;
1636 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1637 *params = mCaps.maxGeometryShaderInvocations;
1638 break;
1639 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1640 *params = mCaps.maxGeometryTextureImageUnits;
1641 break;
1642 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1643 *params = mCaps.maxGeometryAtomicCounterBuffers;
1644 break;
1645 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1646 *params = mCaps.maxGeometryAtomicCounters;
1647 break;
1648 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1649 *params = mCaps.maxGeometryImageUniforms;
1650 break;
1651 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1652 *params = mCaps.maxGeometryShaderStorageBlocks;
1653 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001654 // GLES1 emulation: Caps queries
1655 case GL_MAX_TEXTURE_UNITS:
1656 *params = mCaps.maxMultitextureUnits;
1657 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001658 case GL_MAX_MODELVIEW_STACK_DEPTH:
1659 *params = mCaps.maxModelviewMatrixStackDepth;
1660 break;
1661 case GL_MAX_PROJECTION_STACK_DEPTH:
1662 *params = mCaps.maxProjectionMatrixStackDepth;
1663 break;
1664 case GL_MAX_TEXTURE_STACK_DEPTH:
1665 *params = mCaps.maxTextureMatrixStackDepth;
1666 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001667 // GLES1 emulation: Vertex attribute queries
1668 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1669 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1670 case GL_COLOR_ARRAY_BUFFER_BINDING:
1671 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1672 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1673 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1674 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1675 break;
1676 case GL_VERTEX_ARRAY_STRIDE:
1677 case GL_NORMAL_ARRAY_STRIDE:
1678 case GL_COLOR_ARRAY_STRIDE:
1679 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1680 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1681 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1682 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1683 break;
1684 case GL_VERTEX_ARRAY_SIZE:
1685 case GL_COLOR_ARRAY_SIZE:
1686 case GL_TEXTURE_COORD_ARRAY_SIZE:
1687 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1688 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1689 break;
1690 case GL_VERTEX_ARRAY_TYPE:
1691 case GL_COLOR_ARRAY_TYPE:
1692 case GL_NORMAL_ARRAY_TYPE:
1693 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1694 case GL_TEXTURE_COORD_ARRAY_TYPE:
1695 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1696 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1697 break;
1698
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001700 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001702 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001703}
1704
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001705void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001706{
Shannon Woods53a94a82014-06-24 15:20:36 -04001707 // Queries about context capabilities and maximums are answered by Context.
1708 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001709 switch (pname)
1710 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001711 case GL_MAX_ELEMENT_INDEX:
1712 *params = mCaps.maxElementIndex;
1713 break;
1714 case GL_MAX_UNIFORM_BLOCK_SIZE:
1715 *params = mCaps.maxUniformBlockSize;
1716 break;
1717 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1718 *params = mCaps.maxCombinedVertexUniformComponents;
1719 break;
1720 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1721 *params = mCaps.maxCombinedFragmentUniformComponents;
1722 break;
1723 case GL_MAX_SERVER_WAIT_TIMEOUT:
1724 *params = mCaps.maxServerWaitTimeout;
1725 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001726
Jamie Madill231c7f52017-04-26 13:45:37 -04001727 // GL_EXT_disjoint_timer_query
1728 case GL_TIMESTAMP_EXT:
1729 *params = mImplementation->getTimestamp();
1730 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001731
Jamie Madill231c7f52017-04-26 13:45:37 -04001732 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1733 *params = mCaps.maxShaderStorageBlockSize;
1734 break;
1735 default:
1736 UNREACHABLE();
1737 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001738 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001739}
1740
Geoff Lang70d0f492015-12-10 17:45:46 -05001741void Context::getPointerv(GLenum pname, void **params) const
1742{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001743 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001744}
1745
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001746void Context::getPointervRobustANGLERobust(GLenum pname,
1747 GLsizei bufSize,
1748 GLsizei *length,
1749 void **params)
1750{
1751 UNIMPLEMENTED();
1752}
1753
Martin Radev66fb8202016-07-28 11:45:20 +03001754void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001755{
Shannon Woods53a94a82014-06-24 15:20:36 -04001756 // Queries about context capabilities and maximums are answered by Context.
1757 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001758
1759 GLenum nativeType;
1760 unsigned int numParams;
1761 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1762 ASSERT(queryStatus);
1763
1764 if (nativeType == GL_INT)
1765 {
1766 switch (target)
1767 {
1768 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1769 ASSERT(index < 3u);
1770 *data = mCaps.maxComputeWorkGroupCount[index];
1771 break;
1772 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1773 ASSERT(index < 3u);
1774 *data = mCaps.maxComputeWorkGroupSize[index];
1775 break;
1776 default:
1777 mGLState.getIntegeri_v(target, index, data);
1778 }
1779 }
1780 else
1781 {
1782 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1783 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001784}
1785
Brandon Jones59770802018-04-02 13:18:42 -07001786void Context::getIntegeri_vRobust(GLenum target,
1787 GLuint index,
1788 GLsizei bufSize,
1789 GLsizei *length,
1790 GLint *data)
1791{
1792 getIntegeri_v(target, index, data);
1793}
1794
Martin Radev66fb8202016-07-28 11:45:20 +03001795void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001796{
Shannon Woods53a94a82014-06-24 15:20:36 -04001797 // Queries about context capabilities and maximums are answered by Context.
1798 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001799
1800 GLenum nativeType;
1801 unsigned int numParams;
1802 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1803 ASSERT(queryStatus);
1804
1805 if (nativeType == GL_INT_64_ANGLEX)
1806 {
1807 mGLState.getInteger64i_v(target, index, data);
1808 }
1809 else
1810 {
1811 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1812 }
1813}
1814
Brandon Jones59770802018-04-02 13:18:42 -07001815void Context::getInteger64i_vRobust(GLenum target,
1816 GLuint index,
1817 GLsizei bufSize,
1818 GLsizei *length,
1819 GLint64 *data)
1820{
1821 getInteger64i_v(target, index, data);
1822}
1823
Martin Radev66fb8202016-07-28 11:45:20 +03001824void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1825{
1826 // Queries about context capabilities and maximums are answered by Context.
1827 // Queries about current GL state values are answered by State.
1828
1829 GLenum nativeType;
1830 unsigned int numParams;
1831 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1832 ASSERT(queryStatus);
1833
1834 if (nativeType == GL_BOOL)
1835 {
1836 mGLState.getBooleani_v(target, index, data);
1837 }
1838 else
1839 {
1840 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1841 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001842}
1843
Brandon Jones59770802018-04-02 13:18:42 -07001844void Context::getBooleani_vRobust(GLenum target,
1845 GLuint index,
1846 GLsizei bufSize,
1847 GLsizei *length,
1848 GLboolean *data)
1849{
1850 getBooleani_v(target, index, data);
1851}
1852
Corentin Wallez336129f2017-10-17 15:55:40 -04001853void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001854{
1855 Buffer *buffer = mGLState.getTargetBuffer(target);
1856 QueryBufferParameteriv(buffer, pname, params);
1857}
1858
Brandon Jones59770802018-04-02 13:18:42 -07001859void Context::getBufferParameterivRobust(BufferBinding target,
1860 GLenum pname,
1861 GLsizei bufSize,
1862 GLsizei *length,
1863 GLint *params)
1864{
1865 getBufferParameteriv(target, pname, params);
1866}
1867
He Yunchao010e4db2017-03-03 14:22:06 +08001868void Context::getFramebufferAttachmentParameteriv(GLenum target,
1869 GLenum attachment,
1870 GLenum pname,
1871 GLint *params)
1872{
1873 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001874 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001875}
1876
Brandon Jones59770802018-04-02 13:18:42 -07001877void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1878 GLenum attachment,
1879 GLenum pname,
1880 GLsizei bufSize,
1881 GLsizei *length,
1882 GLint *params)
1883{
1884 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1885}
1886
He Yunchao010e4db2017-03-03 14:22:06 +08001887void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1888{
1889 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1890 QueryRenderbufferiv(this, renderbuffer, pname, params);
1891}
1892
Brandon Jones59770802018-04-02 13:18:42 -07001893void Context::getRenderbufferParameterivRobust(GLenum target,
1894 GLenum pname,
1895 GLsizei bufSize,
1896 GLsizei *length,
1897 GLint *params)
1898{
1899 getRenderbufferParameteriv(target, pname, params);
1900}
1901
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001902void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001903{
1904 Texture *texture = getTargetTexture(target);
1905 QueryTexParameterfv(texture, pname, params);
1906}
1907
Brandon Jones59770802018-04-02 13:18:42 -07001908void Context::getTexParameterfvRobust(TextureType target,
1909 GLenum pname,
1910 GLsizei bufSize,
1911 GLsizei *length,
1912 GLfloat *params)
1913{
1914 getTexParameterfv(target, pname, params);
1915}
1916
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001917void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001918{
1919 Texture *texture = getTargetTexture(target);
1920 QueryTexParameteriv(texture, pname, params);
1921}
Jiajia Qin5451d532017-11-16 17:16:34 +08001922
Brandon Jones59770802018-04-02 13:18:42 -07001923void Context::getTexParameterivRobust(TextureType target,
1924 GLenum pname,
1925 GLsizei bufSize,
1926 GLsizei *length,
1927 GLint *params)
1928{
1929 getTexParameteriv(target, pname, params);
1930}
1931
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001932void Context::getTexParameterIivRobust(TextureType target,
1933 GLenum pname,
1934 GLsizei bufSize,
1935 GLsizei *length,
1936 GLint *params)
1937{
1938 UNIMPLEMENTED();
1939}
1940
1941void Context::getTexParameterIuivRobust(TextureType target,
1942 GLenum pname,
1943 GLsizei bufSize,
1944 GLsizei *length,
1945 GLuint *params)
1946{
1947 UNIMPLEMENTED();
1948}
1949
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001950void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001951{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001952 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001953 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001954}
1955
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001956void Context::getTexLevelParameterivRobust(TextureTarget target,
1957 GLint level,
1958 GLenum pname,
1959 GLsizei bufSize,
1960 GLsizei *length,
1961 GLint *params)
1962{
1963 UNIMPLEMENTED();
1964}
1965
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001966void Context::getTexLevelParameterfv(TextureTarget target,
1967 GLint level,
1968 GLenum pname,
1969 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001970{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001971 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001972 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001973}
1974
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001975void Context::getTexLevelParameterfvRobust(TextureTarget target,
1976 GLint level,
1977 GLenum pname,
1978 GLsizei bufSize,
1979 GLsizei *length,
1980 GLfloat *params)
1981{
1982 UNIMPLEMENTED();
1983}
1984
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001985void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001986{
1987 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001988 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001989 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001990}
1991
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001992void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001993{
1994 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001995 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001996 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001997}
1998
Brandon Jones59770802018-04-02 13:18:42 -07001999void Context::texParameterfvRobust(TextureType target,
2000 GLenum pname,
2001 GLsizei bufSize,
2002 const GLfloat *params)
2003{
2004 texParameterfv(target, pname, params);
2005}
2006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002007void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002008{
2009 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002010 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002011 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002012}
2013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002014void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002015{
2016 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002017 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002018 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::texParameterivRobust(TextureType target,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 const GLint *params)
2025{
2026 texParameteriv(target, pname, params);
2027}
2028
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002029void Context::texParameterIivRobust(TextureType target,
2030 GLenum pname,
2031 GLsizei bufSize,
2032 const GLint *params)
2033{
2034 UNIMPLEMENTED();
2035}
2036
2037void Context::texParameterIuivRobust(TextureType target,
2038 GLenum pname,
2039 GLsizei bufSize,
2040 const GLuint *params)
2041{
2042 UNIMPLEMENTED();
2043}
2044
Jamie Madill675fe712016-12-19 13:07:54 -05002045void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002046{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002047 // No-op if zero count
2048 if (count == 0)
2049 {
2050 return;
2051 }
2052
Jamie Madill05b35b22017-10-03 09:01:44 -04002053 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002054 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002055 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002056}
2057
Jamie Madill675fe712016-12-19 13:07:54 -05002058void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002059{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002060 // No-op if zero count
2061 if (count == 0 || instanceCount == 0)
2062 {
2063 return;
2064 }
2065
Jamie Madill05b35b22017-10-03 09:01:44 -04002066 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002067 ANGLE_CONTEXT_TRY(
2068 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002069 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2070 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002071}
2072
Jamie Madill876429b2017-04-20 15:46:24 -04002073void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002074{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002075 // No-op if zero count
2076 if (count == 0)
2077 {
2078 return;
2079 }
2080
Jamie Madill05b35b22017-10-03 09:01:44 -04002081 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002082 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002083}
2084
Jamie Madill675fe712016-12-19 13:07:54 -05002085void Context::drawElementsInstanced(GLenum mode,
2086 GLsizei count,
2087 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002088 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002089 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002090{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002091 // No-op if zero count
2092 if (count == 0 || instances == 0)
2093 {
2094 return;
2095 }
2096
Jamie Madill05b35b22017-10-03 09:01:44 -04002097 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002098 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002099 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002100}
2101
Jamie Madill675fe712016-12-19 13:07:54 -05002102void Context::drawRangeElements(GLenum mode,
2103 GLuint start,
2104 GLuint end,
2105 GLsizei count,
2106 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002107 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002108{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002109 // No-op if zero count
2110 if (count == 0)
2111 {
2112 return;
2113 }
2114
Jamie Madill05b35b22017-10-03 09:01:44 -04002115 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002116 ANGLE_CONTEXT_TRY(
2117 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002118}
2119
Jamie Madill876429b2017-04-20 15:46:24 -04002120void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002121{
Jamie Madill05b35b22017-10-03 09:01:44 -04002122 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002123 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002124}
2125
Jamie Madill876429b2017-04-20 15:46:24 -04002126void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002127{
Jamie Madill05b35b22017-10-03 09:01:44 -04002128 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002129 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002130}
2131
Jamie Madill675fe712016-12-19 13:07:54 -05002132void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002133{
Jamie Madillafa02a22017-11-23 12:57:38 -05002134 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002135}
2136
Jamie Madill675fe712016-12-19 13:07:54 -05002137void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002138{
Jamie Madillafa02a22017-11-23 12:57:38 -05002139 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002140}
2141
Austin Kinross6ee1e782015-05-29 17:05:37 -07002142void Context::insertEventMarker(GLsizei length, const char *marker)
2143{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002144 ASSERT(mImplementation);
2145 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002146}
2147
2148void Context::pushGroupMarker(GLsizei length, const char *marker)
2149{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002150 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002151
2152 if (marker == nullptr)
2153 {
2154 // From the EXT_debug_marker spec,
2155 // "If <marker> is null then an empty string is pushed on the stack."
2156 mImplementation->pushGroupMarker(length, "");
2157 }
2158 else
2159 {
2160 mImplementation->pushGroupMarker(length, marker);
2161 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002162}
2163
2164void Context::popGroupMarker()
2165{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002166 ASSERT(mImplementation);
2167 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002168}
2169
Geoff Langd8605522016-04-13 10:19:12 -04002170void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2171{
2172 Program *programObject = getProgram(program);
2173 ASSERT(programObject);
2174
2175 programObject->bindUniformLocation(location, name);
2176}
2177
Brandon Jones59770802018-04-02 13:18:42 -07002178void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002179{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002180 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002181}
2182
Brandon Jones59770802018-04-02 13:18:42 -07002183void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002184{
2185 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2186}
2187
Brandon Jones59770802018-04-02 13:18:42 -07002188void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002189{
2190 GLfloat I[16];
2191 angle::Matrix<GLfloat>::setToIdentity(I);
2192
2193 mGLState.loadPathRenderingMatrix(matrixMode, I);
2194}
2195
2196void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2197{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002198 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002199 if (!pathObj)
2200 return;
2201
2202 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002203 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002204
2205 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2206}
2207
2208void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2209{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002210 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002211 if (!pathObj)
2212 return;
2213
2214 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002215 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002216
2217 mImplementation->stencilStrokePath(pathObj, reference, mask);
2218}
2219
2220void Context::coverFillPath(GLuint path, GLenum coverMode)
2221{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002222 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002223 if (!pathObj)
2224 return;
2225
2226 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002227 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228
2229 mImplementation->coverFillPath(pathObj, coverMode);
2230}
2231
2232void Context::coverStrokePath(GLuint path, GLenum coverMode)
2233{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002234 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002235 if (!pathObj)
2236 return;
2237
2238 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002239 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240
2241 mImplementation->coverStrokePath(pathObj, coverMode);
2242}
2243
2244void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2245{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002246 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002247 if (!pathObj)
2248 return;
2249
2250 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002251 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252
2253 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2254}
2255
2256void Context::stencilThenCoverStrokePath(GLuint path,
2257 GLint reference,
2258 GLuint mask,
2259 GLenum coverMode)
2260{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002261 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002262 if (!pathObj)
2263 return;
2264
2265 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002266 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002267
2268 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2269}
2270
Sami Väisänend59ca052016-06-21 16:10:00 +03002271void Context::coverFillPathInstanced(GLsizei numPaths,
2272 GLenum pathNameType,
2273 const void *paths,
2274 GLuint pathBase,
2275 GLenum coverMode,
2276 GLenum transformType,
2277 const GLfloat *transformValues)
2278{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002279 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002280
2281 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002282 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002283
2284 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2285}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002286
Sami Väisänend59ca052016-06-21 16:10:00 +03002287void Context::coverStrokePathInstanced(GLsizei numPaths,
2288 GLenum pathNameType,
2289 const void *paths,
2290 GLuint pathBase,
2291 GLenum coverMode,
2292 GLenum transformType,
2293 const GLfloat *transformValues)
2294{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002295 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002296
2297 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002298 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002299
2300 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2301 transformValues);
2302}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002303
Sami Väisänend59ca052016-06-21 16:10:00 +03002304void Context::stencilFillPathInstanced(GLsizei numPaths,
2305 GLenum pathNameType,
2306 const void *paths,
2307 GLuint pathBase,
2308 GLenum fillMode,
2309 GLuint mask,
2310 GLenum transformType,
2311 const GLfloat *transformValues)
2312{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002313 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002314
2315 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002316 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002317
2318 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2319 transformValues);
2320}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002321
Sami Väisänend59ca052016-06-21 16:10:00 +03002322void Context::stencilStrokePathInstanced(GLsizei numPaths,
2323 GLenum pathNameType,
2324 const void *paths,
2325 GLuint pathBase,
2326 GLint reference,
2327 GLuint mask,
2328 GLenum transformType,
2329 const GLfloat *transformValues)
2330{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002331 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002332
2333 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002334 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002335
2336 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2337 transformValues);
2338}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002339
Sami Väisänend59ca052016-06-21 16:10:00 +03002340void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2341 GLenum pathNameType,
2342 const void *paths,
2343 GLuint pathBase,
2344 GLenum fillMode,
2345 GLuint mask,
2346 GLenum coverMode,
2347 GLenum transformType,
2348 const GLfloat *transformValues)
2349{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002350 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002351
2352 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002353 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002354
2355 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2356 transformType, transformValues);
2357}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002358
Sami Väisänend59ca052016-06-21 16:10:00 +03002359void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2360 GLenum pathNameType,
2361 const void *paths,
2362 GLuint pathBase,
2363 GLint reference,
2364 GLuint mask,
2365 GLenum coverMode,
2366 GLenum transformType,
2367 const GLfloat *transformValues)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002370
2371 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002372 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002373
2374 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2375 transformType, transformValues);
2376}
2377
Sami Väisänen46eaa942016-06-29 10:26:37 +03002378void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2379{
2380 auto *programObject = getProgram(program);
2381
2382 programObject->bindFragmentInputLocation(location, name);
2383}
2384
2385void Context::programPathFragmentInputGen(GLuint program,
2386 GLint location,
2387 GLenum genMode,
2388 GLint components,
2389 const GLfloat *coeffs)
2390{
2391 auto *programObject = getProgram(program);
2392
Jamie Madillbd044ed2017-06-05 12:59:21 -04002393 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002394}
2395
jchen1015015f72017-03-16 13:54:21 +08002396GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2397{
jchen10fd7c3b52017-03-21 15:36:03 +08002398 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002399 return QueryProgramResourceIndex(programObject, programInterface, name);
2400}
2401
jchen10fd7c3b52017-03-21 15:36:03 +08002402void Context::getProgramResourceName(GLuint program,
2403 GLenum programInterface,
2404 GLuint index,
2405 GLsizei bufSize,
2406 GLsizei *length,
2407 GLchar *name)
2408{
2409 const auto *programObject = getProgram(program);
2410 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2411}
2412
jchen10191381f2017-04-11 13:59:04 +08002413GLint Context::getProgramResourceLocation(GLuint program,
2414 GLenum programInterface,
2415 const GLchar *name)
2416{
2417 const auto *programObject = getProgram(program);
2418 return QueryProgramResourceLocation(programObject, programInterface, name);
2419}
2420
jchen10880683b2017-04-12 16:21:55 +08002421void Context::getProgramResourceiv(GLuint program,
2422 GLenum programInterface,
2423 GLuint index,
2424 GLsizei propCount,
2425 const GLenum *props,
2426 GLsizei bufSize,
2427 GLsizei *length,
2428 GLint *params)
2429{
2430 const auto *programObject = getProgram(program);
2431 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2432 length, params);
2433}
2434
jchen10d9cd7b72017-08-30 15:04:25 +08002435void Context::getProgramInterfaceiv(GLuint program,
2436 GLenum programInterface,
2437 GLenum pname,
2438 GLint *params)
2439{
2440 const auto *programObject = getProgram(program);
2441 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2442}
2443
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002444void Context::getProgramInterfaceivRobust(GLuint program,
2445 GLenum programInterface,
2446 GLenum pname,
2447 GLsizei bufSize,
2448 GLsizei *length,
2449 GLint *params)
2450{
2451 UNIMPLEMENTED();
2452}
2453
Jamie Madill427064d2018-04-13 16:20:34 -04002454void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002455{
Geoff Lang7b19a492018-04-20 09:31:52 -04002456 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002457 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002458 GLenum code = error.getCode();
2459 mErrors.insert(code);
2460 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2461 {
2462 markContextLost();
2463 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002464
Geoff Langee6884e2017-11-09 16:51:11 -05002465 ASSERT(!error.getMessage().empty());
2466 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2467 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002468 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002469}
2470
2471// Get one of the recorded errors and clear its flag, if any.
2472// [OpenGL ES 2.0.24] section 2.5 page 13.
2473GLenum Context::getError()
2474{
Geoff Langda5777c2014-07-11 09:52:58 -04002475 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002476 {
Geoff Langda5777c2014-07-11 09:52:58 -04002477 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002478 }
Geoff Langda5777c2014-07-11 09:52:58 -04002479 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002480 {
Geoff Langda5777c2014-07-11 09:52:58 -04002481 GLenum error = *mErrors.begin();
2482 mErrors.erase(mErrors.begin());
2483 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002484 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485}
2486
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002487// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002488void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002489{
2490 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002491 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002492 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002493 mContextLostForced = true;
2494 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002495 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002496}
2497
Jamie Madill427064d2018-04-13 16:20:34 -04002498bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002499{
2500 return mContextLost;
2501}
2502
Jamie Madillfa920eb2018-01-04 11:45:50 -05002503GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002505 // Even if the application doesn't want to know about resets, we want to know
2506 // as it will allow us to skip all the calls.
2507 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002508 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002509 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002510 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002511 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002512 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513
2514 // EXT_robustness, section 2.6: If the reset notification behavior is
2515 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2516 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2517 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002518 }
2519
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002520 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2521 // status should be returned at least once, and GL_NO_ERROR should be returned
2522 // once the device has finished resetting.
2523 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002524 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002525 ASSERT(mResetStatus == GL_NO_ERROR);
2526 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002527
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002528 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002531 }
2532 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002533 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002534 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002535 // If markContextLost was used to mark the context lost then
2536 // assume that is not recoverable, and continue to report the
2537 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002538 mResetStatus = mImplementation->getResetStatus();
2539 }
Jamie Madill893ab082014-05-16 16:56:10 -04002540
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002541 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002542}
2543
2544bool Context::isResetNotificationEnabled()
2545{
2546 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2547}
2548
Corentin Walleze3b10e82015-05-20 11:06:25 -04002549const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002550{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002551 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002552}
2553
2554EGLenum Context::getClientType() const
2555{
2556 return mClientType;
2557}
2558
2559EGLenum Context::getRenderBuffer() const
2560{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002561 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2562 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002563 {
2564 return EGL_NONE;
2565 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002566
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002567 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002568 ASSERT(backAttachment != nullptr);
2569 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002570}
2571
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002572VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002573{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002574 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002575 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2576 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002577 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002578 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2579 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002580
Jamie Madill96a483b2017-06-27 16:49:21 -04002581 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002582 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002583
2584 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002585}
2586
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002587TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002588{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002589 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002590 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2591 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002592 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002593 transformFeedback =
2594 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002595 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002596 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002597 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002598
2599 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002600}
2601
2602bool Context::isVertexArrayGenerated(GLuint vertexArray)
2603{
Jamie Madill96a483b2017-06-27 16:49:21 -04002604 ASSERT(mVertexArrayMap.contains(0));
2605 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002606}
2607
2608bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2609{
Jamie Madill96a483b2017-06-27 16:49:21 -04002610 ASSERT(mTransformFeedbackMap.contains(0));
2611 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002612}
2613
Shannon Woods53a94a82014-06-24 15:20:36 -04002614void Context::detachTexture(GLuint texture)
2615{
2616 // Simple pass-through to State's detachTexture method, as textures do not require
2617 // allocation map management either here or in the resource manager at detach time.
2618 // Zero textures are held by the Context, and we don't attempt to request them from
2619 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002620 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002621}
2622
James Darpinian4d9d4832018-03-13 12:43:28 -07002623void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624{
Yuly Novikov5807a532015-12-03 13:01:22 -05002625 // Simple pass-through to State's detachBuffer method, since
2626 // only buffer attachments to container objects that are bound to the current context
2627 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002628
Yuly Novikov5807a532015-12-03 13:01:22 -05002629 // [OpenGL ES 3.2] section 5.1.2 page 45:
2630 // Attachments to unbound container objects, such as
2631 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2632 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002633 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002634}
2635
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002636void Context::detachFramebuffer(GLuint framebuffer)
2637{
Shannon Woods53a94a82014-06-24 15:20:36 -04002638 // Framebuffer detachment is handled by Context, because 0 is a valid
2639 // Framebuffer object, and a pointer to it must be passed from Context
2640 // to State at binding time.
2641
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002643 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2644 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2645 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002647 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002648 {
2649 bindReadFramebuffer(0);
2650 }
2651
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002652 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002653 {
2654 bindDrawFramebuffer(0);
2655 }
2656}
2657
2658void Context::detachRenderbuffer(GLuint renderbuffer)
2659{
Jamie Madilla02315b2017-02-23 14:14:47 -05002660 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661}
2662
Jamie Madill57a89722013-07-02 11:57:03 -04002663void Context::detachVertexArray(GLuint vertexArray)
2664{
Jamie Madill77a72f62015-04-14 11:18:32 -04002665 // Vertex array detachment is handled by Context, because 0 is a valid
2666 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002667 // binding time.
2668
Jamie Madill57a89722013-07-02 11:57:03 -04002669 // [OpenGL ES 3.0.2] section 2.10 page 43:
2670 // If a vertex array object that is currently bound is deleted, the binding
2671 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002672 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002673 {
2674 bindVertexArray(0);
2675 }
2676}
2677
Geoff Langc8058452014-02-03 12:04:11 -05002678void Context::detachTransformFeedback(GLuint transformFeedback)
2679{
Corentin Walleza2257da2016-04-19 16:43:12 -04002680 // Transform feedback detachment is handled by Context, because 0 is a valid
2681 // transform feedback, and a pointer to it must be passed from Context to State at
2682 // binding time.
2683
2684 // The OpenGL specification doesn't mention what should happen when the currently bound
2685 // transform feedback object is deleted. Since it is a container object, we treat it like
2686 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002687 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002688 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002689 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002690 }
Geoff Langc8058452014-02-03 12:04:11 -05002691}
2692
Jamie Madilldc356042013-07-19 16:36:57 -04002693void Context::detachSampler(GLuint sampler)
2694{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002695 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002696}
2697
Yunchao Hea336b902017-08-02 16:05:21 +08002698void Context::detachProgramPipeline(GLuint pipeline)
2699{
2700 mGLState.detachProgramPipeline(this, pipeline);
2701}
2702
Jamie Madill3ef140a2017-08-26 23:11:21 -04002703void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002704{
Shaodde78e82017-05-22 14:13:27 +08002705 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002706}
2707
Jamie Madille29d1672013-07-19 16:36:57 -04002708void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2709{
Geoff Langc1984ed2016-10-07 12:41:00 -04002710 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002711 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002712 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002713 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002714}
Jamie Madille29d1672013-07-19 16:36:57 -04002715
Geoff Langc1984ed2016-10-07 12:41:00 -04002716void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2717{
2718 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002719 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002720 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002721 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002722}
2723
Brandon Jones59770802018-04-02 13:18:42 -07002724void Context::samplerParameterivRobust(GLuint sampler,
2725 GLenum pname,
2726 GLsizei bufSize,
2727 const GLint *param)
2728{
2729 samplerParameteriv(sampler, pname, param);
2730}
2731
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002732void Context::samplerParameterIivRobust(GLuint sampler,
2733 GLenum pname,
2734 GLsizei bufSize,
2735 const GLint *param)
2736{
2737 UNIMPLEMENTED();
2738}
2739
2740void Context::samplerParameterIuivRobust(GLuint sampler,
2741 GLenum pname,
2742 GLsizei bufSize,
2743 const GLuint *param)
2744{
2745 UNIMPLEMENTED();
2746}
2747
Jamie Madille29d1672013-07-19 16:36:57 -04002748void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2749{
Geoff Langc1984ed2016-10-07 12:41:00 -04002750 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002751 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002752 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002753 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002754}
2755
Geoff Langc1984ed2016-10-07 12:41:00 -04002756void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002757{
Geoff Langc1984ed2016-10-07 12:41:00 -04002758 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002759 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002760 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002761 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002762}
2763
Brandon Jones59770802018-04-02 13:18:42 -07002764void Context::samplerParameterfvRobust(GLuint sampler,
2765 GLenum pname,
2766 GLsizei bufSize,
2767 const GLfloat *param)
2768{
2769 samplerParameterfv(sampler, pname, param);
2770}
2771
Geoff Langc1984ed2016-10-07 12:41:00 -04002772void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002773{
Geoff Langc1984ed2016-10-07 12:41:00 -04002774 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002775 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002776 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002777 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002778}
Jamie Madill9675b802013-07-19 16:36:59 -04002779
Brandon Jones59770802018-04-02 13:18:42 -07002780void Context::getSamplerParameterivRobust(GLuint sampler,
2781 GLenum pname,
2782 GLsizei bufSize,
2783 GLsizei *length,
2784 GLint *params)
2785{
2786 getSamplerParameteriv(sampler, pname, params);
2787}
2788
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002789void Context::getSamplerParameterIivRobust(GLuint sampler,
2790 GLenum pname,
2791 GLsizei bufSize,
2792 GLsizei *length,
2793 GLint *params)
2794{
2795 UNIMPLEMENTED();
2796}
2797
2798void Context::getSamplerParameterIuivRobust(GLuint sampler,
2799 GLenum pname,
2800 GLsizei bufSize,
2801 GLsizei *length,
2802 GLuint *params)
2803{
2804 UNIMPLEMENTED();
2805}
2806
Geoff Langc1984ed2016-10-07 12:41:00 -04002807void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2808{
2809 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002810 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002811 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002812 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002813}
2814
Brandon Jones59770802018-04-02 13:18:42 -07002815void Context::getSamplerParameterfvRobust(GLuint sampler,
2816 GLenum pname,
2817 GLsizei bufSize,
2818 GLsizei *length,
2819 GLfloat *params)
2820{
2821 getSamplerParameterfv(sampler, pname, params);
2822}
2823
Olli Etuahof0fee072016-03-30 15:11:58 +03002824void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2825{
2826 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002827 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002828}
2829
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002830void Context::initRendererString()
2831{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002832 std::ostringstream rendererString;
2833 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002834 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002835 rendererString << ")";
2836
Geoff Langcec35902014-04-16 10:52:36 -04002837 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002838}
2839
Geoff Langc339c4e2016-11-29 10:37:36 -05002840void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002841{
Geoff Langc339c4e2016-11-29 10:37:36 -05002842 const Version &clientVersion = getClientVersion();
2843
2844 std::ostringstream versionString;
2845 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2846 << ANGLE_VERSION_STRING << ")";
2847 mVersionString = MakeStaticString(versionString.str());
2848
2849 std::ostringstream shadingLanguageVersionString;
2850 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2851 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2852 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2853 << ")";
2854 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855}
2856
Geoff Langcec35902014-04-16 10:52:36 -04002857void Context::initExtensionStrings()
2858{
Geoff Langc339c4e2016-11-29 10:37:36 -05002859 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2860 std::ostringstream combinedStringStream;
2861 std::copy(strings.begin(), strings.end(),
2862 std::ostream_iterator<const char *>(combinedStringStream, " "));
2863 return MakeStaticString(combinedStringStream.str());
2864 };
2865
2866 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002867 for (const auto &extensionString : mExtensions.getStrings())
2868 {
2869 mExtensionStrings.push_back(MakeStaticString(extensionString));
2870 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002871 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002872
Geoff Langc339c4e2016-11-29 10:37:36 -05002873 mRequestableExtensionStrings.clear();
2874 for (const auto &extensionInfo : GetExtensionInfoMap())
2875 {
2876 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002877 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002878 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002879 {
2880 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2881 }
2882 }
2883 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002884}
2885
Geoff Langc339c4e2016-11-29 10:37:36 -05002886const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002887{
Geoff Langc339c4e2016-11-29 10:37:36 -05002888 switch (name)
2889 {
2890 case GL_VENDOR:
2891 return reinterpret_cast<const GLubyte *>("Google Inc.");
2892
2893 case GL_RENDERER:
2894 return reinterpret_cast<const GLubyte *>(mRendererString);
2895
2896 case GL_VERSION:
2897 return reinterpret_cast<const GLubyte *>(mVersionString);
2898
2899 case GL_SHADING_LANGUAGE_VERSION:
2900 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2901
2902 case GL_EXTENSIONS:
2903 return reinterpret_cast<const GLubyte *>(mExtensionString);
2904
2905 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2906 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2907
2908 default:
2909 UNREACHABLE();
2910 return nullptr;
2911 }
Geoff Langcec35902014-04-16 10:52:36 -04002912}
2913
Geoff Langc339c4e2016-11-29 10:37:36 -05002914const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002915{
Geoff Langc339c4e2016-11-29 10:37:36 -05002916 switch (name)
2917 {
2918 case GL_EXTENSIONS:
2919 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2920
2921 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2922 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2923
2924 default:
2925 UNREACHABLE();
2926 return nullptr;
2927 }
Geoff Langcec35902014-04-16 10:52:36 -04002928}
2929
2930size_t Context::getExtensionStringCount() const
2931{
2932 return mExtensionStrings.size();
2933}
2934
Geoff Lang111a99e2017-10-17 10:58:41 -04002935bool Context::isExtensionRequestable(const char *name)
2936{
2937 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2938 auto extension = extensionInfos.find(name);
2939
Geoff Lang111a99e2017-10-17 10:58:41 -04002940 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002941 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002942}
2943
Geoff Langc339c4e2016-11-29 10:37:36 -05002944void Context::requestExtension(const char *name)
2945{
2946 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2947 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2948 const auto &extension = extensionInfos.at(name);
2949 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002950 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002951
2952 if (mExtensions.*(extension.ExtensionsMember))
2953 {
2954 // Extension already enabled
2955 return;
2956 }
2957
2958 mExtensions.*(extension.ExtensionsMember) = true;
2959 updateCaps();
2960 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002961
Jamie Madill2f348d22017-06-05 10:50:59 -04002962 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2963 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002964
Jamie Madill81c2e252017-09-09 23:32:46 -04002965 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2966 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002967 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002968 for (auto &zeroTexture : mZeroTextures)
2969 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002970 if (zeroTexture.get() != nullptr)
2971 {
2972 zeroTexture->signalDirty(this, InitState::Initialized);
2973 }
Geoff Lang9aded172017-04-05 11:07:56 -04002974 }
2975
2976 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002977}
2978
2979size_t Context::getRequestableExtensionStringCount() const
2980{
2981 return mRequestableExtensionStrings.size();
2982}
2983
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002984void Context::beginTransformFeedback(GLenum primitiveMode)
2985{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002986 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002987 ASSERT(transformFeedback != nullptr);
2988 ASSERT(!transformFeedback->isPaused());
2989
Jamie Madill6c1f6712017-02-14 19:08:04 -05002990 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002991}
2992
2993bool Context::hasActiveTransformFeedback(GLuint program) const
2994{
2995 for (auto pair : mTransformFeedbackMap)
2996 {
2997 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2998 {
2999 return true;
3000 }
3001 }
3002 return false;
3003}
3004
Geoff Langb0f917f2017-12-05 13:41:54 -05003005Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
3006 bool robustResourceInit) const
3007{
3008 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3009
3010 if (getClientVersion() < ES_2_0)
3011 {
3012 // Default extensions for GLES1
3013 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003014 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003015 }
3016
3017 if (getClientVersion() < ES_3_0)
3018 {
3019 // Disable ES3+ extensions
3020 supportedExtensions.colorBufferFloat = false;
3021 supportedExtensions.eglImageExternalEssl3 = false;
3022 supportedExtensions.textureNorm16 = false;
3023 supportedExtensions.multiview = false;
3024 supportedExtensions.maxViews = 1u;
3025 }
3026
3027 if (getClientVersion() < ES_3_1)
3028 {
3029 // Disable ES3.1+ extensions
3030 supportedExtensions.geometryShader = false;
3031 }
3032
3033 if (getClientVersion() > ES_2_0)
3034 {
3035 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3036 // supportedExtensions.sRGB = false;
3037 }
3038
3039 // Some extensions are always available because they are implemented in the GL layer.
3040 supportedExtensions.bindUniformLocation = true;
3041 supportedExtensions.vertexArrayObject = true;
3042 supportedExtensions.bindGeneratesResource = true;
3043 supportedExtensions.clientArrays = true;
3044 supportedExtensions.requestExtension = true;
3045
3046 // Enable the no error extension if the context was created with the flag.
3047 supportedExtensions.noError = mSkipValidation;
3048
3049 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3050 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3051
3052 // Explicitly enable GL_KHR_debug
3053 supportedExtensions.debug = true;
3054 supportedExtensions.maxDebugMessageLength = 1024;
3055 supportedExtensions.maxDebugLoggedMessages = 1024;
3056 supportedExtensions.maxDebugGroupStackDepth = 1024;
3057 supportedExtensions.maxLabelLength = 1024;
3058
3059 // Explicitly enable GL_ANGLE_robust_client_memory
3060 supportedExtensions.robustClientMemory = true;
3061
3062 // Determine robust resource init availability from EGL.
3063 supportedExtensions.robustResourceInitialization = robustResourceInit;
3064
3065 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3066 // supports it.
3067 supportedExtensions.robustBufferAccessBehavior =
3068 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3069
3070 // Enable the cache control query unconditionally.
3071 supportedExtensions.programCacheControl = true;
3072
3073 return supportedExtensions;
3074}
3075
Geoff Langb433e872017-10-05 14:01:47 -04003076void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003077{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003078 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003079
Geoff Langb0f917f2017-12-05 13:41:54 -05003080 mSupportedExtensions = generateSupportedExtensions(displayExtensions, robustResourceInit);
3081 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003082
3083 mLimitations = mImplementation->getNativeLimitations();
3084
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003085 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3086 if (getClientVersion() < Version(2, 0))
3087 {
3088 mCaps.maxMultitextureUnits = 4;
3089 mCaps.maxClipPlanes = 6;
3090 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003091 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3092 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3093 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003094 }
3095
Geoff Lang301d1612014-07-09 10:34:37 -04003096 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003097 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003098
Jamie Madill0f80ed82017-09-19 00:24:56 -04003099 if (getClientVersion() < ES_3_1)
3100 {
3101 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3102 }
3103 else
3104 {
3105 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3106 }
Geoff Lang301d1612014-07-09 10:34:37 -04003107
Jamie Madill0f80ed82017-09-19 00:24:56 -04003108 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
3109 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3110 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3111
3112 // Limit textures as well, so we can use fast bitsets with texture bindings.
3113 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3114 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3115 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003116
Jiawei Shaodb342272017-09-27 10:21:45 +08003117 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3118
Geoff Langc287ea62016-09-16 14:46:51 -04003119 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003120 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003121 for (const auto &extensionInfo : GetExtensionInfoMap())
3122 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003123 // If the user has requested that extensions start disabled and they are requestable,
3124 // disable them.
3125 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003126 {
3127 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3128 }
3129 }
3130
3131 // Generate texture caps
3132 updateCaps();
3133}
3134
3135void Context::updateCaps()
3136{
Geoff Lang900013c2014-07-07 11:32:19 -04003137 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003138 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003139
Jamie Madill7b62cf92017-11-02 15:20:49 -04003140 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003141 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003142 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003143 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003144
Geoff Lang0d8b7242015-09-09 14:56:53 -04003145 // Update the format caps based on the client version and extensions.
3146 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3147 // ES3.
3148 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003149 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003150 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003151 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003152 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003153 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003154
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003155 // OpenGL ES does not support multisampling with non-rendererable formats
3156 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003157 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003158 (getClientVersion() < ES_3_1 &&
3159 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003160 {
Geoff Langd87878e2014-09-19 15:42:59 -04003161 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003162 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003163 else
3164 {
3165 // We may have limited the max samples for some required renderbuffer formats due to
3166 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3167 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3168
3169 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3170 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3171 // exception of signed and unsigned integer formats."
3172 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3173 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3174 {
3175 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3176 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3177 }
3178
3179 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3180 if (getClientVersion() >= ES_3_1)
3181 {
3182 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3183 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3184 // the exception that the signed and unsigned integer formats are required only to
3185 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3186 // multisamples, which must be at least one."
3187 if (formatInfo.componentType == GL_INT ||
3188 formatInfo.componentType == GL_UNSIGNED_INT)
3189 {
3190 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3191 }
3192
3193 // GLES 3.1 section 19.3.1.
3194 if (formatCaps.texturable)
3195 {
3196 if (formatInfo.depthBits > 0)
3197 {
3198 mCaps.maxDepthTextureSamples =
3199 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3200 }
3201 else if (formatInfo.redBits > 0)
3202 {
3203 mCaps.maxColorTextureSamples =
3204 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3205 }
3206 }
3207 }
3208 }
Geoff Langd87878e2014-09-19 15:42:59 -04003209
3210 if (formatCaps.texturable && formatInfo.compressed)
3211 {
Geoff Langca271392017-04-05 12:30:00 -04003212 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003213 }
3214
Geoff Langca271392017-04-05 12:30:00 -04003215 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003216 }
Jamie Madill32447362017-06-28 14:53:52 -04003217
3218 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003219 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003220 {
3221 mMemoryProgramCache = nullptr;
3222 }
Corentin Walleze4477002017-12-01 14:39:58 -05003223
3224 // Compute which buffer types are allowed
3225 mValidBufferBindings.reset();
3226 mValidBufferBindings.set(BufferBinding::ElementArray);
3227 mValidBufferBindings.set(BufferBinding::Array);
3228
3229 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3230 {
3231 mValidBufferBindings.set(BufferBinding::PixelPack);
3232 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3233 }
3234
3235 if (getClientVersion() >= ES_3_0)
3236 {
3237 mValidBufferBindings.set(BufferBinding::CopyRead);
3238 mValidBufferBindings.set(BufferBinding::CopyWrite);
3239 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3240 mValidBufferBindings.set(BufferBinding::Uniform);
3241 }
3242
3243 if (getClientVersion() >= ES_3_1)
3244 {
3245 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3246 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3247 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3248 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3249 }
Geoff Lang493daf52014-07-03 13:38:44 -04003250}
3251
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003252void Context::initWorkarounds()
3253{
Jamie Madill761b02c2017-06-23 16:27:06 -04003254 // Apply back-end workarounds.
3255 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3256
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003257 // Lose the context upon out of memory error if the application is
3258 // expecting to watch for those events.
3259 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3260}
3261
Jamie Madill05b35b22017-10-03 09:01:44 -04003262Error Context::prepareForDraw()
3263{
Geoff Langa8cb2872018-03-09 16:09:40 -05003264 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003265
3266 if (isRobustResourceInitEnabled())
3267 {
3268 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3269 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3270 }
3271
Geoff Langa8cb2872018-03-09 16:09:40 -05003272 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003273 return NoError();
3274}
3275
3276Error Context::prepareForClear(GLbitfield mask)
3277{
Geoff Langa8cb2872018-03-09 16:09:40 -05003278 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003279 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003280 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003281 return NoError();
3282}
3283
3284Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3285{
Geoff Langa8cb2872018-03-09 16:09:40 -05003286 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003287 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3288 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003289 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003290 return NoError();
3291}
3292
Geoff Langa8cb2872018-03-09 16:09:40 -05003293Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003294{
Geoff Langa8cb2872018-03-09 16:09:40 -05003295 ANGLE_TRY(syncDirtyObjects());
3296 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003297 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003298}
3299
Geoff Langa8cb2872018-03-09 16:09:40 -05003300Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003301{
Geoff Langa8cb2872018-03-09 16:09:40 -05003302 ANGLE_TRY(syncDirtyObjects(objectMask));
3303 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003304 return NoError();
3305}
3306
Geoff Langa8cb2872018-03-09 16:09:40 -05003307Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003308{
3309 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3310 mImplementation->syncState(this, dirtyBits);
3311 mGLState.clearDirtyBits();
3312 return NoError();
3313}
3314
Geoff Langa8cb2872018-03-09 16:09:40 -05003315Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003316{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003317 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003318 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003319 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003320 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003321}
Jamie Madillc29968b2016-01-20 11:17:23 -05003322
Geoff Langa8cb2872018-03-09 16:09:40 -05003323Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003324{
3325 return mGLState.syncDirtyObjects(this);
3326}
3327
Geoff Langa8cb2872018-03-09 16:09:40 -05003328Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003329{
3330 return mGLState.syncDirtyObjects(this, objectMask);
3331}
3332
Jamie Madillc29968b2016-01-20 11:17:23 -05003333void Context::blitFramebuffer(GLint srcX0,
3334 GLint srcY0,
3335 GLint srcX1,
3336 GLint srcY1,
3337 GLint dstX0,
3338 GLint dstY0,
3339 GLint dstX1,
3340 GLint dstY1,
3341 GLbitfield mask,
3342 GLenum filter)
3343{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003344 if (mask == 0)
3345 {
3346 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3347 // buffers are copied.
3348 return;
3349 }
3350
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003351 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003352 ASSERT(drawFramebuffer);
3353
3354 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3355 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3356
Jamie Madillbc918e72018-03-08 09:47:21 -05003357 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003358
Jamie Madillc564c072017-06-01 12:45:42 -04003359 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003360}
Jamie Madillc29968b2016-01-20 11:17:23 -05003361
3362void Context::clear(GLbitfield mask)
3363{
Geoff Langd4fff502017-09-22 11:28:28 -04003364 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3365 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003366}
3367
3368void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3369{
Geoff Langd4fff502017-09-22 11:28:28 -04003370 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3371 ANGLE_CONTEXT_TRY(
3372 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003373}
3374
3375void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3376{
Geoff Langd4fff502017-09-22 11:28:28 -04003377 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3378 ANGLE_CONTEXT_TRY(
3379 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003380}
3381
3382void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3383{
Geoff Langd4fff502017-09-22 11:28:28 -04003384 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3385 ANGLE_CONTEXT_TRY(
3386 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003387}
3388
3389void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3390{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003391 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003392 ASSERT(framebufferObject);
3393
3394 // If a buffer is not present, the clear has no effect
3395 if (framebufferObject->getDepthbuffer() == nullptr &&
3396 framebufferObject->getStencilbuffer() == nullptr)
3397 {
3398 return;
3399 }
3400
Geoff Langd4fff502017-09-22 11:28:28 -04003401 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3402 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003403}
3404
3405void Context::readPixels(GLint x,
3406 GLint y,
3407 GLsizei width,
3408 GLsizei height,
3409 GLenum format,
3410 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003411 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003412{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003413 if (width == 0 || height == 0)
3414 {
3415 return;
3416 }
3417
Jamie Madillbc918e72018-03-08 09:47:21 -05003418 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003419
Jamie Madillb6664922017-07-25 12:55:04 -04003420 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3421 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003422
3423 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003424 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003425}
3426
Brandon Jones59770802018-04-02 13:18:42 -07003427void Context::readPixelsRobust(GLint x,
3428 GLint y,
3429 GLsizei width,
3430 GLsizei height,
3431 GLenum format,
3432 GLenum type,
3433 GLsizei bufSize,
3434 GLsizei *length,
3435 GLsizei *columns,
3436 GLsizei *rows,
3437 void *pixels)
3438{
3439 readPixels(x, y, width, height, format, type, pixels);
3440}
3441
3442void Context::readnPixelsRobust(GLint x,
3443 GLint y,
3444 GLsizei width,
3445 GLsizei height,
3446 GLenum format,
3447 GLenum type,
3448 GLsizei bufSize,
3449 GLsizei *length,
3450 GLsizei *columns,
3451 GLsizei *rows,
3452 void *data)
3453{
3454 readPixels(x, y, width, height, format, type, data);
3455}
3456
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003457void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003458 GLint level,
3459 GLenum internalformat,
3460 GLint x,
3461 GLint y,
3462 GLsizei width,
3463 GLsizei height,
3464 GLint border)
3465{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003466 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003467 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003468
Jamie Madillc29968b2016-01-20 11:17:23 -05003469 Rectangle sourceArea(x, y, width, height);
3470
Jamie Madill05b35b22017-10-03 09:01:44 -04003471 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003472 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003473 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003474}
3475
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003476void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003477 GLint level,
3478 GLint xoffset,
3479 GLint yoffset,
3480 GLint x,
3481 GLint y,
3482 GLsizei width,
3483 GLsizei height)
3484{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003485 if (width == 0 || height == 0)
3486 {
3487 return;
3488 }
3489
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003490 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003491 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003492
Jamie Madillc29968b2016-01-20 11:17:23 -05003493 Offset destOffset(xoffset, yoffset, 0);
3494 Rectangle sourceArea(x, y, width, height);
3495
Jamie Madill05b35b22017-10-03 09:01:44 -04003496 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003497 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003498 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003499}
3500
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003501void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 GLint level,
3503 GLint xoffset,
3504 GLint yoffset,
3505 GLint zoffset,
3506 GLint x,
3507 GLint y,
3508 GLsizei width,
3509 GLsizei height)
3510{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003511 if (width == 0 || height == 0)
3512 {
3513 return;
3514 }
3515
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003516 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003517 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003518
Jamie Madillc29968b2016-01-20 11:17:23 -05003519 Offset destOffset(xoffset, yoffset, zoffset);
3520 Rectangle sourceArea(x, y, width, height);
3521
Jamie Madill05b35b22017-10-03 09:01:44 -04003522 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3523 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003524 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3525 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003526}
3527
3528void Context::framebufferTexture2D(GLenum target,
3529 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003530 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003531 GLuint texture,
3532 GLint level)
3533{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 ASSERT(framebuffer);
3536
3537 if (texture != 0)
3538 {
3539 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003540 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003541 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003542 }
3543 else
3544 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003545 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003546 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003547
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003548 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
3551void Context::framebufferRenderbuffer(GLenum target,
3552 GLenum attachment,
3553 GLenum renderbuffertarget,
3554 GLuint renderbuffer)
3555{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003556 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 ASSERT(framebuffer);
3558
3559 if (renderbuffer != 0)
3560 {
3561 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003562
Jamie Madillcc129372018-04-12 09:13:18 -04003563 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003564 renderbufferObject);
3565 }
3566 else
3567 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003568 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003569 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003570
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003571 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003572}
3573
3574void Context::framebufferTextureLayer(GLenum target,
3575 GLenum attachment,
3576 GLuint texture,
3577 GLint level,
3578 GLint layer)
3579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003580 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003581 ASSERT(framebuffer);
3582
3583 if (texture != 0)
3584 {
3585 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003586 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003587 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003588 }
3589 else
3590 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003591 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003593
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003594 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003595}
3596
Brandon Jones59770802018-04-02 13:18:42 -07003597void Context::framebufferTextureMultiviewLayered(GLenum target,
3598 GLenum attachment,
3599 GLuint texture,
3600 GLint level,
3601 GLint baseViewIndex,
3602 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003603{
Martin Radev82ef7742017-08-08 17:44:58 +03003604 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3605 ASSERT(framebuffer);
3606
3607 if (texture != 0)
3608 {
3609 Texture *textureObj = getTexture(texture);
3610
Martin Radev18b75ba2017-08-15 15:50:40 +03003611 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003612 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3613 numViews, baseViewIndex);
3614 }
3615 else
3616 {
3617 framebuffer->resetAttachment(this, attachment);
3618 }
3619
3620 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003621}
3622
Brandon Jones59770802018-04-02 13:18:42 -07003623void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3624 GLenum attachment,
3625 GLuint texture,
3626 GLint level,
3627 GLsizei numViews,
3628 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003629{
Martin Radev5dae57b2017-07-14 16:15:55 +03003630 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3631 ASSERT(framebuffer);
3632
3633 if (texture != 0)
3634 {
3635 Texture *textureObj = getTexture(texture);
3636
3637 ImageIndex index = ImageIndex::Make2D(level);
3638 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3639 textureObj, numViews, viewportOffsets);
3640 }
3641 else
3642 {
3643 framebuffer->resetAttachment(this, attachment);
3644 }
3645
3646 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003647}
3648
Jamie Madillc29968b2016-01-20 11:17:23 -05003649void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3650{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003652 ASSERT(framebuffer);
3653 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003655}
3656
3657void Context::readBuffer(GLenum mode)
3658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003662}
3663
3664void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3665{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003666 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003667 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003668
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003669 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 ASSERT(framebuffer);
3671
3672 // The specification isn't clear what should be done when the framebuffer isn't complete.
3673 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003674 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003675}
3676
3677void Context::invalidateFramebuffer(GLenum target,
3678 GLsizei numAttachments,
3679 const GLenum *attachments)
3680{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003681 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003682 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003683
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 ASSERT(framebuffer);
3686
Jamie Madill427064d2018-04-13 16:20:34 -04003687 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003688 {
Jamie Madill437fa652016-05-03 15:13:24 -04003689 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003690 }
Jamie Madill437fa652016-05-03 15:13:24 -04003691
Jamie Madill4928b7c2017-06-20 12:57:39 -04003692 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003693}
3694
3695void Context::invalidateSubFramebuffer(GLenum target,
3696 GLsizei numAttachments,
3697 const GLenum *attachments,
3698 GLint x,
3699 GLint y,
3700 GLsizei width,
3701 GLsizei height)
3702{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003703 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003704 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003705
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 ASSERT(framebuffer);
3708
Jamie Madill427064d2018-04-13 16:20:34 -04003709 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003710 {
Jamie Madill437fa652016-05-03 15:13:24 -04003711 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 }
Jamie Madill437fa652016-05-03 15:13:24 -04003713
3714 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003715 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003716}
3717
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003718void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003719 GLint level,
3720 GLint internalformat,
3721 GLsizei width,
3722 GLsizei height,
3723 GLint border,
3724 GLenum format,
3725 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003726 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003727{
Jamie Madillbc918e72018-03-08 09:47:21 -05003728 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003729
3730 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003731 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003732 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3733 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003734}
3735
Brandon Jones59770802018-04-02 13:18:42 -07003736void Context::texImage2DRobust(TextureTarget target,
3737 GLint level,
3738 GLint internalformat,
3739 GLsizei width,
3740 GLsizei height,
3741 GLint border,
3742 GLenum format,
3743 GLenum type,
3744 GLsizei bufSize,
3745 const void *pixels)
3746{
3747 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3748}
3749
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003750void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003751 GLint level,
3752 GLint internalformat,
3753 GLsizei width,
3754 GLsizei height,
3755 GLsizei depth,
3756 GLint border,
3757 GLenum format,
3758 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003759 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003760{
Jamie Madillbc918e72018-03-08 09:47:21 -05003761 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003762
3763 Extents size(width, height, depth);
3764 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003765 handleError(texture->setImage(this, mGLState.getUnpackState(),
3766 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3767 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003768}
3769
Brandon Jones59770802018-04-02 13:18:42 -07003770void Context::texImage3DRobust(TextureType target,
3771 GLint level,
3772 GLint internalformat,
3773 GLsizei width,
3774 GLsizei height,
3775 GLsizei depth,
3776 GLint border,
3777 GLenum format,
3778 GLenum type,
3779 GLsizei bufSize,
3780 const void *pixels)
3781{
3782 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3783}
3784
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003785void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003786 GLint level,
3787 GLint xoffset,
3788 GLint yoffset,
3789 GLsizei width,
3790 GLsizei height,
3791 GLenum format,
3792 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003793 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003794{
3795 // Zero sized uploads are valid but no-ops
3796 if (width == 0 || height == 0)
3797 {
3798 return;
3799 }
3800
Jamie Madillbc918e72018-03-08 09:47:21 -05003801 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003802
3803 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003804 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003805 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3806 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003807}
3808
Brandon Jones59770802018-04-02 13:18:42 -07003809void Context::texSubImage2DRobust(TextureTarget target,
3810 GLint level,
3811 GLint xoffset,
3812 GLint yoffset,
3813 GLsizei width,
3814 GLsizei height,
3815 GLenum format,
3816 GLenum type,
3817 GLsizei bufSize,
3818 const void *pixels)
3819{
3820 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3821}
3822
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003823void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003824 GLint level,
3825 GLint xoffset,
3826 GLint yoffset,
3827 GLint zoffset,
3828 GLsizei width,
3829 GLsizei height,
3830 GLsizei depth,
3831 GLenum format,
3832 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003833 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003834{
3835 // Zero sized uploads are valid but no-ops
3836 if (width == 0 || height == 0 || depth == 0)
3837 {
3838 return;
3839 }
3840
Jamie Madillbc918e72018-03-08 09:47:21 -05003841 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003842
3843 Box area(xoffset, yoffset, zoffset, width, height, depth);
3844 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003845 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3846 NonCubeTextureTypeToTarget(target), level, area, format, type,
3847 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003848}
3849
Brandon Jones59770802018-04-02 13:18:42 -07003850void Context::texSubImage3DRobust(TextureType target,
3851 GLint level,
3852 GLint xoffset,
3853 GLint yoffset,
3854 GLint zoffset,
3855 GLsizei width,
3856 GLsizei height,
3857 GLsizei depth,
3858 GLenum format,
3859 GLenum type,
3860 GLsizei bufSize,
3861 const void *pixels)
3862{
3863 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3864 pixels);
3865}
3866
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003867void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003868 GLint level,
3869 GLenum internalformat,
3870 GLsizei width,
3871 GLsizei height,
3872 GLint border,
3873 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003874 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003875{
Jamie Madillbc918e72018-03-08 09:47:21 -05003876 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003877
3878 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003879 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003880 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3881 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003882 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003883}
3884
Brandon Jones59770802018-04-02 13:18:42 -07003885void Context::compressedTexImage2DRobust(TextureTarget target,
3886 GLint level,
3887 GLenum internalformat,
3888 GLsizei width,
3889 GLsizei height,
3890 GLint border,
3891 GLsizei imageSize,
3892 GLsizei dataSize,
3893 const GLvoid *data)
3894{
3895 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3896}
3897
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003898void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003899 GLint level,
3900 GLenum internalformat,
3901 GLsizei width,
3902 GLsizei height,
3903 GLsizei depth,
3904 GLint border,
3905 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003906 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003907{
Jamie Madillbc918e72018-03-08 09:47:21 -05003908 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003909
3910 Extents size(width, height, depth);
3911 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003912 handleError(texture->setCompressedImage(
3913 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3914 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003915}
3916
Brandon Jones59770802018-04-02 13:18:42 -07003917void Context::compressedTexImage3DRobust(TextureType target,
3918 GLint level,
3919 GLenum internalformat,
3920 GLsizei width,
3921 GLsizei height,
3922 GLsizei depth,
3923 GLint border,
3924 GLsizei imageSize,
3925 GLsizei dataSize,
3926 const GLvoid *data)
3927{
3928 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3929 data);
3930}
3931
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003932void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003933 GLint level,
3934 GLint xoffset,
3935 GLint yoffset,
3936 GLsizei width,
3937 GLsizei height,
3938 GLenum format,
3939 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003940 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003941{
Jamie Madillbc918e72018-03-08 09:47:21 -05003942 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003943
3944 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003945 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003946 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3947 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003949}
3950
Brandon Jones59770802018-04-02 13:18:42 -07003951void Context::compressedTexSubImage2DRobust(TextureTarget target,
3952 GLint level,
3953 GLint xoffset,
3954 GLint yoffset,
3955 GLsizei width,
3956 GLsizei height,
3957 GLenum format,
3958 GLsizei imageSize,
3959 GLsizei dataSize,
3960 const GLvoid *data)
3961{
3962 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3963 data);
3964}
3965
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003966void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003967 GLint level,
3968 GLint xoffset,
3969 GLint yoffset,
3970 GLint zoffset,
3971 GLsizei width,
3972 GLsizei height,
3973 GLsizei depth,
3974 GLenum format,
3975 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003976 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003977{
3978 // Zero sized uploads are valid but no-ops
3979 if (width == 0 || height == 0)
3980 {
3981 return;
3982 }
3983
Jamie Madillbc918e72018-03-08 09:47:21 -05003984 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003985
3986 Box area(xoffset, yoffset, zoffset, width, height, depth);
3987 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003988 handleError(texture->setCompressedSubImage(
3989 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3990 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003991}
3992
Brandon Jones59770802018-04-02 13:18:42 -07003993void Context::compressedTexSubImage3DRobust(TextureType target,
3994 GLint level,
3995 GLint xoffset,
3996 GLint yoffset,
3997 GLint zoffset,
3998 GLsizei width,
3999 GLsizei height,
4000 GLsizei depth,
4001 GLenum format,
4002 GLsizei imageSize,
4003 GLsizei dataSize,
4004 const GLvoid *data)
4005{
4006 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4007 imageSize, data);
4008}
4009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004011{
4012 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004013 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004014}
4015
Jamie Madill007530e2017-12-28 14:27:04 -05004016void Context::copyTexture(GLuint sourceId,
4017 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004018 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004019 GLuint destId,
4020 GLint destLevel,
4021 GLint internalFormat,
4022 GLenum destType,
4023 GLboolean unpackFlipY,
4024 GLboolean unpackPremultiplyAlpha,
4025 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004026{
Jamie Madillbc918e72018-03-08 09:47:21 -05004027 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004028
4029 gl::Texture *sourceTexture = getTexture(sourceId);
4030 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004031 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4032 sourceLevel, ConvertToBool(unpackFlipY),
4033 ConvertToBool(unpackPremultiplyAlpha),
4034 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004035}
4036
Jamie Madill007530e2017-12-28 14:27:04 -05004037void Context::copySubTexture(GLuint sourceId,
4038 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004039 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004040 GLuint destId,
4041 GLint destLevel,
4042 GLint xoffset,
4043 GLint yoffset,
4044 GLint x,
4045 GLint y,
4046 GLsizei width,
4047 GLsizei height,
4048 GLboolean unpackFlipY,
4049 GLboolean unpackPremultiplyAlpha,
4050 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004051{
4052 // Zero sized copies are valid but no-ops
4053 if (width == 0 || height == 0)
4054 {
4055 return;
4056 }
4057
Jamie Madillbc918e72018-03-08 09:47:21 -05004058 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004059
4060 gl::Texture *sourceTexture = getTexture(sourceId);
4061 gl::Texture *destTexture = getTexture(destId);
4062 Offset offset(xoffset, yoffset, 0);
4063 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004064 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4065 ConvertToBool(unpackFlipY),
4066 ConvertToBool(unpackPremultiplyAlpha),
4067 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004068}
4069
Jamie Madill007530e2017-12-28 14:27:04 -05004070void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004071{
Jamie Madillbc918e72018-03-08 09:47:21 -05004072 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004073
4074 gl::Texture *sourceTexture = getTexture(sourceId);
4075 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004076 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004077}
4078
Corentin Wallez336129f2017-10-17 15:55:40 -04004079void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004080{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004081 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004082 ASSERT(buffer);
4083
Geoff Lang496c02d2016-10-20 11:38:11 -07004084 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004085}
4086
Brandon Jones59770802018-04-02 13:18:42 -07004087void Context::getBufferPointervRobust(BufferBinding target,
4088 GLenum pname,
4089 GLsizei bufSize,
4090 GLsizei *length,
4091 void **params)
4092{
4093 getBufferPointerv(target, pname, params);
4094}
4095
Corentin Wallez336129f2017-10-17 15:55:40 -04004096void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004097{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004098 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004099 ASSERT(buffer);
4100
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004101 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004102 if (error.isError())
4103 {
Jamie Madill437fa652016-05-03 15:13:24 -04004104 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004105 return nullptr;
4106 }
4107
4108 return buffer->getMapPointer();
4109}
4110
Corentin Wallez336129f2017-10-17 15:55:40 -04004111GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004112{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004113 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004114 ASSERT(buffer);
4115
4116 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004117 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004118 if (error.isError())
4119 {
Jamie Madill437fa652016-05-03 15:13:24 -04004120 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004121 return GL_FALSE;
4122 }
4123
4124 return result;
4125}
4126
Corentin Wallez336129f2017-10-17 15:55:40 -04004127void *Context::mapBufferRange(BufferBinding target,
4128 GLintptr offset,
4129 GLsizeiptr length,
4130 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004131{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004132 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004133 ASSERT(buffer);
4134
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004135 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004136 if (error.isError())
4137 {
Jamie Madill437fa652016-05-03 15:13:24 -04004138 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004139 return nullptr;
4140 }
4141
4142 return buffer->getMapPointer();
4143}
4144
Corentin Wallez336129f2017-10-17 15:55:40 -04004145void Context::flushMappedBufferRange(BufferBinding /*target*/,
4146 GLintptr /*offset*/,
4147 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004148{
4149 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4150}
4151
Jamie Madillbc918e72018-03-08 09:47:21 -05004152Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004153{
Geoff Langa8cb2872018-03-09 16:09:40 -05004154 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004155}
4156
Jamie Madillbc918e72018-03-08 09:47:21 -05004157Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004158{
Geoff Langa8cb2872018-03-09 16:09:40 -05004159 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004160}
4161
Jamie Madillbc918e72018-03-08 09:47:21 -05004162Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004163{
Geoff Langa8cb2872018-03-09 16:09:40 -05004164 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004165}
4166
Jiajia Qin5451d532017-11-16 17:16:34 +08004167void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4168{
4169 UNIMPLEMENTED();
4170}
4171
Jamie Madillc20ab272016-06-09 07:20:46 -07004172void Context::activeTexture(GLenum texture)
4173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004174 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004175}
4176
Jamie Madill876429b2017-04-20 15:46:24 -04004177void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004178{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004179 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004180}
4181
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004182void Context::blendEquation(GLenum mode)
4183{
4184 mGLState.setBlendEquation(mode, mode);
4185}
4186
Jamie Madillc20ab272016-06-09 07:20:46 -07004187void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4188{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004189 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004190}
4191
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004192void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4193{
4194 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4195}
4196
Jamie Madillc20ab272016-06-09 07:20:46 -07004197void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4198{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004199 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004200}
4201
Jamie Madill876429b2017-04-20 15:46:24 -04004202void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004204 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004205}
4206
Jamie Madill876429b2017-04-20 15:46:24 -04004207void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004208{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004209 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004210}
4211
4212void Context::clearStencil(GLint s)
4213{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004214 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004215}
4216
4217void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4218{
Geoff Lang92019432017-11-20 13:09:34 -05004219 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4220 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004221}
4222
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004223void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004224{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004225 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004226}
4227
4228void Context::depthFunc(GLenum func)
4229{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004230 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004231}
4232
4233void Context::depthMask(GLboolean flag)
4234{
Geoff Lang92019432017-11-20 13:09:34 -05004235 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004236}
4237
Jamie Madill876429b2017-04-20 15:46:24 -04004238void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004239{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004240 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004241}
4242
4243void Context::disable(GLenum cap)
4244{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004245 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004246}
4247
4248void Context::disableVertexAttribArray(GLuint index)
4249{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004250 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004251}
4252
4253void Context::enable(GLenum cap)
4254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004256}
4257
4258void Context::enableVertexAttribArray(GLuint index)
4259{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004260 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004261}
4262
4263void Context::frontFace(GLenum mode)
4264{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004265 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004266}
4267
4268void Context::hint(GLenum target, GLenum mode)
4269{
4270 switch (target)
4271 {
4272 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004273 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004274 break;
4275
4276 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004278 break;
4279
4280 default:
4281 UNREACHABLE();
4282 return;
4283 }
4284}
4285
4286void Context::lineWidth(GLfloat width)
4287{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004288 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004289}
4290
4291void Context::pixelStorei(GLenum pname, GLint param)
4292{
4293 switch (pname)
4294 {
4295 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004297 break;
4298
4299 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004300 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004301 break;
4302
4303 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305 break;
4306
4307 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004308 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004309 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004310 break;
4311
4312 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004313 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004314 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004315 break;
4316
4317 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004318 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004319 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004320 break;
4321
4322 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004323 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004324 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004325 break;
4326
4327 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004328 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004330 break;
4331
4332 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004333 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004335 break;
4336
4337 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004338 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340 break;
4341
4342 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004343 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345 break;
4346
4347 default:
4348 UNREACHABLE();
4349 return;
4350 }
4351}
4352
4353void Context::polygonOffset(GLfloat factor, GLfloat units)
4354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356}
4357
Jamie Madill876429b2017-04-20 15:46:24 -04004358void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004359{
Geoff Lang92019432017-11-20 13:09:34 -05004360 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004361}
4362
Jiawei Shaodb342272017-09-27 10:21:45 +08004363void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4364{
4365 mGLState.setSampleMaskParams(maskNumber, mask);
4366}
4367
Jamie Madillc20ab272016-06-09 07:20:46 -07004368void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4369{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004370 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004371}
4372
4373void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4374{
4375 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4376 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378 }
4379
4380 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4381 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383 }
4384}
4385
4386void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4387{
4388 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4389 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004390 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004391 }
4392
4393 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4394 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004395 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004396 }
4397}
4398
4399void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4400{
4401 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4402 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004403 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004404 }
4405
4406 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4407 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004408 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004409 }
4410}
4411
4412void Context::vertexAttrib1f(GLuint index, GLfloat x)
4413{
4414 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004415 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004416}
4417
4418void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4419{
4420 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422}
4423
4424void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4425{
4426 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004427 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428}
4429
4430void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4431{
4432 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4437{
4438 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004439 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004440}
4441
4442void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4443{
4444 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
4448void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4449{
4450 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004451 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
4454void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
4459void Context::vertexAttribPointer(GLuint index,
4460 GLint size,
4461 GLenum type,
4462 GLboolean normalized,
4463 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004464 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004465{
Corentin Wallez336129f2017-10-17 15:55:40 -04004466 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004467 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468}
4469
Shao80957d92017-02-20 21:25:59 +08004470void Context::vertexAttribFormat(GLuint attribIndex,
4471 GLint size,
4472 GLenum type,
4473 GLboolean normalized,
4474 GLuint relativeOffset)
4475{
Geoff Lang92019432017-11-20 13:09:34 -05004476 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004477 relativeOffset);
4478}
4479
4480void Context::vertexAttribIFormat(GLuint attribIndex,
4481 GLint size,
4482 GLenum type,
4483 GLuint relativeOffset)
4484{
4485 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4486}
4487
4488void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4489{
Shaodde78e82017-05-22 14:13:27 +08004490 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004491}
4492
Jiajia Qin5451d532017-11-16 17:16:34 +08004493void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004494{
4495 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4496}
4497
Jamie Madillc20ab272016-06-09 07:20:46 -07004498void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::vertexAttribIPointer(GLuint index,
4504 GLint size,
4505 GLenum type,
4506 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004507 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004508{
Corentin Wallez336129f2017-10-17 15:55:40 -04004509 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4510 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4514{
4515 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4520{
4521 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
4525void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4526{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004527 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004528}
4529
4530void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4531{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004532 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533}
4534
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004535void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4536{
4537 const VertexAttribCurrentValueData &currentValues =
4538 getGLState().getVertexAttribCurrentValue(index);
4539 const VertexArray *vao = getGLState().getVertexArray();
4540 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4541 currentValues, pname, params);
4542}
4543
Brandon Jones59770802018-04-02 13:18:42 -07004544void Context::getVertexAttribivRobust(GLuint index,
4545 GLenum pname,
4546 GLsizei bufSize,
4547 GLsizei *length,
4548 GLint *params)
4549{
4550 getVertexAttribiv(index, pname, params);
4551}
4552
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004553void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4554{
4555 const VertexAttribCurrentValueData &currentValues =
4556 getGLState().getVertexAttribCurrentValue(index);
4557 const VertexArray *vao = getGLState().getVertexArray();
4558 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4559 currentValues, pname, params);
4560}
4561
Brandon Jones59770802018-04-02 13:18:42 -07004562void Context::getVertexAttribfvRobust(GLuint index,
4563 GLenum pname,
4564 GLsizei bufSize,
4565 GLsizei *length,
4566 GLfloat *params)
4567{
4568 getVertexAttribfv(index, pname, params);
4569}
4570
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004571void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4572{
4573 const VertexAttribCurrentValueData &currentValues =
4574 getGLState().getVertexAttribCurrentValue(index);
4575 const VertexArray *vao = getGLState().getVertexArray();
4576 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4577 currentValues, pname, params);
4578}
4579
Brandon Jones59770802018-04-02 13:18:42 -07004580void Context::getVertexAttribIivRobust(GLuint index,
4581 GLenum pname,
4582 GLsizei bufSize,
4583 GLsizei *length,
4584 GLint *params)
4585{
4586 getVertexAttribIiv(index, pname, params);
4587}
4588
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004589void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4590{
4591 const VertexAttribCurrentValueData &currentValues =
4592 getGLState().getVertexAttribCurrentValue(index);
4593 const VertexArray *vao = getGLState().getVertexArray();
4594 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4595 currentValues, pname, params);
4596}
4597
Brandon Jones59770802018-04-02 13:18:42 -07004598void Context::getVertexAttribIuivRobust(GLuint index,
4599 GLenum pname,
4600 GLsizei bufSize,
4601 GLsizei *length,
4602 GLuint *params)
4603{
4604 getVertexAttribIuiv(index, pname, params);
4605}
4606
Jamie Madill876429b2017-04-20 15:46:24 -04004607void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004608{
4609 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4610 QueryVertexAttribPointerv(attrib, pname, pointer);
4611}
4612
Brandon Jones59770802018-04-02 13:18:42 -07004613void Context::getVertexAttribPointervRobust(GLuint index,
4614 GLenum pname,
4615 GLsizei bufSize,
4616 GLsizei *length,
4617 void **pointer)
4618{
4619 getVertexAttribPointerv(index, pname, pointer);
4620}
4621
Jamie Madillc20ab272016-06-09 07:20:46 -07004622void Context::debugMessageControl(GLenum source,
4623 GLenum type,
4624 GLenum severity,
4625 GLsizei count,
4626 const GLuint *ids,
4627 GLboolean enabled)
4628{
4629 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004631 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004632}
4633
4634void Context::debugMessageInsert(GLenum source,
4635 GLenum type,
4636 GLuint id,
4637 GLenum severity,
4638 GLsizei length,
4639 const GLchar *buf)
4640{
4641 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004642 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004643}
4644
4645void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4646{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004647 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648}
4649
4650GLuint Context::getDebugMessageLog(GLuint count,
4651 GLsizei bufSize,
4652 GLenum *sources,
4653 GLenum *types,
4654 GLuint *ids,
4655 GLenum *severities,
4656 GLsizei *lengths,
4657 GLchar *messageLog)
4658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004659 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4660 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004661}
4662
4663void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4664{
4665 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004666 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004667 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::popDebugGroup()
4671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004673 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
Corentin Wallez336129f2017-10-17 15:55:40 -04004676void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004677{
4678 Buffer *buffer = mGLState.getTargetBuffer(target);
4679 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004680 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004681}
4682
Corentin Wallez336129f2017-10-17 15:55:40 -04004683void Context::bufferSubData(BufferBinding target,
4684 GLintptr offset,
4685 GLsizeiptr size,
4686 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004687{
4688 if (data == nullptr)
4689 {
4690 return;
4691 }
4692
4693 Buffer *buffer = mGLState.getTargetBuffer(target);
4694 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004695 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004696}
4697
Jamie Madillef300b12016-10-07 15:12:09 -04004698void Context::attachShader(GLuint program, GLuint shader)
4699{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004700 Program *programObject = mState.mShaderPrograms->getProgram(program);
4701 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004702 ASSERT(programObject && shaderObject);
4703 programObject->attachShader(shaderObject);
4704}
4705
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004706const Workarounds &Context::getWorkarounds() const
4707{
4708 return mWorkarounds;
4709}
4710
Corentin Wallez336129f2017-10-17 15:55:40 -04004711void Context::copyBufferSubData(BufferBinding readTarget,
4712 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004713 GLintptr readOffset,
4714 GLintptr writeOffset,
4715 GLsizeiptr size)
4716{
4717 // if size is zero, the copy is a successful no-op
4718 if (size == 0)
4719 {
4720 return;
4721 }
4722
4723 // TODO(jmadill): cache these.
4724 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4725 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4726
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004727 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004728}
4729
Jamie Madill01a80ee2016-11-07 12:06:18 -05004730void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4731{
4732 Program *programObject = getProgram(program);
4733 // TODO(jmadill): Re-use this from the validation if possible.
4734 ASSERT(programObject);
4735 programObject->bindAttributeLocation(index, name);
4736}
4737
Corentin Wallez336129f2017-10-17 15:55:40 -04004738void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004739{
Corentin Wallez336129f2017-10-17 15:55:40 -04004740 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4741 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004742}
4743
Corentin Wallez336129f2017-10-17 15:55:40 -04004744void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004745{
4746 bindBufferRange(target, index, buffer, 0, 0);
4747}
4748
Corentin Wallez336129f2017-10-17 15:55:40 -04004749void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004750 GLuint index,
4751 GLuint buffer,
4752 GLintptr offset,
4753 GLsizeiptr size)
4754{
Corentin Wallez336129f2017-10-17 15:55:40 -04004755 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4756 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004757}
4758
Jamie Madill01a80ee2016-11-07 12:06:18 -05004759void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4760{
4761 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4762 {
4763 bindReadFramebuffer(framebuffer);
4764 }
4765
4766 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4767 {
4768 bindDrawFramebuffer(framebuffer);
4769 }
4770}
4771
4772void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4773{
4774 ASSERT(target == GL_RENDERBUFFER);
4775 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004776 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004777 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004778}
4779
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004780void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004781 GLsizei samples,
4782 GLenum internalformat,
4783 GLsizei width,
4784 GLsizei height,
4785 GLboolean fixedsamplelocations)
4786{
4787 Extents size(width, height, 1);
4788 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004789 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4790 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004791}
4792
4793void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4794{
JiangYizhou5b03f472017-01-09 10:22:53 +08004795 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4796 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004797 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004798 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004799
4800 switch (pname)
4801 {
4802 case GL_SAMPLE_POSITION:
4803 handleError(framebuffer->getSamplePosition(index, val));
4804 break;
4805 default:
4806 UNREACHABLE();
4807 }
4808}
4809
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004810void Context::getMultisamplefvRobust(GLenum pname,
4811 GLuint index,
4812 GLsizei bufSize,
4813 GLsizei *length,
4814 GLfloat *val)
4815{
4816 UNIMPLEMENTED();
4817}
4818
Jamie Madille8fb6402017-02-14 17:56:40 -05004819void Context::renderbufferStorage(GLenum target,
4820 GLenum internalformat,
4821 GLsizei width,
4822 GLsizei height)
4823{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004824 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4825 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4826
Jamie Madille8fb6402017-02-14 17:56:40 -05004827 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004828 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004829}
4830
4831void Context::renderbufferStorageMultisample(GLenum target,
4832 GLsizei samples,
4833 GLenum internalformat,
4834 GLsizei width,
4835 GLsizei height)
4836{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004837 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4838 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004839
4840 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004841 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004842 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004843}
4844
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004845void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4846{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004847 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004848 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004849}
4850
JiangYizhoue18e6392017-02-20 10:32:23 +08004851void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4852{
4853 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4854 QueryFramebufferParameteriv(framebuffer, pname, params);
4855}
4856
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004857void Context::getFramebufferParameterivRobust(GLenum target,
4858 GLenum pname,
4859 GLsizei bufSize,
4860 GLsizei *length,
4861 GLint *params)
4862{
4863 UNIMPLEMENTED();
4864}
4865
Jiajia Qin5451d532017-11-16 17:16:34 +08004866void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004867{
4868 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4869 SetFramebufferParameteri(framebuffer, pname, param);
4870}
4871
Jamie Madillb3f26b92017-07-19 15:07:41 -04004872Error Context::getScratchBuffer(size_t requstedSizeBytes,
4873 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004874{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004875 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4876 {
4877 return OutOfMemory() << "Failed to allocate internal buffer.";
4878 }
4879 return NoError();
4880}
4881
4882Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4883 angle::MemoryBuffer **zeroBufferOut) const
4884{
4885 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004886 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004887 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004888 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004889 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004890}
4891
Xinghua Cao10a4d432017-11-28 14:46:26 +08004892Error Context::prepareForDispatch()
4893{
Geoff Langa8cb2872018-03-09 16:09:40 -05004894 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004895
4896 if (isRobustResourceInitEnabled())
4897 {
4898 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4899 }
4900
4901 return NoError();
4902}
4903
Xinghua Cao2b396592017-03-29 15:36:04 +08004904void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4905{
4906 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4907 {
4908 return;
4909 }
4910
Xinghua Cao10a4d432017-11-28 14:46:26 +08004911 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004912 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004913}
4914
Jiajia Qin5451d532017-11-16 17:16:34 +08004915void Context::dispatchComputeIndirect(GLintptr indirect)
4916{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004917 ANGLE_CONTEXT_TRY(prepareForDispatch());
4918 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004919}
4920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004921void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004922 GLsizei levels,
4923 GLenum internalFormat,
4924 GLsizei width,
4925 GLsizei height)
4926{
4927 Extents size(width, height, 1);
4928 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004929 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004930}
4931
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004932void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004933 GLsizei levels,
4934 GLenum internalFormat,
4935 GLsizei width,
4936 GLsizei height,
4937 GLsizei depth)
4938{
4939 Extents size(width, height, depth);
4940 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004941 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004942}
4943
Jiajia Qin5451d532017-11-16 17:16:34 +08004944void Context::memoryBarrier(GLbitfield barriers)
4945{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004946 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004947}
4948
4949void Context::memoryBarrierByRegion(GLbitfield barriers)
4950{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004951 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004952}
4953
Jamie Madillc1d770e2017-04-13 17:31:24 -04004954GLenum Context::checkFramebufferStatus(GLenum target)
4955{
4956 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4957 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004958 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004959}
4960
4961void Context::compileShader(GLuint shader)
4962{
4963 Shader *shaderObject = GetValidShader(this, shader);
4964 if (!shaderObject)
4965 {
4966 return;
4967 }
4968 shaderObject->compile(this);
4969}
4970
4971void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4972{
4973 for (int i = 0; i < n; i++)
4974 {
4975 deleteBuffer(buffers[i]);
4976 }
4977}
4978
4979void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4980{
4981 for (int i = 0; i < n; i++)
4982 {
4983 if (framebuffers[i] != 0)
4984 {
4985 deleteFramebuffer(framebuffers[i]);
4986 }
4987 }
4988}
4989
4990void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4991{
4992 for (int i = 0; i < n; i++)
4993 {
4994 deleteRenderbuffer(renderbuffers[i]);
4995 }
4996}
4997
4998void Context::deleteTextures(GLsizei n, const GLuint *textures)
4999{
5000 for (int i = 0; i < n; i++)
5001 {
5002 if (textures[i] != 0)
5003 {
5004 deleteTexture(textures[i]);
5005 }
5006 }
5007}
5008
5009void Context::detachShader(GLuint program, GLuint shader)
5010{
5011 Program *programObject = getProgram(program);
5012 ASSERT(programObject);
5013
5014 Shader *shaderObject = getShader(shader);
5015 ASSERT(shaderObject);
5016
5017 programObject->detachShader(this, shaderObject);
5018}
5019
5020void Context::genBuffers(GLsizei n, GLuint *buffers)
5021{
5022 for (int i = 0; i < n; i++)
5023 {
5024 buffers[i] = createBuffer();
5025 }
5026}
5027
5028void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5029{
5030 for (int i = 0; i < n; i++)
5031 {
5032 framebuffers[i] = createFramebuffer();
5033 }
5034}
5035
5036void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5037{
5038 for (int i = 0; i < n; i++)
5039 {
5040 renderbuffers[i] = createRenderbuffer();
5041 }
5042}
5043
5044void Context::genTextures(GLsizei n, GLuint *textures)
5045{
5046 for (int i = 0; i < n; i++)
5047 {
5048 textures[i] = createTexture();
5049 }
5050}
5051
5052void Context::getActiveAttrib(GLuint program,
5053 GLuint index,
5054 GLsizei bufsize,
5055 GLsizei *length,
5056 GLint *size,
5057 GLenum *type,
5058 GLchar *name)
5059{
5060 Program *programObject = getProgram(program);
5061 ASSERT(programObject);
5062 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5063}
5064
5065void Context::getActiveUniform(GLuint program,
5066 GLuint index,
5067 GLsizei bufsize,
5068 GLsizei *length,
5069 GLint *size,
5070 GLenum *type,
5071 GLchar *name)
5072{
5073 Program *programObject = getProgram(program);
5074 ASSERT(programObject);
5075 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5076}
5077
5078void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5079{
5080 Program *programObject = getProgram(program);
5081 ASSERT(programObject);
5082 programObject->getAttachedShaders(maxcount, count, shaders);
5083}
5084
5085GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5086{
5087 Program *programObject = getProgram(program);
5088 ASSERT(programObject);
5089 return programObject->getAttributeLocation(name);
5090}
5091
5092void Context::getBooleanv(GLenum pname, GLboolean *params)
5093{
5094 GLenum nativeType;
5095 unsigned int numParams = 0;
5096 getQueryParameterInfo(pname, &nativeType, &numParams);
5097
5098 if (nativeType == GL_BOOL)
5099 {
5100 getBooleanvImpl(pname, params);
5101 }
5102 else
5103 {
5104 CastStateValues(this, nativeType, pname, numParams, params);
5105 }
5106}
5107
Brandon Jones59770802018-04-02 13:18:42 -07005108void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5109{
5110 getBooleanv(pname, params);
5111}
5112
Jamie Madillc1d770e2017-04-13 17:31:24 -04005113void Context::getFloatv(GLenum pname, GLfloat *params)
5114{
5115 GLenum nativeType;
5116 unsigned int numParams = 0;
5117 getQueryParameterInfo(pname, &nativeType, &numParams);
5118
5119 if (nativeType == GL_FLOAT)
5120 {
5121 getFloatvImpl(pname, params);
5122 }
5123 else
5124 {
5125 CastStateValues(this, nativeType, pname, numParams, params);
5126 }
5127}
5128
Brandon Jones59770802018-04-02 13:18:42 -07005129void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5130{
5131 getFloatv(pname, params);
5132}
5133
Jamie Madillc1d770e2017-04-13 17:31:24 -04005134void Context::getIntegerv(GLenum pname, GLint *params)
5135{
5136 GLenum nativeType;
5137 unsigned int numParams = 0;
5138 getQueryParameterInfo(pname, &nativeType, &numParams);
5139
5140 if (nativeType == GL_INT)
5141 {
5142 getIntegervImpl(pname, params);
5143 }
5144 else
5145 {
5146 CastStateValues(this, nativeType, pname, numParams, params);
5147 }
5148}
5149
Brandon Jones59770802018-04-02 13:18:42 -07005150void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5151{
5152 getIntegerv(pname, data);
5153}
5154
Jamie Madillc1d770e2017-04-13 17:31:24 -04005155void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5156{
5157 Program *programObject = getProgram(program);
5158 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005159 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005160}
5161
Brandon Jones59770802018-04-02 13:18:42 -07005162void Context::getProgramivRobust(GLuint program,
5163 GLenum pname,
5164 GLsizei bufSize,
5165 GLsizei *length,
5166 GLint *params)
5167{
5168 getProgramiv(program, pname, params);
5169}
5170
Jiajia Qin5451d532017-11-16 17:16:34 +08005171void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5172{
5173 UNIMPLEMENTED();
5174}
5175
Jamie Madillbe849e42017-05-02 15:49:00 -04005176void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005177{
5178 Program *programObject = getProgram(program);
5179 ASSERT(programObject);
5180 programObject->getInfoLog(bufsize, length, infolog);
5181}
5182
Jiajia Qin5451d532017-11-16 17:16:34 +08005183void Context::getProgramPipelineInfoLog(GLuint pipeline,
5184 GLsizei bufSize,
5185 GLsizei *length,
5186 GLchar *infoLog)
5187{
5188 UNIMPLEMENTED();
5189}
5190
Jamie Madillc1d770e2017-04-13 17:31:24 -04005191void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5192{
5193 Shader *shaderObject = getShader(shader);
5194 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005195 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005196}
5197
Brandon Jones59770802018-04-02 13:18:42 -07005198void Context::getShaderivRobust(GLuint shader,
5199 GLenum pname,
5200 GLsizei bufSize,
5201 GLsizei *length,
5202 GLint *params)
5203{
5204 getShaderiv(shader, pname, params);
5205}
5206
Jamie Madillc1d770e2017-04-13 17:31:24 -04005207void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5208{
5209 Shader *shaderObject = getShader(shader);
5210 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005211 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005212}
5213
5214void Context::getShaderPrecisionFormat(GLenum shadertype,
5215 GLenum precisiontype,
5216 GLint *range,
5217 GLint *precision)
5218{
5219 // TODO(jmadill): Compute shaders.
5220
5221 switch (shadertype)
5222 {
5223 case GL_VERTEX_SHADER:
5224 switch (precisiontype)
5225 {
5226 case GL_LOW_FLOAT:
5227 mCaps.vertexLowpFloat.get(range, precision);
5228 break;
5229 case GL_MEDIUM_FLOAT:
5230 mCaps.vertexMediumpFloat.get(range, precision);
5231 break;
5232 case GL_HIGH_FLOAT:
5233 mCaps.vertexHighpFloat.get(range, precision);
5234 break;
5235
5236 case GL_LOW_INT:
5237 mCaps.vertexLowpInt.get(range, precision);
5238 break;
5239 case GL_MEDIUM_INT:
5240 mCaps.vertexMediumpInt.get(range, precision);
5241 break;
5242 case GL_HIGH_INT:
5243 mCaps.vertexHighpInt.get(range, precision);
5244 break;
5245
5246 default:
5247 UNREACHABLE();
5248 return;
5249 }
5250 break;
5251
5252 case GL_FRAGMENT_SHADER:
5253 switch (precisiontype)
5254 {
5255 case GL_LOW_FLOAT:
5256 mCaps.fragmentLowpFloat.get(range, precision);
5257 break;
5258 case GL_MEDIUM_FLOAT:
5259 mCaps.fragmentMediumpFloat.get(range, precision);
5260 break;
5261 case GL_HIGH_FLOAT:
5262 mCaps.fragmentHighpFloat.get(range, precision);
5263 break;
5264
5265 case GL_LOW_INT:
5266 mCaps.fragmentLowpInt.get(range, precision);
5267 break;
5268 case GL_MEDIUM_INT:
5269 mCaps.fragmentMediumpInt.get(range, precision);
5270 break;
5271 case GL_HIGH_INT:
5272 mCaps.fragmentHighpInt.get(range, precision);
5273 break;
5274
5275 default:
5276 UNREACHABLE();
5277 return;
5278 }
5279 break;
5280
5281 default:
5282 UNREACHABLE();
5283 return;
5284 }
5285}
5286
5287void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5288{
5289 Shader *shaderObject = getShader(shader);
5290 ASSERT(shaderObject);
5291 shaderObject->getSource(bufsize, length, source);
5292}
5293
5294void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5295{
5296 Program *programObject = getProgram(program);
5297 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005298 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005299}
5300
Brandon Jones59770802018-04-02 13:18:42 -07005301void Context::getUniformfvRobust(GLuint program,
5302 GLint location,
5303 GLsizei bufSize,
5304 GLsizei *length,
5305 GLfloat *params)
5306{
5307 getUniformfv(program, location, params);
5308}
5309
Jamie Madillc1d770e2017-04-13 17:31:24 -04005310void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5311{
5312 Program *programObject = getProgram(program);
5313 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005314 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005315}
5316
Brandon Jones59770802018-04-02 13:18:42 -07005317void Context::getUniformivRobust(GLuint program,
5318 GLint location,
5319 GLsizei bufSize,
5320 GLsizei *length,
5321 GLint *params)
5322{
5323 getUniformiv(program, location, params);
5324}
5325
Jamie Madillc1d770e2017-04-13 17:31:24 -04005326GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5327{
5328 Program *programObject = getProgram(program);
5329 ASSERT(programObject);
5330 return programObject->getUniformLocation(name);
5331}
5332
5333GLboolean Context::isBuffer(GLuint buffer)
5334{
5335 if (buffer == 0)
5336 {
5337 return GL_FALSE;
5338 }
5339
5340 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5341}
5342
5343GLboolean Context::isEnabled(GLenum cap)
5344{
5345 return mGLState.getEnableFeature(cap);
5346}
5347
5348GLboolean Context::isFramebuffer(GLuint framebuffer)
5349{
5350 if (framebuffer == 0)
5351 {
5352 return GL_FALSE;
5353 }
5354
5355 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5356}
5357
5358GLboolean Context::isProgram(GLuint program)
5359{
5360 if (program == 0)
5361 {
5362 return GL_FALSE;
5363 }
5364
5365 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5366}
5367
5368GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5369{
5370 if (renderbuffer == 0)
5371 {
5372 return GL_FALSE;
5373 }
5374
5375 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5376}
5377
5378GLboolean Context::isShader(GLuint shader)
5379{
5380 if (shader == 0)
5381 {
5382 return GL_FALSE;
5383 }
5384
5385 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5386}
5387
5388GLboolean Context::isTexture(GLuint texture)
5389{
5390 if (texture == 0)
5391 {
5392 return GL_FALSE;
5393 }
5394
5395 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5396}
5397
5398void Context::linkProgram(GLuint program)
5399{
5400 Program *programObject = getProgram(program);
5401 ASSERT(programObject);
5402 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005403 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005404}
5405
5406void Context::releaseShaderCompiler()
5407{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005408 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005409}
5410
5411void Context::shaderBinary(GLsizei n,
5412 const GLuint *shaders,
5413 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005414 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005415 GLsizei length)
5416{
5417 // No binary shader formats are supported.
5418 UNIMPLEMENTED();
5419}
5420
5421void Context::shaderSource(GLuint shader,
5422 GLsizei count,
5423 const GLchar *const *string,
5424 const GLint *length)
5425{
5426 Shader *shaderObject = getShader(shader);
5427 ASSERT(shaderObject);
5428 shaderObject->setSource(count, string, length);
5429}
5430
5431void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5432{
5433 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5434}
5435
5436void Context::stencilMask(GLuint mask)
5437{
5438 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5439}
5440
5441void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5442{
5443 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5444}
5445
5446void Context::uniform1f(GLint location, GLfloat x)
5447{
5448 Program *program = mGLState.getProgram();
5449 program->setUniform1fv(location, 1, &x);
5450}
5451
5452void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5453{
5454 Program *program = mGLState.getProgram();
5455 program->setUniform1fv(location, count, v);
5456}
5457
5458void Context::uniform1i(GLint location, GLint x)
5459{
5460 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005461 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5462 {
5463 mGLState.setObjectDirty(GL_PROGRAM);
5464 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465}
5466
5467void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5468{
5469 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005470 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5471 {
5472 mGLState.setObjectDirty(GL_PROGRAM);
5473 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474}
5475
5476void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5477{
5478 GLfloat xy[2] = {x, y};
5479 Program *program = mGLState.getProgram();
5480 program->setUniform2fv(location, 1, xy);
5481}
5482
5483void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5484{
5485 Program *program = mGLState.getProgram();
5486 program->setUniform2fv(location, count, v);
5487}
5488
5489void Context::uniform2i(GLint location, GLint x, GLint y)
5490{
5491 GLint xy[2] = {x, y};
5492 Program *program = mGLState.getProgram();
5493 program->setUniform2iv(location, 1, xy);
5494}
5495
5496void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5497{
5498 Program *program = mGLState.getProgram();
5499 program->setUniform2iv(location, count, v);
5500}
5501
5502void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5503{
5504 GLfloat xyz[3] = {x, y, z};
5505 Program *program = mGLState.getProgram();
5506 program->setUniform3fv(location, 1, xyz);
5507}
5508
5509void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5510{
5511 Program *program = mGLState.getProgram();
5512 program->setUniform3fv(location, count, v);
5513}
5514
5515void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5516{
5517 GLint xyz[3] = {x, y, z};
5518 Program *program = mGLState.getProgram();
5519 program->setUniform3iv(location, 1, xyz);
5520}
5521
5522void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5523{
5524 Program *program = mGLState.getProgram();
5525 program->setUniform3iv(location, count, v);
5526}
5527
5528void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5529{
5530 GLfloat xyzw[4] = {x, y, z, w};
5531 Program *program = mGLState.getProgram();
5532 program->setUniform4fv(location, 1, xyzw);
5533}
5534
5535void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5536{
5537 Program *program = mGLState.getProgram();
5538 program->setUniform4fv(location, count, v);
5539}
5540
5541void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5542{
5543 GLint xyzw[4] = {x, y, z, w};
5544 Program *program = mGLState.getProgram();
5545 program->setUniform4iv(location, 1, xyzw);
5546}
5547
5548void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5549{
5550 Program *program = mGLState.getProgram();
5551 program->setUniform4iv(location, count, v);
5552}
5553
5554void Context::uniformMatrix2fv(GLint location,
5555 GLsizei count,
5556 GLboolean transpose,
5557 const GLfloat *value)
5558{
5559 Program *program = mGLState.getProgram();
5560 program->setUniformMatrix2fv(location, count, transpose, value);
5561}
5562
5563void Context::uniformMatrix3fv(GLint location,
5564 GLsizei count,
5565 GLboolean transpose,
5566 const GLfloat *value)
5567{
5568 Program *program = mGLState.getProgram();
5569 program->setUniformMatrix3fv(location, count, transpose, value);
5570}
5571
5572void Context::uniformMatrix4fv(GLint location,
5573 GLsizei count,
5574 GLboolean transpose,
5575 const GLfloat *value)
5576{
5577 Program *program = mGLState.getProgram();
5578 program->setUniformMatrix4fv(location, count, transpose, value);
5579}
5580
5581void Context::validateProgram(GLuint program)
5582{
5583 Program *programObject = getProgram(program);
5584 ASSERT(programObject);
5585 programObject->validate(mCaps);
5586}
5587
Jiajia Qin5451d532017-11-16 17:16:34 +08005588void Context::validateProgramPipeline(GLuint pipeline)
5589{
5590 UNIMPLEMENTED();
5591}
5592
Jamie Madilld04908b2017-06-09 14:15:35 -04005593void Context::getProgramBinary(GLuint program,
5594 GLsizei bufSize,
5595 GLsizei *length,
5596 GLenum *binaryFormat,
5597 void *binary)
5598{
5599 Program *programObject = getProgram(program);
5600 ASSERT(programObject != nullptr);
5601
5602 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5603}
5604
5605void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005609
Jamie Madilld04908b2017-06-09 14:15:35 -04005610 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5611}
5612
Jamie Madillff325f12017-08-26 15:06:05 -04005613void Context::uniform1ui(GLint location, GLuint v0)
5614{
5615 Program *program = mGLState.getProgram();
5616 program->setUniform1uiv(location, 1, &v0);
5617}
5618
5619void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5620{
5621 Program *program = mGLState.getProgram();
5622 const GLuint xy[] = {v0, v1};
5623 program->setUniform2uiv(location, 1, xy);
5624}
5625
5626void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5627{
5628 Program *program = mGLState.getProgram();
5629 const GLuint xyz[] = {v0, v1, v2};
5630 program->setUniform3uiv(location, 1, xyz);
5631}
5632
5633void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5634{
5635 Program *program = mGLState.getProgram();
5636 const GLuint xyzw[] = {v0, v1, v2, v3};
5637 program->setUniform4uiv(location, 1, xyzw);
5638}
5639
5640void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5641{
5642 Program *program = mGLState.getProgram();
5643 program->setUniform1uiv(location, count, value);
5644}
5645void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5646{
5647 Program *program = mGLState.getProgram();
5648 program->setUniform2uiv(location, count, value);
5649}
5650
5651void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5652{
5653 Program *program = mGLState.getProgram();
5654 program->setUniform3uiv(location, count, value);
5655}
5656
5657void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5658{
5659 Program *program = mGLState.getProgram();
5660 program->setUniform4uiv(location, count, value);
5661}
5662
Jamie Madillf0e04492017-08-26 15:28:42 -04005663void Context::genQueries(GLsizei n, GLuint *ids)
5664{
5665 for (GLsizei i = 0; i < n; i++)
5666 {
5667 GLuint handle = mQueryHandleAllocator.allocate();
5668 mQueryMap.assign(handle, nullptr);
5669 ids[i] = handle;
5670 }
5671}
5672
5673void Context::deleteQueries(GLsizei n, const GLuint *ids)
5674{
5675 for (int i = 0; i < n; i++)
5676 {
5677 GLuint query = ids[i];
5678
5679 Query *queryObject = nullptr;
5680 if (mQueryMap.erase(query, &queryObject))
5681 {
5682 mQueryHandleAllocator.release(query);
5683 if (queryObject)
5684 {
5685 queryObject->release(this);
5686 }
5687 }
5688 }
5689}
5690
5691GLboolean Context::isQuery(GLuint id)
5692{
5693 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5694}
5695
Jamie Madillc8c95812017-08-26 18:40:09 -04005696void Context::uniformMatrix2x3fv(GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniformMatrix2x3fv(location, count, transpose, value);
5703}
5704
5705void Context::uniformMatrix3x2fv(GLint location,
5706 GLsizei count,
5707 GLboolean transpose,
5708 const GLfloat *value)
5709{
5710 Program *program = mGLState.getProgram();
5711 program->setUniformMatrix3x2fv(location, count, transpose, value);
5712}
5713
5714void Context::uniformMatrix2x4fv(GLint location,
5715 GLsizei count,
5716 GLboolean transpose,
5717 const GLfloat *value)
5718{
5719 Program *program = mGLState.getProgram();
5720 program->setUniformMatrix2x4fv(location, count, transpose, value);
5721}
5722
5723void Context::uniformMatrix4x2fv(GLint location,
5724 GLsizei count,
5725 GLboolean transpose,
5726 const GLfloat *value)
5727{
5728 Program *program = mGLState.getProgram();
5729 program->setUniformMatrix4x2fv(location, count, transpose, value);
5730}
5731
5732void Context::uniformMatrix3x4fv(GLint location,
5733 GLsizei count,
5734 GLboolean transpose,
5735 const GLfloat *value)
5736{
5737 Program *program = mGLState.getProgram();
5738 program->setUniformMatrix3x4fv(location, count, transpose, value);
5739}
5740
5741void Context::uniformMatrix4x3fv(GLint location,
5742 GLsizei count,
5743 GLboolean transpose,
5744 const GLfloat *value)
5745{
5746 Program *program = mGLState.getProgram();
5747 program->setUniformMatrix4x3fv(location, count, transpose, value);
5748}
5749
Jamie Madilld7576732017-08-26 18:49:50 -04005750void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5751{
5752 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5753 {
5754 GLuint vertexArray = arrays[arrayIndex];
5755
5756 if (arrays[arrayIndex] != 0)
5757 {
5758 VertexArray *vertexArrayObject = nullptr;
5759 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5760 {
5761 if (vertexArrayObject != nullptr)
5762 {
5763 detachVertexArray(vertexArray);
5764 vertexArrayObject->onDestroy(this);
5765 }
5766
5767 mVertexArrayHandleAllocator.release(vertexArray);
5768 }
5769 }
5770 }
5771}
5772
5773void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5774{
5775 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5776 {
5777 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5778 mVertexArrayMap.assign(vertexArray, nullptr);
5779 arrays[arrayIndex] = vertexArray;
5780 }
5781}
5782
5783bool Context::isVertexArray(GLuint array)
5784{
5785 if (array == 0)
5786 {
5787 return GL_FALSE;
5788 }
5789
5790 VertexArray *vao = getVertexArray(array);
5791 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5792}
5793
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005794void Context::endTransformFeedback()
5795{
5796 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5797 transformFeedback->end(this);
5798}
5799
5800void Context::transformFeedbackVaryings(GLuint program,
5801 GLsizei count,
5802 const GLchar *const *varyings,
5803 GLenum bufferMode)
5804{
5805 Program *programObject = getProgram(program);
5806 ASSERT(programObject);
5807 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5808}
5809
5810void Context::getTransformFeedbackVarying(GLuint program,
5811 GLuint index,
5812 GLsizei bufSize,
5813 GLsizei *length,
5814 GLsizei *size,
5815 GLenum *type,
5816 GLchar *name)
5817{
5818 Program *programObject = getProgram(program);
5819 ASSERT(programObject);
5820 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5821}
5822
5823void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5824{
5825 for (int i = 0; i < n; i++)
5826 {
5827 GLuint transformFeedback = ids[i];
5828 if (transformFeedback == 0)
5829 {
5830 continue;
5831 }
5832
5833 TransformFeedback *transformFeedbackObject = nullptr;
5834 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5835 {
5836 if (transformFeedbackObject != nullptr)
5837 {
5838 detachTransformFeedback(transformFeedback);
5839 transformFeedbackObject->release(this);
5840 }
5841
5842 mTransformFeedbackHandleAllocator.release(transformFeedback);
5843 }
5844 }
5845}
5846
5847void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5848{
5849 for (int i = 0; i < n; i++)
5850 {
5851 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5852 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5853 ids[i] = transformFeedback;
5854 }
5855}
5856
5857bool Context::isTransformFeedback(GLuint id)
5858{
5859 if (id == 0)
5860 {
5861 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5862 // returns FALSE
5863 return GL_FALSE;
5864 }
5865
5866 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5867 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5868}
5869
5870void Context::pauseTransformFeedback()
5871{
5872 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5873 transformFeedback->pause();
5874}
5875
5876void Context::resumeTransformFeedback()
5877{
5878 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5879 transformFeedback->resume();
5880}
5881
Jamie Madill12e957f2017-08-26 21:42:26 -04005882void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5883{
5884 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005885 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005886}
5887
Brandon Jones59770802018-04-02 13:18:42 -07005888void Context::getUniformuivRobust(GLuint program,
5889 GLint location,
5890 GLsizei bufSize,
5891 GLsizei *length,
5892 GLuint *params)
5893{
5894 getUniformuiv(program, location, params);
5895}
5896
Jamie Madill12e957f2017-08-26 21:42:26 -04005897GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5898{
5899 const Program *programObject = getProgram(program);
5900 return programObject->getFragDataLocation(name);
5901}
5902
5903void Context::getUniformIndices(GLuint program,
5904 GLsizei uniformCount,
5905 const GLchar *const *uniformNames,
5906 GLuint *uniformIndices)
5907{
5908 const Program *programObject = getProgram(program);
5909 if (!programObject->isLinked())
5910 {
5911 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5912 {
5913 uniformIndices[uniformId] = GL_INVALID_INDEX;
5914 }
5915 }
5916 else
5917 {
5918 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5919 {
5920 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5921 }
5922 }
5923}
5924
5925void Context::getActiveUniformsiv(GLuint program,
5926 GLsizei uniformCount,
5927 const GLuint *uniformIndices,
5928 GLenum pname,
5929 GLint *params)
5930{
5931 const Program *programObject = getProgram(program);
5932 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5933 {
5934 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005935 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005936 }
5937}
5938
5939GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5940{
5941 const Program *programObject = getProgram(program);
5942 return programObject->getUniformBlockIndex(uniformBlockName);
5943}
5944
5945void Context::getActiveUniformBlockiv(GLuint program,
5946 GLuint uniformBlockIndex,
5947 GLenum pname,
5948 GLint *params)
5949{
5950 const Program *programObject = getProgram(program);
5951 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5952}
5953
Brandon Jones59770802018-04-02 13:18:42 -07005954void Context::getActiveUniformBlockivRobust(GLuint program,
5955 GLuint uniformBlockIndex,
5956 GLenum pname,
5957 GLsizei bufSize,
5958 GLsizei *length,
5959 GLint *params)
5960{
5961 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5962}
5963
Jamie Madill12e957f2017-08-26 21:42:26 -04005964void Context::getActiveUniformBlockName(GLuint program,
5965 GLuint uniformBlockIndex,
5966 GLsizei bufSize,
5967 GLsizei *length,
5968 GLchar *uniformBlockName)
5969{
5970 const Program *programObject = getProgram(program);
5971 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5972}
5973
5974void Context::uniformBlockBinding(GLuint program,
5975 GLuint uniformBlockIndex,
5976 GLuint uniformBlockBinding)
5977{
5978 Program *programObject = getProgram(program);
5979 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5980}
5981
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005982GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5983{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005984 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5985 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005986
Jamie Madill70b5bb02017-08-28 13:32:37 -04005987 Sync *syncObject = getSync(syncHandle);
5988 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005989 if (error.isError())
5990 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005991 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005992 handleError(error);
5993 return nullptr;
5994 }
5995
Jamie Madill70b5bb02017-08-28 13:32:37 -04005996 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005997}
5998
5999GLboolean Context::isSync(GLsync sync)
6000{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006001 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006002}
6003
6004GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6005{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006006 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006007
6008 GLenum result = GL_WAIT_FAILED;
6009 handleError(syncObject->clientWait(flags, timeout, &result));
6010 return result;
6011}
6012
6013void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6014{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006015 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006016 handleError(syncObject->serverWait(flags, timeout));
6017}
6018
6019void Context::getInteger64v(GLenum pname, GLint64 *params)
6020{
6021 GLenum nativeType = GL_NONE;
6022 unsigned int numParams = 0;
6023 getQueryParameterInfo(pname, &nativeType, &numParams);
6024
6025 if (nativeType == GL_INT_64_ANGLEX)
6026 {
6027 getInteger64vImpl(pname, params);
6028 }
6029 else
6030 {
6031 CastStateValues(this, nativeType, pname, numParams, params);
6032 }
6033}
6034
Brandon Jones59770802018-04-02 13:18:42 -07006035void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6036{
6037 getInteger64v(pname, data);
6038}
6039
Corentin Wallez336129f2017-10-17 15:55:40 -04006040void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006041{
6042 Buffer *buffer = mGLState.getTargetBuffer(target);
6043 QueryBufferParameteri64v(buffer, pname, params);
6044}
6045
Brandon Jones59770802018-04-02 13:18:42 -07006046void Context::getBufferParameteri64vRobust(BufferBinding target,
6047 GLenum pname,
6048 GLsizei bufSize,
6049 GLsizei *length,
6050 GLint64 *params)
6051{
6052 getBufferParameteri64v(target, pname, params);
6053}
6054
Jamie Madill3ef140a2017-08-26 23:11:21 -04006055void Context::genSamplers(GLsizei count, GLuint *samplers)
6056{
6057 for (int i = 0; i < count; i++)
6058 {
6059 samplers[i] = mState.mSamplers->createSampler();
6060 }
6061}
6062
6063void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6064{
6065 for (int i = 0; i < count; i++)
6066 {
6067 GLuint sampler = samplers[i];
6068
6069 if (mState.mSamplers->getSampler(sampler))
6070 {
6071 detachSampler(sampler);
6072 }
6073
6074 mState.mSamplers->deleteObject(this, sampler);
6075 }
6076}
6077
6078void Context::getInternalformativ(GLenum target,
6079 GLenum internalformat,
6080 GLenum pname,
6081 GLsizei bufSize,
6082 GLint *params)
6083{
6084 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6085 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6086}
6087
Brandon Jones59770802018-04-02 13:18:42 -07006088void Context::getInternalformativRobust(GLenum target,
6089 GLenum internalformat,
6090 GLenum pname,
6091 GLsizei bufSize,
6092 GLsizei *length,
6093 GLint *params)
6094{
6095 getInternalformativ(target, internalformat, pname, bufSize, params);
6096}
6097
Jiajia Qin5451d532017-11-16 17:16:34 +08006098void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6099{
6100 programUniform1iv(program, location, 1, &v0);
6101}
6102
6103void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6104{
6105 GLint xy[2] = {v0, v1};
6106 programUniform2iv(program, location, 1, xy);
6107}
6108
6109void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6110{
6111 GLint xyz[3] = {v0, v1, v2};
6112 programUniform3iv(program, location, 1, xyz);
6113}
6114
6115void Context::programUniform4i(GLuint program,
6116 GLint location,
6117 GLint v0,
6118 GLint v1,
6119 GLint v2,
6120 GLint v3)
6121{
6122 GLint xyzw[4] = {v0, v1, v2, v3};
6123 programUniform4iv(program, location, 1, xyzw);
6124}
6125
6126void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6127{
6128 programUniform1uiv(program, location, 1, &v0);
6129}
6130
6131void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6132{
6133 GLuint xy[2] = {v0, v1};
6134 programUniform2uiv(program, location, 1, xy);
6135}
6136
6137void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6138{
6139 GLuint xyz[3] = {v0, v1, v2};
6140 programUniform3uiv(program, location, 1, xyz);
6141}
6142
6143void Context::programUniform4ui(GLuint program,
6144 GLint location,
6145 GLuint v0,
6146 GLuint v1,
6147 GLuint v2,
6148 GLuint v3)
6149{
6150 GLuint xyzw[4] = {v0, v1, v2, v3};
6151 programUniform4uiv(program, location, 1, xyzw);
6152}
6153
6154void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6155{
6156 programUniform1fv(program, location, 1, &v0);
6157}
6158
6159void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6160{
6161 GLfloat xy[2] = {v0, v1};
6162 programUniform2fv(program, location, 1, xy);
6163}
6164
6165void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6166{
6167 GLfloat xyz[3] = {v0, v1, v2};
6168 programUniform3fv(program, location, 1, xyz);
6169}
6170
6171void Context::programUniform4f(GLuint program,
6172 GLint location,
6173 GLfloat v0,
6174 GLfloat v1,
6175 GLfloat v2,
6176 GLfloat v3)
6177{
6178 GLfloat xyzw[4] = {v0, v1, v2, v3};
6179 programUniform4fv(program, location, 1, xyzw);
6180}
6181
Jamie Madill81c2e252017-09-09 23:32:46 -04006182void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6183{
6184 Program *programObject = getProgram(program);
6185 ASSERT(programObject);
6186 if (programObject->setUniform1iv(location, count, value) ==
6187 Program::SetUniformResult::SamplerChanged)
6188 {
6189 mGLState.setObjectDirty(GL_PROGRAM);
6190 }
6191}
6192
Jiajia Qin5451d532017-11-16 17:16:34 +08006193void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6194{
6195 Program *programObject = getProgram(program);
6196 ASSERT(programObject);
6197 programObject->setUniform2iv(location, count, value);
6198}
6199
6200void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6201{
6202 Program *programObject = getProgram(program);
6203 ASSERT(programObject);
6204 programObject->setUniform3iv(location, count, value);
6205}
6206
6207void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6208{
6209 Program *programObject = getProgram(program);
6210 ASSERT(programObject);
6211 programObject->setUniform4iv(location, count, value);
6212}
6213
6214void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6215{
6216 Program *programObject = getProgram(program);
6217 ASSERT(programObject);
6218 programObject->setUniform1uiv(location, count, value);
6219}
6220
6221void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6222{
6223 Program *programObject = getProgram(program);
6224 ASSERT(programObject);
6225 programObject->setUniform2uiv(location, count, value);
6226}
6227
6228void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6229{
6230 Program *programObject = getProgram(program);
6231 ASSERT(programObject);
6232 programObject->setUniform3uiv(location, count, value);
6233}
6234
6235void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6236{
6237 Program *programObject = getProgram(program);
6238 ASSERT(programObject);
6239 programObject->setUniform4uiv(location, count, value);
6240}
6241
6242void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6243{
6244 Program *programObject = getProgram(program);
6245 ASSERT(programObject);
6246 programObject->setUniform1fv(location, count, value);
6247}
6248
6249void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6250{
6251 Program *programObject = getProgram(program);
6252 ASSERT(programObject);
6253 programObject->setUniform2fv(location, count, value);
6254}
6255
6256void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6257{
6258 Program *programObject = getProgram(program);
6259 ASSERT(programObject);
6260 programObject->setUniform3fv(location, count, value);
6261}
6262
6263void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6264{
6265 Program *programObject = getProgram(program);
6266 ASSERT(programObject);
6267 programObject->setUniform4fv(location, count, value);
6268}
6269
6270void Context::programUniformMatrix2fv(GLuint program,
6271 GLint location,
6272 GLsizei count,
6273 GLboolean transpose,
6274 const GLfloat *value)
6275{
6276 Program *programObject = getProgram(program);
6277 ASSERT(programObject);
6278 programObject->setUniformMatrix2fv(location, count, transpose, value);
6279}
6280
6281void Context::programUniformMatrix3fv(GLuint program,
6282 GLint location,
6283 GLsizei count,
6284 GLboolean transpose,
6285 const GLfloat *value)
6286{
6287 Program *programObject = getProgram(program);
6288 ASSERT(programObject);
6289 programObject->setUniformMatrix3fv(location, count, transpose, value);
6290}
6291
6292void Context::programUniformMatrix4fv(GLuint program,
6293 GLint location,
6294 GLsizei count,
6295 GLboolean transpose,
6296 const GLfloat *value)
6297{
6298 Program *programObject = getProgram(program);
6299 ASSERT(programObject);
6300 programObject->setUniformMatrix4fv(location, count, transpose, value);
6301}
6302
6303void Context::programUniformMatrix2x3fv(GLuint program,
6304 GLint location,
6305 GLsizei count,
6306 GLboolean transpose,
6307 const GLfloat *value)
6308{
6309 Program *programObject = getProgram(program);
6310 ASSERT(programObject);
6311 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6312}
6313
6314void Context::programUniformMatrix3x2fv(GLuint program,
6315 GLint location,
6316 GLsizei count,
6317 GLboolean transpose,
6318 const GLfloat *value)
6319{
6320 Program *programObject = getProgram(program);
6321 ASSERT(programObject);
6322 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6323}
6324
6325void Context::programUniformMatrix2x4fv(GLuint program,
6326 GLint location,
6327 GLsizei count,
6328 GLboolean transpose,
6329 const GLfloat *value)
6330{
6331 Program *programObject = getProgram(program);
6332 ASSERT(programObject);
6333 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6334}
6335
6336void Context::programUniformMatrix4x2fv(GLuint program,
6337 GLint location,
6338 GLsizei count,
6339 GLboolean transpose,
6340 const GLfloat *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6345}
6346
6347void Context::programUniformMatrix3x4fv(GLuint program,
6348 GLint location,
6349 GLsizei count,
6350 GLboolean transpose,
6351 const GLfloat *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6356}
6357
6358void Context::programUniformMatrix4x3fv(GLuint program,
6359 GLint location,
6360 GLsizei count,
6361 GLboolean transpose,
6362 const GLfloat *value)
6363{
6364 Program *programObject = getProgram(program);
6365 ASSERT(programObject);
6366 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6367}
6368
Jamie Madill81c2e252017-09-09 23:32:46 -04006369void Context::onTextureChange(const Texture *texture)
6370{
6371 // Conservatively assume all textures are dirty.
6372 // TODO(jmadill): More fine-grained update.
6373 mGLState.setObjectDirty(GL_TEXTURE);
6374}
6375
James Darpiniane8a93c62018-01-04 18:02:24 -08006376bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6377{
6378 return mGLState.isCurrentTransformFeedback(tf);
6379}
6380bool Context::isCurrentVertexArray(const VertexArray *va) const
6381{
6382 return mGLState.isCurrentVertexArray(va);
6383}
6384
Yunchao Hea336b902017-08-02 16:05:21 +08006385void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6386{
6387 for (int i = 0; i < count; i++)
6388 {
6389 pipelines[i] = createProgramPipeline();
6390 }
6391}
6392
6393void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6394{
6395 for (int i = 0; i < count; i++)
6396 {
6397 if (pipelines[i] != 0)
6398 {
6399 deleteProgramPipeline(pipelines[i]);
6400 }
6401 }
6402}
6403
6404GLboolean Context::isProgramPipeline(GLuint pipeline)
6405{
6406 if (pipeline == 0)
6407 {
6408 return GL_FALSE;
6409 }
6410
6411 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6412}
6413
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006414void Context::finishFenceNV(GLuint fence)
6415{
6416 FenceNV *fenceObject = getFenceNV(fence);
6417
6418 ASSERT(fenceObject && fenceObject->isSet());
6419 handleError(fenceObject->finish());
6420}
6421
6422void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6423{
6424 FenceNV *fenceObject = getFenceNV(fence);
6425
6426 ASSERT(fenceObject && fenceObject->isSet());
6427
6428 switch (pname)
6429 {
6430 case GL_FENCE_STATUS_NV:
6431 {
6432 // GL_NV_fence spec:
6433 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6434 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6435 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6436 GLboolean status = GL_TRUE;
6437 if (fenceObject->getStatus() != GL_TRUE)
6438 {
6439 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6440 }
6441 *params = status;
6442 break;
6443 }
6444
6445 case GL_FENCE_CONDITION_NV:
6446 {
6447 *params = static_cast<GLint>(fenceObject->getCondition());
6448 break;
6449 }
6450
6451 default:
6452 UNREACHABLE();
6453 }
6454}
6455
6456void Context::getTranslatedShaderSource(GLuint shader,
6457 GLsizei bufsize,
6458 GLsizei *length,
6459 GLchar *source)
6460{
6461 Shader *shaderObject = getShader(shader);
6462 ASSERT(shaderObject);
6463 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6464}
6465
6466void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6467{
6468 Program *programObject = getProgram(program);
6469 ASSERT(programObject);
6470
6471 programObject->getUniformfv(this, location, params);
6472}
6473
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006474void Context::getnUniformfvRobust(GLuint program,
6475 GLint location,
6476 GLsizei bufSize,
6477 GLsizei *length,
6478 GLfloat *params)
6479{
6480 UNIMPLEMENTED();
6481}
6482
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006483void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6484{
6485 Program *programObject = getProgram(program);
6486 ASSERT(programObject);
6487
6488 programObject->getUniformiv(this, location, params);
6489}
6490
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006491void Context::getnUniformivRobust(GLuint program,
6492 GLint location,
6493 GLsizei bufSize,
6494 GLsizei *length,
6495 GLint *params)
6496{
6497 UNIMPLEMENTED();
6498}
6499
6500void Context::getnUniformuivRobust(GLuint program,
6501 GLint location,
6502 GLsizei bufSize,
6503 GLsizei *length,
6504 GLuint *params)
6505{
6506 UNIMPLEMENTED();
6507}
6508
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006509GLboolean Context::isFenceNV(GLuint fence)
6510{
6511 FenceNV *fenceObject = getFenceNV(fence);
6512
6513 if (fenceObject == nullptr)
6514 {
6515 return GL_FALSE;
6516 }
6517
6518 // GL_NV_fence spec:
6519 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6520 // existing fence.
6521 return fenceObject->isSet();
6522}
6523
6524void Context::readnPixels(GLint x,
6525 GLint y,
6526 GLsizei width,
6527 GLsizei height,
6528 GLenum format,
6529 GLenum type,
6530 GLsizei bufSize,
6531 void *data)
6532{
6533 return readPixels(x, y, width, height, format, type, data);
6534}
6535
Jamie Madill007530e2017-12-28 14:27:04 -05006536void Context::setFenceNV(GLuint fence, GLenum condition)
6537{
6538 ASSERT(condition == GL_ALL_COMPLETED_NV);
6539
6540 FenceNV *fenceObject = getFenceNV(fence);
6541 ASSERT(fenceObject != nullptr);
6542 handleError(fenceObject->set(condition));
6543}
6544
6545GLboolean Context::testFenceNV(GLuint fence)
6546{
6547 FenceNV *fenceObject = getFenceNV(fence);
6548
6549 ASSERT(fenceObject != nullptr);
6550 ASSERT(fenceObject->isSet() == GL_TRUE);
6551
6552 GLboolean result = GL_TRUE;
6553 Error error = fenceObject->test(&result);
6554 if (error.isError())
6555 {
6556 handleError(error);
6557 return GL_TRUE;
6558 }
6559
6560 return result;
6561}
6562
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006563void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006564{
6565 Texture *texture = getTargetTexture(target);
6566 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006567 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006568}
6569
Jamie Madillfa920eb2018-01-04 11:45:50 -05006570void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006571{
6572 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6573 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6574 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6575}
6576
Jamie Madillfa920eb2018-01-04 11:45:50 -05006577void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6578{
6579 UNIMPLEMENTED();
6580}
6581
Jamie Madill5b772312018-03-08 20:28:32 -05006582bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6583{
6584 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6585 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6586 // to the fact that it is stored internally as a float, and so would require conversion
6587 // if returned from Context::getIntegerv. Since this conversion is already implemented
6588 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6589 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6590 // application.
6591 switch (pname)
6592 {
6593 case GL_COMPRESSED_TEXTURE_FORMATS:
6594 {
6595 *type = GL_INT;
6596 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6597 return true;
6598 }
6599 case GL_SHADER_BINARY_FORMATS:
6600 {
6601 *type = GL_INT;
6602 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6603 return true;
6604 }
6605
6606 case GL_MAX_VERTEX_ATTRIBS:
6607 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6608 case GL_MAX_VARYING_VECTORS:
6609 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6610 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6611 case GL_MAX_TEXTURE_IMAGE_UNITS:
6612 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6613 case GL_MAX_RENDERBUFFER_SIZE:
6614 case GL_NUM_SHADER_BINARY_FORMATS:
6615 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6616 case GL_ARRAY_BUFFER_BINDING:
6617 case GL_FRAMEBUFFER_BINDING:
6618 case GL_RENDERBUFFER_BINDING:
6619 case GL_CURRENT_PROGRAM:
6620 case GL_PACK_ALIGNMENT:
6621 case GL_UNPACK_ALIGNMENT:
6622 case GL_GENERATE_MIPMAP_HINT:
6623 case GL_RED_BITS:
6624 case GL_GREEN_BITS:
6625 case GL_BLUE_BITS:
6626 case GL_ALPHA_BITS:
6627 case GL_DEPTH_BITS:
6628 case GL_STENCIL_BITS:
6629 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6630 case GL_CULL_FACE_MODE:
6631 case GL_FRONT_FACE:
6632 case GL_ACTIVE_TEXTURE:
6633 case GL_STENCIL_FUNC:
6634 case GL_STENCIL_VALUE_MASK:
6635 case GL_STENCIL_REF:
6636 case GL_STENCIL_FAIL:
6637 case GL_STENCIL_PASS_DEPTH_FAIL:
6638 case GL_STENCIL_PASS_DEPTH_PASS:
6639 case GL_STENCIL_BACK_FUNC:
6640 case GL_STENCIL_BACK_VALUE_MASK:
6641 case GL_STENCIL_BACK_REF:
6642 case GL_STENCIL_BACK_FAIL:
6643 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6644 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6645 case GL_DEPTH_FUNC:
6646 case GL_BLEND_SRC_RGB:
6647 case GL_BLEND_SRC_ALPHA:
6648 case GL_BLEND_DST_RGB:
6649 case GL_BLEND_DST_ALPHA:
6650 case GL_BLEND_EQUATION_RGB:
6651 case GL_BLEND_EQUATION_ALPHA:
6652 case GL_STENCIL_WRITEMASK:
6653 case GL_STENCIL_BACK_WRITEMASK:
6654 case GL_STENCIL_CLEAR_VALUE:
6655 case GL_SUBPIXEL_BITS:
6656 case GL_MAX_TEXTURE_SIZE:
6657 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6658 case GL_SAMPLE_BUFFERS:
6659 case GL_SAMPLES:
6660 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6661 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6662 case GL_TEXTURE_BINDING_2D:
6663 case GL_TEXTURE_BINDING_CUBE_MAP:
6664 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6665 {
6666 *type = GL_INT;
6667 *numParams = 1;
6668 return true;
6669 }
6670 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6671 {
6672 if (!getExtensions().packReverseRowOrder)
6673 {
6674 return false;
6675 }
6676 *type = GL_INT;
6677 *numParams = 1;
6678 return true;
6679 }
6680 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6681 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6682 {
6683 if (!getExtensions().textureRectangle)
6684 {
6685 return false;
6686 }
6687 *type = GL_INT;
6688 *numParams = 1;
6689 return true;
6690 }
6691 case GL_MAX_DRAW_BUFFERS_EXT:
6692 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6693 {
6694 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6695 {
6696 return false;
6697 }
6698 *type = GL_INT;
6699 *numParams = 1;
6700 return true;
6701 }
6702 case GL_MAX_VIEWPORT_DIMS:
6703 {
6704 *type = GL_INT;
6705 *numParams = 2;
6706 return true;
6707 }
6708 case GL_VIEWPORT:
6709 case GL_SCISSOR_BOX:
6710 {
6711 *type = GL_INT;
6712 *numParams = 4;
6713 return true;
6714 }
6715 case GL_SHADER_COMPILER:
6716 case GL_SAMPLE_COVERAGE_INVERT:
6717 case GL_DEPTH_WRITEMASK:
6718 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6719 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6720 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6721 // bool-natural
6722 case GL_SAMPLE_COVERAGE:
6723 case GL_SCISSOR_TEST:
6724 case GL_STENCIL_TEST:
6725 case GL_DEPTH_TEST:
6726 case GL_BLEND:
6727 case GL_DITHER:
6728 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6729 {
6730 *type = GL_BOOL;
6731 *numParams = 1;
6732 return true;
6733 }
6734 case GL_COLOR_WRITEMASK:
6735 {
6736 *type = GL_BOOL;
6737 *numParams = 4;
6738 return true;
6739 }
6740 case GL_POLYGON_OFFSET_FACTOR:
6741 case GL_POLYGON_OFFSET_UNITS:
6742 case GL_SAMPLE_COVERAGE_VALUE:
6743 case GL_DEPTH_CLEAR_VALUE:
6744 case GL_LINE_WIDTH:
6745 {
6746 *type = GL_FLOAT;
6747 *numParams = 1;
6748 return true;
6749 }
6750 case GL_ALIASED_LINE_WIDTH_RANGE:
6751 case GL_ALIASED_POINT_SIZE_RANGE:
6752 case GL_DEPTH_RANGE:
6753 {
6754 *type = GL_FLOAT;
6755 *numParams = 2;
6756 return true;
6757 }
6758 case GL_COLOR_CLEAR_VALUE:
6759 case GL_BLEND_COLOR:
6760 {
6761 *type = GL_FLOAT;
6762 *numParams = 4;
6763 return true;
6764 }
6765 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6766 if (!getExtensions().textureFilterAnisotropic)
6767 {
6768 return false;
6769 }
6770 *type = GL_FLOAT;
6771 *numParams = 1;
6772 return true;
6773 case GL_TIMESTAMP_EXT:
6774 if (!getExtensions().disjointTimerQuery)
6775 {
6776 return false;
6777 }
6778 *type = GL_INT_64_ANGLEX;
6779 *numParams = 1;
6780 return true;
6781 case GL_GPU_DISJOINT_EXT:
6782 if (!getExtensions().disjointTimerQuery)
6783 {
6784 return false;
6785 }
6786 *type = GL_INT;
6787 *numParams = 1;
6788 return true;
6789 case GL_COVERAGE_MODULATION_CHROMIUM:
6790 if (!getExtensions().framebufferMixedSamples)
6791 {
6792 return false;
6793 }
6794 *type = GL_INT;
6795 *numParams = 1;
6796 return true;
6797 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6798 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6799 {
6800 return false;
6801 }
6802 *type = GL_INT;
6803 *numParams = 1;
6804 return true;
6805 }
6806
6807 if (getExtensions().debug)
6808 {
6809 switch (pname)
6810 {
6811 case GL_DEBUG_LOGGED_MESSAGES:
6812 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6813 case GL_DEBUG_GROUP_STACK_DEPTH:
6814 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6815 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6816 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6817 case GL_MAX_LABEL_LENGTH:
6818 *type = GL_INT;
6819 *numParams = 1;
6820 return true;
6821
6822 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6823 case GL_DEBUG_OUTPUT:
6824 *type = GL_BOOL;
6825 *numParams = 1;
6826 return true;
6827 }
6828 }
6829
6830 if (getExtensions().multisampleCompatibility)
6831 {
6832 switch (pname)
6833 {
6834 case GL_MULTISAMPLE_EXT:
6835 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6836 *type = GL_BOOL;
6837 *numParams = 1;
6838 return true;
6839 }
6840 }
6841
6842 if (getExtensions().pathRendering)
6843 {
6844 switch (pname)
6845 {
6846 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6847 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6848 *type = GL_FLOAT;
6849 *numParams = 16;
6850 return true;
6851 }
6852 }
6853
6854 if (getExtensions().bindGeneratesResource)
6855 {
6856 switch (pname)
6857 {
6858 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6859 *type = GL_BOOL;
6860 *numParams = 1;
6861 return true;
6862 }
6863 }
6864
6865 if (getExtensions().clientArrays)
6866 {
6867 switch (pname)
6868 {
6869 case GL_CLIENT_ARRAYS_ANGLE:
6870 *type = GL_BOOL;
6871 *numParams = 1;
6872 return true;
6873 }
6874 }
6875
6876 if (getExtensions().sRGBWriteControl)
6877 {
6878 switch (pname)
6879 {
6880 case GL_FRAMEBUFFER_SRGB_EXT:
6881 *type = GL_BOOL;
6882 *numParams = 1;
6883 return true;
6884 }
6885 }
6886
6887 if (getExtensions().robustResourceInitialization &&
6888 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6889 {
6890 *type = GL_BOOL;
6891 *numParams = 1;
6892 return true;
6893 }
6894
6895 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6896 {
6897 *type = GL_BOOL;
6898 *numParams = 1;
6899 return true;
6900 }
6901
6902 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6903 switch (pname)
6904 {
6905 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6906 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6907 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6908 {
6909 return false;
6910 }
6911 *type = GL_INT;
6912 *numParams = 1;
6913 return true;
6914
6915 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6916 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6917 {
6918 return false;
6919 }
6920 *type = GL_INT;
6921 *numParams = 1;
6922 return true;
6923
6924 case GL_PROGRAM_BINARY_FORMATS_OES:
6925 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6926 {
6927 return false;
6928 }
6929 *type = GL_INT;
6930 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6931 return true;
6932
6933 case GL_PACK_ROW_LENGTH:
6934 case GL_PACK_SKIP_ROWS:
6935 case GL_PACK_SKIP_PIXELS:
6936 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6937 {
6938 return false;
6939 }
6940 *type = GL_INT;
6941 *numParams = 1;
6942 return true;
6943 case GL_UNPACK_ROW_LENGTH:
6944 case GL_UNPACK_SKIP_ROWS:
6945 case GL_UNPACK_SKIP_PIXELS:
6946 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6947 {
6948 return false;
6949 }
6950 *type = GL_INT;
6951 *numParams = 1;
6952 return true;
6953 case GL_VERTEX_ARRAY_BINDING:
6954 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6955 {
6956 return false;
6957 }
6958 *type = GL_INT;
6959 *numParams = 1;
6960 return true;
6961 case GL_PIXEL_PACK_BUFFER_BINDING:
6962 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6963 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970 case GL_MAX_SAMPLES:
6971 {
6972 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6973 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6974 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6975 {
6976 return false;
6977 }
6978 *type = GL_INT;
6979 *numParams = 1;
6980 return true;
6981
6982 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6983 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6984 {
6985 return false;
6986 }
6987 *type = GL_INT;
6988 *numParams = 1;
6989 return true;
6990 }
6991 }
6992
6993 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6994 {
6995 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6996 {
6997 return false;
6998 }
6999 *type = GL_INT;
7000 *numParams = 1;
7001 return true;
7002 }
7003
7004 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7005 {
7006 *type = GL_INT;
7007 *numParams = 1;
7008 return true;
7009 }
7010
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007011 if (getClientVersion() < Version(2, 0))
7012 {
7013 switch (pname)
7014 {
7015 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007016 case GL_CLIENT_ACTIVE_TEXTURE:
7017 case GL_MATRIX_MODE:
7018 case GL_MAX_TEXTURE_UNITS:
7019 case GL_MAX_MODELVIEW_STACK_DEPTH:
7020 case GL_MAX_PROJECTION_STACK_DEPTH:
7021 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007022 case GL_VERTEX_ARRAY_STRIDE:
7023 case GL_NORMAL_ARRAY_STRIDE:
7024 case GL_COLOR_ARRAY_STRIDE:
7025 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7026 case GL_VERTEX_ARRAY_SIZE:
7027 case GL_COLOR_ARRAY_SIZE:
7028 case GL_TEXTURE_COORD_ARRAY_SIZE:
7029 case GL_VERTEX_ARRAY_TYPE:
7030 case GL_NORMAL_ARRAY_TYPE:
7031 case GL_COLOR_ARRAY_TYPE:
7032 case GL_TEXTURE_COORD_ARRAY_TYPE:
7033 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7034 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7035 case GL_COLOR_ARRAY_BUFFER_BINDING:
7036 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7037 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7038 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7039 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007040 *type = GL_INT;
7041 *numParams = 1;
7042 return true;
7043 case GL_ALPHA_TEST_REF:
7044 *type = GL_FLOAT;
7045 *numParams = 1;
7046 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007047 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007048 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007049 *type = GL_FLOAT;
7050 *numParams = 4;
7051 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007052 case GL_CURRENT_NORMAL:
7053 *type = GL_FLOAT;
7054 *numParams = 3;
7055 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007056 case GL_MODELVIEW_MATRIX:
7057 case GL_PROJECTION_MATRIX:
7058 case GL_TEXTURE_MATRIX:
7059 *type = GL_FLOAT;
7060 *numParams = 16;
7061 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007062 }
7063 }
7064
Jamie Madill5b772312018-03-08 20:28:32 -05007065 if (getClientVersion() < Version(3, 0))
7066 {
7067 return false;
7068 }
7069
7070 // Check for ES3.0+ parameter names
7071 switch (pname)
7072 {
7073 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7074 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7075 case GL_UNIFORM_BUFFER_BINDING:
7076 case GL_TRANSFORM_FEEDBACK_BINDING:
7077 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7078 case GL_COPY_READ_BUFFER_BINDING:
7079 case GL_COPY_WRITE_BUFFER_BINDING:
7080 case GL_SAMPLER_BINDING:
7081 case GL_READ_BUFFER:
7082 case GL_TEXTURE_BINDING_3D:
7083 case GL_TEXTURE_BINDING_2D_ARRAY:
7084 case GL_MAX_3D_TEXTURE_SIZE:
7085 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7086 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7087 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7088 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7089 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7090 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7091 case GL_MAX_VARYING_COMPONENTS:
7092 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7093 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7094 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7095 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7096 case GL_NUM_EXTENSIONS:
7097 case GL_MAJOR_VERSION:
7098 case GL_MINOR_VERSION:
7099 case GL_MAX_ELEMENTS_INDICES:
7100 case GL_MAX_ELEMENTS_VERTICES:
7101 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7102 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7103 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7104 case GL_UNPACK_IMAGE_HEIGHT:
7105 case GL_UNPACK_SKIP_IMAGES:
7106 {
7107 *type = GL_INT;
7108 *numParams = 1;
7109 return true;
7110 }
7111
7112 case GL_MAX_ELEMENT_INDEX:
7113 case GL_MAX_UNIFORM_BLOCK_SIZE:
7114 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7115 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7116 case GL_MAX_SERVER_WAIT_TIMEOUT:
7117 {
7118 *type = GL_INT_64_ANGLEX;
7119 *numParams = 1;
7120 return true;
7121 }
7122
7123 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7124 case GL_TRANSFORM_FEEDBACK_PAUSED:
7125 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7126 case GL_RASTERIZER_DISCARD:
7127 {
7128 *type = GL_BOOL;
7129 *numParams = 1;
7130 return true;
7131 }
7132
7133 case GL_MAX_TEXTURE_LOD_BIAS:
7134 {
7135 *type = GL_FLOAT;
7136 *numParams = 1;
7137 return true;
7138 }
7139 }
7140
7141 if (getExtensions().requestExtension)
7142 {
7143 switch (pname)
7144 {
7145 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7146 *type = GL_INT;
7147 *numParams = 1;
7148 return true;
7149 }
7150 }
7151
7152 if (getClientVersion() < Version(3, 1))
7153 {
7154 return false;
7155 }
7156
7157 switch (pname)
7158 {
7159 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7160 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7161 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7162 case GL_MAX_FRAMEBUFFER_WIDTH:
7163 case GL_MAX_FRAMEBUFFER_HEIGHT:
7164 case GL_MAX_FRAMEBUFFER_SAMPLES:
7165 case GL_MAX_SAMPLE_MASK_WORDS:
7166 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7167 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7168 case GL_MAX_INTEGER_SAMPLES:
7169 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7170 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7171 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7172 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7173 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7174 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7175 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7176 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7177 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7178 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7179 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7180 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7181 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7182 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7183 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7184 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7185 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7186 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7187 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7188 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7189 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7190 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7191 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7192 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7193 case GL_MAX_UNIFORM_LOCATIONS:
7194 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7195 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7196 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7197 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7198 case GL_MAX_IMAGE_UNITS:
7199 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7200 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7201 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7202 case GL_SHADER_STORAGE_BUFFER_BINDING:
7203 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7204 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7205 *type = GL_INT;
7206 *numParams = 1;
7207 return true;
7208 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7209 *type = GL_INT_64_ANGLEX;
7210 *numParams = 1;
7211 return true;
7212 case GL_SAMPLE_MASK:
7213 *type = GL_BOOL;
7214 *numParams = 1;
7215 return true;
7216 }
7217
7218 if (getExtensions().geometryShader)
7219 {
7220 switch (pname)
7221 {
7222 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7223 case GL_LAYER_PROVOKING_VERTEX_EXT:
7224 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7225 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7226 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7227 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7228 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7229 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7230 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7231 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7232 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7233 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7234 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7235 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7236 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7237 *type = GL_INT;
7238 *numParams = 1;
7239 return true;
7240 }
7241 }
7242
7243 return false;
7244}
7245
7246bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7247{
7248 if (getClientVersion() < Version(3, 0))
7249 {
7250 return false;
7251 }
7252
7253 switch (target)
7254 {
7255 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7256 case GL_UNIFORM_BUFFER_BINDING:
7257 {
7258 *type = GL_INT;
7259 *numParams = 1;
7260 return true;
7261 }
7262 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7263 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7264 case GL_UNIFORM_BUFFER_START:
7265 case GL_UNIFORM_BUFFER_SIZE:
7266 {
7267 *type = GL_INT_64_ANGLEX;
7268 *numParams = 1;
7269 return true;
7270 }
7271 }
7272
7273 if (getClientVersion() < Version(3, 1))
7274 {
7275 return false;
7276 }
7277
7278 switch (target)
7279 {
7280 case GL_IMAGE_BINDING_LAYERED:
7281 {
7282 *type = GL_BOOL;
7283 *numParams = 1;
7284 return true;
7285 }
7286 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7287 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7288 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7289 case GL_SHADER_STORAGE_BUFFER_BINDING:
7290 case GL_VERTEX_BINDING_BUFFER:
7291 case GL_VERTEX_BINDING_DIVISOR:
7292 case GL_VERTEX_BINDING_OFFSET:
7293 case GL_VERTEX_BINDING_STRIDE:
7294 case GL_SAMPLE_MASK_VALUE:
7295 case GL_IMAGE_BINDING_NAME:
7296 case GL_IMAGE_BINDING_LEVEL:
7297 case GL_IMAGE_BINDING_LAYER:
7298 case GL_IMAGE_BINDING_ACCESS:
7299 case GL_IMAGE_BINDING_FORMAT:
7300 {
7301 *type = GL_INT;
7302 *numParams = 1;
7303 return true;
7304 }
7305 case GL_ATOMIC_COUNTER_BUFFER_START:
7306 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7307 case GL_SHADER_STORAGE_BUFFER_START:
7308 case GL_SHADER_STORAGE_BUFFER_SIZE:
7309 {
7310 *type = GL_INT_64_ANGLEX;
7311 *numParams = 1;
7312 return true;
7313 }
7314 }
7315
7316 return false;
7317}
7318
7319Program *Context::getProgram(GLuint handle) const
7320{
7321 return mState.mShaderPrograms->getProgram(handle);
7322}
7323
7324Shader *Context::getShader(GLuint handle) const
7325{
7326 return mState.mShaderPrograms->getShader(handle);
7327}
7328
7329bool Context::isTextureGenerated(GLuint texture) const
7330{
7331 return mState.mTextures->isHandleGenerated(texture);
7332}
7333
7334bool Context::isBufferGenerated(GLuint buffer) const
7335{
7336 return mState.mBuffers->isHandleGenerated(buffer);
7337}
7338
7339bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7340{
7341 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7342}
7343
7344bool Context::isFramebufferGenerated(GLuint framebuffer) const
7345{
7346 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7347}
7348
7349bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7350{
7351 return mState.mPipelines->isHandleGenerated(pipeline);
7352}
7353
7354bool Context::usingDisplayTextureShareGroup() const
7355{
7356 return mDisplayTextureShareGroup;
7357}
7358
7359GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7360{
7361 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7362 internalformat == GL_DEPTH_STENCIL
7363 ? GL_DEPTH24_STENCIL8
7364 : internalformat;
7365}
7366
Jamie Madillc29968b2016-01-20 11:17:23 -05007367} // namespace gl