blob: b0b24ec051f52e9adcc6191b51ed60f4de673431 [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;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001650 case GL_MAX_MODELVIEW_STACK_DEPTH:
1651 *params = mCaps.maxModelviewMatrixStackDepth;
1652 break;
1653 case GL_MAX_PROJECTION_STACK_DEPTH:
1654 *params = mCaps.maxProjectionMatrixStackDepth;
1655 break;
1656 case GL_MAX_TEXTURE_STACK_DEPTH:
1657 *params = mCaps.maxTextureMatrixStackDepth;
1658 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001660 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001662 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001663}
1664
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001665void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001666{
Shannon Woods53a94a82014-06-24 15:20:36 -04001667 // Queries about context capabilities and maximums are answered by Context.
1668 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001669 switch (pname)
1670 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 case GL_MAX_ELEMENT_INDEX:
1672 *params = mCaps.maxElementIndex;
1673 break;
1674 case GL_MAX_UNIFORM_BLOCK_SIZE:
1675 *params = mCaps.maxUniformBlockSize;
1676 break;
1677 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1678 *params = mCaps.maxCombinedVertexUniformComponents;
1679 break;
1680 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1681 *params = mCaps.maxCombinedFragmentUniformComponents;
1682 break;
1683 case GL_MAX_SERVER_WAIT_TIMEOUT:
1684 *params = mCaps.maxServerWaitTimeout;
1685 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001686
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 // GL_EXT_disjoint_timer_query
1688 case GL_TIMESTAMP_EXT:
1689 *params = mImplementation->getTimestamp();
1690 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001691
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1693 *params = mCaps.maxShaderStorageBlockSize;
1694 break;
1695 default:
1696 UNREACHABLE();
1697 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001698 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001699}
1700
Geoff Lang70d0f492015-12-10 17:45:46 -05001701void Context::getPointerv(GLenum pname, void **params) const
1702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001703 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001704}
1705
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001706void Context::getPointervRobustANGLERobust(GLenum pname,
1707 GLsizei bufSize,
1708 GLsizei *length,
1709 void **params)
1710{
1711 UNIMPLEMENTED();
1712}
1713
Martin Radev66fb8202016-07-28 11:45:20 +03001714void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001715{
Shannon Woods53a94a82014-06-24 15:20:36 -04001716 // Queries about context capabilities and maximums are answered by Context.
1717 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001718
1719 GLenum nativeType;
1720 unsigned int numParams;
1721 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1722 ASSERT(queryStatus);
1723
1724 if (nativeType == GL_INT)
1725 {
1726 switch (target)
1727 {
1728 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1729 ASSERT(index < 3u);
1730 *data = mCaps.maxComputeWorkGroupCount[index];
1731 break;
1732 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1733 ASSERT(index < 3u);
1734 *data = mCaps.maxComputeWorkGroupSize[index];
1735 break;
1736 default:
1737 mGLState.getIntegeri_v(target, index, data);
1738 }
1739 }
1740 else
1741 {
1742 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1743 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001744}
1745
Brandon Jones59770802018-04-02 13:18:42 -07001746void Context::getIntegeri_vRobust(GLenum target,
1747 GLuint index,
1748 GLsizei bufSize,
1749 GLsizei *length,
1750 GLint *data)
1751{
1752 getIntegeri_v(target, index, data);
1753}
1754
Martin Radev66fb8202016-07-28 11:45:20 +03001755void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001756{
Shannon Woods53a94a82014-06-24 15:20:36 -04001757 // Queries about context capabilities and maximums are answered by Context.
1758 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001759
1760 GLenum nativeType;
1761 unsigned int numParams;
1762 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1763 ASSERT(queryStatus);
1764
1765 if (nativeType == GL_INT_64_ANGLEX)
1766 {
1767 mGLState.getInteger64i_v(target, index, data);
1768 }
1769 else
1770 {
1771 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1772 }
1773}
1774
Brandon Jones59770802018-04-02 13:18:42 -07001775void Context::getInteger64i_vRobust(GLenum target,
1776 GLuint index,
1777 GLsizei bufSize,
1778 GLsizei *length,
1779 GLint64 *data)
1780{
1781 getInteger64i_v(target, index, data);
1782}
1783
Martin Radev66fb8202016-07-28 11:45:20 +03001784void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1785{
1786 // Queries about context capabilities and maximums are answered by Context.
1787 // Queries about current GL state values are answered by State.
1788
1789 GLenum nativeType;
1790 unsigned int numParams;
1791 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1792 ASSERT(queryStatus);
1793
1794 if (nativeType == GL_BOOL)
1795 {
1796 mGLState.getBooleani_v(target, index, data);
1797 }
1798 else
1799 {
1800 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1801 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001802}
1803
Brandon Jones59770802018-04-02 13:18:42 -07001804void Context::getBooleani_vRobust(GLenum target,
1805 GLuint index,
1806 GLsizei bufSize,
1807 GLsizei *length,
1808 GLboolean *data)
1809{
1810 getBooleani_v(target, index, data);
1811}
1812
Corentin Wallez336129f2017-10-17 15:55:40 -04001813void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001814{
1815 Buffer *buffer = mGLState.getTargetBuffer(target);
1816 QueryBufferParameteriv(buffer, pname, params);
1817}
1818
Brandon Jones59770802018-04-02 13:18:42 -07001819void Context::getBufferParameterivRobust(BufferBinding target,
1820 GLenum pname,
1821 GLsizei bufSize,
1822 GLsizei *length,
1823 GLint *params)
1824{
1825 getBufferParameteriv(target, pname, params);
1826}
1827
He Yunchao010e4db2017-03-03 14:22:06 +08001828void Context::getFramebufferAttachmentParameteriv(GLenum target,
1829 GLenum attachment,
1830 GLenum pname,
1831 GLint *params)
1832{
1833 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001834 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001835}
1836
Brandon Jones59770802018-04-02 13:18:42 -07001837void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1838 GLenum attachment,
1839 GLenum pname,
1840 GLsizei bufSize,
1841 GLsizei *length,
1842 GLint *params)
1843{
1844 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1845}
1846
He Yunchao010e4db2017-03-03 14:22:06 +08001847void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1848{
1849 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1850 QueryRenderbufferiv(this, renderbuffer, pname, params);
1851}
1852
Brandon Jones59770802018-04-02 13:18:42 -07001853void Context::getRenderbufferParameterivRobust(GLenum target,
1854 GLenum pname,
1855 GLsizei bufSize,
1856 GLsizei *length,
1857 GLint *params)
1858{
1859 getRenderbufferParameteriv(target, pname, params);
1860}
1861
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001862void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001863{
1864 Texture *texture = getTargetTexture(target);
1865 QueryTexParameterfv(texture, pname, params);
1866}
1867
Brandon Jones59770802018-04-02 13:18:42 -07001868void Context::getTexParameterfvRobust(TextureType target,
1869 GLenum pname,
1870 GLsizei bufSize,
1871 GLsizei *length,
1872 GLfloat *params)
1873{
1874 getTexParameterfv(target, pname, params);
1875}
1876
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001877void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001878{
1879 Texture *texture = getTargetTexture(target);
1880 QueryTexParameteriv(texture, pname, params);
1881}
Jiajia Qin5451d532017-11-16 17:16:34 +08001882
Brandon Jones59770802018-04-02 13:18:42 -07001883void Context::getTexParameterivRobust(TextureType target,
1884 GLenum pname,
1885 GLsizei bufSize,
1886 GLsizei *length,
1887 GLint *params)
1888{
1889 getTexParameteriv(target, pname, params);
1890}
1891
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001892void Context::getTexParameterIivRobust(TextureType target,
1893 GLenum pname,
1894 GLsizei bufSize,
1895 GLsizei *length,
1896 GLint *params)
1897{
1898 UNIMPLEMENTED();
1899}
1900
1901void Context::getTexParameterIuivRobust(TextureType target,
1902 GLenum pname,
1903 GLsizei bufSize,
1904 GLsizei *length,
1905 GLuint *params)
1906{
1907 UNIMPLEMENTED();
1908}
1909
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001910void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001911{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001912 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001913 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001914}
1915
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001916void Context::getTexLevelParameterivRobust(TextureTarget target,
1917 GLint level,
1918 GLenum pname,
1919 GLsizei bufSize,
1920 GLsizei *length,
1921 GLint *params)
1922{
1923 UNIMPLEMENTED();
1924}
1925
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001926void Context::getTexLevelParameterfv(TextureTarget target,
1927 GLint level,
1928 GLenum pname,
1929 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001930{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001931 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001932 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001933}
1934
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001935void Context::getTexLevelParameterfvRobust(TextureTarget target,
1936 GLint level,
1937 GLenum pname,
1938 GLsizei bufSize,
1939 GLsizei *length,
1940 GLfloat *params)
1941{
1942 UNIMPLEMENTED();
1943}
1944
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001945void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001946{
1947 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001948 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001949 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001950}
1951
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001952void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001953{
1954 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001955 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001956 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001957}
1958
Brandon Jones59770802018-04-02 13:18:42 -07001959void Context::texParameterfvRobust(TextureType target,
1960 GLenum pname,
1961 GLsizei bufSize,
1962 const GLfloat *params)
1963{
1964 texParameterfv(target, pname, params);
1965}
1966
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001967void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001968{
1969 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001970 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001971 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001972}
1973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001974void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001975{
1976 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001977 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001978 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001979}
1980
Brandon Jones59770802018-04-02 13:18:42 -07001981void Context::texParameterivRobust(TextureType target,
1982 GLenum pname,
1983 GLsizei bufSize,
1984 const GLint *params)
1985{
1986 texParameteriv(target, pname, params);
1987}
1988
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001989void Context::texParameterIivRobust(TextureType target,
1990 GLenum pname,
1991 GLsizei bufSize,
1992 const GLint *params)
1993{
1994 UNIMPLEMENTED();
1995}
1996
1997void Context::texParameterIuivRobust(TextureType target,
1998 GLenum pname,
1999 GLsizei bufSize,
2000 const GLuint *params)
2001{
2002 UNIMPLEMENTED();
2003}
2004
Jamie Madill675fe712016-12-19 13:07:54 -05002005void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002006{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002007 // No-op if zero count
2008 if (count == 0)
2009 {
2010 return;
2011 }
2012
Jamie Madill05b35b22017-10-03 09:01:44 -04002013 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002014 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002015 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002016}
2017
Jamie Madill675fe712016-12-19 13:07:54 -05002018void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002019{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002020 // No-op if zero count
2021 if (count == 0 || instanceCount == 0)
2022 {
2023 return;
2024 }
2025
Jamie Madill05b35b22017-10-03 09:01:44 -04002026 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002027 ANGLE_CONTEXT_TRY(
2028 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002029 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2030 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002031}
2032
Jamie Madill876429b2017-04-20 15:46:24 -04002033void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002034{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002035 // No-op if zero count
2036 if (count == 0)
2037 {
2038 return;
2039 }
2040
Jamie Madill05b35b22017-10-03 09:01:44 -04002041 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002042 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002043}
2044
Jamie Madill675fe712016-12-19 13:07:54 -05002045void Context::drawElementsInstanced(GLenum mode,
2046 GLsizei count,
2047 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002048 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002049 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002050{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002051 // No-op if zero count
2052 if (count == 0 || instances == 0)
2053 {
2054 return;
2055 }
2056
Jamie Madill05b35b22017-10-03 09:01:44 -04002057 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002058 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002059 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002060}
2061
Jamie Madill675fe712016-12-19 13:07:54 -05002062void Context::drawRangeElements(GLenum mode,
2063 GLuint start,
2064 GLuint end,
2065 GLsizei count,
2066 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002067 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002068{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002069 // No-op if zero count
2070 if (count == 0)
2071 {
2072 return;
2073 }
2074
Jamie Madill05b35b22017-10-03 09:01:44 -04002075 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002076 ANGLE_CONTEXT_TRY(
2077 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002078}
2079
Jamie Madill876429b2017-04-20 15:46:24 -04002080void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002081{
Jamie Madill05b35b22017-10-03 09:01:44 -04002082 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002083 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002084}
2085
Jamie Madill876429b2017-04-20 15:46:24 -04002086void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002087{
Jamie Madill05b35b22017-10-03 09:01:44 -04002088 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002089 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002090}
2091
Jamie Madill675fe712016-12-19 13:07:54 -05002092void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002093{
Jamie Madillafa02a22017-11-23 12:57:38 -05002094 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002095}
2096
Jamie Madill675fe712016-12-19 13:07:54 -05002097void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002098{
Jamie Madillafa02a22017-11-23 12:57:38 -05002099 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002100}
2101
Austin Kinross6ee1e782015-05-29 17:05:37 -07002102void Context::insertEventMarker(GLsizei length, const char *marker)
2103{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002104 ASSERT(mImplementation);
2105 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002106}
2107
2108void Context::pushGroupMarker(GLsizei length, const char *marker)
2109{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002110 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002111
2112 if (marker == nullptr)
2113 {
2114 // From the EXT_debug_marker spec,
2115 // "If <marker> is null then an empty string is pushed on the stack."
2116 mImplementation->pushGroupMarker(length, "");
2117 }
2118 else
2119 {
2120 mImplementation->pushGroupMarker(length, marker);
2121 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002122}
2123
2124void Context::popGroupMarker()
2125{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002126 ASSERT(mImplementation);
2127 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002128}
2129
Geoff Langd8605522016-04-13 10:19:12 -04002130void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2131{
2132 Program *programObject = getProgram(program);
2133 ASSERT(programObject);
2134
2135 programObject->bindUniformLocation(location, name);
2136}
2137
Brandon Jones59770802018-04-02 13:18:42 -07002138void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002139{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002140 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002141}
2142
Brandon Jones59770802018-04-02 13:18:42 -07002143void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002144{
2145 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2146}
2147
Brandon Jones59770802018-04-02 13:18:42 -07002148void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002149{
2150 GLfloat I[16];
2151 angle::Matrix<GLfloat>::setToIdentity(I);
2152
2153 mGLState.loadPathRenderingMatrix(matrixMode, I);
2154}
2155
2156void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2157{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002158 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002159 if (!pathObj)
2160 return;
2161
2162 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002163 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002164
2165 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2166}
2167
2168void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2169{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002170 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002171 if (!pathObj)
2172 return;
2173
2174 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002175 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002176
2177 mImplementation->stencilStrokePath(pathObj, reference, mask);
2178}
2179
2180void Context::coverFillPath(GLuint path, GLenum coverMode)
2181{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002182 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002183 if (!pathObj)
2184 return;
2185
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änene45e53b2016-05-25 10:36:04 +03002188
2189 mImplementation->coverFillPath(pathObj, coverMode);
2190}
2191
2192void Context::coverStrokePath(GLuint path, GLenum coverMode)
2193{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002194 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002195 if (!pathObj)
2196 return;
2197
2198 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002199 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002200
2201 mImplementation->coverStrokePath(pathObj, coverMode);
2202}
2203
2204void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2205{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002206 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002207 if (!pathObj)
2208 return;
2209
2210 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002211 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002212
2213 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2214}
2215
2216void Context::stencilThenCoverStrokePath(GLuint path,
2217 GLint reference,
2218 GLuint mask,
2219 GLenum coverMode)
2220{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002221 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002222 if (!pathObj)
2223 return;
2224
2225 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002226 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002227
2228 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2229}
2230
Sami Väisänend59ca052016-06-21 16:10:00 +03002231void Context::coverFillPathInstanced(GLsizei numPaths,
2232 GLenum pathNameType,
2233 const void *paths,
2234 GLuint pathBase,
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->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2245}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002246
Sami Väisänend59ca052016-06-21 16:10:00 +03002247void Context::coverStrokePathInstanced(GLsizei numPaths,
2248 GLenum pathNameType,
2249 const void *paths,
2250 GLuint pathBase,
2251 GLenum coverMode,
2252 GLenum transformType,
2253 const GLfloat *transformValues)
2254{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002255 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002256
2257 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002258 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002259
2260 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2261 transformValues);
2262}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002263
Sami Väisänend59ca052016-06-21 16:10:00 +03002264void Context::stencilFillPathInstanced(GLsizei numPaths,
2265 GLenum pathNameType,
2266 const void *paths,
2267 GLuint pathBase,
2268 GLenum fillMode,
2269 GLuint mask,
2270 GLenum transformType,
2271 const GLfloat *transformValues)
2272{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002273 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002274
2275 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002276 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002277
2278 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2279 transformValues);
2280}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002281
Sami Väisänend59ca052016-06-21 16:10:00 +03002282void Context::stencilStrokePathInstanced(GLsizei numPaths,
2283 GLenum pathNameType,
2284 const void *paths,
2285 GLuint pathBase,
2286 GLint reference,
2287 GLuint mask,
2288 GLenum transformType,
2289 const GLfloat *transformValues)
2290{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002291 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002292
2293 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002294 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002295
2296 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2297 transformValues);
2298}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002299
Sami Väisänend59ca052016-06-21 16:10:00 +03002300void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2301 GLenum pathNameType,
2302 const void *paths,
2303 GLuint pathBase,
2304 GLenum fillMode,
2305 GLuint mask,
2306 GLenum coverMode,
2307 GLenum transformType,
2308 const GLfloat *transformValues)
2309{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002310 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002311
2312 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002313 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002314
2315 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2316 transformType, transformValues);
2317}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002318
Sami Väisänend59ca052016-06-21 16:10:00 +03002319void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2320 GLenum pathNameType,
2321 const void *paths,
2322 GLuint pathBase,
2323 GLint reference,
2324 GLuint mask,
2325 GLenum coverMode,
2326 GLenum transformType,
2327 const GLfloat *transformValues)
2328{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002329 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002330
2331 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002332 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002333
2334 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2335 transformType, transformValues);
2336}
2337
Sami Väisänen46eaa942016-06-29 10:26:37 +03002338void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2339{
2340 auto *programObject = getProgram(program);
2341
2342 programObject->bindFragmentInputLocation(location, name);
2343}
2344
2345void Context::programPathFragmentInputGen(GLuint program,
2346 GLint location,
2347 GLenum genMode,
2348 GLint components,
2349 const GLfloat *coeffs)
2350{
2351 auto *programObject = getProgram(program);
2352
Jamie Madillbd044ed2017-06-05 12:59:21 -04002353 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002354}
2355
jchen1015015f72017-03-16 13:54:21 +08002356GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2357{
jchen10fd7c3b52017-03-21 15:36:03 +08002358 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002359 return QueryProgramResourceIndex(programObject, programInterface, name);
2360}
2361
jchen10fd7c3b52017-03-21 15:36:03 +08002362void Context::getProgramResourceName(GLuint program,
2363 GLenum programInterface,
2364 GLuint index,
2365 GLsizei bufSize,
2366 GLsizei *length,
2367 GLchar *name)
2368{
2369 const auto *programObject = getProgram(program);
2370 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2371}
2372
jchen10191381f2017-04-11 13:59:04 +08002373GLint Context::getProgramResourceLocation(GLuint program,
2374 GLenum programInterface,
2375 const GLchar *name)
2376{
2377 const auto *programObject = getProgram(program);
2378 return QueryProgramResourceLocation(programObject, programInterface, name);
2379}
2380
jchen10880683b2017-04-12 16:21:55 +08002381void Context::getProgramResourceiv(GLuint program,
2382 GLenum programInterface,
2383 GLuint index,
2384 GLsizei propCount,
2385 const GLenum *props,
2386 GLsizei bufSize,
2387 GLsizei *length,
2388 GLint *params)
2389{
2390 const auto *programObject = getProgram(program);
2391 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2392 length, params);
2393}
2394
jchen10d9cd7b72017-08-30 15:04:25 +08002395void Context::getProgramInterfaceiv(GLuint program,
2396 GLenum programInterface,
2397 GLenum pname,
2398 GLint *params)
2399{
2400 const auto *programObject = getProgram(program);
2401 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2402}
2403
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002404void Context::getProgramInterfaceivRobust(GLuint program,
2405 GLenum programInterface,
2406 GLenum pname,
2407 GLsizei bufSize,
2408 GLsizei *length,
2409 GLint *params)
2410{
2411 UNIMPLEMENTED();
2412}
2413
Jamie Madill71c88b32017-09-14 22:20:29 -04002414void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002415{
Geoff Langda5777c2014-07-11 09:52:58 -04002416 if (error.isError())
2417 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002418 GLenum code = error.getCode();
2419 mErrors.insert(code);
2420 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2421 {
2422 markContextLost();
2423 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002424
Geoff Langee6884e2017-11-09 16:51:11 -05002425 ASSERT(!error.getMessage().empty());
2426 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2427 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002428 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002429}
2430
2431// Get one of the recorded errors and clear its flag, if any.
2432// [OpenGL ES 2.0.24] section 2.5 page 13.
2433GLenum Context::getError()
2434{
Geoff Langda5777c2014-07-11 09:52:58 -04002435 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002436 {
Geoff Langda5777c2014-07-11 09:52:58 -04002437 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002438 }
Geoff Langda5777c2014-07-11 09:52:58 -04002439 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002440 {
Geoff Langda5777c2014-07-11 09:52:58 -04002441 GLenum error = *mErrors.begin();
2442 mErrors.erase(mErrors.begin());
2443 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002444 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002445}
2446
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002447// NOTE: this function should not assume that this context is current!
2448void Context::markContextLost()
2449{
2450 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002451 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002452 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002453 mContextLostForced = true;
2454 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002455 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002456}
2457
2458bool Context::isContextLost()
2459{
2460 return mContextLost;
2461}
2462
Jamie Madillfa920eb2018-01-04 11:45:50 -05002463GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002464{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002465 // Even if the application doesn't want to know about resets, we want to know
2466 // as it will allow us to skip all the calls.
2467 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002468 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002469 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002470 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002471 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002472 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002473
2474 // EXT_robustness, section 2.6: If the reset notification behavior is
2475 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2476 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2477 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002478 }
2479
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002480 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2481 // status should be returned at least once, and GL_NO_ERROR should be returned
2482 // once the device has finished resetting.
2483 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002484 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002485 ASSERT(mResetStatus == GL_NO_ERROR);
2486 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002487
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002488 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002489 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002490 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002491 }
2492 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002493 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002494 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002495 // If markContextLost was used to mark the context lost then
2496 // assume that is not recoverable, and continue to report the
2497 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002498 mResetStatus = mImplementation->getResetStatus();
2499 }
Jamie Madill893ab082014-05-16 16:56:10 -04002500
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002501 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502}
2503
2504bool Context::isResetNotificationEnabled()
2505{
2506 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2507}
2508
Corentin Walleze3b10e82015-05-20 11:06:25 -04002509const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002510{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002511 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002512}
2513
2514EGLenum Context::getClientType() const
2515{
2516 return mClientType;
2517}
2518
2519EGLenum Context::getRenderBuffer() const
2520{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002521 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2522 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002523 {
2524 return EGL_NONE;
2525 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002526
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002527 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002528 ASSERT(backAttachment != nullptr);
2529 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002530}
2531
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002532VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002533{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002534 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002535 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2536 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002537 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002538 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2539 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002540
Jamie Madill96a483b2017-06-27 16:49:21 -04002541 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002542 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002543
2544 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002545}
2546
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002547TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002548{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002549 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002550 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2551 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002552 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002553 transformFeedback =
2554 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002555 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002556 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002557 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002558
2559 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002560}
2561
2562bool Context::isVertexArrayGenerated(GLuint vertexArray)
2563{
Jamie Madill96a483b2017-06-27 16:49:21 -04002564 ASSERT(mVertexArrayMap.contains(0));
2565 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002566}
2567
2568bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2569{
Jamie Madill96a483b2017-06-27 16:49:21 -04002570 ASSERT(mTransformFeedbackMap.contains(0));
2571 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002572}
2573
Shannon Woods53a94a82014-06-24 15:20:36 -04002574void Context::detachTexture(GLuint texture)
2575{
2576 // Simple pass-through to State's detachTexture method, as textures do not require
2577 // allocation map management either here or in the resource manager at detach time.
2578 // Zero textures are held by the Context, and we don't attempt to request them from
2579 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002580 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002581}
2582
James Darpinian4d9d4832018-03-13 12:43:28 -07002583void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584{
Yuly Novikov5807a532015-12-03 13:01:22 -05002585 // Simple pass-through to State's detachBuffer method, since
2586 // only buffer attachments to container objects that are bound to the current context
2587 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002588
Yuly Novikov5807a532015-12-03 13:01:22 -05002589 // [OpenGL ES 3.2] section 5.1.2 page 45:
2590 // Attachments to unbound container objects, such as
2591 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2592 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002593 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594}
2595
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002596void Context::detachFramebuffer(GLuint framebuffer)
2597{
Shannon Woods53a94a82014-06-24 15:20:36 -04002598 // Framebuffer detachment is handled by Context, because 0 is a valid
2599 // Framebuffer object, and a pointer to it must be passed from Context
2600 // to State at binding time.
2601
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002602 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002603 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2604 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2605 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002606
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002607 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 {
2609 bindReadFramebuffer(0);
2610 }
2611
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002612 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613 {
2614 bindDrawFramebuffer(0);
2615 }
2616}
2617
2618void Context::detachRenderbuffer(GLuint renderbuffer)
2619{
Jamie Madilla02315b2017-02-23 14:14:47 -05002620 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621}
2622
Jamie Madill57a89722013-07-02 11:57:03 -04002623void Context::detachVertexArray(GLuint vertexArray)
2624{
Jamie Madill77a72f62015-04-14 11:18:32 -04002625 // Vertex array detachment is handled by Context, because 0 is a valid
2626 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002627 // binding time.
2628
Jamie Madill57a89722013-07-02 11:57:03 -04002629 // [OpenGL ES 3.0.2] section 2.10 page 43:
2630 // If a vertex array object that is currently bound is deleted, the binding
2631 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002632 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002633 {
2634 bindVertexArray(0);
2635 }
2636}
2637
Geoff Langc8058452014-02-03 12:04:11 -05002638void Context::detachTransformFeedback(GLuint transformFeedback)
2639{
Corentin Walleza2257da2016-04-19 16:43:12 -04002640 // Transform feedback detachment is handled by Context, because 0 is a valid
2641 // transform feedback, and a pointer to it must be passed from Context to State at
2642 // binding time.
2643
2644 // The OpenGL specification doesn't mention what should happen when the currently bound
2645 // transform feedback object is deleted. Since it is a container object, we treat it like
2646 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002647 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002648 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002649 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002650 }
Geoff Langc8058452014-02-03 12:04:11 -05002651}
2652
Jamie Madilldc356042013-07-19 16:36:57 -04002653void Context::detachSampler(GLuint sampler)
2654{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002655 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002656}
2657
Yunchao Hea336b902017-08-02 16:05:21 +08002658void Context::detachProgramPipeline(GLuint pipeline)
2659{
2660 mGLState.detachProgramPipeline(this, pipeline);
2661}
2662
Jamie Madill3ef140a2017-08-26 23:11:21 -04002663void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664{
Shaodde78e82017-05-22 14:13:27 +08002665 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666}
2667
Jamie Madille29d1672013-07-19 16:36:57 -04002668void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2669{
Geoff Langc1984ed2016-10-07 12:41:00 -04002670 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002671 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002672 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002673 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002674}
Jamie Madille29d1672013-07-19 16:36:57 -04002675
Geoff Langc1984ed2016-10-07 12:41:00 -04002676void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2677{
2678 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002679 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002680 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002681 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002682}
2683
Brandon Jones59770802018-04-02 13:18:42 -07002684void Context::samplerParameterivRobust(GLuint sampler,
2685 GLenum pname,
2686 GLsizei bufSize,
2687 const GLint *param)
2688{
2689 samplerParameteriv(sampler, pname, param);
2690}
2691
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002692void Context::samplerParameterIivRobust(GLuint sampler,
2693 GLenum pname,
2694 GLsizei bufSize,
2695 const GLint *param)
2696{
2697 UNIMPLEMENTED();
2698}
2699
2700void Context::samplerParameterIuivRobust(GLuint sampler,
2701 GLenum pname,
2702 GLsizei bufSize,
2703 const GLuint *param)
2704{
2705 UNIMPLEMENTED();
2706}
2707
Jamie Madille29d1672013-07-19 16:36:57 -04002708void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2709{
Geoff Langc1984ed2016-10-07 12:41:00 -04002710 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002711 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002712 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002713 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002714}
2715
Geoff Langc1984ed2016-10-07 12:41:00 -04002716void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002717{
Geoff Langc1984ed2016-10-07 12:41:00 -04002718 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002719 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002720 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002721 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002722}
2723
Brandon Jones59770802018-04-02 13:18:42 -07002724void Context::samplerParameterfvRobust(GLuint sampler,
2725 GLenum pname,
2726 GLsizei bufSize,
2727 const GLfloat *param)
2728{
2729 samplerParameterfv(sampler, pname, param);
2730}
2731
Geoff Langc1984ed2016-10-07 12:41:00 -04002732void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002733{
Geoff Langc1984ed2016-10-07 12:41:00 -04002734 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002735 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002736 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002737 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002738}
Jamie Madill9675b802013-07-19 16:36:59 -04002739
Brandon Jones59770802018-04-02 13:18:42 -07002740void Context::getSamplerParameterivRobust(GLuint sampler,
2741 GLenum pname,
2742 GLsizei bufSize,
2743 GLsizei *length,
2744 GLint *params)
2745{
2746 getSamplerParameteriv(sampler, pname, params);
2747}
2748
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002749void Context::getSamplerParameterIivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 GLsizei *length,
2753 GLint *params)
2754{
2755 UNIMPLEMENTED();
2756}
2757
2758void Context::getSamplerParameterIuivRobust(GLuint sampler,
2759 GLenum pname,
2760 GLsizei bufSize,
2761 GLsizei *length,
2762 GLuint *params)
2763{
2764 UNIMPLEMENTED();
2765}
2766
Geoff Langc1984ed2016-10-07 12:41:00 -04002767void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2768{
2769 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002770 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002771 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002772 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002773}
2774
Brandon Jones59770802018-04-02 13:18:42 -07002775void Context::getSamplerParameterfvRobust(GLuint sampler,
2776 GLenum pname,
2777 GLsizei bufSize,
2778 GLsizei *length,
2779 GLfloat *params)
2780{
2781 getSamplerParameterfv(sampler, pname, params);
2782}
2783
Olli Etuahof0fee072016-03-30 15:11:58 +03002784void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2785{
2786 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002787 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002788}
2789
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790void Context::initRendererString()
2791{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002792 std::ostringstream rendererString;
2793 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002794 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002795 rendererString << ")";
2796
Geoff Langcec35902014-04-16 10:52:36 -04002797 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798}
2799
Geoff Langc339c4e2016-11-29 10:37:36 -05002800void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801{
Geoff Langc339c4e2016-11-29 10:37:36 -05002802 const Version &clientVersion = getClientVersion();
2803
2804 std::ostringstream versionString;
2805 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2806 << ANGLE_VERSION_STRING << ")";
2807 mVersionString = MakeStaticString(versionString.str());
2808
2809 std::ostringstream shadingLanguageVersionString;
2810 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2811 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2812 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2813 << ")";
2814 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002815}
2816
Geoff Langcec35902014-04-16 10:52:36 -04002817void Context::initExtensionStrings()
2818{
Geoff Langc339c4e2016-11-29 10:37:36 -05002819 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2820 std::ostringstream combinedStringStream;
2821 std::copy(strings.begin(), strings.end(),
2822 std::ostream_iterator<const char *>(combinedStringStream, " "));
2823 return MakeStaticString(combinedStringStream.str());
2824 };
2825
2826 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002827 for (const auto &extensionString : mExtensions.getStrings())
2828 {
2829 mExtensionStrings.push_back(MakeStaticString(extensionString));
2830 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002831 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002832
Bryan Bernhart58806562017-01-05 13:09:31 -08002833 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2834
Geoff Langc339c4e2016-11-29 10:37:36 -05002835 mRequestableExtensionStrings.clear();
2836 for (const auto &extensionInfo : GetExtensionInfoMap())
2837 {
2838 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002839 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2840 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002841 {
2842 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2843 }
2844 }
2845 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002846}
2847
Geoff Langc339c4e2016-11-29 10:37:36 -05002848const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002849{
Geoff Langc339c4e2016-11-29 10:37:36 -05002850 switch (name)
2851 {
2852 case GL_VENDOR:
2853 return reinterpret_cast<const GLubyte *>("Google Inc.");
2854
2855 case GL_RENDERER:
2856 return reinterpret_cast<const GLubyte *>(mRendererString);
2857
2858 case GL_VERSION:
2859 return reinterpret_cast<const GLubyte *>(mVersionString);
2860
2861 case GL_SHADING_LANGUAGE_VERSION:
2862 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2863
2864 case GL_EXTENSIONS:
2865 return reinterpret_cast<const GLubyte *>(mExtensionString);
2866
2867 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2868 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2869
2870 default:
2871 UNREACHABLE();
2872 return nullptr;
2873 }
Geoff Langcec35902014-04-16 10:52:36 -04002874}
2875
Geoff Langc339c4e2016-11-29 10:37:36 -05002876const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002877{
Geoff Langc339c4e2016-11-29 10:37:36 -05002878 switch (name)
2879 {
2880 case GL_EXTENSIONS:
2881 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2882
2883 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2884 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2885
2886 default:
2887 UNREACHABLE();
2888 return nullptr;
2889 }
Geoff Langcec35902014-04-16 10:52:36 -04002890}
2891
2892size_t Context::getExtensionStringCount() const
2893{
2894 return mExtensionStrings.size();
2895}
2896
Geoff Lang111a99e2017-10-17 10:58:41 -04002897bool Context::isExtensionRequestable(const char *name)
2898{
2899 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2900 auto extension = extensionInfos.find(name);
2901
2902 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2903 return extension != extensionInfos.end() && extension->second.Requestable &&
2904 nativeExtensions.*(extension->second.ExtensionsMember);
2905}
2906
Geoff Langc339c4e2016-11-29 10:37:36 -05002907void Context::requestExtension(const char *name)
2908{
2909 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2910 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2911 const auto &extension = extensionInfos.at(name);
2912 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002913 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002914
2915 if (mExtensions.*(extension.ExtensionsMember))
2916 {
2917 // Extension already enabled
2918 return;
2919 }
2920
2921 mExtensions.*(extension.ExtensionsMember) = true;
2922 updateCaps();
2923 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002924
Jamie Madill2f348d22017-06-05 10:50:59 -04002925 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2926 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002927
Jamie Madill81c2e252017-09-09 23:32:46 -04002928 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2929 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002930 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002931 for (auto &zeroTexture : mZeroTextures)
2932 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002933 if (zeroTexture.get() != nullptr)
2934 {
2935 zeroTexture->signalDirty(this, InitState::Initialized);
2936 }
Geoff Lang9aded172017-04-05 11:07:56 -04002937 }
2938
2939 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002940}
2941
2942size_t Context::getRequestableExtensionStringCount() const
2943{
2944 return mRequestableExtensionStrings.size();
2945}
2946
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002947void Context::beginTransformFeedback(GLenum primitiveMode)
2948{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002949 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002950 ASSERT(transformFeedback != nullptr);
2951 ASSERT(!transformFeedback->isPaused());
2952
Jamie Madill6c1f6712017-02-14 19:08:04 -05002953 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002954}
2955
2956bool Context::hasActiveTransformFeedback(GLuint program) const
2957{
2958 for (auto pair : mTransformFeedbackMap)
2959 {
2960 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2961 {
2962 return true;
2963 }
2964 }
2965 return false;
2966}
2967
Geoff Langb433e872017-10-05 14:01:47 -04002968void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002969{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002970 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002971
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002972 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2973 if (getClientVersion() < Version(2, 0))
2974 {
2975 mCaps.maxMultitextureUnits = 4;
2976 mCaps.maxClipPlanes = 6;
2977 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07002978 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2979 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2980 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002981 }
2982
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002983 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002984
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002985 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002986
Geoff Langeb66a6e2016-10-31 13:06:12 -04002987 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002988 {
2989 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002990 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002991 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002992 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002993 mExtensions.multiview = false;
2994 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002995 }
2996
Jiawei Shao89be29a2017-11-06 14:36:45 +08002997 if (getClientVersion() < ES_3_1)
2998 {
2999 // Disable ES3.1+ extensions
3000 mExtensions.geometryShader = false;
3001 }
3002
Geoff Langeb66a6e2016-10-31 13:06:12 -04003003 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04003004 {
3005 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04003006 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04003007 }
3008
Jamie Madill00ed7a12016-05-19 13:13:38 -04003009 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04003010 mExtensions.bindUniformLocation = true;
3011 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04003012 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05003013 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003014 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04003015
3016 // Enable the no error extension if the context was created with the flag.
3017 mExtensions.noError = mSkipValidation;
3018
Corentin Wallezccab69d2017-01-27 16:57:15 -05003019 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05003020 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05003021
Geoff Lang70d0f492015-12-10 17:45:46 -05003022 // Explicitly enable GL_KHR_debug
3023 mExtensions.debug = true;
3024 mExtensions.maxDebugMessageLength = 1024;
3025 mExtensions.maxDebugLoggedMessages = 1024;
3026 mExtensions.maxDebugGroupStackDepth = 1024;
3027 mExtensions.maxLabelLength = 1024;
3028
Geoff Langff5b2d52016-09-07 11:32:23 -04003029 // Explicitly enable GL_ANGLE_robust_client_memory
3030 mExtensions.robustClientMemory = true;
3031
Jamie Madille08a1d32017-03-07 17:24:06 -05003032 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04003033 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05003034
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08003035 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3036 // supports it.
3037 mExtensions.robustBufferAccessBehavior =
3038 mRobustAccess && mExtensions.robustBufferAccessBehavior;
3039
Jamie Madillc43be722017-07-13 16:22:14 -04003040 // Enable the cache control query unconditionally.
3041 mExtensions.programCacheControl = true;
3042
Geoff Lang301d1612014-07-09 10:34:37 -04003043 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003044 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003045
Jamie Madill0f80ed82017-09-19 00:24:56 -04003046 if (getClientVersion() < ES_3_1)
3047 {
3048 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3049 }
3050 else
3051 {
3052 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3053 }
Geoff Lang301d1612014-07-09 10:34:37 -04003054
Jamie Madill0f80ed82017-09-19 00:24:56 -04003055 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
3056 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3057 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3058
3059 // Limit textures as well, so we can use fast bitsets with texture bindings.
3060 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3061 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3062 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003063
Jiawei Shaodb342272017-09-27 10:21:45 +08003064 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3065
Geoff Langc287ea62016-09-16 14:46:51 -04003066 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003067 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003068 for (const auto &extensionInfo : GetExtensionInfoMap())
3069 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003070 // If the user has requested that extensions start disabled and they are requestable,
3071 // disable them.
3072 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003073 {
3074 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3075 }
3076 }
3077
3078 // Generate texture caps
3079 updateCaps();
3080}
3081
3082void Context::updateCaps()
3083{
Geoff Lang900013c2014-07-07 11:32:19 -04003084 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003085 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003086
Jamie Madill7b62cf92017-11-02 15:20:49 -04003087 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003088 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003089 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003090 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003091
Geoff Lang0d8b7242015-09-09 14:56:53 -04003092 // Update the format caps based on the client version and extensions.
3093 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3094 // ES3.
3095 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003096 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003097 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003098 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003099 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003100 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003101
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003102 // OpenGL ES does not support multisampling with non-rendererable formats
3103 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003104 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003105 (getClientVersion() < ES_3_1 &&
3106 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003107 {
Geoff Langd87878e2014-09-19 15:42:59 -04003108 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003109 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003110 else
3111 {
3112 // We may have limited the max samples for some required renderbuffer formats due to
3113 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3114 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3115
3116 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3117 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3118 // exception of signed and unsigned integer formats."
3119 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3120 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3121 {
3122 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3123 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3124 }
3125
3126 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3127 if (getClientVersion() >= ES_3_1)
3128 {
3129 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3130 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3131 // the exception that the signed and unsigned integer formats are required only to
3132 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3133 // multisamples, which must be at least one."
3134 if (formatInfo.componentType == GL_INT ||
3135 formatInfo.componentType == GL_UNSIGNED_INT)
3136 {
3137 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3138 }
3139
3140 // GLES 3.1 section 19.3.1.
3141 if (formatCaps.texturable)
3142 {
3143 if (formatInfo.depthBits > 0)
3144 {
3145 mCaps.maxDepthTextureSamples =
3146 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3147 }
3148 else if (formatInfo.redBits > 0)
3149 {
3150 mCaps.maxColorTextureSamples =
3151 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3152 }
3153 }
3154 }
3155 }
Geoff Langd87878e2014-09-19 15:42:59 -04003156
3157 if (formatCaps.texturable && formatInfo.compressed)
3158 {
Geoff Langca271392017-04-05 12:30:00 -04003159 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003160 }
3161
Geoff Langca271392017-04-05 12:30:00 -04003162 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003163 }
Jamie Madill32447362017-06-28 14:53:52 -04003164
3165 // If program binary is disabled, blank out the memory cache pointer.
3166 if (!mImplementation->getNativeExtensions().getProgramBinary)
3167 {
3168 mMemoryProgramCache = nullptr;
3169 }
Corentin Walleze4477002017-12-01 14:39:58 -05003170
3171 // Compute which buffer types are allowed
3172 mValidBufferBindings.reset();
3173 mValidBufferBindings.set(BufferBinding::ElementArray);
3174 mValidBufferBindings.set(BufferBinding::Array);
3175
3176 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3177 {
3178 mValidBufferBindings.set(BufferBinding::PixelPack);
3179 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3180 }
3181
3182 if (getClientVersion() >= ES_3_0)
3183 {
3184 mValidBufferBindings.set(BufferBinding::CopyRead);
3185 mValidBufferBindings.set(BufferBinding::CopyWrite);
3186 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3187 mValidBufferBindings.set(BufferBinding::Uniform);
3188 }
3189
3190 if (getClientVersion() >= ES_3_1)
3191 {
3192 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3193 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3194 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3195 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3196 }
Geoff Lang493daf52014-07-03 13:38:44 -04003197}
3198
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003199void Context::initWorkarounds()
3200{
Jamie Madill761b02c2017-06-23 16:27:06 -04003201 // Apply back-end workarounds.
3202 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3203
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003204 // Lose the context upon out of memory error if the application is
3205 // expecting to watch for those events.
3206 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3207}
3208
Jamie Madill05b35b22017-10-03 09:01:44 -04003209Error Context::prepareForDraw()
3210{
Geoff Langa8cb2872018-03-09 16:09:40 -05003211 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003212
3213 if (isRobustResourceInitEnabled())
3214 {
3215 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3216 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3217 }
3218
Geoff Langa8cb2872018-03-09 16:09:40 -05003219 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003220 return NoError();
3221}
3222
3223Error Context::prepareForClear(GLbitfield mask)
3224{
Geoff Langa8cb2872018-03-09 16:09:40 -05003225 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003226 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003227 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003228 return NoError();
3229}
3230
3231Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3232{
Geoff Langa8cb2872018-03-09 16:09:40 -05003233 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003234 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3235 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003236 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003237 return NoError();
3238}
3239
Geoff Langa8cb2872018-03-09 16:09:40 -05003240Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003241{
Geoff Langa8cb2872018-03-09 16:09:40 -05003242 ANGLE_TRY(syncDirtyObjects());
3243 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003244 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003245}
3246
Geoff Langa8cb2872018-03-09 16:09:40 -05003247Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003248{
Geoff Langa8cb2872018-03-09 16:09:40 -05003249 ANGLE_TRY(syncDirtyObjects(objectMask));
3250 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003251 return NoError();
3252}
3253
Geoff Langa8cb2872018-03-09 16:09:40 -05003254Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003255{
3256 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3257 mImplementation->syncState(this, dirtyBits);
3258 mGLState.clearDirtyBits();
3259 return NoError();
3260}
3261
Geoff Langa8cb2872018-03-09 16:09:40 -05003262Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003264 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003265 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003266 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003267 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003268}
Jamie Madillc29968b2016-01-20 11:17:23 -05003269
Geoff Langa8cb2872018-03-09 16:09:40 -05003270Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003271{
3272 return mGLState.syncDirtyObjects(this);
3273}
3274
Geoff Langa8cb2872018-03-09 16:09:40 -05003275Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003276{
3277 return mGLState.syncDirtyObjects(this, objectMask);
3278}
3279
Jamie Madillc29968b2016-01-20 11:17:23 -05003280void Context::blitFramebuffer(GLint srcX0,
3281 GLint srcY0,
3282 GLint srcX1,
3283 GLint srcY1,
3284 GLint dstX0,
3285 GLint dstY0,
3286 GLint dstX1,
3287 GLint dstY1,
3288 GLbitfield mask,
3289 GLenum filter)
3290{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003291 if (mask == 0)
3292 {
3293 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3294 // buffers are copied.
3295 return;
3296 }
3297
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003298 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003299 ASSERT(drawFramebuffer);
3300
3301 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3302 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3303
Jamie Madillbc918e72018-03-08 09:47:21 -05003304 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003305
Jamie Madillc564c072017-06-01 12:45:42 -04003306 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003307}
Jamie Madillc29968b2016-01-20 11:17:23 -05003308
3309void Context::clear(GLbitfield mask)
3310{
Geoff Langd4fff502017-09-22 11:28:28 -04003311 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3312 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003313}
3314
3315void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3316{
Geoff Langd4fff502017-09-22 11:28:28 -04003317 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3318 ANGLE_CONTEXT_TRY(
3319 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003320}
3321
3322void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3323{
Geoff Langd4fff502017-09-22 11:28:28 -04003324 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3325 ANGLE_CONTEXT_TRY(
3326 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003327}
3328
3329void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3330{
Geoff Langd4fff502017-09-22 11:28:28 -04003331 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3332 ANGLE_CONTEXT_TRY(
3333 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003334}
3335
3336void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003338 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003339 ASSERT(framebufferObject);
3340
3341 // If a buffer is not present, the clear has no effect
3342 if (framebufferObject->getDepthbuffer() == nullptr &&
3343 framebufferObject->getStencilbuffer() == nullptr)
3344 {
3345 return;
3346 }
3347
Geoff Langd4fff502017-09-22 11:28:28 -04003348 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3349 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003350}
3351
3352void Context::readPixels(GLint x,
3353 GLint y,
3354 GLsizei width,
3355 GLsizei height,
3356 GLenum format,
3357 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003358 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003359{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003360 if (width == 0 || height == 0)
3361 {
3362 return;
3363 }
3364
Jamie Madillbc918e72018-03-08 09:47:21 -05003365 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003366
Jamie Madillb6664922017-07-25 12:55:04 -04003367 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3368 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003369
3370 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003371 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003372}
3373
Brandon Jones59770802018-04-02 13:18:42 -07003374void Context::readPixelsRobust(GLint x,
3375 GLint y,
3376 GLsizei width,
3377 GLsizei height,
3378 GLenum format,
3379 GLenum type,
3380 GLsizei bufSize,
3381 GLsizei *length,
3382 GLsizei *columns,
3383 GLsizei *rows,
3384 void *pixels)
3385{
3386 readPixels(x, y, width, height, format, type, pixels);
3387}
3388
3389void Context::readnPixelsRobust(GLint x,
3390 GLint y,
3391 GLsizei width,
3392 GLsizei height,
3393 GLenum format,
3394 GLenum type,
3395 GLsizei bufSize,
3396 GLsizei *length,
3397 GLsizei *columns,
3398 GLsizei *rows,
3399 void *data)
3400{
3401 readPixels(x, y, width, height, format, type, data);
3402}
3403
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003404void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003405 GLint level,
3406 GLenum internalformat,
3407 GLint x,
3408 GLint y,
3409 GLsizei width,
3410 GLsizei height,
3411 GLint border)
3412{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003413 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003414 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003415
Jamie Madillc29968b2016-01-20 11:17:23 -05003416 Rectangle sourceArea(x, y, width, height);
3417
Jamie Madill05b35b22017-10-03 09:01:44 -04003418 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003419 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003420 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003421}
3422
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003423void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003424 GLint level,
3425 GLint xoffset,
3426 GLint yoffset,
3427 GLint x,
3428 GLint y,
3429 GLsizei width,
3430 GLsizei height)
3431{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003432 if (width == 0 || height == 0)
3433 {
3434 return;
3435 }
3436
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003437 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003438 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003439
Jamie Madillc29968b2016-01-20 11:17:23 -05003440 Offset destOffset(xoffset, yoffset, 0);
3441 Rectangle sourceArea(x, y, width, height);
3442
Jamie Madill05b35b22017-10-03 09:01:44 -04003443 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003444 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003445 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003446}
3447
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003448void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003449 GLint level,
3450 GLint xoffset,
3451 GLint yoffset,
3452 GLint zoffset,
3453 GLint x,
3454 GLint y,
3455 GLsizei width,
3456 GLsizei height)
3457{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003458 if (width == 0 || height == 0)
3459 {
3460 return;
3461 }
3462
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003463 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003464 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003465
Jamie Madillc29968b2016-01-20 11:17:23 -05003466 Offset destOffset(xoffset, yoffset, zoffset);
3467 Rectangle sourceArea(x, y, width, height);
3468
Jamie Madill05b35b22017-10-03 09:01:44 -04003469 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3470 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003471 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3472 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003473}
3474
3475void Context::framebufferTexture2D(GLenum target,
3476 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003477 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003478 GLuint texture,
3479 GLint level)
3480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003481 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003482 ASSERT(framebuffer);
3483
3484 if (texture != 0)
3485 {
3486 Texture *textureObj = getTexture(texture);
3487
3488 ImageIndex index = ImageIndex::MakeInvalid();
3489
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003490 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003491 {
3492 index = ImageIndex::Make2D(level);
3493 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003494 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003495 {
3496 index = ImageIndex::MakeRectangle(level);
3497 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003498 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003499 {
3500 ASSERT(level == 0);
3501 index = ImageIndex::Make2DMultisample();
3502 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003503 else
3504 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003505 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003506 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003507 }
3508
Jamie Madilla02315b2017-02-23 14:14:47 -05003509 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003510 }
3511 else
3512 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003513 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003514 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003515
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003517}
3518
3519void Context::framebufferRenderbuffer(GLenum target,
3520 GLenum attachment,
3521 GLenum renderbuffertarget,
3522 GLuint renderbuffer)
3523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003525 ASSERT(framebuffer);
3526
3527 if (renderbuffer != 0)
3528 {
3529 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003530
3531 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003532 renderbufferObject);
3533 }
3534 else
3535 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003536 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003537 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003538
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003539 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003540}
3541
3542void Context::framebufferTextureLayer(GLenum target,
3543 GLenum attachment,
3544 GLuint texture,
3545 GLint level,
3546 GLint layer)
3547{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003548 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003549 ASSERT(framebuffer);
3550
3551 if (texture != 0)
3552 {
3553 Texture *textureObject = getTexture(texture);
3554
3555 ImageIndex index = ImageIndex::MakeInvalid();
3556
Corentin Wallez99d492c2018-02-27 15:17:10 -05003557 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003558 {
3559 index = ImageIndex::Make3D(level, layer);
3560 }
3561 else
3562 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003563 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003564 index = ImageIndex::Make2DArray(level, layer);
3565 }
3566
Jamie Madilla02315b2017-02-23 14:14:47 -05003567 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003568 }
3569 else
3570 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003571 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003572 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003573
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003574 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003575}
3576
Brandon Jones59770802018-04-02 13:18:42 -07003577void Context::framebufferTextureMultiviewLayered(GLenum target,
3578 GLenum attachment,
3579 GLuint texture,
3580 GLint level,
3581 GLint baseViewIndex,
3582 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003583{
Martin Radev82ef7742017-08-08 17:44:58 +03003584 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3585 ASSERT(framebuffer);
3586
3587 if (texture != 0)
3588 {
3589 Texture *textureObj = getTexture(texture);
3590
Martin Radev18b75ba2017-08-15 15:50:40 +03003591 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003592 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3593 numViews, baseViewIndex);
3594 }
3595 else
3596 {
3597 framebuffer->resetAttachment(this, attachment);
3598 }
3599
3600 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003601}
3602
Brandon Jones59770802018-04-02 13:18:42 -07003603void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3604 GLenum attachment,
3605 GLuint texture,
3606 GLint level,
3607 GLsizei numViews,
3608 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003609{
Martin Radev5dae57b2017-07-14 16:15:55 +03003610 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3611 ASSERT(framebuffer);
3612
3613 if (texture != 0)
3614 {
3615 Texture *textureObj = getTexture(texture);
3616
3617 ImageIndex index = ImageIndex::Make2D(level);
3618 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3619 textureObj, numViews, viewportOffsets);
3620 }
3621 else
3622 {
3623 framebuffer->resetAttachment(this, attachment);
3624 }
3625
3626 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003627}
3628
Jamie Madillc29968b2016-01-20 11:17:23 -05003629void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003632 ASSERT(framebuffer);
3633 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003634 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003635}
3636
3637void Context::readBuffer(GLenum mode)
3638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003640 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003642}
3643
3644void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3645{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003646 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003647 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003648
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003649 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003650 ASSERT(framebuffer);
3651
3652 // The specification isn't clear what should be done when the framebuffer isn't complete.
3653 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003654 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003655}
3656
3657void Context::invalidateFramebuffer(GLenum target,
3658 GLsizei numAttachments,
3659 const GLenum *attachments)
3660{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003662 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003663
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003665 ASSERT(framebuffer);
3666
Jamie Madille98b1b52018-03-08 09:47:23 -05003667 bool complete = false;
3668 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3669 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 {
Jamie Madill437fa652016-05-03 15:13:24 -04003671 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003672 }
Jamie Madill437fa652016-05-03 15:13:24 -04003673
Jamie Madill4928b7c2017-06-20 12:57:39 -04003674 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003675}
3676
3677void Context::invalidateSubFramebuffer(GLenum target,
3678 GLsizei numAttachments,
3679 const GLenum *attachments,
3680 GLint x,
3681 GLint y,
3682 GLsizei width,
3683 GLsizei height)
3684{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003686 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003687
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 ASSERT(framebuffer);
3690
Jamie Madille98b1b52018-03-08 09:47:23 -05003691 bool complete = false;
3692 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3693 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003694 {
Jamie Madill437fa652016-05-03 15:13:24 -04003695 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 }
Jamie Madill437fa652016-05-03 15:13:24 -04003697
3698 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003699 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003700}
3701
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003702void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003703 GLint level,
3704 GLint internalformat,
3705 GLsizei width,
3706 GLsizei height,
3707 GLint border,
3708 GLenum format,
3709 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003710 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003711{
Jamie Madillbc918e72018-03-08 09:47:21 -05003712 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003713
3714 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003715 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003716 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3717 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003718}
3719
Brandon Jones59770802018-04-02 13:18:42 -07003720void Context::texImage2DRobust(TextureTarget target,
3721 GLint level,
3722 GLint internalformat,
3723 GLsizei width,
3724 GLsizei height,
3725 GLint border,
3726 GLenum format,
3727 GLenum type,
3728 GLsizei bufSize,
3729 const void *pixels)
3730{
3731 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3732}
3733
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003734void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003735 GLint level,
3736 GLint internalformat,
3737 GLsizei width,
3738 GLsizei height,
3739 GLsizei depth,
3740 GLint border,
3741 GLenum format,
3742 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003743 const void *pixels)
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, depth);
3748 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003749 handleError(texture->setImage(this, mGLState.getUnpackState(),
3750 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3751 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003752}
3753
Brandon Jones59770802018-04-02 13:18:42 -07003754void Context::texImage3DRobust(TextureType target,
3755 GLint level,
3756 GLint internalformat,
3757 GLsizei width,
3758 GLsizei height,
3759 GLsizei depth,
3760 GLint border,
3761 GLenum format,
3762 GLenum type,
3763 GLsizei bufSize,
3764 const void *pixels)
3765{
3766 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3767}
3768
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003769void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003770 GLint level,
3771 GLint xoffset,
3772 GLint yoffset,
3773 GLsizei width,
3774 GLsizei height,
3775 GLenum format,
3776 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003777 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003778{
3779 // Zero sized uploads are valid but no-ops
3780 if (width == 0 || height == 0)
3781 {
3782 return;
3783 }
3784
Jamie Madillbc918e72018-03-08 09:47:21 -05003785 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003786
3787 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003788 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003789 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3790 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003791}
3792
Brandon Jones59770802018-04-02 13:18:42 -07003793void Context::texSubImage2DRobust(TextureTarget target,
3794 GLint level,
3795 GLint xoffset,
3796 GLint yoffset,
3797 GLsizei width,
3798 GLsizei height,
3799 GLenum format,
3800 GLenum type,
3801 GLsizei bufSize,
3802 const void *pixels)
3803{
3804 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3805}
3806
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003807void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003808 GLint level,
3809 GLint xoffset,
3810 GLint yoffset,
3811 GLint zoffset,
3812 GLsizei width,
3813 GLsizei height,
3814 GLsizei depth,
3815 GLenum format,
3816 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003817 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003818{
3819 // Zero sized uploads are valid but no-ops
3820 if (width == 0 || height == 0 || depth == 0)
3821 {
3822 return;
3823 }
3824
Jamie Madillbc918e72018-03-08 09:47:21 -05003825 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003826
3827 Box area(xoffset, yoffset, zoffset, width, height, depth);
3828 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003829 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3830 NonCubeTextureTypeToTarget(target), level, area, format, type,
3831 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003832}
3833
Brandon Jones59770802018-04-02 13:18:42 -07003834void Context::texSubImage3DRobust(TextureType target,
3835 GLint level,
3836 GLint xoffset,
3837 GLint yoffset,
3838 GLint zoffset,
3839 GLsizei width,
3840 GLsizei height,
3841 GLsizei depth,
3842 GLenum format,
3843 GLenum type,
3844 GLsizei bufSize,
3845 const void *pixels)
3846{
3847 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3848 pixels);
3849}
3850
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003851void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003852 GLint level,
3853 GLenum internalformat,
3854 GLsizei width,
3855 GLsizei height,
3856 GLint border,
3857 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003858 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003859{
Jamie Madillbc918e72018-03-08 09:47:21 -05003860 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003861
3862 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003863 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003864 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3865 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003866 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003867}
3868
Brandon Jones59770802018-04-02 13:18:42 -07003869void Context::compressedTexImage2DRobust(TextureTarget target,
3870 GLint level,
3871 GLenum internalformat,
3872 GLsizei width,
3873 GLsizei height,
3874 GLint border,
3875 GLsizei imageSize,
3876 GLsizei dataSize,
3877 const GLvoid *data)
3878{
3879 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3880}
3881
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003882void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003883 GLint level,
3884 GLenum internalformat,
3885 GLsizei width,
3886 GLsizei height,
3887 GLsizei depth,
3888 GLint border,
3889 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003890 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003891{
Jamie Madillbc918e72018-03-08 09:47:21 -05003892 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003893
3894 Extents size(width, height, depth);
3895 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003896 handleError(texture->setCompressedImage(
3897 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3898 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003899}
3900
Brandon Jones59770802018-04-02 13:18:42 -07003901void Context::compressedTexImage3DRobust(TextureType target,
3902 GLint level,
3903 GLenum internalformat,
3904 GLsizei width,
3905 GLsizei height,
3906 GLsizei depth,
3907 GLint border,
3908 GLsizei imageSize,
3909 GLsizei dataSize,
3910 const GLvoid *data)
3911{
3912 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3913 data);
3914}
3915
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003916void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003917 GLint level,
3918 GLint xoffset,
3919 GLint yoffset,
3920 GLsizei width,
3921 GLsizei height,
3922 GLenum format,
3923 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003924 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003925{
Jamie Madillbc918e72018-03-08 09:47:21 -05003926 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003927
3928 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003929 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003930 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3931 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003932 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003933}
3934
Brandon Jones59770802018-04-02 13:18:42 -07003935void Context::compressedTexSubImage2DRobust(TextureTarget target,
3936 GLint level,
3937 GLint xoffset,
3938 GLint yoffset,
3939 GLsizei width,
3940 GLsizei height,
3941 GLenum format,
3942 GLsizei imageSize,
3943 GLsizei dataSize,
3944 const GLvoid *data)
3945{
3946 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3947 data);
3948}
3949
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003950void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003951 GLint level,
3952 GLint xoffset,
3953 GLint yoffset,
3954 GLint zoffset,
3955 GLsizei width,
3956 GLsizei height,
3957 GLsizei depth,
3958 GLenum format,
3959 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003960 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003961{
3962 // Zero sized uploads are valid but no-ops
3963 if (width == 0 || height == 0)
3964 {
3965 return;
3966 }
3967
Jamie Madillbc918e72018-03-08 09:47:21 -05003968 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003969
3970 Box area(xoffset, yoffset, zoffset, width, height, depth);
3971 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003972 handleError(texture->setCompressedSubImage(
3973 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3974 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003975}
3976
Brandon Jones59770802018-04-02 13:18:42 -07003977void Context::compressedTexSubImage3DRobust(TextureType target,
3978 GLint level,
3979 GLint xoffset,
3980 GLint yoffset,
3981 GLint zoffset,
3982 GLsizei width,
3983 GLsizei height,
3984 GLsizei depth,
3985 GLenum format,
3986 GLsizei imageSize,
3987 GLsizei dataSize,
3988 const GLvoid *data)
3989{
3990 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
3991 imageSize, data);
3992}
3993
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003994void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003995{
3996 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003997 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003998}
3999
Jamie Madill007530e2017-12-28 14:27:04 -05004000void Context::copyTexture(GLuint sourceId,
4001 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004002 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004003 GLuint destId,
4004 GLint destLevel,
4005 GLint internalFormat,
4006 GLenum destType,
4007 GLboolean unpackFlipY,
4008 GLboolean unpackPremultiplyAlpha,
4009 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004010{
Jamie Madillbc918e72018-03-08 09:47:21 -05004011 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004012
4013 gl::Texture *sourceTexture = getTexture(sourceId);
4014 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004015 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4016 sourceLevel, ConvertToBool(unpackFlipY),
4017 ConvertToBool(unpackPremultiplyAlpha),
4018 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004019}
4020
Jamie Madill007530e2017-12-28 14:27:04 -05004021void Context::copySubTexture(GLuint sourceId,
4022 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004023 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004024 GLuint destId,
4025 GLint destLevel,
4026 GLint xoffset,
4027 GLint yoffset,
4028 GLint x,
4029 GLint y,
4030 GLsizei width,
4031 GLsizei height,
4032 GLboolean unpackFlipY,
4033 GLboolean unpackPremultiplyAlpha,
4034 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004035{
4036 // Zero sized copies are valid but no-ops
4037 if (width == 0 || height == 0)
4038 {
4039 return;
4040 }
4041
Jamie Madillbc918e72018-03-08 09:47:21 -05004042 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004043
4044 gl::Texture *sourceTexture = getTexture(sourceId);
4045 gl::Texture *destTexture = getTexture(destId);
4046 Offset offset(xoffset, yoffset, 0);
4047 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004048 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4049 ConvertToBool(unpackFlipY),
4050 ConvertToBool(unpackPremultiplyAlpha),
4051 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004052}
4053
Jamie Madill007530e2017-12-28 14:27:04 -05004054void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004055{
Jamie Madillbc918e72018-03-08 09:47:21 -05004056 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004057
4058 gl::Texture *sourceTexture = getTexture(sourceId);
4059 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004060 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004061}
4062
Corentin Wallez336129f2017-10-17 15:55:40 -04004063void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004064{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004065 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004066 ASSERT(buffer);
4067
Geoff Lang496c02d2016-10-20 11:38:11 -07004068 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004069}
4070
Brandon Jones59770802018-04-02 13:18:42 -07004071void Context::getBufferPointervRobust(BufferBinding target,
4072 GLenum pname,
4073 GLsizei bufSize,
4074 GLsizei *length,
4075 void **params)
4076{
4077 getBufferPointerv(target, pname, params);
4078}
4079
Corentin Wallez336129f2017-10-17 15:55:40 -04004080void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004081{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004082 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004083 ASSERT(buffer);
4084
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004085 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004086 if (error.isError())
4087 {
Jamie Madill437fa652016-05-03 15:13:24 -04004088 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004089 return nullptr;
4090 }
4091
4092 return buffer->getMapPointer();
4093}
4094
Corentin Wallez336129f2017-10-17 15:55:40 -04004095GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004096{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004097 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004098 ASSERT(buffer);
4099
4100 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004101 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004102 if (error.isError())
4103 {
Jamie Madill437fa652016-05-03 15:13:24 -04004104 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004105 return GL_FALSE;
4106 }
4107
4108 return result;
4109}
4110
Corentin Wallez336129f2017-10-17 15:55:40 -04004111void *Context::mapBufferRange(BufferBinding target,
4112 GLintptr offset,
4113 GLsizeiptr length,
4114 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004115{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004116 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004117 ASSERT(buffer);
4118
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004119 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004120 if (error.isError())
4121 {
Jamie Madill437fa652016-05-03 15:13:24 -04004122 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004123 return nullptr;
4124 }
4125
4126 return buffer->getMapPointer();
4127}
4128
Corentin Wallez336129f2017-10-17 15:55:40 -04004129void Context::flushMappedBufferRange(BufferBinding /*target*/,
4130 GLintptr /*offset*/,
4131 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004132{
4133 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4134}
4135
Jamie Madillbc918e72018-03-08 09:47:21 -05004136Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004137{
Geoff Langa8cb2872018-03-09 16:09:40 -05004138 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004139}
4140
Jamie Madillbc918e72018-03-08 09:47:21 -05004141Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004142{
Geoff Langa8cb2872018-03-09 16:09:40 -05004143 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004144}
4145
Jamie Madillbc918e72018-03-08 09:47:21 -05004146Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004147{
Geoff Langa8cb2872018-03-09 16:09:40 -05004148 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004149}
4150
Jiajia Qin5451d532017-11-16 17:16:34 +08004151void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4152{
4153 UNIMPLEMENTED();
4154}
4155
Jamie Madillc20ab272016-06-09 07:20:46 -07004156void Context::activeTexture(GLenum texture)
4157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004158 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004159}
4160
Jamie Madill876429b2017-04-20 15:46:24 -04004161void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004162{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004163 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004164}
4165
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004166void Context::blendEquation(GLenum mode)
4167{
4168 mGLState.setBlendEquation(mode, mode);
4169}
4170
Jamie Madillc20ab272016-06-09 07:20:46 -07004171void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4172{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004173 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004174}
4175
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004176void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4177{
4178 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4179}
4180
Jamie Madillc20ab272016-06-09 07:20:46 -07004181void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4182{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004183 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004184}
4185
Jamie Madill876429b2017-04-20 15:46:24 -04004186void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004187{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004188 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004189}
4190
Jamie Madill876429b2017-04-20 15:46:24 -04004191void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004192{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004193 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004194}
4195
4196void Context::clearStencil(GLint s)
4197{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004198 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004199}
4200
4201void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4202{
Geoff Lang92019432017-11-20 13:09:34 -05004203 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4204 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004205}
4206
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004207void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004208{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004209 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004210}
4211
4212void Context::depthFunc(GLenum func)
4213{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004214 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004215}
4216
4217void Context::depthMask(GLboolean flag)
4218{
Geoff Lang92019432017-11-20 13:09:34 -05004219 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004220}
4221
Jamie Madill876429b2017-04-20 15:46:24 -04004222void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004224 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004225}
4226
4227void Context::disable(GLenum cap)
4228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004229 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004230}
4231
4232void Context::disableVertexAttribArray(GLuint index)
4233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004234 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004235}
4236
4237void Context::enable(GLenum cap)
4238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
4242void Context::enableVertexAttribArray(GLuint index)
4243{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004244 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004245}
4246
4247void Context::frontFace(GLenum mode)
4248{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004249 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004250}
4251
4252void Context::hint(GLenum target, GLenum mode)
4253{
4254 switch (target)
4255 {
4256 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004257 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004258 break;
4259
4260 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004261 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004262 break;
4263
4264 default:
4265 UNREACHABLE();
4266 return;
4267 }
4268}
4269
4270void Context::lineWidth(GLfloat width)
4271{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004273}
4274
4275void Context::pixelStorei(GLenum pname, GLint param)
4276{
4277 switch (pname)
4278 {
4279 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004280 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004281 break;
4282
4283 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285 break;
4286
4287 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004288 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004289 break;
4290
4291 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004292 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004293 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004294 break;
4295
4296 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004297 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004298 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004299 break;
4300
4301 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004302 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004303 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004304 break;
4305
4306 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004307 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309 break;
4310
4311 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004312 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004314 break;
4315
4316 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004317 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004319 break;
4320
4321 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004322 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324 break;
4325
4326 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004327 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329 break;
4330
4331 default:
4332 UNREACHABLE();
4333 return;
4334 }
4335}
4336
4337void Context::polygonOffset(GLfloat factor, GLfloat units)
4338{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340}
4341
Jamie Madill876429b2017-04-20 15:46:24 -04004342void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004343{
Geoff Lang92019432017-11-20 13:09:34 -05004344 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004345}
4346
Jiawei Shaodb342272017-09-27 10:21:45 +08004347void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4348{
4349 mGLState.setSampleMaskParams(maskNumber, mask);
4350}
4351
Jamie Madillc20ab272016-06-09 07:20:46 -07004352void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4353{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004354 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004355}
4356
4357void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4358{
4359 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4360 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362 }
4363
4364 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4365 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367 }
4368}
4369
4370void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4371{
4372 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4373 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004375 }
4376
4377 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4378 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380 }
4381}
4382
4383void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4384{
4385 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4386 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004388 }
4389
4390 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4391 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393 }
4394}
4395
4396void Context::vertexAttrib1f(GLuint index, GLfloat x)
4397{
4398 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
4402void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4403{
4404 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
4408void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4409{
4410 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
4414void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4415{
4416 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418}
4419
4420void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4421{
4422 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
4426void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4427{
4428 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
4432void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4433{
4434 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
4438void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
4443void Context::vertexAttribPointer(GLuint index,
4444 GLint size,
4445 GLenum type,
4446 GLboolean normalized,
4447 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004448 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004449{
Corentin Wallez336129f2017-10-17 15:55:40 -04004450 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004451 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
Shao80957d92017-02-20 21:25:59 +08004454void Context::vertexAttribFormat(GLuint attribIndex,
4455 GLint size,
4456 GLenum type,
4457 GLboolean normalized,
4458 GLuint relativeOffset)
4459{
Geoff Lang92019432017-11-20 13:09:34 -05004460 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004461 relativeOffset);
4462}
4463
4464void Context::vertexAttribIFormat(GLuint attribIndex,
4465 GLint size,
4466 GLenum type,
4467 GLuint relativeOffset)
4468{
4469 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4470}
4471
4472void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4473{
Shaodde78e82017-05-22 14:13:27 +08004474 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004475}
4476
Jiajia Qin5451d532017-11-16 17:16:34 +08004477void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004478{
4479 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4480}
4481
Jamie Madillc20ab272016-06-09 07:20:46 -07004482void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4483{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485}
4486
4487void Context::vertexAttribIPointer(GLuint index,
4488 GLint size,
4489 GLenum type,
4490 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004491 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004492{
Corentin Wallez336129f2017-10-17 15:55:40 -04004493 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4494 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004495}
4496
4497void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4498{
4499 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4504{
4505 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
4509void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004519void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4520{
4521 const VertexAttribCurrentValueData &currentValues =
4522 getGLState().getVertexAttribCurrentValue(index);
4523 const VertexArray *vao = getGLState().getVertexArray();
4524 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4525 currentValues, pname, params);
4526}
4527
Brandon Jones59770802018-04-02 13:18:42 -07004528void Context::getVertexAttribivRobust(GLuint index,
4529 GLenum pname,
4530 GLsizei bufSize,
4531 GLsizei *length,
4532 GLint *params)
4533{
4534 getVertexAttribiv(index, pname, params);
4535}
4536
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004537void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4538{
4539 const VertexAttribCurrentValueData &currentValues =
4540 getGLState().getVertexAttribCurrentValue(index);
4541 const VertexArray *vao = getGLState().getVertexArray();
4542 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4543 currentValues, pname, params);
4544}
4545
Brandon Jones59770802018-04-02 13:18:42 -07004546void Context::getVertexAttribfvRobust(GLuint index,
4547 GLenum pname,
4548 GLsizei bufSize,
4549 GLsizei *length,
4550 GLfloat *params)
4551{
4552 getVertexAttribfv(index, pname, params);
4553}
4554
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004555void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4556{
4557 const VertexAttribCurrentValueData &currentValues =
4558 getGLState().getVertexAttribCurrentValue(index);
4559 const VertexArray *vao = getGLState().getVertexArray();
4560 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4561 currentValues, pname, params);
4562}
4563
Brandon Jones59770802018-04-02 13:18:42 -07004564void Context::getVertexAttribIivRobust(GLuint index,
4565 GLenum pname,
4566 GLsizei bufSize,
4567 GLsizei *length,
4568 GLint *params)
4569{
4570 getVertexAttribIiv(index, pname, params);
4571}
4572
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004573void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4574{
4575 const VertexAttribCurrentValueData &currentValues =
4576 getGLState().getVertexAttribCurrentValue(index);
4577 const VertexArray *vao = getGLState().getVertexArray();
4578 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4579 currentValues, pname, params);
4580}
4581
Brandon Jones59770802018-04-02 13:18:42 -07004582void Context::getVertexAttribIuivRobust(GLuint index,
4583 GLenum pname,
4584 GLsizei bufSize,
4585 GLsizei *length,
4586 GLuint *params)
4587{
4588 getVertexAttribIuiv(index, pname, params);
4589}
4590
Jamie Madill876429b2017-04-20 15:46:24 -04004591void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004592{
4593 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4594 QueryVertexAttribPointerv(attrib, pname, pointer);
4595}
4596
Brandon Jones59770802018-04-02 13:18:42 -07004597void Context::getVertexAttribPointervRobust(GLuint index,
4598 GLenum pname,
4599 GLsizei bufSize,
4600 GLsizei *length,
4601 void **pointer)
4602{
4603 getVertexAttribPointerv(index, pname, pointer);
4604}
4605
Jamie Madillc20ab272016-06-09 07:20:46 -07004606void Context::debugMessageControl(GLenum source,
4607 GLenum type,
4608 GLenum severity,
4609 GLsizei count,
4610 const GLuint *ids,
4611 GLboolean enabled)
4612{
4613 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004614 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004615 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004616}
4617
4618void Context::debugMessageInsert(GLenum source,
4619 GLenum type,
4620 GLuint id,
4621 GLenum severity,
4622 GLsizei length,
4623 const GLchar *buf)
4624{
4625 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004626 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004627}
4628
4629void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004631 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004632}
4633
4634GLuint Context::getDebugMessageLog(GLuint count,
4635 GLsizei bufSize,
4636 GLenum *sources,
4637 GLenum *types,
4638 GLuint *ids,
4639 GLenum *severities,
4640 GLsizei *lengths,
4641 GLchar *messageLog)
4642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4644 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004645}
4646
4647void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4648{
4649 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004651 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::popDebugGroup()
4655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004656 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004657 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004658}
4659
Corentin Wallez336129f2017-10-17 15:55:40 -04004660void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004661{
4662 Buffer *buffer = mGLState.getTargetBuffer(target);
4663 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004664 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004665}
4666
Corentin Wallez336129f2017-10-17 15:55:40 -04004667void Context::bufferSubData(BufferBinding target,
4668 GLintptr offset,
4669 GLsizeiptr size,
4670 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004671{
4672 if (data == nullptr)
4673 {
4674 return;
4675 }
4676
4677 Buffer *buffer = mGLState.getTargetBuffer(target);
4678 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004679 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004680}
4681
Jamie Madillef300b12016-10-07 15:12:09 -04004682void Context::attachShader(GLuint program, GLuint shader)
4683{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004684 Program *programObject = mState.mShaderPrograms->getProgram(program);
4685 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004686 ASSERT(programObject && shaderObject);
4687 programObject->attachShader(shaderObject);
4688}
4689
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004690const Workarounds &Context::getWorkarounds() const
4691{
4692 return mWorkarounds;
4693}
4694
Corentin Wallez336129f2017-10-17 15:55:40 -04004695void Context::copyBufferSubData(BufferBinding readTarget,
4696 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004697 GLintptr readOffset,
4698 GLintptr writeOffset,
4699 GLsizeiptr size)
4700{
4701 // if size is zero, the copy is a successful no-op
4702 if (size == 0)
4703 {
4704 return;
4705 }
4706
4707 // TODO(jmadill): cache these.
4708 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4709 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4710
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004711 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004712}
4713
Jamie Madill01a80ee2016-11-07 12:06:18 -05004714void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4715{
4716 Program *programObject = getProgram(program);
4717 // TODO(jmadill): Re-use this from the validation if possible.
4718 ASSERT(programObject);
4719 programObject->bindAttributeLocation(index, name);
4720}
4721
Corentin Wallez336129f2017-10-17 15:55:40 -04004722void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004723{
Corentin Wallez336129f2017-10-17 15:55:40 -04004724 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4725 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004726}
4727
Corentin Wallez336129f2017-10-17 15:55:40 -04004728void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004729{
4730 bindBufferRange(target, index, buffer, 0, 0);
4731}
4732
Corentin Wallez336129f2017-10-17 15:55:40 -04004733void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004734 GLuint index,
4735 GLuint buffer,
4736 GLintptr offset,
4737 GLsizeiptr size)
4738{
Corentin Wallez336129f2017-10-17 15:55:40 -04004739 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4740 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004741}
4742
Jamie Madill01a80ee2016-11-07 12:06:18 -05004743void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4744{
4745 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4746 {
4747 bindReadFramebuffer(framebuffer);
4748 }
4749
4750 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4751 {
4752 bindDrawFramebuffer(framebuffer);
4753 }
4754}
4755
4756void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4757{
4758 ASSERT(target == GL_RENDERBUFFER);
4759 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004760 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004761 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004762}
4763
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004764void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004765 GLsizei samples,
4766 GLenum internalformat,
4767 GLsizei width,
4768 GLsizei height,
4769 GLboolean fixedsamplelocations)
4770{
4771 Extents size(width, height, 1);
4772 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004773 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4774 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004775}
4776
4777void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4778{
JiangYizhou5b03f472017-01-09 10:22:53 +08004779 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4780 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004781 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004782 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004783
4784 switch (pname)
4785 {
4786 case GL_SAMPLE_POSITION:
4787 handleError(framebuffer->getSamplePosition(index, val));
4788 break;
4789 default:
4790 UNREACHABLE();
4791 }
4792}
4793
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004794void Context::getMultisamplefvRobust(GLenum pname,
4795 GLuint index,
4796 GLsizei bufSize,
4797 GLsizei *length,
4798 GLfloat *val)
4799{
4800 UNIMPLEMENTED();
4801}
4802
Jamie Madille8fb6402017-02-14 17:56:40 -05004803void Context::renderbufferStorage(GLenum target,
4804 GLenum internalformat,
4805 GLsizei width,
4806 GLsizei height)
4807{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004808 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4809 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4810
Jamie Madille8fb6402017-02-14 17:56:40 -05004811 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004812 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004813}
4814
4815void Context::renderbufferStorageMultisample(GLenum target,
4816 GLsizei samples,
4817 GLenum internalformat,
4818 GLsizei width,
4819 GLsizei height)
4820{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004821 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4822 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004823
4824 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004825 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004826 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004827}
4828
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004829void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4830{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004831 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004832 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004833}
4834
JiangYizhoue18e6392017-02-20 10:32:23 +08004835void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4836{
4837 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4838 QueryFramebufferParameteriv(framebuffer, pname, params);
4839}
4840
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004841void Context::getFramebufferParameterivRobust(GLenum target,
4842 GLenum pname,
4843 GLsizei bufSize,
4844 GLsizei *length,
4845 GLint *params)
4846{
4847 UNIMPLEMENTED();
4848}
4849
Jiajia Qin5451d532017-11-16 17:16:34 +08004850void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004851{
4852 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4853 SetFramebufferParameteri(framebuffer, pname, param);
4854}
4855
Jamie Madillb3f26b92017-07-19 15:07:41 -04004856Error Context::getScratchBuffer(size_t requstedSizeBytes,
4857 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004858{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004859 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4860 {
4861 return OutOfMemory() << "Failed to allocate internal buffer.";
4862 }
4863 return NoError();
4864}
4865
4866Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4867 angle::MemoryBuffer **zeroBufferOut) const
4868{
4869 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004870 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004871 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004872 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004873 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004874}
4875
Xinghua Cao10a4d432017-11-28 14:46:26 +08004876Error Context::prepareForDispatch()
4877{
Geoff Langa8cb2872018-03-09 16:09:40 -05004878 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004879
4880 if (isRobustResourceInitEnabled())
4881 {
4882 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4883 }
4884
4885 return NoError();
4886}
4887
Xinghua Cao2b396592017-03-29 15:36:04 +08004888void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4889{
4890 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4891 {
4892 return;
4893 }
4894
Xinghua Cao10a4d432017-11-28 14:46:26 +08004895 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004896 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004897}
4898
Jiajia Qin5451d532017-11-16 17:16:34 +08004899void Context::dispatchComputeIndirect(GLintptr indirect)
4900{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004901 ANGLE_CONTEXT_TRY(prepareForDispatch());
4902 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004903}
4904
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004905void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004906 GLsizei levels,
4907 GLenum internalFormat,
4908 GLsizei width,
4909 GLsizei height)
4910{
4911 Extents size(width, height, 1);
4912 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004913 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004914}
4915
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004916void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004917 GLsizei levels,
4918 GLenum internalFormat,
4919 GLsizei width,
4920 GLsizei height,
4921 GLsizei depth)
4922{
4923 Extents size(width, height, depth);
4924 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004925 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004926}
4927
Jiajia Qin5451d532017-11-16 17:16:34 +08004928void Context::memoryBarrier(GLbitfield barriers)
4929{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004930 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004931}
4932
4933void Context::memoryBarrierByRegion(GLbitfield barriers)
4934{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004935 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004936}
4937
Jamie Madillc1d770e2017-04-13 17:31:24 -04004938GLenum Context::checkFramebufferStatus(GLenum target)
4939{
4940 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4941 ASSERT(framebuffer);
4942
Jamie Madille98b1b52018-03-08 09:47:23 -05004943 GLenum status = GL_NONE;
4944 Error err = framebuffer->checkStatus(this, &status);
4945 if (err.isError())
4946 {
4947 handleError(err);
4948 return 0;
4949 }
4950 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004951}
4952
4953void Context::compileShader(GLuint shader)
4954{
4955 Shader *shaderObject = GetValidShader(this, shader);
4956 if (!shaderObject)
4957 {
4958 return;
4959 }
4960 shaderObject->compile(this);
4961}
4962
4963void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4964{
4965 for (int i = 0; i < n; i++)
4966 {
4967 deleteBuffer(buffers[i]);
4968 }
4969}
4970
4971void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4972{
4973 for (int i = 0; i < n; i++)
4974 {
4975 if (framebuffers[i] != 0)
4976 {
4977 deleteFramebuffer(framebuffers[i]);
4978 }
4979 }
4980}
4981
4982void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4983{
4984 for (int i = 0; i < n; i++)
4985 {
4986 deleteRenderbuffer(renderbuffers[i]);
4987 }
4988}
4989
4990void Context::deleteTextures(GLsizei n, const GLuint *textures)
4991{
4992 for (int i = 0; i < n; i++)
4993 {
4994 if (textures[i] != 0)
4995 {
4996 deleteTexture(textures[i]);
4997 }
4998 }
4999}
5000
5001void Context::detachShader(GLuint program, GLuint shader)
5002{
5003 Program *programObject = getProgram(program);
5004 ASSERT(programObject);
5005
5006 Shader *shaderObject = getShader(shader);
5007 ASSERT(shaderObject);
5008
5009 programObject->detachShader(this, shaderObject);
5010}
5011
5012void Context::genBuffers(GLsizei n, GLuint *buffers)
5013{
5014 for (int i = 0; i < n; i++)
5015 {
5016 buffers[i] = createBuffer();
5017 }
5018}
5019
5020void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5021{
5022 for (int i = 0; i < n; i++)
5023 {
5024 framebuffers[i] = createFramebuffer();
5025 }
5026}
5027
5028void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5029{
5030 for (int i = 0; i < n; i++)
5031 {
5032 renderbuffers[i] = createRenderbuffer();
5033 }
5034}
5035
5036void Context::genTextures(GLsizei n, GLuint *textures)
5037{
5038 for (int i = 0; i < n; i++)
5039 {
5040 textures[i] = createTexture();
5041 }
5042}
5043
5044void Context::getActiveAttrib(GLuint program,
5045 GLuint index,
5046 GLsizei bufsize,
5047 GLsizei *length,
5048 GLint *size,
5049 GLenum *type,
5050 GLchar *name)
5051{
5052 Program *programObject = getProgram(program);
5053 ASSERT(programObject);
5054 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5055}
5056
5057void Context::getActiveUniform(GLuint program,
5058 GLuint index,
5059 GLsizei bufsize,
5060 GLsizei *length,
5061 GLint *size,
5062 GLenum *type,
5063 GLchar *name)
5064{
5065 Program *programObject = getProgram(program);
5066 ASSERT(programObject);
5067 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5068}
5069
5070void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5071{
5072 Program *programObject = getProgram(program);
5073 ASSERT(programObject);
5074 programObject->getAttachedShaders(maxcount, count, shaders);
5075}
5076
5077GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5078{
5079 Program *programObject = getProgram(program);
5080 ASSERT(programObject);
5081 return programObject->getAttributeLocation(name);
5082}
5083
5084void Context::getBooleanv(GLenum pname, GLboolean *params)
5085{
5086 GLenum nativeType;
5087 unsigned int numParams = 0;
5088 getQueryParameterInfo(pname, &nativeType, &numParams);
5089
5090 if (nativeType == GL_BOOL)
5091 {
5092 getBooleanvImpl(pname, params);
5093 }
5094 else
5095 {
5096 CastStateValues(this, nativeType, pname, numParams, params);
5097 }
5098}
5099
Brandon Jones59770802018-04-02 13:18:42 -07005100void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5101{
5102 getBooleanv(pname, params);
5103}
5104
Jamie Madillc1d770e2017-04-13 17:31:24 -04005105void Context::getFloatv(GLenum pname, GLfloat *params)
5106{
5107 GLenum nativeType;
5108 unsigned int numParams = 0;
5109 getQueryParameterInfo(pname, &nativeType, &numParams);
5110
5111 if (nativeType == GL_FLOAT)
5112 {
5113 getFloatvImpl(pname, params);
5114 }
5115 else
5116 {
5117 CastStateValues(this, nativeType, pname, numParams, params);
5118 }
5119}
5120
Brandon Jones59770802018-04-02 13:18:42 -07005121void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5122{
5123 getFloatv(pname, params);
5124}
5125
Jamie Madillc1d770e2017-04-13 17:31:24 -04005126void Context::getIntegerv(GLenum pname, GLint *params)
5127{
5128 GLenum nativeType;
5129 unsigned int numParams = 0;
5130 getQueryParameterInfo(pname, &nativeType, &numParams);
5131
5132 if (nativeType == GL_INT)
5133 {
5134 getIntegervImpl(pname, params);
5135 }
5136 else
5137 {
5138 CastStateValues(this, nativeType, pname, numParams, params);
5139 }
5140}
5141
Brandon Jones59770802018-04-02 13:18:42 -07005142void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5143{
5144 getIntegerv(pname, data);
5145}
5146
Jamie Madillc1d770e2017-04-13 17:31:24 -04005147void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5148{
5149 Program *programObject = getProgram(program);
5150 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005151 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005152}
5153
Brandon Jones59770802018-04-02 13:18:42 -07005154void Context::getProgramivRobust(GLuint program,
5155 GLenum pname,
5156 GLsizei bufSize,
5157 GLsizei *length,
5158 GLint *params)
5159{
5160 getProgramiv(program, pname, params);
5161}
5162
Jiajia Qin5451d532017-11-16 17:16:34 +08005163void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5164{
5165 UNIMPLEMENTED();
5166}
5167
Jamie Madillbe849e42017-05-02 15:49:00 -04005168void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005169{
5170 Program *programObject = getProgram(program);
5171 ASSERT(programObject);
5172 programObject->getInfoLog(bufsize, length, infolog);
5173}
5174
Jiajia Qin5451d532017-11-16 17:16:34 +08005175void Context::getProgramPipelineInfoLog(GLuint pipeline,
5176 GLsizei bufSize,
5177 GLsizei *length,
5178 GLchar *infoLog)
5179{
5180 UNIMPLEMENTED();
5181}
5182
Jamie Madillc1d770e2017-04-13 17:31:24 -04005183void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5184{
5185 Shader *shaderObject = getShader(shader);
5186 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005187 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005188}
5189
Brandon Jones59770802018-04-02 13:18:42 -07005190void Context::getShaderivRobust(GLuint shader,
5191 GLenum pname,
5192 GLsizei bufSize,
5193 GLsizei *length,
5194 GLint *params)
5195{
5196 getShaderiv(shader, pname, params);
5197}
5198
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5200{
5201 Shader *shaderObject = getShader(shader);
5202 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005203 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204}
5205
5206void Context::getShaderPrecisionFormat(GLenum shadertype,
5207 GLenum precisiontype,
5208 GLint *range,
5209 GLint *precision)
5210{
5211 // TODO(jmadill): Compute shaders.
5212
5213 switch (shadertype)
5214 {
5215 case GL_VERTEX_SHADER:
5216 switch (precisiontype)
5217 {
5218 case GL_LOW_FLOAT:
5219 mCaps.vertexLowpFloat.get(range, precision);
5220 break;
5221 case GL_MEDIUM_FLOAT:
5222 mCaps.vertexMediumpFloat.get(range, precision);
5223 break;
5224 case GL_HIGH_FLOAT:
5225 mCaps.vertexHighpFloat.get(range, precision);
5226 break;
5227
5228 case GL_LOW_INT:
5229 mCaps.vertexLowpInt.get(range, precision);
5230 break;
5231 case GL_MEDIUM_INT:
5232 mCaps.vertexMediumpInt.get(range, precision);
5233 break;
5234 case GL_HIGH_INT:
5235 mCaps.vertexHighpInt.get(range, precision);
5236 break;
5237
5238 default:
5239 UNREACHABLE();
5240 return;
5241 }
5242 break;
5243
5244 case GL_FRAGMENT_SHADER:
5245 switch (precisiontype)
5246 {
5247 case GL_LOW_FLOAT:
5248 mCaps.fragmentLowpFloat.get(range, precision);
5249 break;
5250 case GL_MEDIUM_FLOAT:
5251 mCaps.fragmentMediumpFloat.get(range, precision);
5252 break;
5253 case GL_HIGH_FLOAT:
5254 mCaps.fragmentHighpFloat.get(range, precision);
5255 break;
5256
5257 case GL_LOW_INT:
5258 mCaps.fragmentLowpInt.get(range, precision);
5259 break;
5260 case GL_MEDIUM_INT:
5261 mCaps.fragmentMediumpInt.get(range, precision);
5262 break;
5263 case GL_HIGH_INT:
5264 mCaps.fragmentHighpInt.get(range, precision);
5265 break;
5266
5267 default:
5268 UNREACHABLE();
5269 return;
5270 }
5271 break;
5272
5273 default:
5274 UNREACHABLE();
5275 return;
5276 }
5277}
5278
5279void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5280{
5281 Shader *shaderObject = getShader(shader);
5282 ASSERT(shaderObject);
5283 shaderObject->getSource(bufsize, length, source);
5284}
5285
5286void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5287{
5288 Program *programObject = getProgram(program);
5289 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005290 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005291}
5292
Brandon Jones59770802018-04-02 13:18:42 -07005293void Context::getUniformfvRobust(GLuint program,
5294 GLint location,
5295 GLsizei bufSize,
5296 GLsizei *length,
5297 GLfloat *params)
5298{
5299 getUniformfv(program, location, params);
5300}
5301
Jamie Madillc1d770e2017-04-13 17:31:24 -04005302void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5303{
5304 Program *programObject = getProgram(program);
5305 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005306 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005307}
5308
Brandon Jones59770802018-04-02 13:18:42 -07005309void Context::getUniformivRobust(GLuint program,
5310 GLint location,
5311 GLsizei bufSize,
5312 GLsizei *length,
5313 GLint *params)
5314{
5315 getUniformiv(program, location, params);
5316}
5317
Jamie Madillc1d770e2017-04-13 17:31:24 -04005318GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5319{
5320 Program *programObject = getProgram(program);
5321 ASSERT(programObject);
5322 return programObject->getUniformLocation(name);
5323}
5324
5325GLboolean Context::isBuffer(GLuint buffer)
5326{
5327 if (buffer == 0)
5328 {
5329 return GL_FALSE;
5330 }
5331
5332 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5333}
5334
5335GLboolean Context::isEnabled(GLenum cap)
5336{
5337 return mGLState.getEnableFeature(cap);
5338}
5339
5340GLboolean Context::isFramebuffer(GLuint framebuffer)
5341{
5342 if (framebuffer == 0)
5343 {
5344 return GL_FALSE;
5345 }
5346
5347 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5348}
5349
5350GLboolean Context::isProgram(GLuint program)
5351{
5352 if (program == 0)
5353 {
5354 return GL_FALSE;
5355 }
5356
5357 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5358}
5359
5360GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5361{
5362 if (renderbuffer == 0)
5363 {
5364 return GL_FALSE;
5365 }
5366
5367 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5368}
5369
5370GLboolean Context::isShader(GLuint shader)
5371{
5372 if (shader == 0)
5373 {
5374 return GL_FALSE;
5375 }
5376
5377 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5378}
5379
5380GLboolean Context::isTexture(GLuint texture)
5381{
5382 if (texture == 0)
5383 {
5384 return GL_FALSE;
5385 }
5386
5387 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5388}
5389
5390void Context::linkProgram(GLuint program)
5391{
5392 Program *programObject = getProgram(program);
5393 ASSERT(programObject);
5394 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005395 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005396}
5397
5398void Context::releaseShaderCompiler()
5399{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005400 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005401}
5402
5403void Context::shaderBinary(GLsizei n,
5404 const GLuint *shaders,
5405 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005406 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005407 GLsizei length)
5408{
5409 // No binary shader formats are supported.
5410 UNIMPLEMENTED();
5411}
5412
5413void Context::shaderSource(GLuint shader,
5414 GLsizei count,
5415 const GLchar *const *string,
5416 const GLint *length)
5417{
5418 Shader *shaderObject = getShader(shader);
5419 ASSERT(shaderObject);
5420 shaderObject->setSource(count, string, length);
5421}
5422
5423void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5424{
5425 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5426}
5427
5428void Context::stencilMask(GLuint mask)
5429{
5430 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5431}
5432
5433void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5434{
5435 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5436}
5437
5438void Context::uniform1f(GLint location, GLfloat x)
5439{
5440 Program *program = mGLState.getProgram();
5441 program->setUniform1fv(location, 1, &x);
5442}
5443
5444void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5445{
5446 Program *program = mGLState.getProgram();
5447 program->setUniform1fv(location, count, v);
5448}
5449
5450void Context::uniform1i(GLint location, GLint x)
5451{
5452 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005453 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5454 {
5455 mGLState.setObjectDirty(GL_PROGRAM);
5456 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457}
5458
5459void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5460{
5461 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005462 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5463 {
5464 mGLState.setObjectDirty(GL_PROGRAM);
5465 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466}
5467
5468void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5469{
5470 GLfloat xy[2] = {x, y};
5471 Program *program = mGLState.getProgram();
5472 program->setUniform2fv(location, 1, xy);
5473}
5474
5475void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5476{
5477 Program *program = mGLState.getProgram();
5478 program->setUniform2fv(location, count, v);
5479}
5480
5481void Context::uniform2i(GLint location, GLint x, GLint y)
5482{
5483 GLint xy[2] = {x, y};
5484 Program *program = mGLState.getProgram();
5485 program->setUniform2iv(location, 1, xy);
5486}
5487
5488void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5489{
5490 Program *program = mGLState.getProgram();
5491 program->setUniform2iv(location, count, v);
5492}
5493
5494void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5495{
5496 GLfloat xyz[3] = {x, y, z};
5497 Program *program = mGLState.getProgram();
5498 program->setUniform3fv(location, 1, xyz);
5499}
5500
5501void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5502{
5503 Program *program = mGLState.getProgram();
5504 program->setUniform3fv(location, count, v);
5505}
5506
5507void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5508{
5509 GLint xyz[3] = {x, y, z};
5510 Program *program = mGLState.getProgram();
5511 program->setUniform3iv(location, 1, xyz);
5512}
5513
5514void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5515{
5516 Program *program = mGLState.getProgram();
5517 program->setUniform3iv(location, count, v);
5518}
5519
5520void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5521{
5522 GLfloat xyzw[4] = {x, y, z, w};
5523 Program *program = mGLState.getProgram();
5524 program->setUniform4fv(location, 1, xyzw);
5525}
5526
5527void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5528{
5529 Program *program = mGLState.getProgram();
5530 program->setUniform4fv(location, count, v);
5531}
5532
5533void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5534{
5535 GLint xyzw[4] = {x, y, z, w};
5536 Program *program = mGLState.getProgram();
5537 program->setUniform4iv(location, 1, xyzw);
5538}
5539
5540void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5541{
5542 Program *program = mGLState.getProgram();
5543 program->setUniform4iv(location, count, v);
5544}
5545
5546void Context::uniformMatrix2fv(GLint location,
5547 GLsizei count,
5548 GLboolean transpose,
5549 const GLfloat *value)
5550{
5551 Program *program = mGLState.getProgram();
5552 program->setUniformMatrix2fv(location, count, transpose, value);
5553}
5554
5555void Context::uniformMatrix3fv(GLint location,
5556 GLsizei count,
5557 GLboolean transpose,
5558 const GLfloat *value)
5559{
5560 Program *program = mGLState.getProgram();
5561 program->setUniformMatrix3fv(location, count, transpose, value);
5562}
5563
5564void Context::uniformMatrix4fv(GLint location,
5565 GLsizei count,
5566 GLboolean transpose,
5567 const GLfloat *value)
5568{
5569 Program *program = mGLState.getProgram();
5570 program->setUniformMatrix4fv(location, count, transpose, value);
5571}
5572
5573void Context::validateProgram(GLuint program)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject);
5577 programObject->validate(mCaps);
5578}
5579
Jiajia Qin5451d532017-11-16 17:16:34 +08005580void Context::validateProgramPipeline(GLuint pipeline)
5581{
5582 UNIMPLEMENTED();
5583}
5584
Jamie Madilld04908b2017-06-09 14:15:35 -04005585void Context::getProgramBinary(GLuint program,
5586 GLsizei bufSize,
5587 GLsizei *length,
5588 GLenum *binaryFormat,
5589 void *binary)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject != nullptr);
5593
5594 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5595}
5596
5597void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5598{
5599 Program *programObject = getProgram(program);
5600 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005601
Jamie Madilld04908b2017-06-09 14:15:35 -04005602 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5603}
5604
Jamie Madillff325f12017-08-26 15:06:05 -04005605void Context::uniform1ui(GLint location, GLuint v0)
5606{
5607 Program *program = mGLState.getProgram();
5608 program->setUniform1uiv(location, 1, &v0);
5609}
5610
5611void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5612{
5613 Program *program = mGLState.getProgram();
5614 const GLuint xy[] = {v0, v1};
5615 program->setUniform2uiv(location, 1, xy);
5616}
5617
5618void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5619{
5620 Program *program = mGLState.getProgram();
5621 const GLuint xyz[] = {v0, v1, v2};
5622 program->setUniform3uiv(location, 1, xyz);
5623}
5624
5625void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5626{
5627 Program *program = mGLState.getProgram();
5628 const GLuint xyzw[] = {v0, v1, v2, v3};
5629 program->setUniform4uiv(location, 1, xyzw);
5630}
5631
5632void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5633{
5634 Program *program = mGLState.getProgram();
5635 program->setUniform1uiv(location, count, value);
5636}
5637void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5638{
5639 Program *program = mGLState.getProgram();
5640 program->setUniform2uiv(location, count, value);
5641}
5642
5643void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5644{
5645 Program *program = mGLState.getProgram();
5646 program->setUniform3uiv(location, count, value);
5647}
5648
5649void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5650{
5651 Program *program = mGLState.getProgram();
5652 program->setUniform4uiv(location, count, value);
5653}
5654
Jamie Madillf0e04492017-08-26 15:28:42 -04005655void Context::genQueries(GLsizei n, GLuint *ids)
5656{
5657 for (GLsizei i = 0; i < n; i++)
5658 {
5659 GLuint handle = mQueryHandleAllocator.allocate();
5660 mQueryMap.assign(handle, nullptr);
5661 ids[i] = handle;
5662 }
5663}
5664
5665void Context::deleteQueries(GLsizei n, const GLuint *ids)
5666{
5667 for (int i = 0; i < n; i++)
5668 {
5669 GLuint query = ids[i];
5670
5671 Query *queryObject = nullptr;
5672 if (mQueryMap.erase(query, &queryObject))
5673 {
5674 mQueryHandleAllocator.release(query);
5675 if (queryObject)
5676 {
5677 queryObject->release(this);
5678 }
5679 }
5680 }
5681}
5682
5683GLboolean Context::isQuery(GLuint id)
5684{
5685 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5686}
5687
Jamie Madillc8c95812017-08-26 18:40:09 -04005688void Context::uniformMatrix2x3fv(GLint location,
5689 GLsizei count,
5690 GLboolean transpose,
5691 const GLfloat *value)
5692{
5693 Program *program = mGLState.getProgram();
5694 program->setUniformMatrix2x3fv(location, count, transpose, value);
5695}
5696
5697void Context::uniformMatrix3x2fv(GLint location,
5698 GLsizei count,
5699 GLboolean transpose,
5700 const GLfloat *value)
5701{
5702 Program *program = mGLState.getProgram();
5703 program->setUniformMatrix3x2fv(location, count, transpose, value);
5704}
5705
5706void Context::uniformMatrix2x4fv(GLint location,
5707 GLsizei count,
5708 GLboolean transpose,
5709 const GLfloat *value)
5710{
5711 Program *program = mGLState.getProgram();
5712 program->setUniformMatrix2x4fv(location, count, transpose, value);
5713}
5714
5715void Context::uniformMatrix4x2fv(GLint location,
5716 GLsizei count,
5717 GLboolean transpose,
5718 const GLfloat *value)
5719{
5720 Program *program = mGLState.getProgram();
5721 program->setUniformMatrix4x2fv(location, count, transpose, value);
5722}
5723
5724void Context::uniformMatrix3x4fv(GLint location,
5725 GLsizei count,
5726 GLboolean transpose,
5727 const GLfloat *value)
5728{
5729 Program *program = mGLState.getProgram();
5730 program->setUniformMatrix3x4fv(location, count, transpose, value);
5731}
5732
5733void Context::uniformMatrix4x3fv(GLint location,
5734 GLsizei count,
5735 GLboolean transpose,
5736 const GLfloat *value)
5737{
5738 Program *program = mGLState.getProgram();
5739 program->setUniformMatrix4x3fv(location, count, transpose, value);
5740}
5741
Jamie Madilld7576732017-08-26 18:49:50 -04005742void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5743{
5744 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5745 {
5746 GLuint vertexArray = arrays[arrayIndex];
5747
5748 if (arrays[arrayIndex] != 0)
5749 {
5750 VertexArray *vertexArrayObject = nullptr;
5751 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5752 {
5753 if (vertexArrayObject != nullptr)
5754 {
5755 detachVertexArray(vertexArray);
5756 vertexArrayObject->onDestroy(this);
5757 }
5758
5759 mVertexArrayHandleAllocator.release(vertexArray);
5760 }
5761 }
5762 }
5763}
5764
5765void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5766{
5767 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5768 {
5769 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5770 mVertexArrayMap.assign(vertexArray, nullptr);
5771 arrays[arrayIndex] = vertexArray;
5772 }
5773}
5774
5775bool Context::isVertexArray(GLuint array)
5776{
5777 if (array == 0)
5778 {
5779 return GL_FALSE;
5780 }
5781
5782 VertexArray *vao = getVertexArray(array);
5783 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5784}
5785
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005786void Context::endTransformFeedback()
5787{
5788 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5789 transformFeedback->end(this);
5790}
5791
5792void Context::transformFeedbackVaryings(GLuint program,
5793 GLsizei count,
5794 const GLchar *const *varyings,
5795 GLenum bufferMode)
5796{
5797 Program *programObject = getProgram(program);
5798 ASSERT(programObject);
5799 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5800}
5801
5802void Context::getTransformFeedbackVarying(GLuint program,
5803 GLuint index,
5804 GLsizei bufSize,
5805 GLsizei *length,
5806 GLsizei *size,
5807 GLenum *type,
5808 GLchar *name)
5809{
5810 Program *programObject = getProgram(program);
5811 ASSERT(programObject);
5812 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5813}
5814
5815void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5816{
5817 for (int i = 0; i < n; i++)
5818 {
5819 GLuint transformFeedback = ids[i];
5820 if (transformFeedback == 0)
5821 {
5822 continue;
5823 }
5824
5825 TransformFeedback *transformFeedbackObject = nullptr;
5826 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5827 {
5828 if (transformFeedbackObject != nullptr)
5829 {
5830 detachTransformFeedback(transformFeedback);
5831 transformFeedbackObject->release(this);
5832 }
5833
5834 mTransformFeedbackHandleAllocator.release(transformFeedback);
5835 }
5836 }
5837}
5838
5839void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5840{
5841 for (int i = 0; i < n; i++)
5842 {
5843 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5844 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5845 ids[i] = transformFeedback;
5846 }
5847}
5848
5849bool Context::isTransformFeedback(GLuint id)
5850{
5851 if (id == 0)
5852 {
5853 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5854 // returns FALSE
5855 return GL_FALSE;
5856 }
5857
5858 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5859 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5860}
5861
5862void Context::pauseTransformFeedback()
5863{
5864 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5865 transformFeedback->pause();
5866}
5867
5868void Context::resumeTransformFeedback()
5869{
5870 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5871 transformFeedback->resume();
5872}
5873
Jamie Madill12e957f2017-08-26 21:42:26 -04005874void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5875{
5876 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005877 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005878}
5879
Brandon Jones59770802018-04-02 13:18:42 -07005880void Context::getUniformuivRobust(GLuint program,
5881 GLint location,
5882 GLsizei bufSize,
5883 GLsizei *length,
5884 GLuint *params)
5885{
5886 getUniformuiv(program, location, params);
5887}
5888
Jamie Madill12e957f2017-08-26 21:42:26 -04005889GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5890{
5891 const Program *programObject = getProgram(program);
5892 return programObject->getFragDataLocation(name);
5893}
5894
5895void Context::getUniformIndices(GLuint program,
5896 GLsizei uniformCount,
5897 const GLchar *const *uniformNames,
5898 GLuint *uniformIndices)
5899{
5900 const Program *programObject = getProgram(program);
5901 if (!programObject->isLinked())
5902 {
5903 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5904 {
5905 uniformIndices[uniformId] = GL_INVALID_INDEX;
5906 }
5907 }
5908 else
5909 {
5910 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5911 {
5912 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5913 }
5914 }
5915}
5916
5917void Context::getActiveUniformsiv(GLuint program,
5918 GLsizei uniformCount,
5919 const GLuint *uniformIndices,
5920 GLenum pname,
5921 GLint *params)
5922{
5923 const Program *programObject = getProgram(program);
5924 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5925 {
5926 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005927 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005928 }
5929}
5930
5931GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5932{
5933 const Program *programObject = getProgram(program);
5934 return programObject->getUniformBlockIndex(uniformBlockName);
5935}
5936
5937void Context::getActiveUniformBlockiv(GLuint program,
5938 GLuint uniformBlockIndex,
5939 GLenum pname,
5940 GLint *params)
5941{
5942 const Program *programObject = getProgram(program);
5943 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5944}
5945
Brandon Jones59770802018-04-02 13:18:42 -07005946void Context::getActiveUniformBlockivRobust(GLuint program,
5947 GLuint uniformBlockIndex,
5948 GLenum pname,
5949 GLsizei bufSize,
5950 GLsizei *length,
5951 GLint *params)
5952{
5953 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5954}
5955
Jamie Madill12e957f2017-08-26 21:42:26 -04005956void Context::getActiveUniformBlockName(GLuint program,
5957 GLuint uniformBlockIndex,
5958 GLsizei bufSize,
5959 GLsizei *length,
5960 GLchar *uniformBlockName)
5961{
5962 const Program *programObject = getProgram(program);
5963 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5964}
5965
5966void Context::uniformBlockBinding(GLuint program,
5967 GLuint uniformBlockIndex,
5968 GLuint uniformBlockBinding)
5969{
5970 Program *programObject = getProgram(program);
5971 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5972}
5973
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005974GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5975{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005976 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5977 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005978
Jamie Madill70b5bb02017-08-28 13:32:37 -04005979 Sync *syncObject = getSync(syncHandle);
5980 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005981 if (error.isError())
5982 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005983 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005984 handleError(error);
5985 return nullptr;
5986 }
5987
Jamie Madill70b5bb02017-08-28 13:32:37 -04005988 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005989}
5990
5991GLboolean Context::isSync(GLsync sync)
5992{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005993 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005994}
5995
5996GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5997{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005998 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005999
6000 GLenum result = GL_WAIT_FAILED;
6001 handleError(syncObject->clientWait(flags, timeout, &result));
6002 return result;
6003}
6004
6005void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6006{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006007 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006008 handleError(syncObject->serverWait(flags, timeout));
6009}
6010
6011void Context::getInteger64v(GLenum pname, GLint64 *params)
6012{
6013 GLenum nativeType = GL_NONE;
6014 unsigned int numParams = 0;
6015 getQueryParameterInfo(pname, &nativeType, &numParams);
6016
6017 if (nativeType == GL_INT_64_ANGLEX)
6018 {
6019 getInteger64vImpl(pname, params);
6020 }
6021 else
6022 {
6023 CastStateValues(this, nativeType, pname, numParams, params);
6024 }
6025}
6026
Brandon Jones59770802018-04-02 13:18:42 -07006027void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6028{
6029 getInteger64v(pname, data);
6030}
6031
Corentin Wallez336129f2017-10-17 15:55:40 -04006032void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006033{
6034 Buffer *buffer = mGLState.getTargetBuffer(target);
6035 QueryBufferParameteri64v(buffer, pname, params);
6036}
6037
Brandon Jones59770802018-04-02 13:18:42 -07006038void Context::getBufferParameteri64vRobust(BufferBinding target,
6039 GLenum pname,
6040 GLsizei bufSize,
6041 GLsizei *length,
6042 GLint64 *params)
6043{
6044 getBufferParameteri64v(target, pname, params);
6045}
6046
Jamie Madill3ef140a2017-08-26 23:11:21 -04006047void Context::genSamplers(GLsizei count, GLuint *samplers)
6048{
6049 for (int i = 0; i < count; i++)
6050 {
6051 samplers[i] = mState.mSamplers->createSampler();
6052 }
6053}
6054
6055void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6056{
6057 for (int i = 0; i < count; i++)
6058 {
6059 GLuint sampler = samplers[i];
6060
6061 if (mState.mSamplers->getSampler(sampler))
6062 {
6063 detachSampler(sampler);
6064 }
6065
6066 mState.mSamplers->deleteObject(this, sampler);
6067 }
6068}
6069
6070void Context::getInternalformativ(GLenum target,
6071 GLenum internalformat,
6072 GLenum pname,
6073 GLsizei bufSize,
6074 GLint *params)
6075{
6076 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6077 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6078}
6079
Brandon Jones59770802018-04-02 13:18:42 -07006080void Context::getInternalformativRobust(GLenum target,
6081 GLenum internalformat,
6082 GLenum pname,
6083 GLsizei bufSize,
6084 GLsizei *length,
6085 GLint *params)
6086{
6087 getInternalformativ(target, internalformat, pname, bufSize, params);
6088}
6089
Jiajia Qin5451d532017-11-16 17:16:34 +08006090void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6091{
6092 programUniform1iv(program, location, 1, &v0);
6093}
6094
6095void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6096{
6097 GLint xy[2] = {v0, v1};
6098 programUniform2iv(program, location, 1, xy);
6099}
6100
6101void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6102{
6103 GLint xyz[3] = {v0, v1, v2};
6104 programUniform3iv(program, location, 1, xyz);
6105}
6106
6107void Context::programUniform4i(GLuint program,
6108 GLint location,
6109 GLint v0,
6110 GLint v1,
6111 GLint v2,
6112 GLint v3)
6113{
6114 GLint xyzw[4] = {v0, v1, v2, v3};
6115 programUniform4iv(program, location, 1, xyzw);
6116}
6117
6118void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6119{
6120 programUniform1uiv(program, location, 1, &v0);
6121}
6122
6123void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6124{
6125 GLuint xy[2] = {v0, v1};
6126 programUniform2uiv(program, location, 1, xy);
6127}
6128
6129void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6130{
6131 GLuint xyz[3] = {v0, v1, v2};
6132 programUniform3uiv(program, location, 1, xyz);
6133}
6134
6135void Context::programUniform4ui(GLuint program,
6136 GLint location,
6137 GLuint v0,
6138 GLuint v1,
6139 GLuint v2,
6140 GLuint v3)
6141{
6142 GLuint xyzw[4] = {v0, v1, v2, v3};
6143 programUniform4uiv(program, location, 1, xyzw);
6144}
6145
6146void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6147{
6148 programUniform1fv(program, location, 1, &v0);
6149}
6150
6151void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6152{
6153 GLfloat xy[2] = {v0, v1};
6154 programUniform2fv(program, location, 1, xy);
6155}
6156
6157void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6158{
6159 GLfloat xyz[3] = {v0, v1, v2};
6160 programUniform3fv(program, location, 1, xyz);
6161}
6162
6163void Context::programUniform4f(GLuint program,
6164 GLint location,
6165 GLfloat v0,
6166 GLfloat v1,
6167 GLfloat v2,
6168 GLfloat v3)
6169{
6170 GLfloat xyzw[4] = {v0, v1, v2, v3};
6171 programUniform4fv(program, location, 1, xyzw);
6172}
6173
Jamie Madill81c2e252017-09-09 23:32:46 -04006174void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6175{
6176 Program *programObject = getProgram(program);
6177 ASSERT(programObject);
6178 if (programObject->setUniform1iv(location, count, value) ==
6179 Program::SetUniformResult::SamplerChanged)
6180 {
6181 mGLState.setObjectDirty(GL_PROGRAM);
6182 }
6183}
6184
Jiajia Qin5451d532017-11-16 17:16:34 +08006185void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6186{
6187 Program *programObject = getProgram(program);
6188 ASSERT(programObject);
6189 programObject->setUniform2iv(location, count, value);
6190}
6191
6192void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6193{
6194 Program *programObject = getProgram(program);
6195 ASSERT(programObject);
6196 programObject->setUniform3iv(location, count, value);
6197}
6198
6199void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6200{
6201 Program *programObject = getProgram(program);
6202 ASSERT(programObject);
6203 programObject->setUniform4iv(location, count, value);
6204}
6205
6206void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6207{
6208 Program *programObject = getProgram(program);
6209 ASSERT(programObject);
6210 programObject->setUniform1uiv(location, count, value);
6211}
6212
6213void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6214{
6215 Program *programObject = getProgram(program);
6216 ASSERT(programObject);
6217 programObject->setUniform2uiv(location, count, value);
6218}
6219
6220void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6221{
6222 Program *programObject = getProgram(program);
6223 ASSERT(programObject);
6224 programObject->setUniform3uiv(location, count, value);
6225}
6226
6227void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6228{
6229 Program *programObject = getProgram(program);
6230 ASSERT(programObject);
6231 programObject->setUniform4uiv(location, count, value);
6232}
6233
6234void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6235{
6236 Program *programObject = getProgram(program);
6237 ASSERT(programObject);
6238 programObject->setUniform1fv(location, count, value);
6239}
6240
6241void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6242{
6243 Program *programObject = getProgram(program);
6244 ASSERT(programObject);
6245 programObject->setUniform2fv(location, count, value);
6246}
6247
6248void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6249{
6250 Program *programObject = getProgram(program);
6251 ASSERT(programObject);
6252 programObject->setUniform3fv(location, count, value);
6253}
6254
6255void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6256{
6257 Program *programObject = getProgram(program);
6258 ASSERT(programObject);
6259 programObject->setUniform4fv(location, count, value);
6260}
6261
6262void Context::programUniformMatrix2fv(GLuint program,
6263 GLint location,
6264 GLsizei count,
6265 GLboolean transpose,
6266 const GLfloat *value)
6267{
6268 Program *programObject = getProgram(program);
6269 ASSERT(programObject);
6270 programObject->setUniformMatrix2fv(location, count, transpose, value);
6271}
6272
6273void Context::programUniformMatrix3fv(GLuint program,
6274 GLint location,
6275 GLsizei count,
6276 GLboolean transpose,
6277 const GLfloat *value)
6278{
6279 Program *programObject = getProgram(program);
6280 ASSERT(programObject);
6281 programObject->setUniformMatrix3fv(location, count, transpose, value);
6282}
6283
6284void Context::programUniformMatrix4fv(GLuint program,
6285 GLint location,
6286 GLsizei count,
6287 GLboolean transpose,
6288 const GLfloat *value)
6289{
6290 Program *programObject = getProgram(program);
6291 ASSERT(programObject);
6292 programObject->setUniformMatrix4fv(location, count, transpose, value);
6293}
6294
6295void Context::programUniformMatrix2x3fv(GLuint program,
6296 GLint location,
6297 GLsizei count,
6298 GLboolean transpose,
6299 const GLfloat *value)
6300{
6301 Program *programObject = getProgram(program);
6302 ASSERT(programObject);
6303 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6304}
6305
6306void Context::programUniformMatrix3x2fv(GLuint program,
6307 GLint location,
6308 GLsizei count,
6309 GLboolean transpose,
6310 const GLfloat *value)
6311{
6312 Program *programObject = getProgram(program);
6313 ASSERT(programObject);
6314 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6315}
6316
6317void Context::programUniformMatrix2x4fv(GLuint program,
6318 GLint location,
6319 GLsizei count,
6320 GLboolean transpose,
6321 const GLfloat *value)
6322{
6323 Program *programObject = getProgram(program);
6324 ASSERT(programObject);
6325 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6326}
6327
6328void Context::programUniformMatrix4x2fv(GLuint program,
6329 GLint location,
6330 GLsizei count,
6331 GLboolean transpose,
6332 const GLfloat *value)
6333{
6334 Program *programObject = getProgram(program);
6335 ASSERT(programObject);
6336 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6337}
6338
6339void Context::programUniformMatrix3x4fv(GLuint program,
6340 GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *programObject = getProgram(program);
6346 ASSERT(programObject);
6347 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6348}
6349
6350void Context::programUniformMatrix4x3fv(GLuint program,
6351 GLint location,
6352 GLsizei count,
6353 GLboolean transpose,
6354 const GLfloat *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6359}
6360
Jamie Madill81c2e252017-09-09 23:32:46 -04006361void Context::onTextureChange(const Texture *texture)
6362{
6363 // Conservatively assume all textures are dirty.
6364 // TODO(jmadill): More fine-grained update.
6365 mGLState.setObjectDirty(GL_TEXTURE);
6366}
6367
James Darpiniane8a93c62018-01-04 18:02:24 -08006368bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6369{
6370 return mGLState.isCurrentTransformFeedback(tf);
6371}
6372bool Context::isCurrentVertexArray(const VertexArray *va) const
6373{
6374 return mGLState.isCurrentVertexArray(va);
6375}
6376
Yunchao Hea336b902017-08-02 16:05:21 +08006377void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6378{
6379 for (int i = 0; i < count; i++)
6380 {
6381 pipelines[i] = createProgramPipeline();
6382 }
6383}
6384
6385void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6386{
6387 for (int i = 0; i < count; i++)
6388 {
6389 if (pipelines[i] != 0)
6390 {
6391 deleteProgramPipeline(pipelines[i]);
6392 }
6393 }
6394}
6395
6396GLboolean Context::isProgramPipeline(GLuint pipeline)
6397{
6398 if (pipeline == 0)
6399 {
6400 return GL_FALSE;
6401 }
6402
6403 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6404}
6405
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006406void Context::finishFenceNV(GLuint fence)
6407{
6408 FenceNV *fenceObject = getFenceNV(fence);
6409
6410 ASSERT(fenceObject && fenceObject->isSet());
6411 handleError(fenceObject->finish());
6412}
6413
6414void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6415{
6416 FenceNV *fenceObject = getFenceNV(fence);
6417
6418 ASSERT(fenceObject && fenceObject->isSet());
6419
6420 switch (pname)
6421 {
6422 case GL_FENCE_STATUS_NV:
6423 {
6424 // GL_NV_fence spec:
6425 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6426 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6427 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6428 GLboolean status = GL_TRUE;
6429 if (fenceObject->getStatus() != GL_TRUE)
6430 {
6431 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6432 }
6433 *params = status;
6434 break;
6435 }
6436
6437 case GL_FENCE_CONDITION_NV:
6438 {
6439 *params = static_cast<GLint>(fenceObject->getCondition());
6440 break;
6441 }
6442
6443 default:
6444 UNREACHABLE();
6445 }
6446}
6447
6448void Context::getTranslatedShaderSource(GLuint shader,
6449 GLsizei bufsize,
6450 GLsizei *length,
6451 GLchar *source)
6452{
6453 Shader *shaderObject = getShader(shader);
6454 ASSERT(shaderObject);
6455 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6456}
6457
6458void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6459{
6460 Program *programObject = getProgram(program);
6461 ASSERT(programObject);
6462
6463 programObject->getUniformfv(this, location, params);
6464}
6465
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006466void Context::getnUniformfvRobust(GLuint program,
6467 GLint location,
6468 GLsizei bufSize,
6469 GLsizei *length,
6470 GLfloat *params)
6471{
6472 UNIMPLEMENTED();
6473}
6474
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006475void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6476{
6477 Program *programObject = getProgram(program);
6478 ASSERT(programObject);
6479
6480 programObject->getUniformiv(this, location, params);
6481}
6482
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006483void Context::getnUniformivRobust(GLuint program,
6484 GLint location,
6485 GLsizei bufSize,
6486 GLsizei *length,
6487 GLint *params)
6488{
6489 UNIMPLEMENTED();
6490}
6491
6492void Context::getnUniformuivRobust(GLuint program,
6493 GLint location,
6494 GLsizei bufSize,
6495 GLsizei *length,
6496 GLuint *params)
6497{
6498 UNIMPLEMENTED();
6499}
6500
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006501GLboolean Context::isFenceNV(GLuint fence)
6502{
6503 FenceNV *fenceObject = getFenceNV(fence);
6504
6505 if (fenceObject == nullptr)
6506 {
6507 return GL_FALSE;
6508 }
6509
6510 // GL_NV_fence spec:
6511 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6512 // existing fence.
6513 return fenceObject->isSet();
6514}
6515
6516void Context::readnPixels(GLint x,
6517 GLint y,
6518 GLsizei width,
6519 GLsizei height,
6520 GLenum format,
6521 GLenum type,
6522 GLsizei bufSize,
6523 void *data)
6524{
6525 return readPixels(x, y, width, height, format, type, data);
6526}
6527
Jamie Madill007530e2017-12-28 14:27:04 -05006528void Context::setFenceNV(GLuint fence, GLenum condition)
6529{
6530 ASSERT(condition == GL_ALL_COMPLETED_NV);
6531
6532 FenceNV *fenceObject = getFenceNV(fence);
6533 ASSERT(fenceObject != nullptr);
6534 handleError(fenceObject->set(condition));
6535}
6536
6537GLboolean Context::testFenceNV(GLuint fence)
6538{
6539 FenceNV *fenceObject = getFenceNV(fence);
6540
6541 ASSERT(fenceObject != nullptr);
6542 ASSERT(fenceObject->isSet() == GL_TRUE);
6543
6544 GLboolean result = GL_TRUE;
6545 Error error = fenceObject->test(&result);
6546 if (error.isError())
6547 {
6548 handleError(error);
6549 return GL_TRUE;
6550 }
6551
6552 return result;
6553}
6554
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006555void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006556{
6557 Texture *texture = getTargetTexture(target);
6558 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006559 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006560}
6561
Jamie Madillfa920eb2018-01-04 11:45:50 -05006562void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006563{
6564 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6565 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6566 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6567}
6568
Jamie Madillfa920eb2018-01-04 11:45:50 -05006569void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6570{
6571 UNIMPLEMENTED();
6572}
6573
Jamie Madill5b772312018-03-08 20:28:32 -05006574bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6575{
6576 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6577 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6578 // to the fact that it is stored internally as a float, and so would require conversion
6579 // if returned from Context::getIntegerv. Since this conversion is already implemented
6580 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6581 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6582 // application.
6583 switch (pname)
6584 {
6585 case GL_COMPRESSED_TEXTURE_FORMATS:
6586 {
6587 *type = GL_INT;
6588 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6589 return true;
6590 }
6591 case GL_SHADER_BINARY_FORMATS:
6592 {
6593 *type = GL_INT;
6594 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6595 return true;
6596 }
6597
6598 case GL_MAX_VERTEX_ATTRIBS:
6599 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6600 case GL_MAX_VARYING_VECTORS:
6601 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6602 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6603 case GL_MAX_TEXTURE_IMAGE_UNITS:
6604 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6605 case GL_MAX_RENDERBUFFER_SIZE:
6606 case GL_NUM_SHADER_BINARY_FORMATS:
6607 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6608 case GL_ARRAY_BUFFER_BINDING:
6609 case GL_FRAMEBUFFER_BINDING:
6610 case GL_RENDERBUFFER_BINDING:
6611 case GL_CURRENT_PROGRAM:
6612 case GL_PACK_ALIGNMENT:
6613 case GL_UNPACK_ALIGNMENT:
6614 case GL_GENERATE_MIPMAP_HINT:
6615 case GL_RED_BITS:
6616 case GL_GREEN_BITS:
6617 case GL_BLUE_BITS:
6618 case GL_ALPHA_BITS:
6619 case GL_DEPTH_BITS:
6620 case GL_STENCIL_BITS:
6621 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6622 case GL_CULL_FACE_MODE:
6623 case GL_FRONT_FACE:
6624 case GL_ACTIVE_TEXTURE:
6625 case GL_STENCIL_FUNC:
6626 case GL_STENCIL_VALUE_MASK:
6627 case GL_STENCIL_REF:
6628 case GL_STENCIL_FAIL:
6629 case GL_STENCIL_PASS_DEPTH_FAIL:
6630 case GL_STENCIL_PASS_DEPTH_PASS:
6631 case GL_STENCIL_BACK_FUNC:
6632 case GL_STENCIL_BACK_VALUE_MASK:
6633 case GL_STENCIL_BACK_REF:
6634 case GL_STENCIL_BACK_FAIL:
6635 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6636 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6637 case GL_DEPTH_FUNC:
6638 case GL_BLEND_SRC_RGB:
6639 case GL_BLEND_SRC_ALPHA:
6640 case GL_BLEND_DST_RGB:
6641 case GL_BLEND_DST_ALPHA:
6642 case GL_BLEND_EQUATION_RGB:
6643 case GL_BLEND_EQUATION_ALPHA:
6644 case GL_STENCIL_WRITEMASK:
6645 case GL_STENCIL_BACK_WRITEMASK:
6646 case GL_STENCIL_CLEAR_VALUE:
6647 case GL_SUBPIXEL_BITS:
6648 case GL_MAX_TEXTURE_SIZE:
6649 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6650 case GL_SAMPLE_BUFFERS:
6651 case GL_SAMPLES:
6652 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6653 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6654 case GL_TEXTURE_BINDING_2D:
6655 case GL_TEXTURE_BINDING_CUBE_MAP:
6656 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6657 {
6658 *type = GL_INT;
6659 *numParams = 1;
6660 return true;
6661 }
6662 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6663 {
6664 if (!getExtensions().packReverseRowOrder)
6665 {
6666 return false;
6667 }
6668 *type = GL_INT;
6669 *numParams = 1;
6670 return true;
6671 }
6672 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6673 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6674 {
6675 if (!getExtensions().textureRectangle)
6676 {
6677 return false;
6678 }
6679 *type = GL_INT;
6680 *numParams = 1;
6681 return true;
6682 }
6683 case GL_MAX_DRAW_BUFFERS_EXT:
6684 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6685 {
6686 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6687 {
6688 return false;
6689 }
6690 *type = GL_INT;
6691 *numParams = 1;
6692 return true;
6693 }
6694 case GL_MAX_VIEWPORT_DIMS:
6695 {
6696 *type = GL_INT;
6697 *numParams = 2;
6698 return true;
6699 }
6700 case GL_VIEWPORT:
6701 case GL_SCISSOR_BOX:
6702 {
6703 *type = GL_INT;
6704 *numParams = 4;
6705 return true;
6706 }
6707 case GL_SHADER_COMPILER:
6708 case GL_SAMPLE_COVERAGE_INVERT:
6709 case GL_DEPTH_WRITEMASK:
6710 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6711 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6712 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6713 // bool-natural
6714 case GL_SAMPLE_COVERAGE:
6715 case GL_SCISSOR_TEST:
6716 case GL_STENCIL_TEST:
6717 case GL_DEPTH_TEST:
6718 case GL_BLEND:
6719 case GL_DITHER:
6720 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6721 {
6722 *type = GL_BOOL;
6723 *numParams = 1;
6724 return true;
6725 }
6726 case GL_COLOR_WRITEMASK:
6727 {
6728 *type = GL_BOOL;
6729 *numParams = 4;
6730 return true;
6731 }
6732 case GL_POLYGON_OFFSET_FACTOR:
6733 case GL_POLYGON_OFFSET_UNITS:
6734 case GL_SAMPLE_COVERAGE_VALUE:
6735 case GL_DEPTH_CLEAR_VALUE:
6736 case GL_LINE_WIDTH:
6737 {
6738 *type = GL_FLOAT;
6739 *numParams = 1;
6740 return true;
6741 }
6742 case GL_ALIASED_LINE_WIDTH_RANGE:
6743 case GL_ALIASED_POINT_SIZE_RANGE:
6744 case GL_DEPTH_RANGE:
6745 {
6746 *type = GL_FLOAT;
6747 *numParams = 2;
6748 return true;
6749 }
6750 case GL_COLOR_CLEAR_VALUE:
6751 case GL_BLEND_COLOR:
6752 {
6753 *type = GL_FLOAT;
6754 *numParams = 4;
6755 return true;
6756 }
6757 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6758 if (!getExtensions().textureFilterAnisotropic)
6759 {
6760 return false;
6761 }
6762 *type = GL_FLOAT;
6763 *numParams = 1;
6764 return true;
6765 case GL_TIMESTAMP_EXT:
6766 if (!getExtensions().disjointTimerQuery)
6767 {
6768 return false;
6769 }
6770 *type = GL_INT_64_ANGLEX;
6771 *numParams = 1;
6772 return true;
6773 case GL_GPU_DISJOINT_EXT:
6774 if (!getExtensions().disjointTimerQuery)
6775 {
6776 return false;
6777 }
6778 *type = GL_INT;
6779 *numParams = 1;
6780 return true;
6781 case GL_COVERAGE_MODULATION_CHROMIUM:
6782 if (!getExtensions().framebufferMixedSamples)
6783 {
6784 return false;
6785 }
6786 *type = GL_INT;
6787 *numParams = 1;
6788 return true;
6789 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6790 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6791 {
6792 return false;
6793 }
6794 *type = GL_INT;
6795 *numParams = 1;
6796 return true;
6797 }
6798
6799 if (getExtensions().debug)
6800 {
6801 switch (pname)
6802 {
6803 case GL_DEBUG_LOGGED_MESSAGES:
6804 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6805 case GL_DEBUG_GROUP_STACK_DEPTH:
6806 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6807 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6808 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6809 case GL_MAX_LABEL_LENGTH:
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813
6814 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6815 case GL_DEBUG_OUTPUT:
6816 *type = GL_BOOL;
6817 *numParams = 1;
6818 return true;
6819 }
6820 }
6821
6822 if (getExtensions().multisampleCompatibility)
6823 {
6824 switch (pname)
6825 {
6826 case GL_MULTISAMPLE_EXT:
6827 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6828 *type = GL_BOOL;
6829 *numParams = 1;
6830 return true;
6831 }
6832 }
6833
6834 if (getExtensions().pathRendering)
6835 {
6836 switch (pname)
6837 {
6838 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6839 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6840 *type = GL_FLOAT;
6841 *numParams = 16;
6842 return true;
6843 }
6844 }
6845
6846 if (getExtensions().bindGeneratesResource)
6847 {
6848 switch (pname)
6849 {
6850 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6851 *type = GL_BOOL;
6852 *numParams = 1;
6853 return true;
6854 }
6855 }
6856
6857 if (getExtensions().clientArrays)
6858 {
6859 switch (pname)
6860 {
6861 case GL_CLIENT_ARRAYS_ANGLE:
6862 *type = GL_BOOL;
6863 *numParams = 1;
6864 return true;
6865 }
6866 }
6867
6868 if (getExtensions().sRGBWriteControl)
6869 {
6870 switch (pname)
6871 {
6872 case GL_FRAMEBUFFER_SRGB_EXT:
6873 *type = GL_BOOL;
6874 *numParams = 1;
6875 return true;
6876 }
6877 }
6878
6879 if (getExtensions().robustResourceInitialization &&
6880 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6881 {
6882 *type = GL_BOOL;
6883 *numParams = 1;
6884 return true;
6885 }
6886
6887 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6888 {
6889 *type = GL_BOOL;
6890 *numParams = 1;
6891 return true;
6892 }
6893
6894 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6895 switch (pname)
6896 {
6897 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6898 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6899 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6900 {
6901 return false;
6902 }
6903 *type = GL_INT;
6904 *numParams = 1;
6905 return true;
6906
6907 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6908 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6909 {
6910 return false;
6911 }
6912 *type = GL_INT;
6913 *numParams = 1;
6914 return true;
6915
6916 case GL_PROGRAM_BINARY_FORMATS_OES:
6917 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6918 {
6919 return false;
6920 }
6921 *type = GL_INT;
6922 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6923 return true;
6924
6925 case GL_PACK_ROW_LENGTH:
6926 case GL_PACK_SKIP_ROWS:
6927 case GL_PACK_SKIP_PIXELS:
6928 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6929 {
6930 return false;
6931 }
6932 *type = GL_INT;
6933 *numParams = 1;
6934 return true;
6935 case GL_UNPACK_ROW_LENGTH:
6936 case GL_UNPACK_SKIP_ROWS:
6937 case GL_UNPACK_SKIP_PIXELS:
6938 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6939 {
6940 return false;
6941 }
6942 *type = GL_INT;
6943 *numParams = 1;
6944 return true;
6945 case GL_VERTEX_ARRAY_BINDING:
6946 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6947 {
6948 return false;
6949 }
6950 *type = GL_INT;
6951 *numParams = 1;
6952 return true;
6953 case GL_PIXEL_PACK_BUFFER_BINDING:
6954 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6955 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6956 {
6957 return false;
6958 }
6959 *type = GL_INT;
6960 *numParams = 1;
6961 return true;
6962 case GL_MAX_SAMPLES:
6963 {
6964 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6965 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6966 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6967 {
6968 return false;
6969 }
6970 *type = GL_INT;
6971 *numParams = 1;
6972 return true;
6973
6974 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6975 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6976 {
6977 return false;
6978 }
6979 *type = GL_INT;
6980 *numParams = 1;
6981 return true;
6982 }
6983 }
6984
6985 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6986 {
6987 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6988 {
6989 return false;
6990 }
6991 *type = GL_INT;
6992 *numParams = 1;
6993 return true;
6994 }
6995
6996 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6997 {
6998 *type = GL_INT;
6999 *numParams = 1;
7000 return true;
7001 }
7002
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007003 if (getClientVersion() < Version(2, 0))
7004 {
7005 switch (pname)
7006 {
7007 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007008 case GL_CLIENT_ACTIVE_TEXTURE:
7009 case GL_MATRIX_MODE:
7010 case GL_MAX_TEXTURE_UNITS:
7011 case GL_MAX_MODELVIEW_STACK_DEPTH:
7012 case GL_MAX_PROJECTION_STACK_DEPTH:
7013 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007014 *type = GL_INT;
7015 *numParams = 1;
7016 return true;
7017 case GL_ALPHA_TEST_REF:
7018 *type = GL_FLOAT;
7019 *numParams = 1;
7020 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007021 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007022 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007023 *type = GL_FLOAT;
7024 *numParams = 4;
7025 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007026 case GL_CURRENT_NORMAL:
7027 *type = GL_FLOAT;
7028 *numParams = 3;
7029 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007030 }
7031 }
7032
Jamie Madill5b772312018-03-08 20:28:32 -05007033 if (getClientVersion() < Version(3, 0))
7034 {
7035 return false;
7036 }
7037
7038 // Check for ES3.0+ parameter names
7039 switch (pname)
7040 {
7041 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7042 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7043 case GL_UNIFORM_BUFFER_BINDING:
7044 case GL_TRANSFORM_FEEDBACK_BINDING:
7045 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7046 case GL_COPY_READ_BUFFER_BINDING:
7047 case GL_COPY_WRITE_BUFFER_BINDING:
7048 case GL_SAMPLER_BINDING:
7049 case GL_READ_BUFFER:
7050 case GL_TEXTURE_BINDING_3D:
7051 case GL_TEXTURE_BINDING_2D_ARRAY:
7052 case GL_MAX_3D_TEXTURE_SIZE:
7053 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7054 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7055 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7056 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7057 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7058 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7059 case GL_MAX_VARYING_COMPONENTS:
7060 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7061 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7062 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7063 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7064 case GL_NUM_EXTENSIONS:
7065 case GL_MAJOR_VERSION:
7066 case GL_MINOR_VERSION:
7067 case GL_MAX_ELEMENTS_INDICES:
7068 case GL_MAX_ELEMENTS_VERTICES:
7069 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7070 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7071 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7072 case GL_UNPACK_IMAGE_HEIGHT:
7073 case GL_UNPACK_SKIP_IMAGES:
7074 {
7075 *type = GL_INT;
7076 *numParams = 1;
7077 return true;
7078 }
7079
7080 case GL_MAX_ELEMENT_INDEX:
7081 case GL_MAX_UNIFORM_BLOCK_SIZE:
7082 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7083 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7084 case GL_MAX_SERVER_WAIT_TIMEOUT:
7085 {
7086 *type = GL_INT_64_ANGLEX;
7087 *numParams = 1;
7088 return true;
7089 }
7090
7091 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7092 case GL_TRANSFORM_FEEDBACK_PAUSED:
7093 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7094 case GL_RASTERIZER_DISCARD:
7095 {
7096 *type = GL_BOOL;
7097 *numParams = 1;
7098 return true;
7099 }
7100
7101 case GL_MAX_TEXTURE_LOD_BIAS:
7102 {
7103 *type = GL_FLOAT;
7104 *numParams = 1;
7105 return true;
7106 }
7107 }
7108
7109 if (getExtensions().requestExtension)
7110 {
7111 switch (pname)
7112 {
7113 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7114 *type = GL_INT;
7115 *numParams = 1;
7116 return true;
7117 }
7118 }
7119
7120 if (getClientVersion() < Version(3, 1))
7121 {
7122 return false;
7123 }
7124
7125 switch (pname)
7126 {
7127 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7128 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7129 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7130 case GL_MAX_FRAMEBUFFER_WIDTH:
7131 case GL_MAX_FRAMEBUFFER_HEIGHT:
7132 case GL_MAX_FRAMEBUFFER_SAMPLES:
7133 case GL_MAX_SAMPLE_MASK_WORDS:
7134 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7135 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7136 case GL_MAX_INTEGER_SAMPLES:
7137 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7138 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7139 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7140 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7141 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7142 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7143 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7144 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7145 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7146 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7147 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7148 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7149 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7150 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7151 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7152 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7153 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7154 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7155 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7156 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7157 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7158 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7159 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7160 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7161 case GL_MAX_UNIFORM_LOCATIONS:
7162 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7163 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7164 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7165 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7166 case GL_MAX_IMAGE_UNITS:
7167 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7168 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7169 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7170 case GL_SHADER_STORAGE_BUFFER_BINDING:
7171 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7172 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7173 *type = GL_INT;
7174 *numParams = 1;
7175 return true;
7176 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7177 *type = GL_INT_64_ANGLEX;
7178 *numParams = 1;
7179 return true;
7180 case GL_SAMPLE_MASK:
7181 *type = GL_BOOL;
7182 *numParams = 1;
7183 return true;
7184 }
7185
7186 if (getExtensions().geometryShader)
7187 {
7188 switch (pname)
7189 {
7190 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7191 case GL_LAYER_PROVOKING_VERTEX_EXT:
7192 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7193 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7194 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7195 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7196 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7197 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7198 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7199 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7200 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7201 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7202 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7203 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7204 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7205 *type = GL_INT;
7206 *numParams = 1;
7207 return true;
7208 }
7209 }
7210
7211 return false;
7212}
7213
7214bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7215{
7216 if (getClientVersion() < Version(3, 0))
7217 {
7218 return false;
7219 }
7220
7221 switch (target)
7222 {
7223 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7224 case GL_UNIFORM_BUFFER_BINDING:
7225 {
7226 *type = GL_INT;
7227 *numParams = 1;
7228 return true;
7229 }
7230 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7231 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7232 case GL_UNIFORM_BUFFER_START:
7233 case GL_UNIFORM_BUFFER_SIZE:
7234 {
7235 *type = GL_INT_64_ANGLEX;
7236 *numParams = 1;
7237 return true;
7238 }
7239 }
7240
7241 if (getClientVersion() < Version(3, 1))
7242 {
7243 return false;
7244 }
7245
7246 switch (target)
7247 {
7248 case GL_IMAGE_BINDING_LAYERED:
7249 {
7250 *type = GL_BOOL;
7251 *numParams = 1;
7252 return true;
7253 }
7254 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7255 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7256 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7257 case GL_SHADER_STORAGE_BUFFER_BINDING:
7258 case GL_VERTEX_BINDING_BUFFER:
7259 case GL_VERTEX_BINDING_DIVISOR:
7260 case GL_VERTEX_BINDING_OFFSET:
7261 case GL_VERTEX_BINDING_STRIDE:
7262 case GL_SAMPLE_MASK_VALUE:
7263 case GL_IMAGE_BINDING_NAME:
7264 case GL_IMAGE_BINDING_LEVEL:
7265 case GL_IMAGE_BINDING_LAYER:
7266 case GL_IMAGE_BINDING_ACCESS:
7267 case GL_IMAGE_BINDING_FORMAT:
7268 {
7269 *type = GL_INT;
7270 *numParams = 1;
7271 return true;
7272 }
7273 case GL_ATOMIC_COUNTER_BUFFER_START:
7274 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7275 case GL_SHADER_STORAGE_BUFFER_START:
7276 case GL_SHADER_STORAGE_BUFFER_SIZE:
7277 {
7278 *type = GL_INT_64_ANGLEX;
7279 *numParams = 1;
7280 return true;
7281 }
7282 }
7283
7284 return false;
7285}
7286
7287Program *Context::getProgram(GLuint handle) const
7288{
7289 return mState.mShaderPrograms->getProgram(handle);
7290}
7291
7292Shader *Context::getShader(GLuint handle) const
7293{
7294 return mState.mShaderPrograms->getShader(handle);
7295}
7296
7297bool Context::isTextureGenerated(GLuint texture) const
7298{
7299 return mState.mTextures->isHandleGenerated(texture);
7300}
7301
7302bool Context::isBufferGenerated(GLuint buffer) const
7303{
7304 return mState.mBuffers->isHandleGenerated(buffer);
7305}
7306
7307bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7308{
7309 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7310}
7311
7312bool Context::isFramebufferGenerated(GLuint framebuffer) const
7313{
7314 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7315}
7316
7317bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7318{
7319 return mState.mPipelines->isHandleGenerated(pipeline);
7320}
7321
7322bool Context::usingDisplayTextureShareGroup() const
7323{
7324 return mDisplayTextureShareGroup;
7325}
7326
7327GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7328{
7329 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7330 internalformat == GL_DEPTH_STENCIL
7331 ? GL_DEPTH24_STENCIL8
7332 : internalformat;
7333}
7334
Jamie Madillc29968b2016-01-20 11:17:23 -05007335} // namespace gl