blob: a23926091cd23f282518d5c3382c3f9daeda161a [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 Lang4751aab2017-10-30 15:14:52 -0400353 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
354 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400355 {
356 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400359 }
360
Geoff Lang4751aab2017-10-30 15:14:52 -0400361 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400362 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400365 }
366
Jamie Madill4928b7c2017-06-20 12:57:39 -0400367 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500368
Jamie Madill57a89722013-07-02 11:57:03 -0400369 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400377 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Corentin Wallez336129f2017-10-17 15:55:40 -0400380 for (auto type : angle::AllEnums<BufferBinding>())
381 {
382 bindBuffer(type, 0);
383 }
384
385 bindRenderbuffer(GL_RENDERBUFFER, 0);
386
387 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
388 {
389 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
390 }
391
Jamie Madillad9f24e2016-02-12 09:27:24 -0500392 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500395 // No dirty objects.
396
397 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500399 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500400 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
401
402 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
404 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
408 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
409 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
412 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
413 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
414
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
416 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700417 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
419 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400420
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
422 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
423 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
424 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
425 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
426 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800427 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800429
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400430 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431}
432
Jamie Madill4928b7c2017-06-20 12:57:39 -0400433egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434{
Jamie Madille7b3fe22018-04-05 09:42:46 -0400435 // Delete the Surface first to trigger a finish() in Vulkan.
436 SafeDelete(mSurfacelessFramebuffer);
437
438 ANGLE_TRY(releaseSurface(display));
439
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400444 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445
Corentin Wallez80b24112015-08-25 16:41:57 -0400446 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400448 if (query.second != nullptr)
449 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400450 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400451 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400453 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400456 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400457 if (vertexArray.second)
458 {
459 vertexArray.second->onDestroy(this);
460 }
Jamie Madill57a89722013-07-02 11:57:03 -0400461 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400462 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400463
Corentin Wallez80b24112015-08-25 16:41:57 -0400464 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500465 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500466 if (transformFeedback.second != nullptr)
467 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500468 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500469 }
Geoff Langc8058452014-02-03 12:04:11 -0500470 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400471 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500472
Jamie Madill5b772312018-03-08 20:28:32 -0500473 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400474 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800475 if (zeroTexture.get() != nullptr)
476 {
477 ANGLE_TRY(zeroTexture->onDestroy(this));
478 zeroTexture.set(this, nullptr);
479 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400480 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481
Jamie Madill2f348d22017-06-05 10:50:59 -0400482 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500483
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484 mGLState.reset(this);
485
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486 mState.mBuffers->release(this);
487 mState.mShaderPrograms->release(this);
488 mState.mTextures->release(this);
489 mState.mRenderbuffers->release(this);
490 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400491 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500492 mState.mPaths->release(this);
493 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800494 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400495
Jamie Madill76e471e2017-10-21 09:56:01 -0400496 mImplementation->onDestroy(this);
497
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499}
500
Jamie Madill70ee0f62017-02-06 16:04:20 -0500501Context::~Context()
502{
503}
504
Jamie Madill4928b7c2017-06-20 12:57:39 -0400505egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506{
Jamie Madill61e16b42017-06-19 11:13:23 -0400507 mCurrentDisplay = display;
508
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 if (!mHasBeenCurrent)
510 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500512 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400513 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514
Corentin Wallezc295e512017-01-27 17:47:50 -0500515 int width = 0;
516 int height = 0;
517 if (surface != nullptr)
518 {
519 width = surface->getWidth();
520 height = surface->getHeight();
521 }
522
523 mGLState.setViewportParams(0, 0, width, height);
524 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525
526 mHasBeenCurrent = true;
527 }
528
Jamie Madill1b94d432015-08-07 13:23:23 -0400529 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700530 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400531 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400532
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534
535 Framebuffer *newDefault = nullptr;
536 if (surface != nullptr)
537 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400538 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500539 mCurrentSurface = surface;
540 newDefault = surface->getDefaultFramebuffer();
541 }
542 else
543 {
544 if (mSurfacelessFramebuffer == nullptr)
545 {
546 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
547 }
548
549 newDefault = mSurfacelessFramebuffer;
550 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000551
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 // Update default framebuffer, the binding of the previous default
553 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700555 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700557 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400558 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700559 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700561 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500563 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400564 }
Ian Ewell292f0052016-02-04 10:37:32 -0500565
566 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400567 mImplementation->onMakeCurrent(this);
568 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000569}
570
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400572{
Corentin Wallez37c39792015-08-20 14:19:46 -0400573 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500574 Framebuffer *currentDefault = nullptr;
575 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400576 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 currentDefault = mCurrentSurface->getDefaultFramebuffer();
578 }
579 else if (mSurfacelessFramebuffer != nullptr)
580 {
581 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400582 }
583
Corentin Wallezc295e512017-01-27 17:47:50 -0500584 if (mGLState.getReadFramebuffer() == currentDefault)
585 {
586 mGLState.setReadFramebufferBinding(nullptr);
587 }
588 if (mGLState.getDrawFramebuffer() == currentDefault)
589 {
590 mGLState.setDrawFramebufferBinding(nullptr);
591 }
592 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
593
594 if (mCurrentSurface)
595 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400596 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500597 mCurrentSurface = nullptr;
598 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599
600 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400601}
602
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603GLuint Context::createBuffer()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createProgram()
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
Jiawei Shao385b3e02018-03-21 09:43:28 +0800613GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createTexture()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
623GLuint Context::createRenderbuffer()
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626}
627
Brandon Jones59770802018-04-02 13:18:42 -0700628GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300629{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500630 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300631 if (resultOrError.isError())
632 {
633 handleError(resultOrError.getError());
634 return 0;
635 }
636 return resultOrError.getResult();
637}
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639// Returns an unused framebuffer name
640GLuint Context::createFramebuffer()
641{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500642 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500645void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500647 for (int i = 0; i < n; i++)
648 {
649 GLuint handle = mFenceNVHandleAllocator.allocate();
650 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
651 fences[i] = handle;
652 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
Yunchao Hea336b902017-08-02 16:05:21 +0800655GLuint Context::createProgramPipeline()
656{
657 return mState.mPipelines->createProgramPipeline();
658}
659
Jiawei Shao385b3e02018-03-21 09:43:28 +0800660GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800661{
662 UNIMPLEMENTED();
663 return 0u;
664}
665
James Darpinian4d9d4832018-03-13 12:43:28 -0700666void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667{
James Darpinian4d9d4832018-03-13 12:43:28 -0700668 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
669 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670 {
671 detachBuffer(buffer);
672 }
Jamie Madill893ab082014-05-16 16:56:10 -0400673
James Darpinian4d9d4832018-03-13 12:43:28 -0700674 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677void Context::deleteShader(GLuint shader)
678{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteProgram(GLuint program)
683{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500684 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687void Context::deleteTexture(GLuint texture)
688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690 {
691 detachTexture(texture);
692 }
693
Jamie Madill6c1f6712017-02-14 19:08:04 -0500694 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697void Context::deleteRenderbuffer(GLuint renderbuffer)
698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700 {
701 detachRenderbuffer(renderbuffer);
702 }
Jamie Madill893ab082014-05-16 16:56:10 -0400703
Jamie Madill6c1f6712017-02-14 19:08:04 -0500704 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000705}
706
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400707void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400708{
709 // The spec specifies the underlying Fence object is not deleted until all current
710 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
711 // and since our API is currently designed for being called from a single thread, we can delete
712 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400713 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400714}
715
Yunchao Hea336b902017-08-02 16:05:21 +0800716void Context::deleteProgramPipeline(GLuint pipeline)
717{
718 if (mState.mPipelines->getProgramPipeline(pipeline))
719 {
720 detachProgramPipeline(pipeline);
721 }
722
723 mState.mPipelines->deleteObject(this, pipeline);
724}
725
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726void Context::deletePaths(GLuint first, GLsizei range)
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729}
730
Brandon Jones59770802018-04-02 13:18:42 -0700731bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300734 if (pathObj == nullptr)
735 return false;
736
737 return pathObj->hasPathData();
738}
739
Brandon Jones59770802018-04-02 13:18:42 -0700740bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743}
744
Brandon Jones59770802018-04-02 13:18:42 -0700745void Context::pathCommands(GLuint path,
746 GLsizei numCommands,
747 const GLubyte *commands,
748 GLsizei numCoords,
749 GLenum coordType,
750 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300751{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500752 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753
754 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
755}
756
Jamie Madill007530e2017-12-28 14:27:04 -0500757void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300758{
Jamie Madill007530e2017-12-28 14:27:04 -0500759 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300760
761 switch (pname)
762 {
763 case GL_PATH_STROKE_WIDTH_CHROMIUM:
764 pathObj->setStrokeWidth(value);
765 break;
766 case GL_PATH_END_CAPS_CHROMIUM:
767 pathObj->setEndCaps(static_cast<GLenum>(value));
768 break;
769 case GL_PATH_JOIN_STYLE_CHROMIUM:
770 pathObj->setJoinStyle(static_cast<GLenum>(value));
771 break;
772 case GL_PATH_MITER_LIMIT_CHROMIUM:
773 pathObj->setMiterLimit(value);
774 break;
775 case GL_PATH_STROKE_BOUND_CHROMIUM:
776 pathObj->setStrokeBound(value);
777 break;
778 default:
779 UNREACHABLE();
780 break;
781 }
782}
783
Jamie Madill007530e2017-12-28 14:27:04 -0500784void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300785{
Jamie Madill007530e2017-12-28 14:27:04 -0500786 // TODO(jmadill): Should use proper clamping/casting.
787 pathParameterf(path, pname, static_cast<GLfloat>(value));
788}
789
790void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
791{
792 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300793
794 switch (pname)
795 {
796 case GL_PATH_STROKE_WIDTH_CHROMIUM:
797 *value = pathObj->getStrokeWidth();
798 break;
799 case GL_PATH_END_CAPS_CHROMIUM:
800 *value = static_cast<GLfloat>(pathObj->getEndCaps());
801 break;
802 case GL_PATH_JOIN_STYLE_CHROMIUM:
803 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
804 break;
805 case GL_PATH_MITER_LIMIT_CHROMIUM:
806 *value = pathObj->getMiterLimit();
807 break;
808 case GL_PATH_STROKE_BOUND_CHROMIUM:
809 *value = pathObj->getStrokeBound();
810 break;
811 default:
812 UNREACHABLE();
813 break;
814 }
815}
816
Jamie Madill007530e2017-12-28 14:27:04 -0500817void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
818{
819 GLfloat val = 0.0f;
820 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
821 if (value)
822 *value = static_cast<GLint>(val);
823}
824
Brandon Jones59770802018-04-02 13:18:42 -0700825void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300826{
827 mGLState.setPathStencilFunc(func, ref, mask);
828}
829
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830void Context::deleteFramebuffer(GLuint framebuffer)
831{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500832 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833 {
834 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500836
Jamie Madill6c1f6712017-02-14 19:08:04 -0500837 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838}
839
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500840void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500842 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500844 GLuint fence = fences[i];
845
846 FenceNV *fenceObject = nullptr;
847 if (mFenceNVMap.erase(fence, &fenceObject))
848 {
849 mFenceNVHandleAllocator.release(fence);
850 delete fenceObject;
851 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852 }
853}
854
Geoff Lang70d0f492015-12-10 17:45:46 -0500855Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858}
859
Jamie Madill570f7c82014-07-03 10:38:54 -0400860Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863}
864
Geoff Lang70d0f492015-12-10 17:45:46 -0500865Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868}
869
Jamie Madill70b5bb02017-08-28 13:32:37 -0400870Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400871{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400872 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400873}
874
Jamie Madill57a89722013-07-02 11:57:03 -0400875VertexArray *Context::getVertexArray(GLuint handle) const
876{
Jamie Madill96a483b2017-06-27 16:49:21 -0400877 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400878}
879
Jamie Madilldc356042013-07-19 16:36:57 -0400880Sampler *Context::getSampler(GLuint handle) const
881{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500882 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400883}
884
Geoff Langc8058452014-02-03 12:04:11 -0500885TransformFeedback *Context::getTransformFeedback(GLuint handle) const
886{
Jamie Madill96a483b2017-06-27 16:49:21 -0400887 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500888}
889
Yunchao Hea336b902017-08-02 16:05:21 +0800890ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
891{
892 return mState.mPipelines->getProgramPipeline(handle);
893}
894
Geoff Lang70d0f492015-12-10 17:45:46 -0500895LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
896{
897 switch (identifier)
898 {
899 case GL_BUFFER:
900 return getBuffer(name);
901 case GL_SHADER:
902 return getShader(name);
903 case GL_PROGRAM:
904 return getProgram(name);
905 case GL_VERTEX_ARRAY:
906 return getVertexArray(name);
907 case GL_QUERY:
908 return getQuery(name);
909 case GL_TRANSFORM_FEEDBACK:
910 return getTransformFeedback(name);
911 case GL_SAMPLER:
912 return getSampler(name);
913 case GL_TEXTURE:
914 return getTexture(name);
915 case GL_RENDERBUFFER:
916 return getRenderbuffer(name);
917 case GL_FRAMEBUFFER:
918 return getFramebuffer(name);
919 default:
920 UNREACHABLE();
921 return nullptr;
922 }
923}
924
925LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
926{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400927 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500928}
929
Martin Radev9d901792016-07-15 15:58:58 +0300930void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
931{
932 LabeledObject *object = getLabeledObject(identifier, name);
933 ASSERT(object != nullptr);
934
935 std::string labelName = GetObjectLabelFromPointer(length, label);
936 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400937
938 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
939 // specified object is active until we do this.
940 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300941}
942
943void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
944{
945 LabeledObject *object = getLabeledObjectFromPtr(ptr);
946 ASSERT(object != nullptr);
947
948 std::string labelName = GetObjectLabelFromPointer(length, label);
949 object->setLabel(labelName);
950}
951
952void Context::getObjectLabel(GLenum identifier,
953 GLuint name,
954 GLsizei bufSize,
955 GLsizei *length,
956 GLchar *label) const
957{
958 LabeledObject *object = getLabeledObject(identifier, name);
959 ASSERT(object != nullptr);
960
961 const std::string &objectLabel = object->getLabel();
962 GetObjectLabelBase(objectLabel, bufSize, length, label);
963}
964
965void Context::getObjectPtrLabel(const void *ptr,
966 GLsizei bufSize,
967 GLsizei *length,
968 GLchar *label) const
969{
970 LabeledObject *object = getLabeledObjectFromPtr(ptr);
971 ASSERT(object != nullptr);
972
973 const std::string &objectLabel = object->getLabel();
974 GetObjectLabelBase(objectLabel, bufSize, length, label);
975}
976
Jamie Madilldc356042013-07-19 16:36:57 -0400977bool Context::isSampler(GLuint samplerName) const
978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400980}
981
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800982void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000983{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500984 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000985
Jamie Madilldedd7b92014-11-05 16:30:36 -0500986 if (handle == 0)
987 {
988 texture = mZeroTextures[target].get();
989 }
990 else
991 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500992 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500993 }
994
995 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400996 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000997}
998
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500999void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001000{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001001 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1002 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001003 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004}
1005
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001006void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001008 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1009 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001010 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011}
1012
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001013void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001014{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001015 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001016 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001017}
1018
Shao80957d92017-02-20 21:25:59 +08001019void Context::bindVertexBuffer(GLuint bindingIndex,
1020 GLuint bufferHandle,
1021 GLintptr offset,
1022 GLsizei stride)
1023{
1024 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001025 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001026}
1027
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001028void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001029{
Geoff Lang76b10c92014-09-05 16:28:14 -04001030 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001031 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001032 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001033 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001034}
1035
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001036void Context::bindImageTexture(GLuint unit,
1037 GLuint texture,
1038 GLint level,
1039 GLboolean layered,
1040 GLint layer,
1041 GLenum access,
1042 GLenum format)
1043{
1044 Texture *tex = mState.mTextures->getTexture(texture);
1045 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1046}
1047
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048void Context::useProgram(GLuint program)
1049{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001050 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001051}
1052
Jiajia Qin5451d532017-11-16 17:16:34 +08001053void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1054{
1055 UNIMPLEMENTED();
1056}
1057
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001058void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001059{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001060 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001061 TransformFeedback *transformFeedback =
1062 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001063 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001064}
1065
Yunchao Hea336b902017-08-02 16:05:21 +08001066void Context::bindProgramPipeline(GLuint pipelineHandle)
1067{
1068 ProgramPipeline *pipeline =
1069 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1070 mGLState.setProgramPipelineBinding(this, pipeline);
1071}
1072
Jamie Madillf0e04492017-08-26 15:28:42 -04001073void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001076 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077
Geoff Lang5aad9672014-09-08 11:10:42 -04001078 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001079 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001080
1081 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001082 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083}
1084
Jamie Madillf0e04492017-08-26 15:28:42 -04001085void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001087 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001088 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091
Geoff Lang5aad9672014-09-08 11:10:42 -04001092 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001094}
1095
Jamie Madillf0e04492017-08-26 15:28:42 -04001096void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001097{
1098 ASSERT(target == GL_TIMESTAMP_EXT);
1099
1100 Query *queryObject = getQuery(id, true, target);
1101 ASSERT(queryObject);
1102
Jamie Madillf0e04492017-08-26 15:28:42 -04001103 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104}
1105
1106void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1107{
1108 switch (pname)
1109 {
1110 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001111 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001112 break;
1113 case GL_QUERY_COUNTER_BITS_EXT:
1114 switch (target)
1115 {
1116 case GL_TIME_ELAPSED_EXT:
1117 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1118 break;
1119 case GL_TIMESTAMP_EXT:
1120 params[0] = getExtensions().queryCounterBitsTimestamp;
1121 break;
1122 default:
1123 UNREACHABLE();
1124 params[0] = 0;
1125 break;
1126 }
1127 break;
1128 default:
1129 UNREACHABLE();
1130 return;
1131 }
1132}
1133
Brandon Jones59770802018-04-02 13:18:42 -07001134void Context::getQueryivRobust(GLenum target,
1135 GLenum pname,
1136 GLsizei bufSize,
1137 GLsizei *length,
1138 GLint *params)
1139{
1140 getQueryiv(target, pname, params);
1141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144{
Geoff Lang2186c382016-10-14 10:54:54 -04001145 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001146}
1147
Brandon Jones59770802018-04-02 13:18:42 -07001148void Context::getQueryObjectivRobust(GLuint id,
1149 GLenum pname,
1150 GLsizei bufSize,
1151 GLsizei *length,
1152 GLint *params)
1153{
1154 getQueryObjectiv(id, pname, params);
1155}
1156
Geoff Lang2186c382016-10-14 10:54:54 -04001157void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158{
Geoff Lang2186c382016-10-14 10:54:54 -04001159 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160}
1161
Brandon Jones59770802018-04-02 13:18:42 -07001162void Context::getQueryObjectuivRobust(GLuint id,
1163 GLenum pname,
1164 GLsizei bufSize,
1165 GLsizei *length,
1166 GLuint *params)
1167{
1168 getQueryObjectuiv(id, pname, params);
1169}
1170
Geoff Lang2186c382016-10-14 10:54:54 -04001171void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172{
Geoff Lang2186c382016-10-14 10:54:54 -04001173 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174}
1175
Brandon Jones59770802018-04-02 13:18:42 -07001176void Context::getQueryObjecti64vRobust(GLuint id,
1177 GLenum pname,
1178 GLsizei bufSize,
1179 GLsizei *length,
1180 GLint64 *params)
1181{
1182 getQueryObjecti64v(id, pname, params);
1183}
1184
Geoff Lang2186c382016-10-14 10:54:54 -04001185void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186{
Geoff Lang2186c382016-10-14 10:54:54 -04001187 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188}
1189
Brandon Jones59770802018-04-02 13:18:42 -07001190void Context::getQueryObjectui64vRobust(GLuint id,
1191 GLenum pname,
1192 GLsizei bufSize,
1193 GLsizei *length,
1194 GLuint64 *params)
1195{
1196 getQueryObjectui64v(id, pname, params);
1197}
1198
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001199Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001201 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202}
1203
Jamie Madill2f348d22017-06-05 10:50:59 -04001204FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205{
Jamie Madill96a483b2017-06-27 16:49:21 -04001206 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Jamie Madill2f348d22017-06-05 10:50:59 -04001209Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Jamie Madill96a483b2017-06-27 16:49:21 -04001211 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001213 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001215
1216 Query *query = mQueryMap.query(handle);
1217 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001219 query = new Query(mImplementation->createQuery(type), handle);
1220 query->addRef();
1221 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224}
1225
Geoff Lang70d0f492015-12-10 17:45:46 -05001226Query *Context::getQuery(GLuint handle) const
1227{
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001229}
1230
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001231Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001232{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001233 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1234 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001235}
1236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001237Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001239 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240}
1241
Geoff Lang492a7e42014-11-05 13:27:06 -05001242Compiler *Context::getCompiler() const
1243{
Jamie Madill2f348d22017-06-05 10:50:59 -04001244 if (mCompiler.get() == nullptr)
1245 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001246 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001247 }
1248 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001249}
1250
Jamie Madillc1d770e2017-04-13 17:31:24 -04001251void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252{
1253 switch (pname)
1254 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001255 case GL_SHADER_COMPILER:
1256 *params = GL_TRUE;
1257 break;
1258 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1259 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1260 break;
1261 default:
1262 mGLState.getBooleanv(pname, params);
1263 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265}
1266
Jamie Madillc1d770e2017-04-13 17:31:24 -04001267void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268{
Shannon Woods53a94a82014-06-24 15:20:36 -04001269 // Queries about context capabilities and maximums are answered by Context.
1270 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271 switch (pname)
1272 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001273 case GL_ALIASED_LINE_WIDTH_RANGE:
1274 params[0] = mCaps.minAliasedLineWidth;
1275 params[1] = mCaps.maxAliasedLineWidth;
1276 break;
1277 case GL_ALIASED_POINT_SIZE_RANGE:
1278 params[0] = mCaps.minAliasedPointSize;
1279 params[1] = mCaps.maxAliasedPointSize;
1280 break;
1281 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1282 ASSERT(mExtensions.textureFilterAnisotropic);
1283 *params = mExtensions.maxTextureAnisotropy;
1284 break;
1285 case GL_MAX_TEXTURE_LOD_BIAS:
1286 *params = mCaps.maxLODBias;
1287 break;
1288
1289 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1290 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1291 {
1292 ASSERT(mExtensions.pathRendering);
1293 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1294 memcpy(params, m, 16 * sizeof(GLfloat));
1295 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001296 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001297
Jamie Madill231c7f52017-04-26 13:45:37 -04001298 default:
1299 mGLState.getFloatv(pname, params);
1300 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001301 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001302}
1303
Jamie Madillc1d770e2017-04-13 17:31:24 -04001304void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305{
Shannon Woods53a94a82014-06-24 15:20:36 -04001306 // Queries about context capabilities and maximums are answered by Context.
1307 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001308
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001309 switch (pname)
1310 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001311 case GL_MAX_VERTEX_ATTRIBS:
1312 *params = mCaps.maxVertexAttributes;
1313 break;
1314 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1315 *params = mCaps.maxVertexUniformVectors;
1316 break;
1317 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1318 *params = mCaps.maxVertexUniformComponents;
1319 break;
1320 case GL_MAX_VARYING_VECTORS:
1321 *params = mCaps.maxVaryingVectors;
1322 break;
1323 case GL_MAX_VARYING_COMPONENTS:
1324 *params = mCaps.maxVertexOutputComponents;
1325 break;
1326 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1327 *params = mCaps.maxCombinedTextureImageUnits;
1328 break;
1329 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1330 *params = mCaps.maxVertexTextureImageUnits;
1331 break;
1332 case GL_MAX_TEXTURE_IMAGE_UNITS:
1333 *params = mCaps.maxTextureImageUnits;
1334 break;
1335 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1336 *params = mCaps.maxFragmentUniformVectors;
1337 break;
1338 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1339 *params = mCaps.maxFragmentUniformComponents;
1340 break;
1341 case GL_MAX_RENDERBUFFER_SIZE:
1342 *params = mCaps.maxRenderbufferSize;
1343 break;
1344 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1345 *params = mCaps.maxColorAttachments;
1346 break;
1347 case GL_MAX_DRAW_BUFFERS_EXT:
1348 *params = mCaps.maxDrawBuffers;
1349 break;
1350 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1351 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1352 case GL_SUBPIXEL_BITS:
1353 *params = 4;
1354 break;
1355 case GL_MAX_TEXTURE_SIZE:
1356 *params = mCaps.max2DTextureSize;
1357 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001358 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1359 *params = mCaps.maxRectangleTextureSize;
1360 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001361 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1362 *params = mCaps.maxCubeMapTextureSize;
1363 break;
1364 case GL_MAX_3D_TEXTURE_SIZE:
1365 *params = mCaps.max3DTextureSize;
1366 break;
1367 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1368 *params = mCaps.maxArrayTextureLayers;
1369 break;
1370 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1371 *params = mCaps.uniformBufferOffsetAlignment;
1372 break;
1373 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1374 *params = mCaps.maxUniformBufferBindings;
1375 break;
1376 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1377 *params = mCaps.maxVertexUniformBlocks;
1378 break;
1379 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1380 *params = mCaps.maxFragmentUniformBlocks;
1381 break;
1382 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1383 *params = mCaps.maxCombinedTextureImageUnits;
1384 break;
1385 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1386 *params = mCaps.maxVertexOutputComponents;
1387 break;
1388 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1389 *params = mCaps.maxFragmentInputComponents;
1390 break;
1391 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1392 *params = mCaps.minProgramTexelOffset;
1393 break;
1394 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1395 *params = mCaps.maxProgramTexelOffset;
1396 break;
1397 case GL_MAJOR_VERSION:
1398 *params = getClientVersion().major;
1399 break;
1400 case GL_MINOR_VERSION:
1401 *params = getClientVersion().minor;
1402 break;
1403 case GL_MAX_ELEMENTS_INDICES:
1404 *params = mCaps.maxElementsIndices;
1405 break;
1406 case GL_MAX_ELEMENTS_VERTICES:
1407 *params = mCaps.maxElementsVertices;
1408 break;
1409 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1410 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1411 break;
1412 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1413 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1414 break;
1415 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1416 *params = mCaps.maxTransformFeedbackSeparateComponents;
1417 break;
1418 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1419 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1420 break;
1421 case GL_MAX_SAMPLES_ANGLE:
1422 *params = mCaps.maxSamples;
1423 break;
1424 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001425 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001426 params[0] = mCaps.maxViewportWidth;
1427 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001428 }
1429 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 case GL_COMPRESSED_TEXTURE_FORMATS:
1431 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1432 params);
1433 break;
1434 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1435 *params = mResetStrategy;
1436 break;
1437 case GL_NUM_SHADER_BINARY_FORMATS:
1438 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1439 break;
1440 case GL_SHADER_BINARY_FORMATS:
1441 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1442 break;
1443 case GL_NUM_PROGRAM_BINARY_FORMATS:
1444 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1445 break;
1446 case GL_PROGRAM_BINARY_FORMATS:
1447 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1448 break;
1449 case GL_NUM_EXTENSIONS:
1450 *params = static_cast<GLint>(mExtensionStrings.size());
1451 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001452
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 // GL_KHR_debug
1454 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1455 *params = mExtensions.maxDebugMessageLength;
1456 break;
1457 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1458 *params = mExtensions.maxDebugLoggedMessages;
1459 break;
1460 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1461 *params = mExtensions.maxDebugGroupStackDepth;
1462 break;
1463 case GL_MAX_LABEL_LENGTH:
1464 *params = mExtensions.maxLabelLength;
1465 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001466
Martin Radeve5285d22017-07-14 16:23:53 +03001467 // GL_ANGLE_multiview
1468 case GL_MAX_VIEWS_ANGLE:
1469 *params = mExtensions.maxViews;
1470 break;
1471
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 // GL_EXT_disjoint_timer_query
1473 case GL_GPU_DISJOINT_EXT:
1474 *params = mImplementation->getGPUDisjoint();
1475 break;
1476 case GL_MAX_FRAMEBUFFER_WIDTH:
1477 *params = mCaps.maxFramebufferWidth;
1478 break;
1479 case GL_MAX_FRAMEBUFFER_HEIGHT:
1480 *params = mCaps.maxFramebufferHeight;
1481 break;
1482 case GL_MAX_FRAMEBUFFER_SAMPLES:
1483 *params = mCaps.maxFramebufferSamples;
1484 break;
1485 case GL_MAX_SAMPLE_MASK_WORDS:
1486 *params = mCaps.maxSampleMaskWords;
1487 break;
1488 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1489 *params = mCaps.maxColorTextureSamples;
1490 break;
1491 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1492 *params = mCaps.maxDepthTextureSamples;
1493 break;
1494 case GL_MAX_INTEGER_SAMPLES:
1495 *params = mCaps.maxIntegerSamples;
1496 break;
1497 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1498 *params = mCaps.maxVertexAttribRelativeOffset;
1499 break;
1500 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1501 *params = mCaps.maxVertexAttribBindings;
1502 break;
1503 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1504 *params = mCaps.maxVertexAttribStride;
1505 break;
1506 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1507 *params = mCaps.maxVertexAtomicCounterBuffers;
1508 break;
1509 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1510 *params = mCaps.maxVertexAtomicCounters;
1511 break;
1512 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1513 *params = mCaps.maxVertexImageUniforms;
1514 break;
1515 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1516 *params = mCaps.maxVertexShaderStorageBlocks;
1517 break;
1518 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1519 *params = mCaps.maxFragmentAtomicCounterBuffers;
1520 break;
1521 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1522 *params = mCaps.maxFragmentAtomicCounters;
1523 break;
1524 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1525 *params = mCaps.maxFragmentImageUniforms;
1526 break;
1527 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1528 *params = mCaps.maxFragmentShaderStorageBlocks;
1529 break;
1530 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1531 *params = mCaps.minProgramTextureGatherOffset;
1532 break;
1533 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1534 *params = mCaps.maxProgramTextureGatherOffset;
1535 break;
1536 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1537 *params = mCaps.maxComputeWorkGroupInvocations;
1538 break;
1539 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1540 *params = mCaps.maxComputeUniformBlocks;
1541 break;
1542 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1543 *params = mCaps.maxComputeTextureImageUnits;
1544 break;
1545 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1546 *params = mCaps.maxComputeSharedMemorySize;
1547 break;
1548 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1549 *params = mCaps.maxComputeUniformComponents;
1550 break;
1551 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1552 *params = mCaps.maxComputeAtomicCounterBuffers;
1553 break;
1554 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1555 *params = mCaps.maxComputeAtomicCounters;
1556 break;
1557 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1558 *params = mCaps.maxComputeImageUniforms;
1559 break;
1560 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1561 *params = mCaps.maxCombinedComputeUniformComponents;
1562 break;
1563 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1564 *params = mCaps.maxComputeShaderStorageBlocks;
1565 break;
1566 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1567 *params = mCaps.maxCombinedShaderOutputResources;
1568 break;
1569 case GL_MAX_UNIFORM_LOCATIONS:
1570 *params = mCaps.maxUniformLocations;
1571 break;
1572 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1573 *params = mCaps.maxAtomicCounterBufferBindings;
1574 break;
1575 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1576 *params = mCaps.maxAtomicCounterBufferSize;
1577 break;
1578 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1579 *params = mCaps.maxCombinedAtomicCounterBuffers;
1580 break;
1581 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1582 *params = mCaps.maxCombinedAtomicCounters;
1583 break;
1584 case GL_MAX_IMAGE_UNITS:
1585 *params = mCaps.maxImageUnits;
1586 break;
1587 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1588 *params = mCaps.maxCombinedImageUniforms;
1589 break;
1590 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1591 *params = mCaps.maxShaderStorageBufferBindings;
1592 break;
1593 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1594 *params = mCaps.maxCombinedShaderStorageBlocks;
1595 break;
1596 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1597 *params = mCaps.shaderStorageBufferOffsetAlignment;
1598 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001599
1600 // GL_EXT_geometry_shader
1601 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1602 *params = mCaps.maxFramebufferLayers;
1603 break;
1604 case GL_LAYER_PROVOKING_VERTEX_EXT:
1605 *params = mCaps.layerProvokingVertex;
1606 break;
1607 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1608 *params = mCaps.maxGeometryUniformComponents;
1609 break;
1610 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1611 *params = mCaps.maxGeometryUniformBlocks;
1612 break;
1613 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1614 *params = mCaps.maxCombinedGeometryUniformComponents;
1615 break;
1616 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1617 *params = mCaps.maxGeometryInputComponents;
1618 break;
1619 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1620 *params = mCaps.maxGeometryOutputComponents;
1621 break;
1622 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1623 *params = mCaps.maxGeometryOutputVertices;
1624 break;
1625 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1626 *params = mCaps.maxGeometryTotalOutputComponents;
1627 break;
1628 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1629 *params = mCaps.maxGeometryShaderInvocations;
1630 break;
1631 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1632 *params = mCaps.maxGeometryTextureImageUnits;
1633 break;
1634 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1635 *params = mCaps.maxGeometryAtomicCounterBuffers;
1636 break;
1637 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1638 *params = mCaps.maxGeometryAtomicCounters;
1639 break;
1640 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1641 *params = mCaps.maxGeometryImageUniforms;
1642 break;
1643 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1644 *params = mCaps.maxGeometryShaderStorageBlocks;
1645 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001646 // GLES1 emulation: Caps queries
1647 case GL_MAX_TEXTURE_UNITS:
1648 *params = mCaps.maxMultitextureUnits;
1649 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001651 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001653 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001654}
1655
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001656void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001657{
Shannon Woods53a94a82014-06-24 15:20:36 -04001658 // Queries about context capabilities and maximums are answered by Context.
1659 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001660 switch (pname)
1661 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 case GL_MAX_ELEMENT_INDEX:
1663 *params = mCaps.maxElementIndex;
1664 break;
1665 case GL_MAX_UNIFORM_BLOCK_SIZE:
1666 *params = mCaps.maxUniformBlockSize;
1667 break;
1668 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1669 *params = mCaps.maxCombinedVertexUniformComponents;
1670 break;
1671 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1672 *params = mCaps.maxCombinedFragmentUniformComponents;
1673 break;
1674 case GL_MAX_SERVER_WAIT_TIMEOUT:
1675 *params = mCaps.maxServerWaitTimeout;
1676 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001677
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 // GL_EXT_disjoint_timer_query
1679 case GL_TIMESTAMP_EXT:
1680 *params = mImplementation->getTimestamp();
1681 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001682
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1684 *params = mCaps.maxShaderStorageBlockSize;
1685 break;
1686 default:
1687 UNREACHABLE();
1688 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001689 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001690}
1691
Geoff Lang70d0f492015-12-10 17:45:46 -05001692void Context::getPointerv(GLenum pname, void **params) const
1693{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001694 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001695}
1696
Martin Radev66fb8202016-07-28 11:45:20 +03001697void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001698{
Shannon Woods53a94a82014-06-24 15:20:36 -04001699 // Queries about context capabilities and maximums are answered by Context.
1700 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001701
1702 GLenum nativeType;
1703 unsigned int numParams;
1704 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1705 ASSERT(queryStatus);
1706
1707 if (nativeType == GL_INT)
1708 {
1709 switch (target)
1710 {
1711 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1712 ASSERT(index < 3u);
1713 *data = mCaps.maxComputeWorkGroupCount[index];
1714 break;
1715 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1716 ASSERT(index < 3u);
1717 *data = mCaps.maxComputeWorkGroupSize[index];
1718 break;
1719 default:
1720 mGLState.getIntegeri_v(target, index, data);
1721 }
1722 }
1723 else
1724 {
1725 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1726 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001727}
1728
Brandon Jones59770802018-04-02 13:18:42 -07001729void Context::getIntegeri_vRobust(GLenum target,
1730 GLuint index,
1731 GLsizei bufSize,
1732 GLsizei *length,
1733 GLint *data)
1734{
1735 getIntegeri_v(target, index, data);
1736}
1737
Martin Radev66fb8202016-07-28 11:45:20 +03001738void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001739{
Shannon Woods53a94a82014-06-24 15:20:36 -04001740 // Queries about context capabilities and maximums are answered by Context.
1741 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001742
1743 GLenum nativeType;
1744 unsigned int numParams;
1745 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1746 ASSERT(queryStatus);
1747
1748 if (nativeType == GL_INT_64_ANGLEX)
1749 {
1750 mGLState.getInteger64i_v(target, index, data);
1751 }
1752 else
1753 {
1754 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1755 }
1756}
1757
Brandon Jones59770802018-04-02 13:18:42 -07001758void Context::getInteger64i_vRobust(GLenum target,
1759 GLuint index,
1760 GLsizei bufSize,
1761 GLsizei *length,
1762 GLint64 *data)
1763{
1764 getInteger64i_v(target, index, data);
1765}
1766
Martin Radev66fb8202016-07-28 11:45:20 +03001767void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1768{
1769 // Queries about context capabilities and maximums are answered by Context.
1770 // Queries about current GL state values are answered by State.
1771
1772 GLenum nativeType;
1773 unsigned int numParams;
1774 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1775 ASSERT(queryStatus);
1776
1777 if (nativeType == GL_BOOL)
1778 {
1779 mGLState.getBooleani_v(target, index, data);
1780 }
1781 else
1782 {
1783 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1784 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001785}
1786
Brandon Jones59770802018-04-02 13:18:42 -07001787void Context::getBooleani_vRobust(GLenum target,
1788 GLuint index,
1789 GLsizei bufSize,
1790 GLsizei *length,
1791 GLboolean *data)
1792{
1793 getBooleani_v(target, index, data);
1794}
1795
Corentin Wallez336129f2017-10-17 15:55:40 -04001796void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001797{
1798 Buffer *buffer = mGLState.getTargetBuffer(target);
1799 QueryBufferParameteriv(buffer, pname, params);
1800}
1801
Brandon Jones59770802018-04-02 13:18:42 -07001802void Context::getBufferParameterivRobust(BufferBinding target,
1803 GLenum pname,
1804 GLsizei bufSize,
1805 GLsizei *length,
1806 GLint *params)
1807{
1808 getBufferParameteriv(target, pname, params);
1809}
1810
He Yunchao010e4db2017-03-03 14:22:06 +08001811void Context::getFramebufferAttachmentParameteriv(GLenum target,
1812 GLenum attachment,
1813 GLenum pname,
1814 GLint *params)
1815{
1816 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001817 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001818}
1819
Brandon Jones59770802018-04-02 13:18:42 -07001820void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1821 GLenum attachment,
1822 GLenum pname,
1823 GLsizei bufSize,
1824 GLsizei *length,
1825 GLint *params)
1826{
1827 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1828}
1829
He Yunchao010e4db2017-03-03 14:22:06 +08001830void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1831{
1832 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1833 QueryRenderbufferiv(this, renderbuffer, pname, params);
1834}
1835
Brandon Jones59770802018-04-02 13:18:42 -07001836void Context::getRenderbufferParameterivRobust(GLenum target,
1837 GLenum pname,
1838 GLsizei bufSize,
1839 GLsizei *length,
1840 GLint *params)
1841{
1842 getRenderbufferParameteriv(target, pname, params);
1843}
1844
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001845void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001846{
1847 Texture *texture = getTargetTexture(target);
1848 QueryTexParameterfv(texture, pname, params);
1849}
1850
Brandon Jones59770802018-04-02 13:18:42 -07001851void Context::getTexParameterfvRobust(TextureType target,
1852 GLenum pname,
1853 GLsizei bufSize,
1854 GLsizei *length,
1855 GLfloat *params)
1856{
1857 getTexParameterfv(target, pname, params);
1858}
1859
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001860void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001861{
1862 Texture *texture = getTargetTexture(target);
1863 QueryTexParameteriv(texture, pname, params);
1864}
Jiajia Qin5451d532017-11-16 17:16:34 +08001865
Brandon Jones59770802018-04-02 13:18:42 -07001866void Context::getTexParameterivRobust(TextureType target,
1867 GLenum pname,
1868 GLsizei bufSize,
1869 GLsizei *length,
1870 GLint *params)
1871{
1872 getTexParameteriv(target, pname, params);
1873}
1874
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001875void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001876{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001877 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001878 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001879}
1880
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001881void Context::getTexLevelParameterfv(TextureTarget target,
1882 GLint level,
1883 GLenum pname,
1884 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001885{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001886 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001887 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001888}
1889
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001890void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001891{
1892 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001893 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001894 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001895}
1896
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001897void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001898{
1899 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001900 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001901 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001902}
1903
Brandon Jones59770802018-04-02 13:18:42 -07001904void Context::texParameterfvRobust(TextureType target,
1905 GLenum pname,
1906 GLsizei bufSize,
1907 const GLfloat *params)
1908{
1909 texParameterfv(target, pname, params);
1910}
1911
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001912void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001913{
1914 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001915 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001916 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001917}
1918
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001919void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001920{
1921 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001922 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001923 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001924}
1925
Brandon Jones59770802018-04-02 13:18:42 -07001926void Context::texParameterivRobust(TextureType target,
1927 GLenum pname,
1928 GLsizei bufSize,
1929 const GLint *params)
1930{
1931 texParameteriv(target, pname, params);
1932}
1933
Jamie Madill675fe712016-12-19 13:07:54 -05001934void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001935{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001936 // No-op if zero count
1937 if (count == 0)
1938 {
1939 return;
1940 }
1941
Jamie Madill05b35b22017-10-03 09:01:44 -04001942 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001943 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04001944 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001945}
1946
Jamie Madill675fe712016-12-19 13:07:54 -05001947void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001948{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001949 // No-op if zero count
1950 if (count == 0 || instanceCount == 0)
1951 {
1952 return;
1953 }
1954
Jamie Madill05b35b22017-10-03 09:01:44 -04001955 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001956 ANGLE_CONTEXT_TRY(
1957 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04001958 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
1959 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04001960}
1961
Jamie Madill876429b2017-04-20 15:46:24 -04001962void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001963{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001964 // No-op if zero count
1965 if (count == 0)
1966 {
1967 return;
1968 }
1969
Jamie Madill05b35b22017-10-03 09:01:44 -04001970 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001971 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001972}
1973
Jamie Madill675fe712016-12-19 13:07:54 -05001974void Context::drawElementsInstanced(GLenum mode,
1975 GLsizei count,
1976 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001977 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001978 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001979{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001980 // No-op if zero count
1981 if (count == 0 || instances == 0)
1982 {
1983 return;
1984 }
1985
Jamie Madill05b35b22017-10-03 09:01:44 -04001986 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001987 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001988 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001989}
1990
Jamie Madill675fe712016-12-19 13:07:54 -05001991void Context::drawRangeElements(GLenum mode,
1992 GLuint start,
1993 GLuint end,
1994 GLsizei count,
1995 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001996 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001997{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001998 // No-op if zero count
1999 if (count == 0)
2000 {
2001 return;
2002 }
2003
Jamie Madill05b35b22017-10-03 09:01:44 -04002004 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002005 ANGLE_CONTEXT_TRY(
2006 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002007}
2008
Jamie Madill876429b2017-04-20 15:46:24 -04002009void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002010{
Jamie Madill05b35b22017-10-03 09:01:44 -04002011 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002012 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002013}
2014
Jamie Madill876429b2017-04-20 15:46:24 -04002015void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002016{
Jamie Madill05b35b22017-10-03 09:01:44 -04002017 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002018 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002019}
2020
Jamie Madill675fe712016-12-19 13:07:54 -05002021void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002022{
Jamie Madillafa02a22017-11-23 12:57:38 -05002023 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002024}
2025
Jamie Madill675fe712016-12-19 13:07:54 -05002026void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002027{
Jamie Madillafa02a22017-11-23 12:57:38 -05002028 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002029}
2030
Austin Kinross6ee1e782015-05-29 17:05:37 -07002031void Context::insertEventMarker(GLsizei length, const char *marker)
2032{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002033 ASSERT(mImplementation);
2034 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002035}
2036
2037void Context::pushGroupMarker(GLsizei length, const char *marker)
2038{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002039 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002040
2041 if (marker == nullptr)
2042 {
2043 // From the EXT_debug_marker spec,
2044 // "If <marker> is null then an empty string is pushed on the stack."
2045 mImplementation->pushGroupMarker(length, "");
2046 }
2047 else
2048 {
2049 mImplementation->pushGroupMarker(length, marker);
2050 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002051}
2052
2053void Context::popGroupMarker()
2054{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002055 ASSERT(mImplementation);
2056 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002057}
2058
Geoff Langd8605522016-04-13 10:19:12 -04002059void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2060{
2061 Program *programObject = getProgram(program);
2062 ASSERT(programObject);
2063
2064 programObject->bindUniformLocation(location, name);
2065}
2066
Brandon Jones59770802018-04-02 13:18:42 -07002067void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002068{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002069 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002070}
2071
Brandon Jones59770802018-04-02 13:18:42 -07002072void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002073{
2074 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2075}
2076
Brandon Jones59770802018-04-02 13:18:42 -07002077void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002078{
2079 GLfloat I[16];
2080 angle::Matrix<GLfloat>::setToIdentity(I);
2081
2082 mGLState.loadPathRenderingMatrix(matrixMode, I);
2083}
2084
2085void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2086{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002087 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002088 if (!pathObj)
2089 return;
2090
2091 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002092 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002093
2094 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2095}
2096
2097void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2098{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002099 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002100 if (!pathObj)
2101 return;
2102
2103 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002104 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002105
2106 mImplementation->stencilStrokePath(pathObj, reference, mask);
2107}
2108
2109void Context::coverFillPath(GLuint path, GLenum coverMode)
2110{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002111 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002112 if (!pathObj)
2113 return;
2114
2115 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002116 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002117
2118 mImplementation->coverFillPath(pathObj, coverMode);
2119}
2120
2121void Context::coverStrokePath(GLuint path, GLenum coverMode)
2122{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002123 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002124 if (!pathObj)
2125 return;
2126
2127 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002128 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002129
2130 mImplementation->coverStrokePath(pathObj, coverMode);
2131}
2132
2133void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2134{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002135 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002136 if (!pathObj)
2137 return;
2138
2139 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002140 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002141
2142 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2143}
2144
2145void Context::stencilThenCoverStrokePath(GLuint path,
2146 GLint reference,
2147 GLuint mask,
2148 GLenum coverMode)
2149{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002150 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002151 if (!pathObj)
2152 return;
2153
2154 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002155 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002156
2157 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2158}
2159
Sami Väisänend59ca052016-06-21 16:10:00 +03002160void Context::coverFillPathInstanced(GLsizei numPaths,
2161 GLenum pathNameType,
2162 const void *paths,
2163 GLuint pathBase,
2164 GLenum coverMode,
2165 GLenum transformType,
2166 const GLfloat *transformValues)
2167{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002168 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002169
2170 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002171 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002172
2173 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2174}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002175
Sami Väisänend59ca052016-06-21 16:10:00 +03002176void Context::coverStrokePathInstanced(GLsizei numPaths,
2177 GLenum pathNameType,
2178 const void *paths,
2179 GLuint pathBase,
2180 GLenum coverMode,
2181 GLenum transformType,
2182 const GLfloat *transformValues)
2183{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002184 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002185
2186 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002187 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002188
2189 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2190 transformValues);
2191}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002192
Sami Väisänend59ca052016-06-21 16:10:00 +03002193void Context::stencilFillPathInstanced(GLsizei numPaths,
2194 GLenum pathNameType,
2195 const void *paths,
2196 GLuint pathBase,
2197 GLenum fillMode,
2198 GLuint mask,
2199 GLenum transformType,
2200 const GLfloat *transformValues)
2201{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002202 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002203
2204 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002205 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002206
2207 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2208 transformValues);
2209}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002210
Sami Väisänend59ca052016-06-21 16:10:00 +03002211void Context::stencilStrokePathInstanced(GLsizei numPaths,
2212 GLenum pathNameType,
2213 const void *paths,
2214 GLuint pathBase,
2215 GLint reference,
2216 GLuint mask,
2217 GLenum transformType,
2218 const GLfloat *transformValues)
2219{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002220 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002221
2222 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002223 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002224
2225 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2226 transformValues);
2227}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002228
Sami Väisänend59ca052016-06-21 16:10:00 +03002229void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2230 GLenum pathNameType,
2231 const void *paths,
2232 GLuint pathBase,
2233 GLenum fillMode,
2234 GLuint mask,
2235 GLenum coverMode,
2236 GLenum transformType,
2237 const GLfloat *transformValues)
2238{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002239 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002240
2241 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002242 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002243
2244 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2245 transformType, transformValues);
2246}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002247
Sami Väisänend59ca052016-06-21 16:10:00 +03002248void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2249 GLenum pathNameType,
2250 const void *paths,
2251 GLuint pathBase,
2252 GLint reference,
2253 GLuint mask,
2254 GLenum coverMode,
2255 GLenum transformType,
2256 const GLfloat *transformValues)
2257{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002258 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002259
2260 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002261 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002262
2263 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2264 transformType, transformValues);
2265}
2266
Sami Väisänen46eaa942016-06-29 10:26:37 +03002267void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2268{
2269 auto *programObject = getProgram(program);
2270
2271 programObject->bindFragmentInputLocation(location, name);
2272}
2273
2274void Context::programPathFragmentInputGen(GLuint program,
2275 GLint location,
2276 GLenum genMode,
2277 GLint components,
2278 const GLfloat *coeffs)
2279{
2280 auto *programObject = getProgram(program);
2281
Jamie Madillbd044ed2017-06-05 12:59:21 -04002282 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002283}
2284
jchen1015015f72017-03-16 13:54:21 +08002285GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2286{
jchen10fd7c3b52017-03-21 15:36:03 +08002287 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002288 return QueryProgramResourceIndex(programObject, programInterface, name);
2289}
2290
jchen10fd7c3b52017-03-21 15:36:03 +08002291void Context::getProgramResourceName(GLuint program,
2292 GLenum programInterface,
2293 GLuint index,
2294 GLsizei bufSize,
2295 GLsizei *length,
2296 GLchar *name)
2297{
2298 const auto *programObject = getProgram(program);
2299 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2300}
2301
jchen10191381f2017-04-11 13:59:04 +08002302GLint Context::getProgramResourceLocation(GLuint program,
2303 GLenum programInterface,
2304 const GLchar *name)
2305{
2306 const auto *programObject = getProgram(program);
2307 return QueryProgramResourceLocation(programObject, programInterface, name);
2308}
2309
jchen10880683b2017-04-12 16:21:55 +08002310void Context::getProgramResourceiv(GLuint program,
2311 GLenum programInterface,
2312 GLuint index,
2313 GLsizei propCount,
2314 const GLenum *props,
2315 GLsizei bufSize,
2316 GLsizei *length,
2317 GLint *params)
2318{
2319 const auto *programObject = getProgram(program);
2320 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2321 length, params);
2322}
2323
jchen10d9cd7b72017-08-30 15:04:25 +08002324void Context::getProgramInterfaceiv(GLuint program,
2325 GLenum programInterface,
2326 GLenum pname,
2327 GLint *params)
2328{
2329 const auto *programObject = getProgram(program);
2330 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2331}
2332
Jamie Madill71c88b32017-09-14 22:20:29 -04002333void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002334{
Geoff Langda5777c2014-07-11 09:52:58 -04002335 if (error.isError())
2336 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002337 GLenum code = error.getCode();
2338 mErrors.insert(code);
2339 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2340 {
2341 markContextLost();
2342 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002343
Geoff Langee6884e2017-11-09 16:51:11 -05002344 ASSERT(!error.getMessage().empty());
2345 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2346 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002347 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002348}
2349
2350// Get one of the recorded errors and clear its flag, if any.
2351// [OpenGL ES 2.0.24] section 2.5 page 13.
2352GLenum Context::getError()
2353{
Geoff Langda5777c2014-07-11 09:52:58 -04002354 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002355 {
Geoff Langda5777c2014-07-11 09:52:58 -04002356 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357 }
Geoff Langda5777c2014-07-11 09:52:58 -04002358 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002359 {
Geoff Langda5777c2014-07-11 09:52:58 -04002360 GLenum error = *mErrors.begin();
2361 mErrors.erase(mErrors.begin());
2362 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002363 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364}
2365
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002366// NOTE: this function should not assume that this context is current!
2367void Context::markContextLost()
2368{
2369 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002370 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002371 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002372 mContextLostForced = true;
2373 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002374 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002375}
2376
2377bool Context::isContextLost()
2378{
2379 return mContextLost;
2380}
2381
Jamie Madillfa920eb2018-01-04 11:45:50 -05002382GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002383{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002384 // Even if the application doesn't want to know about resets, we want to know
2385 // as it will allow us to skip all the calls.
2386 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002388 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002389 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002390 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002391 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002392
2393 // EXT_robustness, section 2.6: If the reset notification behavior is
2394 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2395 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2396 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002397 }
2398
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002399 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2400 // status should be returned at least once, and GL_NO_ERROR should be returned
2401 // once the device has finished resetting.
2402 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002403 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002404 ASSERT(mResetStatus == GL_NO_ERROR);
2405 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002406
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002407 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002408 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002409 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002410 }
2411 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002412 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002413 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002414 // If markContextLost was used to mark the context lost then
2415 // assume that is not recoverable, and continue to report the
2416 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002417 mResetStatus = mImplementation->getResetStatus();
2418 }
Jamie Madill893ab082014-05-16 16:56:10 -04002419
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002420 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002421}
2422
2423bool Context::isResetNotificationEnabled()
2424{
2425 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2426}
2427
Corentin Walleze3b10e82015-05-20 11:06:25 -04002428const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002429{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002430 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002431}
2432
2433EGLenum Context::getClientType() const
2434{
2435 return mClientType;
2436}
2437
2438EGLenum Context::getRenderBuffer() const
2439{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002440 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2441 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002442 {
2443 return EGL_NONE;
2444 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002445
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002446 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002447 ASSERT(backAttachment != nullptr);
2448 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002449}
2450
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002451VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002452{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002453 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002454 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2455 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002456 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002457 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2458 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002459
Jamie Madill96a483b2017-06-27 16:49:21 -04002460 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002461 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002462
2463 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002464}
2465
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002466TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002467{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002468 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002469 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2470 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002471 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002472 transformFeedback =
2473 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002474 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002475 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002476 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002477
2478 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002479}
2480
2481bool Context::isVertexArrayGenerated(GLuint vertexArray)
2482{
Jamie Madill96a483b2017-06-27 16:49:21 -04002483 ASSERT(mVertexArrayMap.contains(0));
2484 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002485}
2486
2487bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2488{
Jamie Madill96a483b2017-06-27 16:49:21 -04002489 ASSERT(mTransformFeedbackMap.contains(0));
2490 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002491}
2492
Shannon Woods53a94a82014-06-24 15:20:36 -04002493void Context::detachTexture(GLuint texture)
2494{
2495 // Simple pass-through to State's detachTexture method, as textures do not require
2496 // allocation map management either here or in the resource manager at detach time.
2497 // Zero textures are held by the Context, and we don't attempt to request them from
2498 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002499 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002500}
2501
James Darpinian4d9d4832018-03-13 12:43:28 -07002502void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503{
Yuly Novikov5807a532015-12-03 13:01:22 -05002504 // Simple pass-through to State's detachBuffer method, since
2505 // only buffer attachments to container objects that are bound to the current context
2506 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002507
Yuly Novikov5807a532015-12-03 13:01:22 -05002508 // [OpenGL ES 3.2] section 5.1.2 page 45:
2509 // Attachments to unbound container objects, such as
2510 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2511 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002512 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513}
2514
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002515void Context::detachFramebuffer(GLuint framebuffer)
2516{
Shannon Woods53a94a82014-06-24 15:20:36 -04002517 // Framebuffer detachment is handled by Context, because 0 is a valid
2518 // Framebuffer object, and a pointer to it must be passed from Context
2519 // to State at binding time.
2520
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002522 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2523 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2524 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002526 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002527 {
2528 bindReadFramebuffer(0);
2529 }
2530
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002531 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002532 {
2533 bindDrawFramebuffer(0);
2534 }
2535}
2536
2537void Context::detachRenderbuffer(GLuint renderbuffer)
2538{
Jamie Madilla02315b2017-02-23 14:14:47 -05002539 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002540}
2541
Jamie Madill57a89722013-07-02 11:57:03 -04002542void Context::detachVertexArray(GLuint vertexArray)
2543{
Jamie Madill77a72f62015-04-14 11:18:32 -04002544 // Vertex array detachment is handled by Context, because 0 is a valid
2545 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002546 // binding time.
2547
Jamie Madill57a89722013-07-02 11:57:03 -04002548 // [OpenGL ES 3.0.2] section 2.10 page 43:
2549 // If a vertex array object that is currently bound is deleted, the binding
2550 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002551 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002552 {
2553 bindVertexArray(0);
2554 }
2555}
2556
Geoff Langc8058452014-02-03 12:04:11 -05002557void Context::detachTransformFeedback(GLuint transformFeedback)
2558{
Corentin Walleza2257da2016-04-19 16:43:12 -04002559 // Transform feedback detachment is handled by Context, because 0 is a valid
2560 // transform feedback, and a pointer to it must be passed from Context to State at
2561 // binding time.
2562
2563 // The OpenGL specification doesn't mention what should happen when the currently bound
2564 // transform feedback object is deleted. Since it is a container object, we treat it like
2565 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002566 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002567 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002568 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002569 }
Geoff Langc8058452014-02-03 12:04:11 -05002570}
2571
Jamie Madilldc356042013-07-19 16:36:57 -04002572void Context::detachSampler(GLuint sampler)
2573{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002574 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002575}
2576
Yunchao Hea336b902017-08-02 16:05:21 +08002577void Context::detachProgramPipeline(GLuint pipeline)
2578{
2579 mGLState.detachProgramPipeline(this, pipeline);
2580}
2581
Jamie Madill3ef140a2017-08-26 23:11:21 -04002582void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583{
Shaodde78e82017-05-22 14:13:27 +08002584 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585}
2586
Jamie Madille29d1672013-07-19 16:36:57 -04002587void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2588{
Geoff Langc1984ed2016-10-07 12:41:00 -04002589 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002590 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002591 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002592 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002593}
Jamie Madille29d1672013-07-19 16:36:57 -04002594
Geoff Langc1984ed2016-10-07 12:41:00 -04002595void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2596{
2597 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002598 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002599 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002600 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002601}
2602
Brandon Jones59770802018-04-02 13:18:42 -07002603void Context::samplerParameterivRobust(GLuint sampler,
2604 GLenum pname,
2605 GLsizei bufSize,
2606 const GLint *param)
2607{
2608 samplerParameteriv(sampler, pname, param);
2609}
2610
Jamie Madille29d1672013-07-19 16:36:57 -04002611void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2612{
Geoff Langc1984ed2016-10-07 12:41:00 -04002613 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002614 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002615 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002616 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002617}
2618
Geoff Langc1984ed2016-10-07 12:41:00 -04002619void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002620{
Geoff Langc1984ed2016-10-07 12:41:00 -04002621 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002622 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002623 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002624 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002625}
2626
Brandon Jones59770802018-04-02 13:18:42 -07002627void Context::samplerParameterfvRobust(GLuint sampler,
2628 GLenum pname,
2629 GLsizei bufSize,
2630 const GLfloat *param)
2631{
2632 samplerParameterfv(sampler, pname, param);
2633}
2634
Geoff Langc1984ed2016-10-07 12:41:00 -04002635void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002636{
Geoff Langc1984ed2016-10-07 12:41:00 -04002637 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002638 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002639 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002640 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002641}
Jamie Madill9675b802013-07-19 16:36:59 -04002642
Brandon Jones59770802018-04-02 13:18:42 -07002643void Context::getSamplerParameterivRobust(GLuint sampler,
2644 GLenum pname,
2645 GLsizei bufSize,
2646 GLsizei *length,
2647 GLint *params)
2648{
2649 getSamplerParameteriv(sampler, pname, params);
2650}
2651
Geoff Langc1984ed2016-10-07 12:41:00 -04002652void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2653{
2654 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002655 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002656 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002657 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002658}
2659
Brandon Jones59770802018-04-02 13:18:42 -07002660void Context::getSamplerParameterfvRobust(GLuint sampler,
2661 GLenum pname,
2662 GLsizei bufSize,
2663 GLsizei *length,
2664 GLfloat *params)
2665{
2666 getSamplerParameterfv(sampler, pname, params);
2667}
2668
Olli Etuahof0fee072016-03-30 15:11:58 +03002669void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2670{
2671 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002672 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002673}
2674
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002675void Context::initRendererString()
2676{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002677 std::ostringstream rendererString;
2678 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002679 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002680 rendererString << ")";
2681
Geoff Langcec35902014-04-16 10:52:36 -04002682 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002683}
2684
Geoff Langc339c4e2016-11-29 10:37:36 -05002685void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686{
Geoff Langc339c4e2016-11-29 10:37:36 -05002687 const Version &clientVersion = getClientVersion();
2688
2689 std::ostringstream versionString;
2690 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2691 << ANGLE_VERSION_STRING << ")";
2692 mVersionString = MakeStaticString(versionString.str());
2693
2694 std::ostringstream shadingLanguageVersionString;
2695 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2696 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2697 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2698 << ")";
2699 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002700}
2701
Geoff Langcec35902014-04-16 10:52:36 -04002702void Context::initExtensionStrings()
2703{
Geoff Langc339c4e2016-11-29 10:37:36 -05002704 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2705 std::ostringstream combinedStringStream;
2706 std::copy(strings.begin(), strings.end(),
2707 std::ostream_iterator<const char *>(combinedStringStream, " "));
2708 return MakeStaticString(combinedStringStream.str());
2709 };
2710
2711 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002712 for (const auto &extensionString : mExtensions.getStrings())
2713 {
2714 mExtensionStrings.push_back(MakeStaticString(extensionString));
2715 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002716 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002717
Bryan Bernhart58806562017-01-05 13:09:31 -08002718 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2719
Geoff Langc339c4e2016-11-29 10:37:36 -05002720 mRequestableExtensionStrings.clear();
2721 for (const auto &extensionInfo : GetExtensionInfoMap())
2722 {
2723 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002724 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2725 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002726 {
2727 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2728 }
2729 }
2730 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002731}
2732
Geoff Langc339c4e2016-11-29 10:37:36 -05002733const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002734{
Geoff Langc339c4e2016-11-29 10:37:36 -05002735 switch (name)
2736 {
2737 case GL_VENDOR:
2738 return reinterpret_cast<const GLubyte *>("Google Inc.");
2739
2740 case GL_RENDERER:
2741 return reinterpret_cast<const GLubyte *>(mRendererString);
2742
2743 case GL_VERSION:
2744 return reinterpret_cast<const GLubyte *>(mVersionString);
2745
2746 case GL_SHADING_LANGUAGE_VERSION:
2747 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2748
2749 case GL_EXTENSIONS:
2750 return reinterpret_cast<const GLubyte *>(mExtensionString);
2751
2752 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2753 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2754
2755 default:
2756 UNREACHABLE();
2757 return nullptr;
2758 }
Geoff Langcec35902014-04-16 10:52:36 -04002759}
2760
Geoff Langc339c4e2016-11-29 10:37:36 -05002761const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002762{
Geoff Langc339c4e2016-11-29 10:37:36 -05002763 switch (name)
2764 {
2765 case GL_EXTENSIONS:
2766 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2767
2768 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2769 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2770
2771 default:
2772 UNREACHABLE();
2773 return nullptr;
2774 }
Geoff Langcec35902014-04-16 10:52:36 -04002775}
2776
2777size_t Context::getExtensionStringCount() const
2778{
2779 return mExtensionStrings.size();
2780}
2781
Geoff Lang111a99e2017-10-17 10:58:41 -04002782bool Context::isExtensionRequestable(const char *name)
2783{
2784 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2785 auto extension = extensionInfos.find(name);
2786
2787 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2788 return extension != extensionInfos.end() && extension->second.Requestable &&
2789 nativeExtensions.*(extension->second.ExtensionsMember);
2790}
2791
Geoff Langc339c4e2016-11-29 10:37:36 -05002792void Context::requestExtension(const char *name)
2793{
2794 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2795 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2796 const auto &extension = extensionInfos.at(name);
2797 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002798 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002799
2800 if (mExtensions.*(extension.ExtensionsMember))
2801 {
2802 // Extension already enabled
2803 return;
2804 }
2805
2806 mExtensions.*(extension.ExtensionsMember) = true;
2807 updateCaps();
2808 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002809
Jamie Madill2f348d22017-06-05 10:50:59 -04002810 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2811 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002812
Jamie Madill81c2e252017-09-09 23:32:46 -04002813 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2814 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002815 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002816 for (auto &zeroTexture : mZeroTextures)
2817 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002818 if (zeroTexture.get() != nullptr)
2819 {
2820 zeroTexture->signalDirty(this, InitState::Initialized);
2821 }
Geoff Lang9aded172017-04-05 11:07:56 -04002822 }
2823
2824 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002825}
2826
2827size_t Context::getRequestableExtensionStringCount() const
2828{
2829 return mRequestableExtensionStrings.size();
2830}
2831
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002832void Context::beginTransformFeedback(GLenum primitiveMode)
2833{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002834 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002835 ASSERT(transformFeedback != nullptr);
2836 ASSERT(!transformFeedback->isPaused());
2837
Jamie Madill6c1f6712017-02-14 19:08:04 -05002838 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002839}
2840
2841bool Context::hasActiveTransformFeedback(GLuint program) const
2842{
2843 for (auto pair : mTransformFeedbackMap)
2844 {
2845 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2846 {
2847 return true;
2848 }
2849 }
2850 return false;
2851}
2852
Geoff Langb433e872017-10-05 14:01:47 -04002853void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002854{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002855 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002856
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002857 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2858 if (getClientVersion() < Version(2, 0))
2859 {
2860 mCaps.maxMultitextureUnits = 4;
2861 mCaps.maxClipPlanes = 6;
2862 mCaps.maxLights = 8;
2863 mCaps.maxModelviewMatrixStackDepth = 16;
2864 mCaps.maxProjectionMatrixStackDepth = 16;
2865 mCaps.maxTextureMatrixStackDepth = 16;
2866 }
2867
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002868 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002869
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002870 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002871
Geoff Langeb66a6e2016-10-31 13:06:12 -04002872 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002873 {
2874 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002875 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002876 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002877 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002878 mExtensions.multiview = false;
2879 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002880 }
2881
Jiawei Shao89be29a2017-11-06 14:36:45 +08002882 if (getClientVersion() < ES_3_1)
2883 {
2884 // Disable ES3.1+ extensions
2885 mExtensions.geometryShader = false;
2886 }
2887
Geoff Langeb66a6e2016-10-31 13:06:12 -04002888 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002889 {
2890 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002891 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002892 }
2893
Jamie Madill00ed7a12016-05-19 13:13:38 -04002894 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002895 mExtensions.bindUniformLocation = true;
2896 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002897 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002898 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002899 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002900
2901 // Enable the no error extension if the context was created with the flag.
2902 mExtensions.noError = mSkipValidation;
2903
Corentin Wallezccab69d2017-01-27 16:57:15 -05002904 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002905 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002906
Geoff Lang70d0f492015-12-10 17:45:46 -05002907 // Explicitly enable GL_KHR_debug
2908 mExtensions.debug = true;
2909 mExtensions.maxDebugMessageLength = 1024;
2910 mExtensions.maxDebugLoggedMessages = 1024;
2911 mExtensions.maxDebugGroupStackDepth = 1024;
2912 mExtensions.maxLabelLength = 1024;
2913
Geoff Langff5b2d52016-09-07 11:32:23 -04002914 // Explicitly enable GL_ANGLE_robust_client_memory
2915 mExtensions.robustClientMemory = true;
2916
Jamie Madille08a1d32017-03-07 17:24:06 -05002917 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002918 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002919
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002920 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2921 // supports it.
2922 mExtensions.robustBufferAccessBehavior =
2923 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2924
Jamie Madillc43be722017-07-13 16:22:14 -04002925 // Enable the cache control query unconditionally.
2926 mExtensions.programCacheControl = true;
2927
Geoff Lang301d1612014-07-09 10:34:37 -04002928 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002929 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002930
Jamie Madill0f80ed82017-09-19 00:24:56 -04002931 if (getClientVersion() < ES_3_1)
2932 {
2933 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2934 }
2935 else
2936 {
2937 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2938 }
Geoff Lang301d1612014-07-09 10:34:37 -04002939
Jamie Madill0f80ed82017-09-19 00:24:56 -04002940 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2941 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2942 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2943
2944 // Limit textures as well, so we can use fast bitsets with texture bindings.
2945 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2946 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2947 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002948
Jiawei Shaodb342272017-09-27 10:21:45 +08002949 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2950
Geoff Langc287ea62016-09-16 14:46:51 -04002951 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002952 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002953 for (const auto &extensionInfo : GetExtensionInfoMap())
2954 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04002955 // If the user has requested that extensions start disabled and they are requestable,
2956 // disable them.
2957 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002958 {
2959 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2960 }
2961 }
2962
2963 // Generate texture caps
2964 updateCaps();
2965}
2966
2967void Context::updateCaps()
2968{
Geoff Lang900013c2014-07-07 11:32:19 -04002969 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002970 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002971
Jamie Madill7b62cf92017-11-02 15:20:49 -04002972 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002973 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002974 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002975 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002976
Geoff Lang0d8b7242015-09-09 14:56:53 -04002977 // Update the format caps based on the client version and extensions.
2978 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2979 // ES3.
2980 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002981 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002982 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002983 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002984 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002985 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002986
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002987 // OpenGL ES does not support multisampling with non-rendererable formats
2988 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002989 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002990 (getClientVersion() < ES_3_1 &&
2991 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002992 {
Geoff Langd87878e2014-09-19 15:42:59 -04002993 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002994 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002995 else
2996 {
2997 // We may have limited the max samples for some required renderbuffer formats due to
2998 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2999 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3000
3001 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3002 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3003 // exception of signed and unsigned integer formats."
3004 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3005 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3006 {
3007 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3008 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3009 }
3010
3011 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3012 if (getClientVersion() >= ES_3_1)
3013 {
3014 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3015 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3016 // the exception that the signed and unsigned integer formats are required only to
3017 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3018 // multisamples, which must be at least one."
3019 if (formatInfo.componentType == GL_INT ||
3020 formatInfo.componentType == GL_UNSIGNED_INT)
3021 {
3022 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3023 }
3024
3025 // GLES 3.1 section 19.3.1.
3026 if (formatCaps.texturable)
3027 {
3028 if (formatInfo.depthBits > 0)
3029 {
3030 mCaps.maxDepthTextureSamples =
3031 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3032 }
3033 else if (formatInfo.redBits > 0)
3034 {
3035 mCaps.maxColorTextureSamples =
3036 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3037 }
3038 }
3039 }
3040 }
Geoff Langd87878e2014-09-19 15:42:59 -04003041
3042 if (formatCaps.texturable && formatInfo.compressed)
3043 {
Geoff Langca271392017-04-05 12:30:00 -04003044 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003045 }
3046
Geoff Langca271392017-04-05 12:30:00 -04003047 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003048 }
Jamie Madill32447362017-06-28 14:53:52 -04003049
3050 // If program binary is disabled, blank out the memory cache pointer.
3051 if (!mImplementation->getNativeExtensions().getProgramBinary)
3052 {
3053 mMemoryProgramCache = nullptr;
3054 }
Corentin Walleze4477002017-12-01 14:39:58 -05003055
3056 // Compute which buffer types are allowed
3057 mValidBufferBindings.reset();
3058 mValidBufferBindings.set(BufferBinding::ElementArray);
3059 mValidBufferBindings.set(BufferBinding::Array);
3060
3061 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3062 {
3063 mValidBufferBindings.set(BufferBinding::PixelPack);
3064 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3065 }
3066
3067 if (getClientVersion() >= ES_3_0)
3068 {
3069 mValidBufferBindings.set(BufferBinding::CopyRead);
3070 mValidBufferBindings.set(BufferBinding::CopyWrite);
3071 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3072 mValidBufferBindings.set(BufferBinding::Uniform);
3073 }
3074
3075 if (getClientVersion() >= ES_3_1)
3076 {
3077 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3078 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3079 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3080 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3081 }
Geoff Lang493daf52014-07-03 13:38:44 -04003082}
3083
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003084void Context::initWorkarounds()
3085{
Jamie Madill761b02c2017-06-23 16:27:06 -04003086 // Apply back-end workarounds.
3087 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3088
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003089 // Lose the context upon out of memory error if the application is
3090 // expecting to watch for those events.
3091 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3092}
3093
Jamie Madill05b35b22017-10-03 09:01:44 -04003094Error Context::prepareForDraw()
3095{
Geoff Langa8cb2872018-03-09 16:09:40 -05003096 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003097
3098 if (isRobustResourceInitEnabled())
3099 {
3100 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3101 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3102 }
3103
Geoff Langa8cb2872018-03-09 16:09:40 -05003104 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003105 return NoError();
3106}
3107
3108Error Context::prepareForClear(GLbitfield mask)
3109{
Geoff Langa8cb2872018-03-09 16:09:40 -05003110 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003111 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003112 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003113 return NoError();
3114}
3115
3116Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3117{
Geoff Langa8cb2872018-03-09 16:09:40 -05003118 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003119 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3120 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003121 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003122 return NoError();
3123}
3124
Geoff Langa8cb2872018-03-09 16:09:40 -05003125Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003126{
Geoff Langa8cb2872018-03-09 16:09:40 -05003127 ANGLE_TRY(syncDirtyObjects());
3128 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003129 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003130}
3131
Geoff Langa8cb2872018-03-09 16:09:40 -05003132Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003133{
Geoff Langa8cb2872018-03-09 16:09:40 -05003134 ANGLE_TRY(syncDirtyObjects(objectMask));
3135 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003136 return NoError();
3137}
3138
Geoff Langa8cb2872018-03-09 16:09:40 -05003139Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003140{
3141 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3142 mImplementation->syncState(this, dirtyBits);
3143 mGLState.clearDirtyBits();
3144 return NoError();
3145}
3146
Geoff Langa8cb2872018-03-09 16:09:40 -05003147Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003149 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003150 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003151 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003152 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003153}
Jamie Madillc29968b2016-01-20 11:17:23 -05003154
Geoff Langa8cb2872018-03-09 16:09:40 -05003155Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003156{
3157 return mGLState.syncDirtyObjects(this);
3158}
3159
Geoff Langa8cb2872018-03-09 16:09:40 -05003160Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003161{
3162 return mGLState.syncDirtyObjects(this, objectMask);
3163}
3164
Jamie Madillc29968b2016-01-20 11:17:23 -05003165void Context::blitFramebuffer(GLint srcX0,
3166 GLint srcY0,
3167 GLint srcX1,
3168 GLint srcY1,
3169 GLint dstX0,
3170 GLint dstY0,
3171 GLint dstX1,
3172 GLint dstY1,
3173 GLbitfield mask,
3174 GLenum filter)
3175{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003176 if (mask == 0)
3177 {
3178 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3179 // buffers are copied.
3180 return;
3181 }
3182
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003183 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003184 ASSERT(drawFramebuffer);
3185
3186 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3187 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3188
Jamie Madillbc918e72018-03-08 09:47:21 -05003189 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003190
Jamie Madillc564c072017-06-01 12:45:42 -04003191 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003192}
Jamie Madillc29968b2016-01-20 11:17:23 -05003193
3194void Context::clear(GLbitfield mask)
3195{
Geoff Langd4fff502017-09-22 11:28:28 -04003196 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3197 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003198}
3199
3200void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3201{
Geoff Langd4fff502017-09-22 11:28:28 -04003202 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3203 ANGLE_CONTEXT_TRY(
3204 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003205}
3206
3207void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3208{
Geoff Langd4fff502017-09-22 11:28:28 -04003209 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3210 ANGLE_CONTEXT_TRY(
3211 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003212}
3213
3214void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3215{
Geoff Langd4fff502017-09-22 11:28:28 -04003216 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3217 ANGLE_CONTEXT_TRY(
3218 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003219}
3220
3221void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003223 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003224 ASSERT(framebufferObject);
3225
3226 // If a buffer is not present, the clear has no effect
3227 if (framebufferObject->getDepthbuffer() == nullptr &&
3228 framebufferObject->getStencilbuffer() == nullptr)
3229 {
3230 return;
3231 }
3232
Geoff Langd4fff502017-09-22 11:28:28 -04003233 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3234 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003235}
3236
3237void Context::readPixels(GLint x,
3238 GLint y,
3239 GLsizei width,
3240 GLsizei height,
3241 GLenum format,
3242 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003243 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003244{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003245 if (width == 0 || height == 0)
3246 {
3247 return;
3248 }
3249
Jamie Madillbc918e72018-03-08 09:47:21 -05003250 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003251
Jamie Madillb6664922017-07-25 12:55:04 -04003252 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3253 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003254
3255 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003256 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003257}
3258
Brandon Jones59770802018-04-02 13:18:42 -07003259void Context::readPixelsRobust(GLint x,
3260 GLint y,
3261 GLsizei width,
3262 GLsizei height,
3263 GLenum format,
3264 GLenum type,
3265 GLsizei bufSize,
3266 GLsizei *length,
3267 GLsizei *columns,
3268 GLsizei *rows,
3269 void *pixels)
3270{
3271 readPixels(x, y, width, height, format, type, pixels);
3272}
3273
3274void Context::readnPixelsRobust(GLint x,
3275 GLint y,
3276 GLsizei width,
3277 GLsizei height,
3278 GLenum format,
3279 GLenum type,
3280 GLsizei bufSize,
3281 GLsizei *length,
3282 GLsizei *columns,
3283 GLsizei *rows,
3284 void *data)
3285{
3286 readPixels(x, y, width, height, format, type, data);
3287}
3288
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003289void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003290 GLint level,
3291 GLenum internalformat,
3292 GLint x,
3293 GLint y,
3294 GLsizei width,
3295 GLsizei height,
3296 GLint border)
3297{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003298 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003299 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003300
Jamie Madillc29968b2016-01-20 11:17:23 -05003301 Rectangle sourceArea(x, y, width, height);
3302
Jamie Madill05b35b22017-10-03 09:01:44 -04003303 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003304 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003305 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003306}
3307
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003308void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003309 GLint level,
3310 GLint xoffset,
3311 GLint yoffset,
3312 GLint x,
3313 GLint y,
3314 GLsizei width,
3315 GLsizei height)
3316{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003317 if (width == 0 || height == 0)
3318 {
3319 return;
3320 }
3321
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003322 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003323 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003324
Jamie Madillc29968b2016-01-20 11:17:23 -05003325 Offset destOffset(xoffset, yoffset, 0);
3326 Rectangle sourceArea(x, y, width, height);
3327
Jamie Madill05b35b22017-10-03 09:01:44 -04003328 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003329 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003330 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003331}
3332
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003333void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003334 GLint level,
3335 GLint xoffset,
3336 GLint yoffset,
3337 GLint zoffset,
3338 GLint x,
3339 GLint y,
3340 GLsizei width,
3341 GLsizei height)
3342{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003343 if (width == 0 || height == 0)
3344 {
3345 return;
3346 }
3347
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003348 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003349 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003350
Jamie Madillc29968b2016-01-20 11:17:23 -05003351 Offset destOffset(xoffset, yoffset, zoffset);
3352 Rectangle sourceArea(x, y, width, height);
3353
Jamie Madill05b35b22017-10-03 09:01:44 -04003354 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3355 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003356 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3357 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003358}
3359
3360void Context::framebufferTexture2D(GLenum target,
3361 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003362 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003363 GLuint texture,
3364 GLint level)
3365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003366 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003367 ASSERT(framebuffer);
3368
3369 if (texture != 0)
3370 {
3371 Texture *textureObj = getTexture(texture);
3372
3373 ImageIndex index = ImageIndex::MakeInvalid();
3374
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003375 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003376 {
3377 index = ImageIndex::Make2D(level);
3378 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003379 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003380 {
3381 index = ImageIndex::MakeRectangle(level);
3382 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003383 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003384 {
3385 ASSERT(level == 0);
3386 index = ImageIndex::Make2DMultisample();
3387 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003388 else
3389 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003390 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003391 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003392 }
3393
Jamie Madilla02315b2017-02-23 14:14:47 -05003394 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003395 }
3396 else
3397 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003398 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003399 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003400
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003401 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003402}
3403
3404void Context::framebufferRenderbuffer(GLenum target,
3405 GLenum attachment,
3406 GLenum renderbuffertarget,
3407 GLuint renderbuffer)
3408{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003409 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003410 ASSERT(framebuffer);
3411
3412 if (renderbuffer != 0)
3413 {
3414 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003415
3416 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003417 renderbufferObject);
3418 }
3419 else
3420 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003421 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003422 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003423
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003424 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003425}
3426
3427void Context::framebufferTextureLayer(GLenum target,
3428 GLenum attachment,
3429 GLuint texture,
3430 GLint level,
3431 GLint layer)
3432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003433 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003434 ASSERT(framebuffer);
3435
3436 if (texture != 0)
3437 {
3438 Texture *textureObject = getTexture(texture);
3439
3440 ImageIndex index = ImageIndex::MakeInvalid();
3441
Corentin Wallez99d492c2018-02-27 15:17:10 -05003442 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003443 {
3444 index = ImageIndex::Make3D(level, layer);
3445 }
3446 else
3447 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003448 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003449 index = ImageIndex::Make2DArray(level, layer);
3450 }
3451
Jamie Madilla02315b2017-02-23 14:14:47 -05003452 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003453 }
3454 else
3455 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003456 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003457 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003458
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003459 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003460}
3461
Brandon Jones59770802018-04-02 13:18:42 -07003462void Context::framebufferTextureMultiviewLayered(GLenum target,
3463 GLenum attachment,
3464 GLuint texture,
3465 GLint level,
3466 GLint baseViewIndex,
3467 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003468{
Martin Radev82ef7742017-08-08 17:44:58 +03003469 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3470 ASSERT(framebuffer);
3471
3472 if (texture != 0)
3473 {
3474 Texture *textureObj = getTexture(texture);
3475
Martin Radev18b75ba2017-08-15 15:50:40 +03003476 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003477 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3478 numViews, baseViewIndex);
3479 }
3480 else
3481 {
3482 framebuffer->resetAttachment(this, attachment);
3483 }
3484
3485 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003486}
3487
Brandon Jones59770802018-04-02 13:18:42 -07003488void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3489 GLenum attachment,
3490 GLuint texture,
3491 GLint level,
3492 GLsizei numViews,
3493 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003494{
Martin Radev5dae57b2017-07-14 16:15:55 +03003495 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3496 ASSERT(framebuffer);
3497
3498 if (texture != 0)
3499 {
3500 Texture *textureObj = getTexture(texture);
3501
3502 ImageIndex index = ImageIndex::Make2D(level);
3503 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3504 textureObj, numViews, viewportOffsets);
3505 }
3506 else
3507 {
3508 framebuffer->resetAttachment(this, attachment);
3509 }
3510
3511 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003512}
3513
Jamie Madillc29968b2016-01-20 11:17:23 -05003514void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003517 ASSERT(framebuffer);
3518 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003519 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003520}
3521
3522void Context::readBuffer(GLenum mode)
3523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003525 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003526 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003527}
3528
3529void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3530{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003531 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003532 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003533
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 ASSERT(framebuffer);
3536
3537 // The specification isn't clear what should be done when the framebuffer isn't complete.
3538 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003539 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003540}
3541
3542void Context::invalidateFramebuffer(GLenum target,
3543 GLsizei numAttachments,
3544 const GLenum *attachments)
3545{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003546 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003547 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003548
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003549 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003550 ASSERT(framebuffer);
3551
Jamie Madille98b1b52018-03-08 09:47:23 -05003552 bool complete = false;
3553 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3554 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003555 {
Jamie Madill437fa652016-05-03 15:13:24 -04003556 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 }
Jamie Madill437fa652016-05-03 15:13:24 -04003558
Jamie Madill4928b7c2017-06-20 12:57:39 -04003559 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003560}
3561
3562void Context::invalidateSubFramebuffer(GLenum target,
3563 GLsizei numAttachments,
3564 const GLenum *attachments,
3565 GLint x,
3566 GLint y,
3567 GLsizei width,
3568 GLsizei height)
3569{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003570 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003571 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003572
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003574 ASSERT(framebuffer);
3575
Jamie Madille98b1b52018-03-08 09:47:23 -05003576 bool complete = false;
3577 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3578 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 {
Jamie Madill437fa652016-05-03 15:13:24 -04003580 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003581 }
Jamie Madill437fa652016-05-03 15:13:24 -04003582
3583 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003584 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003585}
3586
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003587void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003588 GLint level,
3589 GLint internalformat,
3590 GLsizei width,
3591 GLsizei height,
3592 GLint border,
3593 GLenum format,
3594 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003595 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003596{
Jamie Madillbc918e72018-03-08 09:47:21 -05003597 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003598
3599 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003600 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003601 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3602 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003603}
3604
Brandon Jones59770802018-04-02 13:18:42 -07003605void Context::texImage2DRobust(TextureTarget target,
3606 GLint level,
3607 GLint internalformat,
3608 GLsizei width,
3609 GLsizei height,
3610 GLint border,
3611 GLenum format,
3612 GLenum type,
3613 GLsizei bufSize,
3614 const void *pixels)
3615{
3616 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3617}
3618
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003619void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003620 GLint level,
3621 GLint internalformat,
3622 GLsizei width,
3623 GLsizei height,
3624 GLsizei depth,
3625 GLint border,
3626 GLenum format,
3627 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003628 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003629{
Jamie Madillbc918e72018-03-08 09:47:21 -05003630 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003631
3632 Extents size(width, height, depth);
3633 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003634 handleError(texture->setImage(this, mGLState.getUnpackState(),
3635 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3636 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003637}
3638
Brandon Jones59770802018-04-02 13:18:42 -07003639void Context::texImage3DRobust(TextureType target,
3640 GLint level,
3641 GLint internalformat,
3642 GLsizei width,
3643 GLsizei height,
3644 GLsizei depth,
3645 GLint border,
3646 GLenum format,
3647 GLenum type,
3648 GLsizei bufSize,
3649 const void *pixels)
3650{
3651 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3652}
3653
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003654void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003655 GLint level,
3656 GLint xoffset,
3657 GLint yoffset,
3658 GLsizei width,
3659 GLsizei height,
3660 GLenum format,
3661 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003662 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003663{
3664 // Zero sized uploads are valid but no-ops
3665 if (width == 0 || height == 0)
3666 {
3667 return;
3668 }
3669
Jamie Madillbc918e72018-03-08 09:47:21 -05003670 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003671
3672 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003673 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003674 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3675 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003676}
3677
Brandon Jones59770802018-04-02 13:18:42 -07003678void Context::texSubImage2DRobust(TextureTarget target,
3679 GLint level,
3680 GLint xoffset,
3681 GLint yoffset,
3682 GLsizei width,
3683 GLsizei height,
3684 GLenum format,
3685 GLenum type,
3686 GLsizei bufSize,
3687 const void *pixels)
3688{
3689 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3690}
3691
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003692void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003693 GLint level,
3694 GLint xoffset,
3695 GLint yoffset,
3696 GLint zoffset,
3697 GLsizei width,
3698 GLsizei height,
3699 GLsizei depth,
3700 GLenum format,
3701 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003702 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003703{
3704 // Zero sized uploads are valid but no-ops
3705 if (width == 0 || height == 0 || depth == 0)
3706 {
3707 return;
3708 }
3709
Jamie Madillbc918e72018-03-08 09:47:21 -05003710 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003711
3712 Box area(xoffset, yoffset, zoffset, width, height, depth);
3713 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003714 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3715 NonCubeTextureTypeToTarget(target), level, area, format, type,
3716 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003717}
3718
Brandon Jones59770802018-04-02 13:18:42 -07003719void Context::texSubImage3DRobust(TextureType target,
3720 GLint level,
3721 GLint xoffset,
3722 GLint yoffset,
3723 GLint zoffset,
3724 GLsizei width,
3725 GLsizei height,
3726 GLsizei depth,
3727 GLenum format,
3728 GLenum type,
3729 GLsizei bufSize,
3730 const void *pixels)
3731{
3732 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3733 pixels);
3734}
3735
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003736void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003737 GLint level,
3738 GLenum internalformat,
3739 GLsizei width,
3740 GLsizei height,
3741 GLint border,
3742 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003743 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003744{
Jamie Madillbc918e72018-03-08 09:47:21 -05003745 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003746
3747 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003748 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003749 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3750 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003751 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003752}
3753
Brandon Jones59770802018-04-02 13:18:42 -07003754void Context::compressedTexImage2DRobust(TextureTarget target,
3755 GLint level,
3756 GLenum internalformat,
3757 GLsizei width,
3758 GLsizei height,
3759 GLint border,
3760 GLsizei imageSize,
3761 GLsizei dataSize,
3762 const GLvoid *data)
3763{
3764 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3765}
3766
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003767void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003768 GLint level,
3769 GLenum internalformat,
3770 GLsizei width,
3771 GLsizei height,
3772 GLsizei depth,
3773 GLint border,
3774 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003775 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003776{
Jamie Madillbc918e72018-03-08 09:47:21 -05003777 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003778
3779 Extents size(width, height, depth);
3780 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003781 handleError(texture->setCompressedImage(
3782 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3783 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003784}
3785
Brandon Jones59770802018-04-02 13:18:42 -07003786void Context::compressedTexImage3DRobust(TextureType target,
3787 GLint level,
3788 GLenum internalformat,
3789 GLsizei width,
3790 GLsizei height,
3791 GLsizei depth,
3792 GLint border,
3793 GLsizei imageSize,
3794 GLsizei dataSize,
3795 const GLvoid *data)
3796{
3797 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3798 data);
3799}
3800
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003801void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003802 GLint level,
3803 GLint xoffset,
3804 GLint yoffset,
3805 GLsizei width,
3806 GLsizei height,
3807 GLenum format,
3808 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003809 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003810{
Jamie Madillbc918e72018-03-08 09:47:21 -05003811 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003812
3813 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003814 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003815 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3816 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003817 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003818}
3819
Brandon Jones59770802018-04-02 13:18:42 -07003820void Context::compressedTexSubImage2DRobust(TextureTarget target,
3821 GLint level,
3822 GLint xoffset,
3823 GLint yoffset,
3824 GLsizei width,
3825 GLsizei height,
3826 GLenum format,
3827 GLsizei imageSize,
3828 GLsizei dataSize,
3829 const GLvoid *data)
3830{
3831 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3832 data);
3833}
3834
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003835void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003836 GLint level,
3837 GLint xoffset,
3838 GLint yoffset,
3839 GLint zoffset,
3840 GLsizei width,
3841 GLsizei height,
3842 GLsizei depth,
3843 GLenum format,
3844 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003845 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003846{
3847 // Zero sized uploads are valid but no-ops
3848 if (width == 0 || height == 0)
3849 {
3850 return;
3851 }
3852
Jamie Madillbc918e72018-03-08 09:47:21 -05003853 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003854
3855 Box area(xoffset, yoffset, zoffset, width, height, depth);
3856 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003857 handleError(texture->setCompressedSubImage(
3858 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3859 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003860}
3861
Brandon Jones59770802018-04-02 13:18:42 -07003862void Context::compressedTexSubImage3DRobust(TextureType target,
3863 GLint level,
3864 GLint xoffset,
3865 GLint yoffset,
3866 GLint zoffset,
3867 GLsizei width,
3868 GLsizei height,
3869 GLsizei depth,
3870 GLenum format,
3871 GLsizei imageSize,
3872 GLsizei dataSize,
3873 const GLvoid *data)
3874{
3875 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
3876 imageSize, data);
3877}
3878
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003879void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003880{
3881 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003882 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003883}
3884
Jamie Madill007530e2017-12-28 14:27:04 -05003885void Context::copyTexture(GLuint sourceId,
3886 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003887 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003888 GLuint destId,
3889 GLint destLevel,
3890 GLint internalFormat,
3891 GLenum destType,
3892 GLboolean unpackFlipY,
3893 GLboolean unpackPremultiplyAlpha,
3894 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003895{
Jamie Madillbc918e72018-03-08 09:47:21 -05003896 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003897
3898 gl::Texture *sourceTexture = getTexture(sourceId);
3899 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003900 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3901 sourceLevel, ConvertToBool(unpackFlipY),
3902 ConvertToBool(unpackPremultiplyAlpha),
3903 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003904}
3905
Jamie Madill007530e2017-12-28 14:27:04 -05003906void Context::copySubTexture(GLuint sourceId,
3907 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003908 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003909 GLuint destId,
3910 GLint destLevel,
3911 GLint xoffset,
3912 GLint yoffset,
3913 GLint x,
3914 GLint y,
3915 GLsizei width,
3916 GLsizei height,
3917 GLboolean unpackFlipY,
3918 GLboolean unpackPremultiplyAlpha,
3919 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003920{
3921 // Zero sized copies are valid but no-ops
3922 if (width == 0 || height == 0)
3923 {
3924 return;
3925 }
3926
Jamie Madillbc918e72018-03-08 09:47:21 -05003927 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003928
3929 gl::Texture *sourceTexture = getTexture(sourceId);
3930 gl::Texture *destTexture = getTexture(destId);
3931 Offset offset(xoffset, yoffset, 0);
3932 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003933 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3934 ConvertToBool(unpackFlipY),
3935 ConvertToBool(unpackPremultiplyAlpha),
3936 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003937}
3938
Jamie Madill007530e2017-12-28 14:27:04 -05003939void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003940{
Jamie Madillbc918e72018-03-08 09:47:21 -05003941 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003942
3943 gl::Texture *sourceTexture = getTexture(sourceId);
3944 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003945 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003946}
3947
Corentin Wallez336129f2017-10-17 15:55:40 -04003948void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003949{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003950 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003951 ASSERT(buffer);
3952
Geoff Lang496c02d2016-10-20 11:38:11 -07003953 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003954}
3955
Brandon Jones59770802018-04-02 13:18:42 -07003956void Context::getBufferPointervRobust(BufferBinding target,
3957 GLenum pname,
3958 GLsizei bufSize,
3959 GLsizei *length,
3960 void **params)
3961{
3962 getBufferPointerv(target, pname, params);
3963}
3964
Corentin Wallez336129f2017-10-17 15:55:40 -04003965void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003966{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003967 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003968 ASSERT(buffer);
3969
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003970 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003971 if (error.isError())
3972 {
Jamie Madill437fa652016-05-03 15:13:24 -04003973 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003974 return nullptr;
3975 }
3976
3977 return buffer->getMapPointer();
3978}
3979
Corentin Wallez336129f2017-10-17 15:55:40 -04003980GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003981{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003982 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003983 ASSERT(buffer);
3984
3985 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003986 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003987 if (error.isError())
3988 {
Jamie Madill437fa652016-05-03 15:13:24 -04003989 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003990 return GL_FALSE;
3991 }
3992
3993 return result;
3994}
3995
Corentin Wallez336129f2017-10-17 15:55:40 -04003996void *Context::mapBufferRange(BufferBinding target,
3997 GLintptr offset,
3998 GLsizeiptr length,
3999 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004000{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004002 ASSERT(buffer);
4003
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004004 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004005 if (error.isError())
4006 {
Jamie Madill437fa652016-05-03 15:13:24 -04004007 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004008 return nullptr;
4009 }
4010
4011 return buffer->getMapPointer();
4012}
4013
Corentin Wallez336129f2017-10-17 15:55:40 -04004014void Context::flushMappedBufferRange(BufferBinding /*target*/,
4015 GLintptr /*offset*/,
4016 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004017{
4018 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4019}
4020
Jamie Madillbc918e72018-03-08 09:47:21 -05004021Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004022{
Geoff Langa8cb2872018-03-09 16:09:40 -05004023 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004024}
4025
Jamie Madillbc918e72018-03-08 09:47:21 -05004026Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004027{
Geoff Langa8cb2872018-03-09 16:09:40 -05004028 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004029}
4030
Jamie Madillbc918e72018-03-08 09:47:21 -05004031Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004032{
Geoff Langa8cb2872018-03-09 16:09:40 -05004033 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004034}
4035
Jiajia Qin5451d532017-11-16 17:16:34 +08004036void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4037{
4038 UNIMPLEMENTED();
4039}
4040
Jamie Madillc20ab272016-06-09 07:20:46 -07004041void Context::activeTexture(GLenum texture)
4042{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004043 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004044}
4045
Jamie Madill876429b2017-04-20 15:46:24 -04004046void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004047{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004048 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004049}
4050
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004051void Context::blendEquation(GLenum mode)
4052{
4053 mGLState.setBlendEquation(mode, mode);
4054}
4055
Jamie Madillc20ab272016-06-09 07:20:46 -07004056void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004059}
4060
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004061void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4062{
4063 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4064}
4065
Jamie Madillc20ab272016-06-09 07:20:46 -07004066void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4067{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004068 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004069}
4070
Jamie Madill876429b2017-04-20 15:46:24 -04004071void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004072{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004073 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004074}
4075
Jamie Madill876429b2017-04-20 15:46:24 -04004076void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004077{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004078 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004079}
4080
4081void Context::clearStencil(GLint s)
4082{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004083 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004084}
4085
4086void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4087{
Geoff Lang92019432017-11-20 13:09:34 -05004088 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4089 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004090}
4091
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004092void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004093{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004094 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004095}
4096
4097void Context::depthFunc(GLenum func)
4098{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004099 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004100}
4101
4102void Context::depthMask(GLboolean flag)
4103{
Geoff Lang92019432017-11-20 13:09:34 -05004104 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004105}
4106
Jamie Madill876429b2017-04-20 15:46:24 -04004107void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004108{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004109 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004110}
4111
4112void Context::disable(GLenum cap)
4113{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004114 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004115}
4116
4117void Context::disableVertexAttribArray(GLuint index)
4118{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004119 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004120}
4121
4122void Context::enable(GLenum cap)
4123{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004124 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004125}
4126
4127void Context::enableVertexAttribArray(GLuint index)
4128{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004129 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004130}
4131
4132void Context::frontFace(GLenum mode)
4133{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004134 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004135}
4136
4137void Context::hint(GLenum target, GLenum mode)
4138{
4139 switch (target)
4140 {
4141 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004143 break;
4144
4145 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004146 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004147 break;
4148
4149 default:
4150 UNREACHABLE();
4151 return;
4152 }
4153}
4154
4155void Context::lineWidth(GLfloat width)
4156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004157 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004158}
4159
4160void Context::pixelStorei(GLenum pname, GLint param)
4161{
4162 switch (pname)
4163 {
4164 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004165 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004166 break;
4167
4168 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004169 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004170 break;
4171
4172 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004173 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004174 break;
4175
4176 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004177 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004178 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004179 break;
4180
4181 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004182 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004183 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004184 break;
4185
4186 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004187 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004188 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004189 break;
4190
4191 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004192 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004193 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004194 break;
4195
4196 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004197 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004198 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004199 break;
4200
4201 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004202 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004203 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004204 break;
4205
4206 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004207 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004208 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004209 break;
4210
4211 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004212 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004213 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004214 break;
4215
4216 default:
4217 UNREACHABLE();
4218 return;
4219 }
4220}
4221
4222void Context::polygonOffset(GLfloat factor, GLfloat units)
4223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004224 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004225}
4226
Jamie Madill876429b2017-04-20 15:46:24 -04004227void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004228{
Geoff Lang92019432017-11-20 13:09:34 -05004229 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004230}
4231
Jiawei Shaodb342272017-09-27 10:21:45 +08004232void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4233{
4234 mGLState.setSampleMaskParams(maskNumber, mask);
4235}
4236
Jamie Madillc20ab272016-06-09 07:20:46 -07004237void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
4242void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4243{
4244 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4245 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004246 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004247 }
4248
4249 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4250 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004251 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004252 }
4253}
4254
4255void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4256{
4257 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4258 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004259 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004260 }
4261
4262 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4263 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265 }
4266}
4267
4268void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4269{
4270 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4271 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004273 }
4274
4275 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4276 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004278 }
4279}
4280
4281void Context::vertexAttrib1f(GLuint index, GLfloat x)
4282{
4283 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285}
4286
4287void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4288{
4289 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004290 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004291}
4292
4293void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4294{
4295 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004297}
4298
4299void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4300{
4301 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004303}
4304
4305void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4306{
4307 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309}
4310
4311void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4312{
4313 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004314 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004315}
4316
4317void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4318{
4319 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
4323void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004326}
4327
4328void Context::vertexAttribPointer(GLuint index,
4329 GLint size,
4330 GLenum type,
4331 GLboolean normalized,
4332 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004333 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004334{
Corentin Wallez336129f2017-10-17 15:55:40 -04004335 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004336 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004337}
4338
Shao80957d92017-02-20 21:25:59 +08004339void Context::vertexAttribFormat(GLuint attribIndex,
4340 GLint size,
4341 GLenum type,
4342 GLboolean normalized,
4343 GLuint relativeOffset)
4344{
Geoff Lang92019432017-11-20 13:09:34 -05004345 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004346 relativeOffset);
4347}
4348
4349void Context::vertexAttribIFormat(GLuint attribIndex,
4350 GLint size,
4351 GLenum type,
4352 GLuint relativeOffset)
4353{
4354 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4355}
4356
4357void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4358{
Shaodde78e82017-05-22 14:13:27 +08004359 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004360}
4361
Jiajia Qin5451d532017-11-16 17:16:34 +08004362void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004363{
4364 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4365}
4366
Jamie Madillc20ab272016-06-09 07:20:46 -07004367void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4368{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004369 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004370}
4371
4372void Context::vertexAttribIPointer(GLuint index,
4373 GLint size,
4374 GLenum type,
4375 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004376 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004377{
Corentin Wallez336129f2017-10-17 15:55:40 -04004378 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4379 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380}
4381
4382void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4383{
4384 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386}
4387
4388void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4389{
4390 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004391 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004392}
4393
4394void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
4399void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4400{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004401 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004404void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4405{
4406 const VertexAttribCurrentValueData &currentValues =
4407 getGLState().getVertexAttribCurrentValue(index);
4408 const VertexArray *vao = getGLState().getVertexArray();
4409 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4410 currentValues, pname, params);
4411}
4412
Brandon Jones59770802018-04-02 13:18:42 -07004413void Context::getVertexAttribivRobust(GLuint index,
4414 GLenum pname,
4415 GLsizei bufSize,
4416 GLsizei *length,
4417 GLint *params)
4418{
4419 getVertexAttribiv(index, pname, params);
4420}
4421
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004422void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4423{
4424 const VertexAttribCurrentValueData &currentValues =
4425 getGLState().getVertexAttribCurrentValue(index);
4426 const VertexArray *vao = getGLState().getVertexArray();
4427 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4428 currentValues, pname, params);
4429}
4430
Brandon Jones59770802018-04-02 13:18:42 -07004431void Context::getVertexAttribfvRobust(GLuint index,
4432 GLenum pname,
4433 GLsizei bufSize,
4434 GLsizei *length,
4435 GLfloat *params)
4436{
4437 getVertexAttribfv(index, pname, params);
4438}
4439
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004440void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4441{
4442 const VertexAttribCurrentValueData &currentValues =
4443 getGLState().getVertexAttribCurrentValue(index);
4444 const VertexArray *vao = getGLState().getVertexArray();
4445 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4446 currentValues, pname, params);
4447}
4448
Brandon Jones59770802018-04-02 13:18:42 -07004449void Context::getVertexAttribIivRobust(GLuint index,
4450 GLenum pname,
4451 GLsizei bufSize,
4452 GLsizei *length,
4453 GLint *params)
4454{
4455 getVertexAttribIiv(index, pname, params);
4456}
4457
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004458void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4459{
4460 const VertexAttribCurrentValueData &currentValues =
4461 getGLState().getVertexAttribCurrentValue(index);
4462 const VertexArray *vao = getGLState().getVertexArray();
4463 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4464 currentValues, pname, params);
4465}
4466
Brandon Jones59770802018-04-02 13:18:42 -07004467void Context::getVertexAttribIuivRobust(GLuint index,
4468 GLenum pname,
4469 GLsizei bufSize,
4470 GLsizei *length,
4471 GLuint *params)
4472{
4473 getVertexAttribIuiv(index, pname, params);
4474}
4475
Jamie Madill876429b2017-04-20 15:46:24 -04004476void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004477{
4478 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4479 QueryVertexAttribPointerv(attrib, pname, pointer);
4480}
4481
Brandon Jones59770802018-04-02 13:18:42 -07004482void Context::getVertexAttribPointervRobust(GLuint index,
4483 GLenum pname,
4484 GLsizei bufSize,
4485 GLsizei *length,
4486 void **pointer)
4487{
4488 getVertexAttribPointerv(index, pname, pointer);
4489}
4490
Jamie Madillc20ab272016-06-09 07:20:46 -07004491void Context::debugMessageControl(GLenum source,
4492 GLenum type,
4493 GLenum severity,
4494 GLsizei count,
4495 const GLuint *ids,
4496 GLboolean enabled)
4497{
4498 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004499 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004500 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::debugMessageInsert(GLenum source,
4504 GLenum type,
4505 GLuint id,
4506 GLenum severity,
4507 GLsizei length,
4508 const GLchar *buf)
4509{
4510 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519GLuint Context::getDebugMessageLog(GLuint count,
4520 GLsizei bufSize,
4521 GLenum *sources,
4522 GLenum *types,
4523 GLuint *ids,
4524 GLenum *severities,
4525 GLsizei *lengths,
4526 GLchar *messageLog)
4527{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004528 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4529 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004530}
4531
4532void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4533{
4534 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004535 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004536 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
4539void Context::popDebugGroup()
4540{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004542 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004543}
4544
Corentin Wallez336129f2017-10-17 15:55:40 -04004545void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004546{
4547 Buffer *buffer = mGLState.getTargetBuffer(target);
4548 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004549 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004550}
4551
Corentin Wallez336129f2017-10-17 15:55:40 -04004552void Context::bufferSubData(BufferBinding target,
4553 GLintptr offset,
4554 GLsizeiptr size,
4555 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004556{
4557 if (data == nullptr)
4558 {
4559 return;
4560 }
4561
4562 Buffer *buffer = mGLState.getTargetBuffer(target);
4563 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004564 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004565}
4566
Jamie Madillef300b12016-10-07 15:12:09 -04004567void Context::attachShader(GLuint program, GLuint shader)
4568{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004569 Program *programObject = mState.mShaderPrograms->getProgram(program);
4570 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004571 ASSERT(programObject && shaderObject);
4572 programObject->attachShader(shaderObject);
4573}
4574
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004575const Workarounds &Context::getWorkarounds() const
4576{
4577 return mWorkarounds;
4578}
4579
Corentin Wallez336129f2017-10-17 15:55:40 -04004580void Context::copyBufferSubData(BufferBinding readTarget,
4581 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004582 GLintptr readOffset,
4583 GLintptr writeOffset,
4584 GLsizeiptr size)
4585{
4586 // if size is zero, the copy is a successful no-op
4587 if (size == 0)
4588 {
4589 return;
4590 }
4591
4592 // TODO(jmadill): cache these.
4593 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4594 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4595
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004596 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004597}
4598
Jamie Madill01a80ee2016-11-07 12:06:18 -05004599void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4600{
4601 Program *programObject = getProgram(program);
4602 // TODO(jmadill): Re-use this from the validation if possible.
4603 ASSERT(programObject);
4604 programObject->bindAttributeLocation(index, name);
4605}
4606
Corentin Wallez336129f2017-10-17 15:55:40 -04004607void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004608{
Corentin Wallez336129f2017-10-17 15:55:40 -04004609 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4610 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004611}
4612
Corentin Wallez336129f2017-10-17 15:55:40 -04004613void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004614{
4615 bindBufferRange(target, index, buffer, 0, 0);
4616}
4617
Corentin Wallez336129f2017-10-17 15:55:40 -04004618void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004619 GLuint index,
4620 GLuint buffer,
4621 GLintptr offset,
4622 GLsizeiptr size)
4623{
Corentin Wallez336129f2017-10-17 15:55:40 -04004624 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4625 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004626}
4627
Jamie Madill01a80ee2016-11-07 12:06:18 -05004628void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4629{
4630 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4631 {
4632 bindReadFramebuffer(framebuffer);
4633 }
4634
4635 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4636 {
4637 bindDrawFramebuffer(framebuffer);
4638 }
4639}
4640
4641void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4642{
4643 ASSERT(target == GL_RENDERBUFFER);
4644 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004645 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004646 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004647}
4648
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004649void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004650 GLsizei samples,
4651 GLenum internalformat,
4652 GLsizei width,
4653 GLsizei height,
4654 GLboolean fixedsamplelocations)
4655{
4656 Extents size(width, height, 1);
4657 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004658 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4659 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004660}
4661
4662void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4663{
JiangYizhou5b03f472017-01-09 10:22:53 +08004664 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4665 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004666 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004667 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004668
4669 switch (pname)
4670 {
4671 case GL_SAMPLE_POSITION:
4672 handleError(framebuffer->getSamplePosition(index, val));
4673 break;
4674 default:
4675 UNREACHABLE();
4676 }
4677}
4678
Jamie Madille8fb6402017-02-14 17:56:40 -05004679void Context::renderbufferStorage(GLenum target,
4680 GLenum internalformat,
4681 GLsizei width,
4682 GLsizei height)
4683{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004684 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4685 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4686
Jamie Madille8fb6402017-02-14 17:56:40 -05004687 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004688 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004689}
4690
4691void Context::renderbufferStorageMultisample(GLenum target,
4692 GLsizei samples,
4693 GLenum internalformat,
4694 GLsizei width,
4695 GLsizei height)
4696{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004697 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4698 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004699
4700 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004701 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004702 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004703}
4704
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004705void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4706{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004707 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004708 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004709}
4710
JiangYizhoue18e6392017-02-20 10:32:23 +08004711void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4712{
4713 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4714 QueryFramebufferParameteriv(framebuffer, pname, params);
4715}
4716
Jiajia Qin5451d532017-11-16 17:16:34 +08004717void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004718{
4719 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4720 SetFramebufferParameteri(framebuffer, pname, param);
4721}
4722
Jamie Madillb3f26b92017-07-19 15:07:41 -04004723Error Context::getScratchBuffer(size_t requstedSizeBytes,
4724 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004725{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004726 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4727 {
4728 return OutOfMemory() << "Failed to allocate internal buffer.";
4729 }
4730 return NoError();
4731}
4732
4733Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4734 angle::MemoryBuffer **zeroBufferOut) const
4735{
4736 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004737 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004738 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004739 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004740 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004741}
4742
Xinghua Cao10a4d432017-11-28 14:46:26 +08004743Error Context::prepareForDispatch()
4744{
Geoff Langa8cb2872018-03-09 16:09:40 -05004745 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004746
4747 if (isRobustResourceInitEnabled())
4748 {
4749 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4750 }
4751
4752 return NoError();
4753}
4754
Xinghua Cao2b396592017-03-29 15:36:04 +08004755void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4756{
4757 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4758 {
4759 return;
4760 }
4761
Xinghua Cao10a4d432017-11-28 14:46:26 +08004762 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004763 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004764}
4765
Jiajia Qin5451d532017-11-16 17:16:34 +08004766void Context::dispatchComputeIndirect(GLintptr indirect)
4767{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004768 ANGLE_CONTEXT_TRY(prepareForDispatch());
4769 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004770}
4771
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004772void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004773 GLsizei levels,
4774 GLenum internalFormat,
4775 GLsizei width,
4776 GLsizei height)
4777{
4778 Extents size(width, height, 1);
4779 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004780 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004781}
4782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004783void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004784 GLsizei levels,
4785 GLenum internalFormat,
4786 GLsizei width,
4787 GLsizei height,
4788 GLsizei depth)
4789{
4790 Extents size(width, height, depth);
4791 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004792 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004793}
4794
Jiajia Qin5451d532017-11-16 17:16:34 +08004795void Context::memoryBarrier(GLbitfield barriers)
4796{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004797 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004798}
4799
4800void Context::memoryBarrierByRegion(GLbitfield barriers)
4801{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004802 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004803}
4804
Jamie Madillc1d770e2017-04-13 17:31:24 -04004805GLenum Context::checkFramebufferStatus(GLenum target)
4806{
4807 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4808 ASSERT(framebuffer);
4809
Jamie Madille98b1b52018-03-08 09:47:23 -05004810 GLenum status = GL_NONE;
4811 Error err = framebuffer->checkStatus(this, &status);
4812 if (err.isError())
4813 {
4814 handleError(err);
4815 return 0;
4816 }
4817 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004818}
4819
4820void Context::compileShader(GLuint shader)
4821{
4822 Shader *shaderObject = GetValidShader(this, shader);
4823 if (!shaderObject)
4824 {
4825 return;
4826 }
4827 shaderObject->compile(this);
4828}
4829
4830void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4831{
4832 for (int i = 0; i < n; i++)
4833 {
4834 deleteBuffer(buffers[i]);
4835 }
4836}
4837
4838void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4839{
4840 for (int i = 0; i < n; i++)
4841 {
4842 if (framebuffers[i] != 0)
4843 {
4844 deleteFramebuffer(framebuffers[i]);
4845 }
4846 }
4847}
4848
4849void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4850{
4851 for (int i = 0; i < n; i++)
4852 {
4853 deleteRenderbuffer(renderbuffers[i]);
4854 }
4855}
4856
4857void Context::deleteTextures(GLsizei n, const GLuint *textures)
4858{
4859 for (int i = 0; i < n; i++)
4860 {
4861 if (textures[i] != 0)
4862 {
4863 deleteTexture(textures[i]);
4864 }
4865 }
4866}
4867
4868void Context::detachShader(GLuint program, GLuint shader)
4869{
4870 Program *programObject = getProgram(program);
4871 ASSERT(programObject);
4872
4873 Shader *shaderObject = getShader(shader);
4874 ASSERT(shaderObject);
4875
4876 programObject->detachShader(this, shaderObject);
4877}
4878
4879void Context::genBuffers(GLsizei n, GLuint *buffers)
4880{
4881 for (int i = 0; i < n; i++)
4882 {
4883 buffers[i] = createBuffer();
4884 }
4885}
4886
4887void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4888{
4889 for (int i = 0; i < n; i++)
4890 {
4891 framebuffers[i] = createFramebuffer();
4892 }
4893}
4894
4895void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4896{
4897 for (int i = 0; i < n; i++)
4898 {
4899 renderbuffers[i] = createRenderbuffer();
4900 }
4901}
4902
4903void Context::genTextures(GLsizei n, GLuint *textures)
4904{
4905 for (int i = 0; i < n; i++)
4906 {
4907 textures[i] = createTexture();
4908 }
4909}
4910
4911void Context::getActiveAttrib(GLuint program,
4912 GLuint index,
4913 GLsizei bufsize,
4914 GLsizei *length,
4915 GLint *size,
4916 GLenum *type,
4917 GLchar *name)
4918{
4919 Program *programObject = getProgram(program);
4920 ASSERT(programObject);
4921 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4922}
4923
4924void Context::getActiveUniform(GLuint program,
4925 GLuint index,
4926 GLsizei bufsize,
4927 GLsizei *length,
4928 GLint *size,
4929 GLenum *type,
4930 GLchar *name)
4931{
4932 Program *programObject = getProgram(program);
4933 ASSERT(programObject);
4934 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4935}
4936
4937void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4938{
4939 Program *programObject = getProgram(program);
4940 ASSERT(programObject);
4941 programObject->getAttachedShaders(maxcount, count, shaders);
4942}
4943
4944GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4945{
4946 Program *programObject = getProgram(program);
4947 ASSERT(programObject);
4948 return programObject->getAttributeLocation(name);
4949}
4950
4951void Context::getBooleanv(GLenum pname, GLboolean *params)
4952{
4953 GLenum nativeType;
4954 unsigned int numParams = 0;
4955 getQueryParameterInfo(pname, &nativeType, &numParams);
4956
4957 if (nativeType == GL_BOOL)
4958 {
4959 getBooleanvImpl(pname, params);
4960 }
4961 else
4962 {
4963 CastStateValues(this, nativeType, pname, numParams, params);
4964 }
4965}
4966
Brandon Jones59770802018-04-02 13:18:42 -07004967void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
4968{
4969 getBooleanv(pname, params);
4970}
4971
Jamie Madillc1d770e2017-04-13 17:31:24 -04004972void Context::getFloatv(GLenum pname, GLfloat *params)
4973{
4974 GLenum nativeType;
4975 unsigned int numParams = 0;
4976 getQueryParameterInfo(pname, &nativeType, &numParams);
4977
4978 if (nativeType == GL_FLOAT)
4979 {
4980 getFloatvImpl(pname, params);
4981 }
4982 else
4983 {
4984 CastStateValues(this, nativeType, pname, numParams, params);
4985 }
4986}
4987
Brandon Jones59770802018-04-02 13:18:42 -07004988void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
4989{
4990 getFloatv(pname, params);
4991}
4992
Jamie Madillc1d770e2017-04-13 17:31:24 -04004993void Context::getIntegerv(GLenum pname, GLint *params)
4994{
4995 GLenum nativeType;
4996 unsigned int numParams = 0;
4997 getQueryParameterInfo(pname, &nativeType, &numParams);
4998
4999 if (nativeType == GL_INT)
5000 {
5001 getIntegervImpl(pname, params);
5002 }
5003 else
5004 {
5005 CastStateValues(this, nativeType, pname, numParams, params);
5006 }
5007}
5008
Brandon Jones59770802018-04-02 13:18:42 -07005009void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5010{
5011 getIntegerv(pname, data);
5012}
5013
Jamie Madillc1d770e2017-04-13 17:31:24 -04005014void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5015{
5016 Program *programObject = getProgram(program);
5017 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005018 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005019}
5020
Brandon Jones59770802018-04-02 13:18:42 -07005021void Context::getProgramivRobust(GLuint program,
5022 GLenum pname,
5023 GLsizei bufSize,
5024 GLsizei *length,
5025 GLint *params)
5026{
5027 getProgramiv(program, pname, params);
5028}
5029
Jiajia Qin5451d532017-11-16 17:16:34 +08005030void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5031{
5032 UNIMPLEMENTED();
5033}
5034
Jamie Madillbe849e42017-05-02 15:49:00 -04005035void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005036{
5037 Program *programObject = getProgram(program);
5038 ASSERT(programObject);
5039 programObject->getInfoLog(bufsize, length, infolog);
5040}
5041
Jiajia Qin5451d532017-11-16 17:16:34 +08005042void Context::getProgramPipelineInfoLog(GLuint pipeline,
5043 GLsizei bufSize,
5044 GLsizei *length,
5045 GLchar *infoLog)
5046{
5047 UNIMPLEMENTED();
5048}
5049
Jamie Madillc1d770e2017-04-13 17:31:24 -04005050void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5051{
5052 Shader *shaderObject = getShader(shader);
5053 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005054 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005055}
5056
Brandon Jones59770802018-04-02 13:18:42 -07005057void Context::getShaderivRobust(GLuint shader,
5058 GLenum pname,
5059 GLsizei bufSize,
5060 GLsizei *length,
5061 GLint *params)
5062{
5063 getShaderiv(shader, pname, params);
5064}
5065
Jamie Madillc1d770e2017-04-13 17:31:24 -04005066void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5067{
5068 Shader *shaderObject = getShader(shader);
5069 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005070 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005071}
5072
5073void Context::getShaderPrecisionFormat(GLenum shadertype,
5074 GLenum precisiontype,
5075 GLint *range,
5076 GLint *precision)
5077{
5078 // TODO(jmadill): Compute shaders.
5079
5080 switch (shadertype)
5081 {
5082 case GL_VERTEX_SHADER:
5083 switch (precisiontype)
5084 {
5085 case GL_LOW_FLOAT:
5086 mCaps.vertexLowpFloat.get(range, precision);
5087 break;
5088 case GL_MEDIUM_FLOAT:
5089 mCaps.vertexMediumpFloat.get(range, precision);
5090 break;
5091 case GL_HIGH_FLOAT:
5092 mCaps.vertexHighpFloat.get(range, precision);
5093 break;
5094
5095 case GL_LOW_INT:
5096 mCaps.vertexLowpInt.get(range, precision);
5097 break;
5098 case GL_MEDIUM_INT:
5099 mCaps.vertexMediumpInt.get(range, precision);
5100 break;
5101 case GL_HIGH_INT:
5102 mCaps.vertexHighpInt.get(range, precision);
5103 break;
5104
5105 default:
5106 UNREACHABLE();
5107 return;
5108 }
5109 break;
5110
5111 case GL_FRAGMENT_SHADER:
5112 switch (precisiontype)
5113 {
5114 case GL_LOW_FLOAT:
5115 mCaps.fragmentLowpFloat.get(range, precision);
5116 break;
5117 case GL_MEDIUM_FLOAT:
5118 mCaps.fragmentMediumpFloat.get(range, precision);
5119 break;
5120 case GL_HIGH_FLOAT:
5121 mCaps.fragmentHighpFloat.get(range, precision);
5122 break;
5123
5124 case GL_LOW_INT:
5125 mCaps.fragmentLowpInt.get(range, precision);
5126 break;
5127 case GL_MEDIUM_INT:
5128 mCaps.fragmentMediumpInt.get(range, precision);
5129 break;
5130 case GL_HIGH_INT:
5131 mCaps.fragmentHighpInt.get(range, precision);
5132 break;
5133
5134 default:
5135 UNREACHABLE();
5136 return;
5137 }
5138 break;
5139
5140 default:
5141 UNREACHABLE();
5142 return;
5143 }
5144}
5145
5146void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5147{
5148 Shader *shaderObject = getShader(shader);
5149 ASSERT(shaderObject);
5150 shaderObject->getSource(bufsize, length, source);
5151}
5152
5153void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5154{
5155 Program *programObject = getProgram(program);
5156 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005157 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005158}
5159
Brandon Jones59770802018-04-02 13:18:42 -07005160void Context::getUniformfvRobust(GLuint program,
5161 GLint location,
5162 GLsizei bufSize,
5163 GLsizei *length,
5164 GLfloat *params)
5165{
5166 getUniformfv(program, location, params);
5167}
5168
Jamie Madillc1d770e2017-04-13 17:31:24 -04005169void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5170{
5171 Program *programObject = getProgram(program);
5172 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005173 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005174}
5175
Brandon Jones59770802018-04-02 13:18:42 -07005176void Context::getUniformivRobust(GLuint program,
5177 GLint location,
5178 GLsizei bufSize,
5179 GLsizei *length,
5180 GLint *params)
5181{
5182 getUniformiv(program, location, params);
5183}
5184
Jamie Madillc1d770e2017-04-13 17:31:24 -04005185GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5186{
5187 Program *programObject = getProgram(program);
5188 ASSERT(programObject);
5189 return programObject->getUniformLocation(name);
5190}
5191
5192GLboolean Context::isBuffer(GLuint buffer)
5193{
5194 if (buffer == 0)
5195 {
5196 return GL_FALSE;
5197 }
5198
5199 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5200}
5201
5202GLboolean Context::isEnabled(GLenum cap)
5203{
5204 return mGLState.getEnableFeature(cap);
5205}
5206
5207GLboolean Context::isFramebuffer(GLuint framebuffer)
5208{
5209 if (framebuffer == 0)
5210 {
5211 return GL_FALSE;
5212 }
5213
5214 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5215}
5216
5217GLboolean Context::isProgram(GLuint program)
5218{
5219 if (program == 0)
5220 {
5221 return GL_FALSE;
5222 }
5223
5224 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5225}
5226
5227GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5228{
5229 if (renderbuffer == 0)
5230 {
5231 return GL_FALSE;
5232 }
5233
5234 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5235}
5236
5237GLboolean Context::isShader(GLuint shader)
5238{
5239 if (shader == 0)
5240 {
5241 return GL_FALSE;
5242 }
5243
5244 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5245}
5246
5247GLboolean Context::isTexture(GLuint texture)
5248{
5249 if (texture == 0)
5250 {
5251 return GL_FALSE;
5252 }
5253
5254 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5255}
5256
5257void Context::linkProgram(GLuint program)
5258{
5259 Program *programObject = getProgram(program);
5260 ASSERT(programObject);
5261 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005262 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005263}
5264
5265void Context::releaseShaderCompiler()
5266{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005267 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005268}
5269
5270void Context::shaderBinary(GLsizei n,
5271 const GLuint *shaders,
5272 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005273 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005274 GLsizei length)
5275{
5276 // No binary shader formats are supported.
5277 UNIMPLEMENTED();
5278}
5279
5280void Context::shaderSource(GLuint shader,
5281 GLsizei count,
5282 const GLchar *const *string,
5283 const GLint *length)
5284{
5285 Shader *shaderObject = getShader(shader);
5286 ASSERT(shaderObject);
5287 shaderObject->setSource(count, string, length);
5288}
5289
5290void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5291{
5292 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5293}
5294
5295void Context::stencilMask(GLuint mask)
5296{
5297 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5298}
5299
5300void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5301{
5302 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5303}
5304
5305void Context::uniform1f(GLint location, GLfloat x)
5306{
5307 Program *program = mGLState.getProgram();
5308 program->setUniform1fv(location, 1, &x);
5309}
5310
5311void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5312{
5313 Program *program = mGLState.getProgram();
5314 program->setUniform1fv(location, count, v);
5315}
5316
5317void Context::uniform1i(GLint location, GLint x)
5318{
5319 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005320 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5321 {
5322 mGLState.setObjectDirty(GL_PROGRAM);
5323 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324}
5325
5326void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5327{
5328 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005329 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5330 {
5331 mGLState.setObjectDirty(GL_PROGRAM);
5332 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005333}
5334
5335void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5336{
5337 GLfloat xy[2] = {x, y};
5338 Program *program = mGLState.getProgram();
5339 program->setUniform2fv(location, 1, xy);
5340}
5341
5342void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5343{
5344 Program *program = mGLState.getProgram();
5345 program->setUniform2fv(location, count, v);
5346}
5347
5348void Context::uniform2i(GLint location, GLint x, GLint y)
5349{
5350 GLint xy[2] = {x, y};
5351 Program *program = mGLState.getProgram();
5352 program->setUniform2iv(location, 1, xy);
5353}
5354
5355void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5356{
5357 Program *program = mGLState.getProgram();
5358 program->setUniform2iv(location, count, v);
5359}
5360
5361void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5362{
5363 GLfloat xyz[3] = {x, y, z};
5364 Program *program = mGLState.getProgram();
5365 program->setUniform3fv(location, 1, xyz);
5366}
5367
5368void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5369{
5370 Program *program = mGLState.getProgram();
5371 program->setUniform3fv(location, count, v);
5372}
5373
5374void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5375{
5376 GLint xyz[3] = {x, y, z};
5377 Program *program = mGLState.getProgram();
5378 program->setUniform3iv(location, 1, xyz);
5379}
5380
5381void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5382{
5383 Program *program = mGLState.getProgram();
5384 program->setUniform3iv(location, count, v);
5385}
5386
5387void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5388{
5389 GLfloat xyzw[4] = {x, y, z, w};
5390 Program *program = mGLState.getProgram();
5391 program->setUniform4fv(location, 1, xyzw);
5392}
5393
5394void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5395{
5396 Program *program = mGLState.getProgram();
5397 program->setUniform4fv(location, count, v);
5398}
5399
5400void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5401{
5402 GLint xyzw[4] = {x, y, z, w};
5403 Program *program = mGLState.getProgram();
5404 program->setUniform4iv(location, 1, xyzw);
5405}
5406
5407void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5408{
5409 Program *program = mGLState.getProgram();
5410 program->setUniform4iv(location, count, v);
5411}
5412
5413void Context::uniformMatrix2fv(GLint location,
5414 GLsizei count,
5415 GLboolean transpose,
5416 const GLfloat *value)
5417{
5418 Program *program = mGLState.getProgram();
5419 program->setUniformMatrix2fv(location, count, transpose, value);
5420}
5421
5422void Context::uniformMatrix3fv(GLint location,
5423 GLsizei count,
5424 GLboolean transpose,
5425 const GLfloat *value)
5426{
5427 Program *program = mGLState.getProgram();
5428 program->setUniformMatrix3fv(location, count, transpose, value);
5429}
5430
5431void Context::uniformMatrix4fv(GLint location,
5432 GLsizei count,
5433 GLboolean transpose,
5434 const GLfloat *value)
5435{
5436 Program *program = mGLState.getProgram();
5437 program->setUniformMatrix4fv(location, count, transpose, value);
5438}
5439
5440void Context::validateProgram(GLuint program)
5441{
5442 Program *programObject = getProgram(program);
5443 ASSERT(programObject);
5444 programObject->validate(mCaps);
5445}
5446
Jiajia Qin5451d532017-11-16 17:16:34 +08005447void Context::validateProgramPipeline(GLuint pipeline)
5448{
5449 UNIMPLEMENTED();
5450}
5451
Jamie Madilld04908b2017-06-09 14:15:35 -04005452void Context::getProgramBinary(GLuint program,
5453 GLsizei bufSize,
5454 GLsizei *length,
5455 GLenum *binaryFormat,
5456 void *binary)
5457{
5458 Program *programObject = getProgram(program);
5459 ASSERT(programObject != nullptr);
5460
5461 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5462}
5463
5464void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5465{
5466 Program *programObject = getProgram(program);
5467 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005468
Jamie Madilld04908b2017-06-09 14:15:35 -04005469 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5470}
5471
Jamie Madillff325f12017-08-26 15:06:05 -04005472void Context::uniform1ui(GLint location, GLuint v0)
5473{
5474 Program *program = mGLState.getProgram();
5475 program->setUniform1uiv(location, 1, &v0);
5476}
5477
5478void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5479{
5480 Program *program = mGLState.getProgram();
5481 const GLuint xy[] = {v0, v1};
5482 program->setUniform2uiv(location, 1, xy);
5483}
5484
5485void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5486{
5487 Program *program = mGLState.getProgram();
5488 const GLuint xyz[] = {v0, v1, v2};
5489 program->setUniform3uiv(location, 1, xyz);
5490}
5491
5492void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5493{
5494 Program *program = mGLState.getProgram();
5495 const GLuint xyzw[] = {v0, v1, v2, v3};
5496 program->setUniform4uiv(location, 1, xyzw);
5497}
5498
5499void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5500{
5501 Program *program = mGLState.getProgram();
5502 program->setUniform1uiv(location, count, value);
5503}
5504void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5505{
5506 Program *program = mGLState.getProgram();
5507 program->setUniform2uiv(location, count, value);
5508}
5509
5510void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5511{
5512 Program *program = mGLState.getProgram();
5513 program->setUniform3uiv(location, count, value);
5514}
5515
5516void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5517{
5518 Program *program = mGLState.getProgram();
5519 program->setUniform4uiv(location, count, value);
5520}
5521
Jamie Madillf0e04492017-08-26 15:28:42 -04005522void Context::genQueries(GLsizei n, GLuint *ids)
5523{
5524 for (GLsizei i = 0; i < n; i++)
5525 {
5526 GLuint handle = mQueryHandleAllocator.allocate();
5527 mQueryMap.assign(handle, nullptr);
5528 ids[i] = handle;
5529 }
5530}
5531
5532void Context::deleteQueries(GLsizei n, const GLuint *ids)
5533{
5534 for (int i = 0; i < n; i++)
5535 {
5536 GLuint query = ids[i];
5537
5538 Query *queryObject = nullptr;
5539 if (mQueryMap.erase(query, &queryObject))
5540 {
5541 mQueryHandleAllocator.release(query);
5542 if (queryObject)
5543 {
5544 queryObject->release(this);
5545 }
5546 }
5547 }
5548}
5549
5550GLboolean Context::isQuery(GLuint id)
5551{
5552 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5553}
5554
Jamie Madillc8c95812017-08-26 18:40:09 -04005555void Context::uniformMatrix2x3fv(GLint location,
5556 GLsizei count,
5557 GLboolean transpose,
5558 const GLfloat *value)
5559{
5560 Program *program = mGLState.getProgram();
5561 program->setUniformMatrix2x3fv(location, count, transpose, value);
5562}
5563
5564void Context::uniformMatrix3x2fv(GLint location,
5565 GLsizei count,
5566 GLboolean transpose,
5567 const GLfloat *value)
5568{
5569 Program *program = mGLState.getProgram();
5570 program->setUniformMatrix3x2fv(location, count, transpose, value);
5571}
5572
5573void Context::uniformMatrix2x4fv(GLint location,
5574 GLsizei count,
5575 GLboolean transpose,
5576 const GLfloat *value)
5577{
5578 Program *program = mGLState.getProgram();
5579 program->setUniformMatrix2x4fv(location, count, transpose, value);
5580}
5581
5582void Context::uniformMatrix4x2fv(GLint location,
5583 GLsizei count,
5584 GLboolean transpose,
5585 const GLfloat *value)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniformMatrix4x2fv(location, count, transpose, value);
5589}
5590
5591void Context::uniformMatrix3x4fv(GLint location,
5592 GLsizei count,
5593 GLboolean transpose,
5594 const GLfloat *value)
5595{
5596 Program *program = mGLState.getProgram();
5597 program->setUniformMatrix3x4fv(location, count, transpose, value);
5598}
5599
5600void Context::uniformMatrix4x3fv(GLint location,
5601 GLsizei count,
5602 GLboolean transpose,
5603 const GLfloat *value)
5604{
5605 Program *program = mGLState.getProgram();
5606 program->setUniformMatrix4x3fv(location, count, transpose, value);
5607}
5608
Jamie Madilld7576732017-08-26 18:49:50 -04005609void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5610{
5611 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5612 {
5613 GLuint vertexArray = arrays[arrayIndex];
5614
5615 if (arrays[arrayIndex] != 0)
5616 {
5617 VertexArray *vertexArrayObject = nullptr;
5618 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5619 {
5620 if (vertexArrayObject != nullptr)
5621 {
5622 detachVertexArray(vertexArray);
5623 vertexArrayObject->onDestroy(this);
5624 }
5625
5626 mVertexArrayHandleAllocator.release(vertexArray);
5627 }
5628 }
5629 }
5630}
5631
5632void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5633{
5634 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5635 {
5636 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5637 mVertexArrayMap.assign(vertexArray, nullptr);
5638 arrays[arrayIndex] = vertexArray;
5639 }
5640}
5641
5642bool Context::isVertexArray(GLuint array)
5643{
5644 if (array == 0)
5645 {
5646 return GL_FALSE;
5647 }
5648
5649 VertexArray *vao = getVertexArray(array);
5650 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5651}
5652
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005653void Context::endTransformFeedback()
5654{
5655 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5656 transformFeedback->end(this);
5657}
5658
5659void Context::transformFeedbackVaryings(GLuint program,
5660 GLsizei count,
5661 const GLchar *const *varyings,
5662 GLenum bufferMode)
5663{
5664 Program *programObject = getProgram(program);
5665 ASSERT(programObject);
5666 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5667}
5668
5669void Context::getTransformFeedbackVarying(GLuint program,
5670 GLuint index,
5671 GLsizei bufSize,
5672 GLsizei *length,
5673 GLsizei *size,
5674 GLenum *type,
5675 GLchar *name)
5676{
5677 Program *programObject = getProgram(program);
5678 ASSERT(programObject);
5679 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5680}
5681
5682void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5683{
5684 for (int i = 0; i < n; i++)
5685 {
5686 GLuint transformFeedback = ids[i];
5687 if (transformFeedback == 0)
5688 {
5689 continue;
5690 }
5691
5692 TransformFeedback *transformFeedbackObject = nullptr;
5693 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5694 {
5695 if (transformFeedbackObject != nullptr)
5696 {
5697 detachTransformFeedback(transformFeedback);
5698 transformFeedbackObject->release(this);
5699 }
5700
5701 mTransformFeedbackHandleAllocator.release(transformFeedback);
5702 }
5703 }
5704}
5705
5706void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5707{
5708 for (int i = 0; i < n; i++)
5709 {
5710 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5711 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5712 ids[i] = transformFeedback;
5713 }
5714}
5715
5716bool Context::isTransformFeedback(GLuint id)
5717{
5718 if (id == 0)
5719 {
5720 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5721 // returns FALSE
5722 return GL_FALSE;
5723 }
5724
5725 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5726 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5727}
5728
5729void Context::pauseTransformFeedback()
5730{
5731 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5732 transformFeedback->pause();
5733}
5734
5735void Context::resumeTransformFeedback()
5736{
5737 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5738 transformFeedback->resume();
5739}
5740
Jamie Madill12e957f2017-08-26 21:42:26 -04005741void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5742{
5743 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005744 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005745}
5746
Brandon Jones59770802018-04-02 13:18:42 -07005747void Context::getUniformuivRobust(GLuint program,
5748 GLint location,
5749 GLsizei bufSize,
5750 GLsizei *length,
5751 GLuint *params)
5752{
5753 getUniformuiv(program, location, params);
5754}
5755
Jamie Madill12e957f2017-08-26 21:42:26 -04005756GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5757{
5758 const Program *programObject = getProgram(program);
5759 return programObject->getFragDataLocation(name);
5760}
5761
5762void Context::getUniformIndices(GLuint program,
5763 GLsizei uniformCount,
5764 const GLchar *const *uniformNames,
5765 GLuint *uniformIndices)
5766{
5767 const Program *programObject = getProgram(program);
5768 if (!programObject->isLinked())
5769 {
5770 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5771 {
5772 uniformIndices[uniformId] = GL_INVALID_INDEX;
5773 }
5774 }
5775 else
5776 {
5777 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5778 {
5779 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5780 }
5781 }
5782}
5783
5784void Context::getActiveUniformsiv(GLuint program,
5785 GLsizei uniformCount,
5786 const GLuint *uniformIndices,
5787 GLenum pname,
5788 GLint *params)
5789{
5790 const Program *programObject = getProgram(program);
5791 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5792 {
5793 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005794 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005795 }
5796}
5797
5798GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5799{
5800 const Program *programObject = getProgram(program);
5801 return programObject->getUniformBlockIndex(uniformBlockName);
5802}
5803
5804void Context::getActiveUniformBlockiv(GLuint program,
5805 GLuint uniformBlockIndex,
5806 GLenum pname,
5807 GLint *params)
5808{
5809 const Program *programObject = getProgram(program);
5810 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5811}
5812
Brandon Jones59770802018-04-02 13:18:42 -07005813void Context::getActiveUniformBlockivRobust(GLuint program,
5814 GLuint uniformBlockIndex,
5815 GLenum pname,
5816 GLsizei bufSize,
5817 GLsizei *length,
5818 GLint *params)
5819{
5820 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5821}
5822
Jamie Madill12e957f2017-08-26 21:42:26 -04005823void Context::getActiveUniformBlockName(GLuint program,
5824 GLuint uniformBlockIndex,
5825 GLsizei bufSize,
5826 GLsizei *length,
5827 GLchar *uniformBlockName)
5828{
5829 const Program *programObject = getProgram(program);
5830 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5831}
5832
5833void Context::uniformBlockBinding(GLuint program,
5834 GLuint uniformBlockIndex,
5835 GLuint uniformBlockBinding)
5836{
5837 Program *programObject = getProgram(program);
5838 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5839}
5840
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005841GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5842{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005843 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5844 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005845
Jamie Madill70b5bb02017-08-28 13:32:37 -04005846 Sync *syncObject = getSync(syncHandle);
5847 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005848 if (error.isError())
5849 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005850 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005851 handleError(error);
5852 return nullptr;
5853 }
5854
Jamie Madill70b5bb02017-08-28 13:32:37 -04005855 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005856}
5857
5858GLboolean Context::isSync(GLsync sync)
5859{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005860 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005861}
5862
5863GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5864{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005865 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005866
5867 GLenum result = GL_WAIT_FAILED;
5868 handleError(syncObject->clientWait(flags, timeout, &result));
5869 return result;
5870}
5871
5872void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5873{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005874 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005875 handleError(syncObject->serverWait(flags, timeout));
5876}
5877
5878void Context::getInteger64v(GLenum pname, GLint64 *params)
5879{
5880 GLenum nativeType = GL_NONE;
5881 unsigned int numParams = 0;
5882 getQueryParameterInfo(pname, &nativeType, &numParams);
5883
5884 if (nativeType == GL_INT_64_ANGLEX)
5885 {
5886 getInteger64vImpl(pname, params);
5887 }
5888 else
5889 {
5890 CastStateValues(this, nativeType, pname, numParams, params);
5891 }
5892}
5893
Brandon Jones59770802018-04-02 13:18:42 -07005894void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
5895{
5896 getInteger64v(pname, data);
5897}
5898
Corentin Wallez336129f2017-10-17 15:55:40 -04005899void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005900{
5901 Buffer *buffer = mGLState.getTargetBuffer(target);
5902 QueryBufferParameteri64v(buffer, pname, params);
5903}
5904
Brandon Jones59770802018-04-02 13:18:42 -07005905void Context::getBufferParameteri64vRobust(BufferBinding target,
5906 GLenum pname,
5907 GLsizei bufSize,
5908 GLsizei *length,
5909 GLint64 *params)
5910{
5911 getBufferParameteri64v(target, pname, params);
5912}
5913
Jamie Madill3ef140a2017-08-26 23:11:21 -04005914void Context::genSamplers(GLsizei count, GLuint *samplers)
5915{
5916 for (int i = 0; i < count; i++)
5917 {
5918 samplers[i] = mState.mSamplers->createSampler();
5919 }
5920}
5921
5922void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5923{
5924 for (int i = 0; i < count; i++)
5925 {
5926 GLuint sampler = samplers[i];
5927
5928 if (mState.mSamplers->getSampler(sampler))
5929 {
5930 detachSampler(sampler);
5931 }
5932
5933 mState.mSamplers->deleteObject(this, sampler);
5934 }
5935}
5936
5937void Context::getInternalformativ(GLenum target,
5938 GLenum internalformat,
5939 GLenum pname,
5940 GLsizei bufSize,
5941 GLint *params)
5942{
5943 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5944 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5945}
5946
Brandon Jones59770802018-04-02 13:18:42 -07005947void Context::getInternalformativRobust(GLenum target,
5948 GLenum internalformat,
5949 GLenum pname,
5950 GLsizei bufSize,
5951 GLsizei *length,
5952 GLint *params)
5953{
5954 getInternalformativ(target, internalformat, pname, bufSize, params);
5955}
5956
Jiajia Qin5451d532017-11-16 17:16:34 +08005957void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5958{
5959 programUniform1iv(program, location, 1, &v0);
5960}
5961
5962void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5963{
5964 GLint xy[2] = {v0, v1};
5965 programUniform2iv(program, location, 1, xy);
5966}
5967
5968void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5969{
5970 GLint xyz[3] = {v0, v1, v2};
5971 programUniform3iv(program, location, 1, xyz);
5972}
5973
5974void Context::programUniform4i(GLuint program,
5975 GLint location,
5976 GLint v0,
5977 GLint v1,
5978 GLint v2,
5979 GLint v3)
5980{
5981 GLint xyzw[4] = {v0, v1, v2, v3};
5982 programUniform4iv(program, location, 1, xyzw);
5983}
5984
5985void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5986{
5987 programUniform1uiv(program, location, 1, &v0);
5988}
5989
5990void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5991{
5992 GLuint xy[2] = {v0, v1};
5993 programUniform2uiv(program, location, 1, xy);
5994}
5995
5996void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5997{
5998 GLuint xyz[3] = {v0, v1, v2};
5999 programUniform3uiv(program, location, 1, xyz);
6000}
6001
6002void Context::programUniform4ui(GLuint program,
6003 GLint location,
6004 GLuint v0,
6005 GLuint v1,
6006 GLuint v2,
6007 GLuint v3)
6008{
6009 GLuint xyzw[4] = {v0, v1, v2, v3};
6010 programUniform4uiv(program, location, 1, xyzw);
6011}
6012
6013void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6014{
6015 programUniform1fv(program, location, 1, &v0);
6016}
6017
6018void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6019{
6020 GLfloat xy[2] = {v0, v1};
6021 programUniform2fv(program, location, 1, xy);
6022}
6023
6024void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6025{
6026 GLfloat xyz[3] = {v0, v1, v2};
6027 programUniform3fv(program, location, 1, xyz);
6028}
6029
6030void Context::programUniform4f(GLuint program,
6031 GLint location,
6032 GLfloat v0,
6033 GLfloat v1,
6034 GLfloat v2,
6035 GLfloat v3)
6036{
6037 GLfloat xyzw[4] = {v0, v1, v2, v3};
6038 programUniform4fv(program, location, 1, xyzw);
6039}
6040
Jamie Madill81c2e252017-09-09 23:32:46 -04006041void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6042{
6043 Program *programObject = getProgram(program);
6044 ASSERT(programObject);
6045 if (programObject->setUniform1iv(location, count, value) ==
6046 Program::SetUniformResult::SamplerChanged)
6047 {
6048 mGLState.setObjectDirty(GL_PROGRAM);
6049 }
6050}
6051
Jiajia Qin5451d532017-11-16 17:16:34 +08006052void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6053{
6054 Program *programObject = getProgram(program);
6055 ASSERT(programObject);
6056 programObject->setUniform2iv(location, count, value);
6057}
6058
6059void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6060{
6061 Program *programObject = getProgram(program);
6062 ASSERT(programObject);
6063 programObject->setUniform3iv(location, count, value);
6064}
6065
6066void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6067{
6068 Program *programObject = getProgram(program);
6069 ASSERT(programObject);
6070 programObject->setUniform4iv(location, count, value);
6071}
6072
6073void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6074{
6075 Program *programObject = getProgram(program);
6076 ASSERT(programObject);
6077 programObject->setUniform1uiv(location, count, value);
6078}
6079
6080void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6081{
6082 Program *programObject = getProgram(program);
6083 ASSERT(programObject);
6084 programObject->setUniform2uiv(location, count, value);
6085}
6086
6087void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6088{
6089 Program *programObject = getProgram(program);
6090 ASSERT(programObject);
6091 programObject->setUniform3uiv(location, count, value);
6092}
6093
6094void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6095{
6096 Program *programObject = getProgram(program);
6097 ASSERT(programObject);
6098 programObject->setUniform4uiv(location, count, value);
6099}
6100
6101void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6102{
6103 Program *programObject = getProgram(program);
6104 ASSERT(programObject);
6105 programObject->setUniform1fv(location, count, value);
6106}
6107
6108void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6109{
6110 Program *programObject = getProgram(program);
6111 ASSERT(programObject);
6112 programObject->setUniform2fv(location, count, value);
6113}
6114
6115void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6116{
6117 Program *programObject = getProgram(program);
6118 ASSERT(programObject);
6119 programObject->setUniform3fv(location, count, value);
6120}
6121
6122void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6123{
6124 Program *programObject = getProgram(program);
6125 ASSERT(programObject);
6126 programObject->setUniform4fv(location, count, value);
6127}
6128
6129void Context::programUniformMatrix2fv(GLuint program,
6130 GLint location,
6131 GLsizei count,
6132 GLboolean transpose,
6133 const GLfloat *value)
6134{
6135 Program *programObject = getProgram(program);
6136 ASSERT(programObject);
6137 programObject->setUniformMatrix2fv(location, count, transpose, value);
6138}
6139
6140void Context::programUniformMatrix3fv(GLuint program,
6141 GLint location,
6142 GLsizei count,
6143 GLboolean transpose,
6144 const GLfloat *value)
6145{
6146 Program *programObject = getProgram(program);
6147 ASSERT(programObject);
6148 programObject->setUniformMatrix3fv(location, count, transpose, value);
6149}
6150
6151void Context::programUniformMatrix4fv(GLuint program,
6152 GLint location,
6153 GLsizei count,
6154 GLboolean transpose,
6155 const GLfloat *value)
6156{
6157 Program *programObject = getProgram(program);
6158 ASSERT(programObject);
6159 programObject->setUniformMatrix4fv(location, count, transpose, value);
6160}
6161
6162void Context::programUniformMatrix2x3fv(GLuint program,
6163 GLint location,
6164 GLsizei count,
6165 GLboolean transpose,
6166 const GLfloat *value)
6167{
6168 Program *programObject = getProgram(program);
6169 ASSERT(programObject);
6170 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6171}
6172
6173void Context::programUniformMatrix3x2fv(GLuint program,
6174 GLint location,
6175 GLsizei count,
6176 GLboolean transpose,
6177 const GLfloat *value)
6178{
6179 Program *programObject = getProgram(program);
6180 ASSERT(programObject);
6181 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6182}
6183
6184void Context::programUniformMatrix2x4fv(GLuint program,
6185 GLint location,
6186 GLsizei count,
6187 GLboolean transpose,
6188 const GLfloat *value)
6189{
6190 Program *programObject = getProgram(program);
6191 ASSERT(programObject);
6192 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6193}
6194
6195void Context::programUniformMatrix4x2fv(GLuint program,
6196 GLint location,
6197 GLsizei count,
6198 GLboolean transpose,
6199 const GLfloat *value)
6200{
6201 Program *programObject = getProgram(program);
6202 ASSERT(programObject);
6203 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6204}
6205
6206void Context::programUniformMatrix3x4fv(GLuint program,
6207 GLint location,
6208 GLsizei count,
6209 GLboolean transpose,
6210 const GLfloat *value)
6211{
6212 Program *programObject = getProgram(program);
6213 ASSERT(programObject);
6214 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6215}
6216
6217void Context::programUniformMatrix4x3fv(GLuint program,
6218 GLint location,
6219 GLsizei count,
6220 GLboolean transpose,
6221 const GLfloat *value)
6222{
6223 Program *programObject = getProgram(program);
6224 ASSERT(programObject);
6225 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6226}
6227
Jamie Madill81c2e252017-09-09 23:32:46 -04006228void Context::onTextureChange(const Texture *texture)
6229{
6230 // Conservatively assume all textures are dirty.
6231 // TODO(jmadill): More fine-grained update.
6232 mGLState.setObjectDirty(GL_TEXTURE);
6233}
6234
James Darpiniane8a93c62018-01-04 18:02:24 -08006235bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6236{
6237 return mGLState.isCurrentTransformFeedback(tf);
6238}
6239bool Context::isCurrentVertexArray(const VertexArray *va) const
6240{
6241 return mGLState.isCurrentVertexArray(va);
6242}
6243
Yunchao Hea336b902017-08-02 16:05:21 +08006244void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6245{
6246 for (int i = 0; i < count; i++)
6247 {
6248 pipelines[i] = createProgramPipeline();
6249 }
6250}
6251
6252void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6253{
6254 for (int i = 0; i < count; i++)
6255 {
6256 if (pipelines[i] != 0)
6257 {
6258 deleteProgramPipeline(pipelines[i]);
6259 }
6260 }
6261}
6262
6263GLboolean Context::isProgramPipeline(GLuint pipeline)
6264{
6265 if (pipeline == 0)
6266 {
6267 return GL_FALSE;
6268 }
6269
6270 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6271}
6272
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006273void Context::finishFenceNV(GLuint fence)
6274{
6275 FenceNV *fenceObject = getFenceNV(fence);
6276
6277 ASSERT(fenceObject && fenceObject->isSet());
6278 handleError(fenceObject->finish());
6279}
6280
6281void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6282{
6283 FenceNV *fenceObject = getFenceNV(fence);
6284
6285 ASSERT(fenceObject && fenceObject->isSet());
6286
6287 switch (pname)
6288 {
6289 case GL_FENCE_STATUS_NV:
6290 {
6291 // GL_NV_fence spec:
6292 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6293 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6294 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6295 GLboolean status = GL_TRUE;
6296 if (fenceObject->getStatus() != GL_TRUE)
6297 {
6298 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6299 }
6300 *params = status;
6301 break;
6302 }
6303
6304 case GL_FENCE_CONDITION_NV:
6305 {
6306 *params = static_cast<GLint>(fenceObject->getCondition());
6307 break;
6308 }
6309
6310 default:
6311 UNREACHABLE();
6312 }
6313}
6314
6315void Context::getTranslatedShaderSource(GLuint shader,
6316 GLsizei bufsize,
6317 GLsizei *length,
6318 GLchar *source)
6319{
6320 Shader *shaderObject = getShader(shader);
6321 ASSERT(shaderObject);
6322 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6323}
6324
6325void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6326{
6327 Program *programObject = getProgram(program);
6328 ASSERT(programObject);
6329
6330 programObject->getUniformfv(this, location, params);
6331}
6332
6333void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6334{
6335 Program *programObject = getProgram(program);
6336 ASSERT(programObject);
6337
6338 programObject->getUniformiv(this, location, params);
6339}
6340
6341GLboolean Context::isFenceNV(GLuint fence)
6342{
6343 FenceNV *fenceObject = getFenceNV(fence);
6344
6345 if (fenceObject == nullptr)
6346 {
6347 return GL_FALSE;
6348 }
6349
6350 // GL_NV_fence spec:
6351 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6352 // existing fence.
6353 return fenceObject->isSet();
6354}
6355
6356void Context::readnPixels(GLint x,
6357 GLint y,
6358 GLsizei width,
6359 GLsizei height,
6360 GLenum format,
6361 GLenum type,
6362 GLsizei bufSize,
6363 void *data)
6364{
6365 return readPixels(x, y, width, height, format, type, data);
6366}
6367
Jamie Madill007530e2017-12-28 14:27:04 -05006368void Context::setFenceNV(GLuint fence, GLenum condition)
6369{
6370 ASSERT(condition == GL_ALL_COMPLETED_NV);
6371
6372 FenceNV *fenceObject = getFenceNV(fence);
6373 ASSERT(fenceObject != nullptr);
6374 handleError(fenceObject->set(condition));
6375}
6376
6377GLboolean Context::testFenceNV(GLuint fence)
6378{
6379 FenceNV *fenceObject = getFenceNV(fence);
6380
6381 ASSERT(fenceObject != nullptr);
6382 ASSERT(fenceObject->isSet() == GL_TRUE);
6383
6384 GLboolean result = GL_TRUE;
6385 Error error = fenceObject->test(&result);
6386 if (error.isError())
6387 {
6388 handleError(error);
6389 return GL_TRUE;
6390 }
6391
6392 return result;
6393}
6394
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006395void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006396{
6397 Texture *texture = getTargetTexture(target);
6398 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006399 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006400}
6401
Jamie Madillfa920eb2018-01-04 11:45:50 -05006402void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006403{
6404 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6405 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6406 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6407}
6408
Jamie Madillfa920eb2018-01-04 11:45:50 -05006409void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6410{
6411 UNIMPLEMENTED();
6412}
6413
Jamie Madill5b772312018-03-08 20:28:32 -05006414bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6415{
6416 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6417 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6418 // to the fact that it is stored internally as a float, and so would require conversion
6419 // if returned from Context::getIntegerv. Since this conversion is already implemented
6420 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6421 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6422 // application.
6423 switch (pname)
6424 {
6425 case GL_COMPRESSED_TEXTURE_FORMATS:
6426 {
6427 *type = GL_INT;
6428 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6429 return true;
6430 }
6431 case GL_SHADER_BINARY_FORMATS:
6432 {
6433 *type = GL_INT;
6434 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6435 return true;
6436 }
6437
6438 case GL_MAX_VERTEX_ATTRIBS:
6439 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6440 case GL_MAX_VARYING_VECTORS:
6441 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6442 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6443 case GL_MAX_TEXTURE_IMAGE_UNITS:
6444 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6445 case GL_MAX_RENDERBUFFER_SIZE:
6446 case GL_NUM_SHADER_BINARY_FORMATS:
6447 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6448 case GL_ARRAY_BUFFER_BINDING:
6449 case GL_FRAMEBUFFER_BINDING:
6450 case GL_RENDERBUFFER_BINDING:
6451 case GL_CURRENT_PROGRAM:
6452 case GL_PACK_ALIGNMENT:
6453 case GL_UNPACK_ALIGNMENT:
6454 case GL_GENERATE_MIPMAP_HINT:
6455 case GL_RED_BITS:
6456 case GL_GREEN_BITS:
6457 case GL_BLUE_BITS:
6458 case GL_ALPHA_BITS:
6459 case GL_DEPTH_BITS:
6460 case GL_STENCIL_BITS:
6461 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6462 case GL_CULL_FACE_MODE:
6463 case GL_FRONT_FACE:
6464 case GL_ACTIVE_TEXTURE:
6465 case GL_STENCIL_FUNC:
6466 case GL_STENCIL_VALUE_MASK:
6467 case GL_STENCIL_REF:
6468 case GL_STENCIL_FAIL:
6469 case GL_STENCIL_PASS_DEPTH_FAIL:
6470 case GL_STENCIL_PASS_DEPTH_PASS:
6471 case GL_STENCIL_BACK_FUNC:
6472 case GL_STENCIL_BACK_VALUE_MASK:
6473 case GL_STENCIL_BACK_REF:
6474 case GL_STENCIL_BACK_FAIL:
6475 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6476 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6477 case GL_DEPTH_FUNC:
6478 case GL_BLEND_SRC_RGB:
6479 case GL_BLEND_SRC_ALPHA:
6480 case GL_BLEND_DST_RGB:
6481 case GL_BLEND_DST_ALPHA:
6482 case GL_BLEND_EQUATION_RGB:
6483 case GL_BLEND_EQUATION_ALPHA:
6484 case GL_STENCIL_WRITEMASK:
6485 case GL_STENCIL_BACK_WRITEMASK:
6486 case GL_STENCIL_CLEAR_VALUE:
6487 case GL_SUBPIXEL_BITS:
6488 case GL_MAX_TEXTURE_SIZE:
6489 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6490 case GL_SAMPLE_BUFFERS:
6491 case GL_SAMPLES:
6492 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6493 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6494 case GL_TEXTURE_BINDING_2D:
6495 case GL_TEXTURE_BINDING_CUBE_MAP:
6496 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6497 {
6498 *type = GL_INT;
6499 *numParams = 1;
6500 return true;
6501 }
6502 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6503 {
6504 if (!getExtensions().packReverseRowOrder)
6505 {
6506 return false;
6507 }
6508 *type = GL_INT;
6509 *numParams = 1;
6510 return true;
6511 }
6512 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6513 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6514 {
6515 if (!getExtensions().textureRectangle)
6516 {
6517 return false;
6518 }
6519 *type = GL_INT;
6520 *numParams = 1;
6521 return true;
6522 }
6523 case GL_MAX_DRAW_BUFFERS_EXT:
6524 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6525 {
6526 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6527 {
6528 return false;
6529 }
6530 *type = GL_INT;
6531 *numParams = 1;
6532 return true;
6533 }
6534 case GL_MAX_VIEWPORT_DIMS:
6535 {
6536 *type = GL_INT;
6537 *numParams = 2;
6538 return true;
6539 }
6540 case GL_VIEWPORT:
6541 case GL_SCISSOR_BOX:
6542 {
6543 *type = GL_INT;
6544 *numParams = 4;
6545 return true;
6546 }
6547 case GL_SHADER_COMPILER:
6548 case GL_SAMPLE_COVERAGE_INVERT:
6549 case GL_DEPTH_WRITEMASK:
6550 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6551 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6552 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6553 // bool-natural
6554 case GL_SAMPLE_COVERAGE:
6555 case GL_SCISSOR_TEST:
6556 case GL_STENCIL_TEST:
6557 case GL_DEPTH_TEST:
6558 case GL_BLEND:
6559 case GL_DITHER:
6560 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6561 {
6562 *type = GL_BOOL;
6563 *numParams = 1;
6564 return true;
6565 }
6566 case GL_COLOR_WRITEMASK:
6567 {
6568 *type = GL_BOOL;
6569 *numParams = 4;
6570 return true;
6571 }
6572 case GL_POLYGON_OFFSET_FACTOR:
6573 case GL_POLYGON_OFFSET_UNITS:
6574 case GL_SAMPLE_COVERAGE_VALUE:
6575 case GL_DEPTH_CLEAR_VALUE:
6576 case GL_LINE_WIDTH:
6577 {
6578 *type = GL_FLOAT;
6579 *numParams = 1;
6580 return true;
6581 }
6582 case GL_ALIASED_LINE_WIDTH_RANGE:
6583 case GL_ALIASED_POINT_SIZE_RANGE:
6584 case GL_DEPTH_RANGE:
6585 {
6586 *type = GL_FLOAT;
6587 *numParams = 2;
6588 return true;
6589 }
6590 case GL_COLOR_CLEAR_VALUE:
6591 case GL_BLEND_COLOR:
6592 {
6593 *type = GL_FLOAT;
6594 *numParams = 4;
6595 return true;
6596 }
6597 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6598 if (!getExtensions().textureFilterAnisotropic)
6599 {
6600 return false;
6601 }
6602 *type = GL_FLOAT;
6603 *numParams = 1;
6604 return true;
6605 case GL_TIMESTAMP_EXT:
6606 if (!getExtensions().disjointTimerQuery)
6607 {
6608 return false;
6609 }
6610 *type = GL_INT_64_ANGLEX;
6611 *numParams = 1;
6612 return true;
6613 case GL_GPU_DISJOINT_EXT:
6614 if (!getExtensions().disjointTimerQuery)
6615 {
6616 return false;
6617 }
6618 *type = GL_INT;
6619 *numParams = 1;
6620 return true;
6621 case GL_COVERAGE_MODULATION_CHROMIUM:
6622 if (!getExtensions().framebufferMixedSamples)
6623 {
6624 return false;
6625 }
6626 *type = GL_INT;
6627 *numParams = 1;
6628 return true;
6629 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6630 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6631 {
6632 return false;
6633 }
6634 *type = GL_INT;
6635 *numParams = 1;
6636 return true;
6637 }
6638
6639 if (getExtensions().debug)
6640 {
6641 switch (pname)
6642 {
6643 case GL_DEBUG_LOGGED_MESSAGES:
6644 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6645 case GL_DEBUG_GROUP_STACK_DEPTH:
6646 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6647 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6648 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6649 case GL_MAX_LABEL_LENGTH:
6650 *type = GL_INT;
6651 *numParams = 1;
6652 return true;
6653
6654 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6655 case GL_DEBUG_OUTPUT:
6656 *type = GL_BOOL;
6657 *numParams = 1;
6658 return true;
6659 }
6660 }
6661
6662 if (getExtensions().multisampleCompatibility)
6663 {
6664 switch (pname)
6665 {
6666 case GL_MULTISAMPLE_EXT:
6667 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6668 *type = GL_BOOL;
6669 *numParams = 1;
6670 return true;
6671 }
6672 }
6673
6674 if (getExtensions().pathRendering)
6675 {
6676 switch (pname)
6677 {
6678 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6679 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6680 *type = GL_FLOAT;
6681 *numParams = 16;
6682 return true;
6683 }
6684 }
6685
6686 if (getExtensions().bindGeneratesResource)
6687 {
6688 switch (pname)
6689 {
6690 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6691 *type = GL_BOOL;
6692 *numParams = 1;
6693 return true;
6694 }
6695 }
6696
6697 if (getExtensions().clientArrays)
6698 {
6699 switch (pname)
6700 {
6701 case GL_CLIENT_ARRAYS_ANGLE:
6702 *type = GL_BOOL;
6703 *numParams = 1;
6704 return true;
6705 }
6706 }
6707
6708 if (getExtensions().sRGBWriteControl)
6709 {
6710 switch (pname)
6711 {
6712 case GL_FRAMEBUFFER_SRGB_EXT:
6713 *type = GL_BOOL;
6714 *numParams = 1;
6715 return true;
6716 }
6717 }
6718
6719 if (getExtensions().robustResourceInitialization &&
6720 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6721 {
6722 *type = GL_BOOL;
6723 *numParams = 1;
6724 return true;
6725 }
6726
6727 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6728 {
6729 *type = GL_BOOL;
6730 *numParams = 1;
6731 return true;
6732 }
6733
6734 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6735 switch (pname)
6736 {
6737 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6738 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6739 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6740 {
6741 return false;
6742 }
6743 *type = GL_INT;
6744 *numParams = 1;
6745 return true;
6746
6747 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6748 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6749 {
6750 return false;
6751 }
6752 *type = GL_INT;
6753 *numParams = 1;
6754 return true;
6755
6756 case GL_PROGRAM_BINARY_FORMATS_OES:
6757 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6758 {
6759 return false;
6760 }
6761 *type = GL_INT;
6762 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6763 return true;
6764
6765 case GL_PACK_ROW_LENGTH:
6766 case GL_PACK_SKIP_ROWS:
6767 case GL_PACK_SKIP_PIXELS:
6768 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6769 {
6770 return false;
6771 }
6772 *type = GL_INT;
6773 *numParams = 1;
6774 return true;
6775 case GL_UNPACK_ROW_LENGTH:
6776 case GL_UNPACK_SKIP_ROWS:
6777 case GL_UNPACK_SKIP_PIXELS:
6778 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6779 {
6780 return false;
6781 }
6782 *type = GL_INT;
6783 *numParams = 1;
6784 return true;
6785 case GL_VERTEX_ARRAY_BINDING:
6786 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6787 {
6788 return false;
6789 }
6790 *type = GL_INT;
6791 *numParams = 1;
6792 return true;
6793 case GL_PIXEL_PACK_BUFFER_BINDING:
6794 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6795 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6796 {
6797 return false;
6798 }
6799 *type = GL_INT;
6800 *numParams = 1;
6801 return true;
6802 case GL_MAX_SAMPLES:
6803 {
6804 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6805 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6806 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6807 {
6808 return false;
6809 }
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813
6814 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6815 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6816 {
6817 return false;
6818 }
6819 *type = GL_INT;
6820 *numParams = 1;
6821 return true;
6822 }
6823 }
6824
6825 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6826 {
6827 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT;
6832 *numParams = 1;
6833 return true;
6834 }
6835
6836 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6837 {
6838 *type = GL_INT;
6839 *numParams = 1;
6840 return true;
6841 }
6842
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006843 if (getClientVersion() < Version(2, 0))
6844 {
6845 switch (pname)
6846 {
6847 case GL_ALPHA_TEST_FUNC:
6848 *type = GL_INT;
6849 *numParams = 1;
6850 return true;
6851 case GL_ALPHA_TEST_REF:
6852 *type = GL_FLOAT;
6853 *numParams = 1;
6854 return true;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07006855 case GL_MAX_TEXTURE_UNITS:
6856 *type = GL_INT;
6857 *numParams = 1;
6858 return true;
6859 case GL_CLIENT_ACTIVE_TEXTURE:
6860 *type = GL_INT;
6861 *numParams = 1;
6862 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006863 case GL_CURRENT_COLOR:
6864 *type = GL_FLOAT;
6865 *numParams = 4;
6866 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07006867 case GL_CURRENT_NORMAL:
6868 *type = GL_FLOAT;
6869 *numParams = 3;
6870 return true;
Lingfeng Yang038dd532018-03-29 17:31:52 -07006871 case GL_CURRENT_TEXTURE_COORDS:
6872 *type = GL_FLOAT;
6873 *numParams = 4;
6874 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006875 }
6876 }
6877
Jamie Madill5b772312018-03-08 20:28:32 -05006878 if (getClientVersion() < Version(3, 0))
6879 {
6880 return false;
6881 }
6882
6883 // Check for ES3.0+ parameter names
6884 switch (pname)
6885 {
6886 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6887 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6888 case GL_UNIFORM_BUFFER_BINDING:
6889 case GL_TRANSFORM_FEEDBACK_BINDING:
6890 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6891 case GL_COPY_READ_BUFFER_BINDING:
6892 case GL_COPY_WRITE_BUFFER_BINDING:
6893 case GL_SAMPLER_BINDING:
6894 case GL_READ_BUFFER:
6895 case GL_TEXTURE_BINDING_3D:
6896 case GL_TEXTURE_BINDING_2D_ARRAY:
6897 case GL_MAX_3D_TEXTURE_SIZE:
6898 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6899 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6900 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6901 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6902 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6903 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6904 case GL_MAX_VARYING_COMPONENTS:
6905 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6906 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6907 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6908 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6909 case GL_NUM_EXTENSIONS:
6910 case GL_MAJOR_VERSION:
6911 case GL_MINOR_VERSION:
6912 case GL_MAX_ELEMENTS_INDICES:
6913 case GL_MAX_ELEMENTS_VERTICES:
6914 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6915 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6916 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6917 case GL_UNPACK_IMAGE_HEIGHT:
6918 case GL_UNPACK_SKIP_IMAGES:
6919 {
6920 *type = GL_INT;
6921 *numParams = 1;
6922 return true;
6923 }
6924
6925 case GL_MAX_ELEMENT_INDEX:
6926 case GL_MAX_UNIFORM_BLOCK_SIZE:
6927 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6928 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6929 case GL_MAX_SERVER_WAIT_TIMEOUT:
6930 {
6931 *type = GL_INT_64_ANGLEX;
6932 *numParams = 1;
6933 return true;
6934 }
6935
6936 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6937 case GL_TRANSFORM_FEEDBACK_PAUSED:
6938 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6939 case GL_RASTERIZER_DISCARD:
6940 {
6941 *type = GL_BOOL;
6942 *numParams = 1;
6943 return true;
6944 }
6945
6946 case GL_MAX_TEXTURE_LOD_BIAS:
6947 {
6948 *type = GL_FLOAT;
6949 *numParams = 1;
6950 return true;
6951 }
6952 }
6953
6954 if (getExtensions().requestExtension)
6955 {
6956 switch (pname)
6957 {
6958 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6959 *type = GL_INT;
6960 *numParams = 1;
6961 return true;
6962 }
6963 }
6964
6965 if (getClientVersion() < Version(3, 1))
6966 {
6967 return false;
6968 }
6969
6970 switch (pname)
6971 {
6972 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6973 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6974 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6975 case GL_MAX_FRAMEBUFFER_WIDTH:
6976 case GL_MAX_FRAMEBUFFER_HEIGHT:
6977 case GL_MAX_FRAMEBUFFER_SAMPLES:
6978 case GL_MAX_SAMPLE_MASK_WORDS:
6979 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6980 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6981 case GL_MAX_INTEGER_SAMPLES:
6982 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6983 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6984 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6985 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6986 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6987 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6988 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6989 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6990 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6991 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6992 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6993 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6994 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6995 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6996 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6997 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6998 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6999 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7000 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7001 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7002 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7003 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7004 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7005 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7006 case GL_MAX_UNIFORM_LOCATIONS:
7007 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7008 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7009 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7010 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7011 case GL_MAX_IMAGE_UNITS:
7012 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7013 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7014 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7015 case GL_SHADER_STORAGE_BUFFER_BINDING:
7016 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7017 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7018 *type = GL_INT;
7019 *numParams = 1;
7020 return true;
7021 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7022 *type = GL_INT_64_ANGLEX;
7023 *numParams = 1;
7024 return true;
7025 case GL_SAMPLE_MASK:
7026 *type = GL_BOOL;
7027 *numParams = 1;
7028 return true;
7029 }
7030
7031 if (getExtensions().geometryShader)
7032 {
7033 switch (pname)
7034 {
7035 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7036 case GL_LAYER_PROVOKING_VERTEX_EXT:
7037 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7038 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7039 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7040 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7041 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7042 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7043 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7044 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7045 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7046 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7047 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7048 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7049 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7050 *type = GL_INT;
7051 *numParams = 1;
7052 return true;
7053 }
7054 }
7055
7056 return false;
7057}
7058
7059bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7060{
7061 if (getClientVersion() < Version(3, 0))
7062 {
7063 return false;
7064 }
7065
7066 switch (target)
7067 {
7068 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7069 case GL_UNIFORM_BUFFER_BINDING:
7070 {
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074 }
7075 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7076 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7077 case GL_UNIFORM_BUFFER_START:
7078 case GL_UNIFORM_BUFFER_SIZE:
7079 {
7080 *type = GL_INT_64_ANGLEX;
7081 *numParams = 1;
7082 return true;
7083 }
7084 }
7085
7086 if (getClientVersion() < Version(3, 1))
7087 {
7088 return false;
7089 }
7090
7091 switch (target)
7092 {
7093 case GL_IMAGE_BINDING_LAYERED:
7094 {
7095 *type = GL_BOOL;
7096 *numParams = 1;
7097 return true;
7098 }
7099 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7100 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7101 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7102 case GL_SHADER_STORAGE_BUFFER_BINDING:
7103 case GL_VERTEX_BINDING_BUFFER:
7104 case GL_VERTEX_BINDING_DIVISOR:
7105 case GL_VERTEX_BINDING_OFFSET:
7106 case GL_VERTEX_BINDING_STRIDE:
7107 case GL_SAMPLE_MASK_VALUE:
7108 case GL_IMAGE_BINDING_NAME:
7109 case GL_IMAGE_BINDING_LEVEL:
7110 case GL_IMAGE_BINDING_LAYER:
7111 case GL_IMAGE_BINDING_ACCESS:
7112 case GL_IMAGE_BINDING_FORMAT:
7113 {
7114 *type = GL_INT;
7115 *numParams = 1;
7116 return true;
7117 }
7118 case GL_ATOMIC_COUNTER_BUFFER_START:
7119 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7120 case GL_SHADER_STORAGE_BUFFER_START:
7121 case GL_SHADER_STORAGE_BUFFER_SIZE:
7122 {
7123 *type = GL_INT_64_ANGLEX;
7124 *numParams = 1;
7125 return true;
7126 }
7127 }
7128
7129 return false;
7130}
7131
7132Program *Context::getProgram(GLuint handle) const
7133{
7134 return mState.mShaderPrograms->getProgram(handle);
7135}
7136
7137Shader *Context::getShader(GLuint handle) const
7138{
7139 return mState.mShaderPrograms->getShader(handle);
7140}
7141
7142bool Context::isTextureGenerated(GLuint texture) const
7143{
7144 return mState.mTextures->isHandleGenerated(texture);
7145}
7146
7147bool Context::isBufferGenerated(GLuint buffer) const
7148{
7149 return mState.mBuffers->isHandleGenerated(buffer);
7150}
7151
7152bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7153{
7154 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7155}
7156
7157bool Context::isFramebufferGenerated(GLuint framebuffer) const
7158{
7159 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7160}
7161
7162bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7163{
7164 return mState.mPipelines->isHandleGenerated(pipeline);
7165}
7166
7167bool Context::usingDisplayTextureShareGroup() const
7168{
7169 return mDisplayTextureShareGroup;
7170}
7171
7172GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7173{
7174 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7175 internalformat == GL_DEPTH_STENCIL
7176 ? GL_DEPTH24_STENCIL8
7177 : internalformat;
7178}
7179
Jamie Madillc29968b2016-01-20 11:17:23 -05007180} // namespace gl