blob: 659305afcf1979db70c6b6619e8516a4382ad23c [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 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001292 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1293 // GLES1 constants for modelview/projection matrix.
1294 if (getClientVersion() < Version(2, 0))
1295 {
1296 mGLState.getFloatv(pname, params);
1297 }
1298 else
1299 {
1300 ASSERT(mExtensions.pathRendering);
1301 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1302 memcpy(params, m, 16 * sizeof(GLfloat));
1303 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001304 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001305 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001306
Jamie Madill231c7f52017-04-26 13:45:37 -04001307 default:
1308 mGLState.getFloatv(pname, params);
1309 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001311}
1312
Jamie Madillc1d770e2017-04-13 17:31:24 -04001313void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314{
Shannon Woods53a94a82014-06-24 15:20:36 -04001315 // Queries about context capabilities and maximums are answered by Context.
1316 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001317
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318 switch (pname)
1319 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 case GL_MAX_VERTEX_ATTRIBS:
1321 *params = mCaps.maxVertexAttributes;
1322 break;
1323 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1324 *params = mCaps.maxVertexUniformVectors;
1325 break;
1326 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1327 *params = mCaps.maxVertexUniformComponents;
1328 break;
1329 case GL_MAX_VARYING_VECTORS:
1330 *params = mCaps.maxVaryingVectors;
1331 break;
1332 case GL_MAX_VARYING_COMPONENTS:
1333 *params = mCaps.maxVertexOutputComponents;
1334 break;
1335 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1336 *params = mCaps.maxCombinedTextureImageUnits;
1337 break;
1338 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1339 *params = mCaps.maxVertexTextureImageUnits;
1340 break;
1341 case GL_MAX_TEXTURE_IMAGE_UNITS:
1342 *params = mCaps.maxTextureImageUnits;
1343 break;
1344 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1345 *params = mCaps.maxFragmentUniformVectors;
1346 break;
1347 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1348 *params = mCaps.maxFragmentUniformComponents;
1349 break;
1350 case GL_MAX_RENDERBUFFER_SIZE:
1351 *params = mCaps.maxRenderbufferSize;
1352 break;
1353 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1354 *params = mCaps.maxColorAttachments;
1355 break;
1356 case GL_MAX_DRAW_BUFFERS_EXT:
1357 *params = mCaps.maxDrawBuffers;
1358 break;
1359 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1360 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1361 case GL_SUBPIXEL_BITS:
1362 *params = 4;
1363 break;
1364 case GL_MAX_TEXTURE_SIZE:
1365 *params = mCaps.max2DTextureSize;
1366 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001367 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1368 *params = mCaps.maxRectangleTextureSize;
1369 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1371 *params = mCaps.maxCubeMapTextureSize;
1372 break;
1373 case GL_MAX_3D_TEXTURE_SIZE:
1374 *params = mCaps.max3DTextureSize;
1375 break;
1376 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1377 *params = mCaps.maxArrayTextureLayers;
1378 break;
1379 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1380 *params = mCaps.uniformBufferOffsetAlignment;
1381 break;
1382 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1383 *params = mCaps.maxUniformBufferBindings;
1384 break;
1385 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1386 *params = mCaps.maxVertexUniformBlocks;
1387 break;
1388 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1389 *params = mCaps.maxFragmentUniformBlocks;
1390 break;
1391 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1392 *params = mCaps.maxCombinedTextureImageUnits;
1393 break;
1394 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1395 *params = mCaps.maxVertexOutputComponents;
1396 break;
1397 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1398 *params = mCaps.maxFragmentInputComponents;
1399 break;
1400 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1401 *params = mCaps.minProgramTexelOffset;
1402 break;
1403 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1404 *params = mCaps.maxProgramTexelOffset;
1405 break;
1406 case GL_MAJOR_VERSION:
1407 *params = getClientVersion().major;
1408 break;
1409 case GL_MINOR_VERSION:
1410 *params = getClientVersion().minor;
1411 break;
1412 case GL_MAX_ELEMENTS_INDICES:
1413 *params = mCaps.maxElementsIndices;
1414 break;
1415 case GL_MAX_ELEMENTS_VERTICES:
1416 *params = mCaps.maxElementsVertices;
1417 break;
1418 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1419 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1420 break;
1421 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1422 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1423 break;
1424 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1425 *params = mCaps.maxTransformFeedbackSeparateComponents;
1426 break;
1427 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1428 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1429 break;
1430 case GL_MAX_SAMPLES_ANGLE:
1431 *params = mCaps.maxSamples;
1432 break;
1433 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001434 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001435 params[0] = mCaps.maxViewportWidth;
1436 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437 }
1438 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 case GL_COMPRESSED_TEXTURE_FORMATS:
1440 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1441 params);
1442 break;
1443 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1444 *params = mResetStrategy;
1445 break;
1446 case GL_NUM_SHADER_BINARY_FORMATS:
1447 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1448 break;
1449 case GL_SHADER_BINARY_FORMATS:
1450 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1451 break;
1452 case GL_NUM_PROGRAM_BINARY_FORMATS:
1453 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1454 break;
1455 case GL_PROGRAM_BINARY_FORMATS:
1456 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1457 break;
1458 case GL_NUM_EXTENSIONS:
1459 *params = static_cast<GLint>(mExtensionStrings.size());
1460 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001461
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 // GL_KHR_debug
1463 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1464 *params = mExtensions.maxDebugMessageLength;
1465 break;
1466 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1467 *params = mExtensions.maxDebugLoggedMessages;
1468 break;
1469 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1470 *params = mExtensions.maxDebugGroupStackDepth;
1471 break;
1472 case GL_MAX_LABEL_LENGTH:
1473 *params = mExtensions.maxLabelLength;
1474 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001475
Martin Radeve5285d22017-07-14 16:23:53 +03001476 // GL_ANGLE_multiview
1477 case GL_MAX_VIEWS_ANGLE:
1478 *params = mExtensions.maxViews;
1479 break;
1480
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 // GL_EXT_disjoint_timer_query
1482 case GL_GPU_DISJOINT_EXT:
1483 *params = mImplementation->getGPUDisjoint();
1484 break;
1485 case GL_MAX_FRAMEBUFFER_WIDTH:
1486 *params = mCaps.maxFramebufferWidth;
1487 break;
1488 case GL_MAX_FRAMEBUFFER_HEIGHT:
1489 *params = mCaps.maxFramebufferHeight;
1490 break;
1491 case GL_MAX_FRAMEBUFFER_SAMPLES:
1492 *params = mCaps.maxFramebufferSamples;
1493 break;
1494 case GL_MAX_SAMPLE_MASK_WORDS:
1495 *params = mCaps.maxSampleMaskWords;
1496 break;
1497 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1498 *params = mCaps.maxColorTextureSamples;
1499 break;
1500 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1501 *params = mCaps.maxDepthTextureSamples;
1502 break;
1503 case GL_MAX_INTEGER_SAMPLES:
1504 *params = mCaps.maxIntegerSamples;
1505 break;
1506 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1507 *params = mCaps.maxVertexAttribRelativeOffset;
1508 break;
1509 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1510 *params = mCaps.maxVertexAttribBindings;
1511 break;
1512 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1513 *params = mCaps.maxVertexAttribStride;
1514 break;
1515 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1516 *params = mCaps.maxVertexAtomicCounterBuffers;
1517 break;
1518 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1519 *params = mCaps.maxVertexAtomicCounters;
1520 break;
1521 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1522 *params = mCaps.maxVertexImageUniforms;
1523 break;
1524 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1525 *params = mCaps.maxVertexShaderStorageBlocks;
1526 break;
1527 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1528 *params = mCaps.maxFragmentAtomicCounterBuffers;
1529 break;
1530 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1531 *params = mCaps.maxFragmentAtomicCounters;
1532 break;
1533 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1534 *params = mCaps.maxFragmentImageUniforms;
1535 break;
1536 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1537 *params = mCaps.maxFragmentShaderStorageBlocks;
1538 break;
1539 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1540 *params = mCaps.minProgramTextureGatherOffset;
1541 break;
1542 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1543 *params = mCaps.maxProgramTextureGatherOffset;
1544 break;
1545 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1546 *params = mCaps.maxComputeWorkGroupInvocations;
1547 break;
1548 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1549 *params = mCaps.maxComputeUniformBlocks;
1550 break;
1551 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1552 *params = mCaps.maxComputeTextureImageUnits;
1553 break;
1554 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1555 *params = mCaps.maxComputeSharedMemorySize;
1556 break;
1557 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1558 *params = mCaps.maxComputeUniformComponents;
1559 break;
1560 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1561 *params = mCaps.maxComputeAtomicCounterBuffers;
1562 break;
1563 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1564 *params = mCaps.maxComputeAtomicCounters;
1565 break;
1566 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1567 *params = mCaps.maxComputeImageUniforms;
1568 break;
1569 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1570 *params = mCaps.maxCombinedComputeUniformComponents;
1571 break;
1572 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1573 *params = mCaps.maxComputeShaderStorageBlocks;
1574 break;
1575 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1576 *params = mCaps.maxCombinedShaderOutputResources;
1577 break;
1578 case GL_MAX_UNIFORM_LOCATIONS:
1579 *params = mCaps.maxUniformLocations;
1580 break;
1581 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1582 *params = mCaps.maxAtomicCounterBufferBindings;
1583 break;
1584 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1585 *params = mCaps.maxAtomicCounterBufferSize;
1586 break;
1587 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1588 *params = mCaps.maxCombinedAtomicCounterBuffers;
1589 break;
1590 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1591 *params = mCaps.maxCombinedAtomicCounters;
1592 break;
1593 case GL_MAX_IMAGE_UNITS:
1594 *params = mCaps.maxImageUnits;
1595 break;
1596 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1597 *params = mCaps.maxCombinedImageUniforms;
1598 break;
1599 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1600 *params = mCaps.maxShaderStorageBufferBindings;
1601 break;
1602 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1603 *params = mCaps.maxCombinedShaderStorageBlocks;
1604 break;
1605 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1606 *params = mCaps.shaderStorageBufferOffsetAlignment;
1607 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001608
1609 // GL_EXT_geometry_shader
1610 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1611 *params = mCaps.maxFramebufferLayers;
1612 break;
1613 case GL_LAYER_PROVOKING_VERTEX_EXT:
1614 *params = mCaps.layerProvokingVertex;
1615 break;
1616 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1617 *params = mCaps.maxGeometryUniformComponents;
1618 break;
1619 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1620 *params = mCaps.maxGeometryUniformBlocks;
1621 break;
1622 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1623 *params = mCaps.maxCombinedGeometryUniformComponents;
1624 break;
1625 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1626 *params = mCaps.maxGeometryInputComponents;
1627 break;
1628 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1629 *params = mCaps.maxGeometryOutputComponents;
1630 break;
1631 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1632 *params = mCaps.maxGeometryOutputVertices;
1633 break;
1634 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1635 *params = mCaps.maxGeometryTotalOutputComponents;
1636 break;
1637 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1638 *params = mCaps.maxGeometryShaderInvocations;
1639 break;
1640 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1641 *params = mCaps.maxGeometryTextureImageUnits;
1642 break;
1643 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1644 *params = mCaps.maxGeometryAtomicCounterBuffers;
1645 break;
1646 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1647 *params = mCaps.maxGeometryAtomicCounters;
1648 break;
1649 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1650 *params = mCaps.maxGeometryImageUniforms;
1651 break;
1652 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1653 *params = mCaps.maxGeometryShaderStorageBlocks;
1654 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001655 // GLES1 emulation: Caps queries
1656 case GL_MAX_TEXTURE_UNITS:
1657 *params = mCaps.maxMultitextureUnits;
1658 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001659 case GL_MAX_MODELVIEW_STACK_DEPTH:
1660 *params = mCaps.maxModelviewMatrixStackDepth;
1661 break;
1662 case GL_MAX_PROJECTION_STACK_DEPTH:
1663 *params = mCaps.maxProjectionMatrixStackDepth;
1664 break;
1665 case GL_MAX_TEXTURE_STACK_DEPTH:
1666 *params = mCaps.maxTextureMatrixStackDepth;
1667 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001668 // GLES1 emulation: Vertex attribute queries
1669 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1670 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1671 case GL_COLOR_ARRAY_BUFFER_BINDING:
1672 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1673 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1674 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1675 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1676 break;
1677 case GL_VERTEX_ARRAY_STRIDE:
1678 case GL_NORMAL_ARRAY_STRIDE:
1679 case GL_COLOR_ARRAY_STRIDE:
1680 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1681 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1682 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1683 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1684 break;
1685 case GL_VERTEX_ARRAY_SIZE:
1686 case GL_COLOR_ARRAY_SIZE:
1687 case GL_TEXTURE_COORD_ARRAY_SIZE:
1688 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1689 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1690 break;
1691 case GL_VERTEX_ARRAY_TYPE:
1692 case GL_COLOR_ARRAY_TYPE:
1693 case GL_NORMAL_ARRAY_TYPE:
1694 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1695 case GL_TEXTURE_COORD_ARRAY_TYPE:
1696 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1697 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1698 break;
1699
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001701 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001703 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001704}
1705
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001706void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001707{
Shannon Woods53a94a82014-06-24 15:20:36 -04001708 // Queries about context capabilities and maximums are answered by Context.
1709 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001710 switch (pname)
1711 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001712 case GL_MAX_ELEMENT_INDEX:
1713 *params = mCaps.maxElementIndex;
1714 break;
1715 case GL_MAX_UNIFORM_BLOCK_SIZE:
1716 *params = mCaps.maxUniformBlockSize;
1717 break;
1718 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1719 *params = mCaps.maxCombinedVertexUniformComponents;
1720 break;
1721 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1722 *params = mCaps.maxCombinedFragmentUniformComponents;
1723 break;
1724 case GL_MAX_SERVER_WAIT_TIMEOUT:
1725 *params = mCaps.maxServerWaitTimeout;
1726 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001727
Jamie Madill231c7f52017-04-26 13:45:37 -04001728 // GL_EXT_disjoint_timer_query
1729 case GL_TIMESTAMP_EXT:
1730 *params = mImplementation->getTimestamp();
1731 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001732
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1734 *params = mCaps.maxShaderStorageBlockSize;
1735 break;
1736 default:
1737 UNREACHABLE();
1738 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001739 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001740}
1741
Geoff Lang70d0f492015-12-10 17:45:46 -05001742void Context::getPointerv(GLenum pname, void **params) const
1743{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001744 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001745}
1746
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001747void Context::getPointervRobustANGLERobust(GLenum pname,
1748 GLsizei bufSize,
1749 GLsizei *length,
1750 void **params)
1751{
1752 UNIMPLEMENTED();
1753}
1754
Martin Radev66fb8202016-07-28 11:45:20 +03001755void Context::getIntegeri_v(GLenum target, GLuint index, GLint *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)
1766 {
1767 switch (target)
1768 {
1769 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1770 ASSERT(index < 3u);
1771 *data = mCaps.maxComputeWorkGroupCount[index];
1772 break;
1773 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1774 ASSERT(index < 3u);
1775 *data = mCaps.maxComputeWorkGroupSize[index];
1776 break;
1777 default:
1778 mGLState.getIntegeri_v(target, index, data);
1779 }
1780 }
1781 else
1782 {
1783 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1784 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001785}
1786
Brandon Jones59770802018-04-02 13:18:42 -07001787void Context::getIntegeri_vRobust(GLenum target,
1788 GLuint index,
1789 GLsizei bufSize,
1790 GLsizei *length,
1791 GLint *data)
1792{
1793 getIntegeri_v(target, index, data);
1794}
1795
Martin Radev66fb8202016-07-28 11:45:20 +03001796void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001797{
Shannon Woods53a94a82014-06-24 15:20:36 -04001798 // Queries about context capabilities and maximums are answered by Context.
1799 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001800
1801 GLenum nativeType;
1802 unsigned int numParams;
1803 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1804 ASSERT(queryStatus);
1805
1806 if (nativeType == GL_INT_64_ANGLEX)
1807 {
1808 mGLState.getInteger64i_v(target, index, data);
1809 }
1810 else
1811 {
1812 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1813 }
1814}
1815
Brandon Jones59770802018-04-02 13:18:42 -07001816void Context::getInteger64i_vRobust(GLenum target,
1817 GLuint index,
1818 GLsizei bufSize,
1819 GLsizei *length,
1820 GLint64 *data)
1821{
1822 getInteger64i_v(target, index, data);
1823}
1824
Martin Radev66fb8202016-07-28 11:45:20 +03001825void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1826{
1827 // Queries about context capabilities and maximums are answered by Context.
1828 // Queries about current GL state values are answered by State.
1829
1830 GLenum nativeType;
1831 unsigned int numParams;
1832 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1833 ASSERT(queryStatus);
1834
1835 if (nativeType == GL_BOOL)
1836 {
1837 mGLState.getBooleani_v(target, index, data);
1838 }
1839 else
1840 {
1841 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1842 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001843}
1844
Brandon Jones59770802018-04-02 13:18:42 -07001845void Context::getBooleani_vRobust(GLenum target,
1846 GLuint index,
1847 GLsizei bufSize,
1848 GLsizei *length,
1849 GLboolean *data)
1850{
1851 getBooleani_v(target, index, data);
1852}
1853
Corentin Wallez336129f2017-10-17 15:55:40 -04001854void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001855{
1856 Buffer *buffer = mGLState.getTargetBuffer(target);
1857 QueryBufferParameteriv(buffer, pname, params);
1858}
1859
Brandon Jones59770802018-04-02 13:18:42 -07001860void Context::getBufferParameterivRobust(BufferBinding target,
1861 GLenum pname,
1862 GLsizei bufSize,
1863 GLsizei *length,
1864 GLint *params)
1865{
1866 getBufferParameteriv(target, pname, params);
1867}
1868
He Yunchao010e4db2017-03-03 14:22:06 +08001869void Context::getFramebufferAttachmentParameteriv(GLenum target,
1870 GLenum attachment,
1871 GLenum pname,
1872 GLint *params)
1873{
1874 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001875 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001876}
1877
Brandon Jones59770802018-04-02 13:18:42 -07001878void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1879 GLenum attachment,
1880 GLenum pname,
1881 GLsizei bufSize,
1882 GLsizei *length,
1883 GLint *params)
1884{
1885 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1886}
1887
He Yunchao010e4db2017-03-03 14:22:06 +08001888void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1889{
1890 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1891 QueryRenderbufferiv(this, renderbuffer, pname, params);
1892}
1893
Brandon Jones59770802018-04-02 13:18:42 -07001894void Context::getRenderbufferParameterivRobust(GLenum target,
1895 GLenum pname,
1896 GLsizei bufSize,
1897 GLsizei *length,
1898 GLint *params)
1899{
1900 getRenderbufferParameteriv(target, pname, params);
1901}
1902
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001903void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001904{
1905 Texture *texture = getTargetTexture(target);
1906 QueryTexParameterfv(texture, pname, params);
1907}
1908
Brandon Jones59770802018-04-02 13:18:42 -07001909void Context::getTexParameterfvRobust(TextureType target,
1910 GLenum pname,
1911 GLsizei bufSize,
1912 GLsizei *length,
1913 GLfloat *params)
1914{
1915 getTexParameterfv(target, pname, params);
1916}
1917
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001918void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001919{
1920 Texture *texture = getTargetTexture(target);
1921 QueryTexParameteriv(texture, pname, params);
1922}
Jiajia Qin5451d532017-11-16 17:16:34 +08001923
Brandon Jones59770802018-04-02 13:18:42 -07001924void Context::getTexParameterivRobust(TextureType target,
1925 GLenum pname,
1926 GLsizei bufSize,
1927 GLsizei *length,
1928 GLint *params)
1929{
1930 getTexParameteriv(target, pname, params);
1931}
1932
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001933void Context::getTexParameterIivRobust(TextureType target,
1934 GLenum pname,
1935 GLsizei bufSize,
1936 GLsizei *length,
1937 GLint *params)
1938{
1939 UNIMPLEMENTED();
1940}
1941
1942void Context::getTexParameterIuivRobust(TextureType target,
1943 GLenum pname,
1944 GLsizei bufSize,
1945 GLsizei *length,
1946 GLuint *params)
1947{
1948 UNIMPLEMENTED();
1949}
1950
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001951void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001952{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001953 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001954 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001955}
1956
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001957void Context::getTexLevelParameterivRobust(TextureTarget target,
1958 GLint level,
1959 GLenum pname,
1960 GLsizei bufSize,
1961 GLsizei *length,
1962 GLint *params)
1963{
1964 UNIMPLEMENTED();
1965}
1966
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001967void Context::getTexLevelParameterfv(TextureTarget target,
1968 GLint level,
1969 GLenum pname,
1970 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001971{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001972 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001973 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001974}
1975
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001976void Context::getTexLevelParameterfvRobust(TextureTarget target,
1977 GLint level,
1978 GLenum pname,
1979 GLsizei bufSize,
1980 GLsizei *length,
1981 GLfloat *params)
1982{
1983 UNIMPLEMENTED();
1984}
1985
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001986void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001987{
1988 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001989 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001990 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001991}
1992
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001993void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001994{
1995 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001996 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001997 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001998}
1999
Brandon Jones59770802018-04-02 13:18:42 -07002000void Context::texParameterfvRobust(TextureType target,
2001 GLenum pname,
2002 GLsizei bufSize,
2003 const GLfloat *params)
2004{
2005 texParameterfv(target, pname, params);
2006}
2007
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002008void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002009{
2010 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002011 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002012 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002013}
2014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002015void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002016{
2017 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002018 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002019 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002020}
2021
Brandon Jones59770802018-04-02 13:18:42 -07002022void Context::texParameterivRobust(TextureType target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 const GLint *params)
2026{
2027 texParameteriv(target, pname, params);
2028}
2029
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002030void Context::texParameterIivRobust(TextureType target,
2031 GLenum pname,
2032 GLsizei bufSize,
2033 const GLint *params)
2034{
2035 UNIMPLEMENTED();
2036}
2037
2038void Context::texParameterIuivRobust(TextureType target,
2039 GLenum pname,
2040 GLsizei bufSize,
2041 const GLuint *params)
2042{
2043 UNIMPLEMENTED();
2044}
2045
Jamie Madill675fe712016-12-19 13:07:54 -05002046void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002047{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002048 // No-op if zero count
2049 if (count == 0)
2050 {
2051 return;
2052 }
2053
Jamie Madill05b35b22017-10-03 09:01:44 -04002054 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002055 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002056 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002057}
2058
Jamie Madill675fe712016-12-19 13:07:54 -05002059void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002060{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002061 // No-op if zero count
2062 if (count == 0 || instanceCount == 0)
2063 {
2064 return;
2065 }
2066
Jamie Madill05b35b22017-10-03 09:01:44 -04002067 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002068 ANGLE_CONTEXT_TRY(
2069 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002070 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2071 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002072}
2073
Jamie Madill876429b2017-04-20 15:46:24 -04002074void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002075{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002076 // No-op if zero count
2077 if (count == 0)
2078 {
2079 return;
2080 }
2081
Jamie Madill05b35b22017-10-03 09:01:44 -04002082 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002083 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002084}
2085
Jamie Madill675fe712016-12-19 13:07:54 -05002086void Context::drawElementsInstanced(GLenum mode,
2087 GLsizei count,
2088 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002089 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002090 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002091{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002092 // No-op if zero count
2093 if (count == 0 || instances == 0)
2094 {
2095 return;
2096 }
2097
Jamie Madill05b35b22017-10-03 09:01:44 -04002098 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002099 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002100 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002101}
2102
Jamie Madill675fe712016-12-19 13:07:54 -05002103void Context::drawRangeElements(GLenum mode,
2104 GLuint start,
2105 GLuint end,
2106 GLsizei count,
2107 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002108 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002109{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002110 // No-op if zero count
2111 if (count == 0)
2112 {
2113 return;
2114 }
2115
Jamie Madill05b35b22017-10-03 09:01:44 -04002116 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002117 ANGLE_CONTEXT_TRY(
2118 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002119}
2120
Jamie Madill876429b2017-04-20 15:46:24 -04002121void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002122{
Jamie Madill05b35b22017-10-03 09:01:44 -04002123 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002124 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002125}
2126
Jamie Madill876429b2017-04-20 15:46:24 -04002127void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002128{
Jamie Madill05b35b22017-10-03 09:01:44 -04002129 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002130 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002131}
2132
Jamie Madill675fe712016-12-19 13:07:54 -05002133void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002134{
Jamie Madillafa02a22017-11-23 12:57:38 -05002135 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002136}
2137
Jamie Madill675fe712016-12-19 13:07:54 -05002138void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002139{
Jamie Madillafa02a22017-11-23 12:57:38 -05002140 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002141}
2142
Austin Kinross6ee1e782015-05-29 17:05:37 -07002143void Context::insertEventMarker(GLsizei length, const char *marker)
2144{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002145 ASSERT(mImplementation);
2146 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002147}
2148
2149void Context::pushGroupMarker(GLsizei length, const char *marker)
2150{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002151 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002152
2153 if (marker == nullptr)
2154 {
2155 // From the EXT_debug_marker spec,
2156 // "If <marker> is null then an empty string is pushed on the stack."
2157 mImplementation->pushGroupMarker(length, "");
2158 }
2159 else
2160 {
2161 mImplementation->pushGroupMarker(length, marker);
2162 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002163}
2164
2165void Context::popGroupMarker()
2166{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002167 ASSERT(mImplementation);
2168 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002169}
2170
Geoff Langd8605522016-04-13 10:19:12 -04002171void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2172{
2173 Program *programObject = getProgram(program);
2174 ASSERT(programObject);
2175
2176 programObject->bindUniformLocation(location, name);
2177}
2178
Brandon Jones59770802018-04-02 13:18:42 -07002179void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002180{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002181 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002182}
2183
Brandon Jones59770802018-04-02 13:18:42 -07002184void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002185{
2186 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2187}
2188
Brandon Jones59770802018-04-02 13:18:42 -07002189void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002190{
2191 GLfloat I[16];
2192 angle::Matrix<GLfloat>::setToIdentity(I);
2193
2194 mGLState.loadPathRenderingMatrix(matrixMode, I);
2195}
2196
2197void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2198{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002199 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002200 if (!pathObj)
2201 return;
2202
2203 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002204 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002205
2206 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2207}
2208
2209void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2210{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002211 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002212 if (!pathObj)
2213 return;
2214
2215 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002216 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002217
2218 mImplementation->stencilStrokePath(pathObj, reference, mask);
2219}
2220
2221void Context::coverFillPath(GLuint path, GLenum coverMode)
2222{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002223 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002224 if (!pathObj)
2225 return;
2226
2227 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002228 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229
2230 mImplementation->coverFillPath(pathObj, coverMode);
2231}
2232
2233void Context::coverStrokePath(GLuint path, GLenum coverMode)
2234{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002235 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002236 if (!pathObj)
2237 return;
2238
2239 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002240 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002241
2242 mImplementation->coverStrokePath(pathObj, coverMode);
2243}
2244
2245void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2246{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002247 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002248 if (!pathObj)
2249 return;
2250
2251 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002252 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002253
2254 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2255}
2256
2257void Context::stencilThenCoverStrokePath(GLuint path,
2258 GLint reference,
2259 GLuint mask,
2260 GLenum coverMode)
2261{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002262 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002263 if (!pathObj)
2264 return;
2265
2266 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002267 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002268
2269 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2270}
2271
Sami Väisänend59ca052016-06-21 16:10:00 +03002272void Context::coverFillPathInstanced(GLsizei numPaths,
2273 GLenum pathNameType,
2274 const void *paths,
2275 GLuint pathBase,
2276 GLenum coverMode,
2277 GLenum transformType,
2278 const GLfloat *transformValues)
2279{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002280 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002281
2282 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002283 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002284
2285 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2286}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002287
Sami Väisänend59ca052016-06-21 16:10:00 +03002288void Context::coverStrokePathInstanced(GLsizei numPaths,
2289 GLenum pathNameType,
2290 const void *paths,
2291 GLuint pathBase,
2292 GLenum coverMode,
2293 GLenum transformType,
2294 const GLfloat *transformValues)
2295{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002296 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002297
2298 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002299 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002300
2301 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2302 transformValues);
2303}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002304
Sami Väisänend59ca052016-06-21 16:10:00 +03002305void Context::stencilFillPathInstanced(GLsizei numPaths,
2306 GLenum pathNameType,
2307 const void *paths,
2308 GLuint pathBase,
2309 GLenum fillMode,
2310 GLuint mask,
2311 GLenum transformType,
2312 const GLfloat *transformValues)
2313{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002314 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002315
2316 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002317 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002318
2319 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2320 transformValues);
2321}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002322
Sami Väisänend59ca052016-06-21 16:10:00 +03002323void Context::stencilStrokePathInstanced(GLsizei numPaths,
2324 GLenum pathNameType,
2325 const void *paths,
2326 GLuint pathBase,
2327 GLint reference,
2328 GLuint mask,
2329 GLenum transformType,
2330 const GLfloat *transformValues)
2331{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002332 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002333
2334 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002335 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002336
2337 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2338 transformValues);
2339}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002340
Sami Väisänend59ca052016-06-21 16:10:00 +03002341void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2342 GLenum pathNameType,
2343 const void *paths,
2344 GLuint pathBase,
2345 GLenum fillMode,
2346 GLuint mask,
2347 GLenum coverMode,
2348 GLenum transformType,
2349 const GLfloat *transformValues)
2350{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002351 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002352
2353 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002354 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002355
2356 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2357 transformType, transformValues);
2358}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002359
Sami Väisänend59ca052016-06-21 16:10:00 +03002360void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2361 GLenum pathNameType,
2362 const void *paths,
2363 GLuint pathBase,
2364 GLint reference,
2365 GLuint mask,
2366 GLenum coverMode,
2367 GLenum transformType,
2368 const GLfloat *transformValues)
2369{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002370 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002373 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002374
2375 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2376 transformType, transformValues);
2377}
2378
Sami Väisänen46eaa942016-06-29 10:26:37 +03002379void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2380{
2381 auto *programObject = getProgram(program);
2382
2383 programObject->bindFragmentInputLocation(location, name);
2384}
2385
2386void Context::programPathFragmentInputGen(GLuint program,
2387 GLint location,
2388 GLenum genMode,
2389 GLint components,
2390 const GLfloat *coeffs)
2391{
2392 auto *programObject = getProgram(program);
2393
Jamie Madillbd044ed2017-06-05 12:59:21 -04002394 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002395}
2396
jchen1015015f72017-03-16 13:54:21 +08002397GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2398{
jchen10fd7c3b52017-03-21 15:36:03 +08002399 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002400 return QueryProgramResourceIndex(programObject, programInterface, name);
2401}
2402
jchen10fd7c3b52017-03-21 15:36:03 +08002403void Context::getProgramResourceName(GLuint program,
2404 GLenum programInterface,
2405 GLuint index,
2406 GLsizei bufSize,
2407 GLsizei *length,
2408 GLchar *name)
2409{
2410 const auto *programObject = getProgram(program);
2411 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2412}
2413
jchen10191381f2017-04-11 13:59:04 +08002414GLint Context::getProgramResourceLocation(GLuint program,
2415 GLenum programInterface,
2416 const GLchar *name)
2417{
2418 const auto *programObject = getProgram(program);
2419 return QueryProgramResourceLocation(programObject, programInterface, name);
2420}
2421
jchen10880683b2017-04-12 16:21:55 +08002422void Context::getProgramResourceiv(GLuint program,
2423 GLenum programInterface,
2424 GLuint index,
2425 GLsizei propCount,
2426 const GLenum *props,
2427 GLsizei bufSize,
2428 GLsizei *length,
2429 GLint *params)
2430{
2431 const auto *programObject = getProgram(program);
2432 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2433 length, params);
2434}
2435
jchen10d9cd7b72017-08-30 15:04:25 +08002436void Context::getProgramInterfaceiv(GLuint program,
2437 GLenum programInterface,
2438 GLenum pname,
2439 GLint *params)
2440{
2441 const auto *programObject = getProgram(program);
2442 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2443}
2444
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002445void Context::getProgramInterfaceivRobust(GLuint program,
2446 GLenum programInterface,
2447 GLenum pname,
2448 GLsizei bufSize,
2449 GLsizei *length,
2450 GLint *params)
2451{
2452 UNIMPLEMENTED();
2453}
2454
Jamie Madill427064d2018-04-13 16:20:34 -04002455void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002456{
Geoff Langda5777c2014-07-11 09:52:58 -04002457 if (error.isError())
2458 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002459 GLenum code = error.getCode();
2460 mErrors.insert(code);
2461 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2462 {
2463 markContextLost();
2464 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002465
Geoff Langee6884e2017-11-09 16:51:11 -05002466 ASSERT(!error.getMessage().empty());
2467 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2468 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002469 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002470}
2471
2472// Get one of the recorded errors and clear its flag, if any.
2473// [OpenGL ES 2.0.24] section 2.5 page 13.
2474GLenum Context::getError()
2475{
Geoff Langda5777c2014-07-11 09:52:58 -04002476 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002477 {
Geoff Langda5777c2014-07-11 09:52:58 -04002478 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002479 }
Geoff Langda5777c2014-07-11 09:52:58 -04002480 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481 {
Geoff Langda5777c2014-07-11 09:52:58 -04002482 GLenum error = *mErrors.begin();
2483 mErrors.erase(mErrors.begin());
2484 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486}
2487
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002488// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002489void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002490{
2491 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002492 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002493 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002494 mContextLostForced = true;
2495 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002496 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002497}
2498
Jamie Madill427064d2018-04-13 16:20:34 -04002499bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002500{
2501 return mContextLost;
2502}
2503
Jamie Madillfa920eb2018-01-04 11:45:50 -05002504GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002506 // Even if the application doesn't want to know about resets, we want to know
2507 // as it will allow us to skip all the calls.
2508 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002511 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002512 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002513 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514
2515 // EXT_robustness, section 2.6: If the reset notification behavior is
2516 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2517 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2518 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002519 }
2520
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002521 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2522 // status should be returned at least once, and GL_NO_ERROR should be returned
2523 // once the device has finished resetting.
2524 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002526 ASSERT(mResetStatus == GL_NO_ERROR);
2527 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002528
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002529 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002532 }
2533 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002534 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002536 // If markContextLost was used to mark the context lost then
2537 // assume that is not recoverable, and continue to report the
2538 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539 mResetStatus = mImplementation->getResetStatus();
2540 }
Jamie Madill893ab082014-05-16 16:56:10 -04002541
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002543}
2544
2545bool Context::isResetNotificationEnabled()
2546{
2547 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2548}
2549
Corentin Walleze3b10e82015-05-20 11:06:25 -04002550const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002551{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002552 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002553}
2554
2555EGLenum Context::getClientType() const
2556{
2557 return mClientType;
2558}
2559
2560EGLenum Context::getRenderBuffer() const
2561{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002562 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2563 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002564 {
2565 return EGL_NONE;
2566 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002567
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002568 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002569 ASSERT(backAttachment != nullptr);
2570 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002571}
2572
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002573VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002574{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002575 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002576 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2577 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002578 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002579 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2580 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002581
Jamie Madill96a483b2017-06-27 16:49:21 -04002582 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002583 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002584
2585 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002586}
2587
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002588TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002589{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002590 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002591 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2592 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002593 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002594 transformFeedback =
2595 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002596 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002597 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002598 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002599
2600 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002601}
2602
2603bool Context::isVertexArrayGenerated(GLuint vertexArray)
2604{
Jamie Madill96a483b2017-06-27 16:49:21 -04002605 ASSERT(mVertexArrayMap.contains(0));
2606 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002607}
2608
2609bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2610{
Jamie Madill96a483b2017-06-27 16:49:21 -04002611 ASSERT(mTransformFeedbackMap.contains(0));
2612 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002613}
2614
Shannon Woods53a94a82014-06-24 15:20:36 -04002615void Context::detachTexture(GLuint texture)
2616{
2617 // Simple pass-through to State's detachTexture method, as textures do not require
2618 // allocation map management either here or in the resource manager at detach time.
2619 // Zero textures are held by the Context, and we don't attempt to request them from
2620 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002621 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002622}
2623
James Darpinian4d9d4832018-03-13 12:43:28 -07002624void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625{
Yuly Novikov5807a532015-12-03 13:01:22 -05002626 // Simple pass-through to State's detachBuffer method, since
2627 // only buffer attachments to container objects that are bound to the current context
2628 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002629
Yuly Novikov5807a532015-12-03 13:01:22 -05002630 // [OpenGL ES 3.2] section 5.1.2 page 45:
2631 // Attachments to unbound container objects, such as
2632 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2633 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002634 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002635}
2636
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637void Context::detachFramebuffer(GLuint framebuffer)
2638{
Shannon Woods53a94a82014-06-24 15:20:36 -04002639 // Framebuffer detachment is handled by Context, because 0 is a valid
2640 // Framebuffer object, and a pointer to it must be passed from Context
2641 // to State at binding time.
2642
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002644 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2645 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2646 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002648 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649 {
2650 bindReadFramebuffer(0);
2651 }
2652
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002653 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654 {
2655 bindDrawFramebuffer(0);
2656 }
2657}
2658
2659void Context::detachRenderbuffer(GLuint renderbuffer)
2660{
Jamie Madilla02315b2017-02-23 14:14:47 -05002661 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662}
2663
Jamie Madill57a89722013-07-02 11:57:03 -04002664void Context::detachVertexArray(GLuint vertexArray)
2665{
Jamie Madill77a72f62015-04-14 11:18:32 -04002666 // Vertex array detachment is handled by Context, because 0 is a valid
2667 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002668 // binding time.
2669
Jamie Madill57a89722013-07-02 11:57:03 -04002670 // [OpenGL ES 3.0.2] section 2.10 page 43:
2671 // If a vertex array object that is currently bound is deleted, the binding
2672 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002673 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002674 {
2675 bindVertexArray(0);
2676 }
2677}
2678
Geoff Langc8058452014-02-03 12:04:11 -05002679void Context::detachTransformFeedback(GLuint transformFeedback)
2680{
Corentin Walleza2257da2016-04-19 16:43:12 -04002681 // Transform feedback detachment is handled by Context, because 0 is a valid
2682 // transform feedback, and a pointer to it must be passed from Context to State at
2683 // binding time.
2684
2685 // The OpenGL specification doesn't mention what should happen when the currently bound
2686 // transform feedback object is deleted. Since it is a container object, we treat it like
2687 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002688 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002689 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002690 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002691 }
Geoff Langc8058452014-02-03 12:04:11 -05002692}
2693
Jamie Madilldc356042013-07-19 16:36:57 -04002694void Context::detachSampler(GLuint sampler)
2695{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002696 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002697}
2698
Yunchao Hea336b902017-08-02 16:05:21 +08002699void Context::detachProgramPipeline(GLuint pipeline)
2700{
2701 mGLState.detachProgramPipeline(this, pipeline);
2702}
2703
Jamie Madill3ef140a2017-08-26 23:11:21 -04002704void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002705{
Shaodde78e82017-05-22 14:13:27 +08002706 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002707}
2708
Jamie Madille29d1672013-07-19 16:36:57 -04002709void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2710{
Geoff Langc1984ed2016-10-07 12:41:00 -04002711 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002712 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002713 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002714 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002715}
Jamie Madille29d1672013-07-19 16:36:57 -04002716
Geoff Langc1984ed2016-10-07 12:41:00 -04002717void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2718{
2719 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002720 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002721 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002722 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002723}
2724
Brandon Jones59770802018-04-02 13:18:42 -07002725void Context::samplerParameterivRobust(GLuint sampler,
2726 GLenum pname,
2727 GLsizei bufSize,
2728 const GLint *param)
2729{
2730 samplerParameteriv(sampler, pname, param);
2731}
2732
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002733void Context::samplerParameterIivRobust(GLuint sampler,
2734 GLenum pname,
2735 GLsizei bufSize,
2736 const GLint *param)
2737{
2738 UNIMPLEMENTED();
2739}
2740
2741void Context::samplerParameterIuivRobust(GLuint sampler,
2742 GLenum pname,
2743 GLsizei bufSize,
2744 const GLuint *param)
2745{
2746 UNIMPLEMENTED();
2747}
2748
Jamie Madille29d1672013-07-19 16:36:57 -04002749void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2750{
Geoff Langc1984ed2016-10-07 12:41:00 -04002751 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002752 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002753 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002754 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002755}
2756
Geoff Langc1984ed2016-10-07 12:41:00 -04002757void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002758{
Geoff Langc1984ed2016-10-07 12:41:00 -04002759 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002760 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002761 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002762 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002763}
2764
Brandon Jones59770802018-04-02 13:18:42 -07002765void Context::samplerParameterfvRobust(GLuint sampler,
2766 GLenum pname,
2767 GLsizei bufSize,
2768 const GLfloat *param)
2769{
2770 samplerParameterfv(sampler, pname, param);
2771}
2772
Geoff Langc1984ed2016-10-07 12:41:00 -04002773void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002779}
Jamie Madill9675b802013-07-19 16:36:59 -04002780
Brandon Jones59770802018-04-02 13:18:42 -07002781void Context::getSamplerParameterivRobust(GLuint sampler,
2782 GLenum pname,
2783 GLsizei bufSize,
2784 GLsizei *length,
2785 GLint *params)
2786{
2787 getSamplerParameteriv(sampler, pname, params);
2788}
2789
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002790void Context::getSamplerParameterIivRobust(GLuint sampler,
2791 GLenum pname,
2792 GLsizei bufSize,
2793 GLsizei *length,
2794 GLint *params)
2795{
2796 UNIMPLEMENTED();
2797}
2798
2799void Context::getSamplerParameterIuivRobust(GLuint sampler,
2800 GLenum pname,
2801 GLsizei bufSize,
2802 GLsizei *length,
2803 GLuint *params)
2804{
2805 UNIMPLEMENTED();
2806}
2807
Geoff Langc1984ed2016-10-07 12:41:00 -04002808void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2809{
2810 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002811 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002813 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002814}
2815
Brandon Jones59770802018-04-02 13:18:42 -07002816void Context::getSamplerParameterfvRobust(GLuint sampler,
2817 GLenum pname,
2818 GLsizei bufSize,
2819 GLsizei *length,
2820 GLfloat *params)
2821{
2822 getSamplerParameterfv(sampler, pname, params);
2823}
2824
Olli Etuahof0fee072016-03-30 15:11:58 +03002825void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2826{
2827 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002828 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002829}
2830
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002831void Context::initRendererString()
2832{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002833 std::ostringstream rendererString;
2834 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002835 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002836 rendererString << ")";
2837
Geoff Langcec35902014-04-16 10:52:36 -04002838 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002839}
2840
Geoff Langc339c4e2016-11-29 10:37:36 -05002841void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002842{
Geoff Langc339c4e2016-11-29 10:37:36 -05002843 const Version &clientVersion = getClientVersion();
2844
2845 std::ostringstream versionString;
2846 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2847 << ANGLE_VERSION_STRING << ")";
2848 mVersionString = MakeStaticString(versionString.str());
2849
2850 std::ostringstream shadingLanguageVersionString;
2851 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2852 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2853 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2854 << ")";
2855 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002856}
2857
Geoff Langcec35902014-04-16 10:52:36 -04002858void Context::initExtensionStrings()
2859{
Geoff Langc339c4e2016-11-29 10:37:36 -05002860 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2861 std::ostringstream combinedStringStream;
2862 std::copy(strings.begin(), strings.end(),
2863 std::ostream_iterator<const char *>(combinedStringStream, " "));
2864 return MakeStaticString(combinedStringStream.str());
2865 };
2866
2867 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002868 for (const auto &extensionString : mExtensions.getStrings())
2869 {
2870 mExtensionStrings.push_back(MakeStaticString(extensionString));
2871 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002872 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002873
Bryan Bernhart58806562017-01-05 13:09:31 -08002874 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2875
Geoff Langc339c4e2016-11-29 10:37:36 -05002876 mRequestableExtensionStrings.clear();
2877 for (const auto &extensionInfo : GetExtensionInfoMap())
2878 {
2879 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002880 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2881 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002882 {
2883 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2884 }
2885 }
2886 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002887}
2888
Geoff Langc339c4e2016-11-29 10:37:36 -05002889const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002890{
Geoff Langc339c4e2016-11-29 10:37:36 -05002891 switch (name)
2892 {
2893 case GL_VENDOR:
2894 return reinterpret_cast<const GLubyte *>("Google Inc.");
2895
2896 case GL_RENDERER:
2897 return reinterpret_cast<const GLubyte *>(mRendererString);
2898
2899 case GL_VERSION:
2900 return reinterpret_cast<const GLubyte *>(mVersionString);
2901
2902 case GL_SHADING_LANGUAGE_VERSION:
2903 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2904
2905 case GL_EXTENSIONS:
2906 return reinterpret_cast<const GLubyte *>(mExtensionString);
2907
2908 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2909 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2910
2911 default:
2912 UNREACHABLE();
2913 return nullptr;
2914 }
Geoff Langcec35902014-04-16 10:52:36 -04002915}
2916
Geoff Langc339c4e2016-11-29 10:37:36 -05002917const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002918{
Geoff Langc339c4e2016-11-29 10:37:36 -05002919 switch (name)
2920 {
2921 case GL_EXTENSIONS:
2922 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2923
2924 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2925 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2926
2927 default:
2928 UNREACHABLE();
2929 return nullptr;
2930 }
Geoff Langcec35902014-04-16 10:52:36 -04002931}
2932
2933size_t Context::getExtensionStringCount() const
2934{
2935 return mExtensionStrings.size();
2936}
2937
Geoff Lang111a99e2017-10-17 10:58:41 -04002938bool Context::isExtensionRequestable(const char *name)
2939{
2940 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2941 auto extension = extensionInfos.find(name);
2942
2943 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2944 return extension != extensionInfos.end() && extension->second.Requestable &&
2945 nativeExtensions.*(extension->second.ExtensionsMember);
2946}
2947
Geoff Langc339c4e2016-11-29 10:37:36 -05002948void Context::requestExtension(const char *name)
2949{
2950 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2951 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2952 const auto &extension = extensionInfos.at(name);
2953 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002954 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002955
2956 if (mExtensions.*(extension.ExtensionsMember))
2957 {
2958 // Extension already enabled
2959 return;
2960 }
2961
2962 mExtensions.*(extension.ExtensionsMember) = true;
2963 updateCaps();
2964 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002965
Jamie Madill2f348d22017-06-05 10:50:59 -04002966 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2967 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002968
Jamie Madill81c2e252017-09-09 23:32:46 -04002969 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2970 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002971 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002972 for (auto &zeroTexture : mZeroTextures)
2973 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002974 if (zeroTexture.get() != nullptr)
2975 {
2976 zeroTexture->signalDirty(this, InitState::Initialized);
2977 }
Geoff Lang9aded172017-04-05 11:07:56 -04002978 }
2979
2980 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002981}
2982
2983size_t Context::getRequestableExtensionStringCount() const
2984{
2985 return mRequestableExtensionStrings.size();
2986}
2987
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002988void Context::beginTransformFeedback(GLenum primitiveMode)
2989{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002990 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002991 ASSERT(transformFeedback != nullptr);
2992 ASSERT(!transformFeedback->isPaused());
2993
Jamie Madill6c1f6712017-02-14 19:08:04 -05002994 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002995}
2996
2997bool Context::hasActiveTransformFeedback(GLuint program) const
2998{
2999 for (auto pair : mTransformFeedbackMap)
3000 {
3001 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3002 {
3003 return true;
3004 }
3005 }
3006 return false;
3007}
3008
Geoff Langb433e872017-10-05 14:01:47 -04003009void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003010{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003011 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003012
Lingfeng Yang01074432018-04-16 10:19:51 -07003013 mExtensions = mImplementation->getNativeExtensions();
3014
3015 mLimitations = mImplementation->getNativeLimitations();
3016
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003017 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3018 if (getClientVersion() < Version(2, 0))
3019 {
3020 mCaps.maxMultitextureUnits = 4;
3021 mCaps.maxClipPlanes = 6;
3022 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003023 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3024 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3025 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang01074432018-04-16 10:19:51 -07003026
3027 // Default extensions for GLES1
3028 mExtensions.pointSizeArray = true;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003029 }
3030
Geoff Langeb66a6e2016-10-31 13:06:12 -04003031 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04003032 {
3033 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04003034 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04003035 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02003036 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03003037 mExtensions.multiview = false;
3038 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04003039 }
3040
Jiawei Shao89be29a2017-11-06 14:36:45 +08003041 if (getClientVersion() < ES_3_1)
3042 {
3043 // Disable ES3.1+ extensions
3044 mExtensions.geometryShader = false;
3045 }
3046
Geoff Langeb66a6e2016-10-31 13:06:12 -04003047 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04003048 {
3049 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04003050 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04003051 }
3052
Jamie Madill00ed7a12016-05-19 13:13:38 -04003053 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04003054 mExtensions.bindUniformLocation = true;
3055 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04003056 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05003057 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003058 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04003059
3060 // Enable the no error extension if the context was created with the flag.
3061 mExtensions.noError = mSkipValidation;
3062
Corentin Wallezccab69d2017-01-27 16:57:15 -05003063 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05003064 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05003065
Geoff Lang70d0f492015-12-10 17:45:46 -05003066 // Explicitly enable GL_KHR_debug
3067 mExtensions.debug = true;
3068 mExtensions.maxDebugMessageLength = 1024;
3069 mExtensions.maxDebugLoggedMessages = 1024;
3070 mExtensions.maxDebugGroupStackDepth = 1024;
3071 mExtensions.maxLabelLength = 1024;
3072
Geoff Langff5b2d52016-09-07 11:32:23 -04003073 // Explicitly enable GL_ANGLE_robust_client_memory
3074 mExtensions.robustClientMemory = true;
3075
Jamie Madille08a1d32017-03-07 17:24:06 -05003076 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04003077 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05003078
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08003079 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3080 // supports it.
3081 mExtensions.robustBufferAccessBehavior =
3082 mRobustAccess && mExtensions.robustBufferAccessBehavior;
3083
Jamie Madillc43be722017-07-13 16:22:14 -04003084 // Enable the cache control query unconditionally.
3085 mExtensions.programCacheControl = true;
3086
Geoff Lang301d1612014-07-09 10:34:37 -04003087 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003088 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003089
Jamie Madill0f80ed82017-09-19 00:24:56 -04003090 if (getClientVersion() < ES_3_1)
3091 {
3092 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3093 }
3094 else
3095 {
3096 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3097 }
Geoff Lang301d1612014-07-09 10:34:37 -04003098
Jamie Madill0f80ed82017-09-19 00:24:56 -04003099 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
3100 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3101 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3102
3103 // Limit textures as well, so we can use fast bitsets with texture bindings.
3104 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3105 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3106 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003107
Jiawei Shaodb342272017-09-27 10:21:45 +08003108 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3109
Geoff Langc287ea62016-09-16 14:46:51 -04003110 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003111 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003112 for (const auto &extensionInfo : GetExtensionInfoMap())
3113 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003114 // If the user has requested that extensions start disabled and they are requestable,
3115 // disable them.
3116 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003117 {
3118 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3119 }
3120 }
3121
3122 // Generate texture caps
3123 updateCaps();
3124}
3125
3126void Context::updateCaps()
3127{
Geoff Lang900013c2014-07-07 11:32:19 -04003128 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003129 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003130
Jamie Madill7b62cf92017-11-02 15:20:49 -04003131 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003132 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003133 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003134 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003135
Geoff Lang0d8b7242015-09-09 14:56:53 -04003136 // Update the format caps based on the client version and extensions.
3137 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3138 // ES3.
3139 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003140 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003141 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003142 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003143 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003144 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003145
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003146 // OpenGL ES does not support multisampling with non-rendererable formats
3147 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003148 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003149 (getClientVersion() < ES_3_1 &&
3150 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003151 {
Geoff Langd87878e2014-09-19 15:42:59 -04003152 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003153 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003154 else
3155 {
3156 // We may have limited the max samples for some required renderbuffer formats due to
3157 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3158 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3159
3160 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3161 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3162 // exception of signed and unsigned integer formats."
3163 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3164 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3165 {
3166 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3167 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3168 }
3169
3170 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3171 if (getClientVersion() >= ES_3_1)
3172 {
3173 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3174 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3175 // the exception that the signed and unsigned integer formats are required only to
3176 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3177 // multisamples, which must be at least one."
3178 if (formatInfo.componentType == GL_INT ||
3179 formatInfo.componentType == GL_UNSIGNED_INT)
3180 {
3181 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3182 }
3183
3184 // GLES 3.1 section 19.3.1.
3185 if (formatCaps.texturable)
3186 {
3187 if (formatInfo.depthBits > 0)
3188 {
3189 mCaps.maxDepthTextureSamples =
3190 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3191 }
3192 else if (formatInfo.redBits > 0)
3193 {
3194 mCaps.maxColorTextureSamples =
3195 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3196 }
3197 }
3198 }
3199 }
Geoff Langd87878e2014-09-19 15:42:59 -04003200
3201 if (formatCaps.texturable && formatInfo.compressed)
3202 {
Geoff Langca271392017-04-05 12:30:00 -04003203 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003204 }
3205
Geoff Langca271392017-04-05 12:30:00 -04003206 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003207 }
Jamie Madill32447362017-06-28 14:53:52 -04003208
3209 // If program binary is disabled, blank out the memory cache pointer.
3210 if (!mImplementation->getNativeExtensions().getProgramBinary)
3211 {
3212 mMemoryProgramCache = nullptr;
3213 }
Corentin Walleze4477002017-12-01 14:39:58 -05003214
3215 // Compute which buffer types are allowed
3216 mValidBufferBindings.reset();
3217 mValidBufferBindings.set(BufferBinding::ElementArray);
3218 mValidBufferBindings.set(BufferBinding::Array);
3219
3220 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3221 {
3222 mValidBufferBindings.set(BufferBinding::PixelPack);
3223 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3224 }
3225
3226 if (getClientVersion() >= ES_3_0)
3227 {
3228 mValidBufferBindings.set(BufferBinding::CopyRead);
3229 mValidBufferBindings.set(BufferBinding::CopyWrite);
3230 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3231 mValidBufferBindings.set(BufferBinding::Uniform);
3232 }
3233
3234 if (getClientVersion() >= ES_3_1)
3235 {
3236 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3237 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3238 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3239 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3240 }
Geoff Lang493daf52014-07-03 13:38:44 -04003241}
3242
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003243void Context::initWorkarounds()
3244{
Jamie Madill761b02c2017-06-23 16:27:06 -04003245 // Apply back-end workarounds.
3246 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3247
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003248 // Lose the context upon out of memory error if the application is
3249 // expecting to watch for those events.
3250 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3251}
3252
Jamie Madill05b35b22017-10-03 09:01:44 -04003253Error Context::prepareForDraw()
3254{
Geoff Langa8cb2872018-03-09 16:09:40 -05003255 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003256
3257 if (isRobustResourceInitEnabled())
3258 {
3259 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3260 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3261 }
3262
Geoff Langa8cb2872018-03-09 16:09:40 -05003263 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003264 return NoError();
3265}
3266
3267Error Context::prepareForClear(GLbitfield mask)
3268{
Geoff Langa8cb2872018-03-09 16:09:40 -05003269 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003270 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003271 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003272 return NoError();
3273}
3274
3275Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3276{
Geoff Langa8cb2872018-03-09 16:09:40 -05003277 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003278 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3279 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003280 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003281 return NoError();
3282}
3283
Geoff Langa8cb2872018-03-09 16:09:40 -05003284Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003285{
Geoff Langa8cb2872018-03-09 16:09:40 -05003286 ANGLE_TRY(syncDirtyObjects());
3287 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003288 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003289}
3290
Geoff Langa8cb2872018-03-09 16:09:40 -05003291Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003292{
Geoff Langa8cb2872018-03-09 16:09:40 -05003293 ANGLE_TRY(syncDirtyObjects(objectMask));
3294 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003295 return NoError();
3296}
3297
Geoff Langa8cb2872018-03-09 16:09:40 -05003298Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003299{
3300 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3301 mImplementation->syncState(this, dirtyBits);
3302 mGLState.clearDirtyBits();
3303 return NoError();
3304}
3305
Geoff Langa8cb2872018-03-09 16:09:40 -05003306Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003307{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003308 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003309 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003310 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003311 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003312}
Jamie Madillc29968b2016-01-20 11:17:23 -05003313
Geoff Langa8cb2872018-03-09 16:09:40 -05003314Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003315{
3316 return mGLState.syncDirtyObjects(this);
3317}
3318
Geoff Langa8cb2872018-03-09 16:09:40 -05003319Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003320{
3321 return mGLState.syncDirtyObjects(this, objectMask);
3322}
3323
Jamie Madillc29968b2016-01-20 11:17:23 -05003324void Context::blitFramebuffer(GLint srcX0,
3325 GLint srcY0,
3326 GLint srcX1,
3327 GLint srcY1,
3328 GLint dstX0,
3329 GLint dstY0,
3330 GLint dstX1,
3331 GLint dstY1,
3332 GLbitfield mask,
3333 GLenum filter)
3334{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003335 if (mask == 0)
3336 {
3337 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3338 // buffers are copied.
3339 return;
3340 }
3341
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003342 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003343 ASSERT(drawFramebuffer);
3344
3345 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3346 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3347
Jamie Madillbc918e72018-03-08 09:47:21 -05003348 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003349
Jamie Madillc564c072017-06-01 12:45:42 -04003350 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003351}
Jamie Madillc29968b2016-01-20 11:17:23 -05003352
3353void Context::clear(GLbitfield mask)
3354{
Geoff Langd4fff502017-09-22 11:28:28 -04003355 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3356 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003357}
3358
3359void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3360{
Geoff Langd4fff502017-09-22 11:28:28 -04003361 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3362 ANGLE_CONTEXT_TRY(
3363 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003364}
3365
3366void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3367{
Geoff Langd4fff502017-09-22 11:28:28 -04003368 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3369 ANGLE_CONTEXT_TRY(
3370 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003371}
3372
3373void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3374{
Geoff Langd4fff502017-09-22 11:28:28 -04003375 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3376 ANGLE_CONTEXT_TRY(
3377 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003378}
3379
3380void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3381{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003382 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003383 ASSERT(framebufferObject);
3384
3385 // If a buffer is not present, the clear has no effect
3386 if (framebufferObject->getDepthbuffer() == nullptr &&
3387 framebufferObject->getStencilbuffer() == nullptr)
3388 {
3389 return;
3390 }
3391
Geoff Langd4fff502017-09-22 11:28:28 -04003392 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3393 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003394}
3395
3396void Context::readPixels(GLint x,
3397 GLint y,
3398 GLsizei width,
3399 GLsizei height,
3400 GLenum format,
3401 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003402 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003403{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003404 if (width == 0 || height == 0)
3405 {
3406 return;
3407 }
3408
Jamie Madillbc918e72018-03-08 09:47:21 -05003409 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003410
Jamie Madillb6664922017-07-25 12:55:04 -04003411 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3412 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003413
3414 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003415 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003416}
3417
Brandon Jones59770802018-04-02 13:18:42 -07003418void Context::readPixelsRobust(GLint x,
3419 GLint y,
3420 GLsizei width,
3421 GLsizei height,
3422 GLenum format,
3423 GLenum type,
3424 GLsizei bufSize,
3425 GLsizei *length,
3426 GLsizei *columns,
3427 GLsizei *rows,
3428 void *pixels)
3429{
3430 readPixels(x, y, width, height, format, type, pixels);
3431}
3432
3433void Context::readnPixelsRobust(GLint x,
3434 GLint y,
3435 GLsizei width,
3436 GLsizei height,
3437 GLenum format,
3438 GLenum type,
3439 GLsizei bufSize,
3440 GLsizei *length,
3441 GLsizei *columns,
3442 GLsizei *rows,
3443 void *data)
3444{
3445 readPixels(x, y, width, height, format, type, data);
3446}
3447
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003448void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003449 GLint level,
3450 GLenum internalformat,
3451 GLint x,
3452 GLint y,
3453 GLsizei width,
3454 GLsizei height,
3455 GLint border)
3456{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003457 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003458 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003459
Jamie Madillc29968b2016-01-20 11:17:23 -05003460 Rectangle sourceArea(x, y, width, height);
3461
Jamie Madill05b35b22017-10-03 09:01:44 -04003462 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003463 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003464 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003465}
3466
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003467void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003468 GLint level,
3469 GLint xoffset,
3470 GLint yoffset,
3471 GLint x,
3472 GLint y,
3473 GLsizei width,
3474 GLsizei height)
3475{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003476 if (width == 0 || height == 0)
3477 {
3478 return;
3479 }
3480
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003481 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003482 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003483
Jamie Madillc29968b2016-01-20 11:17:23 -05003484 Offset destOffset(xoffset, yoffset, 0);
3485 Rectangle sourceArea(x, y, width, height);
3486
Jamie Madill05b35b22017-10-03 09:01:44 -04003487 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003488 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003489 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003490}
3491
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003492void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003493 GLint level,
3494 GLint xoffset,
3495 GLint yoffset,
3496 GLint zoffset,
3497 GLint x,
3498 GLint y,
3499 GLsizei width,
3500 GLsizei height)
3501{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003502 if (width == 0 || height == 0)
3503 {
3504 return;
3505 }
3506
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003507 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003508 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003509
Jamie Madillc29968b2016-01-20 11:17:23 -05003510 Offset destOffset(xoffset, yoffset, zoffset);
3511 Rectangle sourceArea(x, y, width, height);
3512
Jamie Madill05b35b22017-10-03 09:01:44 -04003513 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3514 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003515 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3516 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003517}
3518
3519void Context::framebufferTexture2D(GLenum target,
3520 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003521 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003522 GLuint texture,
3523 GLint level)
3524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003525 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003526 ASSERT(framebuffer);
3527
3528 if (texture != 0)
3529 {
3530 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003531 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003532 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003533 }
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::framebufferRenderbuffer(GLenum target,
3543 GLenum attachment,
3544 GLenum renderbuffertarget,
3545 GLuint renderbuffer)
3546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003547 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003548 ASSERT(framebuffer);
3549
3550 if (renderbuffer != 0)
3551 {
3552 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003553
Jamie Madillcc129372018-04-12 09:13:18 -04003554 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003555 renderbufferObject);
3556 }
3557 else
3558 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003559 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003560 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003561
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003562 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003563}
3564
3565void Context::framebufferTextureLayer(GLenum target,
3566 GLenum attachment,
3567 GLuint texture,
3568 GLint level,
3569 GLint layer)
3570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003571 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003572 ASSERT(framebuffer);
3573
3574 if (texture != 0)
3575 {
3576 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003577 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003578 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 }
3580 else
3581 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003582 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003583 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003584
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003585 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003586}
3587
Brandon Jones59770802018-04-02 13:18:42 -07003588void Context::framebufferTextureMultiviewLayered(GLenum target,
3589 GLenum attachment,
3590 GLuint texture,
3591 GLint level,
3592 GLint baseViewIndex,
3593 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003594{
Martin Radev82ef7742017-08-08 17:44:58 +03003595 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3596 ASSERT(framebuffer);
3597
3598 if (texture != 0)
3599 {
3600 Texture *textureObj = getTexture(texture);
3601
Martin Radev18b75ba2017-08-15 15:50:40 +03003602 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003603 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3604 numViews, baseViewIndex);
3605 }
3606 else
3607 {
3608 framebuffer->resetAttachment(this, attachment);
3609 }
3610
3611 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003612}
3613
Brandon Jones59770802018-04-02 13:18:42 -07003614void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3615 GLenum attachment,
3616 GLuint texture,
3617 GLint level,
3618 GLsizei numViews,
3619 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003620{
Martin Radev5dae57b2017-07-14 16:15:55 +03003621 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3622 ASSERT(framebuffer);
3623
3624 if (texture != 0)
3625 {
3626 Texture *textureObj = getTexture(texture);
3627
3628 ImageIndex index = ImageIndex::Make2D(level);
3629 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3630 textureObj, numViews, viewportOffsets);
3631 }
3632 else
3633 {
3634 framebuffer->resetAttachment(this, attachment);
3635 }
3636
3637 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003638}
3639
Jamie Madillc29968b2016-01-20 11:17:23 -05003640void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3641{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003642 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003643 ASSERT(framebuffer);
3644 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003645 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003646}
3647
3648void Context::readBuffer(GLenum mode)
3649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003650 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003651 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003652 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003653}
3654
3655void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3656{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003658 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003659
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003660 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003661 ASSERT(framebuffer);
3662
3663 // The specification isn't clear what should be done when the framebuffer isn't complete.
3664 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003665 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003666}
3667
3668void Context::invalidateFramebuffer(GLenum target,
3669 GLsizei numAttachments,
3670 const GLenum *attachments)
3671{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003672 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003673 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003674
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003675 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 ASSERT(framebuffer);
3677
Jamie Madill427064d2018-04-13 16:20:34 -04003678 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003679 {
Jamie Madill437fa652016-05-03 15:13:24 -04003680 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003681 }
Jamie Madill437fa652016-05-03 15:13:24 -04003682
Jamie Madill4928b7c2017-06-20 12:57:39 -04003683 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003684}
3685
3686void Context::invalidateSubFramebuffer(GLenum target,
3687 GLsizei numAttachments,
3688 const GLenum *attachments,
3689 GLint x,
3690 GLint y,
3691 GLsizei width,
3692 GLsizei height)
3693{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003694 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003695 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003696
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003698 ASSERT(framebuffer);
3699
Jamie Madill427064d2018-04-13 16:20:34 -04003700 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 {
Jamie Madill437fa652016-05-03 15:13:24 -04003702 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003703 }
Jamie Madill437fa652016-05-03 15:13:24 -04003704
3705 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003706 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003707}
3708
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003709void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003710 GLint level,
3711 GLint internalformat,
3712 GLsizei width,
3713 GLsizei height,
3714 GLint border,
3715 GLenum format,
3716 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003717 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003718{
Jamie Madillbc918e72018-03-08 09:47:21 -05003719 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003720
3721 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003722 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003723 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3724 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003725}
3726
Brandon Jones59770802018-04-02 13:18:42 -07003727void Context::texImage2DRobust(TextureTarget target,
3728 GLint level,
3729 GLint internalformat,
3730 GLsizei width,
3731 GLsizei height,
3732 GLint border,
3733 GLenum format,
3734 GLenum type,
3735 GLsizei bufSize,
3736 const void *pixels)
3737{
3738 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3739}
3740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003741void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003742 GLint level,
3743 GLint internalformat,
3744 GLsizei width,
3745 GLsizei height,
3746 GLsizei depth,
3747 GLint border,
3748 GLenum format,
3749 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003750 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003751{
Jamie Madillbc918e72018-03-08 09:47:21 -05003752 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003753
3754 Extents size(width, height, depth);
3755 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003756 handleError(texture->setImage(this, mGLState.getUnpackState(),
3757 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3758 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003759}
3760
Brandon Jones59770802018-04-02 13:18:42 -07003761void Context::texImage3DRobust(TextureType target,
3762 GLint level,
3763 GLint internalformat,
3764 GLsizei width,
3765 GLsizei height,
3766 GLsizei depth,
3767 GLint border,
3768 GLenum format,
3769 GLenum type,
3770 GLsizei bufSize,
3771 const void *pixels)
3772{
3773 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3774}
3775
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003776void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003777 GLint level,
3778 GLint xoffset,
3779 GLint yoffset,
3780 GLsizei width,
3781 GLsizei height,
3782 GLenum format,
3783 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003784 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003785{
3786 // Zero sized uploads are valid but no-ops
3787 if (width == 0 || height == 0)
3788 {
3789 return;
3790 }
3791
Jamie Madillbc918e72018-03-08 09:47:21 -05003792 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003793
3794 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003795 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003796 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3797 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003798}
3799
Brandon Jones59770802018-04-02 13:18:42 -07003800void Context::texSubImage2DRobust(TextureTarget target,
3801 GLint level,
3802 GLint xoffset,
3803 GLint yoffset,
3804 GLsizei width,
3805 GLsizei height,
3806 GLenum format,
3807 GLenum type,
3808 GLsizei bufSize,
3809 const void *pixels)
3810{
3811 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3812}
3813
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003814void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003815 GLint level,
3816 GLint xoffset,
3817 GLint yoffset,
3818 GLint zoffset,
3819 GLsizei width,
3820 GLsizei height,
3821 GLsizei depth,
3822 GLenum format,
3823 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003824 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003825{
3826 // Zero sized uploads are valid but no-ops
3827 if (width == 0 || height == 0 || depth == 0)
3828 {
3829 return;
3830 }
3831
Jamie Madillbc918e72018-03-08 09:47:21 -05003832 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003833
3834 Box area(xoffset, yoffset, zoffset, width, height, depth);
3835 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003836 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3837 NonCubeTextureTypeToTarget(target), level, area, format, type,
3838 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003839}
3840
Brandon Jones59770802018-04-02 13:18:42 -07003841void Context::texSubImage3DRobust(TextureType target,
3842 GLint level,
3843 GLint xoffset,
3844 GLint yoffset,
3845 GLint zoffset,
3846 GLsizei width,
3847 GLsizei height,
3848 GLsizei depth,
3849 GLenum format,
3850 GLenum type,
3851 GLsizei bufSize,
3852 const void *pixels)
3853{
3854 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3855 pixels);
3856}
3857
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003858void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003859 GLint level,
3860 GLenum internalformat,
3861 GLsizei width,
3862 GLsizei height,
3863 GLint border,
3864 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003865 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003866{
Jamie Madillbc918e72018-03-08 09:47:21 -05003867 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003868
3869 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003870 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003871 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3872 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003873 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003874}
3875
Brandon Jones59770802018-04-02 13:18:42 -07003876void Context::compressedTexImage2DRobust(TextureTarget target,
3877 GLint level,
3878 GLenum internalformat,
3879 GLsizei width,
3880 GLsizei height,
3881 GLint border,
3882 GLsizei imageSize,
3883 GLsizei dataSize,
3884 const GLvoid *data)
3885{
3886 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3887}
3888
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003889void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003890 GLint level,
3891 GLenum internalformat,
3892 GLsizei width,
3893 GLsizei height,
3894 GLsizei depth,
3895 GLint border,
3896 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003897 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003898{
Jamie Madillbc918e72018-03-08 09:47:21 -05003899 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003900
3901 Extents size(width, height, depth);
3902 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003903 handleError(texture->setCompressedImage(
3904 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3905 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003906}
3907
Brandon Jones59770802018-04-02 13:18:42 -07003908void Context::compressedTexImage3DRobust(TextureType target,
3909 GLint level,
3910 GLenum internalformat,
3911 GLsizei width,
3912 GLsizei height,
3913 GLsizei depth,
3914 GLint border,
3915 GLsizei imageSize,
3916 GLsizei dataSize,
3917 const GLvoid *data)
3918{
3919 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3920 data);
3921}
3922
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003923void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003924 GLint level,
3925 GLint xoffset,
3926 GLint yoffset,
3927 GLsizei width,
3928 GLsizei height,
3929 GLenum format,
3930 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003931 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003932{
Jamie Madillbc918e72018-03-08 09:47:21 -05003933 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003934
3935 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003936 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003937 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3938 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003939 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003940}
3941
Brandon Jones59770802018-04-02 13:18:42 -07003942void Context::compressedTexSubImage2DRobust(TextureTarget target,
3943 GLint level,
3944 GLint xoffset,
3945 GLint yoffset,
3946 GLsizei width,
3947 GLsizei height,
3948 GLenum format,
3949 GLsizei imageSize,
3950 GLsizei dataSize,
3951 const GLvoid *data)
3952{
3953 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3954 data);
3955}
3956
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003957void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003958 GLint level,
3959 GLint xoffset,
3960 GLint yoffset,
3961 GLint zoffset,
3962 GLsizei width,
3963 GLsizei height,
3964 GLsizei depth,
3965 GLenum format,
3966 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003967 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003968{
3969 // Zero sized uploads are valid but no-ops
3970 if (width == 0 || height == 0)
3971 {
3972 return;
3973 }
3974
Jamie Madillbc918e72018-03-08 09:47:21 -05003975 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003976
3977 Box area(xoffset, yoffset, zoffset, width, height, depth);
3978 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003979 handleError(texture->setCompressedSubImage(
3980 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3981 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003982}
3983
Brandon Jones59770802018-04-02 13:18:42 -07003984void Context::compressedTexSubImage3DRobust(TextureType target,
3985 GLint level,
3986 GLint xoffset,
3987 GLint yoffset,
3988 GLint zoffset,
3989 GLsizei width,
3990 GLsizei height,
3991 GLsizei depth,
3992 GLenum format,
3993 GLsizei imageSize,
3994 GLsizei dataSize,
3995 const GLvoid *data)
3996{
3997 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
3998 imageSize, data);
3999}
4000
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004001void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004002{
4003 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004004 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004005}
4006
Jamie Madill007530e2017-12-28 14:27:04 -05004007void Context::copyTexture(GLuint sourceId,
4008 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004009 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004010 GLuint destId,
4011 GLint destLevel,
4012 GLint internalFormat,
4013 GLenum destType,
4014 GLboolean unpackFlipY,
4015 GLboolean unpackPremultiplyAlpha,
4016 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004017{
Jamie Madillbc918e72018-03-08 09:47:21 -05004018 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004019
4020 gl::Texture *sourceTexture = getTexture(sourceId);
4021 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004022 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4023 sourceLevel, ConvertToBool(unpackFlipY),
4024 ConvertToBool(unpackPremultiplyAlpha),
4025 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004026}
4027
Jamie Madill007530e2017-12-28 14:27:04 -05004028void Context::copySubTexture(GLuint sourceId,
4029 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004030 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004031 GLuint destId,
4032 GLint destLevel,
4033 GLint xoffset,
4034 GLint yoffset,
4035 GLint x,
4036 GLint y,
4037 GLsizei width,
4038 GLsizei height,
4039 GLboolean unpackFlipY,
4040 GLboolean unpackPremultiplyAlpha,
4041 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004042{
4043 // Zero sized copies are valid but no-ops
4044 if (width == 0 || height == 0)
4045 {
4046 return;
4047 }
4048
Jamie Madillbc918e72018-03-08 09:47:21 -05004049 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004050
4051 gl::Texture *sourceTexture = getTexture(sourceId);
4052 gl::Texture *destTexture = getTexture(destId);
4053 Offset offset(xoffset, yoffset, 0);
4054 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004055 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4056 ConvertToBool(unpackFlipY),
4057 ConvertToBool(unpackPremultiplyAlpha),
4058 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004059}
4060
Jamie Madill007530e2017-12-28 14:27:04 -05004061void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004062{
Jamie Madillbc918e72018-03-08 09:47:21 -05004063 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004064
4065 gl::Texture *sourceTexture = getTexture(sourceId);
4066 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004067 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004068}
4069
Corentin Wallez336129f2017-10-17 15:55:40 -04004070void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004071{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004072 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004073 ASSERT(buffer);
4074
Geoff Lang496c02d2016-10-20 11:38:11 -07004075 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004076}
4077
Brandon Jones59770802018-04-02 13:18:42 -07004078void Context::getBufferPointervRobust(BufferBinding target,
4079 GLenum pname,
4080 GLsizei bufSize,
4081 GLsizei *length,
4082 void **params)
4083{
4084 getBufferPointerv(target, pname, params);
4085}
4086
Corentin Wallez336129f2017-10-17 15:55:40 -04004087void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004089 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004090 ASSERT(buffer);
4091
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004092 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004093 if (error.isError())
4094 {
Jamie Madill437fa652016-05-03 15:13:24 -04004095 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004096 return nullptr;
4097 }
4098
4099 return buffer->getMapPointer();
4100}
4101
Corentin Wallez336129f2017-10-17 15:55:40 -04004102GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004103{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004104 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004105 ASSERT(buffer);
4106
4107 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004108 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004109 if (error.isError())
4110 {
Jamie Madill437fa652016-05-03 15:13:24 -04004111 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004112 return GL_FALSE;
4113 }
4114
4115 return result;
4116}
4117
Corentin Wallez336129f2017-10-17 15:55:40 -04004118void *Context::mapBufferRange(BufferBinding target,
4119 GLintptr offset,
4120 GLsizeiptr length,
4121 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004124 ASSERT(buffer);
4125
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004126 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004127 if (error.isError())
4128 {
Jamie Madill437fa652016-05-03 15:13:24 -04004129 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004130 return nullptr;
4131 }
4132
4133 return buffer->getMapPointer();
4134}
4135
Corentin Wallez336129f2017-10-17 15:55:40 -04004136void Context::flushMappedBufferRange(BufferBinding /*target*/,
4137 GLintptr /*offset*/,
4138 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004139{
4140 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4141}
4142
Jamie Madillbc918e72018-03-08 09:47:21 -05004143Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004144{
Geoff Langa8cb2872018-03-09 16:09:40 -05004145 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004146}
4147
Jamie Madillbc918e72018-03-08 09:47:21 -05004148Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004149{
Geoff Langa8cb2872018-03-09 16:09:40 -05004150 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004151}
4152
Jamie Madillbc918e72018-03-08 09:47:21 -05004153Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004154{
Geoff Langa8cb2872018-03-09 16:09:40 -05004155 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004156}
4157
Jiajia Qin5451d532017-11-16 17:16:34 +08004158void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4159{
4160 UNIMPLEMENTED();
4161}
4162
Jamie Madillc20ab272016-06-09 07:20:46 -07004163void Context::activeTexture(GLenum texture)
4164{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004165 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004166}
4167
Jamie Madill876429b2017-04-20 15:46:24 -04004168void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004169{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004170 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004171}
4172
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004173void Context::blendEquation(GLenum mode)
4174{
4175 mGLState.setBlendEquation(mode, mode);
4176}
4177
Jamie Madillc20ab272016-06-09 07:20:46 -07004178void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4179{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004180 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004181}
4182
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004183void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4184{
4185 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4186}
4187
Jamie Madillc20ab272016-06-09 07:20:46 -07004188void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4189{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004190 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004191}
4192
Jamie Madill876429b2017-04-20 15:46:24 -04004193void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004194{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004195 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004196}
4197
Jamie Madill876429b2017-04-20 15:46:24 -04004198void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004199{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004200 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004201}
4202
4203void Context::clearStencil(GLint s)
4204{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004205 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004206}
4207
4208void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4209{
Geoff Lang92019432017-11-20 13:09:34 -05004210 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4211 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004212}
4213
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004214void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004215{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004216 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004217}
4218
4219void Context::depthFunc(GLenum func)
4220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004221 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004222}
4223
4224void Context::depthMask(GLboolean flag)
4225{
Geoff Lang92019432017-11-20 13:09:34 -05004226 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004227}
4228
Jamie Madill876429b2017-04-20 15:46:24 -04004229void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004230{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004231 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004232}
4233
4234void Context::disable(GLenum cap)
4235{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004236 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004237}
4238
4239void Context::disableVertexAttribArray(GLuint index)
4240{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004241 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004242}
4243
4244void Context::enable(GLenum cap)
4245{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004246 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004247}
4248
4249void Context::enableVertexAttribArray(GLuint index)
4250{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004251 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004252}
4253
4254void Context::frontFace(GLenum mode)
4255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004256 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004257}
4258
4259void Context::hint(GLenum target, GLenum mode)
4260{
4261 switch (target)
4262 {
4263 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265 break;
4266
4267 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004268 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004269 break;
4270
4271 default:
4272 UNREACHABLE();
4273 return;
4274 }
4275}
4276
4277void Context::lineWidth(GLfloat width)
4278{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004279 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004280}
4281
4282void Context::pixelStorei(GLenum pname, GLint param)
4283{
4284 switch (pname)
4285 {
4286 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004287 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004288 break;
4289
4290 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004291 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004292 break;
4293
4294 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004295 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004296 break;
4297
4298 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004299 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004300 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004301 break;
4302
4303 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004304 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004305 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004306 break;
4307
4308 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004309 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004310 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004311 break;
4312
4313 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004314 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316 break;
4317
4318 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004319 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004321 break;
4322
4323 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004324 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004326 break;
4327
4328 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004329 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331 break;
4332
4333 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004334 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004335 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004336 break;
4337
4338 default:
4339 UNREACHABLE();
4340 return;
4341 }
4342}
4343
4344void Context::polygonOffset(GLfloat factor, GLfloat units)
4345{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004346 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004347}
4348
Jamie Madill876429b2017-04-20 15:46:24 -04004349void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004350{
Geoff Lang92019432017-11-20 13:09:34 -05004351 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004352}
4353
Jiawei Shaodb342272017-09-27 10:21:45 +08004354void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4355{
4356 mGLState.setSampleMaskParams(maskNumber, mask);
4357}
4358
Jamie Madillc20ab272016-06-09 07:20:46 -07004359void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4360{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362}
4363
4364void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4365{
4366 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4367 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369 }
4370
4371 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4372 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374 }
4375}
4376
4377void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4378{
4379 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4380 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382 }
4383
4384 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4385 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387 }
4388}
4389
4390void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4391{
4392 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4393 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 }
4396
4397 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4398 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400 }
4401}
4402
4403void Context::vertexAttrib1f(GLuint index, GLfloat x)
4404{
4405 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
4409void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4410{
4411 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
4415void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4416{
4417 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419}
4420
4421void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4422{
4423 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425}
4426
4427void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4428{
4429 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
4433void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4434{
4435 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004437}
4438
4439void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4440{
4441 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443}
4444
4445void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4446{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448}
4449
4450void Context::vertexAttribPointer(GLuint index,
4451 GLint size,
4452 GLenum type,
4453 GLboolean normalized,
4454 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004455 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004456{
Corentin Wallez336129f2017-10-17 15:55:40 -04004457 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004458 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004459}
4460
Shao80957d92017-02-20 21:25:59 +08004461void Context::vertexAttribFormat(GLuint attribIndex,
4462 GLint size,
4463 GLenum type,
4464 GLboolean normalized,
4465 GLuint relativeOffset)
4466{
Geoff Lang92019432017-11-20 13:09:34 -05004467 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004468 relativeOffset);
4469}
4470
4471void Context::vertexAttribIFormat(GLuint attribIndex,
4472 GLint size,
4473 GLenum type,
4474 GLuint relativeOffset)
4475{
4476 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4477}
4478
4479void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4480{
Shaodde78e82017-05-22 14:13:27 +08004481 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004482}
4483
Jiajia Qin5451d532017-11-16 17:16:34 +08004484void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004485{
4486 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4487}
4488
Jamie Madillc20ab272016-06-09 07:20:46 -07004489void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4490{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004491 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004492}
4493
4494void Context::vertexAttribIPointer(GLuint index,
4495 GLint size,
4496 GLenum type,
4497 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004498 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004499{
Corentin Wallez336129f2017-10-17 15:55:40 -04004500 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4501 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
4504void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4505{
4506 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
4510void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4511{
4512 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514}
4515
4516void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4517{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519}
4520
4521void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4522{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524}
4525
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004526void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4527{
4528 const VertexAttribCurrentValueData &currentValues =
4529 getGLState().getVertexAttribCurrentValue(index);
4530 const VertexArray *vao = getGLState().getVertexArray();
4531 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4532 currentValues, pname, params);
4533}
4534
Brandon Jones59770802018-04-02 13:18:42 -07004535void Context::getVertexAttribivRobust(GLuint index,
4536 GLenum pname,
4537 GLsizei bufSize,
4538 GLsizei *length,
4539 GLint *params)
4540{
4541 getVertexAttribiv(index, pname, params);
4542}
4543
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004544void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4545{
4546 const VertexAttribCurrentValueData &currentValues =
4547 getGLState().getVertexAttribCurrentValue(index);
4548 const VertexArray *vao = getGLState().getVertexArray();
4549 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4550 currentValues, pname, params);
4551}
4552
Brandon Jones59770802018-04-02 13:18:42 -07004553void Context::getVertexAttribfvRobust(GLuint index,
4554 GLenum pname,
4555 GLsizei bufSize,
4556 GLsizei *length,
4557 GLfloat *params)
4558{
4559 getVertexAttribfv(index, pname, params);
4560}
4561
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004562void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4563{
4564 const VertexAttribCurrentValueData &currentValues =
4565 getGLState().getVertexAttribCurrentValue(index);
4566 const VertexArray *vao = getGLState().getVertexArray();
4567 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4568 currentValues, pname, params);
4569}
4570
Brandon Jones59770802018-04-02 13:18:42 -07004571void Context::getVertexAttribIivRobust(GLuint index,
4572 GLenum pname,
4573 GLsizei bufSize,
4574 GLsizei *length,
4575 GLint *params)
4576{
4577 getVertexAttribIiv(index, pname, params);
4578}
4579
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004580void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4581{
4582 const VertexAttribCurrentValueData &currentValues =
4583 getGLState().getVertexAttribCurrentValue(index);
4584 const VertexArray *vao = getGLState().getVertexArray();
4585 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4586 currentValues, pname, params);
4587}
4588
Brandon Jones59770802018-04-02 13:18:42 -07004589void Context::getVertexAttribIuivRobust(GLuint index,
4590 GLenum pname,
4591 GLsizei bufSize,
4592 GLsizei *length,
4593 GLuint *params)
4594{
4595 getVertexAttribIuiv(index, pname, params);
4596}
4597
Jamie Madill876429b2017-04-20 15:46:24 -04004598void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004599{
4600 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4601 QueryVertexAttribPointerv(attrib, pname, pointer);
4602}
4603
Brandon Jones59770802018-04-02 13:18:42 -07004604void Context::getVertexAttribPointervRobust(GLuint index,
4605 GLenum pname,
4606 GLsizei bufSize,
4607 GLsizei *length,
4608 void **pointer)
4609{
4610 getVertexAttribPointerv(index, pname, pointer);
4611}
4612
Jamie Madillc20ab272016-06-09 07:20:46 -07004613void Context::debugMessageControl(GLenum source,
4614 GLenum type,
4615 GLenum severity,
4616 GLsizei count,
4617 const GLuint *ids,
4618 GLboolean enabled)
4619{
4620 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004621 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004622 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
4625void Context::debugMessageInsert(GLenum source,
4626 GLenum type,
4627 GLuint id,
4628 GLenum severity,
4629 GLsizei length,
4630 const GLchar *buf)
4631{
4632 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004633 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
4636void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004638 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639}
4640
4641GLuint Context::getDebugMessageLog(GLuint count,
4642 GLsizei bufSize,
4643 GLenum *sources,
4644 GLenum *types,
4645 GLuint *ids,
4646 GLenum *severities,
4647 GLsizei *lengths,
4648 GLchar *messageLog)
4649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4651 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4655{
4656 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004658 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659}
4660
4661void Context::popDebugGroup()
4662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004664 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004665}
4666
Corentin Wallez336129f2017-10-17 15:55:40 -04004667void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004668{
4669 Buffer *buffer = mGLState.getTargetBuffer(target);
4670 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004671 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004672}
4673
Corentin Wallez336129f2017-10-17 15:55:40 -04004674void Context::bufferSubData(BufferBinding target,
4675 GLintptr offset,
4676 GLsizeiptr size,
4677 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004678{
4679 if (data == nullptr)
4680 {
4681 return;
4682 }
4683
4684 Buffer *buffer = mGLState.getTargetBuffer(target);
4685 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004686 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004687}
4688
Jamie Madillef300b12016-10-07 15:12:09 -04004689void Context::attachShader(GLuint program, GLuint shader)
4690{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004691 Program *programObject = mState.mShaderPrograms->getProgram(program);
4692 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004693 ASSERT(programObject && shaderObject);
4694 programObject->attachShader(shaderObject);
4695}
4696
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004697const Workarounds &Context::getWorkarounds() const
4698{
4699 return mWorkarounds;
4700}
4701
Corentin Wallez336129f2017-10-17 15:55:40 -04004702void Context::copyBufferSubData(BufferBinding readTarget,
4703 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004704 GLintptr readOffset,
4705 GLintptr writeOffset,
4706 GLsizeiptr size)
4707{
4708 // if size is zero, the copy is a successful no-op
4709 if (size == 0)
4710 {
4711 return;
4712 }
4713
4714 // TODO(jmadill): cache these.
4715 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4716 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4717
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004718 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004719}
4720
Jamie Madill01a80ee2016-11-07 12:06:18 -05004721void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4722{
4723 Program *programObject = getProgram(program);
4724 // TODO(jmadill): Re-use this from the validation if possible.
4725 ASSERT(programObject);
4726 programObject->bindAttributeLocation(index, name);
4727}
4728
Corentin Wallez336129f2017-10-17 15:55:40 -04004729void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004730{
Corentin Wallez336129f2017-10-17 15:55:40 -04004731 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4732 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004733}
4734
Corentin Wallez336129f2017-10-17 15:55:40 -04004735void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004736{
4737 bindBufferRange(target, index, buffer, 0, 0);
4738}
4739
Corentin Wallez336129f2017-10-17 15:55:40 -04004740void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004741 GLuint index,
4742 GLuint buffer,
4743 GLintptr offset,
4744 GLsizeiptr size)
4745{
Corentin Wallez336129f2017-10-17 15:55:40 -04004746 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4747 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004748}
4749
Jamie Madill01a80ee2016-11-07 12:06:18 -05004750void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4751{
4752 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4753 {
4754 bindReadFramebuffer(framebuffer);
4755 }
4756
4757 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4758 {
4759 bindDrawFramebuffer(framebuffer);
4760 }
4761}
4762
4763void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4764{
4765 ASSERT(target == GL_RENDERBUFFER);
4766 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004767 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004768 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004769}
4770
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004771void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004772 GLsizei samples,
4773 GLenum internalformat,
4774 GLsizei width,
4775 GLsizei height,
4776 GLboolean fixedsamplelocations)
4777{
4778 Extents size(width, height, 1);
4779 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004780 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4781 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004782}
4783
4784void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4785{
JiangYizhou5b03f472017-01-09 10:22:53 +08004786 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4787 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004788 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004789 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004790
4791 switch (pname)
4792 {
4793 case GL_SAMPLE_POSITION:
4794 handleError(framebuffer->getSamplePosition(index, val));
4795 break;
4796 default:
4797 UNREACHABLE();
4798 }
4799}
4800
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004801void Context::getMultisamplefvRobust(GLenum pname,
4802 GLuint index,
4803 GLsizei bufSize,
4804 GLsizei *length,
4805 GLfloat *val)
4806{
4807 UNIMPLEMENTED();
4808}
4809
Jamie Madille8fb6402017-02-14 17:56:40 -05004810void Context::renderbufferStorage(GLenum target,
4811 GLenum internalformat,
4812 GLsizei width,
4813 GLsizei height)
4814{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004815 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4816 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4817
Jamie Madille8fb6402017-02-14 17:56:40 -05004818 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004819 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004820}
4821
4822void Context::renderbufferStorageMultisample(GLenum target,
4823 GLsizei samples,
4824 GLenum internalformat,
4825 GLsizei width,
4826 GLsizei height)
4827{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004828 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4829 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004830
4831 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004832 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004833 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004834}
4835
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004836void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4837{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004838 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004839 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004840}
4841
JiangYizhoue18e6392017-02-20 10:32:23 +08004842void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4843{
4844 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4845 QueryFramebufferParameteriv(framebuffer, pname, params);
4846}
4847
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004848void Context::getFramebufferParameterivRobust(GLenum target,
4849 GLenum pname,
4850 GLsizei bufSize,
4851 GLsizei *length,
4852 GLint *params)
4853{
4854 UNIMPLEMENTED();
4855}
4856
Jiajia Qin5451d532017-11-16 17:16:34 +08004857void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004858{
4859 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4860 SetFramebufferParameteri(framebuffer, pname, param);
4861}
4862
Jamie Madillb3f26b92017-07-19 15:07:41 -04004863Error Context::getScratchBuffer(size_t requstedSizeBytes,
4864 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004865{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004866 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4867 {
4868 return OutOfMemory() << "Failed to allocate internal buffer.";
4869 }
4870 return NoError();
4871}
4872
4873Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4874 angle::MemoryBuffer **zeroBufferOut) const
4875{
4876 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004877 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004878 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004879 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004880 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004881}
4882
Xinghua Cao10a4d432017-11-28 14:46:26 +08004883Error Context::prepareForDispatch()
4884{
Geoff Langa8cb2872018-03-09 16:09:40 -05004885 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004886
4887 if (isRobustResourceInitEnabled())
4888 {
4889 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4890 }
4891
4892 return NoError();
4893}
4894
Xinghua Cao2b396592017-03-29 15:36:04 +08004895void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4896{
4897 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4898 {
4899 return;
4900 }
4901
Xinghua Cao10a4d432017-11-28 14:46:26 +08004902 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004903 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004904}
4905
Jiajia Qin5451d532017-11-16 17:16:34 +08004906void Context::dispatchComputeIndirect(GLintptr indirect)
4907{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004908 ANGLE_CONTEXT_TRY(prepareForDispatch());
4909 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004910}
4911
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004912void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004913 GLsizei levels,
4914 GLenum internalFormat,
4915 GLsizei width,
4916 GLsizei height)
4917{
4918 Extents size(width, height, 1);
4919 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004920 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004921}
4922
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004923void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004924 GLsizei levels,
4925 GLenum internalFormat,
4926 GLsizei width,
4927 GLsizei height,
4928 GLsizei depth)
4929{
4930 Extents size(width, height, depth);
4931 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004932 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004933}
4934
Jiajia Qin5451d532017-11-16 17:16:34 +08004935void Context::memoryBarrier(GLbitfield barriers)
4936{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004937 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004938}
4939
4940void Context::memoryBarrierByRegion(GLbitfield barriers)
4941{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004942 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004943}
4944
Jamie Madillc1d770e2017-04-13 17:31:24 -04004945GLenum Context::checkFramebufferStatus(GLenum target)
4946{
4947 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4948 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004949 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004950}
4951
4952void Context::compileShader(GLuint shader)
4953{
4954 Shader *shaderObject = GetValidShader(this, shader);
4955 if (!shaderObject)
4956 {
4957 return;
4958 }
4959 shaderObject->compile(this);
4960}
4961
4962void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4963{
4964 for (int i = 0; i < n; i++)
4965 {
4966 deleteBuffer(buffers[i]);
4967 }
4968}
4969
4970void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4971{
4972 for (int i = 0; i < n; i++)
4973 {
4974 if (framebuffers[i] != 0)
4975 {
4976 deleteFramebuffer(framebuffers[i]);
4977 }
4978 }
4979}
4980
4981void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4982{
4983 for (int i = 0; i < n; i++)
4984 {
4985 deleteRenderbuffer(renderbuffers[i]);
4986 }
4987}
4988
4989void Context::deleteTextures(GLsizei n, const GLuint *textures)
4990{
4991 for (int i = 0; i < n; i++)
4992 {
4993 if (textures[i] != 0)
4994 {
4995 deleteTexture(textures[i]);
4996 }
4997 }
4998}
4999
5000void Context::detachShader(GLuint program, GLuint shader)
5001{
5002 Program *programObject = getProgram(program);
5003 ASSERT(programObject);
5004
5005 Shader *shaderObject = getShader(shader);
5006 ASSERT(shaderObject);
5007
5008 programObject->detachShader(this, shaderObject);
5009}
5010
5011void Context::genBuffers(GLsizei n, GLuint *buffers)
5012{
5013 for (int i = 0; i < n; i++)
5014 {
5015 buffers[i] = createBuffer();
5016 }
5017}
5018
5019void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5020{
5021 for (int i = 0; i < n; i++)
5022 {
5023 framebuffers[i] = createFramebuffer();
5024 }
5025}
5026
5027void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5028{
5029 for (int i = 0; i < n; i++)
5030 {
5031 renderbuffers[i] = createRenderbuffer();
5032 }
5033}
5034
5035void Context::genTextures(GLsizei n, GLuint *textures)
5036{
5037 for (int i = 0; i < n; i++)
5038 {
5039 textures[i] = createTexture();
5040 }
5041}
5042
5043void Context::getActiveAttrib(GLuint program,
5044 GLuint index,
5045 GLsizei bufsize,
5046 GLsizei *length,
5047 GLint *size,
5048 GLenum *type,
5049 GLchar *name)
5050{
5051 Program *programObject = getProgram(program);
5052 ASSERT(programObject);
5053 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5054}
5055
5056void Context::getActiveUniform(GLuint program,
5057 GLuint index,
5058 GLsizei bufsize,
5059 GLsizei *length,
5060 GLint *size,
5061 GLenum *type,
5062 GLchar *name)
5063{
5064 Program *programObject = getProgram(program);
5065 ASSERT(programObject);
5066 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5067}
5068
5069void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5070{
5071 Program *programObject = getProgram(program);
5072 ASSERT(programObject);
5073 programObject->getAttachedShaders(maxcount, count, shaders);
5074}
5075
5076GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5077{
5078 Program *programObject = getProgram(program);
5079 ASSERT(programObject);
5080 return programObject->getAttributeLocation(name);
5081}
5082
5083void Context::getBooleanv(GLenum pname, GLboolean *params)
5084{
5085 GLenum nativeType;
5086 unsigned int numParams = 0;
5087 getQueryParameterInfo(pname, &nativeType, &numParams);
5088
5089 if (nativeType == GL_BOOL)
5090 {
5091 getBooleanvImpl(pname, params);
5092 }
5093 else
5094 {
5095 CastStateValues(this, nativeType, pname, numParams, params);
5096 }
5097}
5098
Brandon Jones59770802018-04-02 13:18:42 -07005099void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5100{
5101 getBooleanv(pname, params);
5102}
5103
Jamie Madillc1d770e2017-04-13 17:31:24 -04005104void Context::getFloatv(GLenum pname, GLfloat *params)
5105{
5106 GLenum nativeType;
5107 unsigned int numParams = 0;
5108 getQueryParameterInfo(pname, &nativeType, &numParams);
5109
5110 if (nativeType == GL_FLOAT)
5111 {
5112 getFloatvImpl(pname, params);
5113 }
5114 else
5115 {
5116 CastStateValues(this, nativeType, pname, numParams, params);
5117 }
5118}
5119
Brandon Jones59770802018-04-02 13:18:42 -07005120void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5121{
5122 getFloatv(pname, params);
5123}
5124
Jamie Madillc1d770e2017-04-13 17:31:24 -04005125void Context::getIntegerv(GLenum pname, GLint *params)
5126{
5127 GLenum nativeType;
5128 unsigned int numParams = 0;
5129 getQueryParameterInfo(pname, &nativeType, &numParams);
5130
5131 if (nativeType == GL_INT)
5132 {
5133 getIntegervImpl(pname, params);
5134 }
5135 else
5136 {
5137 CastStateValues(this, nativeType, pname, numParams, params);
5138 }
5139}
5140
Brandon Jones59770802018-04-02 13:18:42 -07005141void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5142{
5143 getIntegerv(pname, data);
5144}
5145
Jamie Madillc1d770e2017-04-13 17:31:24 -04005146void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5147{
5148 Program *programObject = getProgram(program);
5149 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005150 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005151}
5152
Brandon Jones59770802018-04-02 13:18:42 -07005153void Context::getProgramivRobust(GLuint program,
5154 GLenum pname,
5155 GLsizei bufSize,
5156 GLsizei *length,
5157 GLint *params)
5158{
5159 getProgramiv(program, pname, params);
5160}
5161
Jiajia Qin5451d532017-11-16 17:16:34 +08005162void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5163{
5164 UNIMPLEMENTED();
5165}
5166
Jamie Madillbe849e42017-05-02 15:49:00 -04005167void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005168{
5169 Program *programObject = getProgram(program);
5170 ASSERT(programObject);
5171 programObject->getInfoLog(bufsize, length, infolog);
5172}
5173
Jiajia Qin5451d532017-11-16 17:16:34 +08005174void Context::getProgramPipelineInfoLog(GLuint pipeline,
5175 GLsizei bufSize,
5176 GLsizei *length,
5177 GLchar *infoLog)
5178{
5179 UNIMPLEMENTED();
5180}
5181
Jamie Madillc1d770e2017-04-13 17:31:24 -04005182void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5183{
5184 Shader *shaderObject = getShader(shader);
5185 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005186 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005187}
5188
Brandon Jones59770802018-04-02 13:18:42 -07005189void Context::getShaderivRobust(GLuint shader,
5190 GLenum pname,
5191 GLsizei bufSize,
5192 GLsizei *length,
5193 GLint *params)
5194{
5195 getShaderiv(shader, pname, params);
5196}
5197
Jamie Madillc1d770e2017-04-13 17:31:24 -04005198void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5199{
5200 Shader *shaderObject = getShader(shader);
5201 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005202 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005203}
5204
5205void Context::getShaderPrecisionFormat(GLenum shadertype,
5206 GLenum precisiontype,
5207 GLint *range,
5208 GLint *precision)
5209{
5210 // TODO(jmadill): Compute shaders.
5211
5212 switch (shadertype)
5213 {
5214 case GL_VERTEX_SHADER:
5215 switch (precisiontype)
5216 {
5217 case GL_LOW_FLOAT:
5218 mCaps.vertexLowpFloat.get(range, precision);
5219 break;
5220 case GL_MEDIUM_FLOAT:
5221 mCaps.vertexMediumpFloat.get(range, precision);
5222 break;
5223 case GL_HIGH_FLOAT:
5224 mCaps.vertexHighpFloat.get(range, precision);
5225 break;
5226
5227 case GL_LOW_INT:
5228 mCaps.vertexLowpInt.get(range, precision);
5229 break;
5230 case GL_MEDIUM_INT:
5231 mCaps.vertexMediumpInt.get(range, precision);
5232 break;
5233 case GL_HIGH_INT:
5234 mCaps.vertexHighpInt.get(range, precision);
5235 break;
5236
5237 default:
5238 UNREACHABLE();
5239 return;
5240 }
5241 break;
5242
5243 case GL_FRAGMENT_SHADER:
5244 switch (precisiontype)
5245 {
5246 case GL_LOW_FLOAT:
5247 mCaps.fragmentLowpFloat.get(range, precision);
5248 break;
5249 case GL_MEDIUM_FLOAT:
5250 mCaps.fragmentMediumpFloat.get(range, precision);
5251 break;
5252 case GL_HIGH_FLOAT:
5253 mCaps.fragmentHighpFloat.get(range, precision);
5254 break;
5255
5256 case GL_LOW_INT:
5257 mCaps.fragmentLowpInt.get(range, precision);
5258 break;
5259 case GL_MEDIUM_INT:
5260 mCaps.fragmentMediumpInt.get(range, precision);
5261 break;
5262 case GL_HIGH_INT:
5263 mCaps.fragmentHighpInt.get(range, precision);
5264 break;
5265
5266 default:
5267 UNREACHABLE();
5268 return;
5269 }
5270 break;
5271
5272 default:
5273 UNREACHABLE();
5274 return;
5275 }
5276}
5277
5278void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5279{
5280 Shader *shaderObject = getShader(shader);
5281 ASSERT(shaderObject);
5282 shaderObject->getSource(bufsize, length, source);
5283}
5284
5285void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5286{
5287 Program *programObject = getProgram(program);
5288 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005289 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005290}
5291
Brandon Jones59770802018-04-02 13:18:42 -07005292void Context::getUniformfvRobust(GLuint program,
5293 GLint location,
5294 GLsizei bufSize,
5295 GLsizei *length,
5296 GLfloat *params)
5297{
5298 getUniformfv(program, location, params);
5299}
5300
Jamie Madillc1d770e2017-04-13 17:31:24 -04005301void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5302{
5303 Program *programObject = getProgram(program);
5304 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005305 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005306}
5307
Brandon Jones59770802018-04-02 13:18:42 -07005308void Context::getUniformivRobust(GLuint program,
5309 GLint location,
5310 GLsizei bufSize,
5311 GLsizei *length,
5312 GLint *params)
5313{
5314 getUniformiv(program, location, params);
5315}
5316
Jamie Madillc1d770e2017-04-13 17:31:24 -04005317GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5318{
5319 Program *programObject = getProgram(program);
5320 ASSERT(programObject);
5321 return programObject->getUniformLocation(name);
5322}
5323
5324GLboolean Context::isBuffer(GLuint buffer)
5325{
5326 if (buffer == 0)
5327 {
5328 return GL_FALSE;
5329 }
5330
5331 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5332}
5333
5334GLboolean Context::isEnabled(GLenum cap)
5335{
5336 return mGLState.getEnableFeature(cap);
5337}
5338
5339GLboolean Context::isFramebuffer(GLuint framebuffer)
5340{
5341 if (framebuffer == 0)
5342 {
5343 return GL_FALSE;
5344 }
5345
5346 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5347}
5348
5349GLboolean Context::isProgram(GLuint program)
5350{
5351 if (program == 0)
5352 {
5353 return GL_FALSE;
5354 }
5355
5356 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5357}
5358
5359GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5360{
5361 if (renderbuffer == 0)
5362 {
5363 return GL_FALSE;
5364 }
5365
5366 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5367}
5368
5369GLboolean Context::isShader(GLuint shader)
5370{
5371 if (shader == 0)
5372 {
5373 return GL_FALSE;
5374 }
5375
5376 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5377}
5378
5379GLboolean Context::isTexture(GLuint texture)
5380{
5381 if (texture == 0)
5382 {
5383 return GL_FALSE;
5384 }
5385
5386 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5387}
5388
5389void Context::linkProgram(GLuint program)
5390{
5391 Program *programObject = getProgram(program);
5392 ASSERT(programObject);
5393 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005394 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005395}
5396
5397void Context::releaseShaderCompiler()
5398{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005399 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005400}
5401
5402void Context::shaderBinary(GLsizei n,
5403 const GLuint *shaders,
5404 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005405 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005406 GLsizei length)
5407{
5408 // No binary shader formats are supported.
5409 UNIMPLEMENTED();
5410}
5411
5412void Context::shaderSource(GLuint shader,
5413 GLsizei count,
5414 const GLchar *const *string,
5415 const GLint *length)
5416{
5417 Shader *shaderObject = getShader(shader);
5418 ASSERT(shaderObject);
5419 shaderObject->setSource(count, string, length);
5420}
5421
5422void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5423{
5424 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5425}
5426
5427void Context::stencilMask(GLuint mask)
5428{
5429 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5430}
5431
5432void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5433{
5434 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5435}
5436
5437void Context::uniform1f(GLint location, GLfloat x)
5438{
5439 Program *program = mGLState.getProgram();
5440 program->setUniform1fv(location, 1, &x);
5441}
5442
5443void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5444{
5445 Program *program = mGLState.getProgram();
5446 program->setUniform1fv(location, count, v);
5447}
5448
5449void Context::uniform1i(GLint location, GLint x)
5450{
5451 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005452 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5453 {
5454 mGLState.setObjectDirty(GL_PROGRAM);
5455 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005456}
5457
5458void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5459{
5460 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005461 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5462 {
5463 mGLState.setObjectDirty(GL_PROGRAM);
5464 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465}
5466
5467void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5468{
5469 GLfloat xy[2] = {x, y};
5470 Program *program = mGLState.getProgram();
5471 program->setUniform2fv(location, 1, xy);
5472}
5473
5474void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5475{
5476 Program *program = mGLState.getProgram();
5477 program->setUniform2fv(location, count, v);
5478}
5479
5480void Context::uniform2i(GLint location, GLint x, GLint y)
5481{
5482 GLint xy[2] = {x, y};
5483 Program *program = mGLState.getProgram();
5484 program->setUniform2iv(location, 1, xy);
5485}
5486
5487void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5488{
5489 Program *program = mGLState.getProgram();
5490 program->setUniform2iv(location, count, v);
5491}
5492
5493void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5494{
5495 GLfloat xyz[3] = {x, y, z};
5496 Program *program = mGLState.getProgram();
5497 program->setUniform3fv(location, 1, xyz);
5498}
5499
5500void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5501{
5502 Program *program = mGLState.getProgram();
5503 program->setUniform3fv(location, count, v);
5504}
5505
5506void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5507{
5508 GLint xyz[3] = {x, y, z};
5509 Program *program = mGLState.getProgram();
5510 program->setUniform3iv(location, 1, xyz);
5511}
5512
5513void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5514{
5515 Program *program = mGLState.getProgram();
5516 program->setUniform3iv(location, count, v);
5517}
5518
5519void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5520{
5521 GLfloat xyzw[4] = {x, y, z, w};
5522 Program *program = mGLState.getProgram();
5523 program->setUniform4fv(location, 1, xyzw);
5524}
5525
5526void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5527{
5528 Program *program = mGLState.getProgram();
5529 program->setUniform4fv(location, count, v);
5530}
5531
5532void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5533{
5534 GLint xyzw[4] = {x, y, z, w};
5535 Program *program = mGLState.getProgram();
5536 program->setUniform4iv(location, 1, xyzw);
5537}
5538
5539void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5540{
5541 Program *program = mGLState.getProgram();
5542 program->setUniform4iv(location, count, v);
5543}
5544
5545void Context::uniformMatrix2fv(GLint location,
5546 GLsizei count,
5547 GLboolean transpose,
5548 const GLfloat *value)
5549{
5550 Program *program = mGLState.getProgram();
5551 program->setUniformMatrix2fv(location, count, transpose, value);
5552}
5553
5554void Context::uniformMatrix3fv(GLint location,
5555 GLsizei count,
5556 GLboolean transpose,
5557 const GLfloat *value)
5558{
5559 Program *program = mGLState.getProgram();
5560 program->setUniformMatrix3fv(location, count, transpose, value);
5561}
5562
5563void Context::uniformMatrix4fv(GLint location,
5564 GLsizei count,
5565 GLboolean transpose,
5566 const GLfloat *value)
5567{
5568 Program *program = mGLState.getProgram();
5569 program->setUniformMatrix4fv(location, count, transpose, value);
5570}
5571
5572void Context::validateProgram(GLuint program)
5573{
5574 Program *programObject = getProgram(program);
5575 ASSERT(programObject);
5576 programObject->validate(mCaps);
5577}
5578
Jiajia Qin5451d532017-11-16 17:16:34 +08005579void Context::validateProgramPipeline(GLuint pipeline)
5580{
5581 UNIMPLEMENTED();
5582}
5583
Jamie Madilld04908b2017-06-09 14:15:35 -04005584void Context::getProgramBinary(GLuint program,
5585 GLsizei bufSize,
5586 GLsizei *length,
5587 GLenum *binaryFormat,
5588 void *binary)
5589{
5590 Program *programObject = getProgram(program);
5591 ASSERT(programObject != nullptr);
5592
5593 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5594}
5595
5596void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5597{
5598 Program *programObject = getProgram(program);
5599 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005600
Jamie Madilld04908b2017-06-09 14:15:35 -04005601 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5602}
5603
Jamie Madillff325f12017-08-26 15:06:05 -04005604void Context::uniform1ui(GLint location, GLuint v0)
5605{
5606 Program *program = mGLState.getProgram();
5607 program->setUniform1uiv(location, 1, &v0);
5608}
5609
5610void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5611{
5612 Program *program = mGLState.getProgram();
5613 const GLuint xy[] = {v0, v1};
5614 program->setUniform2uiv(location, 1, xy);
5615}
5616
5617void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5618{
5619 Program *program = mGLState.getProgram();
5620 const GLuint xyz[] = {v0, v1, v2};
5621 program->setUniform3uiv(location, 1, xyz);
5622}
5623
5624void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5625{
5626 Program *program = mGLState.getProgram();
5627 const GLuint xyzw[] = {v0, v1, v2, v3};
5628 program->setUniform4uiv(location, 1, xyzw);
5629}
5630
5631void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5632{
5633 Program *program = mGLState.getProgram();
5634 program->setUniform1uiv(location, count, value);
5635}
5636void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5637{
5638 Program *program = mGLState.getProgram();
5639 program->setUniform2uiv(location, count, value);
5640}
5641
5642void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5643{
5644 Program *program = mGLState.getProgram();
5645 program->setUniform3uiv(location, count, value);
5646}
5647
5648void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5649{
5650 Program *program = mGLState.getProgram();
5651 program->setUniform4uiv(location, count, value);
5652}
5653
Jamie Madillf0e04492017-08-26 15:28:42 -04005654void Context::genQueries(GLsizei n, GLuint *ids)
5655{
5656 for (GLsizei i = 0; i < n; i++)
5657 {
5658 GLuint handle = mQueryHandleAllocator.allocate();
5659 mQueryMap.assign(handle, nullptr);
5660 ids[i] = handle;
5661 }
5662}
5663
5664void Context::deleteQueries(GLsizei n, const GLuint *ids)
5665{
5666 for (int i = 0; i < n; i++)
5667 {
5668 GLuint query = ids[i];
5669
5670 Query *queryObject = nullptr;
5671 if (mQueryMap.erase(query, &queryObject))
5672 {
5673 mQueryHandleAllocator.release(query);
5674 if (queryObject)
5675 {
5676 queryObject->release(this);
5677 }
5678 }
5679 }
5680}
5681
5682GLboolean Context::isQuery(GLuint id)
5683{
5684 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5685}
5686
Jamie Madillc8c95812017-08-26 18:40:09 -04005687void Context::uniformMatrix2x3fv(GLint location,
5688 GLsizei count,
5689 GLboolean transpose,
5690 const GLfloat *value)
5691{
5692 Program *program = mGLState.getProgram();
5693 program->setUniformMatrix2x3fv(location, count, transpose, value);
5694}
5695
5696void Context::uniformMatrix3x2fv(GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniformMatrix3x2fv(location, count, transpose, value);
5703}
5704
5705void Context::uniformMatrix2x4fv(GLint location,
5706 GLsizei count,
5707 GLboolean transpose,
5708 const GLfloat *value)
5709{
5710 Program *program = mGLState.getProgram();
5711 program->setUniformMatrix2x4fv(location, count, transpose, value);
5712}
5713
5714void Context::uniformMatrix4x2fv(GLint location,
5715 GLsizei count,
5716 GLboolean transpose,
5717 const GLfloat *value)
5718{
5719 Program *program = mGLState.getProgram();
5720 program->setUniformMatrix4x2fv(location, count, transpose, value);
5721}
5722
5723void Context::uniformMatrix3x4fv(GLint location,
5724 GLsizei count,
5725 GLboolean transpose,
5726 const GLfloat *value)
5727{
5728 Program *program = mGLState.getProgram();
5729 program->setUniformMatrix3x4fv(location, count, transpose, value);
5730}
5731
5732void Context::uniformMatrix4x3fv(GLint location,
5733 GLsizei count,
5734 GLboolean transpose,
5735 const GLfloat *value)
5736{
5737 Program *program = mGLState.getProgram();
5738 program->setUniformMatrix4x3fv(location, count, transpose, value);
5739}
5740
Jamie Madilld7576732017-08-26 18:49:50 -04005741void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5742{
5743 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5744 {
5745 GLuint vertexArray = arrays[arrayIndex];
5746
5747 if (arrays[arrayIndex] != 0)
5748 {
5749 VertexArray *vertexArrayObject = nullptr;
5750 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5751 {
5752 if (vertexArrayObject != nullptr)
5753 {
5754 detachVertexArray(vertexArray);
5755 vertexArrayObject->onDestroy(this);
5756 }
5757
5758 mVertexArrayHandleAllocator.release(vertexArray);
5759 }
5760 }
5761 }
5762}
5763
5764void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5765{
5766 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5767 {
5768 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5769 mVertexArrayMap.assign(vertexArray, nullptr);
5770 arrays[arrayIndex] = vertexArray;
5771 }
5772}
5773
5774bool Context::isVertexArray(GLuint array)
5775{
5776 if (array == 0)
5777 {
5778 return GL_FALSE;
5779 }
5780
5781 VertexArray *vao = getVertexArray(array);
5782 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5783}
5784
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005785void Context::endTransformFeedback()
5786{
5787 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5788 transformFeedback->end(this);
5789}
5790
5791void Context::transformFeedbackVaryings(GLuint program,
5792 GLsizei count,
5793 const GLchar *const *varyings,
5794 GLenum bufferMode)
5795{
5796 Program *programObject = getProgram(program);
5797 ASSERT(programObject);
5798 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5799}
5800
5801void Context::getTransformFeedbackVarying(GLuint program,
5802 GLuint index,
5803 GLsizei bufSize,
5804 GLsizei *length,
5805 GLsizei *size,
5806 GLenum *type,
5807 GLchar *name)
5808{
5809 Program *programObject = getProgram(program);
5810 ASSERT(programObject);
5811 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5812}
5813
5814void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5815{
5816 for (int i = 0; i < n; i++)
5817 {
5818 GLuint transformFeedback = ids[i];
5819 if (transformFeedback == 0)
5820 {
5821 continue;
5822 }
5823
5824 TransformFeedback *transformFeedbackObject = nullptr;
5825 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5826 {
5827 if (transformFeedbackObject != nullptr)
5828 {
5829 detachTransformFeedback(transformFeedback);
5830 transformFeedbackObject->release(this);
5831 }
5832
5833 mTransformFeedbackHandleAllocator.release(transformFeedback);
5834 }
5835 }
5836}
5837
5838void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5839{
5840 for (int i = 0; i < n; i++)
5841 {
5842 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5843 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5844 ids[i] = transformFeedback;
5845 }
5846}
5847
5848bool Context::isTransformFeedback(GLuint id)
5849{
5850 if (id == 0)
5851 {
5852 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5853 // returns FALSE
5854 return GL_FALSE;
5855 }
5856
5857 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5858 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5859}
5860
5861void Context::pauseTransformFeedback()
5862{
5863 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5864 transformFeedback->pause();
5865}
5866
5867void Context::resumeTransformFeedback()
5868{
5869 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5870 transformFeedback->resume();
5871}
5872
Jamie Madill12e957f2017-08-26 21:42:26 -04005873void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5874{
5875 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005876 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005877}
5878
Brandon Jones59770802018-04-02 13:18:42 -07005879void Context::getUniformuivRobust(GLuint program,
5880 GLint location,
5881 GLsizei bufSize,
5882 GLsizei *length,
5883 GLuint *params)
5884{
5885 getUniformuiv(program, location, params);
5886}
5887
Jamie Madill12e957f2017-08-26 21:42:26 -04005888GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5889{
5890 const Program *programObject = getProgram(program);
5891 return programObject->getFragDataLocation(name);
5892}
5893
5894void Context::getUniformIndices(GLuint program,
5895 GLsizei uniformCount,
5896 const GLchar *const *uniformNames,
5897 GLuint *uniformIndices)
5898{
5899 const Program *programObject = getProgram(program);
5900 if (!programObject->isLinked())
5901 {
5902 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5903 {
5904 uniformIndices[uniformId] = GL_INVALID_INDEX;
5905 }
5906 }
5907 else
5908 {
5909 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5910 {
5911 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5912 }
5913 }
5914}
5915
5916void Context::getActiveUniformsiv(GLuint program,
5917 GLsizei uniformCount,
5918 const GLuint *uniformIndices,
5919 GLenum pname,
5920 GLint *params)
5921{
5922 const Program *programObject = getProgram(program);
5923 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5924 {
5925 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005926 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005927 }
5928}
5929
5930GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5931{
5932 const Program *programObject = getProgram(program);
5933 return programObject->getUniformBlockIndex(uniformBlockName);
5934}
5935
5936void Context::getActiveUniformBlockiv(GLuint program,
5937 GLuint uniformBlockIndex,
5938 GLenum pname,
5939 GLint *params)
5940{
5941 const Program *programObject = getProgram(program);
5942 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5943}
5944
Brandon Jones59770802018-04-02 13:18:42 -07005945void Context::getActiveUniformBlockivRobust(GLuint program,
5946 GLuint uniformBlockIndex,
5947 GLenum pname,
5948 GLsizei bufSize,
5949 GLsizei *length,
5950 GLint *params)
5951{
5952 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5953}
5954
Jamie Madill12e957f2017-08-26 21:42:26 -04005955void Context::getActiveUniformBlockName(GLuint program,
5956 GLuint uniformBlockIndex,
5957 GLsizei bufSize,
5958 GLsizei *length,
5959 GLchar *uniformBlockName)
5960{
5961 const Program *programObject = getProgram(program);
5962 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5963}
5964
5965void Context::uniformBlockBinding(GLuint program,
5966 GLuint uniformBlockIndex,
5967 GLuint uniformBlockBinding)
5968{
5969 Program *programObject = getProgram(program);
5970 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5971}
5972
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005973GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5974{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005975 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5976 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005977
Jamie Madill70b5bb02017-08-28 13:32:37 -04005978 Sync *syncObject = getSync(syncHandle);
5979 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005980 if (error.isError())
5981 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005982 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005983 handleError(error);
5984 return nullptr;
5985 }
5986
Jamie Madill70b5bb02017-08-28 13:32:37 -04005987 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005988}
5989
5990GLboolean Context::isSync(GLsync sync)
5991{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005992 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005993}
5994
5995GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5996{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005997 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005998
5999 GLenum result = GL_WAIT_FAILED;
6000 handleError(syncObject->clientWait(flags, timeout, &result));
6001 return result;
6002}
6003
6004void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6005{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006006 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006007 handleError(syncObject->serverWait(flags, timeout));
6008}
6009
6010void Context::getInteger64v(GLenum pname, GLint64 *params)
6011{
6012 GLenum nativeType = GL_NONE;
6013 unsigned int numParams = 0;
6014 getQueryParameterInfo(pname, &nativeType, &numParams);
6015
6016 if (nativeType == GL_INT_64_ANGLEX)
6017 {
6018 getInteger64vImpl(pname, params);
6019 }
6020 else
6021 {
6022 CastStateValues(this, nativeType, pname, numParams, params);
6023 }
6024}
6025
Brandon Jones59770802018-04-02 13:18:42 -07006026void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6027{
6028 getInteger64v(pname, data);
6029}
6030
Corentin Wallez336129f2017-10-17 15:55:40 -04006031void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006032{
6033 Buffer *buffer = mGLState.getTargetBuffer(target);
6034 QueryBufferParameteri64v(buffer, pname, params);
6035}
6036
Brandon Jones59770802018-04-02 13:18:42 -07006037void Context::getBufferParameteri64vRobust(BufferBinding target,
6038 GLenum pname,
6039 GLsizei bufSize,
6040 GLsizei *length,
6041 GLint64 *params)
6042{
6043 getBufferParameteri64v(target, pname, params);
6044}
6045
Jamie Madill3ef140a2017-08-26 23:11:21 -04006046void Context::genSamplers(GLsizei count, GLuint *samplers)
6047{
6048 for (int i = 0; i < count; i++)
6049 {
6050 samplers[i] = mState.mSamplers->createSampler();
6051 }
6052}
6053
6054void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6055{
6056 for (int i = 0; i < count; i++)
6057 {
6058 GLuint sampler = samplers[i];
6059
6060 if (mState.mSamplers->getSampler(sampler))
6061 {
6062 detachSampler(sampler);
6063 }
6064
6065 mState.mSamplers->deleteObject(this, sampler);
6066 }
6067}
6068
6069void Context::getInternalformativ(GLenum target,
6070 GLenum internalformat,
6071 GLenum pname,
6072 GLsizei bufSize,
6073 GLint *params)
6074{
6075 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6076 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6077}
6078
Brandon Jones59770802018-04-02 13:18:42 -07006079void Context::getInternalformativRobust(GLenum target,
6080 GLenum internalformat,
6081 GLenum pname,
6082 GLsizei bufSize,
6083 GLsizei *length,
6084 GLint *params)
6085{
6086 getInternalformativ(target, internalformat, pname, bufSize, params);
6087}
6088
Jiajia Qin5451d532017-11-16 17:16:34 +08006089void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6090{
6091 programUniform1iv(program, location, 1, &v0);
6092}
6093
6094void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6095{
6096 GLint xy[2] = {v0, v1};
6097 programUniform2iv(program, location, 1, xy);
6098}
6099
6100void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6101{
6102 GLint xyz[3] = {v0, v1, v2};
6103 programUniform3iv(program, location, 1, xyz);
6104}
6105
6106void Context::programUniform4i(GLuint program,
6107 GLint location,
6108 GLint v0,
6109 GLint v1,
6110 GLint v2,
6111 GLint v3)
6112{
6113 GLint xyzw[4] = {v0, v1, v2, v3};
6114 programUniform4iv(program, location, 1, xyzw);
6115}
6116
6117void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6118{
6119 programUniform1uiv(program, location, 1, &v0);
6120}
6121
6122void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6123{
6124 GLuint xy[2] = {v0, v1};
6125 programUniform2uiv(program, location, 1, xy);
6126}
6127
6128void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6129{
6130 GLuint xyz[3] = {v0, v1, v2};
6131 programUniform3uiv(program, location, 1, xyz);
6132}
6133
6134void Context::programUniform4ui(GLuint program,
6135 GLint location,
6136 GLuint v0,
6137 GLuint v1,
6138 GLuint v2,
6139 GLuint v3)
6140{
6141 GLuint xyzw[4] = {v0, v1, v2, v3};
6142 programUniform4uiv(program, location, 1, xyzw);
6143}
6144
6145void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6146{
6147 programUniform1fv(program, location, 1, &v0);
6148}
6149
6150void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6151{
6152 GLfloat xy[2] = {v0, v1};
6153 programUniform2fv(program, location, 1, xy);
6154}
6155
6156void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6157{
6158 GLfloat xyz[3] = {v0, v1, v2};
6159 programUniform3fv(program, location, 1, xyz);
6160}
6161
6162void Context::programUniform4f(GLuint program,
6163 GLint location,
6164 GLfloat v0,
6165 GLfloat v1,
6166 GLfloat v2,
6167 GLfloat v3)
6168{
6169 GLfloat xyzw[4] = {v0, v1, v2, v3};
6170 programUniform4fv(program, location, 1, xyzw);
6171}
6172
Jamie Madill81c2e252017-09-09 23:32:46 -04006173void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6174{
6175 Program *programObject = getProgram(program);
6176 ASSERT(programObject);
6177 if (programObject->setUniform1iv(location, count, value) ==
6178 Program::SetUniformResult::SamplerChanged)
6179 {
6180 mGLState.setObjectDirty(GL_PROGRAM);
6181 }
6182}
6183
Jiajia Qin5451d532017-11-16 17:16:34 +08006184void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6185{
6186 Program *programObject = getProgram(program);
6187 ASSERT(programObject);
6188 programObject->setUniform2iv(location, count, value);
6189}
6190
6191void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6192{
6193 Program *programObject = getProgram(program);
6194 ASSERT(programObject);
6195 programObject->setUniform3iv(location, count, value);
6196}
6197
6198void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6199{
6200 Program *programObject = getProgram(program);
6201 ASSERT(programObject);
6202 programObject->setUniform4iv(location, count, value);
6203}
6204
6205void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6206{
6207 Program *programObject = getProgram(program);
6208 ASSERT(programObject);
6209 programObject->setUniform1uiv(location, count, value);
6210}
6211
6212void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6213{
6214 Program *programObject = getProgram(program);
6215 ASSERT(programObject);
6216 programObject->setUniform2uiv(location, count, value);
6217}
6218
6219void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6220{
6221 Program *programObject = getProgram(program);
6222 ASSERT(programObject);
6223 programObject->setUniform3uiv(location, count, value);
6224}
6225
6226void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6227{
6228 Program *programObject = getProgram(program);
6229 ASSERT(programObject);
6230 programObject->setUniform4uiv(location, count, value);
6231}
6232
6233void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6234{
6235 Program *programObject = getProgram(program);
6236 ASSERT(programObject);
6237 programObject->setUniform1fv(location, count, value);
6238}
6239
6240void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6241{
6242 Program *programObject = getProgram(program);
6243 ASSERT(programObject);
6244 programObject->setUniform2fv(location, count, value);
6245}
6246
6247void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6248{
6249 Program *programObject = getProgram(program);
6250 ASSERT(programObject);
6251 programObject->setUniform3fv(location, count, value);
6252}
6253
6254void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6255{
6256 Program *programObject = getProgram(program);
6257 ASSERT(programObject);
6258 programObject->setUniform4fv(location, count, value);
6259}
6260
6261void Context::programUniformMatrix2fv(GLuint program,
6262 GLint location,
6263 GLsizei count,
6264 GLboolean transpose,
6265 const GLfloat *value)
6266{
6267 Program *programObject = getProgram(program);
6268 ASSERT(programObject);
6269 programObject->setUniformMatrix2fv(location, count, transpose, value);
6270}
6271
6272void Context::programUniformMatrix3fv(GLuint program,
6273 GLint location,
6274 GLsizei count,
6275 GLboolean transpose,
6276 const GLfloat *value)
6277{
6278 Program *programObject = getProgram(program);
6279 ASSERT(programObject);
6280 programObject->setUniformMatrix3fv(location, count, transpose, value);
6281}
6282
6283void Context::programUniformMatrix4fv(GLuint program,
6284 GLint location,
6285 GLsizei count,
6286 GLboolean transpose,
6287 const GLfloat *value)
6288{
6289 Program *programObject = getProgram(program);
6290 ASSERT(programObject);
6291 programObject->setUniformMatrix4fv(location, count, transpose, value);
6292}
6293
6294void Context::programUniformMatrix2x3fv(GLuint program,
6295 GLint location,
6296 GLsizei count,
6297 GLboolean transpose,
6298 const GLfloat *value)
6299{
6300 Program *programObject = getProgram(program);
6301 ASSERT(programObject);
6302 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6303}
6304
6305void Context::programUniformMatrix3x2fv(GLuint program,
6306 GLint location,
6307 GLsizei count,
6308 GLboolean transpose,
6309 const GLfloat *value)
6310{
6311 Program *programObject = getProgram(program);
6312 ASSERT(programObject);
6313 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6314}
6315
6316void Context::programUniformMatrix2x4fv(GLuint program,
6317 GLint location,
6318 GLsizei count,
6319 GLboolean transpose,
6320 const GLfloat *value)
6321{
6322 Program *programObject = getProgram(program);
6323 ASSERT(programObject);
6324 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6325}
6326
6327void Context::programUniformMatrix4x2fv(GLuint program,
6328 GLint location,
6329 GLsizei count,
6330 GLboolean transpose,
6331 const GLfloat *value)
6332{
6333 Program *programObject = getProgram(program);
6334 ASSERT(programObject);
6335 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6336}
6337
6338void Context::programUniformMatrix3x4fv(GLuint program,
6339 GLint location,
6340 GLsizei count,
6341 GLboolean transpose,
6342 const GLfloat *value)
6343{
6344 Program *programObject = getProgram(program);
6345 ASSERT(programObject);
6346 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6347}
6348
6349void Context::programUniformMatrix4x3fv(GLuint program,
6350 GLint location,
6351 GLsizei count,
6352 GLboolean transpose,
6353 const GLfloat *value)
6354{
6355 Program *programObject = getProgram(program);
6356 ASSERT(programObject);
6357 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6358}
6359
Jamie Madill81c2e252017-09-09 23:32:46 -04006360void Context::onTextureChange(const Texture *texture)
6361{
6362 // Conservatively assume all textures are dirty.
6363 // TODO(jmadill): More fine-grained update.
6364 mGLState.setObjectDirty(GL_TEXTURE);
6365}
6366
James Darpiniane8a93c62018-01-04 18:02:24 -08006367bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6368{
6369 return mGLState.isCurrentTransformFeedback(tf);
6370}
6371bool Context::isCurrentVertexArray(const VertexArray *va) const
6372{
6373 return mGLState.isCurrentVertexArray(va);
6374}
6375
Yunchao Hea336b902017-08-02 16:05:21 +08006376void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6377{
6378 for (int i = 0; i < count; i++)
6379 {
6380 pipelines[i] = createProgramPipeline();
6381 }
6382}
6383
6384void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6385{
6386 for (int i = 0; i < count; i++)
6387 {
6388 if (pipelines[i] != 0)
6389 {
6390 deleteProgramPipeline(pipelines[i]);
6391 }
6392 }
6393}
6394
6395GLboolean Context::isProgramPipeline(GLuint pipeline)
6396{
6397 if (pipeline == 0)
6398 {
6399 return GL_FALSE;
6400 }
6401
6402 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6403}
6404
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006405void Context::finishFenceNV(GLuint fence)
6406{
6407 FenceNV *fenceObject = getFenceNV(fence);
6408
6409 ASSERT(fenceObject && fenceObject->isSet());
6410 handleError(fenceObject->finish());
6411}
6412
6413void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6414{
6415 FenceNV *fenceObject = getFenceNV(fence);
6416
6417 ASSERT(fenceObject && fenceObject->isSet());
6418
6419 switch (pname)
6420 {
6421 case GL_FENCE_STATUS_NV:
6422 {
6423 // GL_NV_fence spec:
6424 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6425 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6426 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6427 GLboolean status = GL_TRUE;
6428 if (fenceObject->getStatus() != GL_TRUE)
6429 {
6430 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6431 }
6432 *params = status;
6433 break;
6434 }
6435
6436 case GL_FENCE_CONDITION_NV:
6437 {
6438 *params = static_cast<GLint>(fenceObject->getCondition());
6439 break;
6440 }
6441
6442 default:
6443 UNREACHABLE();
6444 }
6445}
6446
6447void Context::getTranslatedShaderSource(GLuint shader,
6448 GLsizei bufsize,
6449 GLsizei *length,
6450 GLchar *source)
6451{
6452 Shader *shaderObject = getShader(shader);
6453 ASSERT(shaderObject);
6454 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6455}
6456
6457void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6458{
6459 Program *programObject = getProgram(program);
6460 ASSERT(programObject);
6461
6462 programObject->getUniformfv(this, location, params);
6463}
6464
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006465void Context::getnUniformfvRobust(GLuint program,
6466 GLint location,
6467 GLsizei bufSize,
6468 GLsizei *length,
6469 GLfloat *params)
6470{
6471 UNIMPLEMENTED();
6472}
6473
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006474void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6475{
6476 Program *programObject = getProgram(program);
6477 ASSERT(programObject);
6478
6479 programObject->getUniformiv(this, location, params);
6480}
6481
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006482void Context::getnUniformivRobust(GLuint program,
6483 GLint location,
6484 GLsizei bufSize,
6485 GLsizei *length,
6486 GLint *params)
6487{
6488 UNIMPLEMENTED();
6489}
6490
6491void Context::getnUniformuivRobust(GLuint program,
6492 GLint location,
6493 GLsizei bufSize,
6494 GLsizei *length,
6495 GLuint *params)
6496{
6497 UNIMPLEMENTED();
6498}
6499
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006500GLboolean Context::isFenceNV(GLuint fence)
6501{
6502 FenceNV *fenceObject = getFenceNV(fence);
6503
6504 if (fenceObject == nullptr)
6505 {
6506 return GL_FALSE;
6507 }
6508
6509 // GL_NV_fence spec:
6510 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6511 // existing fence.
6512 return fenceObject->isSet();
6513}
6514
6515void Context::readnPixels(GLint x,
6516 GLint y,
6517 GLsizei width,
6518 GLsizei height,
6519 GLenum format,
6520 GLenum type,
6521 GLsizei bufSize,
6522 void *data)
6523{
6524 return readPixels(x, y, width, height, format, type, data);
6525}
6526
Jamie Madill007530e2017-12-28 14:27:04 -05006527void Context::setFenceNV(GLuint fence, GLenum condition)
6528{
6529 ASSERT(condition == GL_ALL_COMPLETED_NV);
6530
6531 FenceNV *fenceObject = getFenceNV(fence);
6532 ASSERT(fenceObject != nullptr);
6533 handleError(fenceObject->set(condition));
6534}
6535
6536GLboolean Context::testFenceNV(GLuint fence)
6537{
6538 FenceNV *fenceObject = getFenceNV(fence);
6539
6540 ASSERT(fenceObject != nullptr);
6541 ASSERT(fenceObject->isSet() == GL_TRUE);
6542
6543 GLboolean result = GL_TRUE;
6544 Error error = fenceObject->test(&result);
6545 if (error.isError())
6546 {
6547 handleError(error);
6548 return GL_TRUE;
6549 }
6550
6551 return result;
6552}
6553
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006554void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006555{
6556 Texture *texture = getTargetTexture(target);
6557 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006558 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006559}
6560
Jamie Madillfa920eb2018-01-04 11:45:50 -05006561void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006562{
6563 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6564 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6565 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6566}
6567
Jamie Madillfa920eb2018-01-04 11:45:50 -05006568void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6569{
6570 UNIMPLEMENTED();
6571}
6572
Jamie Madill5b772312018-03-08 20:28:32 -05006573bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6574{
6575 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6576 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6577 // to the fact that it is stored internally as a float, and so would require conversion
6578 // if returned from Context::getIntegerv. Since this conversion is already implemented
6579 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6580 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6581 // application.
6582 switch (pname)
6583 {
6584 case GL_COMPRESSED_TEXTURE_FORMATS:
6585 {
6586 *type = GL_INT;
6587 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6588 return true;
6589 }
6590 case GL_SHADER_BINARY_FORMATS:
6591 {
6592 *type = GL_INT;
6593 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6594 return true;
6595 }
6596
6597 case GL_MAX_VERTEX_ATTRIBS:
6598 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6599 case GL_MAX_VARYING_VECTORS:
6600 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6601 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6602 case GL_MAX_TEXTURE_IMAGE_UNITS:
6603 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6604 case GL_MAX_RENDERBUFFER_SIZE:
6605 case GL_NUM_SHADER_BINARY_FORMATS:
6606 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6607 case GL_ARRAY_BUFFER_BINDING:
6608 case GL_FRAMEBUFFER_BINDING:
6609 case GL_RENDERBUFFER_BINDING:
6610 case GL_CURRENT_PROGRAM:
6611 case GL_PACK_ALIGNMENT:
6612 case GL_UNPACK_ALIGNMENT:
6613 case GL_GENERATE_MIPMAP_HINT:
6614 case GL_RED_BITS:
6615 case GL_GREEN_BITS:
6616 case GL_BLUE_BITS:
6617 case GL_ALPHA_BITS:
6618 case GL_DEPTH_BITS:
6619 case GL_STENCIL_BITS:
6620 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6621 case GL_CULL_FACE_MODE:
6622 case GL_FRONT_FACE:
6623 case GL_ACTIVE_TEXTURE:
6624 case GL_STENCIL_FUNC:
6625 case GL_STENCIL_VALUE_MASK:
6626 case GL_STENCIL_REF:
6627 case GL_STENCIL_FAIL:
6628 case GL_STENCIL_PASS_DEPTH_FAIL:
6629 case GL_STENCIL_PASS_DEPTH_PASS:
6630 case GL_STENCIL_BACK_FUNC:
6631 case GL_STENCIL_BACK_VALUE_MASK:
6632 case GL_STENCIL_BACK_REF:
6633 case GL_STENCIL_BACK_FAIL:
6634 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6635 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6636 case GL_DEPTH_FUNC:
6637 case GL_BLEND_SRC_RGB:
6638 case GL_BLEND_SRC_ALPHA:
6639 case GL_BLEND_DST_RGB:
6640 case GL_BLEND_DST_ALPHA:
6641 case GL_BLEND_EQUATION_RGB:
6642 case GL_BLEND_EQUATION_ALPHA:
6643 case GL_STENCIL_WRITEMASK:
6644 case GL_STENCIL_BACK_WRITEMASK:
6645 case GL_STENCIL_CLEAR_VALUE:
6646 case GL_SUBPIXEL_BITS:
6647 case GL_MAX_TEXTURE_SIZE:
6648 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6649 case GL_SAMPLE_BUFFERS:
6650 case GL_SAMPLES:
6651 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6652 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6653 case GL_TEXTURE_BINDING_2D:
6654 case GL_TEXTURE_BINDING_CUBE_MAP:
6655 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6656 {
6657 *type = GL_INT;
6658 *numParams = 1;
6659 return true;
6660 }
6661 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6662 {
6663 if (!getExtensions().packReverseRowOrder)
6664 {
6665 return false;
6666 }
6667 *type = GL_INT;
6668 *numParams = 1;
6669 return true;
6670 }
6671 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6672 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6673 {
6674 if (!getExtensions().textureRectangle)
6675 {
6676 return false;
6677 }
6678 *type = GL_INT;
6679 *numParams = 1;
6680 return true;
6681 }
6682 case GL_MAX_DRAW_BUFFERS_EXT:
6683 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6684 {
6685 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6686 {
6687 return false;
6688 }
6689 *type = GL_INT;
6690 *numParams = 1;
6691 return true;
6692 }
6693 case GL_MAX_VIEWPORT_DIMS:
6694 {
6695 *type = GL_INT;
6696 *numParams = 2;
6697 return true;
6698 }
6699 case GL_VIEWPORT:
6700 case GL_SCISSOR_BOX:
6701 {
6702 *type = GL_INT;
6703 *numParams = 4;
6704 return true;
6705 }
6706 case GL_SHADER_COMPILER:
6707 case GL_SAMPLE_COVERAGE_INVERT:
6708 case GL_DEPTH_WRITEMASK:
6709 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6710 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6711 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6712 // bool-natural
6713 case GL_SAMPLE_COVERAGE:
6714 case GL_SCISSOR_TEST:
6715 case GL_STENCIL_TEST:
6716 case GL_DEPTH_TEST:
6717 case GL_BLEND:
6718 case GL_DITHER:
6719 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6720 {
6721 *type = GL_BOOL;
6722 *numParams = 1;
6723 return true;
6724 }
6725 case GL_COLOR_WRITEMASK:
6726 {
6727 *type = GL_BOOL;
6728 *numParams = 4;
6729 return true;
6730 }
6731 case GL_POLYGON_OFFSET_FACTOR:
6732 case GL_POLYGON_OFFSET_UNITS:
6733 case GL_SAMPLE_COVERAGE_VALUE:
6734 case GL_DEPTH_CLEAR_VALUE:
6735 case GL_LINE_WIDTH:
6736 {
6737 *type = GL_FLOAT;
6738 *numParams = 1;
6739 return true;
6740 }
6741 case GL_ALIASED_LINE_WIDTH_RANGE:
6742 case GL_ALIASED_POINT_SIZE_RANGE:
6743 case GL_DEPTH_RANGE:
6744 {
6745 *type = GL_FLOAT;
6746 *numParams = 2;
6747 return true;
6748 }
6749 case GL_COLOR_CLEAR_VALUE:
6750 case GL_BLEND_COLOR:
6751 {
6752 *type = GL_FLOAT;
6753 *numParams = 4;
6754 return true;
6755 }
6756 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6757 if (!getExtensions().textureFilterAnisotropic)
6758 {
6759 return false;
6760 }
6761 *type = GL_FLOAT;
6762 *numParams = 1;
6763 return true;
6764 case GL_TIMESTAMP_EXT:
6765 if (!getExtensions().disjointTimerQuery)
6766 {
6767 return false;
6768 }
6769 *type = GL_INT_64_ANGLEX;
6770 *numParams = 1;
6771 return true;
6772 case GL_GPU_DISJOINT_EXT:
6773 if (!getExtensions().disjointTimerQuery)
6774 {
6775 return false;
6776 }
6777 *type = GL_INT;
6778 *numParams = 1;
6779 return true;
6780 case GL_COVERAGE_MODULATION_CHROMIUM:
6781 if (!getExtensions().framebufferMixedSamples)
6782 {
6783 return false;
6784 }
6785 *type = GL_INT;
6786 *numParams = 1;
6787 return true;
6788 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6789 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6790 {
6791 return false;
6792 }
6793 *type = GL_INT;
6794 *numParams = 1;
6795 return true;
6796 }
6797
6798 if (getExtensions().debug)
6799 {
6800 switch (pname)
6801 {
6802 case GL_DEBUG_LOGGED_MESSAGES:
6803 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6804 case GL_DEBUG_GROUP_STACK_DEPTH:
6805 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6806 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6807 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6808 case GL_MAX_LABEL_LENGTH:
6809 *type = GL_INT;
6810 *numParams = 1;
6811 return true;
6812
6813 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6814 case GL_DEBUG_OUTPUT:
6815 *type = GL_BOOL;
6816 *numParams = 1;
6817 return true;
6818 }
6819 }
6820
6821 if (getExtensions().multisampleCompatibility)
6822 {
6823 switch (pname)
6824 {
6825 case GL_MULTISAMPLE_EXT:
6826 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6827 *type = GL_BOOL;
6828 *numParams = 1;
6829 return true;
6830 }
6831 }
6832
6833 if (getExtensions().pathRendering)
6834 {
6835 switch (pname)
6836 {
6837 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6838 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6839 *type = GL_FLOAT;
6840 *numParams = 16;
6841 return true;
6842 }
6843 }
6844
6845 if (getExtensions().bindGeneratesResource)
6846 {
6847 switch (pname)
6848 {
6849 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6850 *type = GL_BOOL;
6851 *numParams = 1;
6852 return true;
6853 }
6854 }
6855
6856 if (getExtensions().clientArrays)
6857 {
6858 switch (pname)
6859 {
6860 case GL_CLIENT_ARRAYS_ANGLE:
6861 *type = GL_BOOL;
6862 *numParams = 1;
6863 return true;
6864 }
6865 }
6866
6867 if (getExtensions().sRGBWriteControl)
6868 {
6869 switch (pname)
6870 {
6871 case GL_FRAMEBUFFER_SRGB_EXT:
6872 *type = GL_BOOL;
6873 *numParams = 1;
6874 return true;
6875 }
6876 }
6877
6878 if (getExtensions().robustResourceInitialization &&
6879 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6880 {
6881 *type = GL_BOOL;
6882 *numParams = 1;
6883 return true;
6884 }
6885
6886 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6887 {
6888 *type = GL_BOOL;
6889 *numParams = 1;
6890 return true;
6891 }
6892
6893 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6894 switch (pname)
6895 {
6896 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6897 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6898 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6899 {
6900 return false;
6901 }
6902 *type = GL_INT;
6903 *numParams = 1;
6904 return true;
6905
6906 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6907 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6908 {
6909 return false;
6910 }
6911 *type = GL_INT;
6912 *numParams = 1;
6913 return true;
6914
6915 case GL_PROGRAM_BINARY_FORMATS_OES:
6916 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6917 {
6918 return false;
6919 }
6920 *type = GL_INT;
6921 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6922 return true;
6923
6924 case GL_PACK_ROW_LENGTH:
6925 case GL_PACK_SKIP_ROWS:
6926 case GL_PACK_SKIP_PIXELS:
6927 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6928 {
6929 return false;
6930 }
6931 *type = GL_INT;
6932 *numParams = 1;
6933 return true;
6934 case GL_UNPACK_ROW_LENGTH:
6935 case GL_UNPACK_SKIP_ROWS:
6936 case GL_UNPACK_SKIP_PIXELS:
6937 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6938 {
6939 return false;
6940 }
6941 *type = GL_INT;
6942 *numParams = 1;
6943 return true;
6944 case GL_VERTEX_ARRAY_BINDING:
6945 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6946 {
6947 return false;
6948 }
6949 *type = GL_INT;
6950 *numParams = 1;
6951 return true;
6952 case GL_PIXEL_PACK_BUFFER_BINDING:
6953 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6954 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6955 {
6956 return false;
6957 }
6958 *type = GL_INT;
6959 *numParams = 1;
6960 return true;
6961 case GL_MAX_SAMPLES:
6962 {
6963 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6964 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6965 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6966 {
6967 return false;
6968 }
6969 *type = GL_INT;
6970 *numParams = 1;
6971 return true;
6972
6973 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6974 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6975 {
6976 return false;
6977 }
6978 *type = GL_INT;
6979 *numParams = 1;
6980 return true;
6981 }
6982 }
6983
6984 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6985 {
6986 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6987 {
6988 return false;
6989 }
6990 *type = GL_INT;
6991 *numParams = 1;
6992 return true;
6993 }
6994
6995 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6996 {
6997 *type = GL_INT;
6998 *numParams = 1;
6999 return true;
7000 }
7001
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007002 if (getClientVersion() < Version(2, 0))
7003 {
7004 switch (pname)
7005 {
7006 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007007 case GL_CLIENT_ACTIVE_TEXTURE:
7008 case GL_MATRIX_MODE:
7009 case GL_MAX_TEXTURE_UNITS:
7010 case GL_MAX_MODELVIEW_STACK_DEPTH:
7011 case GL_MAX_PROJECTION_STACK_DEPTH:
7012 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007013 case GL_VERTEX_ARRAY_STRIDE:
7014 case GL_NORMAL_ARRAY_STRIDE:
7015 case GL_COLOR_ARRAY_STRIDE:
7016 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7017 case GL_VERTEX_ARRAY_SIZE:
7018 case GL_COLOR_ARRAY_SIZE:
7019 case GL_TEXTURE_COORD_ARRAY_SIZE:
7020 case GL_VERTEX_ARRAY_TYPE:
7021 case GL_NORMAL_ARRAY_TYPE:
7022 case GL_COLOR_ARRAY_TYPE:
7023 case GL_TEXTURE_COORD_ARRAY_TYPE:
7024 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7025 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7026 case GL_COLOR_ARRAY_BUFFER_BINDING:
7027 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7028 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7029 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7030 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007031 *type = GL_INT;
7032 *numParams = 1;
7033 return true;
7034 case GL_ALPHA_TEST_REF:
7035 *type = GL_FLOAT;
7036 *numParams = 1;
7037 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007038 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007039 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007040 *type = GL_FLOAT;
7041 *numParams = 4;
7042 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007043 case GL_CURRENT_NORMAL:
7044 *type = GL_FLOAT;
7045 *numParams = 3;
7046 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007047 case GL_MODELVIEW_MATRIX:
7048 case GL_PROJECTION_MATRIX:
7049 case GL_TEXTURE_MATRIX:
7050 *type = GL_FLOAT;
7051 *numParams = 16;
7052 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007053 }
7054 }
7055
Jamie Madill5b772312018-03-08 20:28:32 -05007056 if (getClientVersion() < Version(3, 0))
7057 {
7058 return false;
7059 }
7060
7061 // Check for ES3.0+ parameter names
7062 switch (pname)
7063 {
7064 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7065 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7066 case GL_UNIFORM_BUFFER_BINDING:
7067 case GL_TRANSFORM_FEEDBACK_BINDING:
7068 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7069 case GL_COPY_READ_BUFFER_BINDING:
7070 case GL_COPY_WRITE_BUFFER_BINDING:
7071 case GL_SAMPLER_BINDING:
7072 case GL_READ_BUFFER:
7073 case GL_TEXTURE_BINDING_3D:
7074 case GL_TEXTURE_BINDING_2D_ARRAY:
7075 case GL_MAX_3D_TEXTURE_SIZE:
7076 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7077 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7078 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7079 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7080 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7081 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7082 case GL_MAX_VARYING_COMPONENTS:
7083 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7084 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7085 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7086 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7087 case GL_NUM_EXTENSIONS:
7088 case GL_MAJOR_VERSION:
7089 case GL_MINOR_VERSION:
7090 case GL_MAX_ELEMENTS_INDICES:
7091 case GL_MAX_ELEMENTS_VERTICES:
7092 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7093 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7094 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7095 case GL_UNPACK_IMAGE_HEIGHT:
7096 case GL_UNPACK_SKIP_IMAGES:
7097 {
7098 *type = GL_INT;
7099 *numParams = 1;
7100 return true;
7101 }
7102
7103 case GL_MAX_ELEMENT_INDEX:
7104 case GL_MAX_UNIFORM_BLOCK_SIZE:
7105 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7106 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7107 case GL_MAX_SERVER_WAIT_TIMEOUT:
7108 {
7109 *type = GL_INT_64_ANGLEX;
7110 *numParams = 1;
7111 return true;
7112 }
7113
7114 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7115 case GL_TRANSFORM_FEEDBACK_PAUSED:
7116 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7117 case GL_RASTERIZER_DISCARD:
7118 {
7119 *type = GL_BOOL;
7120 *numParams = 1;
7121 return true;
7122 }
7123
7124 case GL_MAX_TEXTURE_LOD_BIAS:
7125 {
7126 *type = GL_FLOAT;
7127 *numParams = 1;
7128 return true;
7129 }
7130 }
7131
7132 if (getExtensions().requestExtension)
7133 {
7134 switch (pname)
7135 {
7136 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7137 *type = GL_INT;
7138 *numParams = 1;
7139 return true;
7140 }
7141 }
7142
7143 if (getClientVersion() < Version(3, 1))
7144 {
7145 return false;
7146 }
7147
7148 switch (pname)
7149 {
7150 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7151 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7152 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7153 case GL_MAX_FRAMEBUFFER_WIDTH:
7154 case GL_MAX_FRAMEBUFFER_HEIGHT:
7155 case GL_MAX_FRAMEBUFFER_SAMPLES:
7156 case GL_MAX_SAMPLE_MASK_WORDS:
7157 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7158 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7159 case GL_MAX_INTEGER_SAMPLES:
7160 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7161 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7162 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7163 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7164 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7165 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7166 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7167 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7168 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7169 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7170 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7171 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7172 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7173 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7174 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7175 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7176 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7177 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7178 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7179 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7180 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7181 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7182 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7183 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7184 case GL_MAX_UNIFORM_LOCATIONS:
7185 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7186 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7187 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7188 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7189 case GL_MAX_IMAGE_UNITS:
7190 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7191 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7192 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7193 case GL_SHADER_STORAGE_BUFFER_BINDING:
7194 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7195 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7196 *type = GL_INT;
7197 *numParams = 1;
7198 return true;
7199 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7200 *type = GL_INT_64_ANGLEX;
7201 *numParams = 1;
7202 return true;
7203 case GL_SAMPLE_MASK:
7204 *type = GL_BOOL;
7205 *numParams = 1;
7206 return true;
7207 }
7208
7209 if (getExtensions().geometryShader)
7210 {
7211 switch (pname)
7212 {
7213 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7214 case GL_LAYER_PROVOKING_VERTEX_EXT:
7215 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7216 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7217 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7218 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7219 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7220 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7221 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7222 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7223 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7224 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7225 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7226 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7227 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7228 *type = GL_INT;
7229 *numParams = 1;
7230 return true;
7231 }
7232 }
7233
7234 return false;
7235}
7236
7237bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7238{
7239 if (getClientVersion() < Version(3, 0))
7240 {
7241 return false;
7242 }
7243
7244 switch (target)
7245 {
7246 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7247 case GL_UNIFORM_BUFFER_BINDING:
7248 {
7249 *type = GL_INT;
7250 *numParams = 1;
7251 return true;
7252 }
7253 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7254 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7255 case GL_UNIFORM_BUFFER_START:
7256 case GL_UNIFORM_BUFFER_SIZE:
7257 {
7258 *type = GL_INT_64_ANGLEX;
7259 *numParams = 1;
7260 return true;
7261 }
7262 }
7263
7264 if (getClientVersion() < Version(3, 1))
7265 {
7266 return false;
7267 }
7268
7269 switch (target)
7270 {
7271 case GL_IMAGE_BINDING_LAYERED:
7272 {
7273 *type = GL_BOOL;
7274 *numParams = 1;
7275 return true;
7276 }
7277 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7278 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7279 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7280 case GL_SHADER_STORAGE_BUFFER_BINDING:
7281 case GL_VERTEX_BINDING_BUFFER:
7282 case GL_VERTEX_BINDING_DIVISOR:
7283 case GL_VERTEX_BINDING_OFFSET:
7284 case GL_VERTEX_BINDING_STRIDE:
7285 case GL_SAMPLE_MASK_VALUE:
7286 case GL_IMAGE_BINDING_NAME:
7287 case GL_IMAGE_BINDING_LEVEL:
7288 case GL_IMAGE_BINDING_LAYER:
7289 case GL_IMAGE_BINDING_ACCESS:
7290 case GL_IMAGE_BINDING_FORMAT:
7291 {
7292 *type = GL_INT;
7293 *numParams = 1;
7294 return true;
7295 }
7296 case GL_ATOMIC_COUNTER_BUFFER_START:
7297 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7298 case GL_SHADER_STORAGE_BUFFER_START:
7299 case GL_SHADER_STORAGE_BUFFER_SIZE:
7300 {
7301 *type = GL_INT_64_ANGLEX;
7302 *numParams = 1;
7303 return true;
7304 }
7305 }
7306
7307 return false;
7308}
7309
7310Program *Context::getProgram(GLuint handle) const
7311{
7312 return mState.mShaderPrograms->getProgram(handle);
7313}
7314
7315Shader *Context::getShader(GLuint handle) const
7316{
7317 return mState.mShaderPrograms->getShader(handle);
7318}
7319
7320bool Context::isTextureGenerated(GLuint texture) const
7321{
7322 return mState.mTextures->isHandleGenerated(texture);
7323}
7324
7325bool Context::isBufferGenerated(GLuint buffer) const
7326{
7327 return mState.mBuffers->isHandleGenerated(buffer);
7328}
7329
7330bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7331{
7332 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7333}
7334
7335bool Context::isFramebufferGenerated(GLuint framebuffer) const
7336{
7337 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7338}
7339
7340bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7341{
7342 return mState.mPipelines->isHandleGenerated(pipeline);
7343}
7344
7345bool Context::usingDisplayTextureShareGroup() const
7346{
7347 return mDisplayTextureShareGroup;
7348}
7349
7350GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7351{
7352 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7353 internalformat == GL_DEPTH_STENCIL
7354 ? GL_DEPTH24_STENCIL8
7355 : internalformat;
7356}
7357
Jamie Madillc29968b2016-01-20 11:17:23 -05007358} // namespace gl