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