blob: ae4e182f7a9d0274bf0c0d5dedff5c54c74d035f [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.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400300 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
301 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500302
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.
Geoff Lang61107632018-05-09 11:32:46 -0400435 if (mSurfacelessFramebuffer)
436 {
437 mSurfacelessFramebuffer->onDestroy(this);
438 SafeDelete(mSurfacelessFramebuffer);
439 }
Jamie Madille7b3fe22018-04-05 09:42:46 -0400440
441 ANGLE_TRY(releaseSurface(display));
442
Corentin Wallez80b24112015-08-25 16:41:57 -0400443 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400445 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400447 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000448
Corentin Wallez80b24112015-08-25 16:41:57 -0400449 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000450 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400451 if (query.second != nullptr)
452 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400453 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400454 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000455 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400456 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400459 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400460 if (vertexArray.second)
461 {
462 vertexArray.second->onDestroy(this);
463 }
Jamie Madill57a89722013-07-02 11:57:03 -0400464 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400465 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400466
Corentin Wallez80b24112015-08-25 16:41:57 -0400467 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500468 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500469 if (transformFeedback.second != nullptr)
470 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500471 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500472 }
Geoff Langc8058452014-02-03 12:04:11 -0500473 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400474 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500475
Jamie Madill5b772312018-03-08 20:28:32 -0500476 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400477 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800478 if (zeroTexture.get() != nullptr)
479 {
480 ANGLE_TRY(zeroTexture->onDestroy(this));
481 zeroTexture.set(this, nullptr);
482 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400483 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000484
Jamie Madill2f348d22017-06-05 10:50:59 -0400485 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487 mGLState.reset(this);
488
Jamie Madill6c1f6712017-02-14 19:08:04 -0500489 mState.mBuffers->release(this);
490 mState.mShaderPrograms->release(this);
491 mState.mTextures->release(this);
492 mState.mRenderbuffers->release(this);
493 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400494 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500495 mState.mPaths->release(this);
496 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800497 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498
Jamie Madill76e471e2017-10-21 09:56:01 -0400499 mImplementation->onDestroy(this);
500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502}
503
Jamie Madill70ee0f62017-02-06 16:04:20 -0500504Context::~Context()
505{
506}
507
Jamie Madill4928b7c2017-06-20 12:57:39 -0400508egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509{
Jamie Madill61e16b42017-06-19 11:13:23 -0400510 mCurrentDisplay = display;
511
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000512 if (!mHasBeenCurrent)
513 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500515 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400516 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517
Corentin Wallezc295e512017-01-27 17:47:50 -0500518 int width = 0;
519 int height = 0;
520 if (surface != nullptr)
521 {
522 width = surface->getWidth();
523 height = surface->getHeight();
524 }
525
526 mGLState.setViewportParams(0, 0, width, height);
527 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528
529 mHasBeenCurrent = true;
530 }
531
Jamie Madill1b94d432015-08-07 13:23:23 -0400532 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700533 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400534 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400535
Jamie Madill4928b7c2017-06-20 12:57:39 -0400536 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500537
538 Framebuffer *newDefault = nullptr;
539 if (surface != nullptr)
540 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400541 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500542 mCurrentSurface = surface;
543 newDefault = surface->getDefaultFramebuffer();
544 }
545 else
546 {
547 if (mSurfacelessFramebuffer == nullptr)
548 {
549 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
550 }
551
552 newDefault = mSurfacelessFramebuffer;
553 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000554
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 // Update default framebuffer, the binding of the previous default
556 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400557 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700560 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700562 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400563 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700564 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400565 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500566 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400567 }
Ian Ewell292f0052016-02-04 10:37:32 -0500568
569 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570 mImplementation->onMakeCurrent(this);
571 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000572}
573
Jamie Madill4928b7c2017-06-20 12:57:39 -0400574egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400575{
Corentin Wallez37c39792015-08-20 14:19:46 -0400576 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 Framebuffer *currentDefault = nullptr;
578 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400579 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500580 currentDefault = mCurrentSurface->getDefaultFramebuffer();
581 }
582 else if (mSurfacelessFramebuffer != nullptr)
583 {
584 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400585 }
586
Corentin Wallezc295e512017-01-27 17:47:50 -0500587 if (mGLState.getReadFramebuffer() == currentDefault)
588 {
589 mGLState.setReadFramebufferBinding(nullptr);
590 }
591 if (mGLState.getDrawFramebuffer() == currentDefault)
592 {
593 mGLState.setDrawFramebufferBinding(nullptr);
594 }
595 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
596
597 if (mCurrentSurface)
598 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 mCurrentSurface = nullptr;
601 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602
603 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400604}
605
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606GLuint Context::createBuffer()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609}
610
611GLuint Context::createProgram()
612{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500613 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614}
615
Jiawei Shao385b3e02018-03-21 09:43:28 +0800616GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619}
620
621GLuint Context::createTexture()
622{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500623 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000624}
625
626GLuint Context::createRenderbuffer()
627{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500628 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
Brandon Jones59770802018-04-02 13:18:42 -0700631GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300632{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500633 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300634 if (resultOrError.isError())
635 {
636 handleError(resultOrError.getError());
637 return 0;
638 }
639 return resultOrError.getResult();
640}
641
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642// Returns an unused framebuffer name
643GLuint Context::createFramebuffer()
644{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500645 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646}
647
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500648void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500650 for (int i = 0; i < n; i++)
651 {
652 GLuint handle = mFenceNVHandleAllocator.allocate();
653 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
654 fences[i] = handle;
655 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656}
657
Yunchao Hea336b902017-08-02 16:05:21 +0800658GLuint Context::createProgramPipeline()
659{
660 return mState.mPipelines->createProgramPipeline();
661}
662
Jiawei Shao385b3e02018-03-21 09:43:28 +0800663GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800664{
665 UNIMPLEMENTED();
666 return 0u;
667}
668
James Darpinian4d9d4832018-03-13 12:43:28 -0700669void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670{
James Darpinian4d9d4832018-03-13 12:43:28 -0700671 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
672 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673 {
674 detachBuffer(buffer);
675 }
Jamie Madill893ab082014-05-16 16:56:10 -0400676
James Darpinian4d9d4832018-03-13 12:43:28 -0700677 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
680void Context::deleteShader(GLuint shader)
681{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500682 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683}
684
685void Context::deleteProgram(GLuint program)
686{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500687 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
690void Context::deleteTexture(GLuint texture)
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693 {
694 detachTexture(texture);
695 }
696
Jamie Madill6c1f6712017-02-14 19:08:04 -0500697 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700void Context::deleteRenderbuffer(GLuint renderbuffer)
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703 {
704 detachRenderbuffer(renderbuffer);
705 }
Jamie Madill893ab082014-05-16 16:56:10 -0400706
Jamie Madill6c1f6712017-02-14 19:08:04 -0500707 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400710void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400711{
712 // The spec specifies the underlying Fence object is not deleted until all current
713 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
714 // and since our API is currently designed for being called from a single thread, we can delete
715 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400716 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400717}
718
Yunchao Hea336b902017-08-02 16:05:21 +0800719void Context::deleteProgramPipeline(GLuint pipeline)
720{
721 if (mState.mPipelines->getProgramPipeline(pipeline))
722 {
723 detachProgramPipeline(pipeline);
724 }
725
726 mState.mPipelines->deleteObject(this, pipeline);
727}
728
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729void Context::deletePaths(GLuint first, GLsizei range)
730{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500731 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732}
733
Brandon Jones59770802018-04-02 13:18:42 -0700734bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737 if (pathObj == nullptr)
738 return false;
739
740 return pathObj->hasPathData();
741}
742
Brandon Jones59770802018-04-02 13:18:42 -0700743bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746}
747
Brandon Jones59770802018-04-02 13:18:42 -0700748void Context::pathCommands(GLuint path,
749 GLsizei numCommands,
750 const GLubyte *commands,
751 GLsizei numCoords,
752 GLenum coordType,
753 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300754{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500755 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300756
757 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
758}
759
Jamie Madill007530e2017-12-28 14:27:04 -0500760void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300761{
Jamie Madill007530e2017-12-28 14:27:04 -0500762 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763
764 switch (pname)
765 {
766 case GL_PATH_STROKE_WIDTH_CHROMIUM:
767 pathObj->setStrokeWidth(value);
768 break;
769 case GL_PATH_END_CAPS_CHROMIUM:
770 pathObj->setEndCaps(static_cast<GLenum>(value));
771 break;
772 case GL_PATH_JOIN_STYLE_CHROMIUM:
773 pathObj->setJoinStyle(static_cast<GLenum>(value));
774 break;
775 case GL_PATH_MITER_LIMIT_CHROMIUM:
776 pathObj->setMiterLimit(value);
777 break;
778 case GL_PATH_STROKE_BOUND_CHROMIUM:
779 pathObj->setStrokeBound(value);
780 break;
781 default:
782 UNREACHABLE();
783 break;
784 }
785}
786
Jamie Madill007530e2017-12-28 14:27:04 -0500787void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300788{
Jamie Madill007530e2017-12-28 14:27:04 -0500789 // TODO(jmadill): Should use proper clamping/casting.
790 pathParameterf(path, pname, static_cast<GLfloat>(value));
791}
792
793void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
794{
795 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300796
797 switch (pname)
798 {
799 case GL_PATH_STROKE_WIDTH_CHROMIUM:
800 *value = pathObj->getStrokeWidth();
801 break;
802 case GL_PATH_END_CAPS_CHROMIUM:
803 *value = static_cast<GLfloat>(pathObj->getEndCaps());
804 break;
805 case GL_PATH_JOIN_STYLE_CHROMIUM:
806 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
807 break;
808 case GL_PATH_MITER_LIMIT_CHROMIUM:
809 *value = pathObj->getMiterLimit();
810 break;
811 case GL_PATH_STROKE_BOUND_CHROMIUM:
812 *value = pathObj->getStrokeBound();
813 break;
814 default:
815 UNREACHABLE();
816 break;
817 }
818}
819
Jamie Madill007530e2017-12-28 14:27:04 -0500820void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
821{
822 GLfloat val = 0.0f;
823 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
824 if (value)
825 *value = static_cast<GLint>(val);
826}
827
Brandon Jones59770802018-04-02 13:18:42 -0700828void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829{
830 mGLState.setPathStencilFunc(func, ref, mask);
831}
832
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833void Context::deleteFramebuffer(GLuint framebuffer)
834{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500835 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000836 {
837 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500839
Jamie Madill6c1f6712017-02-14 19:08:04 -0500840 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841}
842
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500843void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500845 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500847 GLuint fence = fences[i];
848
849 FenceNV *fenceObject = nullptr;
850 if (mFenceNVMap.erase(fence, &fenceObject))
851 {
852 mFenceNVHandleAllocator.release(fence);
853 delete fenceObject;
854 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855 }
856}
857
Geoff Lang70d0f492015-12-10 17:45:46 -0500858Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500860 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861}
862
Jamie Madill570f7c82014-07-03 10:38:54 -0400863Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500865 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866}
867
Geoff Lang70d0f492015-12-10 17:45:46 -0500868Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000871}
872
Jamie Madill70b5bb02017-08-28 13:32:37 -0400873Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400874{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400875 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400876}
877
Jamie Madill57a89722013-07-02 11:57:03 -0400878VertexArray *Context::getVertexArray(GLuint handle) const
879{
Jamie Madill96a483b2017-06-27 16:49:21 -0400880 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400881}
882
Jamie Madilldc356042013-07-19 16:36:57 -0400883Sampler *Context::getSampler(GLuint handle) const
884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400886}
887
Geoff Langc8058452014-02-03 12:04:11 -0500888TransformFeedback *Context::getTransformFeedback(GLuint handle) const
889{
Jamie Madill96a483b2017-06-27 16:49:21 -0400890 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500891}
892
Yunchao Hea336b902017-08-02 16:05:21 +0800893ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
894{
895 return mState.mPipelines->getProgramPipeline(handle);
896}
897
Geoff Lang70d0f492015-12-10 17:45:46 -0500898LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
899{
900 switch (identifier)
901 {
902 case GL_BUFFER:
903 return getBuffer(name);
904 case GL_SHADER:
905 return getShader(name);
906 case GL_PROGRAM:
907 return getProgram(name);
908 case GL_VERTEX_ARRAY:
909 return getVertexArray(name);
910 case GL_QUERY:
911 return getQuery(name);
912 case GL_TRANSFORM_FEEDBACK:
913 return getTransformFeedback(name);
914 case GL_SAMPLER:
915 return getSampler(name);
916 case GL_TEXTURE:
917 return getTexture(name);
918 case GL_RENDERBUFFER:
919 return getRenderbuffer(name);
920 case GL_FRAMEBUFFER:
921 return getFramebuffer(name);
922 default:
923 UNREACHABLE();
924 return nullptr;
925 }
926}
927
928LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
929{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400930 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500931}
932
Martin Radev9d901792016-07-15 15:58:58 +0300933void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
934{
935 LabeledObject *object = getLabeledObject(identifier, name);
936 ASSERT(object != nullptr);
937
938 std::string labelName = GetObjectLabelFromPointer(length, label);
939 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400940
941 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
942 // specified object is active until we do this.
943 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300944}
945
946void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
947{
948 LabeledObject *object = getLabeledObjectFromPtr(ptr);
949 ASSERT(object != nullptr);
950
951 std::string labelName = GetObjectLabelFromPointer(length, label);
952 object->setLabel(labelName);
953}
954
955void Context::getObjectLabel(GLenum identifier,
956 GLuint name,
957 GLsizei bufSize,
958 GLsizei *length,
959 GLchar *label) const
960{
961 LabeledObject *object = getLabeledObject(identifier, name);
962 ASSERT(object != nullptr);
963
964 const std::string &objectLabel = object->getLabel();
965 GetObjectLabelBase(objectLabel, bufSize, length, label);
966}
967
968void Context::getObjectPtrLabel(const void *ptr,
969 GLsizei bufSize,
970 GLsizei *length,
971 GLchar *label) const
972{
973 LabeledObject *object = getLabeledObjectFromPtr(ptr);
974 ASSERT(object != nullptr);
975
976 const std::string &objectLabel = object->getLabel();
977 GetObjectLabelBase(objectLabel, bufSize, length, label);
978}
979
Jamie Madilldc356042013-07-19 16:36:57 -0400980bool Context::isSampler(GLuint samplerName) const
981{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500982 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400983}
984
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800985void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000986{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500987 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988
Jamie Madilldedd7b92014-11-05 16:30:36 -0500989 if (handle == 0)
990 {
991 texture = mZeroTextures[target].get();
992 }
993 else
994 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500995 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500996 }
997
998 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400999 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001000}
1001
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001002void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001003{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001004 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1005 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001006 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007}
1008
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001009void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001011 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1012 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001013 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001014}
1015
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001016void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001017{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001018 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001019 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001020}
1021
Shao80957d92017-02-20 21:25:59 +08001022void Context::bindVertexBuffer(GLuint bindingIndex,
1023 GLuint bufferHandle,
1024 GLintptr offset,
1025 GLsizei stride)
1026{
1027 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001028 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001029}
1030
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001032{
Geoff Lang76b10c92014-09-05 16:28:14 -04001033 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001034 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001035 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001036 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001037}
1038
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001039void Context::bindImageTexture(GLuint unit,
1040 GLuint texture,
1041 GLint level,
1042 GLboolean layered,
1043 GLint layer,
1044 GLenum access,
1045 GLenum format)
1046{
1047 Texture *tex = mState.mTextures->getTexture(texture);
1048 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1049}
1050
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051void Context::useProgram(GLuint program)
1052{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001053 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001054}
1055
Jiajia Qin5451d532017-11-16 17:16:34 +08001056void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1057{
1058 UNIMPLEMENTED();
1059}
1060
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001061void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001062{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001063 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001064 TransformFeedback *transformFeedback =
1065 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001066 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001067}
1068
Yunchao Hea336b902017-08-02 16:05:21 +08001069void Context::bindProgramPipeline(GLuint pipelineHandle)
1070{
1071 ProgramPipeline *pipeline =
1072 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1073 mGLState.setProgramPipelineBinding(this, pipeline);
1074}
1075
Corentin Wallezad3ae902018-03-09 13:40:42 -05001076void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001079 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080
Geoff Lang5aad9672014-09-08 11:10:42 -04001081 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001082 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001083
1084 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001085 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086}
1087
Corentin Wallezad3ae902018-03-09 13:40:42 -05001088void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001090 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001091 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001092
Jamie Madillf0e04492017-08-26 15:28:42 -04001093 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001094
Geoff Lang5aad9672014-09-08 11:10:42 -04001095 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001096 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097}
1098
Corentin Wallezad3ae902018-03-09 13:40:42 -05001099void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001100{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001101 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001102
1103 Query *queryObject = getQuery(id, true, target);
1104 ASSERT(queryObject);
1105
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001107}
1108
Corentin Wallezad3ae902018-03-09 13:40:42 -05001109void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001110{
1111 switch (pname)
1112 {
1113 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001114 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115 break;
1116 case GL_QUERY_COUNTER_BITS_EXT:
1117 switch (target)
1118 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001119 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1121 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001122 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123 params[0] = getExtensions().queryCounterBitsTimestamp;
1124 break;
1125 default:
1126 UNREACHABLE();
1127 params[0] = 0;
1128 break;
1129 }
1130 break;
1131 default:
1132 UNREACHABLE();
1133 return;
1134 }
1135}
1136
Corentin Wallezad3ae902018-03-09 13:40:42 -05001137void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001138 GLenum pname,
1139 GLsizei bufSize,
1140 GLsizei *length,
1141 GLint *params)
1142{
1143 getQueryiv(target, pname, params);
1144}
1145
Geoff Lang2186c382016-10-14 10:54:54 -04001146void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001147{
Geoff Lang2186c382016-10-14 10:54:54 -04001148 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001149}
1150
Brandon Jones59770802018-04-02 13:18:42 -07001151void Context::getQueryObjectivRobust(GLuint id,
1152 GLenum pname,
1153 GLsizei bufSize,
1154 GLsizei *length,
1155 GLint *params)
1156{
1157 getQueryObjectiv(id, pname, params);
1158}
1159
Geoff Lang2186c382016-10-14 10:54:54 -04001160void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001161{
Geoff Lang2186c382016-10-14 10:54:54 -04001162 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001163}
1164
Brandon Jones59770802018-04-02 13:18:42 -07001165void Context::getQueryObjectuivRobust(GLuint id,
1166 GLenum pname,
1167 GLsizei bufSize,
1168 GLsizei *length,
1169 GLuint *params)
1170{
1171 getQueryObjectuiv(id, pname, params);
1172}
1173
Geoff Lang2186c382016-10-14 10:54:54 -04001174void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175{
Geoff Lang2186c382016-10-14 10:54:54 -04001176 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001177}
1178
Brandon Jones59770802018-04-02 13:18:42 -07001179void Context::getQueryObjecti64vRobust(GLuint id,
1180 GLenum pname,
1181 GLsizei bufSize,
1182 GLsizei *length,
1183 GLint64 *params)
1184{
1185 getQueryObjecti64v(id, pname, params);
1186}
1187
Geoff Lang2186c382016-10-14 10:54:54 -04001188void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189{
Geoff Lang2186c382016-10-14 10:54:54 -04001190 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191}
1192
Brandon Jones59770802018-04-02 13:18:42 -07001193void Context::getQueryObjectui64vRobust(GLuint id,
1194 GLenum pname,
1195 GLsizei bufSize,
1196 GLsizei *length,
1197 GLuint64 *params)
1198{
1199 getQueryObjectui64v(id, pname, params);
1200}
1201
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001202Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001204 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205}
1206
Jamie Madill2f348d22017-06-05 10:50:59 -04001207FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208{
Jamie Madill96a483b2017-06-27 16:49:21 -04001209 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210}
1211
Corentin Wallezad3ae902018-03-09 13:40:42 -05001212Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213{
Jamie Madill96a483b2017-06-27 16:49:21 -04001214 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001216 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001218
1219 Query *query = mQueryMap.query(handle);
1220 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001222 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 query = new Query(mImplementation->createQuery(type), handle);
1224 query->addRef();
1225 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228}
1229
Geoff Lang70d0f492015-12-10 17:45:46 -05001230Query *Context::getQuery(GLuint handle) const
1231{
Jamie Madill96a483b2017-06-27 16:49:21 -04001232 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001233}
1234
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001235Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001236{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001237 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1238 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001239}
1240
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001241Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001242{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001243 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244}
1245
Geoff Lang492a7e42014-11-05 13:27:06 -05001246Compiler *Context::getCompiler() const
1247{
Jamie Madill2f348d22017-06-05 10:50:59 -04001248 if (mCompiler.get() == nullptr)
1249 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001250 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001251 }
1252 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001253}
1254
Jamie Madillc1d770e2017-04-13 17:31:24 -04001255void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001256{
1257 switch (pname)
1258 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001259 case GL_SHADER_COMPILER:
1260 *params = GL_TRUE;
1261 break;
1262 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1263 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1264 break;
1265 default:
1266 mGLState.getBooleanv(pname, params);
1267 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269}
1270
Jamie Madillc1d770e2017-04-13 17:31:24 -04001271void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272{
Shannon Woods53a94a82014-06-24 15:20:36 -04001273 // Queries about context capabilities and maximums are answered by Context.
1274 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275 switch (pname)
1276 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001277 case GL_ALIASED_LINE_WIDTH_RANGE:
1278 params[0] = mCaps.minAliasedLineWidth;
1279 params[1] = mCaps.maxAliasedLineWidth;
1280 break;
1281 case GL_ALIASED_POINT_SIZE_RANGE:
1282 params[0] = mCaps.minAliasedPointSize;
1283 params[1] = mCaps.maxAliasedPointSize;
1284 break;
1285 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1286 ASSERT(mExtensions.textureFilterAnisotropic);
1287 *params = mExtensions.maxTextureAnisotropy;
1288 break;
1289 case GL_MAX_TEXTURE_LOD_BIAS:
1290 *params = mCaps.maxLODBias;
1291 break;
1292
1293 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1294 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1295 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001296 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1297 // GLES1 constants for modelview/projection matrix.
1298 if (getClientVersion() < Version(2, 0))
1299 {
1300 mGLState.getFloatv(pname, params);
1301 }
1302 else
1303 {
1304 ASSERT(mExtensions.pathRendering);
1305 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1306 memcpy(params, m, 16 * sizeof(GLfloat));
1307 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001308 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001309 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001310
Jamie Madill231c7f52017-04-26 13:45:37 -04001311 default:
1312 mGLState.getFloatv(pname, params);
1313 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315}
1316
Jamie Madillc1d770e2017-04-13 17:31:24 -04001317void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318{
Shannon Woods53a94a82014-06-24 15:20:36 -04001319 // Queries about context capabilities and maximums are answered by Context.
1320 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001321
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322 switch (pname)
1323 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001324 case GL_MAX_VERTEX_ATTRIBS:
1325 *params = mCaps.maxVertexAttributes;
1326 break;
1327 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1328 *params = mCaps.maxVertexUniformVectors;
1329 break;
1330 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1331 *params = mCaps.maxVertexUniformComponents;
1332 break;
1333 case GL_MAX_VARYING_VECTORS:
1334 *params = mCaps.maxVaryingVectors;
1335 break;
1336 case GL_MAX_VARYING_COMPONENTS:
1337 *params = mCaps.maxVertexOutputComponents;
1338 break;
1339 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1340 *params = mCaps.maxCombinedTextureImageUnits;
1341 break;
1342 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001343 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001344 break;
1345 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001346 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001347 break;
1348 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1349 *params = mCaps.maxFragmentUniformVectors;
1350 break;
1351 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1352 *params = mCaps.maxFragmentUniformComponents;
1353 break;
1354 case GL_MAX_RENDERBUFFER_SIZE:
1355 *params = mCaps.maxRenderbufferSize;
1356 break;
1357 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1358 *params = mCaps.maxColorAttachments;
1359 break;
1360 case GL_MAX_DRAW_BUFFERS_EXT:
1361 *params = mCaps.maxDrawBuffers;
1362 break;
1363 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1364 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1365 case GL_SUBPIXEL_BITS:
1366 *params = 4;
1367 break;
1368 case GL_MAX_TEXTURE_SIZE:
1369 *params = mCaps.max2DTextureSize;
1370 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001371 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1372 *params = mCaps.maxRectangleTextureSize;
1373 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001374 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1375 *params = mCaps.maxCubeMapTextureSize;
1376 break;
1377 case GL_MAX_3D_TEXTURE_SIZE:
1378 *params = mCaps.max3DTextureSize;
1379 break;
1380 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1381 *params = mCaps.maxArrayTextureLayers;
1382 break;
1383 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1384 *params = mCaps.uniformBufferOffsetAlignment;
1385 break;
1386 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1387 *params = mCaps.maxUniformBufferBindings;
1388 break;
1389 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001390 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 break;
1392 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001393 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 break;
1395 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1396 *params = mCaps.maxCombinedTextureImageUnits;
1397 break;
1398 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1399 *params = mCaps.maxVertexOutputComponents;
1400 break;
1401 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1402 *params = mCaps.maxFragmentInputComponents;
1403 break;
1404 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1405 *params = mCaps.minProgramTexelOffset;
1406 break;
1407 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1408 *params = mCaps.maxProgramTexelOffset;
1409 break;
1410 case GL_MAJOR_VERSION:
1411 *params = getClientVersion().major;
1412 break;
1413 case GL_MINOR_VERSION:
1414 *params = getClientVersion().minor;
1415 break;
1416 case GL_MAX_ELEMENTS_INDICES:
1417 *params = mCaps.maxElementsIndices;
1418 break;
1419 case GL_MAX_ELEMENTS_VERTICES:
1420 *params = mCaps.maxElementsVertices;
1421 break;
1422 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1423 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1424 break;
1425 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1426 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1427 break;
1428 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1429 *params = mCaps.maxTransformFeedbackSeparateComponents;
1430 break;
1431 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1432 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1433 break;
1434 case GL_MAX_SAMPLES_ANGLE:
1435 *params = mCaps.maxSamples;
1436 break;
1437 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001438 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001439 params[0] = mCaps.maxViewportWidth;
1440 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001441 }
1442 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001443 case GL_COMPRESSED_TEXTURE_FORMATS:
1444 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1445 params);
1446 break;
1447 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1448 *params = mResetStrategy;
1449 break;
1450 case GL_NUM_SHADER_BINARY_FORMATS:
1451 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1452 break;
1453 case GL_SHADER_BINARY_FORMATS:
1454 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1455 break;
1456 case GL_NUM_PROGRAM_BINARY_FORMATS:
1457 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1458 break;
1459 case GL_PROGRAM_BINARY_FORMATS:
1460 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1461 break;
1462 case GL_NUM_EXTENSIONS:
1463 *params = static_cast<GLint>(mExtensionStrings.size());
1464 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001465
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 // GL_KHR_debug
1467 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1468 *params = mExtensions.maxDebugMessageLength;
1469 break;
1470 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1471 *params = mExtensions.maxDebugLoggedMessages;
1472 break;
1473 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1474 *params = mExtensions.maxDebugGroupStackDepth;
1475 break;
1476 case GL_MAX_LABEL_LENGTH:
1477 *params = mExtensions.maxLabelLength;
1478 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001479
Martin Radeve5285d22017-07-14 16:23:53 +03001480 // GL_ANGLE_multiview
1481 case GL_MAX_VIEWS_ANGLE:
1482 *params = mExtensions.maxViews;
1483 break;
1484
Jamie Madill231c7f52017-04-26 13:45:37 -04001485 // GL_EXT_disjoint_timer_query
1486 case GL_GPU_DISJOINT_EXT:
1487 *params = mImplementation->getGPUDisjoint();
1488 break;
1489 case GL_MAX_FRAMEBUFFER_WIDTH:
1490 *params = mCaps.maxFramebufferWidth;
1491 break;
1492 case GL_MAX_FRAMEBUFFER_HEIGHT:
1493 *params = mCaps.maxFramebufferHeight;
1494 break;
1495 case GL_MAX_FRAMEBUFFER_SAMPLES:
1496 *params = mCaps.maxFramebufferSamples;
1497 break;
1498 case GL_MAX_SAMPLE_MASK_WORDS:
1499 *params = mCaps.maxSampleMaskWords;
1500 break;
1501 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1502 *params = mCaps.maxColorTextureSamples;
1503 break;
1504 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1505 *params = mCaps.maxDepthTextureSamples;
1506 break;
1507 case GL_MAX_INTEGER_SAMPLES:
1508 *params = mCaps.maxIntegerSamples;
1509 break;
1510 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1511 *params = mCaps.maxVertexAttribRelativeOffset;
1512 break;
1513 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1514 *params = mCaps.maxVertexAttribBindings;
1515 break;
1516 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1517 *params = mCaps.maxVertexAttribStride;
1518 break;
1519 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1520 *params = mCaps.maxVertexAtomicCounterBuffers;
1521 break;
1522 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1523 *params = mCaps.maxVertexAtomicCounters;
1524 break;
1525 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1526 *params = mCaps.maxVertexImageUniforms;
1527 break;
1528 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001529 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001530 break;
1531 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1532 *params = mCaps.maxFragmentAtomicCounterBuffers;
1533 break;
1534 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1535 *params = mCaps.maxFragmentAtomicCounters;
1536 break;
1537 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1538 *params = mCaps.maxFragmentImageUniforms;
1539 break;
1540 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001541 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1544 *params = mCaps.minProgramTextureGatherOffset;
1545 break;
1546 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1547 *params = mCaps.maxProgramTextureGatherOffset;
1548 break;
1549 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1550 *params = mCaps.maxComputeWorkGroupInvocations;
1551 break;
1552 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001553 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001554 break;
1555 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001556 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001557 break;
1558 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1559 *params = mCaps.maxComputeSharedMemorySize;
1560 break;
1561 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1562 *params = mCaps.maxComputeUniformComponents;
1563 break;
1564 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1565 *params = mCaps.maxComputeAtomicCounterBuffers;
1566 break;
1567 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1568 *params = mCaps.maxComputeAtomicCounters;
1569 break;
1570 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1571 *params = mCaps.maxComputeImageUniforms;
1572 break;
1573 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1574 *params = mCaps.maxCombinedComputeUniformComponents;
1575 break;
1576 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001577 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 break;
1579 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1580 *params = mCaps.maxCombinedShaderOutputResources;
1581 break;
1582 case GL_MAX_UNIFORM_LOCATIONS:
1583 *params = mCaps.maxUniformLocations;
1584 break;
1585 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1586 *params = mCaps.maxAtomicCounterBufferBindings;
1587 break;
1588 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1589 *params = mCaps.maxAtomicCounterBufferSize;
1590 break;
1591 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1592 *params = mCaps.maxCombinedAtomicCounterBuffers;
1593 break;
1594 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1595 *params = mCaps.maxCombinedAtomicCounters;
1596 break;
1597 case GL_MAX_IMAGE_UNITS:
1598 *params = mCaps.maxImageUnits;
1599 break;
1600 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1601 *params = mCaps.maxCombinedImageUniforms;
1602 break;
1603 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1604 *params = mCaps.maxShaderStorageBufferBindings;
1605 break;
1606 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1607 *params = mCaps.maxCombinedShaderStorageBlocks;
1608 break;
1609 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1610 *params = mCaps.shaderStorageBufferOffsetAlignment;
1611 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001612
1613 // GL_EXT_geometry_shader
1614 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1615 *params = mCaps.maxFramebufferLayers;
1616 break;
1617 case GL_LAYER_PROVOKING_VERTEX_EXT:
1618 *params = mCaps.layerProvokingVertex;
1619 break;
1620 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1621 *params = mCaps.maxGeometryUniformComponents;
1622 break;
1623 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001624 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001625 break;
1626 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1627 *params = mCaps.maxCombinedGeometryUniformComponents;
1628 break;
1629 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1630 *params = mCaps.maxGeometryInputComponents;
1631 break;
1632 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1633 *params = mCaps.maxGeometryOutputComponents;
1634 break;
1635 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1636 *params = mCaps.maxGeometryOutputVertices;
1637 break;
1638 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1639 *params = mCaps.maxGeometryTotalOutputComponents;
1640 break;
1641 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1642 *params = mCaps.maxGeometryShaderInvocations;
1643 break;
1644 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001645 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001646 break;
1647 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1648 *params = mCaps.maxGeometryAtomicCounterBuffers;
1649 break;
1650 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1651 *params = mCaps.maxGeometryAtomicCounters;
1652 break;
1653 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1654 *params = mCaps.maxGeometryImageUniforms;
1655 break;
1656 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001657 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001659 // GLES1 emulation: Caps queries
1660 case GL_MAX_TEXTURE_UNITS:
1661 *params = mCaps.maxMultitextureUnits;
1662 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001663 case GL_MAX_MODELVIEW_STACK_DEPTH:
1664 *params = mCaps.maxModelviewMatrixStackDepth;
1665 break;
1666 case GL_MAX_PROJECTION_STACK_DEPTH:
1667 *params = mCaps.maxProjectionMatrixStackDepth;
1668 break;
1669 case GL_MAX_TEXTURE_STACK_DEPTH:
1670 *params = mCaps.maxTextureMatrixStackDepth;
1671 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001672 // GLES1 emulation: Vertex attribute queries
1673 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1674 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1675 case GL_COLOR_ARRAY_BUFFER_BINDING:
1676 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1677 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1678 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1679 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1680 break;
1681 case GL_VERTEX_ARRAY_STRIDE:
1682 case GL_NORMAL_ARRAY_STRIDE:
1683 case GL_COLOR_ARRAY_STRIDE:
1684 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1685 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1686 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1687 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1688 break;
1689 case GL_VERTEX_ARRAY_SIZE:
1690 case GL_COLOR_ARRAY_SIZE:
1691 case GL_TEXTURE_COORD_ARRAY_SIZE:
1692 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1693 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1694 break;
1695 case GL_VERTEX_ARRAY_TYPE:
1696 case GL_COLOR_ARRAY_TYPE:
1697 case GL_NORMAL_ARRAY_TYPE:
1698 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1699 case GL_TEXTURE_COORD_ARRAY_TYPE:
1700 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1701 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1702 break;
1703
Jamie Madill231c7f52017-04-26 13:45:37 -04001704 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001705 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001707 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001708}
1709
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001710void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001711{
Shannon Woods53a94a82014-06-24 15:20:36 -04001712 // Queries about context capabilities and maximums are answered by Context.
1713 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001714 switch (pname)
1715 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001716 case GL_MAX_ELEMENT_INDEX:
1717 *params = mCaps.maxElementIndex;
1718 break;
1719 case GL_MAX_UNIFORM_BLOCK_SIZE:
1720 *params = mCaps.maxUniformBlockSize;
1721 break;
1722 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1723 *params = mCaps.maxCombinedVertexUniformComponents;
1724 break;
1725 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1726 *params = mCaps.maxCombinedFragmentUniformComponents;
1727 break;
1728 case GL_MAX_SERVER_WAIT_TIMEOUT:
1729 *params = mCaps.maxServerWaitTimeout;
1730 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001731
Jamie Madill231c7f52017-04-26 13:45:37 -04001732 // GL_EXT_disjoint_timer_query
1733 case GL_TIMESTAMP_EXT:
1734 *params = mImplementation->getTimestamp();
1735 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001736
Jamie Madill231c7f52017-04-26 13:45:37 -04001737 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1738 *params = mCaps.maxShaderStorageBlockSize;
1739 break;
1740 default:
1741 UNREACHABLE();
1742 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001743 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001744}
1745
Geoff Lang70d0f492015-12-10 17:45:46 -05001746void Context::getPointerv(GLenum pname, void **params) const
1747{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001748 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001749}
1750
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001751void Context::getPointervRobustANGLERobust(GLenum pname,
1752 GLsizei bufSize,
1753 GLsizei *length,
1754 void **params)
1755{
1756 UNIMPLEMENTED();
1757}
1758
Martin Radev66fb8202016-07-28 11:45:20 +03001759void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001760{
Shannon Woods53a94a82014-06-24 15:20:36 -04001761 // Queries about context capabilities and maximums are answered by Context.
1762 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001763
1764 GLenum nativeType;
1765 unsigned int numParams;
1766 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1767 ASSERT(queryStatus);
1768
1769 if (nativeType == GL_INT)
1770 {
1771 switch (target)
1772 {
1773 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1774 ASSERT(index < 3u);
1775 *data = mCaps.maxComputeWorkGroupCount[index];
1776 break;
1777 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1778 ASSERT(index < 3u);
1779 *data = mCaps.maxComputeWorkGroupSize[index];
1780 break;
1781 default:
1782 mGLState.getIntegeri_v(target, index, data);
1783 }
1784 }
1785 else
1786 {
1787 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1788 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001789}
1790
Brandon Jones59770802018-04-02 13:18:42 -07001791void Context::getIntegeri_vRobust(GLenum target,
1792 GLuint index,
1793 GLsizei bufSize,
1794 GLsizei *length,
1795 GLint *data)
1796{
1797 getIntegeri_v(target, index, data);
1798}
1799
Martin Radev66fb8202016-07-28 11:45:20 +03001800void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001801{
Shannon Woods53a94a82014-06-24 15:20:36 -04001802 // Queries about context capabilities and maximums are answered by Context.
1803 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001804
1805 GLenum nativeType;
1806 unsigned int numParams;
1807 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1808 ASSERT(queryStatus);
1809
1810 if (nativeType == GL_INT_64_ANGLEX)
1811 {
1812 mGLState.getInteger64i_v(target, index, data);
1813 }
1814 else
1815 {
1816 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1817 }
1818}
1819
Brandon Jones59770802018-04-02 13:18:42 -07001820void Context::getInteger64i_vRobust(GLenum target,
1821 GLuint index,
1822 GLsizei bufSize,
1823 GLsizei *length,
1824 GLint64 *data)
1825{
1826 getInteger64i_v(target, index, data);
1827}
1828
Martin Radev66fb8202016-07-28 11:45:20 +03001829void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1830{
1831 // Queries about context capabilities and maximums are answered by Context.
1832 // Queries about current GL state values are answered by State.
1833
1834 GLenum nativeType;
1835 unsigned int numParams;
1836 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1837 ASSERT(queryStatus);
1838
1839 if (nativeType == GL_BOOL)
1840 {
1841 mGLState.getBooleani_v(target, index, data);
1842 }
1843 else
1844 {
1845 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1846 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001847}
1848
Brandon Jones59770802018-04-02 13:18:42 -07001849void Context::getBooleani_vRobust(GLenum target,
1850 GLuint index,
1851 GLsizei bufSize,
1852 GLsizei *length,
1853 GLboolean *data)
1854{
1855 getBooleani_v(target, index, data);
1856}
1857
Corentin Wallez336129f2017-10-17 15:55:40 -04001858void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001859{
1860 Buffer *buffer = mGLState.getTargetBuffer(target);
1861 QueryBufferParameteriv(buffer, pname, params);
1862}
1863
Brandon Jones59770802018-04-02 13:18:42 -07001864void Context::getBufferParameterivRobust(BufferBinding target,
1865 GLenum pname,
1866 GLsizei bufSize,
1867 GLsizei *length,
1868 GLint *params)
1869{
1870 getBufferParameteriv(target, pname, params);
1871}
1872
He Yunchao010e4db2017-03-03 14:22:06 +08001873void Context::getFramebufferAttachmentParameteriv(GLenum target,
1874 GLenum attachment,
1875 GLenum pname,
1876 GLint *params)
1877{
1878 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001879 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001880}
1881
Brandon Jones59770802018-04-02 13:18:42 -07001882void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1883 GLenum attachment,
1884 GLenum pname,
1885 GLsizei bufSize,
1886 GLsizei *length,
1887 GLint *params)
1888{
1889 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1890}
1891
He Yunchao010e4db2017-03-03 14:22:06 +08001892void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1893{
1894 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1895 QueryRenderbufferiv(this, renderbuffer, pname, params);
1896}
1897
Brandon Jones59770802018-04-02 13:18:42 -07001898void Context::getRenderbufferParameterivRobust(GLenum target,
1899 GLenum pname,
1900 GLsizei bufSize,
1901 GLsizei *length,
1902 GLint *params)
1903{
1904 getRenderbufferParameteriv(target, pname, params);
1905}
1906
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001907void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001908{
1909 Texture *texture = getTargetTexture(target);
1910 QueryTexParameterfv(texture, pname, params);
1911}
1912
Brandon Jones59770802018-04-02 13:18:42 -07001913void Context::getTexParameterfvRobust(TextureType target,
1914 GLenum pname,
1915 GLsizei bufSize,
1916 GLsizei *length,
1917 GLfloat *params)
1918{
1919 getTexParameterfv(target, pname, params);
1920}
1921
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001922void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001923{
1924 Texture *texture = getTargetTexture(target);
1925 QueryTexParameteriv(texture, pname, params);
1926}
Jiajia Qin5451d532017-11-16 17:16:34 +08001927
Brandon Jones59770802018-04-02 13:18:42 -07001928void Context::getTexParameterivRobust(TextureType target,
1929 GLenum pname,
1930 GLsizei bufSize,
1931 GLsizei *length,
1932 GLint *params)
1933{
1934 getTexParameteriv(target, pname, params);
1935}
1936
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001937void Context::getTexParameterIivRobust(TextureType target,
1938 GLenum pname,
1939 GLsizei bufSize,
1940 GLsizei *length,
1941 GLint *params)
1942{
1943 UNIMPLEMENTED();
1944}
1945
1946void Context::getTexParameterIuivRobust(TextureType target,
1947 GLenum pname,
1948 GLsizei bufSize,
1949 GLsizei *length,
1950 GLuint *params)
1951{
1952 UNIMPLEMENTED();
1953}
1954
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001955void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001956{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001957 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001958 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001959}
1960
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001961void Context::getTexLevelParameterivRobust(TextureTarget target,
1962 GLint level,
1963 GLenum pname,
1964 GLsizei bufSize,
1965 GLsizei *length,
1966 GLint *params)
1967{
1968 UNIMPLEMENTED();
1969}
1970
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001971void Context::getTexLevelParameterfv(TextureTarget target,
1972 GLint level,
1973 GLenum pname,
1974 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001975{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001976 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001977 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001978}
1979
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001980void Context::getTexLevelParameterfvRobust(TextureTarget target,
1981 GLint level,
1982 GLenum pname,
1983 GLsizei bufSize,
1984 GLsizei *length,
1985 GLfloat *params)
1986{
1987 UNIMPLEMENTED();
1988}
1989
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001990void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001991{
1992 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001993 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001994 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001995}
1996
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001997void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001998{
1999 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002000 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002001 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002002}
2003
Brandon Jones59770802018-04-02 13:18:42 -07002004void Context::texParameterfvRobust(TextureType target,
2005 GLenum pname,
2006 GLsizei bufSize,
2007 const GLfloat *params)
2008{
2009 texParameterfv(target, pname, params);
2010}
2011
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002012void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002013{
2014 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002015 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002016 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002017}
2018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002019void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002020{
2021 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002022 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002023 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002024}
2025
Brandon Jones59770802018-04-02 13:18:42 -07002026void Context::texParameterivRobust(TextureType target,
2027 GLenum pname,
2028 GLsizei bufSize,
2029 const GLint *params)
2030{
2031 texParameteriv(target, pname, params);
2032}
2033
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002034void Context::texParameterIivRobust(TextureType target,
2035 GLenum pname,
2036 GLsizei bufSize,
2037 const GLint *params)
2038{
2039 UNIMPLEMENTED();
2040}
2041
2042void Context::texParameterIuivRobust(TextureType target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 const GLuint *params)
2046{
2047 UNIMPLEMENTED();
2048}
2049
Jamie Madill675fe712016-12-19 13:07:54 -05002050void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002051{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002052 // No-op if zero count
2053 if (count == 0)
2054 {
2055 return;
2056 }
2057
Jamie Madill05b35b22017-10-03 09:01:44 -04002058 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002059 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002060 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002061}
2062
Jamie Madill675fe712016-12-19 13:07:54 -05002063void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002064{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002065 // No-op if zero count
2066 if (count == 0 || instanceCount == 0)
2067 {
2068 return;
2069 }
2070
Jamie Madill05b35b22017-10-03 09:01:44 -04002071 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002072 ANGLE_CONTEXT_TRY(
2073 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002074 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2075 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002076}
2077
Jamie Madill876429b2017-04-20 15:46:24 -04002078void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002079{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002080 // No-op if zero count
2081 if (count == 0)
2082 {
2083 return;
2084 }
2085
Jamie Madill05b35b22017-10-03 09:01:44 -04002086 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002087 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002088}
2089
Jamie Madill675fe712016-12-19 13:07:54 -05002090void Context::drawElementsInstanced(GLenum mode,
2091 GLsizei count,
2092 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002093 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002094 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002095{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002096 // No-op if zero count
2097 if (count == 0 || instances == 0)
2098 {
2099 return;
2100 }
2101
Jamie Madill05b35b22017-10-03 09:01:44 -04002102 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002103 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002104 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002105}
2106
Jamie Madill675fe712016-12-19 13:07:54 -05002107void Context::drawRangeElements(GLenum mode,
2108 GLuint start,
2109 GLuint end,
2110 GLsizei count,
2111 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002112 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002113{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002114 // No-op if zero count
2115 if (count == 0)
2116 {
2117 return;
2118 }
2119
Jamie Madill05b35b22017-10-03 09:01:44 -04002120 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002121 ANGLE_CONTEXT_TRY(
2122 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002123}
2124
Jamie Madill876429b2017-04-20 15:46:24 -04002125void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002126{
Jamie Madill05b35b22017-10-03 09:01:44 -04002127 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002128 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002129}
2130
Jamie Madill876429b2017-04-20 15:46:24 -04002131void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002132{
Jamie Madill05b35b22017-10-03 09:01:44 -04002133 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002134 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002135}
2136
Jamie Madill675fe712016-12-19 13:07:54 -05002137void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002138{
Jamie Madillafa02a22017-11-23 12:57:38 -05002139 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002140}
2141
Jamie Madill675fe712016-12-19 13:07:54 -05002142void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002143{
Jamie Madillafa02a22017-11-23 12:57:38 -05002144 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002145}
2146
Austin Kinross6ee1e782015-05-29 17:05:37 -07002147void Context::insertEventMarker(GLsizei length, const char *marker)
2148{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002149 ASSERT(mImplementation);
2150 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002151}
2152
2153void Context::pushGroupMarker(GLsizei length, const char *marker)
2154{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002155 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002156
2157 if (marker == nullptr)
2158 {
2159 // From the EXT_debug_marker spec,
2160 // "If <marker> is null then an empty string is pushed on the stack."
2161 mImplementation->pushGroupMarker(length, "");
2162 }
2163 else
2164 {
2165 mImplementation->pushGroupMarker(length, marker);
2166 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002167}
2168
2169void Context::popGroupMarker()
2170{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002171 ASSERT(mImplementation);
2172 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002173}
2174
Geoff Langd8605522016-04-13 10:19:12 -04002175void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2176{
2177 Program *programObject = getProgram(program);
2178 ASSERT(programObject);
2179
2180 programObject->bindUniformLocation(location, name);
2181}
2182
Brandon Jones59770802018-04-02 13:18:42 -07002183void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002184{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002185 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002186}
2187
Brandon Jones59770802018-04-02 13:18:42 -07002188void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002189{
2190 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2191}
2192
Brandon Jones59770802018-04-02 13:18:42 -07002193void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002194{
2195 GLfloat I[16];
2196 angle::Matrix<GLfloat>::setToIdentity(I);
2197
2198 mGLState.loadPathRenderingMatrix(matrixMode, I);
2199}
2200
2201void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2202{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002203 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002204 if (!pathObj)
2205 return;
2206
2207 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002208 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002209
2210 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2211}
2212
2213void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2214{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002215 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002216 if (!pathObj)
2217 return;
2218
2219 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002220 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002221
2222 mImplementation->stencilStrokePath(pathObj, reference, mask);
2223}
2224
2225void Context::coverFillPath(GLuint path, GLenum coverMode)
2226{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002227 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228 if (!pathObj)
2229 return;
2230
2231 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002232 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233
2234 mImplementation->coverFillPath(pathObj, coverMode);
2235}
2236
2237void Context::coverStrokePath(GLuint path, GLenum coverMode)
2238{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002239 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240 if (!pathObj)
2241 return;
2242
2243 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002244 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002245
2246 mImplementation->coverStrokePath(pathObj, coverMode);
2247}
2248
2249void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2250{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002251 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252 if (!pathObj)
2253 return;
2254
2255 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002256 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002257
2258 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2259}
2260
2261void Context::stencilThenCoverStrokePath(GLuint path,
2262 GLint reference,
2263 GLuint mask,
2264 GLenum coverMode)
2265{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002266 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002267 if (!pathObj)
2268 return;
2269
2270 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002271 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002272
2273 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2274}
2275
Sami Väisänend59ca052016-06-21 16:10:00 +03002276void Context::coverFillPathInstanced(GLsizei numPaths,
2277 GLenum pathNameType,
2278 const void *paths,
2279 GLuint pathBase,
2280 GLenum coverMode,
2281 GLenum transformType,
2282 const GLfloat *transformValues)
2283{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002284 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002285
2286 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002287 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002288
2289 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2290}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002291
Sami Väisänend59ca052016-06-21 16:10:00 +03002292void Context::coverStrokePathInstanced(GLsizei numPaths,
2293 GLenum pathNameType,
2294 const void *paths,
2295 GLuint pathBase,
2296 GLenum coverMode,
2297 GLenum transformType,
2298 const GLfloat *transformValues)
2299{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002300 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002301
2302 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002303 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002304
2305 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2306 transformValues);
2307}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002308
Sami Väisänend59ca052016-06-21 16:10:00 +03002309void Context::stencilFillPathInstanced(GLsizei numPaths,
2310 GLenum pathNameType,
2311 const void *paths,
2312 GLuint pathBase,
2313 GLenum fillMode,
2314 GLuint mask,
2315 GLenum transformType,
2316 const GLfloat *transformValues)
2317{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002318 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002319
2320 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002321 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002322
2323 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2324 transformValues);
2325}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002326
Sami Väisänend59ca052016-06-21 16:10:00 +03002327void Context::stencilStrokePathInstanced(GLsizei numPaths,
2328 GLenum pathNameType,
2329 const void *paths,
2330 GLuint pathBase,
2331 GLint reference,
2332 GLuint mask,
2333 GLenum transformType,
2334 const GLfloat *transformValues)
2335{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002336 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002337
2338 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002339 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002340
2341 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2342 transformValues);
2343}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002344
Sami Väisänend59ca052016-06-21 16:10:00 +03002345void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2346 GLenum pathNameType,
2347 const void *paths,
2348 GLuint pathBase,
2349 GLenum fillMode,
2350 GLuint mask,
2351 GLenum coverMode,
2352 GLenum transformType,
2353 const GLfloat *transformValues)
2354{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002355 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002356
2357 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002358 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002359
2360 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2361 transformType, transformValues);
2362}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002363
Sami Väisänend59ca052016-06-21 16:10:00 +03002364void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2365 GLenum pathNameType,
2366 const void *paths,
2367 GLuint pathBase,
2368 GLint reference,
2369 GLuint mask,
2370 GLenum coverMode,
2371 GLenum transformType,
2372 const GLfloat *transformValues)
2373{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002374 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002375
2376 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002377 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002378
2379 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2380 transformType, transformValues);
2381}
2382
Sami Väisänen46eaa942016-06-29 10:26:37 +03002383void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2384{
2385 auto *programObject = getProgram(program);
2386
2387 programObject->bindFragmentInputLocation(location, name);
2388}
2389
2390void Context::programPathFragmentInputGen(GLuint program,
2391 GLint location,
2392 GLenum genMode,
2393 GLint components,
2394 const GLfloat *coeffs)
2395{
2396 auto *programObject = getProgram(program);
2397
Jamie Madillbd044ed2017-06-05 12:59:21 -04002398 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002399}
2400
jchen1015015f72017-03-16 13:54:21 +08002401GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2402{
jchen10fd7c3b52017-03-21 15:36:03 +08002403 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002404 return QueryProgramResourceIndex(programObject, programInterface, name);
2405}
2406
jchen10fd7c3b52017-03-21 15:36:03 +08002407void Context::getProgramResourceName(GLuint program,
2408 GLenum programInterface,
2409 GLuint index,
2410 GLsizei bufSize,
2411 GLsizei *length,
2412 GLchar *name)
2413{
2414 const auto *programObject = getProgram(program);
2415 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2416}
2417
jchen10191381f2017-04-11 13:59:04 +08002418GLint Context::getProgramResourceLocation(GLuint program,
2419 GLenum programInterface,
2420 const GLchar *name)
2421{
2422 const auto *programObject = getProgram(program);
2423 return QueryProgramResourceLocation(programObject, programInterface, name);
2424}
2425
jchen10880683b2017-04-12 16:21:55 +08002426void Context::getProgramResourceiv(GLuint program,
2427 GLenum programInterface,
2428 GLuint index,
2429 GLsizei propCount,
2430 const GLenum *props,
2431 GLsizei bufSize,
2432 GLsizei *length,
2433 GLint *params)
2434{
2435 const auto *programObject = getProgram(program);
2436 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2437 length, params);
2438}
2439
jchen10d9cd7b72017-08-30 15:04:25 +08002440void Context::getProgramInterfaceiv(GLuint program,
2441 GLenum programInterface,
2442 GLenum pname,
2443 GLint *params)
2444{
2445 const auto *programObject = getProgram(program);
2446 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2447}
2448
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002449void Context::getProgramInterfaceivRobust(GLuint program,
2450 GLenum programInterface,
2451 GLenum pname,
2452 GLsizei bufSize,
2453 GLsizei *length,
2454 GLint *params)
2455{
2456 UNIMPLEMENTED();
2457}
2458
Jamie Madill427064d2018-04-13 16:20:34 -04002459void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002460{
Geoff Lang7b19a492018-04-20 09:31:52 -04002461 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002462 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002463 GLenum code = error.getCode();
2464 mErrors.insert(code);
2465 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2466 {
2467 markContextLost();
2468 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002469
Geoff Langee6884e2017-11-09 16:51:11 -05002470 ASSERT(!error.getMessage().empty());
2471 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2472 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002473 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002474}
2475
2476// Get one of the recorded errors and clear its flag, if any.
2477// [OpenGL ES 2.0.24] section 2.5 page 13.
2478GLenum Context::getError()
2479{
Geoff Langda5777c2014-07-11 09:52:58 -04002480 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481 {
Geoff Langda5777c2014-07-11 09:52:58 -04002482 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002483 }
Geoff Langda5777c2014-07-11 09:52:58 -04002484 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485 {
Geoff Langda5777c2014-07-11 09:52:58 -04002486 GLenum error = *mErrors.begin();
2487 mErrors.erase(mErrors.begin());
2488 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002489 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490}
2491
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002492// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002493void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002494{
2495 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002496 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002497 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002498 mContextLostForced = true;
2499 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002500 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002501}
2502
Jamie Madill427064d2018-04-13 16:20:34 -04002503bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002504{
2505 return mContextLost;
2506}
2507
Jamie Madillfa920eb2018-01-04 11:45:50 -05002508GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510 // Even if the application doesn't want to know about resets, we want to know
2511 // as it will allow us to skip all the calls.
2512 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002515 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002516 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002517 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002518
2519 // EXT_robustness, section 2.6: If the reset notification behavior is
2520 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2521 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2522 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002523 }
2524
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002525 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2526 // status should be returned at least once, and GL_NO_ERROR should be returned
2527 // once the device has finished resetting.
2528 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530 ASSERT(mResetStatus == GL_NO_ERROR);
2531 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002532
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002533 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002534 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002536 }
2537 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002538 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002540 // If markContextLost was used to mark the context lost then
2541 // assume that is not recoverable, and continue to report the
2542 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002543 mResetStatus = mImplementation->getResetStatus();
2544 }
Jamie Madill893ab082014-05-16 16:56:10 -04002545
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002546 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002547}
2548
2549bool Context::isResetNotificationEnabled()
2550{
2551 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2552}
2553
Corentin Walleze3b10e82015-05-20 11:06:25 -04002554const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002555{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002556 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002557}
2558
2559EGLenum Context::getClientType() const
2560{
2561 return mClientType;
2562}
2563
2564EGLenum Context::getRenderBuffer() const
2565{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002566 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2567 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002568 {
2569 return EGL_NONE;
2570 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002571
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002572 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002573 ASSERT(backAttachment != nullptr);
2574 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002575}
2576
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002577VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002578{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002579 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002580 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2581 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002582 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002583 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2584 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002585
Jamie Madill96a483b2017-06-27 16:49:21 -04002586 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002587 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002588
2589 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002590}
2591
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002592TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002593{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002594 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002595 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2596 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002597 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002598 transformFeedback =
2599 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002600 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002601 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002602 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002603
2604 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002605}
2606
2607bool Context::isVertexArrayGenerated(GLuint vertexArray)
2608{
Jamie Madill96a483b2017-06-27 16:49:21 -04002609 ASSERT(mVertexArrayMap.contains(0));
2610 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002611}
2612
2613bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2614{
Jamie Madill96a483b2017-06-27 16:49:21 -04002615 ASSERT(mTransformFeedbackMap.contains(0));
2616 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002617}
2618
Shannon Woods53a94a82014-06-24 15:20:36 -04002619void Context::detachTexture(GLuint texture)
2620{
2621 // Simple pass-through to State's detachTexture method, as textures do not require
2622 // allocation map management either here or in the resource manager at detach time.
2623 // Zero textures are held by the Context, and we don't attempt to request them from
2624 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002625 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002626}
2627
James Darpinian4d9d4832018-03-13 12:43:28 -07002628void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629{
Yuly Novikov5807a532015-12-03 13:01:22 -05002630 // Simple pass-through to State's detachBuffer method, since
2631 // only buffer attachments to container objects that are bound to the current context
2632 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002633
Yuly Novikov5807a532015-12-03 13:01:22 -05002634 // [OpenGL ES 3.2] section 5.1.2 page 45:
2635 // Attachments to unbound container objects, such as
2636 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2637 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002638 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639}
2640
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641void Context::detachFramebuffer(GLuint framebuffer)
2642{
Shannon Woods53a94a82014-06-24 15:20:36 -04002643 // Framebuffer detachment is handled by Context, because 0 is a valid
2644 // Framebuffer object, and a pointer to it must be passed from Context
2645 // to State at binding time.
2646
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002648 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2649 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2650 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002651
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002652 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002653 {
2654 bindReadFramebuffer(0);
2655 }
2656
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002657 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002658 {
2659 bindDrawFramebuffer(0);
2660 }
2661}
2662
2663void Context::detachRenderbuffer(GLuint renderbuffer)
2664{
Jamie Madilla02315b2017-02-23 14:14:47 -05002665 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666}
2667
Jamie Madill57a89722013-07-02 11:57:03 -04002668void Context::detachVertexArray(GLuint vertexArray)
2669{
Jamie Madill77a72f62015-04-14 11:18:32 -04002670 // Vertex array detachment is handled by Context, because 0 is a valid
2671 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002672 // binding time.
2673
Jamie Madill57a89722013-07-02 11:57:03 -04002674 // [OpenGL ES 3.0.2] section 2.10 page 43:
2675 // If a vertex array object that is currently bound is deleted, the binding
2676 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002677 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002678 {
2679 bindVertexArray(0);
2680 }
2681}
2682
Geoff Langc8058452014-02-03 12:04:11 -05002683void Context::detachTransformFeedback(GLuint transformFeedback)
2684{
Corentin Walleza2257da2016-04-19 16:43:12 -04002685 // Transform feedback detachment is handled by Context, because 0 is a valid
2686 // transform feedback, and a pointer to it must be passed from Context to State at
2687 // binding time.
2688
2689 // The OpenGL specification doesn't mention what should happen when the currently bound
2690 // transform feedback object is deleted. Since it is a container object, we treat it like
2691 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002692 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002693 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002694 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002695 }
Geoff Langc8058452014-02-03 12:04:11 -05002696}
2697
Jamie Madilldc356042013-07-19 16:36:57 -04002698void Context::detachSampler(GLuint sampler)
2699{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002700 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002701}
2702
Yunchao Hea336b902017-08-02 16:05:21 +08002703void Context::detachProgramPipeline(GLuint pipeline)
2704{
2705 mGLState.detachProgramPipeline(this, pipeline);
2706}
2707
Jamie Madill3ef140a2017-08-26 23:11:21 -04002708void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002709{
Shaodde78e82017-05-22 14:13:27 +08002710 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002711}
2712
Jamie Madille29d1672013-07-19 16:36:57 -04002713void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2714{
Geoff Langc1984ed2016-10-07 12:41:00 -04002715 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002716 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002717 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002718 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002719}
Jamie Madille29d1672013-07-19 16:36:57 -04002720
Geoff Langc1984ed2016-10-07 12:41:00 -04002721void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2722{
2723 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002724 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002725 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002726 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002727}
2728
Brandon Jones59770802018-04-02 13:18:42 -07002729void Context::samplerParameterivRobust(GLuint sampler,
2730 GLenum pname,
2731 GLsizei bufSize,
2732 const GLint *param)
2733{
2734 samplerParameteriv(sampler, pname, param);
2735}
2736
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002737void Context::samplerParameterIivRobust(GLuint sampler,
2738 GLenum pname,
2739 GLsizei bufSize,
2740 const GLint *param)
2741{
2742 UNIMPLEMENTED();
2743}
2744
2745void Context::samplerParameterIuivRobust(GLuint sampler,
2746 GLenum pname,
2747 GLsizei bufSize,
2748 const GLuint *param)
2749{
2750 UNIMPLEMENTED();
2751}
2752
Jamie Madille29d1672013-07-19 16:36:57 -04002753void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2754{
Geoff Langc1984ed2016-10-07 12:41:00 -04002755 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002756 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002757 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002758 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002759}
2760
Geoff Langc1984ed2016-10-07 12:41:00 -04002761void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002762{
Geoff Langc1984ed2016-10-07 12:41:00 -04002763 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002764 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002765 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002766 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002767}
2768
Brandon Jones59770802018-04-02 13:18:42 -07002769void Context::samplerParameterfvRobust(GLuint sampler,
2770 GLenum pname,
2771 GLsizei bufSize,
2772 const GLfloat *param)
2773{
2774 samplerParameterfv(sampler, pname, param);
2775}
2776
Geoff Langc1984ed2016-10-07 12:41:00 -04002777void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002778{
Geoff Langc1984ed2016-10-07 12:41:00 -04002779 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002780 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002781 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002782 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002783}
Jamie Madill9675b802013-07-19 16:36:59 -04002784
Brandon Jones59770802018-04-02 13:18:42 -07002785void Context::getSamplerParameterivRobust(GLuint sampler,
2786 GLenum pname,
2787 GLsizei bufSize,
2788 GLsizei *length,
2789 GLint *params)
2790{
2791 getSamplerParameteriv(sampler, pname, params);
2792}
2793
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002794void Context::getSamplerParameterIivRobust(GLuint sampler,
2795 GLenum pname,
2796 GLsizei bufSize,
2797 GLsizei *length,
2798 GLint *params)
2799{
2800 UNIMPLEMENTED();
2801}
2802
2803void Context::getSamplerParameterIuivRobust(GLuint sampler,
2804 GLenum pname,
2805 GLsizei bufSize,
2806 GLsizei *length,
2807 GLuint *params)
2808{
2809 UNIMPLEMENTED();
2810}
2811
Geoff Langc1984ed2016-10-07 12:41:00 -04002812void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2813{
2814 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002815 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002816 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002817 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002818}
2819
Brandon Jones59770802018-04-02 13:18:42 -07002820void Context::getSamplerParameterfvRobust(GLuint sampler,
2821 GLenum pname,
2822 GLsizei bufSize,
2823 GLsizei *length,
2824 GLfloat *params)
2825{
2826 getSamplerParameterfv(sampler, pname, params);
2827}
2828
Olli Etuahof0fee072016-03-30 15:11:58 +03002829void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2830{
2831 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002832 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002833}
2834
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002835void Context::initRendererString()
2836{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002837 std::ostringstream rendererString;
2838 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002839 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002840 rendererString << ")";
2841
Geoff Langcec35902014-04-16 10:52:36 -04002842 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002843}
2844
Geoff Langc339c4e2016-11-29 10:37:36 -05002845void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002846{
Geoff Langc339c4e2016-11-29 10:37:36 -05002847 const Version &clientVersion = getClientVersion();
2848
2849 std::ostringstream versionString;
2850 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2851 << ANGLE_VERSION_STRING << ")";
2852 mVersionString = MakeStaticString(versionString.str());
2853
2854 std::ostringstream shadingLanguageVersionString;
2855 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2856 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2857 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2858 << ")";
2859 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002860}
2861
Geoff Langcec35902014-04-16 10:52:36 -04002862void Context::initExtensionStrings()
2863{
Geoff Langc339c4e2016-11-29 10:37:36 -05002864 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2865 std::ostringstream combinedStringStream;
2866 std::copy(strings.begin(), strings.end(),
2867 std::ostream_iterator<const char *>(combinedStringStream, " "));
2868 return MakeStaticString(combinedStringStream.str());
2869 };
2870
2871 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002872 for (const auto &extensionString : mExtensions.getStrings())
2873 {
2874 mExtensionStrings.push_back(MakeStaticString(extensionString));
2875 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002876 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002877
Geoff Langc339c4e2016-11-29 10:37:36 -05002878 mRequestableExtensionStrings.clear();
2879 for (const auto &extensionInfo : GetExtensionInfoMap())
2880 {
2881 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002882 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002883 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002884 {
2885 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2886 }
2887 }
2888 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002889}
2890
Geoff Langc339c4e2016-11-29 10:37:36 -05002891const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002892{
Geoff Langc339c4e2016-11-29 10:37:36 -05002893 switch (name)
2894 {
2895 case GL_VENDOR:
2896 return reinterpret_cast<const GLubyte *>("Google Inc.");
2897
2898 case GL_RENDERER:
2899 return reinterpret_cast<const GLubyte *>(mRendererString);
2900
2901 case GL_VERSION:
2902 return reinterpret_cast<const GLubyte *>(mVersionString);
2903
2904 case GL_SHADING_LANGUAGE_VERSION:
2905 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2906
2907 case GL_EXTENSIONS:
2908 return reinterpret_cast<const GLubyte *>(mExtensionString);
2909
2910 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2911 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2912
2913 default:
2914 UNREACHABLE();
2915 return nullptr;
2916 }
Geoff Langcec35902014-04-16 10:52:36 -04002917}
2918
Geoff Langc339c4e2016-11-29 10:37:36 -05002919const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002920{
Geoff Langc339c4e2016-11-29 10:37:36 -05002921 switch (name)
2922 {
2923 case GL_EXTENSIONS:
2924 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2925
2926 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2927 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2928
2929 default:
2930 UNREACHABLE();
2931 return nullptr;
2932 }
Geoff Langcec35902014-04-16 10:52:36 -04002933}
2934
2935size_t Context::getExtensionStringCount() const
2936{
2937 return mExtensionStrings.size();
2938}
2939
Geoff Lang111a99e2017-10-17 10:58:41 -04002940bool Context::isExtensionRequestable(const char *name)
2941{
2942 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2943 auto extension = extensionInfos.find(name);
2944
Geoff Lang111a99e2017-10-17 10:58:41 -04002945 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002946 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002947}
2948
Geoff Langc339c4e2016-11-29 10:37:36 -05002949void Context::requestExtension(const char *name)
2950{
2951 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2952 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2953 const auto &extension = extensionInfos.at(name);
2954 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002955 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002956
2957 if (mExtensions.*(extension.ExtensionsMember))
2958 {
2959 // Extension already enabled
2960 return;
2961 }
2962
2963 mExtensions.*(extension.ExtensionsMember) = true;
2964 updateCaps();
2965 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002966
Jamie Madill2f348d22017-06-05 10:50:59 -04002967 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2968 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002969
Jamie Madill81c2e252017-09-09 23:32:46 -04002970 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2971 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002972 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002973 for (auto &zeroTexture : mZeroTextures)
2974 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002975 if (zeroTexture.get() != nullptr)
2976 {
2977 zeroTexture->signalDirty(this, InitState::Initialized);
2978 }
Geoff Lang9aded172017-04-05 11:07:56 -04002979 }
2980
2981 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002982}
2983
2984size_t Context::getRequestableExtensionStringCount() const
2985{
2986 return mRequestableExtensionStrings.size();
2987}
2988
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002989void Context::beginTransformFeedback(GLenum primitiveMode)
2990{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002991 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002992 ASSERT(transformFeedback != nullptr);
2993 ASSERT(!transformFeedback->isPaused());
2994
Jamie Madill6c1f6712017-02-14 19:08:04 -05002995 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002996}
2997
2998bool Context::hasActiveTransformFeedback(GLuint program) const
2999{
3000 for (auto pair : mTransformFeedbackMap)
3001 {
3002 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3003 {
3004 return true;
3005 }
3006 }
3007 return false;
3008}
3009
Geoff Langb0f917f2017-12-05 13:41:54 -05003010Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
3011 bool robustResourceInit) const
3012{
3013 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3014
3015 if (getClientVersion() < ES_2_0)
3016 {
3017 // Default extensions for GLES1
3018 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003019 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003020 }
3021
3022 if (getClientVersion() < ES_3_0)
3023 {
3024 // Disable ES3+ extensions
3025 supportedExtensions.colorBufferFloat = false;
3026 supportedExtensions.eglImageExternalEssl3 = false;
3027 supportedExtensions.textureNorm16 = false;
3028 supportedExtensions.multiview = false;
3029 supportedExtensions.maxViews = 1u;
3030 }
3031
3032 if (getClientVersion() < ES_3_1)
3033 {
3034 // Disable ES3.1+ extensions
3035 supportedExtensions.geometryShader = false;
3036 }
3037
3038 if (getClientVersion() > ES_2_0)
3039 {
3040 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3041 // supportedExtensions.sRGB = false;
3042 }
3043
3044 // Some extensions are always available because they are implemented in the GL layer.
3045 supportedExtensions.bindUniformLocation = true;
3046 supportedExtensions.vertexArrayObject = true;
3047 supportedExtensions.bindGeneratesResource = true;
3048 supportedExtensions.clientArrays = true;
3049 supportedExtensions.requestExtension = true;
3050
3051 // Enable the no error extension if the context was created with the flag.
3052 supportedExtensions.noError = mSkipValidation;
3053
3054 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3055 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3056
3057 // Explicitly enable GL_KHR_debug
3058 supportedExtensions.debug = true;
3059 supportedExtensions.maxDebugMessageLength = 1024;
3060 supportedExtensions.maxDebugLoggedMessages = 1024;
3061 supportedExtensions.maxDebugGroupStackDepth = 1024;
3062 supportedExtensions.maxLabelLength = 1024;
3063
3064 // Explicitly enable GL_ANGLE_robust_client_memory
3065 supportedExtensions.robustClientMemory = true;
3066
3067 // Determine robust resource init availability from EGL.
3068 supportedExtensions.robustResourceInitialization = robustResourceInit;
3069
3070 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3071 // supports it.
3072 supportedExtensions.robustBufferAccessBehavior =
3073 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3074
3075 // Enable the cache control query unconditionally.
3076 supportedExtensions.programCacheControl = true;
3077
3078 return supportedExtensions;
3079}
3080
Geoff Langb433e872017-10-05 14:01:47 -04003081void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003082{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003083 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003084
Geoff Langb0f917f2017-12-05 13:41:54 -05003085 mSupportedExtensions = generateSupportedExtensions(displayExtensions, robustResourceInit);
3086 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003087
3088 mLimitations = mImplementation->getNativeLimitations();
3089
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003090 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3091 if (getClientVersion() < Version(2, 0))
3092 {
3093 mCaps.maxMultitextureUnits = 4;
3094 mCaps.maxClipPlanes = 6;
3095 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003096 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3097 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3098 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003099 }
3100
Geoff Lang301d1612014-07-09 10:34:37 -04003101 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003102 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003103
Jamie Madill0f80ed82017-09-19 00:24:56 -04003104 if (getClientVersion() < ES_3_1)
3105 {
3106 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3107 }
3108 else
3109 {
3110 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3111 }
Geoff Lang301d1612014-07-09 10:34:37 -04003112
Jiawei Shao54aafe52018-04-27 14:54:57 +08003113 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3114 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003115 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3116 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3117
3118 // Limit textures as well, so we can use fast bitsets with texture bindings.
3119 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003120 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3121 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3122 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3123 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003124
Jiawei Shaodb342272017-09-27 10:21:45 +08003125 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3126
Geoff Langc287ea62016-09-16 14:46:51 -04003127 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003128 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003129 for (const auto &extensionInfo : GetExtensionInfoMap())
3130 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003131 // If the user has requested that extensions start disabled and they are requestable,
3132 // disable them.
3133 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003134 {
3135 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3136 }
3137 }
3138
3139 // Generate texture caps
3140 updateCaps();
3141}
3142
3143void Context::updateCaps()
3144{
Geoff Lang900013c2014-07-07 11:32:19 -04003145 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003146 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003147
Jamie Madill7b62cf92017-11-02 15:20:49 -04003148 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003149 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003150 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003151 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003152
Geoff Lang0d8b7242015-09-09 14:56:53 -04003153 // Update the format caps based on the client version and extensions.
3154 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3155 // ES3.
3156 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003157 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003158 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003159 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003160 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003161 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003162
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003163 // OpenGL ES does not support multisampling with non-rendererable formats
3164 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003165 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003166 (getClientVersion() < ES_3_1 &&
3167 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003168 {
Geoff Langd87878e2014-09-19 15:42:59 -04003169 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003170 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003171 else
3172 {
3173 // We may have limited the max samples for some required renderbuffer formats due to
3174 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3175 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3176
3177 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3178 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3179 // exception of signed and unsigned integer formats."
3180 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3181 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3182 {
3183 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3184 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3185 }
3186
3187 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3188 if (getClientVersion() >= ES_3_1)
3189 {
3190 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3191 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3192 // the exception that the signed and unsigned integer formats are required only to
3193 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3194 // multisamples, which must be at least one."
3195 if (formatInfo.componentType == GL_INT ||
3196 formatInfo.componentType == GL_UNSIGNED_INT)
3197 {
3198 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3199 }
3200
3201 // GLES 3.1 section 19.3.1.
3202 if (formatCaps.texturable)
3203 {
3204 if (formatInfo.depthBits > 0)
3205 {
3206 mCaps.maxDepthTextureSamples =
3207 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3208 }
3209 else if (formatInfo.redBits > 0)
3210 {
3211 mCaps.maxColorTextureSamples =
3212 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3213 }
3214 }
3215 }
3216 }
Geoff Langd87878e2014-09-19 15:42:59 -04003217
3218 if (formatCaps.texturable && formatInfo.compressed)
3219 {
Geoff Langca271392017-04-05 12:30:00 -04003220 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003221 }
3222
Geoff Langca271392017-04-05 12:30:00 -04003223 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003224 }
Jamie Madill32447362017-06-28 14:53:52 -04003225
3226 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003227 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003228 {
3229 mMemoryProgramCache = nullptr;
3230 }
Corentin Walleze4477002017-12-01 14:39:58 -05003231
3232 // Compute which buffer types are allowed
3233 mValidBufferBindings.reset();
3234 mValidBufferBindings.set(BufferBinding::ElementArray);
3235 mValidBufferBindings.set(BufferBinding::Array);
3236
3237 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3238 {
3239 mValidBufferBindings.set(BufferBinding::PixelPack);
3240 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3241 }
3242
3243 if (getClientVersion() >= ES_3_0)
3244 {
3245 mValidBufferBindings.set(BufferBinding::CopyRead);
3246 mValidBufferBindings.set(BufferBinding::CopyWrite);
3247 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3248 mValidBufferBindings.set(BufferBinding::Uniform);
3249 }
3250
3251 if (getClientVersion() >= ES_3_1)
3252 {
3253 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3254 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3255 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3256 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3257 }
Geoff Lang493daf52014-07-03 13:38:44 -04003258}
3259
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003260void Context::initWorkarounds()
3261{
Jamie Madill761b02c2017-06-23 16:27:06 -04003262 // Apply back-end workarounds.
3263 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3264
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003265 // Lose the context upon out of memory error if the application is
3266 // expecting to watch for those events.
3267 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3268}
3269
Jamie Madill05b35b22017-10-03 09:01:44 -04003270Error Context::prepareForDraw()
3271{
Geoff Langa8cb2872018-03-09 16:09:40 -05003272 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003273
3274 if (isRobustResourceInitEnabled())
3275 {
3276 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3277 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3278 }
3279
Geoff Langa8cb2872018-03-09 16:09:40 -05003280 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003281 return NoError();
3282}
3283
3284Error Context::prepareForClear(GLbitfield mask)
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()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003288 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003289 return NoError();
3290}
3291
3292Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3293{
Geoff Langa8cb2872018-03-09 16:09:40 -05003294 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003295 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3296 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003297 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003298 return NoError();
3299}
3300
Geoff Langa8cb2872018-03-09 16:09:40 -05003301Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003302{
Geoff Langa8cb2872018-03-09 16:09:40 -05003303 ANGLE_TRY(syncDirtyObjects());
3304 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003305 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003306}
3307
Geoff Langa8cb2872018-03-09 16:09:40 -05003308Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003309{
Geoff Langa8cb2872018-03-09 16:09:40 -05003310 ANGLE_TRY(syncDirtyObjects(objectMask));
3311 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003312 return NoError();
3313}
3314
Geoff Langa8cb2872018-03-09 16:09:40 -05003315Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003316{
3317 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3318 mImplementation->syncState(this, dirtyBits);
3319 mGLState.clearDirtyBits();
3320 return NoError();
3321}
3322
Geoff Langa8cb2872018-03-09 16:09:40 -05003323Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003325 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003326 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003327 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003328 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003329}
Jamie Madillc29968b2016-01-20 11:17:23 -05003330
Geoff Langa8cb2872018-03-09 16:09:40 -05003331Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003332{
3333 return mGLState.syncDirtyObjects(this);
3334}
3335
Geoff Langa8cb2872018-03-09 16:09:40 -05003336Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003337{
3338 return mGLState.syncDirtyObjects(this, objectMask);
3339}
3340
Jamie Madillc29968b2016-01-20 11:17:23 -05003341void Context::blitFramebuffer(GLint srcX0,
3342 GLint srcY0,
3343 GLint srcX1,
3344 GLint srcY1,
3345 GLint dstX0,
3346 GLint dstY0,
3347 GLint dstX1,
3348 GLint dstY1,
3349 GLbitfield mask,
3350 GLenum filter)
3351{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003352 if (mask == 0)
3353 {
3354 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3355 // buffers are copied.
3356 return;
3357 }
3358
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003359 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003360 ASSERT(drawFramebuffer);
3361
3362 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3363 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3364
Jamie Madillbc918e72018-03-08 09:47:21 -05003365 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003366
Jamie Madillc564c072017-06-01 12:45:42 -04003367 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003368}
Jamie Madillc29968b2016-01-20 11:17:23 -05003369
3370void Context::clear(GLbitfield mask)
3371{
Geoff Langd4fff502017-09-22 11:28:28 -04003372 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3373 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003374}
3375
3376void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3377{
Geoff Langd4fff502017-09-22 11:28:28 -04003378 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3379 ANGLE_CONTEXT_TRY(
3380 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003381}
3382
3383void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3384{
Geoff Langd4fff502017-09-22 11:28:28 -04003385 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3386 ANGLE_CONTEXT_TRY(
3387 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003388}
3389
3390void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3391{
Geoff Langd4fff502017-09-22 11:28:28 -04003392 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3393 ANGLE_CONTEXT_TRY(
3394 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003395}
3396
3397void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003399 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003400 ASSERT(framebufferObject);
3401
3402 // If a buffer is not present, the clear has no effect
3403 if (framebufferObject->getDepthbuffer() == nullptr &&
3404 framebufferObject->getStencilbuffer() == nullptr)
3405 {
3406 return;
3407 }
3408
Geoff Langd4fff502017-09-22 11:28:28 -04003409 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3410 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003411}
3412
3413void Context::readPixels(GLint x,
3414 GLint y,
3415 GLsizei width,
3416 GLsizei height,
3417 GLenum format,
3418 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003419 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003420{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003421 if (width == 0 || height == 0)
3422 {
3423 return;
3424 }
3425
Jamie Madillbc918e72018-03-08 09:47:21 -05003426 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003427
Jamie Madillb6664922017-07-25 12:55:04 -04003428 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3429 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003430
3431 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003432 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003433}
3434
Brandon Jones59770802018-04-02 13:18:42 -07003435void Context::readPixelsRobust(GLint x,
3436 GLint y,
3437 GLsizei width,
3438 GLsizei height,
3439 GLenum format,
3440 GLenum type,
3441 GLsizei bufSize,
3442 GLsizei *length,
3443 GLsizei *columns,
3444 GLsizei *rows,
3445 void *pixels)
3446{
3447 readPixels(x, y, width, height, format, type, pixels);
3448}
3449
3450void Context::readnPixelsRobust(GLint x,
3451 GLint y,
3452 GLsizei width,
3453 GLsizei height,
3454 GLenum format,
3455 GLenum type,
3456 GLsizei bufSize,
3457 GLsizei *length,
3458 GLsizei *columns,
3459 GLsizei *rows,
3460 void *data)
3461{
3462 readPixels(x, y, width, height, format, type, data);
3463}
3464
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003465void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003466 GLint level,
3467 GLenum internalformat,
3468 GLint x,
3469 GLint y,
3470 GLsizei width,
3471 GLsizei height,
3472 GLint border)
3473{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003474 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003475 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003476
Jamie Madillc29968b2016-01-20 11:17:23 -05003477 Rectangle sourceArea(x, y, width, height);
3478
Jamie Madill05b35b22017-10-03 09:01:44 -04003479 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003480 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003481 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003482}
3483
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003484void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003485 GLint level,
3486 GLint xoffset,
3487 GLint yoffset,
3488 GLint x,
3489 GLint y,
3490 GLsizei width,
3491 GLsizei height)
3492{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003493 if (width == 0 || height == 0)
3494 {
3495 return;
3496 }
3497
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003498 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003499 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003500
Jamie Madillc29968b2016-01-20 11:17:23 -05003501 Offset destOffset(xoffset, yoffset, 0);
3502 Rectangle sourceArea(x, y, width, height);
3503
Jamie Madill05b35b22017-10-03 09:01:44 -04003504 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003505 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003506 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003507}
3508
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003509void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003510 GLint level,
3511 GLint xoffset,
3512 GLint yoffset,
3513 GLint zoffset,
3514 GLint x,
3515 GLint y,
3516 GLsizei width,
3517 GLsizei height)
3518{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003519 if (width == 0 || height == 0)
3520 {
3521 return;
3522 }
3523
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003524 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003525 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003526
Jamie Madillc29968b2016-01-20 11:17:23 -05003527 Offset destOffset(xoffset, yoffset, zoffset);
3528 Rectangle sourceArea(x, y, width, height);
3529
Jamie Madill05b35b22017-10-03 09:01:44 -04003530 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3531 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003532 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3533 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003534}
3535
3536void Context::framebufferTexture2D(GLenum target,
3537 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003538 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003539 GLuint texture,
3540 GLint level)
3541{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003542 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003543 ASSERT(framebuffer);
3544
3545 if (texture != 0)
3546 {
3547 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003548 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003549 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003550 }
3551 else
3552 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003553 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003554 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003555
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003556 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003557}
3558
3559void Context::framebufferRenderbuffer(GLenum target,
3560 GLenum attachment,
3561 GLenum renderbuffertarget,
3562 GLuint renderbuffer)
3563{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003564 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003565 ASSERT(framebuffer);
3566
3567 if (renderbuffer != 0)
3568 {
3569 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003570
Jamie Madillcc129372018-04-12 09:13:18 -04003571 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003572 renderbufferObject);
3573 }
3574 else
3575 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003576 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003577 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003578
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003579 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003580}
3581
3582void Context::framebufferTextureLayer(GLenum target,
3583 GLenum attachment,
3584 GLuint texture,
3585 GLint level,
3586 GLint layer)
3587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003589 ASSERT(framebuffer);
3590
3591 if (texture != 0)
3592 {
3593 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003594 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003595 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 }
3597 else
3598 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003599 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003600 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003601
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003603}
3604
Brandon Jones59770802018-04-02 13:18:42 -07003605void Context::framebufferTextureMultiviewLayered(GLenum target,
3606 GLenum attachment,
3607 GLuint texture,
3608 GLint level,
3609 GLint baseViewIndex,
3610 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003611{
Martin Radev82ef7742017-08-08 17:44:58 +03003612 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3613 ASSERT(framebuffer);
3614
3615 if (texture != 0)
3616 {
3617 Texture *textureObj = getTexture(texture);
3618
Martin Radev18b75ba2017-08-15 15:50:40 +03003619 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003620 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3621 numViews, baseViewIndex);
3622 }
3623 else
3624 {
3625 framebuffer->resetAttachment(this, attachment);
3626 }
3627
3628 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003629}
3630
Brandon Jones59770802018-04-02 13:18:42 -07003631void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3632 GLenum attachment,
3633 GLuint texture,
3634 GLint level,
3635 GLsizei numViews,
3636 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003637{
Martin Radev5dae57b2017-07-14 16:15:55 +03003638 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3639 ASSERT(framebuffer);
3640
3641 if (texture != 0)
3642 {
3643 Texture *textureObj = getTexture(texture);
3644
3645 ImageIndex index = ImageIndex::Make2D(level);
3646 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3647 textureObj, numViews, viewportOffsets);
3648 }
3649 else
3650 {
3651 framebuffer->resetAttachment(this, attachment);
3652 }
3653
3654 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003655}
3656
Jamie Madillc29968b2016-01-20 11:17:23 -05003657void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 ASSERT(framebuffer);
3661 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003663}
3664
3665void Context::readBuffer(GLenum mode)
3666{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003667 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003668 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003669 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003670}
3671
3672void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3673{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003674 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003675 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003676
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003677 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 ASSERT(framebuffer);
3679
3680 // The specification isn't clear what should be done when the framebuffer isn't complete.
3681 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003682 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003683}
3684
3685void Context::invalidateFramebuffer(GLenum target,
3686 GLsizei numAttachments,
3687 const GLenum *attachments)
3688{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003689 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003690 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003693 ASSERT(framebuffer);
3694
Jamie Madill427064d2018-04-13 16:20:34 -04003695 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 {
Jamie Madill437fa652016-05-03 15:13:24 -04003697 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003698 }
Jamie Madill437fa652016-05-03 15:13:24 -04003699
Jamie Madill4928b7c2017-06-20 12:57:39 -04003700 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003701}
3702
3703void Context::invalidateSubFramebuffer(GLenum target,
3704 GLsizei numAttachments,
3705 const GLenum *attachments,
3706 GLint x,
3707 GLint y,
3708 GLsizei width,
3709 GLsizei height)
3710{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003711 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003712 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003713
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003715 ASSERT(framebuffer);
3716
Jamie Madill427064d2018-04-13 16:20:34 -04003717 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003718 {
Jamie Madill437fa652016-05-03 15:13:24 -04003719 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003720 }
Jamie Madill437fa652016-05-03 15:13:24 -04003721
3722 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003723 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003724}
3725
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003726void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003727 GLint level,
3728 GLint internalformat,
3729 GLsizei width,
3730 GLsizei height,
3731 GLint border,
3732 GLenum format,
3733 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003734 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003735{
Jamie Madillbc918e72018-03-08 09:47:21 -05003736 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003737
3738 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003739 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003740 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3741 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003742}
3743
Brandon Jones59770802018-04-02 13:18:42 -07003744void Context::texImage2DRobust(TextureTarget target,
3745 GLint level,
3746 GLint internalformat,
3747 GLsizei width,
3748 GLsizei height,
3749 GLint border,
3750 GLenum format,
3751 GLenum type,
3752 GLsizei bufSize,
3753 const void *pixels)
3754{
3755 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3756}
3757
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003758void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003759 GLint level,
3760 GLint internalformat,
3761 GLsizei width,
3762 GLsizei height,
3763 GLsizei depth,
3764 GLint border,
3765 GLenum format,
3766 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003767 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003768{
Jamie Madillbc918e72018-03-08 09:47:21 -05003769 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003770
3771 Extents size(width, height, depth);
3772 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003773 handleError(texture->setImage(this, mGLState.getUnpackState(),
3774 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3775 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003776}
3777
Brandon Jones59770802018-04-02 13:18:42 -07003778void Context::texImage3DRobust(TextureType target,
3779 GLint level,
3780 GLint internalformat,
3781 GLsizei width,
3782 GLsizei height,
3783 GLsizei depth,
3784 GLint border,
3785 GLenum format,
3786 GLenum type,
3787 GLsizei bufSize,
3788 const void *pixels)
3789{
3790 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3791}
3792
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003793void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003794 GLint level,
3795 GLint xoffset,
3796 GLint yoffset,
3797 GLsizei width,
3798 GLsizei height,
3799 GLenum format,
3800 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003801 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003802{
3803 // Zero sized uploads are valid but no-ops
3804 if (width == 0 || height == 0)
3805 {
3806 return;
3807 }
3808
Jamie Madillbc918e72018-03-08 09:47:21 -05003809 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003810
3811 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003812 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003813 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3814 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003815}
3816
Brandon Jones59770802018-04-02 13:18:42 -07003817void Context::texSubImage2DRobust(TextureTarget target,
3818 GLint level,
3819 GLint xoffset,
3820 GLint yoffset,
3821 GLsizei width,
3822 GLsizei height,
3823 GLenum format,
3824 GLenum type,
3825 GLsizei bufSize,
3826 const void *pixels)
3827{
3828 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3829}
3830
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003831void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003832 GLint level,
3833 GLint xoffset,
3834 GLint yoffset,
3835 GLint zoffset,
3836 GLsizei width,
3837 GLsizei height,
3838 GLsizei depth,
3839 GLenum format,
3840 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003841 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003842{
3843 // Zero sized uploads are valid but no-ops
3844 if (width == 0 || height == 0 || depth == 0)
3845 {
3846 return;
3847 }
3848
Jamie Madillbc918e72018-03-08 09:47:21 -05003849 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003850
3851 Box area(xoffset, yoffset, zoffset, width, height, depth);
3852 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003853 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3854 NonCubeTextureTypeToTarget(target), level, area, format, type,
3855 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003856}
3857
Brandon Jones59770802018-04-02 13:18:42 -07003858void Context::texSubImage3DRobust(TextureType target,
3859 GLint level,
3860 GLint xoffset,
3861 GLint yoffset,
3862 GLint zoffset,
3863 GLsizei width,
3864 GLsizei height,
3865 GLsizei depth,
3866 GLenum format,
3867 GLenum type,
3868 GLsizei bufSize,
3869 const void *pixels)
3870{
3871 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3872 pixels);
3873}
3874
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003875void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003876 GLint level,
3877 GLenum internalformat,
3878 GLsizei width,
3879 GLsizei height,
3880 GLint border,
3881 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003882 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003883{
Jamie Madillbc918e72018-03-08 09:47:21 -05003884 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003885
3886 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003887 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003888 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3889 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003890 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003891}
3892
Brandon Jones59770802018-04-02 13:18:42 -07003893void Context::compressedTexImage2DRobust(TextureTarget target,
3894 GLint level,
3895 GLenum internalformat,
3896 GLsizei width,
3897 GLsizei height,
3898 GLint border,
3899 GLsizei imageSize,
3900 GLsizei dataSize,
3901 const GLvoid *data)
3902{
3903 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3904}
3905
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003906void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003907 GLint level,
3908 GLenum internalformat,
3909 GLsizei width,
3910 GLsizei height,
3911 GLsizei depth,
3912 GLint border,
3913 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003914 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003915{
Jamie Madillbc918e72018-03-08 09:47:21 -05003916 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003917
3918 Extents size(width, height, depth);
3919 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003920 handleError(texture->setCompressedImage(
3921 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3922 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003923}
3924
Brandon Jones59770802018-04-02 13:18:42 -07003925void Context::compressedTexImage3DRobust(TextureType target,
3926 GLint level,
3927 GLenum internalformat,
3928 GLsizei width,
3929 GLsizei height,
3930 GLsizei depth,
3931 GLint border,
3932 GLsizei imageSize,
3933 GLsizei dataSize,
3934 const GLvoid *data)
3935{
3936 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3937 data);
3938}
3939
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003940void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003941 GLint level,
3942 GLint xoffset,
3943 GLint yoffset,
3944 GLsizei width,
3945 GLsizei height,
3946 GLenum format,
3947 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003948 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003949{
Jamie Madillbc918e72018-03-08 09:47:21 -05003950 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003951
3952 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003953 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003954 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3955 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003956 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003957}
3958
Brandon Jones59770802018-04-02 13:18:42 -07003959void Context::compressedTexSubImage2DRobust(TextureTarget target,
3960 GLint level,
3961 GLint xoffset,
3962 GLint yoffset,
3963 GLsizei width,
3964 GLsizei height,
3965 GLenum format,
3966 GLsizei imageSize,
3967 GLsizei dataSize,
3968 const GLvoid *data)
3969{
3970 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3971 data);
3972}
3973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003974void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003975 GLint level,
3976 GLint xoffset,
3977 GLint yoffset,
3978 GLint zoffset,
3979 GLsizei width,
3980 GLsizei height,
3981 GLsizei depth,
3982 GLenum format,
3983 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
3986 // Zero sized uploads are valid but no-ops
3987 if (width == 0 || height == 0)
3988 {
3989 return;
3990 }
3991
Jamie Madillbc918e72018-03-08 09:47:21 -05003992 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003993
3994 Box area(xoffset, yoffset, zoffset, width, height, depth);
3995 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003996 handleError(texture->setCompressedSubImage(
3997 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3998 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003999}
4000
Brandon Jones59770802018-04-02 13:18:42 -07004001void Context::compressedTexSubImage3DRobust(TextureType target,
4002 GLint level,
4003 GLint xoffset,
4004 GLint yoffset,
4005 GLint zoffset,
4006 GLsizei width,
4007 GLsizei height,
4008 GLsizei depth,
4009 GLenum format,
4010 GLsizei imageSize,
4011 GLsizei dataSize,
4012 const GLvoid *data)
4013{
4014 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4015 imageSize, data);
4016}
4017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004018void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004019{
4020 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004021 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004022}
4023
Jamie Madill007530e2017-12-28 14:27:04 -05004024void Context::copyTexture(GLuint sourceId,
4025 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004026 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004027 GLuint destId,
4028 GLint destLevel,
4029 GLint internalFormat,
4030 GLenum destType,
4031 GLboolean unpackFlipY,
4032 GLboolean unpackPremultiplyAlpha,
4033 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004034{
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004036
4037 gl::Texture *sourceTexture = getTexture(sourceId);
4038 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004039 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4040 sourceLevel, ConvertToBool(unpackFlipY),
4041 ConvertToBool(unpackPremultiplyAlpha),
4042 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004043}
4044
Jamie Madill007530e2017-12-28 14:27:04 -05004045void Context::copySubTexture(GLuint sourceId,
4046 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004047 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004048 GLuint destId,
4049 GLint destLevel,
4050 GLint xoffset,
4051 GLint yoffset,
4052 GLint x,
4053 GLint y,
4054 GLsizei width,
4055 GLsizei height,
4056 GLboolean unpackFlipY,
4057 GLboolean unpackPremultiplyAlpha,
4058 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004059{
4060 // Zero sized copies are valid but no-ops
4061 if (width == 0 || height == 0)
4062 {
4063 return;
4064 }
4065
Jamie Madillbc918e72018-03-08 09:47:21 -05004066 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004067
4068 gl::Texture *sourceTexture = getTexture(sourceId);
4069 gl::Texture *destTexture = getTexture(destId);
4070 Offset offset(xoffset, yoffset, 0);
4071 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004072 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4073 ConvertToBool(unpackFlipY),
4074 ConvertToBool(unpackPremultiplyAlpha),
4075 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004076}
4077
Jamie Madill007530e2017-12-28 14:27:04 -05004078void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004079{
Jamie Madillbc918e72018-03-08 09:47:21 -05004080 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004081
4082 gl::Texture *sourceTexture = getTexture(sourceId);
4083 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004084 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004085}
4086
Corentin Wallez336129f2017-10-17 15:55:40 -04004087void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004089 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004090 ASSERT(buffer);
4091
Geoff Lang496c02d2016-10-20 11:38:11 -07004092 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004093}
4094
Brandon Jones59770802018-04-02 13:18:42 -07004095void Context::getBufferPointervRobust(BufferBinding target,
4096 GLenum pname,
4097 GLsizei bufSize,
4098 GLsizei *length,
4099 void **params)
4100{
4101 getBufferPointerv(target, pname, params);
4102}
4103
Corentin Wallez336129f2017-10-17 15:55:40 -04004104void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004105{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004106 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004107 ASSERT(buffer);
4108
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004109 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004110 if (error.isError())
4111 {
Jamie Madill437fa652016-05-03 15:13:24 -04004112 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004113 return nullptr;
4114 }
4115
4116 return buffer->getMapPointer();
4117}
4118
Corentin Wallez336129f2017-10-17 15:55:40 -04004119GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004120{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004121 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004122 ASSERT(buffer);
4123
4124 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004125 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004126 if (error.isError())
4127 {
Jamie Madill437fa652016-05-03 15:13:24 -04004128 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004129 return GL_FALSE;
4130 }
4131
4132 return result;
4133}
4134
Corentin Wallez336129f2017-10-17 15:55:40 -04004135void *Context::mapBufferRange(BufferBinding target,
4136 GLintptr offset,
4137 GLsizeiptr length,
4138 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004139{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004140 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004141 ASSERT(buffer);
4142
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004143 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004144 if (error.isError())
4145 {
Jamie Madill437fa652016-05-03 15:13:24 -04004146 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004147 return nullptr;
4148 }
4149
4150 return buffer->getMapPointer();
4151}
4152
Corentin Wallez336129f2017-10-17 15:55:40 -04004153void Context::flushMappedBufferRange(BufferBinding /*target*/,
4154 GLintptr /*offset*/,
4155 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004156{
4157 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4158}
4159
Jamie Madillbc918e72018-03-08 09:47:21 -05004160Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004161{
Geoff Langa8cb2872018-03-09 16:09:40 -05004162 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004163}
4164
Jamie Madillbc918e72018-03-08 09:47:21 -05004165Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004166{
Geoff Langa8cb2872018-03-09 16:09:40 -05004167 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004168}
4169
Jamie Madillbc918e72018-03-08 09:47:21 -05004170Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004171{
Geoff Langa8cb2872018-03-09 16:09:40 -05004172 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004173}
4174
Jiajia Qin5451d532017-11-16 17:16:34 +08004175void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4176{
4177 UNIMPLEMENTED();
4178}
4179
Jamie Madillc20ab272016-06-09 07:20:46 -07004180void Context::activeTexture(GLenum texture)
4181{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004182 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004183}
4184
Jamie Madill876429b2017-04-20 15:46:24 -04004185void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004186{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004187 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004188}
4189
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004190void Context::blendEquation(GLenum mode)
4191{
4192 mGLState.setBlendEquation(mode, mode);
4193}
4194
Jamie Madillc20ab272016-06-09 07:20:46 -07004195void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004197 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004198}
4199
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004200void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4201{
4202 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4203}
4204
Jamie Madillc20ab272016-06-09 07:20:46 -07004205void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4206{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004207 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004208}
4209
Jamie Madill876429b2017-04-20 15:46:24 -04004210void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004211{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004212 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004213}
4214
Jamie Madill876429b2017-04-20 15:46:24 -04004215void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004216{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004217 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004218}
4219
4220void Context::clearStencil(GLint s)
4221{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004222 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004223}
4224
4225void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4226{
Geoff Lang92019432017-11-20 13:09:34 -05004227 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4228 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004229}
4230
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004231void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004234}
4235
4236void Context::depthFunc(GLenum func)
4237{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004238 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004239}
4240
4241void Context::depthMask(GLboolean flag)
4242{
Geoff Lang92019432017-11-20 13:09:34 -05004243 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004244}
4245
Jamie Madill876429b2017-04-20 15:46:24 -04004246void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
4251void Context::disable(GLenum cap)
4252{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004253 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004254}
4255
4256void Context::disableVertexAttribArray(GLuint index)
4257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004258 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004259}
4260
4261void Context::enable(GLenum cap)
4262{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004263 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004264}
4265
4266void Context::enableVertexAttribArray(GLuint index)
4267{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004268 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004269}
4270
4271void Context::frontFace(GLenum mode)
4272{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004273 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004274}
4275
4276void Context::hint(GLenum target, GLenum mode)
4277{
4278 switch (target)
4279 {
4280 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004282 break;
4283
4284 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004285 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004286 break;
4287
4288 default:
4289 UNREACHABLE();
4290 return;
4291 }
4292}
4293
4294void Context::lineWidth(GLfloat width)
4295{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004297}
4298
4299void Context::pixelStorei(GLenum pname, GLint param)
4300{
4301 switch (pname)
4302 {
4303 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305 break;
4306
4307 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309 break;
4310
4311 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004312 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004313 break;
4314
4315 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004316 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004317 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004318 break;
4319
4320 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004321 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004322 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004323 break;
4324
4325 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004326 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004327 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004328 break;
4329
4330 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004331 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004332 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004333 break;
4334
4335 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004336 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004337 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004338 break;
4339
4340 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004341 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004342 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004343 break;
4344
4345 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004346 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004347 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004348 break;
4349
4350 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004351 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004352 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004353 break;
4354
4355 default:
4356 UNREACHABLE();
4357 return;
4358 }
4359}
4360
4361void Context::polygonOffset(GLfloat factor, GLfloat units)
4362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364}
4365
Jamie Madill876429b2017-04-20 15:46:24 -04004366void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004367{
Geoff Lang92019432017-11-20 13:09:34 -05004368 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004369}
4370
Jiawei Shaodb342272017-09-27 10:21:45 +08004371void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4372{
4373 mGLState.setSampleMaskParams(maskNumber, mask);
4374}
4375
Jamie Madillc20ab272016-06-09 07:20:46 -07004376void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4377{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379}
4380
4381void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4382{
4383 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4384 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386 }
4387
4388 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4389 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004390 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004391 }
4392}
4393
4394void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4395{
4396 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4397 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004398 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004399 }
4400
4401 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4402 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004403 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004404 }
4405}
4406
4407void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4408{
4409 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4410 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412 }
4413
4414 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4415 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417 }
4418}
4419
4420void Context::vertexAttrib1f(GLuint index, GLfloat x)
4421{
4422 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
4426void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4427{
4428 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
4432void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4433{
4434 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
4438void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4439{
4440 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442}
4443
4444void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4445{
4446 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448}
4449
4450void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4451{
4452 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454}
4455
4456void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4457{
4458 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4463{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004465}
4466
4467void Context::vertexAttribPointer(GLuint index,
4468 GLint size,
4469 GLenum type,
4470 GLboolean normalized,
4471 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004472 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004473{
Corentin Wallez336129f2017-10-17 15:55:40 -04004474 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004475 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476}
4477
Shao80957d92017-02-20 21:25:59 +08004478void Context::vertexAttribFormat(GLuint attribIndex,
4479 GLint size,
4480 GLenum type,
4481 GLboolean normalized,
4482 GLuint relativeOffset)
4483{
Geoff Lang92019432017-11-20 13:09:34 -05004484 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004485 relativeOffset);
4486}
4487
4488void Context::vertexAttribIFormat(GLuint attribIndex,
4489 GLint size,
4490 GLenum type,
4491 GLuint relativeOffset)
4492{
4493 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4494}
4495
4496void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4497{
Shaodde78e82017-05-22 14:13:27 +08004498 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004499}
4500
Jiajia Qin5451d532017-11-16 17:16:34 +08004501void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004502{
4503 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4504}
4505
Jamie Madillc20ab272016-06-09 07:20:46 -07004506void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4507{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004509}
4510
4511void Context::vertexAttribIPointer(GLuint index,
4512 GLint size,
4513 GLenum type,
4514 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004515 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004516{
Corentin Wallez336129f2017-10-17 15:55:40 -04004517 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4518 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519}
4520
4521void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4522{
4523 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525}
4526
4527void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4528{
4529 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004530 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004531}
4532
4533void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4534{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004535 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536}
4537
4538void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4539{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004540 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004541}
4542
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004543void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4544{
4545 const VertexAttribCurrentValueData &currentValues =
4546 getGLState().getVertexAttribCurrentValue(index);
4547 const VertexArray *vao = getGLState().getVertexArray();
4548 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4549 currentValues, pname, params);
4550}
4551
Brandon Jones59770802018-04-02 13:18:42 -07004552void Context::getVertexAttribivRobust(GLuint index,
4553 GLenum pname,
4554 GLsizei bufSize,
4555 GLsizei *length,
4556 GLint *params)
4557{
4558 getVertexAttribiv(index, pname, params);
4559}
4560
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004561void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4562{
4563 const VertexAttribCurrentValueData &currentValues =
4564 getGLState().getVertexAttribCurrentValue(index);
4565 const VertexArray *vao = getGLState().getVertexArray();
4566 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4567 currentValues, pname, params);
4568}
4569
Brandon Jones59770802018-04-02 13:18:42 -07004570void Context::getVertexAttribfvRobust(GLuint index,
4571 GLenum pname,
4572 GLsizei bufSize,
4573 GLsizei *length,
4574 GLfloat *params)
4575{
4576 getVertexAttribfv(index, pname, params);
4577}
4578
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004579void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4580{
4581 const VertexAttribCurrentValueData &currentValues =
4582 getGLState().getVertexAttribCurrentValue(index);
4583 const VertexArray *vao = getGLState().getVertexArray();
4584 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4585 currentValues, pname, params);
4586}
4587
Brandon Jones59770802018-04-02 13:18:42 -07004588void Context::getVertexAttribIivRobust(GLuint index,
4589 GLenum pname,
4590 GLsizei bufSize,
4591 GLsizei *length,
4592 GLint *params)
4593{
4594 getVertexAttribIiv(index, pname, params);
4595}
4596
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004597void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4598{
4599 const VertexAttribCurrentValueData &currentValues =
4600 getGLState().getVertexAttribCurrentValue(index);
4601 const VertexArray *vao = getGLState().getVertexArray();
4602 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4603 currentValues, pname, params);
4604}
4605
Brandon Jones59770802018-04-02 13:18:42 -07004606void Context::getVertexAttribIuivRobust(GLuint index,
4607 GLenum pname,
4608 GLsizei bufSize,
4609 GLsizei *length,
4610 GLuint *params)
4611{
4612 getVertexAttribIuiv(index, pname, params);
4613}
4614
Jamie Madill876429b2017-04-20 15:46:24 -04004615void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004616{
4617 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4618 QueryVertexAttribPointerv(attrib, pname, pointer);
4619}
4620
Brandon Jones59770802018-04-02 13:18:42 -07004621void Context::getVertexAttribPointervRobust(GLuint index,
4622 GLenum pname,
4623 GLsizei bufSize,
4624 GLsizei *length,
4625 void **pointer)
4626{
4627 getVertexAttribPointerv(index, pname, pointer);
4628}
4629
Jamie Madillc20ab272016-06-09 07:20:46 -07004630void Context::debugMessageControl(GLenum source,
4631 GLenum type,
4632 GLenum severity,
4633 GLsizei count,
4634 const GLuint *ids,
4635 GLboolean enabled)
4636{
4637 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004638 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004639 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004640}
4641
4642void Context::debugMessageInsert(GLenum source,
4643 GLenum type,
4644 GLuint id,
4645 GLenum severity,
4646 GLsizei length,
4647 const GLchar *buf)
4648{
4649 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004651}
4652
4653void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656}
4657
4658GLuint Context::getDebugMessageLog(GLuint count,
4659 GLsizei bufSize,
4660 GLenum *sources,
4661 GLenum *types,
4662 GLuint *ids,
4663 GLenum *severities,
4664 GLsizei *lengths,
4665 GLchar *messageLog)
4666{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4668 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4672{
4673 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004675 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
4678void Context::popDebugGroup()
4679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004680 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004681 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
Corentin Wallez336129f2017-10-17 15:55:40 -04004684void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004685{
4686 Buffer *buffer = mGLState.getTargetBuffer(target);
4687 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004688 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004689}
4690
Corentin Wallez336129f2017-10-17 15:55:40 -04004691void Context::bufferSubData(BufferBinding target,
4692 GLintptr offset,
4693 GLsizeiptr size,
4694 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004695{
4696 if (data == nullptr)
4697 {
4698 return;
4699 }
4700
4701 Buffer *buffer = mGLState.getTargetBuffer(target);
4702 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004703 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004704}
4705
Jamie Madillef300b12016-10-07 15:12:09 -04004706void Context::attachShader(GLuint program, GLuint shader)
4707{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004708 Program *programObject = mState.mShaderPrograms->getProgram(program);
4709 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004710 ASSERT(programObject && shaderObject);
4711 programObject->attachShader(shaderObject);
4712}
4713
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004714const Workarounds &Context::getWorkarounds() const
4715{
4716 return mWorkarounds;
4717}
4718
Corentin Wallez336129f2017-10-17 15:55:40 -04004719void Context::copyBufferSubData(BufferBinding readTarget,
4720 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004721 GLintptr readOffset,
4722 GLintptr writeOffset,
4723 GLsizeiptr size)
4724{
4725 // if size is zero, the copy is a successful no-op
4726 if (size == 0)
4727 {
4728 return;
4729 }
4730
4731 // TODO(jmadill): cache these.
4732 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4733 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4734
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004735 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004736}
4737
Jamie Madill01a80ee2016-11-07 12:06:18 -05004738void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4739{
4740 Program *programObject = getProgram(program);
4741 // TODO(jmadill): Re-use this from the validation if possible.
4742 ASSERT(programObject);
4743 programObject->bindAttributeLocation(index, name);
4744}
4745
Corentin Wallez336129f2017-10-17 15:55:40 -04004746void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004747{
Corentin Wallez336129f2017-10-17 15:55:40 -04004748 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4749 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004750}
4751
Corentin Wallez336129f2017-10-17 15:55:40 -04004752void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004753{
4754 bindBufferRange(target, index, buffer, 0, 0);
4755}
4756
Corentin Wallez336129f2017-10-17 15:55:40 -04004757void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004758 GLuint index,
4759 GLuint buffer,
4760 GLintptr offset,
4761 GLsizeiptr size)
4762{
Corentin Wallez336129f2017-10-17 15:55:40 -04004763 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4764 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004765}
4766
Jamie Madill01a80ee2016-11-07 12:06:18 -05004767void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4768{
4769 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4770 {
4771 bindReadFramebuffer(framebuffer);
4772 }
4773
4774 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4775 {
4776 bindDrawFramebuffer(framebuffer);
4777 }
4778}
4779
4780void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4781{
4782 ASSERT(target == GL_RENDERBUFFER);
4783 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004784 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004785 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004786}
4787
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004788void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004789 GLsizei samples,
4790 GLenum internalformat,
4791 GLsizei width,
4792 GLsizei height,
4793 GLboolean fixedsamplelocations)
4794{
4795 Extents size(width, height, 1);
4796 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004797 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4798 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004799}
4800
4801void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4802{
JiangYizhou5b03f472017-01-09 10:22:53 +08004803 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4804 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004805 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004806 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004807
4808 switch (pname)
4809 {
4810 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004811 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004812 break;
4813 default:
4814 UNREACHABLE();
4815 }
4816}
4817
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004818void Context::getMultisamplefvRobust(GLenum pname,
4819 GLuint index,
4820 GLsizei bufSize,
4821 GLsizei *length,
4822 GLfloat *val)
4823{
4824 UNIMPLEMENTED();
4825}
4826
Jamie Madille8fb6402017-02-14 17:56:40 -05004827void Context::renderbufferStorage(GLenum target,
4828 GLenum internalformat,
4829 GLsizei width,
4830 GLsizei height)
4831{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004832 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4833 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4834
Jamie Madille8fb6402017-02-14 17:56:40 -05004835 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004836 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004837}
4838
4839void Context::renderbufferStorageMultisample(GLenum target,
4840 GLsizei samples,
4841 GLenum internalformat,
4842 GLsizei width,
4843 GLsizei height)
4844{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004845 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4846 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004847
4848 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004849 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004850 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004851}
4852
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004853void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4854{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004855 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004856 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004857}
4858
JiangYizhoue18e6392017-02-20 10:32:23 +08004859void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4860{
4861 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4862 QueryFramebufferParameteriv(framebuffer, pname, params);
4863}
4864
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004865void Context::getFramebufferParameterivRobust(GLenum target,
4866 GLenum pname,
4867 GLsizei bufSize,
4868 GLsizei *length,
4869 GLint *params)
4870{
4871 UNIMPLEMENTED();
4872}
4873
Jiajia Qin5451d532017-11-16 17:16:34 +08004874void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004875{
4876 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4877 SetFramebufferParameteri(framebuffer, pname, param);
4878}
4879
Jamie Madillb3f26b92017-07-19 15:07:41 -04004880Error Context::getScratchBuffer(size_t requstedSizeBytes,
4881 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004882{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004883 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4884 {
4885 return OutOfMemory() << "Failed to allocate internal buffer.";
4886 }
4887 return NoError();
4888}
4889
4890Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4891 angle::MemoryBuffer **zeroBufferOut) const
4892{
4893 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004894 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004895 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004896 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004897 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004898}
4899
Xinghua Cao10a4d432017-11-28 14:46:26 +08004900Error Context::prepareForDispatch()
4901{
Geoff Langa8cb2872018-03-09 16:09:40 -05004902 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004903
4904 if (isRobustResourceInitEnabled())
4905 {
4906 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4907 }
4908
4909 return NoError();
4910}
4911
Xinghua Cao2b396592017-03-29 15:36:04 +08004912void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4913{
4914 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4915 {
4916 return;
4917 }
4918
Xinghua Cao10a4d432017-11-28 14:46:26 +08004919 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004920 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004921}
4922
Jiajia Qin5451d532017-11-16 17:16:34 +08004923void Context::dispatchComputeIndirect(GLintptr indirect)
4924{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004925 ANGLE_CONTEXT_TRY(prepareForDispatch());
4926 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004927}
4928
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004929void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004930 GLsizei levels,
4931 GLenum internalFormat,
4932 GLsizei width,
4933 GLsizei height)
4934{
4935 Extents size(width, height, 1);
4936 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004937 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004938}
4939
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004940void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004941 GLsizei levels,
4942 GLenum internalFormat,
4943 GLsizei width,
4944 GLsizei height,
4945 GLsizei depth)
4946{
4947 Extents size(width, height, depth);
4948 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004949 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004950}
4951
Jiajia Qin5451d532017-11-16 17:16:34 +08004952void Context::memoryBarrier(GLbitfield barriers)
4953{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004954 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004955}
4956
4957void Context::memoryBarrierByRegion(GLbitfield barriers)
4958{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004959 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004960}
4961
Jamie Madillc1d770e2017-04-13 17:31:24 -04004962GLenum Context::checkFramebufferStatus(GLenum target)
4963{
4964 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4965 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004966 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004967}
4968
4969void Context::compileShader(GLuint shader)
4970{
4971 Shader *shaderObject = GetValidShader(this, shader);
4972 if (!shaderObject)
4973 {
4974 return;
4975 }
4976 shaderObject->compile(this);
4977}
4978
4979void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4980{
4981 for (int i = 0; i < n; i++)
4982 {
4983 deleteBuffer(buffers[i]);
4984 }
4985}
4986
4987void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4988{
4989 for (int i = 0; i < n; i++)
4990 {
4991 if (framebuffers[i] != 0)
4992 {
4993 deleteFramebuffer(framebuffers[i]);
4994 }
4995 }
4996}
4997
4998void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4999{
5000 for (int i = 0; i < n; i++)
5001 {
5002 deleteRenderbuffer(renderbuffers[i]);
5003 }
5004}
5005
5006void Context::deleteTextures(GLsizei n, const GLuint *textures)
5007{
5008 for (int i = 0; i < n; i++)
5009 {
5010 if (textures[i] != 0)
5011 {
5012 deleteTexture(textures[i]);
5013 }
5014 }
5015}
5016
5017void Context::detachShader(GLuint program, GLuint shader)
5018{
5019 Program *programObject = getProgram(program);
5020 ASSERT(programObject);
5021
5022 Shader *shaderObject = getShader(shader);
5023 ASSERT(shaderObject);
5024
5025 programObject->detachShader(this, shaderObject);
5026}
5027
5028void Context::genBuffers(GLsizei n, GLuint *buffers)
5029{
5030 for (int i = 0; i < n; i++)
5031 {
5032 buffers[i] = createBuffer();
5033 }
5034}
5035
5036void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5037{
5038 for (int i = 0; i < n; i++)
5039 {
5040 framebuffers[i] = createFramebuffer();
5041 }
5042}
5043
5044void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5045{
5046 for (int i = 0; i < n; i++)
5047 {
5048 renderbuffers[i] = createRenderbuffer();
5049 }
5050}
5051
5052void Context::genTextures(GLsizei n, GLuint *textures)
5053{
5054 for (int i = 0; i < n; i++)
5055 {
5056 textures[i] = createTexture();
5057 }
5058}
5059
5060void Context::getActiveAttrib(GLuint program,
5061 GLuint index,
5062 GLsizei bufsize,
5063 GLsizei *length,
5064 GLint *size,
5065 GLenum *type,
5066 GLchar *name)
5067{
5068 Program *programObject = getProgram(program);
5069 ASSERT(programObject);
5070 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5071}
5072
5073void Context::getActiveUniform(GLuint program,
5074 GLuint index,
5075 GLsizei bufsize,
5076 GLsizei *length,
5077 GLint *size,
5078 GLenum *type,
5079 GLchar *name)
5080{
5081 Program *programObject = getProgram(program);
5082 ASSERT(programObject);
5083 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5084}
5085
5086void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5087{
5088 Program *programObject = getProgram(program);
5089 ASSERT(programObject);
5090 programObject->getAttachedShaders(maxcount, count, shaders);
5091}
5092
5093GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5094{
5095 Program *programObject = getProgram(program);
5096 ASSERT(programObject);
5097 return programObject->getAttributeLocation(name);
5098}
5099
5100void Context::getBooleanv(GLenum pname, GLboolean *params)
5101{
5102 GLenum nativeType;
5103 unsigned int numParams = 0;
5104 getQueryParameterInfo(pname, &nativeType, &numParams);
5105
5106 if (nativeType == GL_BOOL)
5107 {
5108 getBooleanvImpl(pname, params);
5109 }
5110 else
5111 {
5112 CastStateValues(this, nativeType, pname, numParams, params);
5113 }
5114}
5115
Brandon Jones59770802018-04-02 13:18:42 -07005116void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5117{
5118 getBooleanv(pname, params);
5119}
5120
Jamie Madillc1d770e2017-04-13 17:31:24 -04005121void Context::getFloatv(GLenum pname, GLfloat *params)
5122{
5123 GLenum nativeType;
5124 unsigned int numParams = 0;
5125 getQueryParameterInfo(pname, &nativeType, &numParams);
5126
5127 if (nativeType == GL_FLOAT)
5128 {
5129 getFloatvImpl(pname, params);
5130 }
5131 else
5132 {
5133 CastStateValues(this, nativeType, pname, numParams, params);
5134 }
5135}
5136
Brandon Jones59770802018-04-02 13:18:42 -07005137void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5138{
5139 getFloatv(pname, params);
5140}
5141
Jamie Madillc1d770e2017-04-13 17:31:24 -04005142void Context::getIntegerv(GLenum pname, GLint *params)
5143{
5144 GLenum nativeType;
5145 unsigned int numParams = 0;
5146 getQueryParameterInfo(pname, &nativeType, &numParams);
5147
5148 if (nativeType == GL_INT)
5149 {
5150 getIntegervImpl(pname, params);
5151 }
5152 else
5153 {
5154 CastStateValues(this, nativeType, pname, numParams, params);
5155 }
5156}
5157
Brandon Jones59770802018-04-02 13:18:42 -07005158void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5159{
5160 getIntegerv(pname, data);
5161}
5162
Jamie Madillc1d770e2017-04-13 17:31:24 -04005163void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5164{
5165 Program *programObject = getProgram(program);
5166 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005167 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005168}
5169
Brandon Jones59770802018-04-02 13:18:42 -07005170void Context::getProgramivRobust(GLuint program,
5171 GLenum pname,
5172 GLsizei bufSize,
5173 GLsizei *length,
5174 GLint *params)
5175{
5176 getProgramiv(program, pname, params);
5177}
5178
Jiajia Qin5451d532017-11-16 17:16:34 +08005179void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5180{
5181 UNIMPLEMENTED();
5182}
5183
Jamie Madillbe849e42017-05-02 15:49:00 -04005184void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005185{
5186 Program *programObject = getProgram(program);
5187 ASSERT(programObject);
5188 programObject->getInfoLog(bufsize, length, infolog);
5189}
5190
Jiajia Qin5451d532017-11-16 17:16:34 +08005191void Context::getProgramPipelineInfoLog(GLuint pipeline,
5192 GLsizei bufSize,
5193 GLsizei *length,
5194 GLchar *infoLog)
5195{
5196 UNIMPLEMENTED();
5197}
5198
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5200{
5201 Shader *shaderObject = getShader(shader);
5202 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005203 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204}
5205
Brandon Jones59770802018-04-02 13:18:42 -07005206void Context::getShaderivRobust(GLuint shader,
5207 GLenum pname,
5208 GLsizei bufSize,
5209 GLsizei *length,
5210 GLint *params)
5211{
5212 getShaderiv(shader, pname, params);
5213}
5214
Jamie Madillc1d770e2017-04-13 17:31:24 -04005215void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5216{
5217 Shader *shaderObject = getShader(shader);
5218 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005219 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005220}
5221
5222void Context::getShaderPrecisionFormat(GLenum shadertype,
5223 GLenum precisiontype,
5224 GLint *range,
5225 GLint *precision)
5226{
5227 // TODO(jmadill): Compute shaders.
5228
5229 switch (shadertype)
5230 {
5231 case GL_VERTEX_SHADER:
5232 switch (precisiontype)
5233 {
5234 case GL_LOW_FLOAT:
5235 mCaps.vertexLowpFloat.get(range, precision);
5236 break;
5237 case GL_MEDIUM_FLOAT:
5238 mCaps.vertexMediumpFloat.get(range, precision);
5239 break;
5240 case GL_HIGH_FLOAT:
5241 mCaps.vertexHighpFloat.get(range, precision);
5242 break;
5243
5244 case GL_LOW_INT:
5245 mCaps.vertexLowpInt.get(range, precision);
5246 break;
5247 case GL_MEDIUM_INT:
5248 mCaps.vertexMediumpInt.get(range, precision);
5249 break;
5250 case GL_HIGH_INT:
5251 mCaps.vertexHighpInt.get(range, precision);
5252 break;
5253
5254 default:
5255 UNREACHABLE();
5256 return;
5257 }
5258 break;
5259
5260 case GL_FRAGMENT_SHADER:
5261 switch (precisiontype)
5262 {
5263 case GL_LOW_FLOAT:
5264 mCaps.fragmentLowpFloat.get(range, precision);
5265 break;
5266 case GL_MEDIUM_FLOAT:
5267 mCaps.fragmentMediumpFloat.get(range, precision);
5268 break;
5269 case GL_HIGH_FLOAT:
5270 mCaps.fragmentHighpFloat.get(range, precision);
5271 break;
5272
5273 case GL_LOW_INT:
5274 mCaps.fragmentLowpInt.get(range, precision);
5275 break;
5276 case GL_MEDIUM_INT:
5277 mCaps.fragmentMediumpInt.get(range, precision);
5278 break;
5279 case GL_HIGH_INT:
5280 mCaps.fragmentHighpInt.get(range, precision);
5281 break;
5282
5283 default:
5284 UNREACHABLE();
5285 return;
5286 }
5287 break;
5288
5289 default:
5290 UNREACHABLE();
5291 return;
5292 }
5293}
5294
5295void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5296{
5297 Shader *shaderObject = getShader(shader);
5298 ASSERT(shaderObject);
5299 shaderObject->getSource(bufsize, length, source);
5300}
5301
5302void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5303{
5304 Program *programObject = getProgram(program);
5305 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005306 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005307}
5308
Brandon Jones59770802018-04-02 13:18:42 -07005309void Context::getUniformfvRobust(GLuint program,
5310 GLint location,
5311 GLsizei bufSize,
5312 GLsizei *length,
5313 GLfloat *params)
5314{
5315 getUniformfv(program, location, params);
5316}
5317
Jamie Madillc1d770e2017-04-13 17:31:24 -04005318void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5319{
5320 Program *programObject = getProgram(program);
5321 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005322 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005323}
5324
Brandon Jones59770802018-04-02 13:18:42 -07005325void Context::getUniformivRobust(GLuint program,
5326 GLint location,
5327 GLsizei bufSize,
5328 GLsizei *length,
5329 GLint *params)
5330{
5331 getUniformiv(program, location, params);
5332}
5333
Jamie Madillc1d770e2017-04-13 17:31:24 -04005334GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5335{
5336 Program *programObject = getProgram(program);
5337 ASSERT(programObject);
5338 return programObject->getUniformLocation(name);
5339}
5340
5341GLboolean Context::isBuffer(GLuint buffer)
5342{
5343 if (buffer == 0)
5344 {
5345 return GL_FALSE;
5346 }
5347
5348 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5349}
5350
5351GLboolean Context::isEnabled(GLenum cap)
5352{
5353 return mGLState.getEnableFeature(cap);
5354}
5355
5356GLboolean Context::isFramebuffer(GLuint framebuffer)
5357{
5358 if (framebuffer == 0)
5359 {
5360 return GL_FALSE;
5361 }
5362
5363 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5364}
5365
5366GLboolean Context::isProgram(GLuint program)
5367{
5368 if (program == 0)
5369 {
5370 return GL_FALSE;
5371 }
5372
5373 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5374}
5375
5376GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5377{
5378 if (renderbuffer == 0)
5379 {
5380 return GL_FALSE;
5381 }
5382
5383 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5384}
5385
5386GLboolean Context::isShader(GLuint shader)
5387{
5388 if (shader == 0)
5389 {
5390 return GL_FALSE;
5391 }
5392
5393 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5394}
5395
5396GLboolean Context::isTexture(GLuint texture)
5397{
5398 if (texture == 0)
5399 {
5400 return GL_FALSE;
5401 }
5402
5403 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5404}
5405
5406void Context::linkProgram(GLuint program)
5407{
5408 Program *programObject = getProgram(program);
5409 ASSERT(programObject);
5410 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005411 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005412}
5413
5414void Context::releaseShaderCompiler()
5415{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005416 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005417}
5418
5419void Context::shaderBinary(GLsizei n,
5420 const GLuint *shaders,
5421 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005422 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005423 GLsizei length)
5424{
5425 // No binary shader formats are supported.
5426 UNIMPLEMENTED();
5427}
5428
5429void Context::shaderSource(GLuint shader,
5430 GLsizei count,
5431 const GLchar *const *string,
5432 const GLint *length)
5433{
5434 Shader *shaderObject = getShader(shader);
5435 ASSERT(shaderObject);
5436 shaderObject->setSource(count, string, length);
5437}
5438
5439void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5440{
5441 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5442}
5443
5444void Context::stencilMask(GLuint mask)
5445{
5446 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5447}
5448
5449void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5450{
5451 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5452}
5453
5454void Context::uniform1f(GLint location, GLfloat x)
5455{
5456 Program *program = mGLState.getProgram();
5457 program->setUniform1fv(location, 1, &x);
5458}
5459
5460void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5461{
5462 Program *program = mGLState.getProgram();
5463 program->setUniform1fv(location, count, v);
5464}
5465
5466void Context::uniform1i(GLint location, GLint x)
5467{
5468 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005469 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5470 {
5471 mGLState.setObjectDirty(GL_PROGRAM);
5472 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005473}
5474
5475void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5476{
5477 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005478 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5479 {
5480 mGLState.setObjectDirty(GL_PROGRAM);
5481 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005482}
5483
5484void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5485{
5486 GLfloat xy[2] = {x, y};
5487 Program *program = mGLState.getProgram();
5488 program->setUniform2fv(location, 1, xy);
5489}
5490
5491void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5492{
5493 Program *program = mGLState.getProgram();
5494 program->setUniform2fv(location, count, v);
5495}
5496
5497void Context::uniform2i(GLint location, GLint x, GLint y)
5498{
5499 GLint xy[2] = {x, y};
5500 Program *program = mGLState.getProgram();
5501 program->setUniform2iv(location, 1, xy);
5502}
5503
5504void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5505{
5506 Program *program = mGLState.getProgram();
5507 program->setUniform2iv(location, count, v);
5508}
5509
5510void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5511{
5512 GLfloat xyz[3] = {x, y, z};
5513 Program *program = mGLState.getProgram();
5514 program->setUniform3fv(location, 1, xyz);
5515}
5516
5517void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5518{
5519 Program *program = mGLState.getProgram();
5520 program->setUniform3fv(location, count, v);
5521}
5522
5523void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5524{
5525 GLint xyz[3] = {x, y, z};
5526 Program *program = mGLState.getProgram();
5527 program->setUniform3iv(location, 1, xyz);
5528}
5529
5530void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5531{
5532 Program *program = mGLState.getProgram();
5533 program->setUniform3iv(location, count, v);
5534}
5535
5536void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5537{
5538 GLfloat xyzw[4] = {x, y, z, w};
5539 Program *program = mGLState.getProgram();
5540 program->setUniform4fv(location, 1, xyzw);
5541}
5542
5543void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5544{
5545 Program *program = mGLState.getProgram();
5546 program->setUniform4fv(location, count, v);
5547}
5548
5549void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5550{
5551 GLint xyzw[4] = {x, y, z, w};
5552 Program *program = mGLState.getProgram();
5553 program->setUniform4iv(location, 1, xyzw);
5554}
5555
5556void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5557{
5558 Program *program = mGLState.getProgram();
5559 program->setUniform4iv(location, count, v);
5560}
5561
5562void Context::uniformMatrix2fv(GLint location,
5563 GLsizei count,
5564 GLboolean transpose,
5565 const GLfloat *value)
5566{
5567 Program *program = mGLState.getProgram();
5568 program->setUniformMatrix2fv(location, count, transpose, value);
5569}
5570
5571void Context::uniformMatrix3fv(GLint location,
5572 GLsizei count,
5573 GLboolean transpose,
5574 const GLfloat *value)
5575{
5576 Program *program = mGLState.getProgram();
5577 program->setUniformMatrix3fv(location, count, transpose, value);
5578}
5579
5580void Context::uniformMatrix4fv(GLint location,
5581 GLsizei count,
5582 GLboolean transpose,
5583 const GLfloat *value)
5584{
5585 Program *program = mGLState.getProgram();
5586 program->setUniformMatrix4fv(location, count, transpose, value);
5587}
5588
5589void Context::validateProgram(GLuint program)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject);
5593 programObject->validate(mCaps);
5594}
5595
Jiajia Qin5451d532017-11-16 17:16:34 +08005596void Context::validateProgramPipeline(GLuint pipeline)
5597{
5598 UNIMPLEMENTED();
5599}
5600
Jamie Madilld04908b2017-06-09 14:15:35 -04005601void Context::getProgramBinary(GLuint program,
5602 GLsizei bufSize,
5603 GLsizei *length,
5604 GLenum *binaryFormat,
5605 void *binary)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject != nullptr);
5609
5610 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5611}
5612
5613void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5614{
5615 Program *programObject = getProgram(program);
5616 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005617
Jamie Madilld04908b2017-06-09 14:15:35 -04005618 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5619}
5620
Jamie Madillff325f12017-08-26 15:06:05 -04005621void Context::uniform1ui(GLint location, GLuint v0)
5622{
5623 Program *program = mGLState.getProgram();
5624 program->setUniform1uiv(location, 1, &v0);
5625}
5626
5627void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5628{
5629 Program *program = mGLState.getProgram();
5630 const GLuint xy[] = {v0, v1};
5631 program->setUniform2uiv(location, 1, xy);
5632}
5633
5634void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5635{
5636 Program *program = mGLState.getProgram();
5637 const GLuint xyz[] = {v0, v1, v2};
5638 program->setUniform3uiv(location, 1, xyz);
5639}
5640
5641void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5642{
5643 Program *program = mGLState.getProgram();
5644 const GLuint xyzw[] = {v0, v1, v2, v3};
5645 program->setUniform4uiv(location, 1, xyzw);
5646}
5647
5648void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5649{
5650 Program *program = mGLState.getProgram();
5651 program->setUniform1uiv(location, count, value);
5652}
5653void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5654{
5655 Program *program = mGLState.getProgram();
5656 program->setUniform2uiv(location, count, value);
5657}
5658
5659void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5660{
5661 Program *program = mGLState.getProgram();
5662 program->setUniform3uiv(location, count, value);
5663}
5664
5665void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5666{
5667 Program *program = mGLState.getProgram();
5668 program->setUniform4uiv(location, count, value);
5669}
5670
Jamie Madillf0e04492017-08-26 15:28:42 -04005671void Context::genQueries(GLsizei n, GLuint *ids)
5672{
5673 for (GLsizei i = 0; i < n; i++)
5674 {
5675 GLuint handle = mQueryHandleAllocator.allocate();
5676 mQueryMap.assign(handle, nullptr);
5677 ids[i] = handle;
5678 }
5679}
5680
5681void Context::deleteQueries(GLsizei n, const GLuint *ids)
5682{
5683 for (int i = 0; i < n; i++)
5684 {
5685 GLuint query = ids[i];
5686
5687 Query *queryObject = nullptr;
5688 if (mQueryMap.erase(query, &queryObject))
5689 {
5690 mQueryHandleAllocator.release(query);
5691 if (queryObject)
5692 {
5693 queryObject->release(this);
5694 }
5695 }
5696 }
5697}
5698
5699GLboolean Context::isQuery(GLuint id)
5700{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005701 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005702}
5703
Jamie Madillc8c95812017-08-26 18:40:09 -04005704void Context::uniformMatrix2x3fv(GLint location,
5705 GLsizei count,
5706 GLboolean transpose,
5707 const GLfloat *value)
5708{
5709 Program *program = mGLState.getProgram();
5710 program->setUniformMatrix2x3fv(location, count, transpose, value);
5711}
5712
5713void Context::uniformMatrix3x2fv(GLint location,
5714 GLsizei count,
5715 GLboolean transpose,
5716 const GLfloat *value)
5717{
5718 Program *program = mGLState.getProgram();
5719 program->setUniformMatrix3x2fv(location, count, transpose, value);
5720}
5721
5722void Context::uniformMatrix2x4fv(GLint location,
5723 GLsizei count,
5724 GLboolean transpose,
5725 const GLfloat *value)
5726{
5727 Program *program = mGLState.getProgram();
5728 program->setUniformMatrix2x4fv(location, count, transpose, value);
5729}
5730
5731void Context::uniformMatrix4x2fv(GLint location,
5732 GLsizei count,
5733 GLboolean transpose,
5734 const GLfloat *value)
5735{
5736 Program *program = mGLState.getProgram();
5737 program->setUniformMatrix4x2fv(location, count, transpose, value);
5738}
5739
5740void Context::uniformMatrix3x4fv(GLint location,
5741 GLsizei count,
5742 GLboolean transpose,
5743 const GLfloat *value)
5744{
5745 Program *program = mGLState.getProgram();
5746 program->setUniformMatrix3x4fv(location, count, transpose, value);
5747}
5748
5749void Context::uniformMatrix4x3fv(GLint location,
5750 GLsizei count,
5751 GLboolean transpose,
5752 const GLfloat *value)
5753{
5754 Program *program = mGLState.getProgram();
5755 program->setUniformMatrix4x3fv(location, count, transpose, value);
5756}
5757
Jamie Madilld7576732017-08-26 18:49:50 -04005758void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5759{
5760 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5761 {
5762 GLuint vertexArray = arrays[arrayIndex];
5763
5764 if (arrays[arrayIndex] != 0)
5765 {
5766 VertexArray *vertexArrayObject = nullptr;
5767 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5768 {
5769 if (vertexArrayObject != nullptr)
5770 {
5771 detachVertexArray(vertexArray);
5772 vertexArrayObject->onDestroy(this);
5773 }
5774
5775 mVertexArrayHandleAllocator.release(vertexArray);
5776 }
5777 }
5778 }
5779}
5780
5781void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5782{
5783 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5784 {
5785 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5786 mVertexArrayMap.assign(vertexArray, nullptr);
5787 arrays[arrayIndex] = vertexArray;
5788 }
5789}
5790
5791bool Context::isVertexArray(GLuint array)
5792{
5793 if (array == 0)
5794 {
5795 return GL_FALSE;
5796 }
5797
5798 VertexArray *vao = getVertexArray(array);
5799 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5800}
5801
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005802void Context::endTransformFeedback()
5803{
5804 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5805 transformFeedback->end(this);
5806}
5807
5808void Context::transformFeedbackVaryings(GLuint program,
5809 GLsizei count,
5810 const GLchar *const *varyings,
5811 GLenum bufferMode)
5812{
5813 Program *programObject = getProgram(program);
5814 ASSERT(programObject);
5815 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5816}
5817
5818void Context::getTransformFeedbackVarying(GLuint program,
5819 GLuint index,
5820 GLsizei bufSize,
5821 GLsizei *length,
5822 GLsizei *size,
5823 GLenum *type,
5824 GLchar *name)
5825{
5826 Program *programObject = getProgram(program);
5827 ASSERT(programObject);
5828 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5829}
5830
5831void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5832{
5833 for (int i = 0; i < n; i++)
5834 {
5835 GLuint transformFeedback = ids[i];
5836 if (transformFeedback == 0)
5837 {
5838 continue;
5839 }
5840
5841 TransformFeedback *transformFeedbackObject = nullptr;
5842 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5843 {
5844 if (transformFeedbackObject != nullptr)
5845 {
5846 detachTransformFeedback(transformFeedback);
5847 transformFeedbackObject->release(this);
5848 }
5849
5850 mTransformFeedbackHandleAllocator.release(transformFeedback);
5851 }
5852 }
5853}
5854
5855void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5856{
5857 for (int i = 0; i < n; i++)
5858 {
5859 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5860 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5861 ids[i] = transformFeedback;
5862 }
5863}
5864
5865bool Context::isTransformFeedback(GLuint id)
5866{
5867 if (id == 0)
5868 {
5869 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5870 // returns FALSE
5871 return GL_FALSE;
5872 }
5873
5874 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5875 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5876}
5877
5878void Context::pauseTransformFeedback()
5879{
5880 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5881 transformFeedback->pause();
5882}
5883
5884void Context::resumeTransformFeedback()
5885{
5886 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5887 transformFeedback->resume();
5888}
5889
Jamie Madill12e957f2017-08-26 21:42:26 -04005890void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5891{
5892 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005893 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005894}
5895
Brandon Jones59770802018-04-02 13:18:42 -07005896void Context::getUniformuivRobust(GLuint program,
5897 GLint location,
5898 GLsizei bufSize,
5899 GLsizei *length,
5900 GLuint *params)
5901{
5902 getUniformuiv(program, location, params);
5903}
5904
Jamie Madill12e957f2017-08-26 21:42:26 -04005905GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5906{
5907 const Program *programObject = getProgram(program);
5908 return programObject->getFragDataLocation(name);
5909}
5910
5911void Context::getUniformIndices(GLuint program,
5912 GLsizei uniformCount,
5913 const GLchar *const *uniformNames,
5914 GLuint *uniformIndices)
5915{
5916 const Program *programObject = getProgram(program);
5917 if (!programObject->isLinked())
5918 {
5919 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5920 {
5921 uniformIndices[uniformId] = GL_INVALID_INDEX;
5922 }
5923 }
5924 else
5925 {
5926 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5927 {
5928 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5929 }
5930 }
5931}
5932
5933void Context::getActiveUniformsiv(GLuint program,
5934 GLsizei uniformCount,
5935 const GLuint *uniformIndices,
5936 GLenum pname,
5937 GLint *params)
5938{
5939 const Program *programObject = getProgram(program);
5940 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5941 {
5942 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005943 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005944 }
5945}
5946
5947GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5948{
5949 const Program *programObject = getProgram(program);
5950 return programObject->getUniformBlockIndex(uniformBlockName);
5951}
5952
5953void Context::getActiveUniformBlockiv(GLuint program,
5954 GLuint uniformBlockIndex,
5955 GLenum pname,
5956 GLint *params)
5957{
5958 const Program *programObject = getProgram(program);
5959 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5960}
5961
Brandon Jones59770802018-04-02 13:18:42 -07005962void Context::getActiveUniformBlockivRobust(GLuint program,
5963 GLuint uniformBlockIndex,
5964 GLenum pname,
5965 GLsizei bufSize,
5966 GLsizei *length,
5967 GLint *params)
5968{
5969 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5970}
5971
Jamie Madill12e957f2017-08-26 21:42:26 -04005972void Context::getActiveUniformBlockName(GLuint program,
5973 GLuint uniformBlockIndex,
5974 GLsizei bufSize,
5975 GLsizei *length,
5976 GLchar *uniformBlockName)
5977{
5978 const Program *programObject = getProgram(program);
5979 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5980}
5981
5982void Context::uniformBlockBinding(GLuint program,
5983 GLuint uniformBlockIndex,
5984 GLuint uniformBlockBinding)
5985{
5986 Program *programObject = getProgram(program);
5987 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5988}
5989
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005990GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5991{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005992 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5993 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005994
Jamie Madill70b5bb02017-08-28 13:32:37 -04005995 Sync *syncObject = getSync(syncHandle);
5996 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005997 if (error.isError())
5998 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005999 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006000 handleError(error);
6001 return nullptr;
6002 }
6003
Jamie Madill70b5bb02017-08-28 13:32:37 -04006004 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006005}
6006
6007GLboolean Context::isSync(GLsync sync)
6008{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006009 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006010}
6011
6012GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6013{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006014 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006015
6016 GLenum result = GL_WAIT_FAILED;
6017 handleError(syncObject->clientWait(flags, timeout, &result));
6018 return result;
6019}
6020
6021void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6022{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006023 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006024 handleError(syncObject->serverWait(flags, timeout));
6025}
6026
6027void Context::getInteger64v(GLenum pname, GLint64 *params)
6028{
6029 GLenum nativeType = GL_NONE;
6030 unsigned int numParams = 0;
6031 getQueryParameterInfo(pname, &nativeType, &numParams);
6032
6033 if (nativeType == GL_INT_64_ANGLEX)
6034 {
6035 getInteger64vImpl(pname, params);
6036 }
6037 else
6038 {
6039 CastStateValues(this, nativeType, pname, numParams, params);
6040 }
6041}
6042
Brandon Jones59770802018-04-02 13:18:42 -07006043void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6044{
6045 getInteger64v(pname, data);
6046}
6047
Corentin Wallez336129f2017-10-17 15:55:40 -04006048void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006049{
6050 Buffer *buffer = mGLState.getTargetBuffer(target);
6051 QueryBufferParameteri64v(buffer, pname, params);
6052}
6053
Brandon Jones59770802018-04-02 13:18:42 -07006054void Context::getBufferParameteri64vRobust(BufferBinding target,
6055 GLenum pname,
6056 GLsizei bufSize,
6057 GLsizei *length,
6058 GLint64 *params)
6059{
6060 getBufferParameteri64v(target, pname, params);
6061}
6062
Jamie Madill3ef140a2017-08-26 23:11:21 -04006063void Context::genSamplers(GLsizei count, GLuint *samplers)
6064{
6065 for (int i = 0; i < count; i++)
6066 {
6067 samplers[i] = mState.mSamplers->createSampler();
6068 }
6069}
6070
6071void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6072{
6073 for (int i = 0; i < count; i++)
6074 {
6075 GLuint sampler = samplers[i];
6076
6077 if (mState.mSamplers->getSampler(sampler))
6078 {
6079 detachSampler(sampler);
6080 }
6081
6082 mState.mSamplers->deleteObject(this, sampler);
6083 }
6084}
6085
6086void Context::getInternalformativ(GLenum target,
6087 GLenum internalformat,
6088 GLenum pname,
6089 GLsizei bufSize,
6090 GLint *params)
6091{
6092 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6093 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6094}
6095
Brandon Jones59770802018-04-02 13:18:42 -07006096void Context::getInternalformativRobust(GLenum target,
6097 GLenum internalformat,
6098 GLenum pname,
6099 GLsizei bufSize,
6100 GLsizei *length,
6101 GLint *params)
6102{
6103 getInternalformativ(target, internalformat, pname, bufSize, params);
6104}
6105
Jiajia Qin5451d532017-11-16 17:16:34 +08006106void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6107{
6108 programUniform1iv(program, location, 1, &v0);
6109}
6110
6111void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6112{
6113 GLint xy[2] = {v0, v1};
6114 programUniform2iv(program, location, 1, xy);
6115}
6116
6117void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6118{
6119 GLint xyz[3] = {v0, v1, v2};
6120 programUniform3iv(program, location, 1, xyz);
6121}
6122
6123void Context::programUniform4i(GLuint program,
6124 GLint location,
6125 GLint v0,
6126 GLint v1,
6127 GLint v2,
6128 GLint v3)
6129{
6130 GLint xyzw[4] = {v0, v1, v2, v3};
6131 programUniform4iv(program, location, 1, xyzw);
6132}
6133
6134void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6135{
6136 programUniform1uiv(program, location, 1, &v0);
6137}
6138
6139void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6140{
6141 GLuint xy[2] = {v0, v1};
6142 programUniform2uiv(program, location, 1, xy);
6143}
6144
6145void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6146{
6147 GLuint xyz[3] = {v0, v1, v2};
6148 programUniform3uiv(program, location, 1, xyz);
6149}
6150
6151void Context::programUniform4ui(GLuint program,
6152 GLint location,
6153 GLuint v0,
6154 GLuint v1,
6155 GLuint v2,
6156 GLuint v3)
6157{
6158 GLuint xyzw[4] = {v0, v1, v2, v3};
6159 programUniform4uiv(program, location, 1, xyzw);
6160}
6161
6162void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6163{
6164 programUniform1fv(program, location, 1, &v0);
6165}
6166
6167void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6168{
6169 GLfloat xy[2] = {v0, v1};
6170 programUniform2fv(program, location, 1, xy);
6171}
6172
6173void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6174{
6175 GLfloat xyz[3] = {v0, v1, v2};
6176 programUniform3fv(program, location, 1, xyz);
6177}
6178
6179void Context::programUniform4f(GLuint program,
6180 GLint location,
6181 GLfloat v0,
6182 GLfloat v1,
6183 GLfloat v2,
6184 GLfloat v3)
6185{
6186 GLfloat xyzw[4] = {v0, v1, v2, v3};
6187 programUniform4fv(program, location, 1, xyzw);
6188}
6189
Jamie Madill81c2e252017-09-09 23:32:46 -04006190void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6191{
6192 Program *programObject = getProgram(program);
6193 ASSERT(programObject);
6194 if (programObject->setUniform1iv(location, count, value) ==
6195 Program::SetUniformResult::SamplerChanged)
6196 {
6197 mGLState.setObjectDirty(GL_PROGRAM);
6198 }
6199}
6200
Jiajia Qin5451d532017-11-16 17:16:34 +08006201void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6202{
6203 Program *programObject = getProgram(program);
6204 ASSERT(programObject);
6205 programObject->setUniform2iv(location, count, value);
6206}
6207
6208void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6209{
6210 Program *programObject = getProgram(program);
6211 ASSERT(programObject);
6212 programObject->setUniform3iv(location, count, value);
6213}
6214
6215void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6216{
6217 Program *programObject = getProgram(program);
6218 ASSERT(programObject);
6219 programObject->setUniform4iv(location, count, value);
6220}
6221
6222void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6223{
6224 Program *programObject = getProgram(program);
6225 ASSERT(programObject);
6226 programObject->setUniform1uiv(location, count, value);
6227}
6228
6229void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6230{
6231 Program *programObject = getProgram(program);
6232 ASSERT(programObject);
6233 programObject->setUniform2uiv(location, count, value);
6234}
6235
6236void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6237{
6238 Program *programObject = getProgram(program);
6239 ASSERT(programObject);
6240 programObject->setUniform3uiv(location, count, value);
6241}
6242
6243void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6244{
6245 Program *programObject = getProgram(program);
6246 ASSERT(programObject);
6247 programObject->setUniform4uiv(location, count, value);
6248}
6249
6250void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6251{
6252 Program *programObject = getProgram(program);
6253 ASSERT(programObject);
6254 programObject->setUniform1fv(location, count, value);
6255}
6256
6257void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6258{
6259 Program *programObject = getProgram(program);
6260 ASSERT(programObject);
6261 programObject->setUniform2fv(location, count, value);
6262}
6263
6264void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6265{
6266 Program *programObject = getProgram(program);
6267 ASSERT(programObject);
6268 programObject->setUniform3fv(location, count, value);
6269}
6270
6271void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6272{
6273 Program *programObject = getProgram(program);
6274 ASSERT(programObject);
6275 programObject->setUniform4fv(location, count, value);
6276}
6277
6278void Context::programUniformMatrix2fv(GLuint program,
6279 GLint location,
6280 GLsizei count,
6281 GLboolean transpose,
6282 const GLfloat *value)
6283{
6284 Program *programObject = getProgram(program);
6285 ASSERT(programObject);
6286 programObject->setUniformMatrix2fv(location, count, transpose, value);
6287}
6288
6289void Context::programUniformMatrix3fv(GLuint program,
6290 GLint location,
6291 GLsizei count,
6292 GLboolean transpose,
6293 const GLfloat *value)
6294{
6295 Program *programObject = getProgram(program);
6296 ASSERT(programObject);
6297 programObject->setUniformMatrix3fv(location, count, transpose, value);
6298}
6299
6300void Context::programUniformMatrix4fv(GLuint program,
6301 GLint location,
6302 GLsizei count,
6303 GLboolean transpose,
6304 const GLfloat *value)
6305{
6306 Program *programObject = getProgram(program);
6307 ASSERT(programObject);
6308 programObject->setUniformMatrix4fv(location, count, transpose, value);
6309}
6310
6311void Context::programUniformMatrix2x3fv(GLuint program,
6312 GLint location,
6313 GLsizei count,
6314 GLboolean transpose,
6315 const GLfloat *value)
6316{
6317 Program *programObject = getProgram(program);
6318 ASSERT(programObject);
6319 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6320}
6321
6322void Context::programUniformMatrix3x2fv(GLuint program,
6323 GLint location,
6324 GLsizei count,
6325 GLboolean transpose,
6326 const GLfloat *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6331}
6332
6333void Context::programUniformMatrix2x4fv(GLuint program,
6334 GLint location,
6335 GLsizei count,
6336 GLboolean transpose,
6337 const GLfloat *value)
6338{
6339 Program *programObject = getProgram(program);
6340 ASSERT(programObject);
6341 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6342}
6343
6344void Context::programUniformMatrix4x2fv(GLuint program,
6345 GLint location,
6346 GLsizei count,
6347 GLboolean transpose,
6348 const GLfloat *value)
6349{
6350 Program *programObject = getProgram(program);
6351 ASSERT(programObject);
6352 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6353}
6354
6355void Context::programUniformMatrix3x4fv(GLuint program,
6356 GLint location,
6357 GLsizei count,
6358 GLboolean transpose,
6359 const GLfloat *value)
6360{
6361 Program *programObject = getProgram(program);
6362 ASSERT(programObject);
6363 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6364}
6365
6366void Context::programUniformMatrix4x3fv(GLuint program,
6367 GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *programObject = getProgram(program);
6373 ASSERT(programObject);
6374 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6375}
6376
Jamie Madill81c2e252017-09-09 23:32:46 -04006377void Context::onTextureChange(const Texture *texture)
6378{
6379 // Conservatively assume all textures are dirty.
6380 // TODO(jmadill): More fine-grained update.
6381 mGLState.setObjectDirty(GL_TEXTURE);
6382}
6383
James Darpiniane8a93c62018-01-04 18:02:24 -08006384bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6385{
6386 return mGLState.isCurrentTransformFeedback(tf);
6387}
6388bool Context::isCurrentVertexArray(const VertexArray *va) const
6389{
6390 return mGLState.isCurrentVertexArray(va);
6391}
6392
Yunchao Hea336b902017-08-02 16:05:21 +08006393void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6394{
6395 for (int i = 0; i < count; i++)
6396 {
6397 pipelines[i] = createProgramPipeline();
6398 }
6399}
6400
6401void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6402{
6403 for (int i = 0; i < count; i++)
6404 {
6405 if (pipelines[i] != 0)
6406 {
6407 deleteProgramPipeline(pipelines[i]);
6408 }
6409 }
6410}
6411
6412GLboolean Context::isProgramPipeline(GLuint pipeline)
6413{
6414 if (pipeline == 0)
6415 {
6416 return GL_FALSE;
6417 }
6418
6419 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6420}
6421
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006422void Context::finishFenceNV(GLuint fence)
6423{
6424 FenceNV *fenceObject = getFenceNV(fence);
6425
6426 ASSERT(fenceObject && fenceObject->isSet());
6427 handleError(fenceObject->finish());
6428}
6429
6430void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6431{
6432 FenceNV *fenceObject = getFenceNV(fence);
6433
6434 ASSERT(fenceObject && fenceObject->isSet());
6435
6436 switch (pname)
6437 {
6438 case GL_FENCE_STATUS_NV:
6439 {
6440 // GL_NV_fence spec:
6441 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6442 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6443 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6444 GLboolean status = GL_TRUE;
6445 if (fenceObject->getStatus() != GL_TRUE)
6446 {
6447 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6448 }
6449 *params = status;
6450 break;
6451 }
6452
6453 case GL_FENCE_CONDITION_NV:
6454 {
6455 *params = static_cast<GLint>(fenceObject->getCondition());
6456 break;
6457 }
6458
6459 default:
6460 UNREACHABLE();
6461 }
6462}
6463
6464void Context::getTranslatedShaderSource(GLuint shader,
6465 GLsizei bufsize,
6466 GLsizei *length,
6467 GLchar *source)
6468{
6469 Shader *shaderObject = getShader(shader);
6470 ASSERT(shaderObject);
6471 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6472}
6473
6474void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6475{
6476 Program *programObject = getProgram(program);
6477 ASSERT(programObject);
6478
6479 programObject->getUniformfv(this, location, params);
6480}
6481
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006482void Context::getnUniformfvRobust(GLuint program,
6483 GLint location,
6484 GLsizei bufSize,
6485 GLsizei *length,
6486 GLfloat *params)
6487{
6488 UNIMPLEMENTED();
6489}
6490
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006491void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6492{
6493 Program *programObject = getProgram(program);
6494 ASSERT(programObject);
6495
6496 programObject->getUniformiv(this, location, params);
6497}
6498
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006499void Context::getnUniformivRobust(GLuint program,
6500 GLint location,
6501 GLsizei bufSize,
6502 GLsizei *length,
6503 GLint *params)
6504{
6505 UNIMPLEMENTED();
6506}
6507
6508void Context::getnUniformuivRobust(GLuint program,
6509 GLint location,
6510 GLsizei bufSize,
6511 GLsizei *length,
6512 GLuint *params)
6513{
6514 UNIMPLEMENTED();
6515}
6516
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006517GLboolean Context::isFenceNV(GLuint fence)
6518{
6519 FenceNV *fenceObject = getFenceNV(fence);
6520
6521 if (fenceObject == nullptr)
6522 {
6523 return GL_FALSE;
6524 }
6525
6526 // GL_NV_fence spec:
6527 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6528 // existing fence.
6529 return fenceObject->isSet();
6530}
6531
6532void Context::readnPixels(GLint x,
6533 GLint y,
6534 GLsizei width,
6535 GLsizei height,
6536 GLenum format,
6537 GLenum type,
6538 GLsizei bufSize,
6539 void *data)
6540{
6541 return readPixels(x, y, width, height, format, type, data);
6542}
6543
Jamie Madill007530e2017-12-28 14:27:04 -05006544void Context::setFenceNV(GLuint fence, GLenum condition)
6545{
6546 ASSERT(condition == GL_ALL_COMPLETED_NV);
6547
6548 FenceNV *fenceObject = getFenceNV(fence);
6549 ASSERT(fenceObject != nullptr);
6550 handleError(fenceObject->set(condition));
6551}
6552
6553GLboolean Context::testFenceNV(GLuint fence)
6554{
6555 FenceNV *fenceObject = getFenceNV(fence);
6556
6557 ASSERT(fenceObject != nullptr);
6558 ASSERT(fenceObject->isSet() == GL_TRUE);
6559
6560 GLboolean result = GL_TRUE;
6561 Error error = fenceObject->test(&result);
6562 if (error.isError())
6563 {
6564 handleError(error);
6565 return GL_TRUE;
6566 }
6567
6568 return result;
6569}
6570
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006571void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006572{
6573 Texture *texture = getTargetTexture(target);
6574 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006575 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006576}
6577
Jamie Madillfa920eb2018-01-04 11:45:50 -05006578void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006579{
6580 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6581 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6582 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6583}
6584
Jamie Madillfa920eb2018-01-04 11:45:50 -05006585void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6586{
6587 UNIMPLEMENTED();
6588}
6589
Jamie Madill5b772312018-03-08 20:28:32 -05006590bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6591{
6592 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6593 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6594 // to the fact that it is stored internally as a float, and so would require conversion
6595 // if returned from Context::getIntegerv. Since this conversion is already implemented
6596 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6597 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6598 // application.
6599 switch (pname)
6600 {
6601 case GL_COMPRESSED_TEXTURE_FORMATS:
6602 {
6603 *type = GL_INT;
6604 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6605 return true;
6606 }
6607 case GL_SHADER_BINARY_FORMATS:
6608 {
6609 *type = GL_INT;
6610 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6611 return true;
6612 }
6613
6614 case GL_MAX_VERTEX_ATTRIBS:
6615 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6616 case GL_MAX_VARYING_VECTORS:
6617 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6618 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6619 case GL_MAX_TEXTURE_IMAGE_UNITS:
6620 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6621 case GL_MAX_RENDERBUFFER_SIZE:
6622 case GL_NUM_SHADER_BINARY_FORMATS:
6623 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6624 case GL_ARRAY_BUFFER_BINDING:
6625 case GL_FRAMEBUFFER_BINDING:
6626 case GL_RENDERBUFFER_BINDING:
6627 case GL_CURRENT_PROGRAM:
6628 case GL_PACK_ALIGNMENT:
6629 case GL_UNPACK_ALIGNMENT:
6630 case GL_GENERATE_MIPMAP_HINT:
6631 case GL_RED_BITS:
6632 case GL_GREEN_BITS:
6633 case GL_BLUE_BITS:
6634 case GL_ALPHA_BITS:
6635 case GL_DEPTH_BITS:
6636 case GL_STENCIL_BITS:
6637 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6638 case GL_CULL_FACE_MODE:
6639 case GL_FRONT_FACE:
6640 case GL_ACTIVE_TEXTURE:
6641 case GL_STENCIL_FUNC:
6642 case GL_STENCIL_VALUE_MASK:
6643 case GL_STENCIL_REF:
6644 case GL_STENCIL_FAIL:
6645 case GL_STENCIL_PASS_DEPTH_FAIL:
6646 case GL_STENCIL_PASS_DEPTH_PASS:
6647 case GL_STENCIL_BACK_FUNC:
6648 case GL_STENCIL_BACK_VALUE_MASK:
6649 case GL_STENCIL_BACK_REF:
6650 case GL_STENCIL_BACK_FAIL:
6651 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6652 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6653 case GL_DEPTH_FUNC:
6654 case GL_BLEND_SRC_RGB:
6655 case GL_BLEND_SRC_ALPHA:
6656 case GL_BLEND_DST_RGB:
6657 case GL_BLEND_DST_ALPHA:
6658 case GL_BLEND_EQUATION_RGB:
6659 case GL_BLEND_EQUATION_ALPHA:
6660 case GL_STENCIL_WRITEMASK:
6661 case GL_STENCIL_BACK_WRITEMASK:
6662 case GL_STENCIL_CLEAR_VALUE:
6663 case GL_SUBPIXEL_BITS:
6664 case GL_MAX_TEXTURE_SIZE:
6665 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6666 case GL_SAMPLE_BUFFERS:
6667 case GL_SAMPLES:
6668 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6669 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6670 case GL_TEXTURE_BINDING_2D:
6671 case GL_TEXTURE_BINDING_CUBE_MAP:
6672 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6673 {
6674 *type = GL_INT;
6675 *numParams = 1;
6676 return true;
6677 }
6678 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6679 {
6680 if (!getExtensions().packReverseRowOrder)
6681 {
6682 return false;
6683 }
6684 *type = GL_INT;
6685 *numParams = 1;
6686 return true;
6687 }
6688 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6689 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6690 {
6691 if (!getExtensions().textureRectangle)
6692 {
6693 return false;
6694 }
6695 *type = GL_INT;
6696 *numParams = 1;
6697 return true;
6698 }
6699 case GL_MAX_DRAW_BUFFERS_EXT:
6700 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6701 {
6702 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6703 {
6704 return false;
6705 }
6706 *type = GL_INT;
6707 *numParams = 1;
6708 return true;
6709 }
6710 case GL_MAX_VIEWPORT_DIMS:
6711 {
6712 *type = GL_INT;
6713 *numParams = 2;
6714 return true;
6715 }
6716 case GL_VIEWPORT:
6717 case GL_SCISSOR_BOX:
6718 {
6719 *type = GL_INT;
6720 *numParams = 4;
6721 return true;
6722 }
6723 case GL_SHADER_COMPILER:
6724 case GL_SAMPLE_COVERAGE_INVERT:
6725 case GL_DEPTH_WRITEMASK:
6726 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6727 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6728 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6729 // bool-natural
6730 case GL_SAMPLE_COVERAGE:
6731 case GL_SCISSOR_TEST:
6732 case GL_STENCIL_TEST:
6733 case GL_DEPTH_TEST:
6734 case GL_BLEND:
6735 case GL_DITHER:
6736 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6737 {
6738 *type = GL_BOOL;
6739 *numParams = 1;
6740 return true;
6741 }
6742 case GL_COLOR_WRITEMASK:
6743 {
6744 *type = GL_BOOL;
6745 *numParams = 4;
6746 return true;
6747 }
6748 case GL_POLYGON_OFFSET_FACTOR:
6749 case GL_POLYGON_OFFSET_UNITS:
6750 case GL_SAMPLE_COVERAGE_VALUE:
6751 case GL_DEPTH_CLEAR_VALUE:
6752 case GL_LINE_WIDTH:
6753 {
6754 *type = GL_FLOAT;
6755 *numParams = 1;
6756 return true;
6757 }
6758 case GL_ALIASED_LINE_WIDTH_RANGE:
6759 case GL_ALIASED_POINT_SIZE_RANGE:
6760 case GL_DEPTH_RANGE:
6761 {
6762 *type = GL_FLOAT;
6763 *numParams = 2;
6764 return true;
6765 }
6766 case GL_COLOR_CLEAR_VALUE:
6767 case GL_BLEND_COLOR:
6768 {
6769 *type = GL_FLOAT;
6770 *numParams = 4;
6771 return true;
6772 }
6773 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6774 if (!getExtensions().textureFilterAnisotropic)
6775 {
6776 return false;
6777 }
6778 *type = GL_FLOAT;
6779 *numParams = 1;
6780 return true;
6781 case GL_TIMESTAMP_EXT:
6782 if (!getExtensions().disjointTimerQuery)
6783 {
6784 return false;
6785 }
6786 *type = GL_INT_64_ANGLEX;
6787 *numParams = 1;
6788 return true;
6789 case GL_GPU_DISJOINT_EXT:
6790 if (!getExtensions().disjointTimerQuery)
6791 {
6792 return false;
6793 }
6794 *type = GL_INT;
6795 *numParams = 1;
6796 return true;
6797 case GL_COVERAGE_MODULATION_CHROMIUM:
6798 if (!getExtensions().framebufferMixedSamples)
6799 {
6800 return false;
6801 }
6802 *type = GL_INT;
6803 *numParams = 1;
6804 return true;
6805 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6806 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6807 {
6808 return false;
6809 }
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 }
6814
6815 if (getExtensions().debug)
6816 {
6817 switch (pname)
6818 {
6819 case GL_DEBUG_LOGGED_MESSAGES:
6820 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6821 case GL_DEBUG_GROUP_STACK_DEPTH:
6822 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6823 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6824 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6825 case GL_MAX_LABEL_LENGTH:
6826 *type = GL_INT;
6827 *numParams = 1;
6828 return true;
6829
6830 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6831 case GL_DEBUG_OUTPUT:
6832 *type = GL_BOOL;
6833 *numParams = 1;
6834 return true;
6835 }
6836 }
6837
6838 if (getExtensions().multisampleCompatibility)
6839 {
6840 switch (pname)
6841 {
6842 case GL_MULTISAMPLE_EXT:
6843 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6844 *type = GL_BOOL;
6845 *numParams = 1;
6846 return true;
6847 }
6848 }
6849
6850 if (getExtensions().pathRendering)
6851 {
6852 switch (pname)
6853 {
6854 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6855 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6856 *type = GL_FLOAT;
6857 *numParams = 16;
6858 return true;
6859 }
6860 }
6861
6862 if (getExtensions().bindGeneratesResource)
6863 {
6864 switch (pname)
6865 {
6866 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6867 *type = GL_BOOL;
6868 *numParams = 1;
6869 return true;
6870 }
6871 }
6872
6873 if (getExtensions().clientArrays)
6874 {
6875 switch (pname)
6876 {
6877 case GL_CLIENT_ARRAYS_ANGLE:
6878 *type = GL_BOOL;
6879 *numParams = 1;
6880 return true;
6881 }
6882 }
6883
6884 if (getExtensions().sRGBWriteControl)
6885 {
6886 switch (pname)
6887 {
6888 case GL_FRAMEBUFFER_SRGB_EXT:
6889 *type = GL_BOOL;
6890 *numParams = 1;
6891 return true;
6892 }
6893 }
6894
6895 if (getExtensions().robustResourceInitialization &&
6896 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6897 {
6898 *type = GL_BOOL;
6899 *numParams = 1;
6900 return true;
6901 }
6902
6903 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6904 {
6905 *type = GL_BOOL;
6906 *numParams = 1;
6907 return true;
6908 }
6909
6910 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6911 switch (pname)
6912 {
6913 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6914 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6915 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6916 {
6917 return false;
6918 }
6919 *type = GL_INT;
6920 *numParams = 1;
6921 return true;
6922
6923 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6924 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6925 {
6926 return false;
6927 }
6928 *type = GL_INT;
6929 *numParams = 1;
6930 return true;
6931
6932 case GL_PROGRAM_BINARY_FORMATS_OES:
6933 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6934 {
6935 return false;
6936 }
6937 *type = GL_INT;
6938 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6939 return true;
6940
6941 case GL_PACK_ROW_LENGTH:
6942 case GL_PACK_SKIP_ROWS:
6943 case GL_PACK_SKIP_PIXELS:
6944 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6945 {
6946 return false;
6947 }
6948 *type = GL_INT;
6949 *numParams = 1;
6950 return true;
6951 case GL_UNPACK_ROW_LENGTH:
6952 case GL_UNPACK_SKIP_ROWS:
6953 case GL_UNPACK_SKIP_PIXELS:
6954 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6955 {
6956 return false;
6957 }
6958 *type = GL_INT;
6959 *numParams = 1;
6960 return true;
6961 case GL_VERTEX_ARRAY_BINDING:
6962 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6963 {
6964 return false;
6965 }
6966 *type = GL_INT;
6967 *numParams = 1;
6968 return true;
6969 case GL_PIXEL_PACK_BUFFER_BINDING:
6970 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6971 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6972 {
6973 return false;
6974 }
6975 *type = GL_INT;
6976 *numParams = 1;
6977 return true;
6978 case GL_MAX_SAMPLES:
6979 {
6980 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6981 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6982 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6983 {
6984 return false;
6985 }
6986 *type = GL_INT;
6987 *numParams = 1;
6988 return true;
6989
6990 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6991 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6992 {
6993 return false;
6994 }
6995 *type = GL_INT;
6996 *numParams = 1;
6997 return true;
6998 }
6999 }
7000
7001 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7002 {
7003 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7004 {
7005 return false;
7006 }
7007 *type = GL_INT;
7008 *numParams = 1;
7009 return true;
7010 }
7011
7012 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7013 {
7014 *type = GL_INT;
7015 *numParams = 1;
7016 return true;
7017 }
7018
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007019 if (getClientVersion() < Version(2, 0))
7020 {
7021 switch (pname)
7022 {
7023 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007024 case GL_CLIENT_ACTIVE_TEXTURE:
7025 case GL_MATRIX_MODE:
7026 case GL_MAX_TEXTURE_UNITS:
7027 case GL_MAX_MODELVIEW_STACK_DEPTH:
7028 case GL_MAX_PROJECTION_STACK_DEPTH:
7029 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007030 case GL_VERTEX_ARRAY_STRIDE:
7031 case GL_NORMAL_ARRAY_STRIDE:
7032 case GL_COLOR_ARRAY_STRIDE:
7033 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7034 case GL_VERTEX_ARRAY_SIZE:
7035 case GL_COLOR_ARRAY_SIZE:
7036 case GL_TEXTURE_COORD_ARRAY_SIZE:
7037 case GL_VERTEX_ARRAY_TYPE:
7038 case GL_NORMAL_ARRAY_TYPE:
7039 case GL_COLOR_ARRAY_TYPE:
7040 case GL_TEXTURE_COORD_ARRAY_TYPE:
7041 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7042 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7043 case GL_COLOR_ARRAY_BUFFER_BINDING:
7044 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7045 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7046 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7047 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007048 *type = GL_INT;
7049 *numParams = 1;
7050 return true;
7051 case GL_ALPHA_TEST_REF:
7052 *type = GL_FLOAT;
7053 *numParams = 1;
7054 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007055 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007056 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007057 *type = GL_FLOAT;
7058 *numParams = 4;
7059 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007060 case GL_CURRENT_NORMAL:
7061 *type = GL_FLOAT;
7062 *numParams = 3;
7063 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007064 case GL_MODELVIEW_MATRIX:
7065 case GL_PROJECTION_MATRIX:
7066 case GL_TEXTURE_MATRIX:
7067 *type = GL_FLOAT;
7068 *numParams = 16;
7069 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007070 }
7071 }
7072
Jamie Madill5b772312018-03-08 20:28:32 -05007073 if (getClientVersion() < Version(3, 0))
7074 {
7075 return false;
7076 }
7077
7078 // Check for ES3.0+ parameter names
7079 switch (pname)
7080 {
7081 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7082 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7083 case GL_UNIFORM_BUFFER_BINDING:
7084 case GL_TRANSFORM_FEEDBACK_BINDING:
7085 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7086 case GL_COPY_READ_BUFFER_BINDING:
7087 case GL_COPY_WRITE_BUFFER_BINDING:
7088 case GL_SAMPLER_BINDING:
7089 case GL_READ_BUFFER:
7090 case GL_TEXTURE_BINDING_3D:
7091 case GL_TEXTURE_BINDING_2D_ARRAY:
7092 case GL_MAX_3D_TEXTURE_SIZE:
7093 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7094 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7095 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7096 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7097 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7098 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7099 case GL_MAX_VARYING_COMPONENTS:
7100 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7101 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7102 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7103 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7104 case GL_NUM_EXTENSIONS:
7105 case GL_MAJOR_VERSION:
7106 case GL_MINOR_VERSION:
7107 case GL_MAX_ELEMENTS_INDICES:
7108 case GL_MAX_ELEMENTS_VERTICES:
7109 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7110 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7111 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7112 case GL_UNPACK_IMAGE_HEIGHT:
7113 case GL_UNPACK_SKIP_IMAGES:
7114 {
7115 *type = GL_INT;
7116 *numParams = 1;
7117 return true;
7118 }
7119
7120 case GL_MAX_ELEMENT_INDEX:
7121 case GL_MAX_UNIFORM_BLOCK_SIZE:
7122 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7123 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7124 case GL_MAX_SERVER_WAIT_TIMEOUT:
7125 {
7126 *type = GL_INT_64_ANGLEX;
7127 *numParams = 1;
7128 return true;
7129 }
7130
7131 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7132 case GL_TRANSFORM_FEEDBACK_PAUSED:
7133 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7134 case GL_RASTERIZER_DISCARD:
7135 {
7136 *type = GL_BOOL;
7137 *numParams = 1;
7138 return true;
7139 }
7140
7141 case GL_MAX_TEXTURE_LOD_BIAS:
7142 {
7143 *type = GL_FLOAT;
7144 *numParams = 1;
7145 return true;
7146 }
7147 }
7148
7149 if (getExtensions().requestExtension)
7150 {
7151 switch (pname)
7152 {
7153 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7154 *type = GL_INT;
7155 *numParams = 1;
7156 return true;
7157 }
7158 }
7159
7160 if (getClientVersion() < Version(3, 1))
7161 {
7162 return false;
7163 }
7164
7165 switch (pname)
7166 {
7167 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7168 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7169 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7170 case GL_MAX_FRAMEBUFFER_WIDTH:
7171 case GL_MAX_FRAMEBUFFER_HEIGHT:
7172 case GL_MAX_FRAMEBUFFER_SAMPLES:
7173 case GL_MAX_SAMPLE_MASK_WORDS:
7174 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7175 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7176 case GL_MAX_INTEGER_SAMPLES:
7177 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7178 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7179 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7180 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7181 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7182 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7183 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7184 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7185 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7186 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7187 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7188 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7189 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7190 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7191 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7192 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7193 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7194 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7195 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7196 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7197 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7198 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7199 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7200 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7201 case GL_MAX_UNIFORM_LOCATIONS:
7202 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7203 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7204 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7205 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7206 case GL_MAX_IMAGE_UNITS:
7207 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7208 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7209 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7210 case GL_SHADER_STORAGE_BUFFER_BINDING:
7211 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7212 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7213 *type = GL_INT;
7214 *numParams = 1;
7215 return true;
7216 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7217 *type = GL_INT_64_ANGLEX;
7218 *numParams = 1;
7219 return true;
7220 case GL_SAMPLE_MASK:
7221 *type = GL_BOOL;
7222 *numParams = 1;
7223 return true;
7224 }
7225
7226 if (getExtensions().geometryShader)
7227 {
7228 switch (pname)
7229 {
7230 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7231 case GL_LAYER_PROVOKING_VERTEX_EXT:
7232 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7233 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7234 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7235 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7236 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7237 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7238 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7239 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7240 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7241 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7242 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7243 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7244 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7245 *type = GL_INT;
7246 *numParams = 1;
7247 return true;
7248 }
7249 }
7250
7251 return false;
7252}
7253
7254bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7255{
7256 if (getClientVersion() < Version(3, 0))
7257 {
7258 return false;
7259 }
7260
7261 switch (target)
7262 {
7263 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7264 case GL_UNIFORM_BUFFER_BINDING:
7265 {
7266 *type = GL_INT;
7267 *numParams = 1;
7268 return true;
7269 }
7270 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7271 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7272 case GL_UNIFORM_BUFFER_START:
7273 case GL_UNIFORM_BUFFER_SIZE:
7274 {
7275 *type = GL_INT_64_ANGLEX;
7276 *numParams = 1;
7277 return true;
7278 }
7279 }
7280
7281 if (getClientVersion() < Version(3, 1))
7282 {
7283 return false;
7284 }
7285
7286 switch (target)
7287 {
7288 case GL_IMAGE_BINDING_LAYERED:
7289 {
7290 *type = GL_BOOL;
7291 *numParams = 1;
7292 return true;
7293 }
7294 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7295 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7296 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7297 case GL_SHADER_STORAGE_BUFFER_BINDING:
7298 case GL_VERTEX_BINDING_BUFFER:
7299 case GL_VERTEX_BINDING_DIVISOR:
7300 case GL_VERTEX_BINDING_OFFSET:
7301 case GL_VERTEX_BINDING_STRIDE:
7302 case GL_SAMPLE_MASK_VALUE:
7303 case GL_IMAGE_BINDING_NAME:
7304 case GL_IMAGE_BINDING_LEVEL:
7305 case GL_IMAGE_BINDING_LAYER:
7306 case GL_IMAGE_BINDING_ACCESS:
7307 case GL_IMAGE_BINDING_FORMAT:
7308 {
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313 case GL_ATOMIC_COUNTER_BUFFER_START:
7314 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7315 case GL_SHADER_STORAGE_BUFFER_START:
7316 case GL_SHADER_STORAGE_BUFFER_SIZE:
7317 {
7318 *type = GL_INT_64_ANGLEX;
7319 *numParams = 1;
7320 return true;
7321 }
7322 }
7323
7324 return false;
7325}
7326
7327Program *Context::getProgram(GLuint handle) const
7328{
7329 return mState.mShaderPrograms->getProgram(handle);
7330}
7331
7332Shader *Context::getShader(GLuint handle) const
7333{
7334 return mState.mShaderPrograms->getShader(handle);
7335}
7336
7337bool Context::isTextureGenerated(GLuint texture) const
7338{
7339 return mState.mTextures->isHandleGenerated(texture);
7340}
7341
7342bool Context::isBufferGenerated(GLuint buffer) const
7343{
7344 return mState.mBuffers->isHandleGenerated(buffer);
7345}
7346
7347bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7348{
7349 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7350}
7351
7352bool Context::isFramebufferGenerated(GLuint framebuffer) const
7353{
7354 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7355}
7356
7357bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7358{
7359 return mState.mPipelines->isHandleGenerated(pipeline);
7360}
7361
7362bool Context::usingDisplayTextureShareGroup() const
7363{
7364 return mDisplayTextureShareGroup;
7365}
7366
7367GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7368{
7369 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7370 internalformat == GL_DEPTH_STENCIL
7371 ? GL_DEPTH24_STENCIL8
7372 : internalformat;
7373}
7374
Jamie Madillc29968b2016-01-20 11:17:23 -05007375} // namespace gl