blob: 5bc64e2f8e5cebfd4e2646a447cb0b8fbdad412d [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"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070027#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030028#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080030#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050032#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050033#include "libANGLE/ResourceManager.h"
34#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050035#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050036#include "libANGLE/Texture.h"
37#include "libANGLE/TransformFeedback.h"
38#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040040#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030041#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040042#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040043#include "libANGLE/renderer/ContextImpl.h"
44#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040045#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040046#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000047
Geoff Langf6db0982015-08-25 13:04:00 -040048namespace
49{
50
Jamie Madillb6664922017-07-25 12:55:04 -040051#define ANGLE_HANDLE_ERR(X) \
52 handleError(X); \
53 return;
54#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
55
Ian Ewell3ffd78b2016-01-22 16:09:42 -050056template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050057std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030058 GLsizei numPaths,
59 const void *paths,
60 GLuint pathBase)
61{
62 std::vector<gl::Path *> ret;
63 ret.reserve(numPaths);
64
65 const auto *nameArray = static_cast<const T *>(paths);
66
67 for (GLsizei i = 0; i < numPaths; ++i)
68 {
69 const GLuint pathName = nameArray[i] + pathBase;
70
71 ret.push_back(resourceManager.getPath(pathName));
72 }
73
74 return ret;
75}
76
Geoff Lang4ddf5af2016-12-01 14:30:44 -050077std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030078 GLsizei numPaths,
79 GLenum pathNameType,
80 const void *paths,
81 GLuint pathBase)
82{
83 switch (pathNameType)
84 {
85 case GL_UNSIGNED_BYTE:
86 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_BYTE:
89 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_UNSIGNED_SHORT:
92 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_SHORT:
95 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_UNSIGNED_INT:
98 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_INT:
101 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
102 }
103
104 UNREACHABLE();
105 return std::vector<gl::Path *>();
106}
107
108template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400109gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110{
Geoff Lang2186c382016-10-14 10:54:54 -0400111 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500112
113 switch (pname)
114 {
115 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400116 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117 case GL_QUERY_RESULT_AVAILABLE_EXT:
118 {
119 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400120 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 if (!error.isError())
122 {
jchen10a99ed552017-09-22 08:10:32 +0800123 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125 return error;
126 }
127 default:
128 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500129 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill09463932018-04-04 05:26:59 -0400133void MarkTransformFeedbackBufferUsage(const gl::Context *context,
134 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Geoff Lang1a683462015-09-29 15:09:59 -0400138 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155gl::Version GetClientVersion(const egl::AttributeMap &attribs)
156{
157 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Geoff Langf6db0982015-08-25 13:04:00 -0400257} // anonymous namespace
258
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000259namespace gl
260{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000261
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400262Context::Context(rx::EGLImplFactory *implFactory,
263 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400264 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500265 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400266 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500267 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700268 const egl::DisplayExtensions &displayExtensions,
269 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500270 : mState(reinterpret_cast<ContextID>(this),
271 shareContext ? &shareContext->mState : nullptr,
272 shareTextures,
273 GetClientVersion(attribs),
274 &mGLState,
275 mCaps,
276 mTextureCaps,
277 mExtensions,
278 mLimitations),
279 mSkipValidation(GetNoError(attribs)),
280 mDisplayTextureShareGroup(shareTextures != nullptr),
281 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700282 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400283 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400284 mGLState(GetDebug(attribs),
285 GetBindGeneratesResource(attribs),
286 GetClientArraysEnabled(attribs),
287 GetRobustResourceInit(attribs),
288 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400289 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mClientType(EGL_OPENGL_ES_API),
291 mHasBeenCurrent(false),
292 mContextLost(false),
293 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700294 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500295 mResetStrategy(GetResetStrategy(attribs)),
296 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400297 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
298 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500299 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400300 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400301 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400302 mScratchBuffer(1000u),
303 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000304{
Jamie Madill5b772312018-03-08 20:28:32 -0500305 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400306 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
307 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500308
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400309 mImplementation->setMemoryProgramCache(memoryProgramCache);
310
Geoff Langb433e872017-10-05 14:01:47 -0400311 bool robustResourceInit = GetRobustResourceInit(attribs);
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700312 initCaps(displayExtensions, clientExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700313 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400314
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400315 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100316
Shannon Woods53a94a82014-06-24 15:20:36 -0400317 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400318
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000319 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400320 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000321 // and cube map texture state vectors respectively associated with them.
322 // In order that access to these initial textures not be lost, they are treated as texture
323 // objects all of whose names are 0.
324
Corentin Wallez99d492c2018-02-27 15:17:10 -0500325 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500327
Corentin Wallez99d492c2018-02-27 15:17:10 -0500328 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800329 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400330
Geoff Langeb66a6e2016-10-31 13:06:12 -0400331 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400332 {
333 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500334 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800335 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400336
Corentin Wallez99d492c2018-02-27 15:17:10 -0500337 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400339 }
Geoff Lang3b573612016-10-31 14:08:10 -0400340 if (getClientVersion() >= Version(3, 1))
341 {
342 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500343 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800344 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800345
Jiajia Qin6eafb042016-12-27 17:04:07 +0800346 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
347 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800348 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800349 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800350
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800351 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
352 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400353 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800354 }
Geoff Lang3b573612016-10-31 14:08:10 -0400355 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000356
Geoff Langb0f917f2017-12-05 13:41:54 -0500357 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400358 {
359 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500360 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800361 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400362 }
363
Geoff Langb0f917f2017-12-05 13:41:54 -0500364 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400365 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500366 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800367 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400368 }
369
Jamie Madill4928b7c2017-06-20 12:57:39 -0400370 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500371
Jamie Madill57a89722013-07-02 11:57:03 -0400372 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000373
Geoff Langeb66a6e2016-10-31 13:06:12 -0400374 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400375 {
376 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
377 // In the initial state, a default transform feedback object is bound and treated as
378 // a transform feedback object with a name of zero. That object is bound any time
379 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400380 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400381 }
Geoff Langc8058452014-02-03 12:04:11 -0500382
Corentin Wallez336129f2017-10-17 15:55:40 -0400383 for (auto type : angle::AllEnums<BufferBinding>())
384 {
385 bindBuffer(type, 0);
386 }
387
388 bindRenderbuffer(GL_RENDERBUFFER, 0);
389
390 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
391 {
392 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
393 }
394
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700395 // Initialize GLES1 renderer if appropriate.
396 if (getClientVersion() < Version(2, 0))
397 {
398 mGLES1Renderer.reset(new GLES1Renderer());
399 }
400
Jamie Madillad9f24e2016-02-12 09:27:24 -0500401 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400402 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500403 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500404 // No dirty objects.
405
406 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400407 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500408 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
410
411 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
412 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
413 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
416 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
417 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
418 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
419 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
420 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
421 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
422 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
423
424 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
425 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700426 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500427 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
428 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400429
Xinghua Cao10a4d432017-11-28 14:46:26 +0800430 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
431 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
432 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
433 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
434 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
435 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800436 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800437 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800438
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400439 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440}
441
Jamie Madill4928b7c2017-06-20 12:57:39 -0400442egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700444 if (mGLES1Renderer)
445 {
446 mGLES1Renderer->onDestroy(this, &mGLState);
447 }
448
Jamie Madille7b3fe22018-04-05 09:42:46 -0400449 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400450 ANGLE_TRY(releaseSurface(display));
451
Corentin Wallez80b24112015-08-25 16:41:57 -0400452 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000453 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400454 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000455 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400456 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400460 if (query.second != nullptr)
461 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400462 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400463 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400465 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallez80b24112015-08-25 16:41:57 -0400467 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400468 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 if (vertexArray.second)
470 {
471 vertexArray.second->onDestroy(this);
472 }
Jamie Madill57a89722013-07-02 11:57:03 -0400473 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400474 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400475
Corentin Wallez80b24112015-08-25 16:41:57 -0400476 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500477 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500478 if (transformFeedback.second != nullptr)
479 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500480 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500481 }
Geoff Langc8058452014-02-03 12:04:11 -0500482 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400483 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500484
Jamie Madill5b772312018-03-08 20:28:32 -0500485 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400486 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800487 if (zeroTexture.get() != nullptr)
488 {
489 ANGLE_TRY(zeroTexture->onDestroy(this));
490 zeroTexture.set(this, nullptr);
491 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400492 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493
Jamie Madill2f348d22017-06-05 10:50:59 -0400494 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500495
Jamie Madill4928b7c2017-06-20 12:57:39 -0400496 mGLState.reset(this);
497
Jamie Madill6c1f6712017-02-14 19:08:04 -0500498 mState.mBuffers->release(this);
499 mState.mShaderPrograms->release(this);
500 mState.mTextures->release(this);
501 mState.mRenderbuffers->release(this);
502 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400503 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500504 mState.mPaths->release(this);
505 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800506 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400507
Jamie Madill76e471e2017-10-21 09:56:01 -0400508 mImplementation->onDestroy(this);
509
Jamie Madill4928b7c2017-06-20 12:57:39 -0400510 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511}
512
Jamie Madill70ee0f62017-02-06 16:04:20 -0500513Context::~Context()
514{
515}
516
Jamie Madill4928b7c2017-06-20 12:57:39 -0400517egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000518{
Jamie Madill61e16b42017-06-19 11:13:23 -0400519 mCurrentDisplay = display;
520
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521 if (!mHasBeenCurrent)
522 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500524 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400525 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000526
Corentin Wallezc295e512017-01-27 17:47:50 -0500527 int width = 0;
528 int height = 0;
529 if (surface != nullptr)
530 {
531 width = surface->getWidth();
532 height = surface->getHeight();
533 }
534
535 mGLState.setViewportParams(0, 0, width, height);
536 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537
538 mHasBeenCurrent = true;
539 }
540
Jamie Madill1b94d432015-08-07 13:23:23 -0400541 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700542 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400543 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400544
Jamie Madill4928b7c2017-06-20 12:57:39 -0400545 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500546
547 Framebuffer *newDefault = nullptr;
548 if (surface != nullptr)
549 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400550 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500551 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400552 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500553 }
554 else
555 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400556 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500557 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000558
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 // Update default framebuffer, the binding of the previous default
560 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400561 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700562 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400563 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700564 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400565 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700566 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400567 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700568 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400569 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500570 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400571 }
Ian Ewell292f0052016-02-04 10:37:32 -0500572
573 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400574 mImplementation->onMakeCurrent(this);
575 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000576}
577
Jamie Madill4928b7c2017-06-20 12:57:39 -0400578egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400579{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400580 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400581
Geoff Langbf7b95d2018-05-01 16:48:21 -0400582 // Remove the default framebuffer
583 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500584 {
585 mGLState.setReadFramebufferBinding(nullptr);
586 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400587
588 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 {
590 mGLState.setDrawFramebufferBinding(nullptr);
591 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400592
593 if (defaultFramebuffer)
594 {
595 defaultFramebuffer->onDestroy(this);
596 delete defaultFramebuffer;
597 }
598
Corentin Wallezc295e512017-01-27 17:47:50 -0500599 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
600
601 if (mCurrentSurface)
602 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400603 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500604 mCurrentSurface = nullptr;
605 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400606
607 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400608}
609
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610GLuint Context::createBuffer()
611{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500612 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613}
614
615GLuint Context::createProgram()
616{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500617 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618}
619
Jiawei Shao385b3e02018-03-21 09:43:28 +0800620GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500622 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623}
624
625GLuint Context::createTexture()
626{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500627 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628}
629
630GLuint Context::createRenderbuffer()
631{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500632 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
Brandon Jones59770802018-04-02 13:18:42 -0700635GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300636{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500637 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300638 if (resultOrError.isError())
639 {
640 handleError(resultOrError.getError());
641 return 0;
642 }
643 return resultOrError.getResult();
644}
645
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646// Returns an unused framebuffer name
647GLuint Context::createFramebuffer()
648{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500649 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650}
651
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500652void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500654 for (int i = 0; i < n; i++)
655 {
656 GLuint handle = mFenceNVHandleAllocator.allocate();
657 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
658 fences[i] = handle;
659 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000660}
661
Yunchao Hea336b902017-08-02 16:05:21 +0800662GLuint Context::createProgramPipeline()
663{
664 return mState.mPipelines->createProgramPipeline();
665}
666
Jiawei Shao385b3e02018-03-21 09:43:28 +0800667GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800668{
669 UNIMPLEMENTED();
670 return 0u;
671}
672
James Darpinian4d9d4832018-03-13 12:43:28 -0700673void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674{
James Darpinian4d9d4832018-03-13 12:43:28 -0700675 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
676 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677 {
678 detachBuffer(buffer);
679 }
Jamie Madill893ab082014-05-16 16:56:10 -0400680
James Darpinian4d9d4832018-03-13 12:43:28 -0700681 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
684void Context::deleteShader(GLuint shader)
685{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500686 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
689void Context::deleteProgram(GLuint program)
690{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
694void Context::deleteTexture(GLuint texture)
695{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500696 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697 {
698 detachTexture(texture);
699 }
700
Jamie Madill6c1f6712017-02-14 19:08:04 -0500701 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000702}
703
704void Context::deleteRenderbuffer(GLuint renderbuffer)
705{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500706 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707 {
708 detachRenderbuffer(renderbuffer);
709 }
Jamie Madill893ab082014-05-16 16:56:10 -0400710
Jamie Madill6c1f6712017-02-14 19:08:04 -0500711 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400714void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400715{
716 // The spec specifies the underlying Fence object is not deleted until all current
717 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
718 // and since our API is currently designed for being called from a single thread, we can delete
719 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400720 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400721}
722
Yunchao Hea336b902017-08-02 16:05:21 +0800723void Context::deleteProgramPipeline(GLuint pipeline)
724{
725 if (mState.mPipelines->getProgramPipeline(pipeline))
726 {
727 detachProgramPipeline(pipeline);
728 }
729
730 mState.mPipelines->deleteObject(this, pipeline);
731}
732
Sami Väisänene45e53b2016-05-25 10:36:04 +0300733void Context::deletePaths(GLuint first, GLsizei range)
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300736}
737
Brandon Jones59770802018-04-02 13:18:42 -0700738bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741 if (pathObj == nullptr)
742 return false;
743
744 return pathObj->hasPathData();
745}
746
Brandon Jones59770802018-04-02 13:18:42 -0700747bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500749 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750}
751
Brandon Jones59770802018-04-02 13:18:42 -0700752void Context::pathCommands(GLuint path,
753 GLsizei numCommands,
754 const GLubyte *commands,
755 GLsizei numCoords,
756 GLenum coordType,
757 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300758{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500759 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300760
761 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
762}
763
Jamie Madill007530e2017-12-28 14:27:04 -0500764void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300765{
Jamie Madill007530e2017-12-28 14:27:04 -0500766 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300767
768 switch (pname)
769 {
770 case GL_PATH_STROKE_WIDTH_CHROMIUM:
771 pathObj->setStrokeWidth(value);
772 break;
773 case GL_PATH_END_CAPS_CHROMIUM:
774 pathObj->setEndCaps(static_cast<GLenum>(value));
775 break;
776 case GL_PATH_JOIN_STYLE_CHROMIUM:
777 pathObj->setJoinStyle(static_cast<GLenum>(value));
778 break;
779 case GL_PATH_MITER_LIMIT_CHROMIUM:
780 pathObj->setMiterLimit(value);
781 break;
782 case GL_PATH_STROKE_BOUND_CHROMIUM:
783 pathObj->setStrokeBound(value);
784 break;
785 default:
786 UNREACHABLE();
787 break;
788 }
789}
790
Jamie Madill007530e2017-12-28 14:27:04 -0500791void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300792{
Jamie Madill007530e2017-12-28 14:27:04 -0500793 // TODO(jmadill): Should use proper clamping/casting.
794 pathParameterf(path, pname, static_cast<GLfloat>(value));
795}
796
797void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
798{
799 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300800
801 switch (pname)
802 {
803 case GL_PATH_STROKE_WIDTH_CHROMIUM:
804 *value = pathObj->getStrokeWidth();
805 break;
806 case GL_PATH_END_CAPS_CHROMIUM:
807 *value = static_cast<GLfloat>(pathObj->getEndCaps());
808 break;
809 case GL_PATH_JOIN_STYLE_CHROMIUM:
810 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
811 break;
812 case GL_PATH_MITER_LIMIT_CHROMIUM:
813 *value = pathObj->getMiterLimit();
814 break;
815 case GL_PATH_STROKE_BOUND_CHROMIUM:
816 *value = pathObj->getStrokeBound();
817 break;
818 default:
819 UNREACHABLE();
820 break;
821 }
822}
823
Jamie Madill007530e2017-12-28 14:27:04 -0500824void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
825{
826 GLfloat val = 0.0f;
827 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
828 if (value)
829 *value = static_cast<GLint>(val);
830}
831
Brandon Jones59770802018-04-02 13:18:42 -0700832void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300833{
834 mGLState.setPathStencilFunc(func, ref, mask);
835}
836
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837void Context::deleteFramebuffer(GLuint framebuffer)
838{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500839 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840 {
841 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500843
Jamie Madill6c1f6712017-02-14 19:08:04 -0500844 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845}
846
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500847void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500849 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500851 GLuint fence = fences[i];
852
853 FenceNV *fenceObject = nullptr;
854 if (mFenceNVMap.erase(fence, &fenceObject))
855 {
856 mFenceNVHandleAllocator.release(fence);
857 delete fenceObject;
858 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859 }
860}
861
Geoff Lang70d0f492015-12-10 17:45:46 -0500862Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500864 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865}
866
Jamie Madill570f7c82014-07-03 10:38:54 -0400867Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870}
871
Geoff Lang70d0f492015-12-10 17:45:46 -0500872Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500874 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875}
876
Jamie Madill70b5bb02017-08-28 13:32:37 -0400877Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400878{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400879 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400880}
881
Jamie Madill57a89722013-07-02 11:57:03 -0400882VertexArray *Context::getVertexArray(GLuint handle) const
883{
Jamie Madill96a483b2017-06-27 16:49:21 -0400884 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400885}
886
Jamie Madilldc356042013-07-19 16:36:57 -0400887Sampler *Context::getSampler(GLuint handle) const
888{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500889 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400890}
891
Geoff Langc8058452014-02-03 12:04:11 -0500892TransformFeedback *Context::getTransformFeedback(GLuint handle) const
893{
Jamie Madill96a483b2017-06-27 16:49:21 -0400894 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500895}
896
Yunchao Hea336b902017-08-02 16:05:21 +0800897ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
898{
899 return mState.mPipelines->getProgramPipeline(handle);
900}
901
Geoff Lang70d0f492015-12-10 17:45:46 -0500902LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
903{
904 switch (identifier)
905 {
906 case GL_BUFFER:
907 return getBuffer(name);
908 case GL_SHADER:
909 return getShader(name);
910 case GL_PROGRAM:
911 return getProgram(name);
912 case GL_VERTEX_ARRAY:
913 return getVertexArray(name);
914 case GL_QUERY:
915 return getQuery(name);
916 case GL_TRANSFORM_FEEDBACK:
917 return getTransformFeedback(name);
918 case GL_SAMPLER:
919 return getSampler(name);
920 case GL_TEXTURE:
921 return getTexture(name);
922 case GL_RENDERBUFFER:
923 return getRenderbuffer(name);
924 case GL_FRAMEBUFFER:
925 return getFramebuffer(name);
926 default:
927 UNREACHABLE();
928 return nullptr;
929 }
930}
931
932LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
933{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400934 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500935}
936
Martin Radev9d901792016-07-15 15:58:58 +0300937void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
938{
939 LabeledObject *object = getLabeledObject(identifier, name);
940 ASSERT(object != nullptr);
941
942 std::string labelName = GetObjectLabelFromPointer(length, label);
943 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400944
945 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
946 // specified object is active until we do this.
947 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300948}
949
950void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
951{
952 LabeledObject *object = getLabeledObjectFromPtr(ptr);
953 ASSERT(object != nullptr);
954
955 std::string labelName = GetObjectLabelFromPointer(length, label);
956 object->setLabel(labelName);
957}
958
959void Context::getObjectLabel(GLenum identifier,
960 GLuint name,
961 GLsizei bufSize,
962 GLsizei *length,
963 GLchar *label) const
964{
965 LabeledObject *object = getLabeledObject(identifier, name);
966 ASSERT(object != nullptr);
967
968 const std::string &objectLabel = object->getLabel();
969 GetObjectLabelBase(objectLabel, bufSize, length, label);
970}
971
972void Context::getObjectPtrLabel(const void *ptr,
973 GLsizei bufSize,
974 GLsizei *length,
975 GLchar *label) const
976{
977 LabeledObject *object = getLabeledObjectFromPtr(ptr);
978 ASSERT(object != nullptr);
979
980 const std::string &objectLabel = object->getLabel();
981 GetObjectLabelBase(objectLabel, bufSize, length, label);
982}
983
Jamie Madilldc356042013-07-19 16:36:57 -0400984bool Context::isSampler(GLuint samplerName) const
985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500986 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400987}
988
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800989void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000990{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500991 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992
Jamie Madilldedd7b92014-11-05 16:30:36 -0500993 if (handle == 0)
994 {
995 texture = mZeroTextures[target].get();
996 }
997 else
998 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500999 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001000 }
1001
1002 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001003 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001004}
1005
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001006void Context::bindReadFramebuffer(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.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011}
1012
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001013void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001014{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001015 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1016 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001017 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001018}
1019
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001020void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001021{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001022 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001023 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001024}
1025
Shao80957d92017-02-20 21:25:59 +08001026void Context::bindVertexBuffer(GLuint bindingIndex,
1027 GLuint bufferHandle,
1028 GLintptr offset,
1029 GLsizei stride)
1030{
1031 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001032 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001033}
1034
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001035void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001036{
Geoff Lang76b10c92014-09-05 16:28:14 -04001037 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001038 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001039 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001040 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001041}
1042
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001043void Context::bindImageTexture(GLuint unit,
1044 GLuint texture,
1045 GLint level,
1046 GLboolean layered,
1047 GLint layer,
1048 GLenum access,
1049 GLenum format)
1050{
1051 Texture *tex = mState.mTextures->getTexture(texture);
1052 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1053}
1054
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001055void Context::useProgram(GLuint program)
1056{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001057 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001058}
1059
Jiajia Qin5451d532017-11-16 17:16:34 +08001060void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1061{
1062 UNIMPLEMENTED();
1063}
1064
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001065void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001066{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001067 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001068 TransformFeedback *transformFeedback =
1069 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001070 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001071}
1072
Yunchao Hea336b902017-08-02 16:05:21 +08001073void Context::bindProgramPipeline(GLuint pipelineHandle)
1074{
1075 ProgramPipeline *pipeline =
1076 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1077 mGLState.setProgramPipelineBinding(this, pipeline);
1078}
1079
Corentin Wallezad3ae902018-03-09 13:40:42 -05001080void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001083 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001084
Geoff Lang5aad9672014-09-08 11:10:42 -04001085 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001086 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001087
1088 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001089 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090}
1091
Corentin Wallezad3ae902018-03-09 13:40:42 -05001092void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001094 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001095 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001096
Jamie Madillf0e04492017-08-26 15:28:42 -04001097 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098
Geoff Lang5aad9672014-09-08 11:10:42 -04001099 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001100 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101}
1102
Corentin Wallezad3ae902018-03-09 13:40:42 -05001103void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001105 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001106
1107 Query *queryObject = getQuery(id, true, target);
1108 ASSERT(queryObject);
1109
Jamie Madillf0e04492017-08-26 15:28:42 -04001110 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111}
1112
Corentin Wallezad3ae902018-03-09 13:40:42 -05001113void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001114{
1115 switch (pname)
1116 {
1117 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001118 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001119 break;
1120 case GL_QUERY_COUNTER_BITS_EXT:
1121 switch (target)
1122 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001123 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1125 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001126 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127 params[0] = getExtensions().queryCounterBitsTimestamp;
1128 break;
1129 default:
1130 UNREACHABLE();
1131 params[0] = 0;
1132 break;
1133 }
1134 break;
1135 default:
1136 UNREACHABLE();
1137 return;
1138 }
1139}
1140
Corentin Wallezad3ae902018-03-09 13:40:42 -05001141void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001142 GLenum pname,
1143 GLsizei bufSize,
1144 GLsizei *length,
1145 GLint *params)
1146{
1147 getQueryiv(target, pname, params);
1148}
1149
Geoff Lang2186c382016-10-14 10:54:54 -04001150void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001151{
Geoff Lang2186c382016-10-14 10:54:54 -04001152 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001153}
1154
Brandon Jones59770802018-04-02 13:18:42 -07001155void Context::getQueryObjectivRobust(GLuint id,
1156 GLenum pname,
1157 GLsizei bufSize,
1158 GLsizei *length,
1159 GLint *params)
1160{
1161 getQueryObjectiv(id, pname, params);
1162}
1163
Geoff Lang2186c382016-10-14 10:54:54 -04001164void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001165{
Geoff Lang2186c382016-10-14 10:54:54 -04001166 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001167}
1168
Brandon Jones59770802018-04-02 13:18:42 -07001169void Context::getQueryObjectuivRobust(GLuint id,
1170 GLenum pname,
1171 GLsizei bufSize,
1172 GLsizei *length,
1173 GLuint *params)
1174{
1175 getQueryObjectuiv(id, pname, params);
1176}
1177
Geoff Lang2186c382016-10-14 10:54:54 -04001178void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001179{
Geoff Lang2186c382016-10-14 10:54:54 -04001180 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181}
1182
Brandon Jones59770802018-04-02 13:18:42 -07001183void Context::getQueryObjecti64vRobust(GLuint id,
1184 GLenum pname,
1185 GLsizei bufSize,
1186 GLsizei *length,
1187 GLint64 *params)
1188{
1189 getQueryObjecti64v(id, pname, params);
1190}
1191
Geoff Lang2186c382016-10-14 10:54:54 -04001192void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001193{
Geoff Lang2186c382016-10-14 10:54:54 -04001194 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195}
1196
Brandon Jones59770802018-04-02 13:18:42 -07001197void Context::getQueryObjectui64vRobust(GLuint id,
1198 GLenum pname,
1199 GLsizei bufSize,
1200 GLsizei *length,
1201 GLuint64 *params)
1202{
1203 getQueryObjectui64v(id, pname, params);
1204}
1205
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001206Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001208 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209}
1210
Jamie Madill2f348d22017-06-05 10:50:59 -04001211FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212{
Jamie Madill96a483b2017-06-27 16:49:21 -04001213 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Corentin Wallezad3ae902018-03-09 13:40:42 -05001216Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Jamie Madill96a483b2017-06-27 16:49:21 -04001218 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001220 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001222
1223 Query *query = mQueryMap.query(handle);
1224 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001226 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 query = new Query(mImplementation->createQuery(type), handle);
1228 query->addRef();
1229 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001231 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001232}
1233
Geoff Lang70d0f492015-12-10 17:45:46 -05001234Query *Context::getQuery(GLuint handle) const
1235{
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001237}
1238
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001239Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001240{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001241 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1242 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001243}
1244
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001245Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001246{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001247 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001248}
1249
Geoff Lang492a7e42014-11-05 13:27:06 -05001250Compiler *Context::getCompiler() const
1251{
Jamie Madill2f348d22017-06-05 10:50:59 -04001252 if (mCompiler.get() == nullptr)
1253 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001254 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001255 }
1256 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001257}
1258
Jamie Madillc1d770e2017-04-13 17:31:24 -04001259void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001260{
1261 switch (pname)
1262 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001263 case GL_SHADER_COMPILER:
1264 *params = GL_TRUE;
1265 break;
1266 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1267 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1268 break;
1269 default:
1270 mGLState.getBooleanv(pname, params);
1271 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273}
1274
Jamie Madillc1d770e2017-04-13 17:31:24 -04001275void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276{
Shannon Woods53a94a82014-06-24 15:20:36 -04001277 // Queries about context capabilities and maximums are answered by Context.
1278 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279 switch (pname)
1280 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001281 case GL_ALIASED_LINE_WIDTH_RANGE:
1282 params[0] = mCaps.minAliasedLineWidth;
1283 params[1] = mCaps.maxAliasedLineWidth;
1284 break;
1285 case GL_ALIASED_POINT_SIZE_RANGE:
1286 params[0] = mCaps.minAliasedPointSize;
1287 params[1] = mCaps.maxAliasedPointSize;
1288 break;
1289 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1290 ASSERT(mExtensions.textureFilterAnisotropic);
1291 *params = mExtensions.maxTextureAnisotropy;
1292 break;
1293 case GL_MAX_TEXTURE_LOD_BIAS:
1294 *params = mCaps.maxLODBias;
1295 break;
1296
1297 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1298 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1299 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001300 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1301 // GLES1 constants for modelview/projection matrix.
1302 if (getClientVersion() < Version(2, 0))
1303 {
1304 mGLState.getFloatv(pname, params);
1305 }
1306 else
1307 {
1308 ASSERT(mExtensions.pathRendering);
1309 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1310 memcpy(params, m, 16 * sizeof(GLfloat));
1311 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001312 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001313 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001314
Jamie Madill231c7f52017-04-26 13:45:37 -04001315 default:
1316 mGLState.getFloatv(pname, params);
1317 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319}
1320
Jamie Madillc1d770e2017-04-13 17:31:24 -04001321void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322{
Shannon Woods53a94a82014-06-24 15:20:36 -04001323 // Queries about context capabilities and maximums are answered by Context.
1324 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001325
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 switch (pname)
1327 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001328 case GL_MAX_VERTEX_ATTRIBS:
1329 *params = mCaps.maxVertexAttributes;
1330 break;
1331 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1332 *params = mCaps.maxVertexUniformVectors;
1333 break;
1334 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001335 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001336 break;
1337 case GL_MAX_VARYING_VECTORS:
1338 *params = mCaps.maxVaryingVectors;
1339 break;
1340 case GL_MAX_VARYING_COMPONENTS:
1341 *params = mCaps.maxVertexOutputComponents;
1342 break;
1343 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1344 *params = mCaps.maxCombinedTextureImageUnits;
1345 break;
1346 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001347 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001348 break;
1349 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001350 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001351 break;
1352 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1353 *params = mCaps.maxFragmentUniformVectors;
1354 break;
1355 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001356 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_MAX_RENDERBUFFER_SIZE:
1359 *params = mCaps.maxRenderbufferSize;
1360 break;
1361 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1362 *params = mCaps.maxColorAttachments;
1363 break;
1364 case GL_MAX_DRAW_BUFFERS_EXT:
1365 *params = mCaps.maxDrawBuffers;
1366 break;
1367 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1368 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1369 case GL_SUBPIXEL_BITS:
1370 *params = 4;
1371 break;
1372 case GL_MAX_TEXTURE_SIZE:
1373 *params = mCaps.max2DTextureSize;
1374 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001375 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1376 *params = mCaps.maxRectangleTextureSize;
1377 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001378 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1379 *params = mCaps.maxCubeMapTextureSize;
1380 break;
1381 case GL_MAX_3D_TEXTURE_SIZE:
1382 *params = mCaps.max3DTextureSize;
1383 break;
1384 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1385 *params = mCaps.maxArrayTextureLayers;
1386 break;
1387 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1388 *params = mCaps.uniformBufferOffsetAlignment;
1389 break;
1390 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1391 *params = mCaps.maxUniformBufferBindings;
1392 break;
1393 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001394 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 break;
1396 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001397 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001398 break;
1399 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1400 *params = mCaps.maxCombinedTextureImageUnits;
1401 break;
1402 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1403 *params = mCaps.maxVertexOutputComponents;
1404 break;
1405 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1406 *params = mCaps.maxFragmentInputComponents;
1407 break;
1408 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1409 *params = mCaps.minProgramTexelOffset;
1410 break;
1411 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1412 *params = mCaps.maxProgramTexelOffset;
1413 break;
1414 case GL_MAJOR_VERSION:
1415 *params = getClientVersion().major;
1416 break;
1417 case GL_MINOR_VERSION:
1418 *params = getClientVersion().minor;
1419 break;
1420 case GL_MAX_ELEMENTS_INDICES:
1421 *params = mCaps.maxElementsIndices;
1422 break;
1423 case GL_MAX_ELEMENTS_VERTICES:
1424 *params = mCaps.maxElementsVertices;
1425 break;
1426 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1427 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1428 break;
1429 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1430 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1431 break;
1432 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1433 *params = mCaps.maxTransformFeedbackSeparateComponents;
1434 break;
1435 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1436 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1437 break;
1438 case GL_MAX_SAMPLES_ANGLE:
1439 *params = mCaps.maxSamples;
1440 break;
1441 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001443 params[0] = mCaps.maxViewportWidth;
1444 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001445 }
1446 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 case GL_COMPRESSED_TEXTURE_FORMATS:
1448 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1449 params);
1450 break;
1451 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1452 *params = mResetStrategy;
1453 break;
1454 case GL_NUM_SHADER_BINARY_FORMATS:
1455 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1456 break;
1457 case GL_SHADER_BINARY_FORMATS:
1458 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1459 break;
1460 case GL_NUM_PROGRAM_BINARY_FORMATS:
1461 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1462 break;
1463 case GL_PROGRAM_BINARY_FORMATS:
1464 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1465 break;
1466 case GL_NUM_EXTENSIONS:
1467 *params = static_cast<GLint>(mExtensionStrings.size());
1468 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001469
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 // GL_KHR_debug
1471 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1472 *params = mExtensions.maxDebugMessageLength;
1473 break;
1474 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1475 *params = mExtensions.maxDebugLoggedMessages;
1476 break;
1477 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1478 *params = mExtensions.maxDebugGroupStackDepth;
1479 break;
1480 case GL_MAX_LABEL_LENGTH:
1481 *params = mExtensions.maxLabelLength;
1482 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001483
Martin Radeve5285d22017-07-14 16:23:53 +03001484 // GL_ANGLE_multiview
1485 case GL_MAX_VIEWS_ANGLE:
1486 *params = mExtensions.maxViews;
1487 break;
1488
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 // GL_EXT_disjoint_timer_query
1490 case GL_GPU_DISJOINT_EXT:
1491 *params = mImplementation->getGPUDisjoint();
1492 break;
1493 case GL_MAX_FRAMEBUFFER_WIDTH:
1494 *params = mCaps.maxFramebufferWidth;
1495 break;
1496 case GL_MAX_FRAMEBUFFER_HEIGHT:
1497 *params = mCaps.maxFramebufferHeight;
1498 break;
1499 case GL_MAX_FRAMEBUFFER_SAMPLES:
1500 *params = mCaps.maxFramebufferSamples;
1501 break;
1502 case GL_MAX_SAMPLE_MASK_WORDS:
1503 *params = mCaps.maxSampleMaskWords;
1504 break;
1505 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1506 *params = mCaps.maxColorTextureSamples;
1507 break;
1508 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1509 *params = mCaps.maxDepthTextureSamples;
1510 break;
1511 case GL_MAX_INTEGER_SAMPLES:
1512 *params = mCaps.maxIntegerSamples;
1513 break;
1514 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1515 *params = mCaps.maxVertexAttribRelativeOffset;
1516 break;
1517 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1518 *params = mCaps.maxVertexAttribBindings;
1519 break;
1520 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1521 *params = mCaps.maxVertexAttribStride;
1522 break;
1523 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001524 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 break;
1526 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001527 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001528 break;
1529 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001530 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001531 break;
1532 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001533 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001536 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001537 break;
1538 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001539 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001540 break;
1541 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001542 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001545 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001546 break;
1547 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1548 *params = mCaps.minProgramTextureGatherOffset;
1549 break;
1550 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1551 *params = mCaps.maxProgramTextureGatherOffset;
1552 break;
1553 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1554 *params = mCaps.maxComputeWorkGroupInvocations;
1555 break;
1556 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001557 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001560 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001561 break;
1562 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1563 *params = mCaps.maxComputeSharedMemorySize;
1564 break;
1565 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001566 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001569 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001572 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001573 break;
1574 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001575 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001576 break;
1577 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001578 *params =
1579 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001580 break;
1581 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001582 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 break;
1584 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1585 *params = mCaps.maxCombinedShaderOutputResources;
1586 break;
1587 case GL_MAX_UNIFORM_LOCATIONS:
1588 *params = mCaps.maxUniformLocations;
1589 break;
1590 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1591 *params = mCaps.maxAtomicCounterBufferBindings;
1592 break;
1593 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1594 *params = mCaps.maxAtomicCounterBufferSize;
1595 break;
1596 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1597 *params = mCaps.maxCombinedAtomicCounterBuffers;
1598 break;
1599 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1600 *params = mCaps.maxCombinedAtomicCounters;
1601 break;
1602 case GL_MAX_IMAGE_UNITS:
1603 *params = mCaps.maxImageUnits;
1604 break;
1605 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1606 *params = mCaps.maxCombinedImageUniforms;
1607 break;
1608 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1609 *params = mCaps.maxShaderStorageBufferBindings;
1610 break;
1611 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1612 *params = mCaps.maxCombinedShaderStorageBlocks;
1613 break;
1614 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1615 *params = mCaps.shaderStorageBufferOffsetAlignment;
1616 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001617
1618 // GL_EXT_geometry_shader
1619 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1620 *params = mCaps.maxFramebufferLayers;
1621 break;
1622 case GL_LAYER_PROVOKING_VERTEX_EXT:
1623 *params = mCaps.layerProvokingVertex;
1624 break;
1625 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001626 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001627 break;
1628 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001629 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001630 break;
1631 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001632 *params =
1633 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001634 break;
1635 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1636 *params = mCaps.maxGeometryInputComponents;
1637 break;
1638 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1639 *params = mCaps.maxGeometryOutputComponents;
1640 break;
1641 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1642 *params = mCaps.maxGeometryOutputVertices;
1643 break;
1644 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1645 *params = mCaps.maxGeometryTotalOutputComponents;
1646 break;
1647 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1648 *params = mCaps.maxGeometryShaderInvocations;
1649 break;
1650 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001651 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001652 break;
1653 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001655 break;
1656 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
1659 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001661 break;
1662 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001663 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001664 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001665 // GLES1 emulation: Caps queries
1666 case GL_MAX_TEXTURE_UNITS:
1667 *params = mCaps.maxMultitextureUnits;
1668 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001669 case GL_MAX_MODELVIEW_STACK_DEPTH:
1670 *params = mCaps.maxModelviewMatrixStackDepth;
1671 break;
1672 case GL_MAX_PROJECTION_STACK_DEPTH:
1673 *params = mCaps.maxProjectionMatrixStackDepth;
1674 break;
1675 case GL_MAX_TEXTURE_STACK_DEPTH:
1676 *params = mCaps.maxTextureMatrixStackDepth;
1677 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001678 case GL_MAX_LIGHTS:
1679 *params = mCaps.maxLights;
1680 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001681 // GLES1 emulation: Vertex attribute queries
1682 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1683 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1684 case GL_COLOR_ARRAY_BUFFER_BINDING:
1685 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1686 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1687 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1688 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1689 break;
1690 case GL_VERTEX_ARRAY_STRIDE:
1691 case GL_NORMAL_ARRAY_STRIDE:
1692 case GL_COLOR_ARRAY_STRIDE:
1693 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1694 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1695 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1696 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1697 break;
1698 case GL_VERTEX_ARRAY_SIZE:
1699 case GL_COLOR_ARRAY_SIZE:
1700 case GL_TEXTURE_COORD_ARRAY_SIZE:
1701 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1702 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1703 break;
1704 case GL_VERTEX_ARRAY_TYPE:
1705 case GL_COLOR_ARRAY_TYPE:
1706 case GL_NORMAL_ARRAY_TYPE:
1707 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1708 case GL_TEXTURE_COORD_ARRAY_TYPE:
1709 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1710 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1711 break;
1712
Jamie Madill231c7f52017-04-26 13:45:37 -04001713 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001714 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001715 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001716 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001717}
1718
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001719void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001720{
Shannon Woods53a94a82014-06-24 15:20:36 -04001721 // Queries about context capabilities and maximums are answered by Context.
1722 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001723 switch (pname)
1724 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001725 case GL_MAX_ELEMENT_INDEX:
1726 *params = mCaps.maxElementIndex;
1727 break;
1728 case GL_MAX_UNIFORM_BLOCK_SIZE:
1729 *params = mCaps.maxUniformBlockSize;
1730 break;
1731 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001732 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 break;
1734 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001735 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001736 break;
1737 case GL_MAX_SERVER_WAIT_TIMEOUT:
1738 *params = mCaps.maxServerWaitTimeout;
1739 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001740
Jamie Madill231c7f52017-04-26 13:45:37 -04001741 // GL_EXT_disjoint_timer_query
1742 case GL_TIMESTAMP_EXT:
1743 *params = mImplementation->getTimestamp();
1744 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001745
Jamie Madill231c7f52017-04-26 13:45:37 -04001746 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1747 *params = mCaps.maxShaderStorageBlockSize;
1748 break;
1749 default:
1750 UNREACHABLE();
1751 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001752 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001753}
1754
Geoff Lang70d0f492015-12-10 17:45:46 -05001755void Context::getPointerv(GLenum pname, void **params) const
1756{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001757 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001758}
1759
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001760void Context::getPointervRobustANGLERobust(GLenum pname,
1761 GLsizei bufSize,
1762 GLsizei *length,
1763 void **params)
1764{
1765 UNIMPLEMENTED();
1766}
1767
Martin Radev66fb8202016-07-28 11:45:20 +03001768void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001769{
Shannon Woods53a94a82014-06-24 15:20:36 -04001770 // Queries about context capabilities and maximums are answered by Context.
1771 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001772
1773 GLenum nativeType;
1774 unsigned int numParams;
1775 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1776 ASSERT(queryStatus);
1777
1778 if (nativeType == GL_INT)
1779 {
1780 switch (target)
1781 {
1782 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1783 ASSERT(index < 3u);
1784 *data = mCaps.maxComputeWorkGroupCount[index];
1785 break;
1786 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1787 ASSERT(index < 3u);
1788 *data = mCaps.maxComputeWorkGroupSize[index];
1789 break;
1790 default:
1791 mGLState.getIntegeri_v(target, index, data);
1792 }
1793 }
1794 else
1795 {
1796 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1797 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001798}
1799
Brandon Jones59770802018-04-02 13:18:42 -07001800void Context::getIntegeri_vRobust(GLenum target,
1801 GLuint index,
1802 GLsizei bufSize,
1803 GLsizei *length,
1804 GLint *data)
1805{
1806 getIntegeri_v(target, index, data);
1807}
1808
Martin Radev66fb8202016-07-28 11:45:20 +03001809void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001810{
Shannon Woods53a94a82014-06-24 15:20:36 -04001811 // Queries about context capabilities and maximums are answered by Context.
1812 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001813
1814 GLenum nativeType;
1815 unsigned int numParams;
1816 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1817 ASSERT(queryStatus);
1818
1819 if (nativeType == GL_INT_64_ANGLEX)
1820 {
1821 mGLState.getInteger64i_v(target, index, data);
1822 }
1823 else
1824 {
1825 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1826 }
1827}
1828
Brandon Jones59770802018-04-02 13:18:42 -07001829void Context::getInteger64i_vRobust(GLenum target,
1830 GLuint index,
1831 GLsizei bufSize,
1832 GLsizei *length,
1833 GLint64 *data)
1834{
1835 getInteger64i_v(target, index, data);
1836}
1837
Martin Radev66fb8202016-07-28 11:45:20 +03001838void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1839{
1840 // Queries about context capabilities and maximums are answered by Context.
1841 // Queries about current GL state values are answered by State.
1842
1843 GLenum nativeType;
1844 unsigned int numParams;
1845 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1846 ASSERT(queryStatus);
1847
1848 if (nativeType == GL_BOOL)
1849 {
1850 mGLState.getBooleani_v(target, index, data);
1851 }
1852 else
1853 {
1854 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1855 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001856}
1857
Brandon Jones59770802018-04-02 13:18:42 -07001858void Context::getBooleani_vRobust(GLenum target,
1859 GLuint index,
1860 GLsizei bufSize,
1861 GLsizei *length,
1862 GLboolean *data)
1863{
1864 getBooleani_v(target, index, data);
1865}
1866
Corentin Wallez336129f2017-10-17 15:55:40 -04001867void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001868{
1869 Buffer *buffer = mGLState.getTargetBuffer(target);
1870 QueryBufferParameteriv(buffer, pname, params);
1871}
1872
Brandon Jones59770802018-04-02 13:18:42 -07001873void Context::getBufferParameterivRobust(BufferBinding target,
1874 GLenum pname,
1875 GLsizei bufSize,
1876 GLsizei *length,
1877 GLint *params)
1878{
1879 getBufferParameteriv(target, pname, params);
1880}
1881
He Yunchao010e4db2017-03-03 14:22:06 +08001882void Context::getFramebufferAttachmentParameteriv(GLenum target,
1883 GLenum attachment,
1884 GLenum pname,
1885 GLint *params)
1886{
1887 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001888 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001889}
1890
Brandon Jones59770802018-04-02 13:18:42 -07001891void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1892 GLenum attachment,
1893 GLenum pname,
1894 GLsizei bufSize,
1895 GLsizei *length,
1896 GLint *params)
1897{
1898 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1899}
1900
He Yunchao010e4db2017-03-03 14:22:06 +08001901void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1902{
1903 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1904 QueryRenderbufferiv(this, renderbuffer, pname, params);
1905}
1906
Brandon Jones59770802018-04-02 13:18:42 -07001907void Context::getRenderbufferParameterivRobust(GLenum target,
1908 GLenum pname,
1909 GLsizei bufSize,
1910 GLsizei *length,
1911 GLint *params)
1912{
1913 getRenderbufferParameteriv(target, pname, params);
1914}
1915
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001916void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001917{
1918 Texture *texture = getTargetTexture(target);
1919 QueryTexParameterfv(texture, pname, params);
1920}
1921
Brandon Jones59770802018-04-02 13:18:42 -07001922void Context::getTexParameterfvRobust(TextureType target,
1923 GLenum pname,
1924 GLsizei bufSize,
1925 GLsizei *length,
1926 GLfloat *params)
1927{
1928 getTexParameterfv(target, pname, params);
1929}
1930
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001931void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001932{
1933 Texture *texture = getTargetTexture(target);
1934 QueryTexParameteriv(texture, pname, params);
1935}
Jiajia Qin5451d532017-11-16 17:16:34 +08001936
Brandon Jones59770802018-04-02 13:18:42 -07001937void Context::getTexParameterivRobust(TextureType target,
1938 GLenum pname,
1939 GLsizei bufSize,
1940 GLsizei *length,
1941 GLint *params)
1942{
1943 getTexParameteriv(target, pname, params);
1944}
1945
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001946void Context::getTexParameterIivRobust(TextureType target,
1947 GLenum pname,
1948 GLsizei bufSize,
1949 GLsizei *length,
1950 GLint *params)
1951{
1952 UNIMPLEMENTED();
1953}
1954
1955void Context::getTexParameterIuivRobust(TextureType target,
1956 GLenum pname,
1957 GLsizei bufSize,
1958 GLsizei *length,
1959 GLuint *params)
1960{
1961 UNIMPLEMENTED();
1962}
1963
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001964void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001965{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001966 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001967 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001968}
1969
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001970void Context::getTexLevelParameterivRobust(TextureTarget target,
1971 GLint level,
1972 GLenum pname,
1973 GLsizei bufSize,
1974 GLsizei *length,
1975 GLint *params)
1976{
1977 UNIMPLEMENTED();
1978}
1979
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001980void Context::getTexLevelParameterfv(TextureTarget target,
1981 GLint level,
1982 GLenum pname,
1983 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001984{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001985 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001986 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001987}
1988
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001989void Context::getTexLevelParameterfvRobust(TextureTarget target,
1990 GLint level,
1991 GLenum pname,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLfloat *params)
1995{
1996 UNIMPLEMENTED();
1997}
1998
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001999void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002000{
2001 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002002 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002003 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002004}
2005
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002006void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002007{
2008 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002009 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002010 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002011}
2012
Brandon Jones59770802018-04-02 13:18:42 -07002013void Context::texParameterfvRobust(TextureType target,
2014 GLenum pname,
2015 GLsizei bufSize,
2016 const GLfloat *params)
2017{
2018 texParameterfv(target, pname, params);
2019}
2020
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002021void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002022{
2023 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002024 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002025 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002026}
2027
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002028void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002029{
2030 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002031 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002032 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002033}
2034
Brandon Jones59770802018-04-02 13:18:42 -07002035void Context::texParameterivRobust(TextureType target,
2036 GLenum pname,
2037 GLsizei bufSize,
2038 const GLint *params)
2039{
2040 texParameteriv(target, pname, params);
2041}
2042
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002043void Context::texParameterIivRobust(TextureType target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 const GLint *params)
2047{
2048 UNIMPLEMENTED();
2049}
2050
2051void Context::texParameterIuivRobust(TextureType target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 const GLuint *params)
2055{
2056 UNIMPLEMENTED();
2057}
2058
Jamie Madill493f9572018-05-24 19:52:15 -04002059void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002060{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002061 // No-op if zero count
2062 if (count == 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(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002069 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002070}
2071
Jamie Madill493f9572018-05-24 19:52:15 -04002072void Context::drawArraysInstanced(PrimitiveMode mode,
2073 GLint first,
2074 GLsizei count,
2075 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002076{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002077 // No-op if zero count
2078 if (count == 0 || instanceCount == 0)
2079 {
2080 return;
2081 }
2082
Jamie Madill05b35b22017-10-03 09:01:44 -04002083 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002084 ANGLE_CONTEXT_TRY(
2085 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002086 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2087 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002088}
2089
Jamie Madill493f9572018-05-24 19:52:15 -04002090void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002091{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002092 // No-op if zero count
2093 if (count == 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(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002100}
2101
Jamie Madill493f9572018-05-24 19:52:15 -04002102void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002103 GLsizei count,
2104 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002105 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002106 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002107{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002108 // No-op if zero count
2109 if (count == 0 || instances == 0)
2110 {
2111 return;
2112 }
2113
Jamie Madill05b35b22017-10-03 09:01:44 -04002114 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002115 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002116 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002117}
2118
Jamie Madill493f9572018-05-24 19:52:15 -04002119void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002120 GLuint start,
2121 GLuint end,
2122 GLsizei count,
2123 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002124 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002125{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002126 // No-op if zero count
2127 if (count == 0)
2128 {
2129 return;
2130 }
2131
Jamie Madill05b35b22017-10-03 09:01:44 -04002132 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002133 ANGLE_CONTEXT_TRY(
2134 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002135}
2136
Jamie Madill493f9572018-05-24 19:52:15 -04002137void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002138{
Jamie Madill05b35b22017-10-03 09:01:44 -04002139 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002140 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002141}
2142
Jamie Madill493f9572018-05-24 19:52:15 -04002143void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002144{
Jamie Madill05b35b22017-10-03 09:01:44 -04002145 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002146 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002147}
2148
Jamie Madill675fe712016-12-19 13:07:54 -05002149void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002150{
Jamie Madillafa02a22017-11-23 12:57:38 -05002151 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002152}
2153
Jamie Madill675fe712016-12-19 13:07:54 -05002154void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002155{
Jamie Madillafa02a22017-11-23 12:57:38 -05002156 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002157}
2158
Austin Kinross6ee1e782015-05-29 17:05:37 -07002159void Context::insertEventMarker(GLsizei length, const char *marker)
2160{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002161 ASSERT(mImplementation);
2162 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002163}
2164
2165void Context::pushGroupMarker(GLsizei length, const char *marker)
2166{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002167 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002168
2169 if (marker == nullptr)
2170 {
2171 // From the EXT_debug_marker spec,
2172 // "If <marker> is null then an empty string is pushed on the stack."
2173 mImplementation->pushGroupMarker(length, "");
2174 }
2175 else
2176 {
2177 mImplementation->pushGroupMarker(length, marker);
2178 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002179}
2180
2181void Context::popGroupMarker()
2182{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002183 ASSERT(mImplementation);
2184 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002185}
2186
Geoff Langd8605522016-04-13 10:19:12 -04002187void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2188{
2189 Program *programObject = getProgram(program);
2190 ASSERT(programObject);
2191
2192 programObject->bindUniformLocation(location, name);
2193}
2194
Brandon Jones59770802018-04-02 13:18:42 -07002195void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002197 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002198}
2199
Brandon Jones59770802018-04-02 13:18:42 -07002200void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002201{
2202 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2203}
2204
Brandon Jones59770802018-04-02 13:18:42 -07002205void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002206{
2207 GLfloat I[16];
2208 angle::Matrix<GLfloat>::setToIdentity(I);
2209
2210 mGLState.loadPathRenderingMatrix(matrixMode, I);
2211}
2212
2213void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2214{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002215 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002216 if (!pathObj)
2217 return;
2218
2219 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002220 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002221
2222 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2223}
2224
2225void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2226{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002227 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228 if (!pathObj)
2229 return;
2230
2231 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002232 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233
2234 mImplementation->stencilStrokePath(pathObj, reference, mask);
2235}
2236
2237void Context::coverFillPath(GLuint path, GLenum coverMode)
2238{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002239 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240 if (!pathObj)
2241 return;
2242
2243 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002244 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002245
2246 mImplementation->coverFillPath(pathObj, coverMode);
2247}
2248
2249void Context::coverStrokePath(GLuint path, GLenum coverMode)
2250{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002251 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252 if (!pathObj)
2253 return;
2254
2255 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002256 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002257
2258 mImplementation->coverStrokePath(pathObj, coverMode);
2259}
2260
2261void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2262{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002263 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002264 if (!pathObj)
2265 return;
2266
2267 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002268 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002269
2270 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2271}
2272
2273void Context::stencilThenCoverStrokePath(GLuint path,
2274 GLint reference,
2275 GLuint mask,
2276 GLenum coverMode)
2277{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002278 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002279 if (!pathObj)
2280 return;
2281
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änene45e53b2016-05-25 10:36:04 +03002284
2285 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2286}
2287
Sami Väisänend59ca052016-06-21 16:10:00 +03002288void Context::coverFillPathInstanced(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->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2302}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002303
Sami Väisänend59ca052016-06-21 16:10:00 +03002304void Context::coverStrokePathInstanced(GLsizei numPaths,
2305 GLenum pathNameType,
2306 const void *paths,
2307 GLuint pathBase,
2308 GLenum coverMode,
2309 GLenum transformType,
2310 const GLfloat *transformValues)
2311{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002312 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002313
2314 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002315 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002316
2317 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2318 transformValues);
2319}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002320
Sami Väisänend59ca052016-06-21 16:10:00 +03002321void Context::stencilFillPathInstanced(GLsizei numPaths,
2322 GLenum pathNameType,
2323 const void *paths,
2324 GLuint pathBase,
2325 GLenum fillMode,
2326 GLuint mask,
2327 GLenum transformType,
2328 const GLfloat *transformValues)
2329{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002330 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002331
2332 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002333 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002334
2335 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2336 transformValues);
2337}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002338
Sami Väisänend59ca052016-06-21 16:10:00 +03002339void Context::stencilStrokePathInstanced(GLsizei numPaths,
2340 GLenum pathNameType,
2341 const void *paths,
2342 GLuint pathBase,
2343 GLint reference,
2344 GLuint mask,
2345 GLenum transformType,
2346 const GLfloat *transformValues)
2347{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002348 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002349
2350 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002351 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002352
2353 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2354 transformValues);
2355}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002356
Sami Väisänend59ca052016-06-21 16:10:00 +03002357void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2358 GLenum pathNameType,
2359 const void *paths,
2360 GLuint pathBase,
2361 GLenum fillMode,
2362 GLuint mask,
2363 GLenum coverMode,
2364 GLenum transformType,
2365 const GLfloat *transformValues)
2366{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002367 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002368
2369 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002370 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2373 transformType, transformValues);
2374}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002375
Sami Väisänend59ca052016-06-21 16:10:00 +03002376void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2377 GLenum pathNameType,
2378 const void *paths,
2379 GLuint pathBase,
2380 GLint reference,
2381 GLuint mask,
2382 GLenum coverMode,
2383 GLenum transformType,
2384 const GLfloat *transformValues)
2385{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002386 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002389 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002390
2391 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2392 transformType, transformValues);
2393}
2394
Sami Väisänen46eaa942016-06-29 10:26:37 +03002395void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2396{
2397 auto *programObject = getProgram(program);
2398
2399 programObject->bindFragmentInputLocation(location, name);
2400}
2401
2402void Context::programPathFragmentInputGen(GLuint program,
2403 GLint location,
2404 GLenum genMode,
2405 GLint components,
2406 const GLfloat *coeffs)
2407{
2408 auto *programObject = getProgram(program);
2409
Jamie Madillbd044ed2017-06-05 12:59:21 -04002410 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002411}
2412
jchen1015015f72017-03-16 13:54:21 +08002413GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2414{
jchen10fd7c3b52017-03-21 15:36:03 +08002415 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002416 return QueryProgramResourceIndex(programObject, programInterface, name);
2417}
2418
jchen10fd7c3b52017-03-21 15:36:03 +08002419void Context::getProgramResourceName(GLuint program,
2420 GLenum programInterface,
2421 GLuint index,
2422 GLsizei bufSize,
2423 GLsizei *length,
2424 GLchar *name)
2425{
2426 const auto *programObject = getProgram(program);
2427 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2428}
2429
jchen10191381f2017-04-11 13:59:04 +08002430GLint Context::getProgramResourceLocation(GLuint program,
2431 GLenum programInterface,
2432 const GLchar *name)
2433{
2434 const auto *programObject = getProgram(program);
2435 return QueryProgramResourceLocation(programObject, programInterface, name);
2436}
2437
jchen10880683b2017-04-12 16:21:55 +08002438void Context::getProgramResourceiv(GLuint program,
2439 GLenum programInterface,
2440 GLuint index,
2441 GLsizei propCount,
2442 const GLenum *props,
2443 GLsizei bufSize,
2444 GLsizei *length,
2445 GLint *params)
2446{
2447 const auto *programObject = getProgram(program);
2448 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2449 length, params);
2450}
2451
jchen10d9cd7b72017-08-30 15:04:25 +08002452void Context::getProgramInterfaceiv(GLuint program,
2453 GLenum programInterface,
2454 GLenum pname,
2455 GLint *params)
2456{
2457 const auto *programObject = getProgram(program);
2458 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2459}
2460
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002461void Context::getProgramInterfaceivRobust(GLuint program,
2462 GLenum programInterface,
2463 GLenum pname,
2464 GLsizei bufSize,
2465 GLsizei *length,
2466 GLint *params)
2467{
2468 UNIMPLEMENTED();
2469}
2470
Jamie Madill427064d2018-04-13 16:20:34 -04002471void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002472{
Geoff Lang7b19a492018-04-20 09:31:52 -04002473 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002474 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002475 GLenum code = error.getCode();
2476 mErrors.insert(code);
2477 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2478 {
2479 markContextLost();
2480 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002481
Geoff Langee6884e2017-11-09 16:51:11 -05002482 ASSERT(!error.getMessage().empty());
2483 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2484 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002485 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486}
2487
2488// Get one of the recorded errors and clear its flag, if any.
2489// [OpenGL ES 2.0.24] section 2.5 page 13.
2490GLenum Context::getError()
2491{
Geoff Langda5777c2014-07-11 09:52:58 -04002492 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002493 {
Geoff Langda5777c2014-07-11 09:52:58 -04002494 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002495 }
Geoff Langda5777c2014-07-11 09:52:58 -04002496 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002497 {
Geoff Langda5777c2014-07-11 09:52:58 -04002498 GLenum error = *mErrors.begin();
2499 mErrors.erase(mErrors.begin());
2500 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502}
2503
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002504// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002505void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002506{
2507 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002508 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002509 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002510 mContextLostForced = true;
2511 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002512 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513}
2514
Jamie Madill427064d2018-04-13 16:20:34 -04002515bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002516{
2517 return mContextLost;
2518}
2519
Jamie Madillfa920eb2018-01-04 11:45:50 -05002520GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002522 // Even if the application doesn't want to know about resets, we want to know
2523 // as it will allow us to skip all the calls.
2524 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002526 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002527 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002528 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002529 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530
2531 // EXT_robustness, section 2.6: If the reset notification behavior is
2532 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2533 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2534 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002535 }
2536
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002537 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2538 // status should be returned at least once, and GL_NO_ERROR should be returned
2539 // once the device has finished resetting.
2540 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002541 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 ASSERT(mResetStatus == GL_NO_ERROR);
2543 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002544
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002546 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002547 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548 }
2549 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002550 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002551 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002552 // If markContextLost was used to mark the context lost then
2553 // assume that is not recoverable, and continue to report the
2554 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 mResetStatus = mImplementation->getResetStatus();
2556 }
Jamie Madill893ab082014-05-16 16:56:10 -04002557
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002558 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002559}
2560
2561bool Context::isResetNotificationEnabled()
2562{
2563 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2564}
2565
Corentin Walleze3b10e82015-05-20 11:06:25 -04002566const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002567{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002568 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002569}
2570
2571EGLenum Context::getClientType() const
2572{
2573 return mClientType;
2574}
2575
2576EGLenum Context::getRenderBuffer() const
2577{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002578 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2579 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002580 {
2581 return EGL_NONE;
2582 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002583
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002584 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002585 ASSERT(backAttachment != nullptr);
2586 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002587}
2588
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002589VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002590{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002591 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002592 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2593 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002594 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002595 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2596 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002597
Jamie Madill96a483b2017-06-27 16:49:21 -04002598 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002599 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002600
2601 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002602}
2603
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002604TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002605{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002606 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002607 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2608 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002609 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002610 transformFeedback =
2611 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002613 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002614 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002615
2616 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002617}
2618
2619bool Context::isVertexArrayGenerated(GLuint vertexArray)
2620{
Jamie Madill96a483b2017-06-27 16:49:21 -04002621 ASSERT(mVertexArrayMap.contains(0));
2622 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002623}
2624
2625bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2626{
Jamie Madill96a483b2017-06-27 16:49:21 -04002627 ASSERT(mTransformFeedbackMap.contains(0));
2628 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002629}
2630
Shannon Woods53a94a82014-06-24 15:20:36 -04002631void Context::detachTexture(GLuint texture)
2632{
2633 // Simple pass-through to State's detachTexture method, as textures do not require
2634 // allocation map management either here or in the resource manager at detach time.
2635 // Zero textures are held by the Context, and we don't attempt to request them from
2636 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002637 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002638}
2639
James Darpinian4d9d4832018-03-13 12:43:28 -07002640void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641{
Yuly Novikov5807a532015-12-03 13:01:22 -05002642 // Simple pass-through to State's detachBuffer method, since
2643 // only buffer attachments to container objects that are bound to the current context
2644 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002645
Yuly Novikov5807a532015-12-03 13:01:22 -05002646 // [OpenGL ES 3.2] section 5.1.2 page 45:
2647 // Attachments to unbound container objects, such as
2648 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2649 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002650 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002651}
2652
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002653void Context::detachFramebuffer(GLuint framebuffer)
2654{
Shannon Woods53a94a82014-06-24 15:20:36 -04002655 // Framebuffer detachment is handled by Context, because 0 is a valid
2656 // Framebuffer object, and a pointer to it must be passed from Context
2657 // to State at binding time.
2658
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2661 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2662 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002664 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002665 {
2666 bindReadFramebuffer(0);
2667 }
2668
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002669 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670 {
2671 bindDrawFramebuffer(0);
2672 }
2673}
2674
2675void Context::detachRenderbuffer(GLuint renderbuffer)
2676{
Jamie Madilla02315b2017-02-23 14:14:47 -05002677 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678}
2679
Jamie Madill57a89722013-07-02 11:57:03 -04002680void Context::detachVertexArray(GLuint vertexArray)
2681{
Jamie Madill77a72f62015-04-14 11:18:32 -04002682 // Vertex array detachment is handled by Context, because 0 is a valid
2683 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002684 // binding time.
2685
Jamie Madill57a89722013-07-02 11:57:03 -04002686 // [OpenGL ES 3.0.2] section 2.10 page 43:
2687 // If a vertex array object that is currently bound is deleted, the binding
2688 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002689 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002690 {
2691 bindVertexArray(0);
2692 }
2693}
2694
Geoff Langc8058452014-02-03 12:04:11 -05002695void Context::detachTransformFeedback(GLuint transformFeedback)
2696{
Corentin Walleza2257da2016-04-19 16:43:12 -04002697 // Transform feedback detachment is handled by Context, because 0 is a valid
2698 // transform feedback, and a pointer to it must be passed from Context to State at
2699 // binding time.
2700
2701 // The OpenGL specification doesn't mention what should happen when the currently bound
2702 // transform feedback object is deleted. Since it is a container object, we treat it like
2703 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002704 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002705 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002706 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002707 }
Geoff Langc8058452014-02-03 12:04:11 -05002708}
2709
Jamie Madilldc356042013-07-19 16:36:57 -04002710void Context::detachSampler(GLuint sampler)
2711{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002712 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002713}
2714
Yunchao Hea336b902017-08-02 16:05:21 +08002715void Context::detachProgramPipeline(GLuint pipeline)
2716{
2717 mGLState.detachProgramPipeline(this, pipeline);
2718}
2719
Jamie Madill3ef140a2017-08-26 23:11:21 -04002720void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002721{
Shaodde78e82017-05-22 14:13:27 +08002722 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002723}
2724
Jamie Madille29d1672013-07-19 16:36:57 -04002725void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2726{
Geoff Langc1984ed2016-10-07 12:41:00 -04002727 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002728 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002729 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002730 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002731}
Jamie Madille29d1672013-07-19 16:36:57 -04002732
Geoff Langc1984ed2016-10-07 12:41:00 -04002733void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2734{
2735 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002736 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002737 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002738 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002739}
2740
Brandon Jones59770802018-04-02 13:18:42 -07002741void Context::samplerParameterivRobust(GLuint sampler,
2742 GLenum pname,
2743 GLsizei bufSize,
2744 const GLint *param)
2745{
2746 samplerParameteriv(sampler, pname, param);
2747}
2748
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002749void Context::samplerParameterIivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 const GLint *param)
2753{
2754 UNIMPLEMENTED();
2755}
2756
2757void Context::samplerParameterIuivRobust(GLuint sampler,
2758 GLenum pname,
2759 GLsizei bufSize,
2760 const GLuint *param)
2761{
2762 UNIMPLEMENTED();
2763}
2764
Jamie Madille29d1672013-07-19 16:36:57 -04002765void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2766{
Geoff Langc1984ed2016-10-07 12:41:00 -04002767 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002768 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002769 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002770 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002771}
2772
Geoff Langc1984ed2016-10-07 12:41:00 -04002773void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002779}
2780
Brandon Jones59770802018-04-02 13:18:42 -07002781void Context::samplerParameterfvRobust(GLuint sampler,
2782 GLenum pname,
2783 GLsizei bufSize,
2784 const GLfloat *param)
2785{
2786 samplerParameterfv(sampler, pname, param);
2787}
2788
Geoff Langc1984ed2016-10-07 12:41:00 -04002789void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002790{
Geoff Langc1984ed2016-10-07 12:41:00 -04002791 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002792 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002793 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002794 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002795}
Jamie Madill9675b802013-07-19 16:36:59 -04002796
Brandon Jones59770802018-04-02 13:18:42 -07002797void Context::getSamplerParameterivRobust(GLuint sampler,
2798 GLenum pname,
2799 GLsizei bufSize,
2800 GLsizei *length,
2801 GLint *params)
2802{
2803 getSamplerParameteriv(sampler, pname, params);
2804}
2805
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002806void Context::getSamplerParameterIivRobust(GLuint sampler,
2807 GLenum pname,
2808 GLsizei bufSize,
2809 GLsizei *length,
2810 GLint *params)
2811{
2812 UNIMPLEMENTED();
2813}
2814
2815void Context::getSamplerParameterIuivRobust(GLuint sampler,
2816 GLenum pname,
2817 GLsizei bufSize,
2818 GLsizei *length,
2819 GLuint *params)
2820{
2821 UNIMPLEMENTED();
2822}
2823
Geoff Langc1984ed2016-10-07 12:41:00 -04002824void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2825{
2826 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002827 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002828 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002829 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002830}
2831
Brandon Jones59770802018-04-02 13:18:42 -07002832void Context::getSamplerParameterfvRobust(GLuint sampler,
2833 GLenum pname,
2834 GLsizei bufSize,
2835 GLsizei *length,
2836 GLfloat *params)
2837{
2838 getSamplerParameterfv(sampler, pname, params);
2839}
2840
Olli Etuahof0fee072016-03-30 15:11:58 +03002841void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2842{
2843 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002844 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002845}
2846
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002847void Context::initRendererString()
2848{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002849 std::ostringstream rendererString;
2850 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002851 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002852 rendererString << ")";
2853
Geoff Langcec35902014-04-16 10:52:36 -04002854 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855}
2856
Geoff Langc339c4e2016-11-29 10:37:36 -05002857void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002858{
Geoff Langc339c4e2016-11-29 10:37:36 -05002859 const Version &clientVersion = getClientVersion();
2860
2861 std::ostringstream versionString;
2862 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2863 << ANGLE_VERSION_STRING << ")";
2864 mVersionString = MakeStaticString(versionString.str());
2865
2866 std::ostringstream shadingLanguageVersionString;
2867 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2868 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2869 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2870 << ")";
2871 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002872}
2873
Geoff Langcec35902014-04-16 10:52:36 -04002874void Context::initExtensionStrings()
2875{
Geoff Langc339c4e2016-11-29 10:37:36 -05002876 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2877 std::ostringstream combinedStringStream;
2878 std::copy(strings.begin(), strings.end(),
2879 std::ostream_iterator<const char *>(combinedStringStream, " "));
2880 return MakeStaticString(combinedStringStream.str());
2881 };
2882
2883 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002884 for (const auto &extensionString : mExtensions.getStrings())
2885 {
2886 mExtensionStrings.push_back(MakeStaticString(extensionString));
2887 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002888 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002889
Geoff Langc339c4e2016-11-29 10:37:36 -05002890 mRequestableExtensionStrings.clear();
2891 for (const auto &extensionInfo : GetExtensionInfoMap())
2892 {
2893 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002894 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002895 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002896 {
2897 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2898 }
2899 }
2900 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002901}
2902
Geoff Langc339c4e2016-11-29 10:37:36 -05002903const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002904{
Geoff Langc339c4e2016-11-29 10:37:36 -05002905 switch (name)
2906 {
2907 case GL_VENDOR:
2908 return reinterpret_cast<const GLubyte *>("Google Inc.");
2909
2910 case GL_RENDERER:
2911 return reinterpret_cast<const GLubyte *>(mRendererString);
2912
2913 case GL_VERSION:
2914 return reinterpret_cast<const GLubyte *>(mVersionString);
2915
2916 case GL_SHADING_LANGUAGE_VERSION:
2917 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2918
2919 case GL_EXTENSIONS:
2920 return reinterpret_cast<const GLubyte *>(mExtensionString);
2921
2922 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2923 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2924
2925 default:
2926 UNREACHABLE();
2927 return nullptr;
2928 }
Geoff Langcec35902014-04-16 10:52:36 -04002929}
2930
Geoff Langc339c4e2016-11-29 10:37:36 -05002931const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002932{
Geoff Langc339c4e2016-11-29 10:37:36 -05002933 switch (name)
2934 {
2935 case GL_EXTENSIONS:
2936 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2937
2938 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2939 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2940
2941 default:
2942 UNREACHABLE();
2943 return nullptr;
2944 }
Geoff Langcec35902014-04-16 10:52:36 -04002945}
2946
2947size_t Context::getExtensionStringCount() const
2948{
2949 return mExtensionStrings.size();
2950}
2951
Geoff Lang111a99e2017-10-17 10:58:41 -04002952bool Context::isExtensionRequestable(const char *name)
2953{
2954 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2955 auto extension = extensionInfos.find(name);
2956
Geoff Lang111a99e2017-10-17 10:58:41 -04002957 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002958 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002959}
2960
Geoff Langc339c4e2016-11-29 10:37:36 -05002961void Context::requestExtension(const char *name)
2962{
2963 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2964 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2965 const auto &extension = extensionInfos.at(name);
2966 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002967 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002968
2969 if (mExtensions.*(extension.ExtensionsMember))
2970 {
2971 // Extension already enabled
2972 return;
2973 }
2974
2975 mExtensions.*(extension.ExtensionsMember) = true;
2976 updateCaps();
2977 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002978
Jamie Madill2f348d22017-06-05 10:50:59 -04002979 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2980 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002981
Jamie Madill81c2e252017-09-09 23:32:46 -04002982 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2983 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002984 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002985 for (auto &zeroTexture : mZeroTextures)
2986 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002987 if (zeroTexture.get() != nullptr)
2988 {
2989 zeroTexture->signalDirty(this, InitState::Initialized);
2990 }
Geoff Lang9aded172017-04-05 11:07:56 -04002991 }
2992
2993 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002994}
2995
2996size_t Context::getRequestableExtensionStringCount() const
2997{
2998 return mRequestableExtensionStrings.size();
2999}
3000
Jamie Madill493f9572018-05-24 19:52:15 -04003001void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003002{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003003 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003004 ASSERT(transformFeedback != nullptr);
3005 ASSERT(!transformFeedback->isPaused());
3006
Jamie Madill6c1f6712017-02-14 19:08:04 -05003007 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003008}
3009
3010bool Context::hasActiveTransformFeedback(GLuint program) const
3011{
3012 for (auto pair : mTransformFeedbackMap)
3013 {
3014 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3015 {
3016 return true;
3017 }
3018 }
3019 return false;
3020}
3021
Geoff Langb0f917f2017-12-05 13:41:54 -05003022Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003023 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003024 bool robustResourceInit) const
3025{
3026 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3027
3028 if (getClientVersion() < ES_2_0)
3029 {
3030 // Default extensions for GLES1
3031 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003032 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003033 }
3034
3035 if (getClientVersion() < ES_3_0)
3036 {
3037 // Disable ES3+ extensions
3038 supportedExtensions.colorBufferFloat = false;
3039 supportedExtensions.eglImageExternalEssl3 = false;
3040 supportedExtensions.textureNorm16 = false;
3041 supportedExtensions.multiview = false;
3042 supportedExtensions.maxViews = 1u;
3043 }
3044
3045 if (getClientVersion() < ES_3_1)
3046 {
3047 // Disable ES3.1+ extensions
3048 supportedExtensions.geometryShader = false;
3049 }
3050
3051 if (getClientVersion() > ES_2_0)
3052 {
3053 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3054 // supportedExtensions.sRGB = false;
3055 }
3056
3057 // Some extensions are always available because they are implemented in the GL layer.
3058 supportedExtensions.bindUniformLocation = true;
3059 supportedExtensions.vertexArrayObject = true;
3060 supportedExtensions.bindGeneratesResource = true;
3061 supportedExtensions.clientArrays = true;
3062 supportedExtensions.requestExtension = true;
3063
3064 // Enable the no error extension if the context was created with the flag.
3065 supportedExtensions.noError = mSkipValidation;
3066
3067 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3068 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3069
3070 // Explicitly enable GL_KHR_debug
3071 supportedExtensions.debug = true;
3072 supportedExtensions.maxDebugMessageLength = 1024;
3073 supportedExtensions.maxDebugLoggedMessages = 1024;
3074 supportedExtensions.maxDebugGroupStackDepth = 1024;
3075 supportedExtensions.maxLabelLength = 1024;
3076
3077 // Explicitly enable GL_ANGLE_robust_client_memory
3078 supportedExtensions.robustClientMemory = true;
3079
3080 // Determine robust resource init availability from EGL.
3081 supportedExtensions.robustResourceInitialization = robustResourceInit;
3082
3083 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3084 // supports it.
3085 supportedExtensions.robustBufferAccessBehavior =
3086 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3087
3088 // Enable the cache control query unconditionally.
3089 supportedExtensions.programCacheControl = true;
3090
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003091 // Enable EGL_ANGLE_explicit_context subextensions
3092 if (clientExtensions.explicitContext)
3093 {
3094 // GL_ANGLE_explicit_context_gles1
3095 supportedExtensions.explicitContextGles1 = true;
3096 // GL_ANGLE_explicit_context
3097 supportedExtensions.explicitContext = true;
3098 }
3099
Geoff Langb0f917f2017-12-05 13:41:54 -05003100 return supportedExtensions;
3101}
3102
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003103void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3104 const egl::ClientExtensions &clientExtensions,
3105 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003106{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003107 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003108
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003109 mSupportedExtensions =
3110 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Jamie Madill493f9572018-05-24 19:52:15 -04003111 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003112
3113 mLimitations = mImplementation->getNativeLimitations();
3114
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003115 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3116 if (getClientVersion() < Version(2, 0))
3117 {
3118 mCaps.maxMultitextureUnits = 4;
3119 mCaps.maxClipPlanes = 6;
3120 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003121 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3122 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3123 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003124 }
3125
Geoff Lang301d1612014-07-09 10:34:37 -04003126 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003127 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003128
Jamie Madill0f80ed82017-09-19 00:24:56 -04003129 if (getClientVersion() < ES_3_1)
3130 {
3131 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3132 }
3133 else
3134 {
3135 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3136 }
Geoff Lang301d1612014-07-09 10:34:37 -04003137
Jiawei Shao54aafe52018-04-27 14:54:57 +08003138 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3139 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003140 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3141 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3142
3143 // Limit textures as well, so we can use fast bitsets with texture bindings.
3144 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003145 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3146 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3147 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3148 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003149
Jiawei Shaodb342272017-09-27 10:21:45 +08003150 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3151
Geoff Langc287ea62016-09-16 14:46:51 -04003152 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003153 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003154 for (const auto &extensionInfo : GetExtensionInfoMap())
3155 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003156 // If the user has requested that extensions start disabled and they are requestable,
3157 // disable them.
3158 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003159 {
3160 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3161 }
3162 }
3163
3164 // Generate texture caps
3165 updateCaps();
3166}
3167
3168void Context::updateCaps()
3169{
Geoff Lang900013c2014-07-07 11:32:19 -04003170 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003171 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003172
Jamie Madill7b62cf92017-11-02 15:20:49 -04003173 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003174 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003175 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003176 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003177
Geoff Lang0d8b7242015-09-09 14:56:53 -04003178 // Update the format caps based on the client version and extensions.
3179 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3180 // ES3.
3181 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003182 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003183 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003184 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003185 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003186 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003187
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003188 // OpenGL ES does not support multisampling with non-rendererable formats
3189 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003190 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003191 (getClientVersion() < ES_3_1 &&
3192 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003193 {
Geoff Langd87878e2014-09-19 15:42:59 -04003194 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003195 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003196 else
3197 {
3198 // We may have limited the max samples for some required renderbuffer formats due to
3199 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3200 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3201
3202 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3203 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3204 // exception of signed and unsigned integer formats."
3205 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3206 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3207 {
3208 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3209 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3210 }
3211
3212 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3213 if (getClientVersion() >= ES_3_1)
3214 {
3215 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3216 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3217 // the exception that the signed and unsigned integer formats are required only to
3218 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3219 // multisamples, which must be at least one."
3220 if (formatInfo.componentType == GL_INT ||
3221 formatInfo.componentType == GL_UNSIGNED_INT)
3222 {
3223 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3224 }
3225
3226 // GLES 3.1 section 19.3.1.
3227 if (formatCaps.texturable)
3228 {
3229 if (formatInfo.depthBits > 0)
3230 {
3231 mCaps.maxDepthTextureSamples =
3232 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3233 }
3234 else if (formatInfo.redBits > 0)
3235 {
3236 mCaps.maxColorTextureSamples =
3237 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3238 }
3239 }
3240 }
3241 }
Geoff Langd87878e2014-09-19 15:42:59 -04003242
3243 if (formatCaps.texturable && formatInfo.compressed)
3244 {
Geoff Langca271392017-04-05 12:30:00 -04003245 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003246 }
3247
Geoff Langca271392017-04-05 12:30:00 -04003248 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003249 }
Jamie Madill32447362017-06-28 14:53:52 -04003250
3251 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003252 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003253 {
3254 mMemoryProgramCache = nullptr;
3255 }
Corentin Walleze4477002017-12-01 14:39:58 -05003256
3257 // Compute which buffer types are allowed
3258 mValidBufferBindings.reset();
3259 mValidBufferBindings.set(BufferBinding::ElementArray);
3260 mValidBufferBindings.set(BufferBinding::Array);
3261
3262 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3263 {
3264 mValidBufferBindings.set(BufferBinding::PixelPack);
3265 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3266 }
3267
3268 if (getClientVersion() >= ES_3_0)
3269 {
3270 mValidBufferBindings.set(BufferBinding::CopyRead);
3271 mValidBufferBindings.set(BufferBinding::CopyWrite);
3272 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3273 mValidBufferBindings.set(BufferBinding::Uniform);
3274 }
3275
3276 if (getClientVersion() >= ES_3_1)
3277 {
3278 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3279 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3280 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3281 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3282 }
Geoff Lang493daf52014-07-03 13:38:44 -04003283}
3284
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003285void Context::initWorkarounds()
3286{
Jamie Madill761b02c2017-06-23 16:27:06 -04003287 // Apply back-end workarounds.
3288 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3289
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003290 // Lose the context upon out of memory error if the application is
3291 // expecting to watch for those events.
3292 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3293}
3294
Jamie Madill05b35b22017-10-03 09:01:44 -04003295Error Context::prepareForDraw()
3296{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003297 if (mGLES1Renderer)
3298 {
3299 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3300 }
3301
Geoff Langa8cb2872018-03-09 16:09:40 -05003302 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003303
3304 if (isRobustResourceInitEnabled())
3305 {
3306 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3307 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3308 }
3309
Geoff Langa8cb2872018-03-09 16:09:40 -05003310 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003311 return NoError();
3312}
3313
3314Error Context::prepareForClear(GLbitfield mask)
3315{
Geoff Langa8cb2872018-03-09 16:09:40 -05003316 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003317 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003318 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003319 return NoError();
3320}
3321
3322Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3323{
Geoff Langa8cb2872018-03-09 16:09:40 -05003324 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003325 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3326 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003327 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003328 return NoError();
3329}
3330
Geoff Langa8cb2872018-03-09 16:09:40 -05003331Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003332{
Geoff Langa8cb2872018-03-09 16:09:40 -05003333 ANGLE_TRY(syncDirtyObjects());
3334 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003335 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003336}
3337
Geoff Langa8cb2872018-03-09 16:09:40 -05003338Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003339{
Geoff Langa8cb2872018-03-09 16:09:40 -05003340 ANGLE_TRY(syncDirtyObjects(objectMask));
3341 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003342 return NoError();
3343}
3344
Geoff Langa8cb2872018-03-09 16:09:40 -05003345Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003346{
3347 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3348 mImplementation->syncState(this, dirtyBits);
3349 mGLState.clearDirtyBits();
3350 return NoError();
3351}
3352
Geoff Langa8cb2872018-03-09 16:09:40 -05003353Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003355 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003356 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003357 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003358 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003359}
Jamie Madillc29968b2016-01-20 11:17:23 -05003360
Geoff Langa8cb2872018-03-09 16:09:40 -05003361Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003362{
3363 return mGLState.syncDirtyObjects(this);
3364}
3365
Geoff Langa8cb2872018-03-09 16:09:40 -05003366Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003367{
3368 return mGLState.syncDirtyObjects(this, objectMask);
3369}
3370
Jamie Madillc29968b2016-01-20 11:17:23 -05003371void Context::blitFramebuffer(GLint srcX0,
3372 GLint srcY0,
3373 GLint srcX1,
3374 GLint srcY1,
3375 GLint dstX0,
3376 GLint dstY0,
3377 GLint dstX1,
3378 GLint dstY1,
3379 GLbitfield mask,
3380 GLenum filter)
3381{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003382 if (mask == 0)
3383 {
3384 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3385 // buffers are copied.
3386 return;
3387 }
3388
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003389 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003390 ASSERT(drawFramebuffer);
3391
3392 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3393 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3394
Jamie Madillbc918e72018-03-08 09:47:21 -05003395 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003396
Jamie Madillc564c072017-06-01 12:45:42 -04003397 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003398}
Jamie Madillc29968b2016-01-20 11:17:23 -05003399
3400void Context::clear(GLbitfield mask)
3401{
Geoff Langd4fff502017-09-22 11:28:28 -04003402 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3403 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003404}
3405
3406void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3407{
Geoff Langd4fff502017-09-22 11:28:28 -04003408 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3409 ANGLE_CONTEXT_TRY(
3410 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003411}
3412
3413void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3414{
Geoff Langd4fff502017-09-22 11:28:28 -04003415 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3416 ANGLE_CONTEXT_TRY(
3417 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003418}
3419
3420void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3421{
Geoff Langd4fff502017-09-22 11:28:28 -04003422 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3423 ANGLE_CONTEXT_TRY(
3424 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003425}
3426
3427void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003429 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003430 ASSERT(framebufferObject);
3431
3432 // If a buffer is not present, the clear has no effect
3433 if (framebufferObject->getDepthbuffer() == nullptr &&
3434 framebufferObject->getStencilbuffer() == nullptr)
3435 {
3436 return;
3437 }
3438
Geoff Langd4fff502017-09-22 11:28:28 -04003439 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3440 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003441}
3442
3443void Context::readPixels(GLint x,
3444 GLint y,
3445 GLsizei width,
3446 GLsizei height,
3447 GLenum format,
3448 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003449 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003450{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003451 if (width == 0 || height == 0)
3452 {
3453 return;
3454 }
3455
Jamie Madillbc918e72018-03-08 09:47:21 -05003456 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003457
Jamie Madillb6664922017-07-25 12:55:04 -04003458 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3459 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003460
3461 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003462 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003463}
3464
Brandon Jones59770802018-04-02 13:18:42 -07003465void Context::readPixelsRobust(GLint x,
3466 GLint y,
3467 GLsizei width,
3468 GLsizei height,
3469 GLenum format,
3470 GLenum type,
3471 GLsizei bufSize,
3472 GLsizei *length,
3473 GLsizei *columns,
3474 GLsizei *rows,
3475 void *pixels)
3476{
3477 readPixels(x, y, width, height, format, type, pixels);
3478}
3479
3480void Context::readnPixelsRobust(GLint x,
3481 GLint y,
3482 GLsizei width,
3483 GLsizei height,
3484 GLenum format,
3485 GLenum type,
3486 GLsizei bufSize,
3487 GLsizei *length,
3488 GLsizei *columns,
3489 GLsizei *rows,
3490 void *data)
3491{
3492 readPixels(x, y, width, height, format, type, data);
3493}
3494
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003495void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003496 GLint level,
3497 GLenum internalformat,
3498 GLint x,
3499 GLint y,
3500 GLsizei width,
3501 GLsizei height,
3502 GLint border)
3503{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003504 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003505 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003506
Jamie Madillc29968b2016-01-20 11:17:23 -05003507 Rectangle sourceArea(x, y, width, height);
3508
Jamie Madill05b35b22017-10-03 09:01:44 -04003509 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003510 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003511 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003512}
3513
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003514void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003515 GLint level,
3516 GLint xoffset,
3517 GLint yoffset,
3518 GLint x,
3519 GLint y,
3520 GLsizei width,
3521 GLsizei height)
3522{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003523 if (width == 0 || height == 0)
3524 {
3525 return;
3526 }
3527
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003528 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003529 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003530
Jamie Madillc29968b2016-01-20 11:17:23 -05003531 Offset destOffset(xoffset, yoffset, 0);
3532 Rectangle sourceArea(x, y, width, height);
3533
Jamie Madill05b35b22017-10-03 09:01:44 -04003534 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003535 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003536 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003537}
3538
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003539void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003540 GLint level,
3541 GLint xoffset,
3542 GLint yoffset,
3543 GLint zoffset,
3544 GLint x,
3545 GLint y,
3546 GLsizei width,
3547 GLsizei height)
3548{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003549 if (width == 0 || height == 0)
3550 {
3551 return;
3552 }
3553
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003554 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003555 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003556
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 Offset destOffset(xoffset, yoffset, zoffset);
3558 Rectangle sourceArea(x, y, width, height);
3559
Jamie Madill05b35b22017-10-03 09:01:44 -04003560 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3561 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003562 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3563 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003564}
3565
3566void Context::framebufferTexture2D(GLenum target,
3567 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003568 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003569 GLuint texture,
3570 GLint level)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003573 ASSERT(framebuffer);
3574
3575 if (texture != 0)
3576 {
3577 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003578 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003579 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003580 }
3581 else
3582 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003583 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003584 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003585
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003587}
3588
3589void Context::framebufferRenderbuffer(GLenum target,
3590 GLenum attachment,
3591 GLenum renderbuffertarget,
3592 GLuint renderbuffer)
3593{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003594 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003595 ASSERT(framebuffer);
3596
3597 if (renderbuffer != 0)
3598 {
3599 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003600
Jamie Madillcc129372018-04-12 09:13:18 -04003601 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003602 renderbufferObject);
3603 }
3604 else
3605 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003606 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003607 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003608
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003609 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610}
3611
3612void Context::framebufferTextureLayer(GLenum target,
3613 GLenum attachment,
3614 GLuint texture,
3615 GLint level,
3616 GLint layer)
3617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003619 ASSERT(framebuffer);
3620
3621 if (texture != 0)
3622 {
3623 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003624 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003625 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 }
3627 else
3628 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003629 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003630 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003631
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003632 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003633}
3634
Brandon Jones59770802018-04-02 13:18:42 -07003635void Context::framebufferTextureMultiviewLayered(GLenum target,
3636 GLenum attachment,
3637 GLuint texture,
3638 GLint level,
3639 GLint baseViewIndex,
3640 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003641{
Martin Radev82ef7742017-08-08 17:44:58 +03003642 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3643 ASSERT(framebuffer);
3644
3645 if (texture != 0)
3646 {
3647 Texture *textureObj = getTexture(texture);
3648
Martin Radev18b75ba2017-08-15 15:50:40 +03003649 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003650 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3651 numViews, baseViewIndex);
3652 }
3653 else
3654 {
3655 framebuffer->resetAttachment(this, attachment);
3656 }
3657
3658 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003659}
3660
Brandon Jones59770802018-04-02 13:18:42 -07003661void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3662 GLenum attachment,
3663 GLuint texture,
3664 GLint level,
3665 GLsizei numViews,
3666 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003667{
Martin Radev5dae57b2017-07-14 16:15:55 +03003668 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3669 ASSERT(framebuffer);
3670
3671 if (texture != 0)
3672 {
3673 Texture *textureObj = getTexture(texture);
3674
3675 ImageIndex index = ImageIndex::Make2D(level);
3676 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3677 textureObj, numViews, viewportOffsets);
3678 }
3679 else
3680 {
3681 framebuffer->resetAttachment(this, attachment);
3682 }
3683
3684 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003685}
3686
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003687// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3688void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3689{
3690 UNIMPLEMENTED();
3691}
3692
Jamie Madillc29968b2016-01-20 11:17:23 -05003693void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3694{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 ASSERT(framebuffer);
3697 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003699}
3700
3701void Context::readBuffer(GLenum mode)
3702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003704 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706}
3707
3708void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3709{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003710 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003711 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003712
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003714 ASSERT(framebuffer);
3715
3716 // The specification isn't clear what should be done when the framebuffer isn't complete.
3717 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003718 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003719}
3720
3721void Context::invalidateFramebuffer(GLenum target,
3722 GLsizei numAttachments,
3723 const GLenum *attachments)
3724{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003726 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003727
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 ASSERT(framebuffer);
3730
Jamie Madill427064d2018-04-13 16:20:34 -04003731 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 {
Jamie Madill437fa652016-05-03 15:13:24 -04003733 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 }
Jamie Madill437fa652016-05-03 15:13:24 -04003735
Jamie Madill4928b7c2017-06-20 12:57:39 -04003736 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003737}
3738
3739void Context::invalidateSubFramebuffer(GLenum target,
3740 GLsizei numAttachments,
3741 const GLenum *attachments,
3742 GLint x,
3743 GLint y,
3744 GLsizei width,
3745 GLsizei height)
3746{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003748 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003749
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 ASSERT(framebuffer);
3752
Jamie Madill427064d2018-04-13 16:20:34 -04003753 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003754 {
Jamie Madill437fa652016-05-03 15:13:24 -04003755 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003756 }
Jamie Madill437fa652016-05-03 15:13:24 -04003757
3758 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003759 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003762void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003763 GLint level,
3764 GLint internalformat,
3765 GLsizei width,
3766 GLsizei height,
3767 GLint border,
3768 GLenum format,
3769 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003770 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003771{
Jamie Madillbc918e72018-03-08 09:47:21 -05003772 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003773
3774 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003775 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003776 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3777 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003778}
3779
Brandon Jones59770802018-04-02 13:18:42 -07003780void Context::texImage2DRobust(TextureTarget target,
3781 GLint level,
3782 GLint internalformat,
3783 GLsizei width,
3784 GLsizei height,
3785 GLint border,
3786 GLenum format,
3787 GLenum type,
3788 GLsizei bufSize,
3789 const void *pixels)
3790{
3791 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3792}
3793
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003794void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003795 GLint level,
3796 GLint internalformat,
3797 GLsizei width,
3798 GLsizei height,
3799 GLsizei depth,
3800 GLint border,
3801 GLenum format,
3802 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003803 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003804{
Jamie Madillbc918e72018-03-08 09:47:21 -05003805 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003806
3807 Extents size(width, height, depth);
3808 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003809 handleError(texture->setImage(this, mGLState.getUnpackState(),
3810 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3811 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003812}
3813
Brandon Jones59770802018-04-02 13:18:42 -07003814void Context::texImage3DRobust(TextureType target,
3815 GLint level,
3816 GLint internalformat,
3817 GLsizei width,
3818 GLsizei height,
3819 GLsizei depth,
3820 GLint border,
3821 GLenum format,
3822 GLenum type,
3823 GLsizei bufSize,
3824 const void *pixels)
3825{
3826 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3827}
3828
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003829void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003830 GLint level,
3831 GLint xoffset,
3832 GLint yoffset,
3833 GLsizei width,
3834 GLsizei height,
3835 GLenum format,
3836 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003837 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003838{
3839 // Zero sized uploads are valid but no-ops
3840 if (width == 0 || height == 0)
3841 {
3842 return;
3843 }
3844
Jamie Madillbc918e72018-03-08 09:47:21 -05003845 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003846
3847 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003848 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003849 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3850 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003851}
3852
Brandon Jones59770802018-04-02 13:18:42 -07003853void Context::texSubImage2DRobust(TextureTarget target,
3854 GLint level,
3855 GLint xoffset,
3856 GLint yoffset,
3857 GLsizei width,
3858 GLsizei height,
3859 GLenum format,
3860 GLenum type,
3861 GLsizei bufSize,
3862 const void *pixels)
3863{
3864 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3865}
3866
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003867void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003868 GLint level,
3869 GLint xoffset,
3870 GLint yoffset,
3871 GLint zoffset,
3872 GLsizei width,
3873 GLsizei height,
3874 GLsizei depth,
3875 GLenum format,
3876 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003877 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003878{
3879 // Zero sized uploads are valid but no-ops
3880 if (width == 0 || height == 0 || depth == 0)
3881 {
3882 return;
3883 }
3884
Jamie Madillbc918e72018-03-08 09:47:21 -05003885 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003886
3887 Box area(xoffset, yoffset, zoffset, width, height, depth);
3888 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003889 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3890 NonCubeTextureTypeToTarget(target), level, area, format, type,
3891 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003892}
3893
Brandon Jones59770802018-04-02 13:18:42 -07003894void Context::texSubImage3DRobust(TextureType target,
3895 GLint level,
3896 GLint xoffset,
3897 GLint yoffset,
3898 GLint zoffset,
3899 GLsizei width,
3900 GLsizei height,
3901 GLsizei depth,
3902 GLenum format,
3903 GLenum type,
3904 GLsizei bufSize,
3905 const void *pixels)
3906{
3907 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3908 pixels);
3909}
3910
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003911void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003912 GLint level,
3913 GLenum internalformat,
3914 GLsizei width,
3915 GLsizei height,
3916 GLint border,
3917 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003918 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003919{
Jamie Madillbc918e72018-03-08 09:47:21 -05003920 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003921
3922 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003923 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003924 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3925 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003926 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003927}
3928
Brandon Jones59770802018-04-02 13:18:42 -07003929void Context::compressedTexImage2DRobust(TextureTarget target,
3930 GLint level,
3931 GLenum internalformat,
3932 GLsizei width,
3933 GLsizei height,
3934 GLint border,
3935 GLsizei imageSize,
3936 GLsizei dataSize,
3937 const GLvoid *data)
3938{
3939 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3940}
3941
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003942void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003943 GLint level,
3944 GLenum internalformat,
3945 GLsizei width,
3946 GLsizei height,
3947 GLsizei depth,
3948 GLint border,
3949 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003950 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003951{
Jamie Madillbc918e72018-03-08 09:47:21 -05003952 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003953
3954 Extents size(width, height, depth);
3955 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003956 handleError(texture->setCompressedImage(
3957 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3958 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003959}
3960
Brandon Jones59770802018-04-02 13:18:42 -07003961void Context::compressedTexImage3DRobust(TextureType target,
3962 GLint level,
3963 GLenum internalformat,
3964 GLsizei width,
3965 GLsizei height,
3966 GLsizei depth,
3967 GLint border,
3968 GLsizei imageSize,
3969 GLsizei dataSize,
3970 const GLvoid *data)
3971{
3972 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3973 data);
3974}
3975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003976void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003977 GLint level,
3978 GLint xoffset,
3979 GLint yoffset,
3980 GLsizei width,
3981 GLsizei height,
3982 GLenum format,
3983 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
Jamie Madillbc918e72018-03-08 09:47:21 -05003986 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003987
3988 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003989 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003990 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3991 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003993}
3994
Brandon Jones59770802018-04-02 13:18:42 -07003995void Context::compressedTexSubImage2DRobust(TextureTarget target,
3996 GLint level,
3997 GLint xoffset,
3998 GLint yoffset,
3999 GLsizei width,
4000 GLsizei height,
4001 GLenum format,
4002 GLsizei imageSize,
4003 GLsizei dataSize,
4004 const GLvoid *data)
4005{
4006 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4007 data);
4008}
4009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004011 GLint level,
4012 GLint xoffset,
4013 GLint yoffset,
4014 GLint zoffset,
4015 GLsizei width,
4016 GLsizei height,
4017 GLsizei depth,
4018 GLenum format,
4019 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004020 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004021{
4022 // Zero sized uploads are valid but no-ops
4023 if (width == 0 || height == 0)
4024 {
4025 return;
4026 }
4027
Jamie Madillbc918e72018-03-08 09:47:21 -05004028 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004029
4030 Box area(xoffset, yoffset, zoffset, width, height, depth);
4031 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004032 handleError(texture->setCompressedSubImage(
4033 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4034 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004035}
4036
Brandon Jones59770802018-04-02 13:18:42 -07004037void Context::compressedTexSubImage3DRobust(TextureType target,
4038 GLint level,
4039 GLint xoffset,
4040 GLint yoffset,
4041 GLint zoffset,
4042 GLsizei width,
4043 GLsizei height,
4044 GLsizei depth,
4045 GLenum format,
4046 GLsizei imageSize,
4047 GLsizei dataSize,
4048 const GLvoid *data)
4049{
4050 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4051 imageSize, data);
4052}
4053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004054void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004055{
4056 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004057 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004058}
4059
Jamie Madill007530e2017-12-28 14:27:04 -05004060void Context::copyTexture(GLuint sourceId,
4061 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004062 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004063 GLuint destId,
4064 GLint destLevel,
4065 GLint internalFormat,
4066 GLenum destType,
4067 GLboolean unpackFlipY,
4068 GLboolean unpackPremultiplyAlpha,
4069 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004070{
Jamie Madillbc918e72018-03-08 09:47:21 -05004071 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004072
4073 gl::Texture *sourceTexture = getTexture(sourceId);
4074 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004075 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4076 sourceLevel, ConvertToBool(unpackFlipY),
4077 ConvertToBool(unpackPremultiplyAlpha),
4078 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004079}
4080
Jamie Madill007530e2017-12-28 14:27:04 -05004081void Context::copySubTexture(GLuint sourceId,
4082 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004083 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004084 GLuint destId,
4085 GLint destLevel,
4086 GLint xoffset,
4087 GLint yoffset,
4088 GLint x,
4089 GLint y,
4090 GLsizei width,
4091 GLsizei height,
4092 GLboolean unpackFlipY,
4093 GLboolean unpackPremultiplyAlpha,
4094 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004095{
4096 // Zero sized copies are valid but no-ops
4097 if (width == 0 || height == 0)
4098 {
4099 return;
4100 }
4101
Jamie Madillbc918e72018-03-08 09:47:21 -05004102 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004103
4104 gl::Texture *sourceTexture = getTexture(sourceId);
4105 gl::Texture *destTexture = getTexture(destId);
4106 Offset offset(xoffset, yoffset, 0);
4107 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004108 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4109 ConvertToBool(unpackFlipY),
4110 ConvertToBool(unpackPremultiplyAlpha),
4111 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004112}
4113
Jamie Madill007530e2017-12-28 14:27:04 -05004114void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004115{
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004117
4118 gl::Texture *sourceTexture = getTexture(sourceId);
4119 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004120 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004121}
4122
Corentin Wallez336129f2017-10-17 15:55:40 -04004123void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004124{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004125 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004126 ASSERT(buffer);
4127
Geoff Lang496c02d2016-10-20 11:38:11 -07004128 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004129}
4130
Brandon Jones59770802018-04-02 13:18:42 -07004131void Context::getBufferPointervRobust(BufferBinding target,
4132 GLenum pname,
4133 GLsizei bufSize,
4134 GLsizei *length,
4135 void **params)
4136{
4137 getBufferPointerv(target, pname, params);
4138}
4139
Corentin Wallez336129f2017-10-17 15:55:40 -04004140void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004141{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004143 ASSERT(buffer);
4144
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004145 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004146 if (error.isError())
4147 {
Jamie Madill437fa652016-05-03 15:13:24 -04004148 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004149 return nullptr;
4150 }
4151
4152 return buffer->getMapPointer();
4153}
4154
Corentin Wallez336129f2017-10-17 15:55:40 -04004155GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004157 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004158 ASSERT(buffer);
4159
4160 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004161 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004162 if (error.isError())
4163 {
Jamie Madill437fa652016-05-03 15:13:24 -04004164 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004165 return GL_FALSE;
4166 }
4167
4168 return result;
4169}
4170
Corentin Wallez336129f2017-10-17 15:55:40 -04004171void *Context::mapBufferRange(BufferBinding target,
4172 GLintptr offset,
4173 GLsizeiptr length,
4174 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004175{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004176 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004177 ASSERT(buffer);
4178
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004179 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 if (error.isError())
4181 {
Jamie Madill437fa652016-05-03 15:13:24 -04004182 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 return nullptr;
4184 }
4185
4186 return buffer->getMapPointer();
4187}
4188
Corentin Wallez336129f2017-10-17 15:55:40 -04004189void Context::flushMappedBufferRange(BufferBinding /*target*/,
4190 GLintptr /*offset*/,
4191 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004192{
4193 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4194}
4195
Jamie Madillbc918e72018-03-08 09:47:21 -05004196Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004197{
Geoff Langa8cb2872018-03-09 16:09:40 -05004198 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004199}
4200
Jamie Madillbc918e72018-03-08 09:47:21 -05004201Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004202{
Geoff Langa8cb2872018-03-09 16:09:40 -05004203 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004204}
4205
Jamie Madillbc918e72018-03-08 09:47:21 -05004206Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004207{
Geoff Langa8cb2872018-03-09 16:09:40 -05004208 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004209}
4210
Jiajia Qin5451d532017-11-16 17:16:34 +08004211void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4212{
4213 UNIMPLEMENTED();
4214}
4215
Jamie Madillc20ab272016-06-09 07:20:46 -07004216void Context::activeTexture(GLenum texture)
4217{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004218 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004219}
4220
Jamie Madill876429b2017-04-20 15:46:24 -04004221void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004223 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004224}
4225
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004226void Context::blendEquation(GLenum mode)
4227{
4228 mGLState.setBlendEquation(mode, mode);
4229}
4230
Jamie Madillc20ab272016-06-09 07:20:46 -07004231void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004234}
4235
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004236void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4237{
4238 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4239}
4240
Jamie Madillc20ab272016-06-09 07:20:46 -07004241void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4242{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004243 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004244}
4245
Jamie Madill876429b2017-04-20 15:46:24 -04004246void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
Jamie Madill876429b2017-04-20 15:46:24 -04004251void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004252{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004253 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004254}
4255
4256void Context::clearStencil(GLint s)
4257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004258 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004259}
4260
4261void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4262{
Geoff Lang92019432017-11-20 13:09:34 -05004263 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4264 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004267void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004268{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270}
4271
4272void Context::depthFunc(GLenum func)
4273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004275}
4276
4277void Context::depthMask(GLboolean flag)
4278{
Geoff Lang92019432017-11-20 13:09:34 -05004279 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004280}
4281
Jamie Madill876429b2017-04-20 15:46:24 -04004282void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285}
4286
4287void Context::disable(GLenum cap)
4288{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004289 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004290}
4291
4292void Context::disableVertexAttribArray(GLuint index)
4293{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004294 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004295}
4296
4297void Context::enable(GLenum cap)
4298{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300}
4301
4302void Context::enableVertexAttribArray(GLuint index)
4303{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305}
4306
4307void Context::frontFace(GLenum mode)
4308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004309 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004310}
4311
4312void Context::hint(GLenum target, GLenum mode)
4313{
4314 switch (target)
4315 {
4316 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004317 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004318 break;
4319
4320 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004321 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004322 break;
4323
4324 default:
4325 UNREACHABLE();
4326 return;
4327 }
4328}
4329
4330void Context::lineWidth(GLfloat width)
4331{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004332 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004333}
4334
4335void Context::pixelStorei(GLenum pname, GLint param)
4336{
4337 switch (pname)
4338 {
4339 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004341 break;
4342
4343 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345 break;
4346
4347 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349 break;
4350
4351 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004352 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354 break;
4355
4356 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004357 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359 break;
4360
4361 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004362 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364 break;
4365
4366 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004367 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369 break;
4370
4371 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004372 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374 break;
4375
4376 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004377 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379 break;
4380
4381 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004382 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004383 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004384 break;
4385
4386 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004387 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004388 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004389 break;
4390
4391 default:
4392 UNREACHABLE();
4393 return;
4394 }
4395}
4396
4397void Context::polygonOffset(GLfloat factor, GLfloat units)
4398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
Jamie Madill876429b2017-04-20 15:46:24 -04004402void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004403{
Geoff Lang92019432017-11-20 13:09:34 -05004404 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jiawei Shaodb342272017-09-27 10:21:45 +08004407void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4408{
4409 mGLState.setSampleMaskParams(maskNumber, mask);
4410}
4411
Jamie Madillc20ab272016-06-09 07:20:46 -07004412void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
4417void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4418{
4419 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4420 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422 }
4423
4424 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4425 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004426 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004427 }
4428}
4429
4430void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4431{
4432 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4433 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004434 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004435 }
4436
4437 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4438 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004439 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004440 }
4441}
4442
4443void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4444{
4445 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4446 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448 }
4449
4450 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4451 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004452 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004453 }
4454}
4455
4456void Context::vertexAttrib1f(GLuint index, GLfloat x)
4457{
4458 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4463{
4464 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4469{
4470 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4475{
4476 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4481{
4482 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004483 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4487{
4488 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
4492void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4493{
4494 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004495 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
4498void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::vertexAttribPointer(GLuint index,
4504 GLint size,
4505 GLenum type,
4506 GLboolean normalized,
4507 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004508 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004509{
Corentin Wallez336129f2017-10-17 15:55:40 -04004510 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004511 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
Shao80957d92017-02-20 21:25:59 +08004514void Context::vertexAttribFormat(GLuint attribIndex,
4515 GLint size,
4516 GLenum type,
4517 GLboolean normalized,
4518 GLuint relativeOffset)
4519{
Geoff Lang92019432017-11-20 13:09:34 -05004520 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004521 relativeOffset);
4522}
4523
4524void Context::vertexAttribIFormat(GLuint attribIndex,
4525 GLint size,
4526 GLenum type,
4527 GLuint relativeOffset)
4528{
4529 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4530}
4531
4532void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4533{
Shaodde78e82017-05-22 14:13:27 +08004534 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004535}
4536
Jiajia Qin5451d532017-11-16 17:16:34 +08004537void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004538{
4539 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4540}
4541
Jamie Madillc20ab272016-06-09 07:20:46 -07004542void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4543{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545}
4546
4547void Context::vertexAttribIPointer(GLuint index,
4548 GLint size,
4549 GLenum type,
4550 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004551 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004552{
Corentin Wallez336129f2017-10-17 15:55:40 -04004553 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4554 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4558{
4559 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4564{
4565 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572}
4573
4574void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577}
4578
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004579void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4580{
4581 const VertexAttribCurrentValueData &currentValues =
4582 getGLState().getVertexAttribCurrentValue(index);
4583 const VertexArray *vao = getGLState().getVertexArray();
4584 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4585 currentValues, pname, params);
4586}
4587
Brandon Jones59770802018-04-02 13:18:42 -07004588void Context::getVertexAttribivRobust(GLuint index,
4589 GLenum pname,
4590 GLsizei bufSize,
4591 GLsizei *length,
4592 GLint *params)
4593{
4594 getVertexAttribiv(index, pname, params);
4595}
4596
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004597void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4598{
4599 const VertexAttribCurrentValueData &currentValues =
4600 getGLState().getVertexAttribCurrentValue(index);
4601 const VertexArray *vao = getGLState().getVertexArray();
4602 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4603 currentValues, pname, params);
4604}
4605
Brandon Jones59770802018-04-02 13:18:42 -07004606void Context::getVertexAttribfvRobust(GLuint index,
4607 GLenum pname,
4608 GLsizei bufSize,
4609 GLsizei *length,
4610 GLfloat *params)
4611{
4612 getVertexAttribfv(index, pname, params);
4613}
4614
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004615void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4616{
4617 const VertexAttribCurrentValueData &currentValues =
4618 getGLState().getVertexAttribCurrentValue(index);
4619 const VertexArray *vao = getGLState().getVertexArray();
4620 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4621 currentValues, pname, params);
4622}
4623
Brandon Jones59770802018-04-02 13:18:42 -07004624void Context::getVertexAttribIivRobust(GLuint index,
4625 GLenum pname,
4626 GLsizei bufSize,
4627 GLsizei *length,
4628 GLint *params)
4629{
4630 getVertexAttribIiv(index, pname, params);
4631}
4632
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004633void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4634{
4635 const VertexAttribCurrentValueData &currentValues =
4636 getGLState().getVertexAttribCurrentValue(index);
4637 const VertexArray *vao = getGLState().getVertexArray();
4638 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4639 currentValues, pname, params);
4640}
4641
Brandon Jones59770802018-04-02 13:18:42 -07004642void Context::getVertexAttribIuivRobust(GLuint index,
4643 GLenum pname,
4644 GLsizei bufSize,
4645 GLsizei *length,
4646 GLuint *params)
4647{
4648 getVertexAttribIuiv(index, pname, params);
4649}
4650
Jamie Madill876429b2017-04-20 15:46:24 -04004651void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004652{
4653 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4654 QueryVertexAttribPointerv(attrib, pname, pointer);
4655}
4656
Brandon Jones59770802018-04-02 13:18:42 -07004657void Context::getVertexAttribPointervRobust(GLuint index,
4658 GLenum pname,
4659 GLsizei bufSize,
4660 GLsizei *length,
4661 void **pointer)
4662{
4663 getVertexAttribPointerv(index, pname, pointer);
4664}
4665
Jamie Madillc20ab272016-06-09 07:20:46 -07004666void Context::debugMessageControl(GLenum source,
4667 GLenum type,
4668 GLenum severity,
4669 GLsizei count,
4670 const GLuint *ids,
4671 GLboolean enabled)
4672{
4673 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004675 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
4678void Context::debugMessageInsert(GLenum source,
4679 GLenum type,
4680 GLuint id,
4681 GLenum severity,
4682 GLsizei length,
4683 const GLchar *buf)
4684{
4685 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004687}
4688
4689void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4690{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004691 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004692}
4693
4694GLuint Context::getDebugMessageLog(GLuint count,
4695 GLsizei bufSize,
4696 GLenum *sources,
4697 GLenum *types,
4698 GLuint *ids,
4699 GLenum *severities,
4700 GLsizei *lengths,
4701 GLchar *messageLog)
4702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004703 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4704 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004705}
4706
4707void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4708{
4709 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004710 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004711 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712}
4713
4714void Context::popDebugGroup()
4715{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004717 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004718}
4719
Corentin Wallez336129f2017-10-17 15:55:40 -04004720void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004721{
4722 Buffer *buffer = mGLState.getTargetBuffer(target);
4723 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004724 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004725}
4726
Corentin Wallez336129f2017-10-17 15:55:40 -04004727void Context::bufferSubData(BufferBinding target,
4728 GLintptr offset,
4729 GLsizeiptr size,
4730 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004731{
4732 if (data == nullptr)
4733 {
4734 return;
4735 }
4736
4737 Buffer *buffer = mGLState.getTargetBuffer(target);
4738 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004739 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004740}
4741
Jamie Madillef300b12016-10-07 15:12:09 -04004742void Context::attachShader(GLuint program, GLuint shader)
4743{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004744 Program *programObject = mState.mShaderPrograms->getProgram(program);
4745 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004746 ASSERT(programObject && shaderObject);
4747 programObject->attachShader(shaderObject);
4748}
4749
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004750const Workarounds &Context::getWorkarounds() const
4751{
4752 return mWorkarounds;
4753}
4754
Corentin Wallez336129f2017-10-17 15:55:40 -04004755void Context::copyBufferSubData(BufferBinding readTarget,
4756 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004757 GLintptr readOffset,
4758 GLintptr writeOffset,
4759 GLsizeiptr size)
4760{
4761 // if size is zero, the copy is a successful no-op
4762 if (size == 0)
4763 {
4764 return;
4765 }
4766
4767 // TODO(jmadill): cache these.
4768 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4769 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4770
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004771 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004772}
4773
Jamie Madill01a80ee2016-11-07 12:06:18 -05004774void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4775{
4776 Program *programObject = getProgram(program);
4777 // TODO(jmadill): Re-use this from the validation if possible.
4778 ASSERT(programObject);
4779 programObject->bindAttributeLocation(index, name);
4780}
4781
Corentin Wallez336129f2017-10-17 15:55:40 -04004782void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783{
Corentin Wallez336129f2017-10-17 15:55:40 -04004784 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4785 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004786}
4787
Corentin Wallez336129f2017-10-17 15:55:40 -04004788void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004789{
4790 bindBufferRange(target, index, buffer, 0, 0);
4791}
4792
Corentin Wallez336129f2017-10-17 15:55:40 -04004793void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004794 GLuint index,
4795 GLuint buffer,
4796 GLintptr offset,
4797 GLsizeiptr size)
4798{
Corentin Wallez336129f2017-10-17 15:55:40 -04004799 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4800 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004801}
4802
Jamie Madill01a80ee2016-11-07 12:06:18 -05004803void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4804{
4805 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4806 {
4807 bindReadFramebuffer(framebuffer);
4808 }
4809
4810 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4811 {
4812 bindDrawFramebuffer(framebuffer);
4813 }
4814}
4815
4816void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4817{
4818 ASSERT(target == GL_RENDERBUFFER);
4819 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004820 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004821 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004822}
4823
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004824void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004825 GLsizei samples,
4826 GLenum internalformat,
4827 GLsizei width,
4828 GLsizei height,
4829 GLboolean fixedsamplelocations)
4830{
4831 Extents size(width, height, 1);
4832 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004833 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4834 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004835}
4836
4837void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4838{
JiangYizhou5b03f472017-01-09 10:22:53 +08004839 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4840 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004841 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004842 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004843
4844 switch (pname)
4845 {
4846 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004847 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004848 break;
4849 default:
4850 UNREACHABLE();
4851 }
4852}
4853
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004854void Context::getMultisamplefvRobust(GLenum pname,
4855 GLuint index,
4856 GLsizei bufSize,
4857 GLsizei *length,
4858 GLfloat *val)
4859{
4860 UNIMPLEMENTED();
4861}
4862
Jamie Madille8fb6402017-02-14 17:56:40 -05004863void Context::renderbufferStorage(GLenum target,
4864 GLenum internalformat,
4865 GLsizei width,
4866 GLsizei height)
4867{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004868 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4869 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4870
Jamie Madille8fb6402017-02-14 17:56:40 -05004871 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004872 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004873}
4874
4875void Context::renderbufferStorageMultisample(GLenum target,
4876 GLsizei samples,
4877 GLenum internalformat,
4878 GLsizei width,
4879 GLsizei height)
4880{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004881 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4882 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004883
4884 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004885 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004886 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004887}
4888
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004889void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4890{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004891 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004892 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004893}
4894
JiangYizhoue18e6392017-02-20 10:32:23 +08004895void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4896{
4897 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4898 QueryFramebufferParameteriv(framebuffer, pname, params);
4899}
4900
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004901void Context::getFramebufferParameterivRobust(GLenum target,
4902 GLenum pname,
4903 GLsizei bufSize,
4904 GLsizei *length,
4905 GLint *params)
4906{
4907 UNIMPLEMENTED();
4908}
4909
Jiajia Qin5451d532017-11-16 17:16:34 +08004910void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004911{
4912 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4913 SetFramebufferParameteri(framebuffer, pname, param);
4914}
4915
Jamie Madillb3f26b92017-07-19 15:07:41 -04004916Error Context::getScratchBuffer(size_t requstedSizeBytes,
4917 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004918{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004919 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4920 {
4921 return OutOfMemory() << "Failed to allocate internal buffer.";
4922 }
4923 return NoError();
4924}
4925
4926Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4927 angle::MemoryBuffer **zeroBufferOut) const
4928{
4929 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004930 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004931 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004932 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004933 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004934}
4935
Xinghua Cao10a4d432017-11-28 14:46:26 +08004936Error Context::prepareForDispatch()
4937{
Geoff Langa8cb2872018-03-09 16:09:40 -05004938 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004939
4940 if (isRobustResourceInitEnabled())
4941 {
4942 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4943 }
4944
4945 return NoError();
4946}
4947
Xinghua Cao2b396592017-03-29 15:36:04 +08004948void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4949{
4950 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4951 {
4952 return;
4953 }
4954
Xinghua Cao10a4d432017-11-28 14:46:26 +08004955 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004956 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004957}
4958
Jiajia Qin5451d532017-11-16 17:16:34 +08004959void Context::dispatchComputeIndirect(GLintptr indirect)
4960{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004961 ANGLE_CONTEXT_TRY(prepareForDispatch());
4962 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004963}
4964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004965void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004966 GLsizei levels,
4967 GLenum internalFormat,
4968 GLsizei width,
4969 GLsizei height)
4970{
4971 Extents size(width, height, 1);
4972 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004973 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004974}
4975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004976void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004977 GLsizei levels,
4978 GLenum internalFormat,
4979 GLsizei width,
4980 GLsizei height,
4981 GLsizei depth)
4982{
4983 Extents size(width, height, depth);
4984 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004985 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004986}
4987
Jiajia Qin5451d532017-11-16 17:16:34 +08004988void Context::memoryBarrier(GLbitfield barriers)
4989{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004990 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004991}
4992
4993void Context::memoryBarrierByRegion(GLbitfield barriers)
4994{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004995 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004996}
4997
Jamie Madillc1d770e2017-04-13 17:31:24 -04004998GLenum Context::checkFramebufferStatus(GLenum target)
4999{
5000 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5001 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005002 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005003}
5004
5005void Context::compileShader(GLuint shader)
5006{
5007 Shader *shaderObject = GetValidShader(this, shader);
5008 if (!shaderObject)
5009 {
5010 return;
5011 }
5012 shaderObject->compile(this);
5013}
5014
5015void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5016{
5017 for (int i = 0; i < n; i++)
5018 {
5019 deleteBuffer(buffers[i]);
5020 }
5021}
5022
5023void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5024{
5025 for (int i = 0; i < n; i++)
5026 {
5027 if (framebuffers[i] != 0)
5028 {
5029 deleteFramebuffer(framebuffers[i]);
5030 }
5031 }
5032}
5033
5034void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5035{
5036 for (int i = 0; i < n; i++)
5037 {
5038 deleteRenderbuffer(renderbuffers[i]);
5039 }
5040}
5041
5042void Context::deleteTextures(GLsizei n, const GLuint *textures)
5043{
5044 for (int i = 0; i < n; i++)
5045 {
5046 if (textures[i] != 0)
5047 {
5048 deleteTexture(textures[i]);
5049 }
5050 }
5051}
5052
5053void Context::detachShader(GLuint program, GLuint shader)
5054{
5055 Program *programObject = getProgram(program);
5056 ASSERT(programObject);
5057
5058 Shader *shaderObject = getShader(shader);
5059 ASSERT(shaderObject);
5060
5061 programObject->detachShader(this, shaderObject);
5062}
5063
5064void Context::genBuffers(GLsizei n, GLuint *buffers)
5065{
5066 for (int i = 0; i < n; i++)
5067 {
5068 buffers[i] = createBuffer();
5069 }
5070}
5071
5072void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5073{
5074 for (int i = 0; i < n; i++)
5075 {
5076 framebuffers[i] = createFramebuffer();
5077 }
5078}
5079
5080void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5081{
5082 for (int i = 0; i < n; i++)
5083 {
5084 renderbuffers[i] = createRenderbuffer();
5085 }
5086}
5087
5088void Context::genTextures(GLsizei n, GLuint *textures)
5089{
5090 for (int i = 0; i < n; i++)
5091 {
5092 textures[i] = createTexture();
5093 }
5094}
5095
5096void Context::getActiveAttrib(GLuint program,
5097 GLuint index,
5098 GLsizei bufsize,
5099 GLsizei *length,
5100 GLint *size,
5101 GLenum *type,
5102 GLchar *name)
5103{
5104 Program *programObject = getProgram(program);
5105 ASSERT(programObject);
5106 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5107}
5108
5109void Context::getActiveUniform(GLuint program,
5110 GLuint index,
5111 GLsizei bufsize,
5112 GLsizei *length,
5113 GLint *size,
5114 GLenum *type,
5115 GLchar *name)
5116{
5117 Program *programObject = getProgram(program);
5118 ASSERT(programObject);
5119 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5120}
5121
5122void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5123{
5124 Program *programObject = getProgram(program);
5125 ASSERT(programObject);
5126 programObject->getAttachedShaders(maxcount, count, shaders);
5127}
5128
5129GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5130{
5131 Program *programObject = getProgram(program);
5132 ASSERT(programObject);
5133 return programObject->getAttributeLocation(name);
5134}
5135
5136void Context::getBooleanv(GLenum pname, GLboolean *params)
5137{
5138 GLenum nativeType;
5139 unsigned int numParams = 0;
5140 getQueryParameterInfo(pname, &nativeType, &numParams);
5141
5142 if (nativeType == GL_BOOL)
5143 {
5144 getBooleanvImpl(pname, params);
5145 }
5146 else
5147 {
5148 CastStateValues(this, nativeType, pname, numParams, params);
5149 }
5150}
5151
Brandon Jones59770802018-04-02 13:18:42 -07005152void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5153{
5154 getBooleanv(pname, params);
5155}
5156
Jamie Madillc1d770e2017-04-13 17:31:24 -04005157void Context::getFloatv(GLenum pname, GLfloat *params)
5158{
5159 GLenum nativeType;
5160 unsigned int numParams = 0;
5161 getQueryParameterInfo(pname, &nativeType, &numParams);
5162
5163 if (nativeType == GL_FLOAT)
5164 {
5165 getFloatvImpl(pname, params);
5166 }
5167 else
5168 {
5169 CastStateValues(this, nativeType, pname, numParams, params);
5170 }
5171}
5172
Brandon Jones59770802018-04-02 13:18:42 -07005173void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5174{
5175 getFloatv(pname, params);
5176}
5177
Jamie Madillc1d770e2017-04-13 17:31:24 -04005178void Context::getIntegerv(GLenum pname, GLint *params)
5179{
5180 GLenum nativeType;
5181 unsigned int numParams = 0;
5182 getQueryParameterInfo(pname, &nativeType, &numParams);
5183
5184 if (nativeType == GL_INT)
5185 {
5186 getIntegervImpl(pname, params);
5187 }
5188 else
5189 {
5190 CastStateValues(this, nativeType, pname, numParams, params);
5191 }
5192}
5193
Brandon Jones59770802018-04-02 13:18:42 -07005194void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5195{
5196 getIntegerv(pname, data);
5197}
5198
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5200{
5201 Program *programObject = getProgram(program);
5202 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005203 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204}
5205
Brandon Jones59770802018-04-02 13:18:42 -07005206void Context::getProgramivRobust(GLuint program,
5207 GLenum pname,
5208 GLsizei bufSize,
5209 GLsizei *length,
5210 GLint *params)
5211{
5212 getProgramiv(program, pname, params);
5213}
5214
Jiajia Qin5451d532017-11-16 17:16:34 +08005215void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5216{
5217 UNIMPLEMENTED();
5218}
5219
Jamie Madillbe849e42017-05-02 15:49:00 -04005220void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221{
5222 Program *programObject = getProgram(program);
5223 ASSERT(programObject);
5224 programObject->getInfoLog(bufsize, length, infolog);
5225}
5226
Jiajia Qin5451d532017-11-16 17:16:34 +08005227void Context::getProgramPipelineInfoLog(GLuint pipeline,
5228 GLsizei bufSize,
5229 GLsizei *length,
5230 GLchar *infoLog)
5231{
5232 UNIMPLEMENTED();
5233}
5234
Jamie Madillc1d770e2017-04-13 17:31:24 -04005235void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5236{
5237 Shader *shaderObject = getShader(shader);
5238 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005239 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005240}
5241
Brandon Jones59770802018-04-02 13:18:42 -07005242void Context::getShaderivRobust(GLuint shader,
5243 GLenum pname,
5244 GLsizei bufSize,
5245 GLsizei *length,
5246 GLint *params)
5247{
5248 getShaderiv(shader, pname, params);
5249}
5250
Jamie Madillc1d770e2017-04-13 17:31:24 -04005251void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5252{
5253 Shader *shaderObject = getShader(shader);
5254 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005255 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005256}
5257
5258void Context::getShaderPrecisionFormat(GLenum shadertype,
5259 GLenum precisiontype,
5260 GLint *range,
5261 GLint *precision)
5262{
5263 // TODO(jmadill): Compute shaders.
5264
5265 switch (shadertype)
5266 {
5267 case GL_VERTEX_SHADER:
5268 switch (precisiontype)
5269 {
5270 case GL_LOW_FLOAT:
5271 mCaps.vertexLowpFloat.get(range, precision);
5272 break;
5273 case GL_MEDIUM_FLOAT:
5274 mCaps.vertexMediumpFloat.get(range, precision);
5275 break;
5276 case GL_HIGH_FLOAT:
5277 mCaps.vertexHighpFloat.get(range, precision);
5278 break;
5279
5280 case GL_LOW_INT:
5281 mCaps.vertexLowpInt.get(range, precision);
5282 break;
5283 case GL_MEDIUM_INT:
5284 mCaps.vertexMediumpInt.get(range, precision);
5285 break;
5286 case GL_HIGH_INT:
5287 mCaps.vertexHighpInt.get(range, precision);
5288 break;
5289
5290 default:
5291 UNREACHABLE();
5292 return;
5293 }
5294 break;
5295
5296 case GL_FRAGMENT_SHADER:
5297 switch (precisiontype)
5298 {
5299 case GL_LOW_FLOAT:
5300 mCaps.fragmentLowpFloat.get(range, precision);
5301 break;
5302 case GL_MEDIUM_FLOAT:
5303 mCaps.fragmentMediumpFloat.get(range, precision);
5304 break;
5305 case GL_HIGH_FLOAT:
5306 mCaps.fragmentHighpFloat.get(range, precision);
5307 break;
5308
5309 case GL_LOW_INT:
5310 mCaps.fragmentLowpInt.get(range, precision);
5311 break;
5312 case GL_MEDIUM_INT:
5313 mCaps.fragmentMediumpInt.get(range, precision);
5314 break;
5315 case GL_HIGH_INT:
5316 mCaps.fragmentHighpInt.get(range, precision);
5317 break;
5318
5319 default:
5320 UNREACHABLE();
5321 return;
5322 }
5323 break;
5324
5325 default:
5326 UNREACHABLE();
5327 return;
5328 }
5329}
5330
5331void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5332{
5333 Shader *shaderObject = getShader(shader);
5334 ASSERT(shaderObject);
5335 shaderObject->getSource(bufsize, length, source);
5336}
5337
5338void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5339{
5340 Program *programObject = getProgram(program);
5341 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005342 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005343}
5344
Brandon Jones59770802018-04-02 13:18:42 -07005345void Context::getUniformfvRobust(GLuint program,
5346 GLint location,
5347 GLsizei bufSize,
5348 GLsizei *length,
5349 GLfloat *params)
5350{
5351 getUniformfv(program, location, params);
5352}
5353
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5355{
5356 Program *programObject = getProgram(program);
5357 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005358 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359}
5360
Brandon Jones59770802018-04-02 13:18:42 -07005361void Context::getUniformivRobust(GLuint program,
5362 GLint location,
5363 GLsizei bufSize,
5364 GLsizei *length,
5365 GLint *params)
5366{
5367 getUniformiv(program, location, params);
5368}
5369
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5371{
5372 Program *programObject = getProgram(program);
5373 ASSERT(programObject);
5374 return programObject->getUniformLocation(name);
5375}
5376
5377GLboolean Context::isBuffer(GLuint buffer)
5378{
5379 if (buffer == 0)
5380 {
5381 return GL_FALSE;
5382 }
5383
5384 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5385}
5386
5387GLboolean Context::isEnabled(GLenum cap)
5388{
5389 return mGLState.getEnableFeature(cap);
5390}
5391
5392GLboolean Context::isFramebuffer(GLuint framebuffer)
5393{
5394 if (framebuffer == 0)
5395 {
5396 return GL_FALSE;
5397 }
5398
5399 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5400}
5401
5402GLboolean Context::isProgram(GLuint program)
5403{
5404 if (program == 0)
5405 {
5406 return GL_FALSE;
5407 }
5408
5409 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5410}
5411
5412GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5413{
5414 if (renderbuffer == 0)
5415 {
5416 return GL_FALSE;
5417 }
5418
5419 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5420}
5421
5422GLboolean Context::isShader(GLuint shader)
5423{
5424 if (shader == 0)
5425 {
5426 return GL_FALSE;
5427 }
5428
5429 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5430}
5431
5432GLboolean Context::isTexture(GLuint texture)
5433{
5434 if (texture == 0)
5435 {
5436 return GL_FALSE;
5437 }
5438
5439 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5440}
5441
5442void Context::linkProgram(GLuint program)
5443{
5444 Program *programObject = getProgram(program);
5445 ASSERT(programObject);
5446 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005447 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448}
5449
5450void Context::releaseShaderCompiler()
5451{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005452 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005453}
5454
5455void Context::shaderBinary(GLsizei n,
5456 const GLuint *shaders,
5457 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005458 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459 GLsizei length)
5460{
5461 // No binary shader formats are supported.
5462 UNIMPLEMENTED();
5463}
5464
5465void Context::shaderSource(GLuint shader,
5466 GLsizei count,
5467 const GLchar *const *string,
5468 const GLint *length)
5469{
5470 Shader *shaderObject = getShader(shader);
5471 ASSERT(shaderObject);
5472 shaderObject->setSource(count, string, length);
5473}
5474
5475void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5476{
5477 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5478}
5479
5480void Context::stencilMask(GLuint mask)
5481{
5482 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5483}
5484
5485void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5486{
5487 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5488}
5489
5490void Context::uniform1f(GLint location, GLfloat x)
5491{
5492 Program *program = mGLState.getProgram();
5493 program->setUniform1fv(location, 1, &x);
5494}
5495
5496void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5497{
5498 Program *program = mGLState.getProgram();
5499 program->setUniform1fv(location, count, v);
5500}
5501
5502void Context::uniform1i(GLint location, GLint x)
5503{
5504 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005505 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5506 {
5507 mGLState.setObjectDirty(GL_PROGRAM);
5508 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005509}
5510
5511void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5512{
5513 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005514 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5515 {
5516 mGLState.setObjectDirty(GL_PROGRAM);
5517 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518}
5519
5520void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5521{
5522 GLfloat xy[2] = {x, y};
5523 Program *program = mGLState.getProgram();
5524 program->setUniform2fv(location, 1, xy);
5525}
5526
5527void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5528{
5529 Program *program = mGLState.getProgram();
5530 program->setUniform2fv(location, count, v);
5531}
5532
5533void Context::uniform2i(GLint location, GLint x, GLint y)
5534{
5535 GLint xy[2] = {x, y};
5536 Program *program = mGLState.getProgram();
5537 program->setUniform2iv(location, 1, xy);
5538}
5539
5540void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5541{
5542 Program *program = mGLState.getProgram();
5543 program->setUniform2iv(location, count, v);
5544}
5545
5546void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5547{
5548 GLfloat xyz[3] = {x, y, z};
5549 Program *program = mGLState.getProgram();
5550 program->setUniform3fv(location, 1, xyz);
5551}
5552
5553void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5554{
5555 Program *program = mGLState.getProgram();
5556 program->setUniform3fv(location, count, v);
5557}
5558
5559void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5560{
5561 GLint xyz[3] = {x, y, z};
5562 Program *program = mGLState.getProgram();
5563 program->setUniform3iv(location, 1, xyz);
5564}
5565
5566void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5567{
5568 Program *program = mGLState.getProgram();
5569 program->setUniform3iv(location, count, v);
5570}
5571
5572void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5573{
5574 GLfloat xyzw[4] = {x, y, z, w};
5575 Program *program = mGLState.getProgram();
5576 program->setUniform4fv(location, 1, xyzw);
5577}
5578
5579void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5580{
5581 Program *program = mGLState.getProgram();
5582 program->setUniform4fv(location, count, v);
5583}
5584
5585void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5586{
5587 GLint xyzw[4] = {x, y, z, w};
5588 Program *program = mGLState.getProgram();
5589 program->setUniform4iv(location, 1, xyzw);
5590}
5591
5592void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5593{
5594 Program *program = mGLState.getProgram();
5595 program->setUniform4iv(location, count, v);
5596}
5597
5598void Context::uniformMatrix2fv(GLint location,
5599 GLsizei count,
5600 GLboolean transpose,
5601 const GLfloat *value)
5602{
5603 Program *program = mGLState.getProgram();
5604 program->setUniformMatrix2fv(location, count, transpose, value);
5605}
5606
5607void Context::uniformMatrix3fv(GLint location,
5608 GLsizei count,
5609 GLboolean transpose,
5610 const GLfloat *value)
5611{
5612 Program *program = mGLState.getProgram();
5613 program->setUniformMatrix3fv(location, count, transpose, value);
5614}
5615
5616void Context::uniformMatrix4fv(GLint location,
5617 GLsizei count,
5618 GLboolean transpose,
5619 const GLfloat *value)
5620{
5621 Program *program = mGLState.getProgram();
5622 program->setUniformMatrix4fv(location, count, transpose, value);
5623}
5624
5625void Context::validateProgram(GLuint program)
5626{
5627 Program *programObject = getProgram(program);
5628 ASSERT(programObject);
5629 programObject->validate(mCaps);
5630}
5631
Jiajia Qin5451d532017-11-16 17:16:34 +08005632void Context::validateProgramPipeline(GLuint pipeline)
5633{
5634 UNIMPLEMENTED();
5635}
5636
Jamie Madilld04908b2017-06-09 14:15:35 -04005637void Context::getProgramBinary(GLuint program,
5638 GLsizei bufSize,
5639 GLsizei *length,
5640 GLenum *binaryFormat,
5641 void *binary)
5642{
5643 Program *programObject = getProgram(program);
5644 ASSERT(programObject != nullptr);
5645
5646 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5647}
5648
5649void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5650{
5651 Program *programObject = getProgram(program);
5652 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005653
Jamie Madilld04908b2017-06-09 14:15:35 -04005654 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5655}
5656
Jamie Madillff325f12017-08-26 15:06:05 -04005657void Context::uniform1ui(GLint location, GLuint v0)
5658{
5659 Program *program = mGLState.getProgram();
5660 program->setUniform1uiv(location, 1, &v0);
5661}
5662
5663void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5664{
5665 Program *program = mGLState.getProgram();
5666 const GLuint xy[] = {v0, v1};
5667 program->setUniform2uiv(location, 1, xy);
5668}
5669
5670void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5671{
5672 Program *program = mGLState.getProgram();
5673 const GLuint xyz[] = {v0, v1, v2};
5674 program->setUniform3uiv(location, 1, xyz);
5675}
5676
5677void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5678{
5679 Program *program = mGLState.getProgram();
5680 const GLuint xyzw[] = {v0, v1, v2, v3};
5681 program->setUniform4uiv(location, 1, xyzw);
5682}
5683
5684void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5685{
5686 Program *program = mGLState.getProgram();
5687 program->setUniform1uiv(location, count, value);
5688}
5689void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5690{
5691 Program *program = mGLState.getProgram();
5692 program->setUniform2uiv(location, count, value);
5693}
5694
5695void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5696{
5697 Program *program = mGLState.getProgram();
5698 program->setUniform3uiv(location, count, value);
5699}
5700
5701void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5702{
5703 Program *program = mGLState.getProgram();
5704 program->setUniform4uiv(location, count, value);
5705}
5706
Jamie Madillf0e04492017-08-26 15:28:42 -04005707void Context::genQueries(GLsizei n, GLuint *ids)
5708{
5709 for (GLsizei i = 0; i < n; i++)
5710 {
5711 GLuint handle = mQueryHandleAllocator.allocate();
5712 mQueryMap.assign(handle, nullptr);
5713 ids[i] = handle;
5714 }
5715}
5716
5717void Context::deleteQueries(GLsizei n, const GLuint *ids)
5718{
5719 for (int i = 0; i < n; i++)
5720 {
5721 GLuint query = ids[i];
5722
5723 Query *queryObject = nullptr;
5724 if (mQueryMap.erase(query, &queryObject))
5725 {
5726 mQueryHandleAllocator.release(query);
5727 if (queryObject)
5728 {
5729 queryObject->release(this);
5730 }
5731 }
5732 }
5733}
5734
5735GLboolean Context::isQuery(GLuint id)
5736{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005737 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005738}
5739
Jamie Madillc8c95812017-08-26 18:40:09 -04005740void Context::uniformMatrix2x3fv(GLint location,
5741 GLsizei count,
5742 GLboolean transpose,
5743 const GLfloat *value)
5744{
5745 Program *program = mGLState.getProgram();
5746 program->setUniformMatrix2x3fv(location, count, transpose, value);
5747}
5748
5749void Context::uniformMatrix3x2fv(GLint location,
5750 GLsizei count,
5751 GLboolean transpose,
5752 const GLfloat *value)
5753{
5754 Program *program = mGLState.getProgram();
5755 program->setUniformMatrix3x2fv(location, count, transpose, value);
5756}
5757
5758void Context::uniformMatrix2x4fv(GLint location,
5759 GLsizei count,
5760 GLboolean transpose,
5761 const GLfloat *value)
5762{
5763 Program *program = mGLState.getProgram();
5764 program->setUniformMatrix2x4fv(location, count, transpose, value);
5765}
5766
5767void Context::uniformMatrix4x2fv(GLint location,
5768 GLsizei count,
5769 GLboolean transpose,
5770 const GLfloat *value)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniformMatrix4x2fv(location, count, transpose, value);
5774}
5775
5776void Context::uniformMatrix3x4fv(GLint location,
5777 GLsizei count,
5778 GLboolean transpose,
5779 const GLfloat *value)
5780{
5781 Program *program = mGLState.getProgram();
5782 program->setUniformMatrix3x4fv(location, count, transpose, value);
5783}
5784
5785void Context::uniformMatrix4x3fv(GLint location,
5786 GLsizei count,
5787 GLboolean transpose,
5788 const GLfloat *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniformMatrix4x3fv(location, count, transpose, value);
5792}
5793
Jamie Madilld7576732017-08-26 18:49:50 -04005794void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5795{
5796 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5797 {
5798 GLuint vertexArray = arrays[arrayIndex];
5799
5800 if (arrays[arrayIndex] != 0)
5801 {
5802 VertexArray *vertexArrayObject = nullptr;
5803 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5804 {
5805 if (vertexArrayObject != nullptr)
5806 {
5807 detachVertexArray(vertexArray);
5808 vertexArrayObject->onDestroy(this);
5809 }
5810
5811 mVertexArrayHandleAllocator.release(vertexArray);
5812 }
5813 }
5814 }
5815}
5816
5817void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5818{
5819 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5820 {
5821 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5822 mVertexArrayMap.assign(vertexArray, nullptr);
5823 arrays[arrayIndex] = vertexArray;
5824 }
5825}
5826
5827bool Context::isVertexArray(GLuint array)
5828{
5829 if (array == 0)
5830 {
5831 return GL_FALSE;
5832 }
5833
5834 VertexArray *vao = getVertexArray(array);
5835 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5836}
5837
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005838void Context::endTransformFeedback()
5839{
5840 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5841 transformFeedback->end(this);
5842}
5843
5844void Context::transformFeedbackVaryings(GLuint program,
5845 GLsizei count,
5846 const GLchar *const *varyings,
5847 GLenum bufferMode)
5848{
5849 Program *programObject = getProgram(program);
5850 ASSERT(programObject);
5851 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5852}
5853
5854void Context::getTransformFeedbackVarying(GLuint program,
5855 GLuint index,
5856 GLsizei bufSize,
5857 GLsizei *length,
5858 GLsizei *size,
5859 GLenum *type,
5860 GLchar *name)
5861{
5862 Program *programObject = getProgram(program);
5863 ASSERT(programObject);
5864 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5865}
5866
5867void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5868{
5869 for (int i = 0; i < n; i++)
5870 {
5871 GLuint transformFeedback = ids[i];
5872 if (transformFeedback == 0)
5873 {
5874 continue;
5875 }
5876
5877 TransformFeedback *transformFeedbackObject = nullptr;
5878 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5879 {
5880 if (transformFeedbackObject != nullptr)
5881 {
5882 detachTransformFeedback(transformFeedback);
5883 transformFeedbackObject->release(this);
5884 }
5885
5886 mTransformFeedbackHandleAllocator.release(transformFeedback);
5887 }
5888 }
5889}
5890
5891void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5892{
5893 for (int i = 0; i < n; i++)
5894 {
5895 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5896 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5897 ids[i] = transformFeedback;
5898 }
5899}
5900
5901bool Context::isTransformFeedback(GLuint id)
5902{
5903 if (id == 0)
5904 {
5905 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5906 // returns FALSE
5907 return GL_FALSE;
5908 }
5909
5910 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5911 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5912}
5913
5914void Context::pauseTransformFeedback()
5915{
5916 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5917 transformFeedback->pause();
5918}
5919
5920void Context::resumeTransformFeedback()
5921{
5922 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5923 transformFeedback->resume();
5924}
5925
Jamie Madill12e957f2017-08-26 21:42:26 -04005926void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5927{
5928 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005929 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005930}
5931
Brandon Jones59770802018-04-02 13:18:42 -07005932void Context::getUniformuivRobust(GLuint program,
5933 GLint location,
5934 GLsizei bufSize,
5935 GLsizei *length,
5936 GLuint *params)
5937{
5938 getUniformuiv(program, location, params);
5939}
5940
Jamie Madill12e957f2017-08-26 21:42:26 -04005941GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5942{
5943 const Program *programObject = getProgram(program);
5944 return programObject->getFragDataLocation(name);
5945}
5946
5947void Context::getUniformIndices(GLuint program,
5948 GLsizei uniformCount,
5949 const GLchar *const *uniformNames,
5950 GLuint *uniformIndices)
5951{
5952 const Program *programObject = getProgram(program);
5953 if (!programObject->isLinked())
5954 {
5955 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5956 {
5957 uniformIndices[uniformId] = GL_INVALID_INDEX;
5958 }
5959 }
5960 else
5961 {
5962 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5963 {
5964 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5965 }
5966 }
5967}
5968
5969void Context::getActiveUniformsiv(GLuint program,
5970 GLsizei uniformCount,
5971 const GLuint *uniformIndices,
5972 GLenum pname,
5973 GLint *params)
5974{
5975 const Program *programObject = getProgram(program);
5976 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5977 {
5978 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005979 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005980 }
5981}
5982
5983GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5984{
5985 const Program *programObject = getProgram(program);
5986 return programObject->getUniformBlockIndex(uniformBlockName);
5987}
5988
5989void Context::getActiveUniformBlockiv(GLuint program,
5990 GLuint uniformBlockIndex,
5991 GLenum pname,
5992 GLint *params)
5993{
5994 const Program *programObject = getProgram(program);
5995 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5996}
5997
Brandon Jones59770802018-04-02 13:18:42 -07005998void Context::getActiveUniformBlockivRobust(GLuint program,
5999 GLuint uniformBlockIndex,
6000 GLenum pname,
6001 GLsizei bufSize,
6002 GLsizei *length,
6003 GLint *params)
6004{
6005 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6006}
6007
Jamie Madill12e957f2017-08-26 21:42:26 -04006008void Context::getActiveUniformBlockName(GLuint program,
6009 GLuint uniformBlockIndex,
6010 GLsizei bufSize,
6011 GLsizei *length,
6012 GLchar *uniformBlockName)
6013{
6014 const Program *programObject = getProgram(program);
6015 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6016}
6017
6018void Context::uniformBlockBinding(GLuint program,
6019 GLuint uniformBlockIndex,
6020 GLuint uniformBlockBinding)
6021{
6022 Program *programObject = getProgram(program);
6023 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6024}
6025
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006026GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6027{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006028 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6029 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006030
Jamie Madill70b5bb02017-08-28 13:32:37 -04006031 Sync *syncObject = getSync(syncHandle);
6032 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006033 if (error.isError())
6034 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006035 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006036 handleError(error);
6037 return nullptr;
6038 }
6039
Jamie Madill70b5bb02017-08-28 13:32:37 -04006040 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006041}
6042
6043GLboolean Context::isSync(GLsync sync)
6044{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006045 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006046}
6047
6048GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6049{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006050 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006051
6052 GLenum result = GL_WAIT_FAILED;
6053 handleError(syncObject->clientWait(flags, timeout, &result));
6054 return result;
6055}
6056
6057void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6058{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006059 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006060 handleError(syncObject->serverWait(flags, timeout));
6061}
6062
6063void Context::getInteger64v(GLenum pname, GLint64 *params)
6064{
6065 GLenum nativeType = GL_NONE;
6066 unsigned int numParams = 0;
6067 getQueryParameterInfo(pname, &nativeType, &numParams);
6068
6069 if (nativeType == GL_INT_64_ANGLEX)
6070 {
6071 getInteger64vImpl(pname, params);
6072 }
6073 else
6074 {
6075 CastStateValues(this, nativeType, pname, numParams, params);
6076 }
6077}
6078
Brandon Jones59770802018-04-02 13:18:42 -07006079void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6080{
6081 getInteger64v(pname, data);
6082}
6083
Corentin Wallez336129f2017-10-17 15:55:40 -04006084void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006085{
6086 Buffer *buffer = mGLState.getTargetBuffer(target);
6087 QueryBufferParameteri64v(buffer, pname, params);
6088}
6089
Brandon Jones59770802018-04-02 13:18:42 -07006090void Context::getBufferParameteri64vRobust(BufferBinding target,
6091 GLenum pname,
6092 GLsizei bufSize,
6093 GLsizei *length,
6094 GLint64 *params)
6095{
6096 getBufferParameteri64v(target, pname, params);
6097}
6098
Jamie Madill3ef140a2017-08-26 23:11:21 -04006099void Context::genSamplers(GLsizei count, GLuint *samplers)
6100{
6101 for (int i = 0; i < count; i++)
6102 {
6103 samplers[i] = mState.mSamplers->createSampler();
6104 }
6105}
6106
6107void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6108{
6109 for (int i = 0; i < count; i++)
6110 {
6111 GLuint sampler = samplers[i];
6112
6113 if (mState.mSamplers->getSampler(sampler))
6114 {
6115 detachSampler(sampler);
6116 }
6117
6118 mState.mSamplers->deleteObject(this, sampler);
6119 }
6120}
6121
6122void Context::getInternalformativ(GLenum target,
6123 GLenum internalformat,
6124 GLenum pname,
6125 GLsizei bufSize,
6126 GLint *params)
6127{
6128 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6129 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6130}
6131
Brandon Jones59770802018-04-02 13:18:42 -07006132void Context::getInternalformativRobust(GLenum target,
6133 GLenum internalformat,
6134 GLenum pname,
6135 GLsizei bufSize,
6136 GLsizei *length,
6137 GLint *params)
6138{
6139 getInternalformativ(target, internalformat, pname, bufSize, params);
6140}
6141
Jiajia Qin5451d532017-11-16 17:16:34 +08006142void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6143{
6144 programUniform1iv(program, location, 1, &v0);
6145}
6146
6147void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6148{
6149 GLint xy[2] = {v0, v1};
6150 programUniform2iv(program, location, 1, xy);
6151}
6152
6153void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6154{
6155 GLint xyz[3] = {v0, v1, v2};
6156 programUniform3iv(program, location, 1, xyz);
6157}
6158
6159void Context::programUniform4i(GLuint program,
6160 GLint location,
6161 GLint v0,
6162 GLint v1,
6163 GLint v2,
6164 GLint v3)
6165{
6166 GLint xyzw[4] = {v0, v1, v2, v3};
6167 programUniform4iv(program, location, 1, xyzw);
6168}
6169
6170void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6171{
6172 programUniform1uiv(program, location, 1, &v0);
6173}
6174
6175void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6176{
6177 GLuint xy[2] = {v0, v1};
6178 programUniform2uiv(program, location, 1, xy);
6179}
6180
6181void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6182{
6183 GLuint xyz[3] = {v0, v1, v2};
6184 programUniform3uiv(program, location, 1, xyz);
6185}
6186
6187void Context::programUniform4ui(GLuint program,
6188 GLint location,
6189 GLuint v0,
6190 GLuint v1,
6191 GLuint v2,
6192 GLuint v3)
6193{
6194 GLuint xyzw[4] = {v0, v1, v2, v3};
6195 programUniform4uiv(program, location, 1, xyzw);
6196}
6197
6198void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6199{
6200 programUniform1fv(program, location, 1, &v0);
6201}
6202
6203void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6204{
6205 GLfloat xy[2] = {v0, v1};
6206 programUniform2fv(program, location, 1, xy);
6207}
6208
6209void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6210{
6211 GLfloat xyz[3] = {v0, v1, v2};
6212 programUniform3fv(program, location, 1, xyz);
6213}
6214
6215void Context::programUniform4f(GLuint program,
6216 GLint location,
6217 GLfloat v0,
6218 GLfloat v1,
6219 GLfloat v2,
6220 GLfloat v3)
6221{
6222 GLfloat xyzw[4] = {v0, v1, v2, v3};
6223 programUniform4fv(program, location, 1, xyzw);
6224}
6225
Jamie Madill81c2e252017-09-09 23:32:46 -04006226void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6227{
6228 Program *programObject = getProgram(program);
6229 ASSERT(programObject);
6230 if (programObject->setUniform1iv(location, count, value) ==
6231 Program::SetUniformResult::SamplerChanged)
6232 {
6233 mGLState.setObjectDirty(GL_PROGRAM);
6234 }
6235}
6236
Jiajia Qin5451d532017-11-16 17:16:34 +08006237void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6238{
6239 Program *programObject = getProgram(program);
6240 ASSERT(programObject);
6241 programObject->setUniform2iv(location, count, value);
6242}
6243
6244void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6245{
6246 Program *programObject = getProgram(program);
6247 ASSERT(programObject);
6248 programObject->setUniform3iv(location, count, value);
6249}
6250
6251void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6252{
6253 Program *programObject = getProgram(program);
6254 ASSERT(programObject);
6255 programObject->setUniform4iv(location, count, value);
6256}
6257
6258void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6259{
6260 Program *programObject = getProgram(program);
6261 ASSERT(programObject);
6262 programObject->setUniform1uiv(location, count, value);
6263}
6264
6265void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6266{
6267 Program *programObject = getProgram(program);
6268 ASSERT(programObject);
6269 programObject->setUniform2uiv(location, count, value);
6270}
6271
6272void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6273{
6274 Program *programObject = getProgram(program);
6275 ASSERT(programObject);
6276 programObject->setUniform3uiv(location, count, value);
6277}
6278
6279void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6280{
6281 Program *programObject = getProgram(program);
6282 ASSERT(programObject);
6283 programObject->setUniform4uiv(location, count, value);
6284}
6285
6286void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6287{
6288 Program *programObject = getProgram(program);
6289 ASSERT(programObject);
6290 programObject->setUniform1fv(location, count, value);
6291}
6292
6293void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6294{
6295 Program *programObject = getProgram(program);
6296 ASSERT(programObject);
6297 programObject->setUniform2fv(location, count, value);
6298}
6299
6300void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6301{
6302 Program *programObject = getProgram(program);
6303 ASSERT(programObject);
6304 programObject->setUniform3fv(location, count, value);
6305}
6306
6307void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6308{
6309 Program *programObject = getProgram(program);
6310 ASSERT(programObject);
6311 programObject->setUniform4fv(location, count, value);
6312}
6313
6314void Context::programUniformMatrix2fv(GLuint program,
6315 GLint location,
6316 GLsizei count,
6317 GLboolean transpose,
6318 const GLfloat *value)
6319{
6320 Program *programObject = getProgram(program);
6321 ASSERT(programObject);
6322 programObject->setUniformMatrix2fv(location, count, transpose, value);
6323}
6324
6325void Context::programUniformMatrix3fv(GLuint program,
6326 GLint location,
6327 GLsizei count,
6328 GLboolean transpose,
6329 const GLfloat *value)
6330{
6331 Program *programObject = getProgram(program);
6332 ASSERT(programObject);
6333 programObject->setUniformMatrix3fv(location, count, transpose, value);
6334}
6335
6336void Context::programUniformMatrix4fv(GLuint program,
6337 GLint location,
6338 GLsizei count,
6339 GLboolean transpose,
6340 const GLfloat *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniformMatrix4fv(location, count, transpose, value);
6345}
6346
6347void Context::programUniformMatrix2x3fv(GLuint program,
6348 GLint location,
6349 GLsizei count,
6350 GLboolean transpose,
6351 const GLfloat *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6356}
6357
6358void Context::programUniformMatrix3x2fv(GLuint program,
6359 GLint location,
6360 GLsizei count,
6361 GLboolean transpose,
6362 const GLfloat *value)
6363{
6364 Program *programObject = getProgram(program);
6365 ASSERT(programObject);
6366 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6367}
6368
6369void Context::programUniformMatrix2x4fv(GLuint program,
6370 GLint location,
6371 GLsizei count,
6372 GLboolean transpose,
6373 const GLfloat *value)
6374{
6375 Program *programObject = getProgram(program);
6376 ASSERT(programObject);
6377 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6378}
6379
6380void Context::programUniformMatrix4x2fv(GLuint program,
6381 GLint location,
6382 GLsizei count,
6383 GLboolean transpose,
6384 const GLfloat *value)
6385{
6386 Program *programObject = getProgram(program);
6387 ASSERT(programObject);
6388 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6389}
6390
6391void Context::programUniformMatrix3x4fv(GLuint program,
6392 GLint location,
6393 GLsizei count,
6394 GLboolean transpose,
6395 const GLfloat *value)
6396{
6397 Program *programObject = getProgram(program);
6398 ASSERT(programObject);
6399 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6400}
6401
6402void Context::programUniformMatrix4x3fv(GLuint program,
6403 GLint location,
6404 GLsizei count,
6405 GLboolean transpose,
6406 const GLfloat *value)
6407{
6408 Program *programObject = getProgram(program);
6409 ASSERT(programObject);
6410 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6411}
6412
Jamie Madill81c2e252017-09-09 23:32:46 -04006413void Context::onTextureChange(const Texture *texture)
6414{
6415 // Conservatively assume all textures are dirty.
6416 // TODO(jmadill): More fine-grained update.
6417 mGLState.setObjectDirty(GL_TEXTURE);
6418}
6419
James Darpiniane8a93c62018-01-04 18:02:24 -08006420bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6421{
6422 return mGLState.isCurrentTransformFeedback(tf);
6423}
6424bool Context::isCurrentVertexArray(const VertexArray *va) const
6425{
6426 return mGLState.isCurrentVertexArray(va);
6427}
6428
Yunchao Hea336b902017-08-02 16:05:21 +08006429void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6430{
6431 for (int i = 0; i < count; i++)
6432 {
6433 pipelines[i] = createProgramPipeline();
6434 }
6435}
6436
6437void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6438{
6439 for (int i = 0; i < count; i++)
6440 {
6441 if (pipelines[i] != 0)
6442 {
6443 deleteProgramPipeline(pipelines[i]);
6444 }
6445 }
6446}
6447
6448GLboolean Context::isProgramPipeline(GLuint pipeline)
6449{
6450 if (pipeline == 0)
6451 {
6452 return GL_FALSE;
6453 }
6454
6455 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6456}
6457
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006458void Context::finishFenceNV(GLuint fence)
6459{
6460 FenceNV *fenceObject = getFenceNV(fence);
6461
6462 ASSERT(fenceObject && fenceObject->isSet());
6463 handleError(fenceObject->finish());
6464}
6465
6466void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6467{
6468 FenceNV *fenceObject = getFenceNV(fence);
6469
6470 ASSERT(fenceObject && fenceObject->isSet());
6471
6472 switch (pname)
6473 {
6474 case GL_FENCE_STATUS_NV:
6475 {
6476 // GL_NV_fence spec:
6477 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6478 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6479 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6480 GLboolean status = GL_TRUE;
6481 if (fenceObject->getStatus() != GL_TRUE)
6482 {
6483 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6484 }
6485 *params = status;
6486 break;
6487 }
6488
6489 case GL_FENCE_CONDITION_NV:
6490 {
6491 *params = static_cast<GLint>(fenceObject->getCondition());
6492 break;
6493 }
6494
6495 default:
6496 UNREACHABLE();
6497 }
6498}
6499
6500void Context::getTranslatedShaderSource(GLuint shader,
6501 GLsizei bufsize,
6502 GLsizei *length,
6503 GLchar *source)
6504{
6505 Shader *shaderObject = getShader(shader);
6506 ASSERT(shaderObject);
6507 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6508}
6509
6510void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6511{
6512 Program *programObject = getProgram(program);
6513 ASSERT(programObject);
6514
6515 programObject->getUniformfv(this, location, params);
6516}
6517
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006518void Context::getnUniformfvRobust(GLuint program,
6519 GLint location,
6520 GLsizei bufSize,
6521 GLsizei *length,
6522 GLfloat *params)
6523{
6524 UNIMPLEMENTED();
6525}
6526
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006527void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531
6532 programObject->getUniformiv(this, location, params);
6533}
6534
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006535void Context::getnUniformivRobust(GLuint program,
6536 GLint location,
6537 GLsizei bufSize,
6538 GLsizei *length,
6539 GLint *params)
6540{
6541 UNIMPLEMENTED();
6542}
6543
6544void Context::getnUniformuivRobust(GLuint program,
6545 GLint location,
6546 GLsizei bufSize,
6547 GLsizei *length,
6548 GLuint *params)
6549{
6550 UNIMPLEMENTED();
6551}
6552
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006553GLboolean Context::isFenceNV(GLuint fence)
6554{
6555 FenceNV *fenceObject = getFenceNV(fence);
6556
6557 if (fenceObject == nullptr)
6558 {
6559 return GL_FALSE;
6560 }
6561
6562 // GL_NV_fence spec:
6563 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6564 // existing fence.
6565 return fenceObject->isSet();
6566}
6567
6568void Context::readnPixels(GLint x,
6569 GLint y,
6570 GLsizei width,
6571 GLsizei height,
6572 GLenum format,
6573 GLenum type,
6574 GLsizei bufSize,
6575 void *data)
6576{
6577 return readPixels(x, y, width, height, format, type, data);
6578}
6579
Jamie Madill007530e2017-12-28 14:27:04 -05006580void Context::setFenceNV(GLuint fence, GLenum condition)
6581{
6582 ASSERT(condition == GL_ALL_COMPLETED_NV);
6583
6584 FenceNV *fenceObject = getFenceNV(fence);
6585 ASSERT(fenceObject != nullptr);
6586 handleError(fenceObject->set(condition));
6587}
6588
6589GLboolean Context::testFenceNV(GLuint fence)
6590{
6591 FenceNV *fenceObject = getFenceNV(fence);
6592
6593 ASSERT(fenceObject != nullptr);
6594 ASSERT(fenceObject->isSet() == GL_TRUE);
6595
6596 GLboolean result = GL_TRUE;
6597 Error error = fenceObject->test(&result);
6598 if (error.isError())
6599 {
6600 handleError(error);
6601 return GL_TRUE;
6602 }
6603
6604 return result;
6605}
6606
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006607void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006608{
6609 Texture *texture = getTargetTexture(target);
6610 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006611 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006612}
6613
Jamie Madillfa920eb2018-01-04 11:45:50 -05006614void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006615{
6616 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6617 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6618 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6619}
6620
Jamie Madillfa920eb2018-01-04 11:45:50 -05006621void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6622{
6623 UNIMPLEMENTED();
6624}
6625
Jamie Madill5b772312018-03-08 20:28:32 -05006626bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6627{
6628 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6629 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6630 // to the fact that it is stored internally as a float, and so would require conversion
6631 // if returned from Context::getIntegerv. Since this conversion is already implemented
6632 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6633 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6634 // application.
6635 switch (pname)
6636 {
6637 case GL_COMPRESSED_TEXTURE_FORMATS:
6638 {
6639 *type = GL_INT;
6640 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6641 return true;
6642 }
6643 case GL_SHADER_BINARY_FORMATS:
6644 {
6645 *type = GL_INT;
6646 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6647 return true;
6648 }
6649
6650 case GL_MAX_VERTEX_ATTRIBS:
6651 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6652 case GL_MAX_VARYING_VECTORS:
6653 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6654 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6655 case GL_MAX_TEXTURE_IMAGE_UNITS:
6656 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6657 case GL_MAX_RENDERBUFFER_SIZE:
6658 case GL_NUM_SHADER_BINARY_FORMATS:
6659 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6660 case GL_ARRAY_BUFFER_BINDING:
6661 case GL_FRAMEBUFFER_BINDING:
6662 case GL_RENDERBUFFER_BINDING:
6663 case GL_CURRENT_PROGRAM:
6664 case GL_PACK_ALIGNMENT:
6665 case GL_UNPACK_ALIGNMENT:
6666 case GL_GENERATE_MIPMAP_HINT:
6667 case GL_RED_BITS:
6668 case GL_GREEN_BITS:
6669 case GL_BLUE_BITS:
6670 case GL_ALPHA_BITS:
6671 case GL_DEPTH_BITS:
6672 case GL_STENCIL_BITS:
6673 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6674 case GL_CULL_FACE_MODE:
6675 case GL_FRONT_FACE:
6676 case GL_ACTIVE_TEXTURE:
6677 case GL_STENCIL_FUNC:
6678 case GL_STENCIL_VALUE_MASK:
6679 case GL_STENCIL_REF:
6680 case GL_STENCIL_FAIL:
6681 case GL_STENCIL_PASS_DEPTH_FAIL:
6682 case GL_STENCIL_PASS_DEPTH_PASS:
6683 case GL_STENCIL_BACK_FUNC:
6684 case GL_STENCIL_BACK_VALUE_MASK:
6685 case GL_STENCIL_BACK_REF:
6686 case GL_STENCIL_BACK_FAIL:
6687 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6688 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6689 case GL_DEPTH_FUNC:
6690 case GL_BLEND_SRC_RGB:
6691 case GL_BLEND_SRC_ALPHA:
6692 case GL_BLEND_DST_RGB:
6693 case GL_BLEND_DST_ALPHA:
6694 case GL_BLEND_EQUATION_RGB:
6695 case GL_BLEND_EQUATION_ALPHA:
6696 case GL_STENCIL_WRITEMASK:
6697 case GL_STENCIL_BACK_WRITEMASK:
6698 case GL_STENCIL_CLEAR_VALUE:
6699 case GL_SUBPIXEL_BITS:
6700 case GL_MAX_TEXTURE_SIZE:
6701 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6702 case GL_SAMPLE_BUFFERS:
6703 case GL_SAMPLES:
6704 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6705 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6706 case GL_TEXTURE_BINDING_2D:
6707 case GL_TEXTURE_BINDING_CUBE_MAP:
6708 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6709 {
6710 *type = GL_INT;
6711 *numParams = 1;
6712 return true;
6713 }
6714 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6715 {
6716 if (!getExtensions().packReverseRowOrder)
6717 {
6718 return false;
6719 }
6720 *type = GL_INT;
6721 *numParams = 1;
6722 return true;
6723 }
6724 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6725 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6726 {
6727 if (!getExtensions().textureRectangle)
6728 {
6729 return false;
6730 }
6731 *type = GL_INT;
6732 *numParams = 1;
6733 return true;
6734 }
6735 case GL_MAX_DRAW_BUFFERS_EXT:
6736 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6737 {
6738 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6739 {
6740 return false;
6741 }
6742 *type = GL_INT;
6743 *numParams = 1;
6744 return true;
6745 }
6746 case GL_MAX_VIEWPORT_DIMS:
6747 {
6748 *type = GL_INT;
6749 *numParams = 2;
6750 return true;
6751 }
6752 case GL_VIEWPORT:
6753 case GL_SCISSOR_BOX:
6754 {
6755 *type = GL_INT;
6756 *numParams = 4;
6757 return true;
6758 }
6759 case GL_SHADER_COMPILER:
6760 case GL_SAMPLE_COVERAGE_INVERT:
6761 case GL_DEPTH_WRITEMASK:
6762 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6763 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6764 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6765 // bool-natural
6766 case GL_SAMPLE_COVERAGE:
6767 case GL_SCISSOR_TEST:
6768 case GL_STENCIL_TEST:
6769 case GL_DEPTH_TEST:
6770 case GL_BLEND:
6771 case GL_DITHER:
6772 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6773 {
6774 *type = GL_BOOL;
6775 *numParams = 1;
6776 return true;
6777 }
6778 case GL_COLOR_WRITEMASK:
6779 {
6780 *type = GL_BOOL;
6781 *numParams = 4;
6782 return true;
6783 }
6784 case GL_POLYGON_OFFSET_FACTOR:
6785 case GL_POLYGON_OFFSET_UNITS:
6786 case GL_SAMPLE_COVERAGE_VALUE:
6787 case GL_DEPTH_CLEAR_VALUE:
6788 case GL_LINE_WIDTH:
6789 {
6790 *type = GL_FLOAT;
6791 *numParams = 1;
6792 return true;
6793 }
6794 case GL_ALIASED_LINE_WIDTH_RANGE:
6795 case GL_ALIASED_POINT_SIZE_RANGE:
6796 case GL_DEPTH_RANGE:
6797 {
6798 *type = GL_FLOAT;
6799 *numParams = 2;
6800 return true;
6801 }
6802 case GL_COLOR_CLEAR_VALUE:
6803 case GL_BLEND_COLOR:
6804 {
6805 *type = GL_FLOAT;
6806 *numParams = 4;
6807 return true;
6808 }
6809 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6810 if (!getExtensions().textureFilterAnisotropic)
6811 {
6812 return false;
6813 }
6814 *type = GL_FLOAT;
6815 *numParams = 1;
6816 return true;
6817 case GL_TIMESTAMP_EXT:
6818 if (!getExtensions().disjointTimerQuery)
6819 {
6820 return false;
6821 }
6822 *type = GL_INT_64_ANGLEX;
6823 *numParams = 1;
6824 return true;
6825 case GL_GPU_DISJOINT_EXT:
6826 if (!getExtensions().disjointTimerQuery)
6827 {
6828 return false;
6829 }
6830 *type = GL_INT;
6831 *numParams = 1;
6832 return true;
6833 case GL_COVERAGE_MODULATION_CHROMIUM:
6834 if (!getExtensions().framebufferMixedSamples)
6835 {
6836 return false;
6837 }
6838 *type = GL_INT;
6839 *numParams = 1;
6840 return true;
6841 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6842 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6843 {
6844 return false;
6845 }
6846 *type = GL_INT;
6847 *numParams = 1;
6848 return true;
6849 }
6850
6851 if (getExtensions().debug)
6852 {
6853 switch (pname)
6854 {
6855 case GL_DEBUG_LOGGED_MESSAGES:
6856 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6857 case GL_DEBUG_GROUP_STACK_DEPTH:
6858 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6859 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6860 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6861 case GL_MAX_LABEL_LENGTH:
6862 *type = GL_INT;
6863 *numParams = 1;
6864 return true;
6865
6866 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6867 case GL_DEBUG_OUTPUT:
6868 *type = GL_BOOL;
6869 *numParams = 1;
6870 return true;
6871 }
6872 }
6873
6874 if (getExtensions().multisampleCompatibility)
6875 {
6876 switch (pname)
6877 {
6878 case GL_MULTISAMPLE_EXT:
6879 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6880 *type = GL_BOOL;
6881 *numParams = 1;
6882 return true;
6883 }
6884 }
6885
6886 if (getExtensions().pathRendering)
6887 {
6888 switch (pname)
6889 {
6890 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6891 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6892 *type = GL_FLOAT;
6893 *numParams = 16;
6894 return true;
6895 }
6896 }
6897
6898 if (getExtensions().bindGeneratesResource)
6899 {
6900 switch (pname)
6901 {
6902 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6903 *type = GL_BOOL;
6904 *numParams = 1;
6905 return true;
6906 }
6907 }
6908
6909 if (getExtensions().clientArrays)
6910 {
6911 switch (pname)
6912 {
6913 case GL_CLIENT_ARRAYS_ANGLE:
6914 *type = GL_BOOL;
6915 *numParams = 1;
6916 return true;
6917 }
6918 }
6919
6920 if (getExtensions().sRGBWriteControl)
6921 {
6922 switch (pname)
6923 {
6924 case GL_FRAMEBUFFER_SRGB_EXT:
6925 *type = GL_BOOL;
6926 *numParams = 1;
6927 return true;
6928 }
6929 }
6930
6931 if (getExtensions().robustResourceInitialization &&
6932 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6933 {
6934 *type = GL_BOOL;
6935 *numParams = 1;
6936 return true;
6937 }
6938
6939 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6940 {
6941 *type = GL_BOOL;
6942 *numParams = 1;
6943 return true;
6944 }
6945
6946 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6947 switch (pname)
6948 {
6949 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6950 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6951 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6952 {
6953 return false;
6954 }
6955 *type = GL_INT;
6956 *numParams = 1;
6957 return true;
6958
6959 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6960 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6961 {
6962 return false;
6963 }
6964 *type = GL_INT;
6965 *numParams = 1;
6966 return true;
6967
6968 case GL_PROGRAM_BINARY_FORMATS_OES:
6969 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6970 {
6971 return false;
6972 }
6973 *type = GL_INT;
6974 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6975 return true;
6976
6977 case GL_PACK_ROW_LENGTH:
6978 case GL_PACK_SKIP_ROWS:
6979 case GL_PACK_SKIP_PIXELS:
6980 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6981 {
6982 return false;
6983 }
6984 *type = GL_INT;
6985 *numParams = 1;
6986 return true;
6987 case GL_UNPACK_ROW_LENGTH:
6988 case GL_UNPACK_SKIP_ROWS:
6989 case GL_UNPACK_SKIP_PIXELS:
6990 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = 1;
6996 return true;
6997 case GL_VERTEX_ARRAY_BINDING:
6998 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6999 {
7000 return false;
7001 }
7002 *type = GL_INT;
7003 *numParams = 1;
7004 return true;
7005 case GL_PIXEL_PACK_BUFFER_BINDING:
7006 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7007 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7008 {
7009 return false;
7010 }
7011 *type = GL_INT;
7012 *numParams = 1;
7013 return true;
7014 case GL_MAX_SAMPLES:
7015 {
7016 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7017 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7018 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7019 {
7020 return false;
7021 }
7022 *type = GL_INT;
7023 *numParams = 1;
7024 return true;
7025
7026 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7027 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7028 {
7029 return false;
7030 }
7031 *type = GL_INT;
7032 *numParams = 1;
7033 return true;
7034 }
7035 }
7036
7037 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7038 {
7039 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7040 {
7041 return false;
7042 }
7043 *type = GL_INT;
7044 *numParams = 1;
7045 return true;
7046 }
7047
7048 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7049 {
7050 *type = GL_INT;
7051 *numParams = 1;
7052 return true;
7053 }
7054
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007055 if (getClientVersion() < Version(2, 0))
7056 {
7057 switch (pname)
7058 {
7059 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007060 case GL_CLIENT_ACTIVE_TEXTURE:
7061 case GL_MATRIX_MODE:
7062 case GL_MAX_TEXTURE_UNITS:
7063 case GL_MAX_MODELVIEW_STACK_DEPTH:
7064 case GL_MAX_PROJECTION_STACK_DEPTH:
7065 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007066 case GL_MAX_LIGHTS:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007067 case GL_VERTEX_ARRAY_STRIDE:
7068 case GL_NORMAL_ARRAY_STRIDE:
7069 case GL_COLOR_ARRAY_STRIDE:
7070 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7071 case GL_VERTEX_ARRAY_SIZE:
7072 case GL_COLOR_ARRAY_SIZE:
7073 case GL_TEXTURE_COORD_ARRAY_SIZE:
7074 case GL_VERTEX_ARRAY_TYPE:
7075 case GL_NORMAL_ARRAY_TYPE:
7076 case GL_COLOR_ARRAY_TYPE:
7077 case GL_TEXTURE_COORD_ARRAY_TYPE:
7078 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7079 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7080 case GL_COLOR_ARRAY_BUFFER_BINDING:
7081 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7082 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7083 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7084 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007085 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007086 *type = GL_INT;
7087 *numParams = 1;
7088 return true;
7089 case GL_ALPHA_TEST_REF:
7090 *type = GL_FLOAT;
7091 *numParams = 1;
7092 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007093 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007094 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007095 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007096 *type = GL_FLOAT;
7097 *numParams = 4;
7098 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007099 case GL_CURRENT_NORMAL:
7100 *type = GL_FLOAT;
7101 *numParams = 3;
7102 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007103 case GL_MODELVIEW_MATRIX:
7104 case GL_PROJECTION_MATRIX:
7105 case GL_TEXTURE_MATRIX:
7106 *type = GL_FLOAT;
7107 *numParams = 16;
7108 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007109 case GL_LIGHT_MODEL_TWO_SIDE:
7110 *type = GL_BOOL;
7111 *numParams = 1;
7112 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007113 }
7114 }
7115
Jamie Madill5b772312018-03-08 20:28:32 -05007116 if (getClientVersion() < Version(3, 0))
7117 {
7118 return false;
7119 }
7120
7121 // Check for ES3.0+ parameter names
7122 switch (pname)
7123 {
7124 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7125 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7126 case GL_UNIFORM_BUFFER_BINDING:
7127 case GL_TRANSFORM_FEEDBACK_BINDING:
7128 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7129 case GL_COPY_READ_BUFFER_BINDING:
7130 case GL_COPY_WRITE_BUFFER_BINDING:
7131 case GL_SAMPLER_BINDING:
7132 case GL_READ_BUFFER:
7133 case GL_TEXTURE_BINDING_3D:
7134 case GL_TEXTURE_BINDING_2D_ARRAY:
7135 case GL_MAX_3D_TEXTURE_SIZE:
7136 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7137 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7138 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7139 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7140 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7141 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7142 case GL_MAX_VARYING_COMPONENTS:
7143 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7144 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7145 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7146 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7147 case GL_NUM_EXTENSIONS:
7148 case GL_MAJOR_VERSION:
7149 case GL_MINOR_VERSION:
7150 case GL_MAX_ELEMENTS_INDICES:
7151 case GL_MAX_ELEMENTS_VERTICES:
7152 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7153 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7154 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7155 case GL_UNPACK_IMAGE_HEIGHT:
7156 case GL_UNPACK_SKIP_IMAGES:
7157 {
7158 *type = GL_INT;
7159 *numParams = 1;
7160 return true;
7161 }
7162
7163 case GL_MAX_ELEMENT_INDEX:
7164 case GL_MAX_UNIFORM_BLOCK_SIZE:
7165 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7166 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7167 case GL_MAX_SERVER_WAIT_TIMEOUT:
7168 {
7169 *type = GL_INT_64_ANGLEX;
7170 *numParams = 1;
7171 return true;
7172 }
7173
7174 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7175 case GL_TRANSFORM_FEEDBACK_PAUSED:
7176 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7177 case GL_RASTERIZER_DISCARD:
7178 {
7179 *type = GL_BOOL;
7180 *numParams = 1;
7181 return true;
7182 }
7183
7184 case GL_MAX_TEXTURE_LOD_BIAS:
7185 {
7186 *type = GL_FLOAT;
7187 *numParams = 1;
7188 return true;
7189 }
7190 }
7191
7192 if (getExtensions().requestExtension)
7193 {
7194 switch (pname)
7195 {
7196 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7197 *type = GL_INT;
7198 *numParams = 1;
7199 return true;
7200 }
7201 }
7202
7203 if (getClientVersion() < Version(3, 1))
7204 {
7205 return false;
7206 }
7207
7208 switch (pname)
7209 {
7210 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7211 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7212 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7213 case GL_MAX_FRAMEBUFFER_WIDTH:
7214 case GL_MAX_FRAMEBUFFER_HEIGHT:
7215 case GL_MAX_FRAMEBUFFER_SAMPLES:
7216 case GL_MAX_SAMPLE_MASK_WORDS:
7217 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7218 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7219 case GL_MAX_INTEGER_SAMPLES:
7220 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7221 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7222 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7223 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7224 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7225 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7226 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7227 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7228 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7229 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7230 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7231 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7232 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7233 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7234 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7235 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7236 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7237 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7238 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7239 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7240 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7241 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7242 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7243 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7244 case GL_MAX_UNIFORM_LOCATIONS:
7245 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7246 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7247 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7248 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7249 case GL_MAX_IMAGE_UNITS:
7250 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7251 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7252 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7253 case GL_SHADER_STORAGE_BUFFER_BINDING:
7254 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7255 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7256 *type = GL_INT;
7257 *numParams = 1;
7258 return true;
7259 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7260 *type = GL_INT_64_ANGLEX;
7261 *numParams = 1;
7262 return true;
7263 case GL_SAMPLE_MASK:
7264 *type = GL_BOOL;
7265 *numParams = 1;
7266 return true;
7267 }
7268
7269 if (getExtensions().geometryShader)
7270 {
7271 switch (pname)
7272 {
7273 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7274 case GL_LAYER_PROVOKING_VERTEX_EXT:
7275 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7276 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7277 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7278 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7279 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7280 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7281 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7282 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7283 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7284 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7285 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7286 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7287 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7288 *type = GL_INT;
7289 *numParams = 1;
7290 return true;
7291 }
7292 }
7293
7294 return false;
7295}
7296
7297bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7298{
7299 if (getClientVersion() < Version(3, 0))
7300 {
7301 return false;
7302 }
7303
7304 switch (target)
7305 {
7306 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7307 case GL_UNIFORM_BUFFER_BINDING:
7308 {
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7314 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7315 case GL_UNIFORM_BUFFER_START:
7316 case GL_UNIFORM_BUFFER_SIZE:
7317 {
7318 *type = GL_INT_64_ANGLEX;
7319 *numParams = 1;
7320 return true;
7321 }
7322 }
7323
7324 if (getClientVersion() < Version(3, 1))
7325 {
7326 return false;
7327 }
7328
7329 switch (target)
7330 {
7331 case GL_IMAGE_BINDING_LAYERED:
7332 {
7333 *type = GL_BOOL;
7334 *numParams = 1;
7335 return true;
7336 }
7337 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7338 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7339 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7340 case GL_SHADER_STORAGE_BUFFER_BINDING:
7341 case GL_VERTEX_BINDING_BUFFER:
7342 case GL_VERTEX_BINDING_DIVISOR:
7343 case GL_VERTEX_BINDING_OFFSET:
7344 case GL_VERTEX_BINDING_STRIDE:
7345 case GL_SAMPLE_MASK_VALUE:
7346 case GL_IMAGE_BINDING_NAME:
7347 case GL_IMAGE_BINDING_LEVEL:
7348 case GL_IMAGE_BINDING_LAYER:
7349 case GL_IMAGE_BINDING_ACCESS:
7350 case GL_IMAGE_BINDING_FORMAT:
7351 {
7352 *type = GL_INT;
7353 *numParams = 1;
7354 return true;
7355 }
7356 case GL_ATOMIC_COUNTER_BUFFER_START:
7357 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7358 case GL_SHADER_STORAGE_BUFFER_START:
7359 case GL_SHADER_STORAGE_BUFFER_SIZE:
7360 {
7361 *type = GL_INT_64_ANGLEX;
7362 *numParams = 1;
7363 return true;
7364 }
7365 }
7366
7367 return false;
7368}
7369
7370Program *Context::getProgram(GLuint handle) const
7371{
7372 return mState.mShaderPrograms->getProgram(handle);
7373}
7374
7375Shader *Context::getShader(GLuint handle) const
7376{
7377 return mState.mShaderPrograms->getShader(handle);
7378}
7379
7380bool Context::isTextureGenerated(GLuint texture) const
7381{
7382 return mState.mTextures->isHandleGenerated(texture);
7383}
7384
7385bool Context::isBufferGenerated(GLuint buffer) const
7386{
7387 return mState.mBuffers->isHandleGenerated(buffer);
7388}
7389
7390bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7391{
7392 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7393}
7394
7395bool Context::isFramebufferGenerated(GLuint framebuffer) const
7396{
7397 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7398}
7399
7400bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7401{
7402 return mState.mPipelines->isHandleGenerated(pipeline);
7403}
7404
7405bool Context::usingDisplayTextureShareGroup() const
7406{
7407 return mDisplayTextureShareGroup;
7408}
7409
7410GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7411{
7412 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7413 internalformat == GL_DEPTH_STENCIL
7414 ? GL_DEPTH24_STENCIL8
7415 : internalformat;
7416}
7417
Jamie Madillc29968b2016-01-20 11:17:23 -05007418} // namespace gl