blob: 8eb6d9d320e795220c51bcc713640fb03952747d [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(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400284 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mClientType(EGL_OPENGL_ES_API),
286 mHasBeenCurrent(false),
287 mContextLost(false),
288 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700289 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mResetStrategy(GetResetStrategy(attribs)),
291 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400292 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
293 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500294 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500295 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400296 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400297 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400298 mScratchBuffer(1000u),
299 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000300{
Jamie Madill5b772312018-03-08 20:28:32 -0500301 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400302 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
303 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500304
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400305 mImplementation->setMemoryProgramCache(memoryProgramCache);
306
Geoff Langb433e872017-10-05 14:01:47 -0400307 bool robustResourceInit = GetRobustResourceInit(attribs);
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700308 initCaps(displayExtensions, clientExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700309 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400310
Jamie Madill4928b7c2017-06-20 12:57:39 -0400311 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400312 GetClientArraysEnabled(attribs), robustResourceInit,
313 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100314
Shannon Woods53a94a82014-06-24 15:20:36 -0400315 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400316
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400318 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000319 // and cube map texture state vectors respectively associated with them.
320 // In order that access to these initial textures not be lost, they are treated as texture
321 // objects all of whose names are 0.
322
Corentin Wallez99d492c2018-02-27 15:17:10 -0500323 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800324 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500325
Corentin Wallez99d492c2018-02-27 15:17:10 -0500326 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800327 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400328
Geoff Langeb66a6e2016-10-31 13:06:12 -0400329 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400330 {
331 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500332 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800333 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400334
Corentin Wallez99d492c2018-02-27 15:17:10 -0500335 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800336 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 }
Geoff Lang3b573612016-10-31 14:08:10 -0400338 if (getClientVersion() >= Version(3, 1))
339 {
340 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500341 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800342 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343
Jiajia Qin6eafb042016-12-27 17:04:07 +0800344 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
345 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800346 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800347 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800349 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
350 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400351 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800352 }
Geoff Lang3b573612016-10-31 14:08:10 -0400353 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000354
Geoff Langb0f917f2017-12-05 13:41:54 -0500355 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400356 {
357 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500358 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800359 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400360 }
361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400363 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500364 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800365 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400366 }
367
Jamie Madill4928b7c2017-06-20 12:57:39 -0400368 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500369
Jamie Madill57a89722013-07-02 11:57:03 -0400370 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000371
Geoff Langeb66a6e2016-10-31 13:06:12 -0400372 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400373 {
374 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
375 // In the initial state, a default transform feedback object is bound and treated as
376 // a transform feedback object with a name of zero. That object is bound any time
377 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400378 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400379 }
Geoff Langc8058452014-02-03 12:04:11 -0500380
Corentin Wallez336129f2017-10-17 15:55:40 -0400381 for (auto type : angle::AllEnums<BufferBinding>())
382 {
383 bindBuffer(type, 0);
384 }
385
386 bindRenderbuffer(GL_RENDERBUFFER, 0);
387
388 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
389 {
390 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
391 }
392
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700393 // Initialize GLES1 renderer if appropriate.
394 if (getClientVersion() < Version(2, 0))
395 {
396 mGLES1Renderer.reset(new GLES1Renderer());
397 }
398
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500401 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500402 // No dirty objects.
403
404 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500407 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
408
409 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
411 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
412 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
416 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
419 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
420 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
421
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
423 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700424 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400427
Xinghua Cao10a4d432017-11-28 14:46:26 +0800428 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
429 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
431 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
432 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
433 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800434 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800435 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800436
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400437 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438}
439
Jamie Madill4928b7c2017-06-20 12:57:39 -0400440egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700442 if (mGLES1Renderer)
443 {
444 mGLES1Renderer->onDestroy(this, &mGLState);
445 }
446
Jamie Madille7b3fe22018-04-05 09:42:46 -0400447 // Delete the Surface first to trigger a finish() in Vulkan.
Geoff Lang61107632018-05-09 11:32:46 -0400448 if (mSurfacelessFramebuffer)
449 {
450 mSurfacelessFramebuffer->onDestroy(this);
451 SafeDelete(mSurfacelessFramebuffer);
452 }
Jamie Madille7b3fe22018-04-05 09:42:46 -0400453
454 ANGLE_TRY(releaseSurface(display));
455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400460 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461
Corentin Wallez80b24112015-08-25 16:41:57 -0400462 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400464 if (query.second != nullptr)
465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400469 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000470
Corentin Wallez80b24112015-08-25 16:41:57 -0400471 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400472 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 if (vertexArray.second)
474 {
475 vertexArray.second->onDestroy(this);
476 }
Jamie Madill57a89722013-07-02 11:57:03 -0400477 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400478 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400479
Corentin Wallez80b24112015-08-25 16:41:57 -0400480 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500481 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500482 if (transformFeedback.second != nullptr)
483 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500484 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500485 }
Geoff Langc8058452014-02-03 12:04:11 -0500486 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400487 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500488
Jamie Madill5b772312018-03-08 20:28:32 -0500489 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400490 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800491 if (zeroTexture.get() != nullptr)
492 {
493 ANGLE_TRY(zeroTexture->onDestroy(this));
494 zeroTexture.set(this, nullptr);
495 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400496 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497
Jamie Madill2f348d22017-06-05 10:50:59 -0400498 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500 mGLState.reset(this);
501
Jamie Madill6c1f6712017-02-14 19:08:04 -0500502 mState.mBuffers->release(this);
503 mState.mShaderPrograms->release(this);
504 mState.mTextures->release(this);
505 mState.mRenderbuffers->release(this);
506 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400507 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500508 mState.mPaths->release(this);
509 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800510 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511
Jamie Madill76e471e2017-10-21 09:56:01 -0400512 mImplementation->onDestroy(this);
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517Context::~Context()
518{
519}
520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522{
Jamie Madill61e16b42017-06-19 11:13:23 -0400523 mCurrentDisplay = display;
524
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 if (!mHasBeenCurrent)
526 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000527 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500528 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400529 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallezc295e512017-01-27 17:47:50 -0500531 int width = 0;
532 int height = 0;
533 if (surface != nullptr)
534 {
535 width = surface->getWidth();
536 height = surface->getHeight();
537 }
538
539 mGLState.setViewportParams(0, 0, width, height);
540 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541
542 mHasBeenCurrent = true;
543 }
544
Jamie Madill1b94d432015-08-07 13:23:23 -0400545 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400547 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400548
Jamie Madill4928b7c2017-06-20 12:57:39 -0400549 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500550
551 Framebuffer *newDefault = nullptr;
552 if (surface != nullptr)
553 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400554 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500555 mCurrentSurface = surface;
556 newDefault = surface->getDefaultFramebuffer();
557 }
558 else
559 {
560 if (mSurfacelessFramebuffer == nullptr)
561 {
562 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
563 }
564
565 newDefault = mSurfacelessFramebuffer;
566 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000567
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Update default framebuffer, the binding of the previous default
569 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400570 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700571 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700573 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400574 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700575 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400576 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700577 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400578 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500579 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400580 }
Ian Ewell292f0052016-02-04 10:37:32 -0500581
582 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583 mImplementation->onMakeCurrent(this);
584 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585}
586
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400588{
Corentin Wallez37c39792015-08-20 14:19:46 -0400589 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500590 Framebuffer *currentDefault = nullptr;
591 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400592 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500593 currentDefault = mCurrentSurface->getDefaultFramebuffer();
594 }
595 else if (mSurfacelessFramebuffer != nullptr)
596 {
597 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400598 }
599
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 if (mGLState.getReadFramebuffer() == currentDefault)
601 {
602 mGLState.setReadFramebufferBinding(nullptr);
603 }
604 if (mGLState.getDrawFramebuffer() == currentDefault)
605 {
606 mGLState.setDrawFramebufferBinding(nullptr);
607 }
608 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
609
610 if (mCurrentSurface)
611 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500613 mCurrentSurface = nullptr;
614 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400615
616 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400617}
618
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619GLuint Context::createBuffer()
620{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500621 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622}
623
624GLuint Context::createProgram()
625{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500626 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627}
628
Jiawei Shao385b3e02018-03-21 09:43:28 +0800629GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500631 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632}
633
634GLuint Context::createTexture()
635{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500636 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
639GLuint Context::createRenderbuffer()
640{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500641 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Brandon Jones59770802018-04-02 13:18:42 -0700644GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300645{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500646 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300647 if (resultOrError.isError())
648 {
649 handleError(resultOrError.getError());
650 return 0;
651 }
652 return resultOrError.getResult();
653}
654
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655// Returns an unused framebuffer name
656GLuint Context::createFramebuffer()
657{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500658 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500661void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500663 for (int i = 0; i < n; i++)
664 {
665 GLuint handle = mFenceNVHandleAllocator.allocate();
666 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
667 fences[i] = handle;
668 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
Yunchao Hea336b902017-08-02 16:05:21 +0800671GLuint Context::createProgramPipeline()
672{
673 return mState.mPipelines->createProgramPipeline();
674}
675
Jiawei Shao385b3e02018-03-21 09:43:28 +0800676GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800677{
678 UNIMPLEMENTED();
679 return 0u;
680}
681
James Darpinian4d9d4832018-03-13 12:43:28 -0700682void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683{
James Darpinian4d9d4832018-03-13 12:43:28 -0700684 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
685 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000686 {
687 detachBuffer(buffer);
688 }
Jamie Madill893ab082014-05-16 16:56:10 -0400689
James Darpinian4d9d4832018-03-13 12:43:28 -0700690 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000691}
692
693void Context::deleteShader(GLuint shader)
694{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500695 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696}
697
698void Context::deleteProgram(GLuint program)
699{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500700 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000701}
702
703void Context::deleteTexture(GLuint texture)
704{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500705 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000706 {
707 detachTexture(texture);
708 }
709
Jamie Madill6c1f6712017-02-14 19:08:04 -0500710 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
713void Context::deleteRenderbuffer(GLuint renderbuffer)
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716 {
717 detachRenderbuffer(renderbuffer);
718 }
Jamie Madill893ab082014-05-16 16:56:10 -0400719
Jamie Madill6c1f6712017-02-14 19:08:04 -0500720 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400723void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400724{
725 // The spec specifies the underlying Fence object is not deleted until all current
726 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
727 // and since our API is currently designed for being called from a single thread, we can delete
728 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400729 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400730}
731
Yunchao Hea336b902017-08-02 16:05:21 +0800732void Context::deleteProgramPipeline(GLuint pipeline)
733{
734 if (mState.mPipelines->getProgramPipeline(pipeline))
735 {
736 detachProgramPipeline(pipeline);
737 }
738
739 mState.mPipelines->deleteObject(this, pipeline);
740}
741
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742void Context::deletePaths(GLuint first, GLsizei range)
743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745}
746
Brandon Jones59770802018-04-02 13:18:42 -0700747bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500749 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750 if (pathObj == nullptr)
751 return false;
752
753 return pathObj->hasPathData();
754}
755
Brandon Jones59770802018-04-02 13:18:42 -0700756bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759}
760
Brandon Jones59770802018-04-02 13:18:42 -0700761void Context::pathCommands(GLuint path,
762 GLsizei numCommands,
763 const GLubyte *commands,
764 GLsizei numCoords,
765 GLenum coordType,
766 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300767{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500768 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300769
770 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
771}
772
Jamie Madill007530e2017-12-28 14:27:04 -0500773void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Jamie Madill007530e2017-12-28 14:27:04 -0500775 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300776
777 switch (pname)
778 {
779 case GL_PATH_STROKE_WIDTH_CHROMIUM:
780 pathObj->setStrokeWidth(value);
781 break;
782 case GL_PATH_END_CAPS_CHROMIUM:
783 pathObj->setEndCaps(static_cast<GLenum>(value));
784 break;
785 case GL_PATH_JOIN_STYLE_CHROMIUM:
786 pathObj->setJoinStyle(static_cast<GLenum>(value));
787 break;
788 case GL_PATH_MITER_LIMIT_CHROMIUM:
789 pathObj->setMiterLimit(value);
790 break;
791 case GL_PATH_STROKE_BOUND_CHROMIUM:
792 pathObj->setStrokeBound(value);
793 break;
794 default:
795 UNREACHABLE();
796 break;
797 }
798}
799
Jamie Madill007530e2017-12-28 14:27:04 -0500800void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801{
Jamie Madill007530e2017-12-28 14:27:04 -0500802 // TODO(jmadill): Should use proper clamping/casting.
803 pathParameterf(path, pname, static_cast<GLfloat>(value));
804}
805
806void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
807{
808 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300809
810 switch (pname)
811 {
812 case GL_PATH_STROKE_WIDTH_CHROMIUM:
813 *value = pathObj->getStrokeWidth();
814 break;
815 case GL_PATH_END_CAPS_CHROMIUM:
816 *value = static_cast<GLfloat>(pathObj->getEndCaps());
817 break;
818 case GL_PATH_JOIN_STYLE_CHROMIUM:
819 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
820 break;
821 case GL_PATH_MITER_LIMIT_CHROMIUM:
822 *value = pathObj->getMiterLimit();
823 break;
824 case GL_PATH_STROKE_BOUND_CHROMIUM:
825 *value = pathObj->getStrokeBound();
826 break;
827 default:
828 UNREACHABLE();
829 break;
830 }
831}
832
Jamie Madill007530e2017-12-28 14:27:04 -0500833void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
834{
835 GLfloat val = 0.0f;
836 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
837 if (value)
838 *value = static_cast<GLint>(val);
839}
840
Brandon Jones59770802018-04-02 13:18:42 -0700841void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842{
843 mGLState.setPathStencilFunc(func, ref, mask);
844}
845
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846void Context::deleteFramebuffer(GLuint framebuffer)
847{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500848 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849 {
850 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500852
Jamie Madill6c1f6712017-02-14 19:08:04 -0500853 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854}
855
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500856void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500858 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500860 GLuint fence = fences[i];
861
862 FenceNV *fenceObject = nullptr;
863 if (mFenceNVMap.erase(fence, &fenceObject))
864 {
865 mFenceNVHandleAllocator.release(fence);
866 delete fenceObject;
867 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868 }
869}
870
Geoff Lang70d0f492015-12-10 17:45:46 -0500871Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500873 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874}
875
Jamie Madill570f7c82014-07-03 10:38:54 -0400876Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000877{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500878 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879}
880
Geoff Lang70d0f492015-12-10 17:45:46 -0500881Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000882{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500883 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884}
885
Jamie Madill70b5bb02017-08-28 13:32:37 -0400886Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400887{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400888 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400889}
890
Jamie Madill57a89722013-07-02 11:57:03 -0400891VertexArray *Context::getVertexArray(GLuint handle) const
892{
Jamie Madill96a483b2017-06-27 16:49:21 -0400893 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400894}
895
Jamie Madilldc356042013-07-19 16:36:57 -0400896Sampler *Context::getSampler(GLuint handle) const
897{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500898 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400899}
900
Geoff Langc8058452014-02-03 12:04:11 -0500901TransformFeedback *Context::getTransformFeedback(GLuint handle) const
902{
Jamie Madill96a483b2017-06-27 16:49:21 -0400903 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500904}
905
Yunchao Hea336b902017-08-02 16:05:21 +0800906ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
907{
908 return mState.mPipelines->getProgramPipeline(handle);
909}
910
Geoff Lang70d0f492015-12-10 17:45:46 -0500911LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
912{
913 switch (identifier)
914 {
915 case GL_BUFFER:
916 return getBuffer(name);
917 case GL_SHADER:
918 return getShader(name);
919 case GL_PROGRAM:
920 return getProgram(name);
921 case GL_VERTEX_ARRAY:
922 return getVertexArray(name);
923 case GL_QUERY:
924 return getQuery(name);
925 case GL_TRANSFORM_FEEDBACK:
926 return getTransformFeedback(name);
927 case GL_SAMPLER:
928 return getSampler(name);
929 case GL_TEXTURE:
930 return getTexture(name);
931 case GL_RENDERBUFFER:
932 return getRenderbuffer(name);
933 case GL_FRAMEBUFFER:
934 return getFramebuffer(name);
935 default:
936 UNREACHABLE();
937 return nullptr;
938 }
939}
940
941LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
942{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400943 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500944}
945
Martin Radev9d901792016-07-15 15:58:58 +0300946void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
947{
948 LabeledObject *object = getLabeledObject(identifier, name);
949 ASSERT(object != nullptr);
950
951 std::string labelName = GetObjectLabelFromPointer(length, label);
952 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400953
954 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
955 // specified object is active until we do this.
956 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300957}
958
959void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
960{
961 LabeledObject *object = getLabeledObjectFromPtr(ptr);
962 ASSERT(object != nullptr);
963
964 std::string labelName = GetObjectLabelFromPointer(length, label);
965 object->setLabel(labelName);
966}
967
968void Context::getObjectLabel(GLenum identifier,
969 GLuint name,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObject(identifier, name);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
981void Context::getObjectPtrLabel(const void *ptr,
982 GLsizei bufSize,
983 GLsizei *length,
984 GLchar *label) const
985{
986 LabeledObject *object = getLabeledObjectFromPtr(ptr);
987 ASSERT(object != nullptr);
988
989 const std::string &objectLabel = object->getLabel();
990 GetObjectLabelBase(objectLabel, bufSize, length, label);
991}
992
Jamie Madilldc356042013-07-19 16:36:57 -0400993bool Context::isSampler(GLuint samplerName) const
994{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500995 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400996}
997
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800998void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001
Jamie Madilldedd7b92014-11-05 16:30:36 -05001002 if (handle == 0)
1003 {
1004 texture = mZeroTextures[target].get();
1005 }
1006 else
1007 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001008 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009 }
1010
1011 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001013}
1014
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001015void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001017 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1018 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001019 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001020}
1021
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001022void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001024 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1025 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001026 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027}
1028
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001029void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001030{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001032 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001033}
1034
Shao80957d92017-02-20 21:25:59 +08001035void Context::bindVertexBuffer(GLuint bindingIndex,
1036 GLuint bufferHandle,
1037 GLintptr offset,
1038 GLsizei stride)
1039{
1040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001041 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001045{
Geoff Lang76b10c92014-09-05 16:28:14 -04001046 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001047 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001048 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001049 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001050}
1051
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001052void Context::bindImageTexture(GLuint unit,
1053 GLuint texture,
1054 GLint level,
1055 GLboolean layered,
1056 GLint layer,
1057 GLenum access,
1058 GLenum format)
1059{
1060 Texture *tex = mState.mTextures->getTexture(texture);
1061 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1062}
1063
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064void Context::useProgram(GLuint program)
1065{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001066 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001067}
1068
Jiajia Qin5451d532017-11-16 17:16:34 +08001069void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1070{
1071 UNIMPLEMENTED();
1072}
1073
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001074void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001075{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001076 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001077 TransformFeedback *transformFeedback =
1078 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001079 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001080}
1081
Yunchao Hea336b902017-08-02 16:05:21 +08001082void Context::bindProgramPipeline(GLuint pipelineHandle)
1083{
1084 ProgramPipeline *pipeline =
1085 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1086 mGLState.setProgramPipelineBinding(this, pipeline);
1087}
1088
Corentin Wallezad3ae902018-03-09 13:40:42 -05001089void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001092 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093
Geoff Lang5aad9672014-09-08 11:10:42 -04001094 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001095 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001096
1097 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001099}
1100
Corentin Wallezad3ae902018-03-09 13:40:42 -05001101void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001103 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001104 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001107
Geoff Lang5aad9672014-09-08 11:10:42 -04001108 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Corentin Wallezad3ae902018-03-09 13:40:42 -05001112void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001113{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001114 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115
1116 Query *queryObject = getQuery(id, true, target);
1117 ASSERT(queryObject);
1118
Jamie Madillf0e04492017-08-26 15:28:42 -04001119 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120}
1121
Corentin Wallezad3ae902018-03-09 13:40:42 -05001122void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123{
1124 switch (pname)
1125 {
1126 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001128 break;
1129 case GL_QUERY_COUNTER_BITS_EXT:
1130 switch (target)
1131 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001132 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001133 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1134 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001135 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001136 params[0] = getExtensions().queryCounterBitsTimestamp;
1137 break;
1138 default:
1139 UNREACHABLE();
1140 params[0] = 0;
1141 break;
1142 }
1143 break;
1144 default:
1145 UNREACHABLE();
1146 return;
1147 }
1148}
1149
Corentin Wallezad3ae902018-03-09 13:40:42 -05001150void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001151 GLenum pname,
1152 GLsizei bufSize,
1153 GLsizei *length,
1154 GLint *params)
1155{
1156 getQueryiv(target, pname, params);
1157}
1158
Geoff Lang2186c382016-10-14 10:54:54 -04001159void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160{
Geoff Lang2186c382016-10-14 10:54:54 -04001161 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001162}
1163
Brandon Jones59770802018-04-02 13:18:42 -07001164void Context::getQueryObjectivRobust(GLuint id,
1165 GLenum pname,
1166 GLsizei bufSize,
1167 GLsizei *length,
1168 GLint *params)
1169{
1170 getQueryObjectiv(id, pname, params);
1171}
1172
Geoff Lang2186c382016-10-14 10:54:54 -04001173void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174{
Geoff Lang2186c382016-10-14 10:54:54 -04001175 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176}
1177
Brandon Jones59770802018-04-02 13:18:42 -07001178void Context::getQueryObjectuivRobust(GLuint id,
1179 GLenum pname,
1180 GLsizei bufSize,
1181 GLsizei *length,
1182 GLuint *params)
1183{
1184 getQueryObjectuiv(id, pname, params);
1185}
1186
Geoff Lang2186c382016-10-14 10:54:54 -04001187void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188{
Geoff Lang2186c382016-10-14 10:54:54 -04001189 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190}
1191
Brandon Jones59770802018-04-02 13:18:42 -07001192void Context::getQueryObjecti64vRobust(GLuint id,
1193 GLenum pname,
1194 GLsizei bufSize,
1195 GLsizei *length,
1196 GLint64 *params)
1197{
1198 getQueryObjecti64v(id, pname, params);
1199}
1200
Geoff Lang2186c382016-10-14 10:54:54 -04001201void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202{
Geoff Lang2186c382016-10-14 10:54:54 -04001203 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204}
1205
Brandon Jones59770802018-04-02 13:18:42 -07001206void Context::getQueryObjectui64vRobust(GLuint id,
1207 GLenum pname,
1208 GLsizei bufSize,
1209 GLsizei *length,
1210 GLuint64 *params)
1211{
1212 getQueryObjectui64v(id, pname, params);
1213}
1214
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001215Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001217 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218}
1219
Jamie Madill2f348d22017-06-05 10:50:59 -04001220FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221{
Jamie Madill96a483b2017-06-27 16:49:21 -04001222 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223}
1224
Corentin Wallezad3ae902018-03-09 13:40:42 -05001225Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226{
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001229 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001231
1232 Query *query = mQueryMap.query(handle);
1233 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001234 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 query = new Query(mImplementation->createQuery(type), handle);
1237 query->addRef();
1238 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001240 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241}
1242
Geoff Lang70d0f492015-12-10 17:45:46 -05001243Query *Context::getQuery(GLuint handle) const
1244{
Jamie Madill96a483b2017-06-27 16:49:21 -04001245 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001246}
1247
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001249{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001250 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1251 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001252}
1253
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001254Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001256 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257}
1258
Geoff Lang492a7e42014-11-05 13:27:06 -05001259Compiler *Context::getCompiler() const
1260{
Jamie Madill2f348d22017-06-05 10:50:59 -04001261 if (mCompiler.get() == nullptr)
1262 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001263 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001264 }
1265 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001266}
1267
Jamie Madillc1d770e2017-04-13 17:31:24 -04001268void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
1270 switch (pname)
1271 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001272 case GL_SHADER_COMPILER:
1273 *params = GL_TRUE;
1274 break;
1275 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1276 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1277 break;
1278 default:
1279 mGLState.getBooleanv(pname, params);
1280 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282}
1283
Jamie Madillc1d770e2017-04-13 17:31:24 -04001284void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285{
Shannon Woods53a94a82014-06-24 15:20:36 -04001286 // Queries about context capabilities and maximums are answered by Context.
1287 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 switch (pname)
1289 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001290 case GL_ALIASED_LINE_WIDTH_RANGE:
1291 params[0] = mCaps.minAliasedLineWidth;
1292 params[1] = mCaps.maxAliasedLineWidth;
1293 break;
1294 case GL_ALIASED_POINT_SIZE_RANGE:
1295 params[0] = mCaps.minAliasedPointSize;
1296 params[1] = mCaps.maxAliasedPointSize;
1297 break;
1298 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1299 ASSERT(mExtensions.textureFilterAnisotropic);
1300 *params = mExtensions.maxTextureAnisotropy;
1301 break;
1302 case GL_MAX_TEXTURE_LOD_BIAS:
1303 *params = mCaps.maxLODBias;
1304 break;
1305
1306 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1307 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1308 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001309 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1310 // GLES1 constants for modelview/projection matrix.
1311 if (getClientVersion() < Version(2, 0))
1312 {
1313 mGLState.getFloatv(pname, params);
1314 }
1315 else
1316 {
1317 ASSERT(mExtensions.pathRendering);
1318 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1319 memcpy(params, m, 16 * sizeof(GLfloat));
1320 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001321 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001322 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001323
Jamie Madill231c7f52017-04-26 13:45:37 -04001324 default:
1325 mGLState.getFloatv(pname, params);
1326 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Jamie Madillc1d770e2017-04-13 17:31:24 -04001330void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
Shannon Woods53a94a82014-06-24 15:20:36 -04001332 // Queries about context capabilities and maximums are answered by Context.
1333 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001334
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 switch (pname)
1336 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001337 case GL_MAX_VERTEX_ATTRIBS:
1338 *params = mCaps.maxVertexAttributes;
1339 break;
1340 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1341 *params = mCaps.maxVertexUniformVectors;
1342 break;
1343 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001344 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001345 break;
1346 case GL_MAX_VARYING_VECTORS:
1347 *params = mCaps.maxVaryingVectors;
1348 break;
1349 case GL_MAX_VARYING_COMPONENTS:
1350 *params = mCaps.maxVertexOutputComponents;
1351 break;
1352 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1353 *params = mCaps.maxCombinedTextureImageUnits;
1354 break;
1355 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001356 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001359 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
1361 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1362 *params = mCaps.maxFragmentUniformVectors;
1363 break;
1364 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001365 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001366 break;
1367 case GL_MAX_RENDERBUFFER_SIZE:
1368 *params = mCaps.maxRenderbufferSize;
1369 break;
1370 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1371 *params = mCaps.maxColorAttachments;
1372 break;
1373 case GL_MAX_DRAW_BUFFERS_EXT:
1374 *params = mCaps.maxDrawBuffers;
1375 break;
1376 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1377 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1378 case GL_SUBPIXEL_BITS:
1379 *params = 4;
1380 break;
1381 case GL_MAX_TEXTURE_SIZE:
1382 *params = mCaps.max2DTextureSize;
1383 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001384 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1385 *params = mCaps.maxRectangleTextureSize;
1386 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1388 *params = mCaps.maxCubeMapTextureSize;
1389 break;
1390 case GL_MAX_3D_TEXTURE_SIZE:
1391 *params = mCaps.max3DTextureSize;
1392 break;
1393 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1394 *params = mCaps.maxArrayTextureLayers;
1395 break;
1396 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1397 *params = mCaps.uniformBufferOffsetAlignment;
1398 break;
1399 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1400 *params = mCaps.maxUniformBufferBindings;
1401 break;
1402 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001403 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001404 break;
1405 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001406 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 break;
1408 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1409 *params = mCaps.maxCombinedTextureImageUnits;
1410 break;
1411 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1412 *params = mCaps.maxVertexOutputComponents;
1413 break;
1414 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1415 *params = mCaps.maxFragmentInputComponents;
1416 break;
1417 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1418 *params = mCaps.minProgramTexelOffset;
1419 break;
1420 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1421 *params = mCaps.maxProgramTexelOffset;
1422 break;
1423 case GL_MAJOR_VERSION:
1424 *params = getClientVersion().major;
1425 break;
1426 case GL_MINOR_VERSION:
1427 *params = getClientVersion().minor;
1428 break;
1429 case GL_MAX_ELEMENTS_INDICES:
1430 *params = mCaps.maxElementsIndices;
1431 break;
1432 case GL_MAX_ELEMENTS_VERTICES:
1433 *params = mCaps.maxElementsVertices;
1434 break;
1435 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1436 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1437 break;
1438 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1439 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1440 break;
1441 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1442 *params = mCaps.maxTransformFeedbackSeparateComponents;
1443 break;
1444 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1445 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1446 break;
1447 case GL_MAX_SAMPLES_ANGLE:
1448 *params = mCaps.maxSamples;
1449 break;
1450 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001451 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001452 params[0] = mCaps.maxViewportWidth;
1453 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001454 }
1455 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 case GL_COMPRESSED_TEXTURE_FORMATS:
1457 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1458 params);
1459 break;
1460 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1461 *params = mResetStrategy;
1462 break;
1463 case GL_NUM_SHADER_BINARY_FORMATS:
1464 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1465 break;
1466 case GL_SHADER_BINARY_FORMATS:
1467 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1468 break;
1469 case GL_NUM_PROGRAM_BINARY_FORMATS:
1470 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1471 break;
1472 case GL_PROGRAM_BINARY_FORMATS:
1473 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1474 break;
1475 case GL_NUM_EXTENSIONS:
1476 *params = static_cast<GLint>(mExtensionStrings.size());
1477 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001478
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 // GL_KHR_debug
1480 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1481 *params = mExtensions.maxDebugMessageLength;
1482 break;
1483 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1484 *params = mExtensions.maxDebugLoggedMessages;
1485 break;
1486 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1487 *params = mExtensions.maxDebugGroupStackDepth;
1488 break;
1489 case GL_MAX_LABEL_LENGTH:
1490 *params = mExtensions.maxLabelLength;
1491 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001492
Martin Radeve5285d22017-07-14 16:23:53 +03001493 // GL_ANGLE_multiview
1494 case GL_MAX_VIEWS_ANGLE:
1495 *params = mExtensions.maxViews;
1496 break;
1497
Jamie Madill231c7f52017-04-26 13:45:37 -04001498 // GL_EXT_disjoint_timer_query
1499 case GL_GPU_DISJOINT_EXT:
1500 *params = mImplementation->getGPUDisjoint();
1501 break;
1502 case GL_MAX_FRAMEBUFFER_WIDTH:
1503 *params = mCaps.maxFramebufferWidth;
1504 break;
1505 case GL_MAX_FRAMEBUFFER_HEIGHT:
1506 *params = mCaps.maxFramebufferHeight;
1507 break;
1508 case GL_MAX_FRAMEBUFFER_SAMPLES:
1509 *params = mCaps.maxFramebufferSamples;
1510 break;
1511 case GL_MAX_SAMPLE_MASK_WORDS:
1512 *params = mCaps.maxSampleMaskWords;
1513 break;
1514 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1515 *params = mCaps.maxColorTextureSamples;
1516 break;
1517 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1518 *params = mCaps.maxDepthTextureSamples;
1519 break;
1520 case GL_MAX_INTEGER_SAMPLES:
1521 *params = mCaps.maxIntegerSamples;
1522 break;
1523 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1524 *params = mCaps.maxVertexAttribRelativeOffset;
1525 break;
1526 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1527 *params = mCaps.maxVertexAttribBindings;
1528 break;
1529 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1530 *params = mCaps.maxVertexAttribStride;
1531 break;
1532 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001533 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001536 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001537 break;
1538 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001539 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001540 break;
1541 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001542 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001545 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001546 break;
1547 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001548 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001549 break;
1550 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001551 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001552 break;
1553 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001554 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1557 *params = mCaps.minProgramTextureGatherOffset;
1558 break;
1559 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1560 *params = mCaps.maxProgramTextureGatherOffset;
1561 break;
1562 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1563 *params = mCaps.maxComputeWorkGroupInvocations;
1564 break;
1565 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001566 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001569 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1572 *params = mCaps.maxComputeSharedMemorySize;
1573 break;
1574 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001575 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001576 break;
1577 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001578 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001579 break;
1580 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001581 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001582 break;
1583 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001584 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001587 *params =
1588 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 break;
1590 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001591 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 break;
1593 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1594 *params = mCaps.maxCombinedShaderOutputResources;
1595 break;
1596 case GL_MAX_UNIFORM_LOCATIONS:
1597 *params = mCaps.maxUniformLocations;
1598 break;
1599 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1600 *params = mCaps.maxAtomicCounterBufferBindings;
1601 break;
1602 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1603 *params = mCaps.maxAtomicCounterBufferSize;
1604 break;
1605 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1606 *params = mCaps.maxCombinedAtomicCounterBuffers;
1607 break;
1608 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1609 *params = mCaps.maxCombinedAtomicCounters;
1610 break;
1611 case GL_MAX_IMAGE_UNITS:
1612 *params = mCaps.maxImageUnits;
1613 break;
1614 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1615 *params = mCaps.maxCombinedImageUniforms;
1616 break;
1617 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1618 *params = mCaps.maxShaderStorageBufferBindings;
1619 break;
1620 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1621 *params = mCaps.maxCombinedShaderStorageBlocks;
1622 break;
1623 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1624 *params = mCaps.shaderStorageBufferOffsetAlignment;
1625 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001626
1627 // GL_EXT_geometry_shader
1628 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1629 *params = mCaps.maxFramebufferLayers;
1630 break;
1631 case GL_LAYER_PROVOKING_VERTEX_EXT:
1632 *params = mCaps.layerProvokingVertex;
1633 break;
1634 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001635 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001636 break;
1637 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001638 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001639 break;
1640 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001641 *params =
1642 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001643 break;
1644 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1645 *params = mCaps.maxGeometryInputComponents;
1646 break;
1647 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1648 *params = mCaps.maxGeometryOutputComponents;
1649 break;
1650 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1651 *params = mCaps.maxGeometryOutputVertices;
1652 break;
1653 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1654 *params = mCaps.maxGeometryTotalOutputComponents;
1655 break;
1656 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1657 *params = mCaps.maxGeometryShaderInvocations;
1658 break;
1659 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001660 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001661 break;
1662 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001664 break;
1665 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001667 break;
1668 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001669 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001670 break;
1671 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001672 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001673 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001674 // GLES1 emulation: Caps queries
1675 case GL_MAX_TEXTURE_UNITS:
1676 *params = mCaps.maxMultitextureUnits;
1677 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001678 case GL_MAX_MODELVIEW_STACK_DEPTH:
1679 *params = mCaps.maxModelviewMatrixStackDepth;
1680 break;
1681 case GL_MAX_PROJECTION_STACK_DEPTH:
1682 *params = mCaps.maxProjectionMatrixStackDepth;
1683 break;
1684 case GL_MAX_TEXTURE_STACK_DEPTH:
1685 *params = mCaps.maxTextureMatrixStackDepth;
1686 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001687 case GL_MAX_LIGHTS:
1688 *params = mCaps.maxLights;
1689 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001690 // GLES1 emulation: Vertex attribute queries
1691 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1692 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1693 case GL_COLOR_ARRAY_BUFFER_BINDING:
1694 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1695 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1696 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1697 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1698 break;
1699 case GL_VERTEX_ARRAY_STRIDE:
1700 case GL_NORMAL_ARRAY_STRIDE:
1701 case GL_COLOR_ARRAY_STRIDE:
1702 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1703 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1704 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1705 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1706 break;
1707 case GL_VERTEX_ARRAY_SIZE:
1708 case GL_COLOR_ARRAY_SIZE:
1709 case GL_TEXTURE_COORD_ARRAY_SIZE:
1710 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1711 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1712 break;
1713 case GL_VERTEX_ARRAY_TYPE:
1714 case GL_COLOR_ARRAY_TYPE:
1715 case GL_NORMAL_ARRAY_TYPE:
1716 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1717 case GL_TEXTURE_COORD_ARRAY_TYPE:
1718 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1719 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1720 break;
1721
Jamie Madill231c7f52017-04-26 13:45:37 -04001722 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001723 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001724 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001725 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001726}
1727
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001728void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001729{
Shannon Woods53a94a82014-06-24 15:20:36 -04001730 // Queries about context capabilities and maximums are answered by Context.
1731 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001732 switch (pname)
1733 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001734 case GL_MAX_ELEMENT_INDEX:
1735 *params = mCaps.maxElementIndex;
1736 break;
1737 case GL_MAX_UNIFORM_BLOCK_SIZE:
1738 *params = mCaps.maxUniformBlockSize;
1739 break;
1740 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001741 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001742 break;
1743 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001744 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001745 break;
1746 case GL_MAX_SERVER_WAIT_TIMEOUT:
1747 *params = mCaps.maxServerWaitTimeout;
1748 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001749
Jamie Madill231c7f52017-04-26 13:45:37 -04001750 // GL_EXT_disjoint_timer_query
1751 case GL_TIMESTAMP_EXT:
1752 *params = mImplementation->getTimestamp();
1753 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001754
Jamie Madill231c7f52017-04-26 13:45:37 -04001755 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1756 *params = mCaps.maxShaderStorageBlockSize;
1757 break;
1758 default:
1759 UNREACHABLE();
1760 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001761 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001762}
1763
Geoff Lang70d0f492015-12-10 17:45:46 -05001764void Context::getPointerv(GLenum pname, void **params) const
1765{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001766 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001767}
1768
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001769void Context::getPointervRobustANGLERobust(GLenum pname,
1770 GLsizei bufSize,
1771 GLsizei *length,
1772 void **params)
1773{
1774 UNIMPLEMENTED();
1775}
1776
Martin Radev66fb8202016-07-28 11:45:20 +03001777void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001778{
Shannon Woods53a94a82014-06-24 15:20:36 -04001779 // Queries about context capabilities and maximums are answered by Context.
1780 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001781
1782 GLenum nativeType;
1783 unsigned int numParams;
1784 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1785 ASSERT(queryStatus);
1786
1787 if (nativeType == GL_INT)
1788 {
1789 switch (target)
1790 {
1791 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1792 ASSERT(index < 3u);
1793 *data = mCaps.maxComputeWorkGroupCount[index];
1794 break;
1795 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1796 ASSERT(index < 3u);
1797 *data = mCaps.maxComputeWorkGroupSize[index];
1798 break;
1799 default:
1800 mGLState.getIntegeri_v(target, index, data);
1801 }
1802 }
1803 else
1804 {
1805 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1806 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001807}
1808
Brandon Jones59770802018-04-02 13:18:42 -07001809void Context::getIntegeri_vRobust(GLenum target,
1810 GLuint index,
1811 GLsizei bufSize,
1812 GLsizei *length,
1813 GLint *data)
1814{
1815 getIntegeri_v(target, index, data);
1816}
1817
Martin Radev66fb8202016-07-28 11:45:20 +03001818void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001819{
Shannon Woods53a94a82014-06-24 15:20:36 -04001820 // Queries about context capabilities and maximums are answered by Context.
1821 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001822
1823 GLenum nativeType;
1824 unsigned int numParams;
1825 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1826 ASSERT(queryStatus);
1827
1828 if (nativeType == GL_INT_64_ANGLEX)
1829 {
1830 mGLState.getInteger64i_v(target, index, data);
1831 }
1832 else
1833 {
1834 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1835 }
1836}
1837
Brandon Jones59770802018-04-02 13:18:42 -07001838void Context::getInteger64i_vRobust(GLenum target,
1839 GLuint index,
1840 GLsizei bufSize,
1841 GLsizei *length,
1842 GLint64 *data)
1843{
1844 getInteger64i_v(target, index, data);
1845}
1846
Martin Radev66fb8202016-07-28 11:45:20 +03001847void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1848{
1849 // Queries about context capabilities and maximums are answered by Context.
1850 // Queries about current GL state values are answered by State.
1851
1852 GLenum nativeType;
1853 unsigned int numParams;
1854 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1855 ASSERT(queryStatus);
1856
1857 if (nativeType == GL_BOOL)
1858 {
1859 mGLState.getBooleani_v(target, index, data);
1860 }
1861 else
1862 {
1863 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1864 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001865}
1866
Brandon Jones59770802018-04-02 13:18:42 -07001867void Context::getBooleani_vRobust(GLenum target,
1868 GLuint index,
1869 GLsizei bufSize,
1870 GLsizei *length,
1871 GLboolean *data)
1872{
1873 getBooleani_v(target, index, data);
1874}
1875
Corentin Wallez336129f2017-10-17 15:55:40 -04001876void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001877{
1878 Buffer *buffer = mGLState.getTargetBuffer(target);
1879 QueryBufferParameteriv(buffer, pname, params);
1880}
1881
Brandon Jones59770802018-04-02 13:18:42 -07001882void Context::getBufferParameterivRobust(BufferBinding target,
1883 GLenum pname,
1884 GLsizei bufSize,
1885 GLsizei *length,
1886 GLint *params)
1887{
1888 getBufferParameteriv(target, pname, params);
1889}
1890
He Yunchao010e4db2017-03-03 14:22:06 +08001891void Context::getFramebufferAttachmentParameteriv(GLenum target,
1892 GLenum attachment,
1893 GLenum pname,
1894 GLint *params)
1895{
1896 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001897 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001898}
1899
Brandon Jones59770802018-04-02 13:18:42 -07001900void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1901 GLenum attachment,
1902 GLenum pname,
1903 GLsizei bufSize,
1904 GLsizei *length,
1905 GLint *params)
1906{
1907 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1908}
1909
He Yunchao010e4db2017-03-03 14:22:06 +08001910void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1911{
1912 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1913 QueryRenderbufferiv(this, renderbuffer, pname, params);
1914}
1915
Brandon Jones59770802018-04-02 13:18:42 -07001916void Context::getRenderbufferParameterivRobust(GLenum target,
1917 GLenum pname,
1918 GLsizei bufSize,
1919 GLsizei *length,
1920 GLint *params)
1921{
1922 getRenderbufferParameteriv(target, pname, params);
1923}
1924
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001925void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001926{
1927 Texture *texture = getTargetTexture(target);
1928 QueryTexParameterfv(texture, pname, params);
1929}
1930
Brandon Jones59770802018-04-02 13:18:42 -07001931void Context::getTexParameterfvRobust(TextureType target,
1932 GLenum pname,
1933 GLsizei bufSize,
1934 GLsizei *length,
1935 GLfloat *params)
1936{
1937 getTexParameterfv(target, pname, params);
1938}
1939
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001940void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001941{
1942 Texture *texture = getTargetTexture(target);
1943 QueryTexParameteriv(texture, pname, params);
1944}
Jiajia Qin5451d532017-11-16 17:16:34 +08001945
Brandon Jones59770802018-04-02 13:18:42 -07001946void Context::getTexParameterivRobust(TextureType target,
1947 GLenum pname,
1948 GLsizei bufSize,
1949 GLsizei *length,
1950 GLint *params)
1951{
1952 getTexParameteriv(target, pname, params);
1953}
1954
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001955void Context::getTexParameterIivRobust(TextureType target,
1956 GLenum pname,
1957 GLsizei bufSize,
1958 GLsizei *length,
1959 GLint *params)
1960{
1961 UNIMPLEMENTED();
1962}
1963
1964void Context::getTexParameterIuivRobust(TextureType target,
1965 GLenum pname,
1966 GLsizei bufSize,
1967 GLsizei *length,
1968 GLuint *params)
1969{
1970 UNIMPLEMENTED();
1971}
1972
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001973void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001974{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001975 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001976 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001977}
1978
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001979void Context::getTexLevelParameterivRobust(TextureTarget target,
1980 GLint level,
1981 GLenum pname,
1982 GLsizei bufSize,
1983 GLsizei *length,
1984 GLint *params)
1985{
1986 UNIMPLEMENTED();
1987}
1988
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001989void Context::getTexLevelParameterfv(TextureTarget target,
1990 GLint level,
1991 GLenum pname,
1992 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001993{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001994 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001995 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001996}
1997
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001998void Context::getTexLevelParameterfvRobust(TextureTarget target,
1999 GLint level,
2000 GLenum pname,
2001 GLsizei bufSize,
2002 GLsizei *length,
2003 GLfloat *params)
2004{
2005 UNIMPLEMENTED();
2006}
2007
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002008void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002009{
2010 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002011 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002012 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002013}
2014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002015void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002016{
2017 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002018 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002019 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002020}
2021
Brandon Jones59770802018-04-02 13:18:42 -07002022void Context::texParameterfvRobust(TextureType target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 const GLfloat *params)
2026{
2027 texParameterfv(target, pname, params);
2028}
2029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002030void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002031{
2032 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002033 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002034 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002035}
2036
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002037void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002038{
2039 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002040 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002041 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002042}
2043
Brandon Jones59770802018-04-02 13:18:42 -07002044void Context::texParameterivRobust(TextureType target,
2045 GLenum pname,
2046 GLsizei bufSize,
2047 const GLint *params)
2048{
2049 texParameteriv(target, pname, params);
2050}
2051
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002052void Context::texParameterIivRobust(TextureType target,
2053 GLenum pname,
2054 GLsizei bufSize,
2055 const GLint *params)
2056{
2057 UNIMPLEMENTED();
2058}
2059
2060void Context::texParameterIuivRobust(TextureType target,
2061 GLenum pname,
2062 GLsizei bufSize,
2063 const GLuint *params)
2064{
2065 UNIMPLEMENTED();
2066}
2067
Jamie Madill493f9572018-05-24 19:52:15 -04002068void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002069{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002070 // No-op if zero count
2071 if (count == 0)
2072 {
2073 return;
2074 }
2075
Jamie Madill05b35b22017-10-03 09:01:44 -04002076 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002077 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002078 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002079}
2080
Jamie Madill493f9572018-05-24 19:52:15 -04002081void Context::drawArraysInstanced(PrimitiveMode mode,
2082 GLint first,
2083 GLsizei count,
2084 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002085{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002086 // No-op if zero count
2087 if (count == 0 || instanceCount == 0)
2088 {
2089 return;
2090 }
2091
Jamie Madill05b35b22017-10-03 09:01:44 -04002092 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002093 ANGLE_CONTEXT_TRY(
2094 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002095 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2096 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002097}
2098
Jamie Madill493f9572018-05-24 19:52:15 -04002099void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002100{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002101 // No-op if zero count
2102 if (count == 0)
2103 {
2104 return;
2105 }
2106
Jamie Madill05b35b22017-10-03 09:01:44 -04002107 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002108 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002109}
2110
Jamie Madill493f9572018-05-24 19:52:15 -04002111void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002112 GLsizei count,
2113 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002114 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002115 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002116{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002117 // No-op if zero count
2118 if (count == 0 || instances == 0)
2119 {
2120 return;
2121 }
2122
Jamie Madill05b35b22017-10-03 09:01:44 -04002123 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002124 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002125 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002126}
2127
Jamie Madill493f9572018-05-24 19:52:15 -04002128void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002129 GLuint start,
2130 GLuint end,
2131 GLsizei count,
2132 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002133 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002134{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002135 // No-op if zero count
2136 if (count == 0)
2137 {
2138 return;
2139 }
2140
Jamie Madill05b35b22017-10-03 09:01:44 -04002141 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002142 ANGLE_CONTEXT_TRY(
2143 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002144}
2145
Jamie Madill493f9572018-05-24 19:52:15 -04002146void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002147{
Jamie Madill05b35b22017-10-03 09:01:44 -04002148 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002149 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002150}
2151
Jamie Madill493f9572018-05-24 19:52:15 -04002152void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002153{
Jamie Madill05b35b22017-10-03 09:01:44 -04002154 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002155 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002156}
2157
Jamie Madill675fe712016-12-19 13:07:54 -05002158void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002159{
Jamie Madillafa02a22017-11-23 12:57:38 -05002160 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002161}
2162
Jamie Madill675fe712016-12-19 13:07:54 -05002163void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002164{
Jamie Madillafa02a22017-11-23 12:57:38 -05002165 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002166}
2167
Austin Kinross6ee1e782015-05-29 17:05:37 -07002168void Context::insertEventMarker(GLsizei length, const char *marker)
2169{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002170 ASSERT(mImplementation);
2171 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002172}
2173
2174void Context::pushGroupMarker(GLsizei length, const char *marker)
2175{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002176 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002177
2178 if (marker == nullptr)
2179 {
2180 // From the EXT_debug_marker spec,
2181 // "If <marker> is null then an empty string is pushed on the stack."
2182 mImplementation->pushGroupMarker(length, "");
2183 }
2184 else
2185 {
2186 mImplementation->pushGroupMarker(length, marker);
2187 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002188}
2189
2190void Context::popGroupMarker()
2191{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002192 ASSERT(mImplementation);
2193 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002194}
2195
Geoff Langd8605522016-04-13 10:19:12 -04002196void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2197{
2198 Program *programObject = getProgram(program);
2199 ASSERT(programObject);
2200
2201 programObject->bindUniformLocation(location, name);
2202}
2203
Brandon Jones59770802018-04-02 13:18:42 -07002204void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002205{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002206 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002207}
2208
Brandon Jones59770802018-04-02 13:18:42 -07002209void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002210{
2211 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2212}
2213
Brandon Jones59770802018-04-02 13:18:42 -07002214void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002215{
2216 GLfloat I[16];
2217 angle::Matrix<GLfloat>::setToIdentity(I);
2218
2219 mGLState.loadPathRenderingMatrix(matrixMode, I);
2220}
2221
2222void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2223{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002224 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002225 if (!pathObj)
2226 return;
2227
2228 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002229 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002230
2231 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2232}
2233
2234void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2235{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002236 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002237 if (!pathObj)
2238 return;
2239
2240 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002241 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002242
2243 mImplementation->stencilStrokePath(pathObj, reference, mask);
2244}
2245
2246void Context::coverFillPath(GLuint path, GLenum coverMode)
2247{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002248 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002249 if (!pathObj)
2250 return;
2251
2252 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002253 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002254
2255 mImplementation->coverFillPath(pathObj, coverMode);
2256}
2257
2258void Context::coverStrokePath(GLuint path, GLenum coverMode)
2259{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002260 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002261 if (!pathObj)
2262 return;
2263
2264 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002265 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002266
2267 mImplementation->coverStrokePath(pathObj, coverMode);
2268}
2269
2270void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2271{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002272 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002273 if (!pathObj)
2274 return;
2275
2276 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002277 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002278
2279 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2280}
2281
2282void Context::stencilThenCoverStrokePath(GLuint path,
2283 GLint reference,
2284 GLuint mask,
2285 GLenum coverMode)
2286{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002287 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002288 if (!pathObj)
2289 return;
2290
2291 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002292 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002293
2294 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2295}
2296
Sami Väisänend59ca052016-06-21 16:10:00 +03002297void Context::coverFillPathInstanced(GLsizei numPaths,
2298 GLenum pathNameType,
2299 const void *paths,
2300 GLuint pathBase,
2301 GLenum coverMode,
2302 GLenum transformType,
2303 const GLfloat *transformValues)
2304{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002305 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002306
2307 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002308 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002309
2310 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2311}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002312
Sami Väisänend59ca052016-06-21 16:10:00 +03002313void Context::coverStrokePathInstanced(GLsizei numPaths,
2314 GLenum pathNameType,
2315 const void *paths,
2316 GLuint pathBase,
2317 GLenum coverMode,
2318 GLenum transformType,
2319 const GLfloat *transformValues)
2320{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002321 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002322
2323 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002324 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002325
2326 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2327 transformValues);
2328}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002329
Sami Väisänend59ca052016-06-21 16:10:00 +03002330void Context::stencilFillPathInstanced(GLsizei numPaths,
2331 GLenum pathNameType,
2332 const void *paths,
2333 GLuint pathBase,
2334 GLenum fillMode,
2335 GLuint mask,
2336 GLenum transformType,
2337 const GLfloat *transformValues)
2338{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002339 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002340
2341 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002342 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002343
2344 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2345 transformValues);
2346}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002347
Sami Väisänend59ca052016-06-21 16:10:00 +03002348void Context::stencilStrokePathInstanced(GLsizei numPaths,
2349 GLenum pathNameType,
2350 const void *paths,
2351 GLuint pathBase,
2352 GLint reference,
2353 GLuint mask,
2354 GLenum transformType,
2355 const GLfloat *transformValues)
2356{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002357 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002358
2359 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002360 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002361
2362 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2363 transformValues);
2364}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002365
Sami Väisänend59ca052016-06-21 16:10:00 +03002366void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2367 GLenum pathNameType,
2368 const void *paths,
2369 GLuint pathBase,
2370 GLenum fillMode,
2371 GLuint mask,
2372 GLenum coverMode,
2373 GLenum transformType,
2374 const GLfloat *transformValues)
2375{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002376 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002377
2378 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002379 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002380
2381 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2382 transformType, transformValues);
2383}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002384
Sami Väisänend59ca052016-06-21 16:10:00 +03002385void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2386 GLenum pathNameType,
2387 const void *paths,
2388 GLuint pathBase,
2389 GLint reference,
2390 GLuint mask,
2391 GLenum coverMode,
2392 GLenum transformType,
2393 const GLfloat *transformValues)
2394{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002395 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002396
2397 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002398 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002399
2400 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2401 transformType, transformValues);
2402}
2403
Sami Väisänen46eaa942016-06-29 10:26:37 +03002404void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2405{
2406 auto *programObject = getProgram(program);
2407
2408 programObject->bindFragmentInputLocation(location, name);
2409}
2410
2411void Context::programPathFragmentInputGen(GLuint program,
2412 GLint location,
2413 GLenum genMode,
2414 GLint components,
2415 const GLfloat *coeffs)
2416{
2417 auto *programObject = getProgram(program);
2418
Jamie Madillbd044ed2017-06-05 12:59:21 -04002419 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002420}
2421
jchen1015015f72017-03-16 13:54:21 +08002422GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2423{
jchen10fd7c3b52017-03-21 15:36:03 +08002424 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002425 return QueryProgramResourceIndex(programObject, programInterface, name);
2426}
2427
jchen10fd7c3b52017-03-21 15:36:03 +08002428void Context::getProgramResourceName(GLuint program,
2429 GLenum programInterface,
2430 GLuint index,
2431 GLsizei bufSize,
2432 GLsizei *length,
2433 GLchar *name)
2434{
2435 const auto *programObject = getProgram(program);
2436 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2437}
2438
jchen10191381f2017-04-11 13:59:04 +08002439GLint Context::getProgramResourceLocation(GLuint program,
2440 GLenum programInterface,
2441 const GLchar *name)
2442{
2443 const auto *programObject = getProgram(program);
2444 return QueryProgramResourceLocation(programObject, programInterface, name);
2445}
2446
jchen10880683b2017-04-12 16:21:55 +08002447void Context::getProgramResourceiv(GLuint program,
2448 GLenum programInterface,
2449 GLuint index,
2450 GLsizei propCount,
2451 const GLenum *props,
2452 GLsizei bufSize,
2453 GLsizei *length,
2454 GLint *params)
2455{
2456 const auto *programObject = getProgram(program);
2457 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2458 length, params);
2459}
2460
jchen10d9cd7b72017-08-30 15:04:25 +08002461void Context::getProgramInterfaceiv(GLuint program,
2462 GLenum programInterface,
2463 GLenum pname,
2464 GLint *params)
2465{
2466 const auto *programObject = getProgram(program);
2467 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2468}
2469
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002470void Context::getProgramInterfaceivRobust(GLuint program,
2471 GLenum programInterface,
2472 GLenum pname,
2473 GLsizei bufSize,
2474 GLsizei *length,
2475 GLint *params)
2476{
2477 UNIMPLEMENTED();
2478}
2479
Jamie Madill427064d2018-04-13 16:20:34 -04002480void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481{
Geoff Lang7b19a492018-04-20 09:31:52 -04002482 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002483 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002484 GLenum code = error.getCode();
2485 mErrors.insert(code);
2486 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2487 {
2488 markContextLost();
2489 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002490
Geoff Langee6884e2017-11-09 16:51:11 -05002491 ASSERT(!error.getMessage().empty());
2492 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2493 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002494 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002495}
2496
2497// Get one of the recorded errors and clear its flag, if any.
2498// [OpenGL ES 2.0.24] section 2.5 page 13.
2499GLenum Context::getError()
2500{
Geoff Langda5777c2014-07-11 09:52:58 -04002501 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502 {
Geoff Langda5777c2014-07-11 09:52:58 -04002503 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504 }
Geoff Langda5777c2014-07-11 09:52:58 -04002505 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002506 {
Geoff Langda5777c2014-07-11 09:52:58 -04002507 GLenum error = *mErrors.begin();
2508 mErrors.erase(mErrors.begin());
2509 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002510 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002511}
2512
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002514void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002515{
2516 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002517 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002518 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002519 mContextLostForced = true;
2520 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002521 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002522}
2523
Jamie Madill427064d2018-04-13 16:20:34 -04002524bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002525{
2526 return mContextLost;
2527}
2528
Jamie Madillfa920eb2018-01-04 11:45:50 -05002529GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531 // Even if the application doesn't want to know about resets, we want to know
2532 // as it will allow us to skip all the calls.
2533 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002534 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002536 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002537 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002538 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539
2540 // EXT_robustness, section 2.6: If the reset notification behavior is
2541 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2542 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2543 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002544 }
2545
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002546 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2547 // status should be returned at least once, and GL_NO_ERROR should be returned
2548 // once the device has finished resetting.
2549 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002550 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002551 ASSERT(mResetStatus == GL_NO_ERROR);
2552 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002553
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002554 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002555 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002556 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002557 }
2558 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002559 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002560 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002561 // If markContextLost was used to mark the context lost then
2562 // assume that is not recoverable, and continue to report the
2563 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002564 mResetStatus = mImplementation->getResetStatus();
2565 }
Jamie Madill893ab082014-05-16 16:56:10 -04002566
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002567 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568}
2569
2570bool Context::isResetNotificationEnabled()
2571{
2572 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2573}
2574
Corentin Walleze3b10e82015-05-20 11:06:25 -04002575const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002576{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002577 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002578}
2579
2580EGLenum Context::getClientType() const
2581{
2582 return mClientType;
2583}
2584
2585EGLenum Context::getRenderBuffer() const
2586{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002587 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2588 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002589 {
2590 return EGL_NONE;
2591 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002592
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002593 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002594 ASSERT(backAttachment != nullptr);
2595 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002596}
2597
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002598VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002599{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002600 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002601 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2602 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002603 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002604 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2605 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002606
Jamie Madill96a483b2017-06-27 16:49:21 -04002607 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002608 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002609
2610 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002611}
2612
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002613TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002614{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002615 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002616 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2617 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002618 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002619 transformFeedback =
2620 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002621 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002622 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002623 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002624
2625 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002626}
2627
2628bool Context::isVertexArrayGenerated(GLuint vertexArray)
2629{
Jamie Madill96a483b2017-06-27 16:49:21 -04002630 ASSERT(mVertexArrayMap.contains(0));
2631 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002632}
2633
2634bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2635{
Jamie Madill96a483b2017-06-27 16:49:21 -04002636 ASSERT(mTransformFeedbackMap.contains(0));
2637 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002638}
2639
Shannon Woods53a94a82014-06-24 15:20:36 -04002640void Context::detachTexture(GLuint texture)
2641{
2642 // Simple pass-through to State's detachTexture method, as textures do not require
2643 // allocation map management either here or in the resource manager at detach time.
2644 // Zero textures are held by the Context, and we don't attempt to request them from
2645 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002646 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002647}
2648
James Darpinian4d9d4832018-03-13 12:43:28 -07002649void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002650{
Yuly Novikov5807a532015-12-03 13:01:22 -05002651 // Simple pass-through to State's detachBuffer method, since
2652 // only buffer attachments to container objects that are bound to the current context
2653 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002654
Yuly Novikov5807a532015-12-03 13:01:22 -05002655 // [OpenGL ES 3.2] section 5.1.2 page 45:
2656 // Attachments to unbound container objects, such as
2657 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2658 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002659 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660}
2661
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662void Context::detachFramebuffer(GLuint framebuffer)
2663{
Shannon Woods53a94a82014-06-24 15:20:36 -04002664 // Framebuffer detachment is handled by Context, because 0 is a valid
2665 // Framebuffer object, and a pointer to it must be passed from Context
2666 // to State at binding time.
2667
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002669 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2670 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2671 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002672
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002673 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002674 {
2675 bindReadFramebuffer(0);
2676 }
2677
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002678 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679 {
2680 bindDrawFramebuffer(0);
2681 }
2682}
2683
2684void Context::detachRenderbuffer(GLuint renderbuffer)
2685{
Jamie Madilla02315b2017-02-23 14:14:47 -05002686 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002687}
2688
Jamie Madill57a89722013-07-02 11:57:03 -04002689void Context::detachVertexArray(GLuint vertexArray)
2690{
Jamie Madill77a72f62015-04-14 11:18:32 -04002691 // Vertex array detachment is handled by Context, because 0 is a valid
2692 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002693 // binding time.
2694
Jamie Madill57a89722013-07-02 11:57:03 -04002695 // [OpenGL ES 3.0.2] section 2.10 page 43:
2696 // If a vertex array object that is currently bound is deleted, the binding
2697 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002698 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002699 {
2700 bindVertexArray(0);
2701 }
2702}
2703
Geoff Langc8058452014-02-03 12:04:11 -05002704void Context::detachTransformFeedback(GLuint transformFeedback)
2705{
Corentin Walleza2257da2016-04-19 16:43:12 -04002706 // Transform feedback detachment is handled by Context, because 0 is a valid
2707 // transform feedback, and a pointer to it must be passed from Context to State at
2708 // binding time.
2709
2710 // The OpenGL specification doesn't mention what should happen when the currently bound
2711 // transform feedback object is deleted. Since it is a container object, we treat it like
2712 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002713 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002714 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002715 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002716 }
Geoff Langc8058452014-02-03 12:04:11 -05002717}
2718
Jamie Madilldc356042013-07-19 16:36:57 -04002719void Context::detachSampler(GLuint sampler)
2720{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002721 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002722}
2723
Yunchao Hea336b902017-08-02 16:05:21 +08002724void Context::detachProgramPipeline(GLuint pipeline)
2725{
2726 mGLState.detachProgramPipeline(this, pipeline);
2727}
2728
Jamie Madill3ef140a2017-08-26 23:11:21 -04002729void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730{
Shaodde78e82017-05-22 14:13:27 +08002731 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732}
2733
Jamie Madille29d1672013-07-19 16:36:57 -04002734void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2735{
Geoff Langc1984ed2016-10-07 12:41:00 -04002736 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002737 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002738 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002739 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002740}
Jamie Madille29d1672013-07-19 16:36:57 -04002741
Geoff Langc1984ed2016-10-07 12:41:00 -04002742void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2743{
2744 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002745 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002746 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002747 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002748}
2749
Brandon Jones59770802018-04-02 13:18:42 -07002750void Context::samplerParameterivRobust(GLuint sampler,
2751 GLenum pname,
2752 GLsizei bufSize,
2753 const GLint *param)
2754{
2755 samplerParameteriv(sampler, pname, param);
2756}
2757
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002758void Context::samplerParameterIivRobust(GLuint sampler,
2759 GLenum pname,
2760 GLsizei bufSize,
2761 const GLint *param)
2762{
2763 UNIMPLEMENTED();
2764}
2765
2766void Context::samplerParameterIuivRobust(GLuint sampler,
2767 GLenum pname,
2768 GLsizei bufSize,
2769 const GLuint *param)
2770{
2771 UNIMPLEMENTED();
2772}
2773
Jamie Madille29d1672013-07-19 16:36:57 -04002774void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2775{
Geoff Langc1984ed2016-10-07 12:41:00 -04002776 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002777 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002778 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002779 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002780}
2781
Geoff Langc1984ed2016-10-07 12:41:00 -04002782void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002783{
Geoff Langc1984ed2016-10-07 12:41:00 -04002784 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002785 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002786 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002787 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002788}
2789
Brandon Jones59770802018-04-02 13:18:42 -07002790void Context::samplerParameterfvRobust(GLuint sampler,
2791 GLenum pname,
2792 GLsizei bufSize,
2793 const GLfloat *param)
2794{
2795 samplerParameterfv(sampler, pname, param);
2796}
2797
Geoff Langc1984ed2016-10-07 12:41:00 -04002798void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002799{
Geoff Langc1984ed2016-10-07 12:41:00 -04002800 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002801 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002802 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002803 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002804}
Jamie Madill9675b802013-07-19 16:36:59 -04002805
Brandon Jones59770802018-04-02 13:18:42 -07002806void Context::getSamplerParameterivRobust(GLuint sampler,
2807 GLenum pname,
2808 GLsizei bufSize,
2809 GLsizei *length,
2810 GLint *params)
2811{
2812 getSamplerParameteriv(sampler, pname, params);
2813}
2814
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002815void Context::getSamplerParameterIivRobust(GLuint sampler,
2816 GLenum pname,
2817 GLsizei bufSize,
2818 GLsizei *length,
2819 GLint *params)
2820{
2821 UNIMPLEMENTED();
2822}
2823
2824void Context::getSamplerParameterIuivRobust(GLuint sampler,
2825 GLenum pname,
2826 GLsizei bufSize,
2827 GLsizei *length,
2828 GLuint *params)
2829{
2830 UNIMPLEMENTED();
2831}
2832
Geoff Langc1984ed2016-10-07 12:41:00 -04002833void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2834{
2835 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002836 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002837 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002838 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002839}
2840
Brandon Jones59770802018-04-02 13:18:42 -07002841void Context::getSamplerParameterfvRobust(GLuint sampler,
2842 GLenum pname,
2843 GLsizei bufSize,
2844 GLsizei *length,
2845 GLfloat *params)
2846{
2847 getSamplerParameterfv(sampler, pname, params);
2848}
2849
Olli Etuahof0fee072016-03-30 15:11:58 +03002850void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2851{
2852 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002853 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002854}
2855
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002856void Context::initRendererString()
2857{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002858 std::ostringstream rendererString;
2859 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002860 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002861 rendererString << ")";
2862
Geoff Langcec35902014-04-16 10:52:36 -04002863 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002864}
2865
Geoff Langc339c4e2016-11-29 10:37:36 -05002866void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002867{
Geoff Langc339c4e2016-11-29 10:37:36 -05002868 const Version &clientVersion = getClientVersion();
2869
2870 std::ostringstream versionString;
2871 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2872 << ANGLE_VERSION_STRING << ")";
2873 mVersionString = MakeStaticString(versionString.str());
2874
2875 std::ostringstream shadingLanguageVersionString;
2876 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2877 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2878 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2879 << ")";
2880 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002881}
2882
Geoff Langcec35902014-04-16 10:52:36 -04002883void Context::initExtensionStrings()
2884{
Geoff Langc339c4e2016-11-29 10:37:36 -05002885 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2886 std::ostringstream combinedStringStream;
2887 std::copy(strings.begin(), strings.end(),
2888 std::ostream_iterator<const char *>(combinedStringStream, " "));
2889 return MakeStaticString(combinedStringStream.str());
2890 };
2891
2892 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002893 for (const auto &extensionString : mExtensions.getStrings())
2894 {
2895 mExtensionStrings.push_back(MakeStaticString(extensionString));
2896 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002897 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002898
Geoff Langc339c4e2016-11-29 10:37:36 -05002899 mRequestableExtensionStrings.clear();
2900 for (const auto &extensionInfo : GetExtensionInfoMap())
2901 {
2902 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002903 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002904 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002905 {
2906 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2907 }
2908 }
2909 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002910}
2911
Geoff Langc339c4e2016-11-29 10:37:36 -05002912const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002913{
Geoff Langc339c4e2016-11-29 10:37:36 -05002914 switch (name)
2915 {
2916 case GL_VENDOR:
2917 return reinterpret_cast<const GLubyte *>("Google Inc.");
2918
2919 case GL_RENDERER:
2920 return reinterpret_cast<const GLubyte *>(mRendererString);
2921
2922 case GL_VERSION:
2923 return reinterpret_cast<const GLubyte *>(mVersionString);
2924
2925 case GL_SHADING_LANGUAGE_VERSION:
2926 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2927
2928 case GL_EXTENSIONS:
2929 return reinterpret_cast<const GLubyte *>(mExtensionString);
2930
2931 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2932 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2933
2934 default:
2935 UNREACHABLE();
2936 return nullptr;
2937 }
Geoff Langcec35902014-04-16 10:52:36 -04002938}
2939
Geoff Langc339c4e2016-11-29 10:37:36 -05002940const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002941{
Geoff Langc339c4e2016-11-29 10:37:36 -05002942 switch (name)
2943 {
2944 case GL_EXTENSIONS:
2945 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2946
2947 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2948 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2949
2950 default:
2951 UNREACHABLE();
2952 return nullptr;
2953 }
Geoff Langcec35902014-04-16 10:52:36 -04002954}
2955
2956size_t Context::getExtensionStringCount() const
2957{
2958 return mExtensionStrings.size();
2959}
2960
Geoff Lang111a99e2017-10-17 10:58:41 -04002961bool Context::isExtensionRequestable(const char *name)
2962{
2963 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2964 auto extension = extensionInfos.find(name);
2965
Geoff Lang111a99e2017-10-17 10:58:41 -04002966 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002967 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002968}
2969
Geoff Langc339c4e2016-11-29 10:37:36 -05002970void Context::requestExtension(const char *name)
2971{
2972 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2973 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2974 const auto &extension = extensionInfos.at(name);
2975 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002976 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002977
2978 if (mExtensions.*(extension.ExtensionsMember))
2979 {
2980 // Extension already enabled
2981 return;
2982 }
2983
2984 mExtensions.*(extension.ExtensionsMember) = true;
2985 updateCaps();
2986 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002987
Jamie Madill2f348d22017-06-05 10:50:59 -04002988 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2989 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002990
Jamie Madill81c2e252017-09-09 23:32:46 -04002991 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2992 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002993 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002994 for (auto &zeroTexture : mZeroTextures)
2995 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002996 if (zeroTexture.get() != nullptr)
2997 {
2998 zeroTexture->signalDirty(this, InitState::Initialized);
2999 }
Geoff Lang9aded172017-04-05 11:07:56 -04003000 }
3001
3002 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003003}
3004
3005size_t Context::getRequestableExtensionStringCount() const
3006{
3007 return mRequestableExtensionStrings.size();
3008}
3009
Jamie Madill493f9572018-05-24 19:52:15 -04003010void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003011{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003012 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003013 ASSERT(transformFeedback != nullptr);
3014 ASSERT(!transformFeedback->isPaused());
3015
Jamie Madill6c1f6712017-02-14 19:08:04 -05003016 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003017}
3018
3019bool Context::hasActiveTransformFeedback(GLuint program) const
3020{
3021 for (auto pair : mTransformFeedbackMap)
3022 {
3023 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3024 {
3025 return true;
3026 }
3027 }
3028 return false;
3029}
3030
Geoff Langb0f917f2017-12-05 13:41:54 -05003031Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003032 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003033 bool robustResourceInit) const
3034{
3035 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3036
3037 if (getClientVersion() < ES_2_0)
3038 {
3039 // Default extensions for GLES1
3040 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003041 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003042 }
3043
3044 if (getClientVersion() < ES_3_0)
3045 {
3046 // Disable ES3+ extensions
3047 supportedExtensions.colorBufferFloat = false;
3048 supportedExtensions.eglImageExternalEssl3 = false;
3049 supportedExtensions.textureNorm16 = false;
3050 supportedExtensions.multiview = false;
3051 supportedExtensions.maxViews = 1u;
3052 }
3053
3054 if (getClientVersion() < ES_3_1)
3055 {
3056 // Disable ES3.1+ extensions
3057 supportedExtensions.geometryShader = false;
3058 }
3059
3060 if (getClientVersion() > ES_2_0)
3061 {
3062 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3063 // supportedExtensions.sRGB = false;
3064 }
3065
3066 // Some extensions are always available because they are implemented in the GL layer.
3067 supportedExtensions.bindUniformLocation = true;
3068 supportedExtensions.vertexArrayObject = true;
3069 supportedExtensions.bindGeneratesResource = true;
3070 supportedExtensions.clientArrays = true;
3071 supportedExtensions.requestExtension = true;
3072
3073 // Enable the no error extension if the context was created with the flag.
3074 supportedExtensions.noError = mSkipValidation;
3075
3076 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3077 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3078
3079 // Explicitly enable GL_KHR_debug
3080 supportedExtensions.debug = true;
3081 supportedExtensions.maxDebugMessageLength = 1024;
3082 supportedExtensions.maxDebugLoggedMessages = 1024;
3083 supportedExtensions.maxDebugGroupStackDepth = 1024;
3084 supportedExtensions.maxLabelLength = 1024;
3085
3086 // Explicitly enable GL_ANGLE_robust_client_memory
3087 supportedExtensions.robustClientMemory = true;
3088
3089 // Determine robust resource init availability from EGL.
3090 supportedExtensions.robustResourceInitialization = robustResourceInit;
3091
3092 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3093 // supports it.
3094 supportedExtensions.robustBufferAccessBehavior =
3095 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3096
3097 // Enable the cache control query unconditionally.
3098 supportedExtensions.programCacheControl = true;
3099
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003100 // Enable EGL_ANGLE_explicit_context subextensions
3101 if (clientExtensions.explicitContext)
3102 {
3103 // GL_ANGLE_explicit_context_gles1
3104 supportedExtensions.explicitContextGles1 = true;
3105 // GL_ANGLE_explicit_context
3106 supportedExtensions.explicitContext = true;
3107 }
3108
Geoff Langb0f917f2017-12-05 13:41:54 -05003109 return supportedExtensions;
3110}
3111
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003112void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3113 const egl::ClientExtensions &clientExtensions,
3114 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003115{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003116 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003117
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003118 mSupportedExtensions =
3119 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Jamie Madill493f9572018-05-24 19:52:15 -04003120 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003121
3122 mLimitations = mImplementation->getNativeLimitations();
3123
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003124 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3125 if (getClientVersion() < Version(2, 0))
3126 {
3127 mCaps.maxMultitextureUnits = 4;
3128 mCaps.maxClipPlanes = 6;
3129 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003130 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3131 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3132 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003133 }
3134
Geoff Lang301d1612014-07-09 10:34:37 -04003135 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003136 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003137
Jamie Madill0f80ed82017-09-19 00:24:56 -04003138 if (getClientVersion() < ES_3_1)
3139 {
3140 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3141 }
3142 else
3143 {
3144 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3145 }
Geoff Lang301d1612014-07-09 10:34:37 -04003146
Jiawei Shao54aafe52018-04-27 14:54:57 +08003147 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3148 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003149 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3150 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3151
3152 // Limit textures as well, so we can use fast bitsets with texture bindings.
3153 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003154 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3155 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3156 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3157 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003158
Jiawei Shaodb342272017-09-27 10:21:45 +08003159 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3160
Geoff Langc287ea62016-09-16 14:46:51 -04003161 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003162 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003163 for (const auto &extensionInfo : GetExtensionInfoMap())
3164 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003165 // If the user has requested that extensions start disabled and they are requestable,
3166 // disable them.
3167 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003168 {
3169 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3170 }
3171 }
3172
3173 // Generate texture caps
3174 updateCaps();
3175}
3176
3177void Context::updateCaps()
3178{
Geoff Lang900013c2014-07-07 11:32:19 -04003179 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003180 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003181
Jamie Madill7b62cf92017-11-02 15:20:49 -04003182 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003183 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003184 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003185 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003186
Geoff Lang0d8b7242015-09-09 14:56:53 -04003187 // Update the format caps based on the client version and extensions.
3188 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3189 // ES3.
3190 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003191 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003192 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003193 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003194 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003195 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003196
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003197 // OpenGL ES does not support multisampling with non-rendererable formats
3198 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003199 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003200 (getClientVersion() < ES_3_1 &&
3201 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003202 {
Geoff Langd87878e2014-09-19 15:42:59 -04003203 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003204 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003205 else
3206 {
3207 // We may have limited the max samples for some required renderbuffer formats due to
3208 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3209 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3210
3211 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3212 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3213 // exception of signed and unsigned integer formats."
3214 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3215 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3216 {
3217 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3218 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3219 }
3220
3221 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3222 if (getClientVersion() >= ES_3_1)
3223 {
3224 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3225 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3226 // the exception that the signed and unsigned integer formats are required only to
3227 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3228 // multisamples, which must be at least one."
3229 if (formatInfo.componentType == GL_INT ||
3230 formatInfo.componentType == GL_UNSIGNED_INT)
3231 {
3232 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3233 }
3234
3235 // GLES 3.1 section 19.3.1.
3236 if (formatCaps.texturable)
3237 {
3238 if (formatInfo.depthBits > 0)
3239 {
3240 mCaps.maxDepthTextureSamples =
3241 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3242 }
3243 else if (formatInfo.redBits > 0)
3244 {
3245 mCaps.maxColorTextureSamples =
3246 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3247 }
3248 }
3249 }
3250 }
Geoff Langd87878e2014-09-19 15:42:59 -04003251
3252 if (formatCaps.texturable && formatInfo.compressed)
3253 {
Geoff Langca271392017-04-05 12:30:00 -04003254 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003255 }
3256
Geoff Langca271392017-04-05 12:30:00 -04003257 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003258 }
Jamie Madill32447362017-06-28 14:53:52 -04003259
3260 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003261 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003262 {
3263 mMemoryProgramCache = nullptr;
3264 }
Corentin Walleze4477002017-12-01 14:39:58 -05003265
3266 // Compute which buffer types are allowed
3267 mValidBufferBindings.reset();
3268 mValidBufferBindings.set(BufferBinding::ElementArray);
3269 mValidBufferBindings.set(BufferBinding::Array);
3270
3271 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3272 {
3273 mValidBufferBindings.set(BufferBinding::PixelPack);
3274 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3275 }
3276
3277 if (getClientVersion() >= ES_3_0)
3278 {
3279 mValidBufferBindings.set(BufferBinding::CopyRead);
3280 mValidBufferBindings.set(BufferBinding::CopyWrite);
3281 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3282 mValidBufferBindings.set(BufferBinding::Uniform);
3283 }
3284
3285 if (getClientVersion() >= ES_3_1)
3286 {
3287 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3288 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3289 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3290 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3291 }
Geoff Lang493daf52014-07-03 13:38:44 -04003292}
3293
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003294void Context::initWorkarounds()
3295{
Jamie Madill761b02c2017-06-23 16:27:06 -04003296 // Apply back-end workarounds.
3297 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3298
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003299 // Lose the context upon out of memory error if the application is
3300 // expecting to watch for those events.
3301 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3302}
3303
Jamie Madill05b35b22017-10-03 09:01:44 -04003304Error Context::prepareForDraw()
3305{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003306 if (mGLES1Renderer)
3307 {
3308 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3309 }
3310
Geoff Langa8cb2872018-03-09 16:09:40 -05003311 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003312
3313 if (isRobustResourceInitEnabled())
3314 {
3315 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3316 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3317 }
3318
Geoff Langa8cb2872018-03-09 16:09:40 -05003319 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003320 return NoError();
3321}
3322
3323Error Context::prepareForClear(GLbitfield mask)
3324{
Geoff Langa8cb2872018-03-09 16:09:40 -05003325 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003326 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003327 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003328 return NoError();
3329}
3330
3331Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3332{
Geoff Langa8cb2872018-03-09 16:09:40 -05003333 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003334 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3335 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003336 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003337 return NoError();
3338}
3339
Geoff Langa8cb2872018-03-09 16:09:40 -05003340Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003341{
Geoff Langa8cb2872018-03-09 16:09:40 -05003342 ANGLE_TRY(syncDirtyObjects());
3343 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003344 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003345}
3346
Geoff Langa8cb2872018-03-09 16:09:40 -05003347Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003348{
Geoff Langa8cb2872018-03-09 16:09:40 -05003349 ANGLE_TRY(syncDirtyObjects(objectMask));
3350 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003351 return NoError();
3352}
3353
Geoff Langa8cb2872018-03-09 16:09:40 -05003354Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003355{
3356 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3357 mImplementation->syncState(this, dirtyBits);
3358 mGLState.clearDirtyBits();
3359 return NoError();
3360}
3361
Geoff Langa8cb2872018-03-09 16:09:40 -05003362Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003363{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003364 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003365 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003366 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003367 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003368}
Jamie Madillc29968b2016-01-20 11:17:23 -05003369
Geoff Langa8cb2872018-03-09 16:09:40 -05003370Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003371{
3372 return mGLState.syncDirtyObjects(this);
3373}
3374
Geoff Langa8cb2872018-03-09 16:09:40 -05003375Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003376{
3377 return mGLState.syncDirtyObjects(this, objectMask);
3378}
3379
Jamie Madillc29968b2016-01-20 11:17:23 -05003380void Context::blitFramebuffer(GLint srcX0,
3381 GLint srcY0,
3382 GLint srcX1,
3383 GLint srcY1,
3384 GLint dstX0,
3385 GLint dstY0,
3386 GLint dstX1,
3387 GLint dstY1,
3388 GLbitfield mask,
3389 GLenum filter)
3390{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003391 if (mask == 0)
3392 {
3393 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3394 // buffers are copied.
3395 return;
3396 }
3397
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003398 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003399 ASSERT(drawFramebuffer);
3400
3401 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3402 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3403
Jamie Madillbc918e72018-03-08 09:47:21 -05003404 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003405
Jamie Madillc564c072017-06-01 12:45:42 -04003406 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003407}
Jamie Madillc29968b2016-01-20 11:17:23 -05003408
3409void Context::clear(GLbitfield mask)
3410{
Geoff Langd4fff502017-09-22 11:28:28 -04003411 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3412 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003413}
3414
3415void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3416{
Geoff Langd4fff502017-09-22 11:28:28 -04003417 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3418 ANGLE_CONTEXT_TRY(
3419 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003420}
3421
3422void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3423{
Geoff Langd4fff502017-09-22 11:28:28 -04003424 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3425 ANGLE_CONTEXT_TRY(
3426 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003427}
3428
3429void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3430{
Geoff Langd4fff502017-09-22 11:28:28 -04003431 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3432 ANGLE_CONTEXT_TRY(
3433 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003434}
3435
3436void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3437{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003438 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003439 ASSERT(framebufferObject);
3440
3441 // If a buffer is not present, the clear has no effect
3442 if (framebufferObject->getDepthbuffer() == nullptr &&
3443 framebufferObject->getStencilbuffer() == nullptr)
3444 {
3445 return;
3446 }
3447
Geoff Langd4fff502017-09-22 11:28:28 -04003448 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3449 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003450}
3451
3452void Context::readPixels(GLint x,
3453 GLint y,
3454 GLsizei width,
3455 GLsizei height,
3456 GLenum format,
3457 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003458 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003459{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003460 if (width == 0 || height == 0)
3461 {
3462 return;
3463 }
3464
Jamie Madillbc918e72018-03-08 09:47:21 -05003465 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003466
Jamie Madillb6664922017-07-25 12:55:04 -04003467 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3468 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003469
3470 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003471 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003472}
3473
Brandon Jones59770802018-04-02 13:18:42 -07003474void Context::readPixelsRobust(GLint x,
3475 GLint y,
3476 GLsizei width,
3477 GLsizei height,
3478 GLenum format,
3479 GLenum type,
3480 GLsizei bufSize,
3481 GLsizei *length,
3482 GLsizei *columns,
3483 GLsizei *rows,
3484 void *pixels)
3485{
3486 readPixels(x, y, width, height, format, type, pixels);
3487}
3488
3489void Context::readnPixelsRobust(GLint x,
3490 GLint y,
3491 GLsizei width,
3492 GLsizei height,
3493 GLenum format,
3494 GLenum type,
3495 GLsizei bufSize,
3496 GLsizei *length,
3497 GLsizei *columns,
3498 GLsizei *rows,
3499 void *data)
3500{
3501 readPixels(x, y, width, height, format, type, data);
3502}
3503
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003504void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003505 GLint level,
3506 GLenum internalformat,
3507 GLint x,
3508 GLint y,
3509 GLsizei width,
3510 GLsizei height,
3511 GLint border)
3512{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003513 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003514 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003515
Jamie Madillc29968b2016-01-20 11:17:23 -05003516 Rectangle sourceArea(x, y, width, height);
3517
Jamie Madill05b35b22017-10-03 09:01:44 -04003518 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003519 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003520 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003521}
3522
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003523void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003524 GLint level,
3525 GLint xoffset,
3526 GLint yoffset,
3527 GLint x,
3528 GLint y,
3529 GLsizei width,
3530 GLsizei height)
3531{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003532 if (width == 0 || height == 0)
3533 {
3534 return;
3535 }
3536
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003537 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003538 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003539
Jamie Madillc29968b2016-01-20 11:17:23 -05003540 Offset destOffset(xoffset, yoffset, 0);
3541 Rectangle sourceArea(x, y, width, height);
3542
Jamie Madill05b35b22017-10-03 09:01:44 -04003543 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003544 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003545 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003546}
3547
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003548void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003549 GLint level,
3550 GLint xoffset,
3551 GLint yoffset,
3552 GLint zoffset,
3553 GLint x,
3554 GLint y,
3555 GLsizei width,
3556 GLsizei height)
3557{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003558 if (width == 0 || height == 0)
3559 {
3560 return;
3561 }
3562
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003563 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003564 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003565
Jamie Madillc29968b2016-01-20 11:17:23 -05003566 Offset destOffset(xoffset, yoffset, zoffset);
3567 Rectangle sourceArea(x, y, width, height);
3568
Jamie Madill05b35b22017-10-03 09:01:44 -04003569 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3570 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003571 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3572 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003573}
3574
3575void Context::framebufferTexture2D(GLenum target,
3576 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003577 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003578 GLuint texture,
3579 GLint level)
3580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003581 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003582 ASSERT(framebuffer);
3583
3584 if (texture != 0)
3585 {
3586 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003587 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003588 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003589 }
3590 else
3591 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003592 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003593 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003594
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003596}
3597
3598void Context::framebufferRenderbuffer(GLenum target,
3599 GLenum attachment,
3600 GLenum renderbuffertarget,
3601 GLuint renderbuffer)
3602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003604 ASSERT(framebuffer);
3605
3606 if (renderbuffer != 0)
3607 {
3608 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003609
Jamie Madillcc129372018-04-12 09:13:18 -04003610 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003611 renderbufferObject);
3612 }
3613 else
3614 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003615 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003616 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003617
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003619}
3620
3621void Context::framebufferTextureLayer(GLenum target,
3622 GLenum attachment,
3623 GLuint texture,
3624 GLint level,
3625 GLint layer)
3626{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003627 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003628 ASSERT(framebuffer);
3629
3630 if (texture != 0)
3631 {
3632 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003633 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003634 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003635 }
3636 else
3637 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003638 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003639 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003640
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003642}
3643
Brandon Jones59770802018-04-02 13:18:42 -07003644void Context::framebufferTextureMultiviewLayered(GLenum target,
3645 GLenum attachment,
3646 GLuint texture,
3647 GLint level,
3648 GLint baseViewIndex,
3649 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003650{
Martin Radev82ef7742017-08-08 17:44:58 +03003651 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3652 ASSERT(framebuffer);
3653
3654 if (texture != 0)
3655 {
3656 Texture *textureObj = getTexture(texture);
3657
Martin Radev18b75ba2017-08-15 15:50:40 +03003658 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003659 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3660 numViews, baseViewIndex);
3661 }
3662 else
3663 {
3664 framebuffer->resetAttachment(this, attachment);
3665 }
3666
3667 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003668}
3669
Brandon Jones59770802018-04-02 13:18:42 -07003670void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3671 GLenum attachment,
3672 GLuint texture,
3673 GLint level,
3674 GLsizei numViews,
3675 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003676{
Martin Radev5dae57b2017-07-14 16:15:55 +03003677 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3678 ASSERT(framebuffer);
3679
3680 if (texture != 0)
3681 {
3682 Texture *textureObj = getTexture(texture);
3683
3684 ImageIndex index = ImageIndex::Make2D(level);
3685 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3686 textureObj, numViews, viewportOffsets);
3687 }
3688 else
3689 {
3690 framebuffer->resetAttachment(this, attachment);
3691 }
3692
3693 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003694}
3695
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003696// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3697void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3698{
3699 UNIMPLEMENTED();
3700}
3701
Jamie Madillc29968b2016-01-20 11:17:23 -05003702void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003705 ASSERT(framebuffer);
3706 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003708}
3709
3710void Context::readBuffer(GLenum mode)
3711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003715}
3716
3717void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3718{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003719 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003720 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003721
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 ASSERT(framebuffer);
3724
3725 // The specification isn't clear what should be done when the framebuffer isn't complete.
3726 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003727 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003728}
3729
3730void Context::invalidateFramebuffer(GLenum target,
3731 GLsizei numAttachments,
3732 const GLenum *attachments)
3733{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003734 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003735 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003736
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 ASSERT(framebuffer);
3739
Jamie Madill427064d2018-04-13 16:20:34 -04003740 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003741 {
Jamie Madill437fa652016-05-03 15:13:24 -04003742 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003743 }
Jamie Madill437fa652016-05-03 15:13:24 -04003744
Jamie Madill4928b7c2017-06-20 12:57:39 -04003745 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003746}
3747
3748void Context::invalidateSubFramebuffer(GLenum target,
3749 GLsizei numAttachments,
3750 const GLenum *attachments,
3751 GLint x,
3752 GLint y,
3753 GLsizei width,
3754 GLsizei height)
3755{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003756 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003757 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003758
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003759 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003760 ASSERT(framebuffer);
3761
Jamie Madill427064d2018-04-13 16:20:34 -04003762 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003763 {
Jamie Madill437fa652016-05-03 15:13:24 -04003764 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003765 }
Jamie Madill437fa652016-05-03 15:13:24 -04003766
3767 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003768 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003769}
3770
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003771void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003772 GLint level,
3773 GLint internalformat,
3774 GLsizei width,
3775 GLsizei height,
3776 GLint border,
3777 GLenum format,
3778 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003779 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003780{
Jamie Madillbc918e72018-03-08 09:47:21 -05003781 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003782
3783 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003784 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003785 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3786 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003787}
3788
Brandon Jones59770802018-04-02 13:18:42 -07003789void Context::texImage2DRobust(TextureTarget target,
3790 GLint level,
3791 GLint internalformat,
3792 GLsizei width,
3793 GLsizei height,
3794 GLint border,
3795 GLenum format,
3796 GLenum type,
3797 GLsizei bufSize,
3798 const void *pixels)
3799{
3800 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3801}
3802
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003803void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003804 GLint level,
3805 GLint internalformat,
3806 GLsizei width,
3807 GLsizei height,
3808 GLsizei depth,
3809 GLint border,
3810 GLenum format,
3811 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003812 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003813{
Jamie Madillbc918e72018-03-08 09:47:21 -05003814 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003815
3816 Extents size(width, height, depth);
3817 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003818 handleError(texture->setImage(this, mGLState.getUnpackState(),
3819 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3820 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003821}
3822
Brandon Jones59770802018-04-02 13:18:42 -07003823void Context::texImage3DRobust(TextureType target,
3824 GLint level,
3825 GLint internalformat,
3826 GLsizei width,
3827 GLsizei height,
3828 GLsizei depth,
3829 GLint border,
3830 GLenum format,
3831 GLenum type,
3832 GLsizei bufSize,
3833 const void *pixels)
3834{
3835 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3836}
3837
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003838void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003839 GLint level,
3840 GLint xoffset,
3841 GLint yoffset,
3842 GLsizei width,
3843 GLsizei height,
3844 GLenum format,
3845 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003846 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003847{
3848 // Zero sized uploads are valid but no-ops
3849 if (width == 0 || height == 0)
3850 {
3851 return;
3852 }
3853
Jamie Madillbc918e72018-03-08 09:47:21 -05003854 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003855
3856 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003857 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003858 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3859 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003860}
3861
Brandon Jones59770802018-04-02 13:18:42 -07003862void Context::texSubImage2DRobust(TextureTarget target,
3863 GLint level,
3864 GLint xoffset,
3865 GLint yoffset,
3866 GLsizei width,
3867 GLsizei height,
3868 GLenum format,
3869 GLenum type,
3870 GLsizei bufSize,
3871 const void *pixels)
3872{
3873 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3874}
3875
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003876void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003877 GLint level,
3878 GLint xoffset,
3879 GLint yoffset,
3880 GLint zoffset,
3881 GLsizei width,
3882 GLsizei height,
3883 GLsizei depth,
3884 GLenum format,
3885 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003886 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003887{
3888 // Zero sized uploads are valid but no-ops
3889 if (width == 0 || height == 0 || depth == 0)
3890 {
3891 return;
3892 }
3893
Jamie Madillbc918e72018-03-08 09:47:21 -05003894 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003895
3896 Box area(xoffset, yoffset, zoffset, width, height, depth);
3897 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003898 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3899 NonCubeTextureTypeToTarget(target), level, area, format, type,
3900 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003901}
3902
Brandon Jones59770802018-04-02 13:18:42 -07003903void Context::texSubImage3DRobust(TextureType target,
3904 GLint level,
3905 GLint xoffset,
3906 GLint yoffset,
3907 GLint zoffset,
3908 GLsizei width,
3909 GLsizei height,
3910 GLsizei depth,
3911 GLenum format,
3912 GLenum type,
3913 GLsizei bufSize,
3914 const void *pixels)
3915{
3916 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3917 pixels);
3918}
3919
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003920void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003921 GLint level,
3922 GLenum internalformat,
3923 GLsizei width,
3924 GLsizei height,
3925 GLint border,
3926 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003927 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003928{
Jamie Madillbc918e72018-03-08 09:47:21 -05003929 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003930
3931 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003932 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003933 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3934 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003935 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003936}
3937
Brandon Jones59770802018-04-02 13:18:42 -07003938void Context::compressedTexImage2DRobust(TextureTarget target,
3939 GLint level,
3940 GLenum internalformat,
3941 GLsizei width,
3942 GLsizei height,
3943 GLint border,
3944 GLsizei imageSize,
3945 GLsizei dataSize,
3946 const GLvoid *data)
3947{
3948 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3949}
3950
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003951void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003952 GLint level,
3953 GLenum internalformat,
3954 GLsizei width,
3955 GLsizei height,
3956 GLsizei depth,
3957 GLint border,
3958 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003959 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003960{
Jamie Madillbc918e72018-03-08 09:47:21 -05003961 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003962
3963 Extents size(width, height, depth);
3964 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003965 handleError(texture->setCompressedImage(
3966 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3967 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003968}
3969
Brandon Jones59770802018-04-02 13:18:42 -07003970void Context::compressedTexImage3DRobust(TextureType target,
3971 GLint level,
3972 GLenum internalformat,
3973 GLsizei width,
3974 GLsizei height,
3975 GLsizei depth,
3976 GLint border,
3977 GLsizei imageSize,
3978 GLsizei dataSize,
3979 const GLvoid *data)
3980{
3981 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3982 data);
3983}
3984
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003985void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003986 GLint level,
3987 GLint xoffset,
3988 GLint yoffset,
3989 GLsizei width,
3990 GLsizei height,
3991 GLenum format,
3992 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003993 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003994{
Jamie Madillbc918e72018-03-08 09:47:21 -05003995 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003996
3997 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003998 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003999 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4000 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004002}
4003
Brandon Jones59770802018-04-02 13:18:42 -07004004void Context::compressedTexSubImage2DRobust(TextureTarget target,
4005 GLint level,
4006 GLint xoffset,
4007 GLint yoffset,
4008 GLsizei width,
4009 GLsizei height,
4010 GLenum format,
4011 GLsizei imageSize,
4012 GLsizei dataSize,
4013 const GLvoid *data)
4014{
4015 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4016 data);
4017}
4018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004019void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004020 GLint level,
4021 GLint xoffset,
4022 GLint yoffset,
4023 GLint zoffset,
4024 GLsizei width,
4025 GLsizei height,
4026 GLsizei depth,
4027 GLenum format,
4028 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004029 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004030{
4031 // Zero sized uploads are valid but no-ops
4032 if (width == 0 || height == 0)
4033 {
4034 return;
4035 }
4036
Jamie Madillbc918e72018-03-08 09:47:21 -05004037 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004038
4039 Box area(xoffset, yoffset, zoffset, width, height, depth);
4040 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004041 handleError(texture->setCompressedSubImage(
4042 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4043 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004044}
4045
Brandon Jones59770802018-04-02 13:18:42 -07004046void Context::compressedTexSubImage3DRobust(TextureType target,
4047 GLint level,
4048 GLint xoffset,
4049 GLint yoffset,
4050 GLint zoffset,
4051 GLsizei width,
4052 GLsizei height,
4053 GLsizei depth,
4054 GLenum format,
4055 GLsizei imageSize,
4056 GLsizei dataSize,
4057 const GLvoid *data)
4058{
4059 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4060 imageSize, data);
4061}
4062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004063void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004064{
4065 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004066 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004067}
4068
Jamie Madill007530e2017-12-28 14:27:04 -05004069void Context::copyTexture(GLuint sourceId,
4070 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004071 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004072 GLuint destId,
4073 GLint destLevel,
4074 GLint internalFormat,
4075 GLenum destType,
4076 GLboolean unpackFlipY,
4077 GLboolean unpackPremultiplyAlpha,
4078 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004079{
Jamie Madillbc918e72018-03-08 09:47:21 -05004080 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004081
4082 gl::Texture *sourceTexture = getTexture(sourceId);
4083 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004084 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4085 sourceLevel, ConvertToBool(unpackFlipY),
4086 ConvertToBool(unpackPremultiplyAlpha),
4087 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004088}
4089
Jamie Madill007530e2017-12-28 14:27:04 -05004090void Context::copySubTexture(GLuint sourceId,
4091 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004092 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004093 GLuint destId,
4094 GLint destLevel,
4095 GLint xoffset,
4096 GLint yoffset,
4097 GLint x,
4098 GLint y,
4099 GLsizei width,
4100 GLsizei height,
4101 GLboolean unpackFlipY,
4102 GLboolean unpackPremultiplyAlpha,
4103 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004104{
4105 // Zero sized copies are valid but no-ops
4106 if (width == 0 || height == 0)
4107 {
4108 return;
4109 }
4110
Jamie Madillbc918e72018-03-08 09:47:21 -05004111 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004112
4113 gl::Texture *sourceTexture = getTexture(sourceId);
4114 gl::Texture *destTexture = getTexture(destId);
4115 Offset offset(xoffset, yoffset, 0);
4116 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004117 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4118 ConvertToBool(unpackFlipY),
4119 ConvertToBool(unpackPremultiplyAlpha),
4120 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004121}
4122
Jamie Madill007530e2017-12-28 14:27:04 -05004123void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004124{
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004126
4127 gl::Texture *sourceTexture = getTexture(sourceId);
4128 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004129 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004130}
4131
Corentin Wallez336129f2017-10-17 15:55:40 -04004132void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004133{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004134 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004135 ASSERT(buffer);
4136
Geoff Lang496c02d2016-10-20 11:38:11 -07004137 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004138}
4139
Brandon Jones59770802018-04-02 13:18:42 -07004140void Context::getBufferPointervRobust(BufferBinding target,
4141 GLenum pname,
4142 GLsizei bufSize,
4143 GLsizei *length,
4144 void **params)
4145{
4146 getBufferPointerv(target, pname, params);
4147}
4148
Corentin Wallez336129f2017-10-17 15:55:40 -04004149void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004150{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004151 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004152 ASSERT(buffer);
4153
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004154 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004155 if (error.isError())
4156 {
Jamie Madill437fa652016-05-03 15:13:24 -04004157 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004158 return nullptr;
4159 }
4160
4161 return buffer->getMapPointer();
4162}
4163
Corentin Wallez336129f2017-10-17 15:55:40 -04004164GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004165{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004166 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004167 ASSERT(buffer);
4168
4169 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004170 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004171 if (error.isError())
4172 {
Jamie Madill437fa652016-05-03 15:13:24 -04004173 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004174 return GL_FALSE;
4175 }
4176
4177 return result;
4178}
4179
Corentin Wallez336129f2017-10-17 15:55:40 -04004180void *Context::mapBufferRange(BufferBinding target,
4181 GLintptr offset,
4182 GLsizeiptr length,
4183 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004184{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004185 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004186 ASSERT(buffer);
4187
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004188 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004189 if (error.isError())
4190 {
Jamie Madill437fa652016-05-03 15:13:24 -04004191 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004192 return nullptr;
4193 }
4194
4195 return buffer->getMapPointer();
4196}
4197
Corentin Wallez336129f2017-10-17 15:55:40 -04004198void Context::flushMappedBufferRange(BufferBinding /*target*/,
4199 GLintptr /*offset*/,
4200 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004201{
4202 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4203}
4204
Jamie Madillbc918e72018-03-08 09:47:21 -05004205Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004206{
Geoff Langa8cb2872018-03-09 16:09:40 -05004207 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004208}
4209
Jamie Madillbc918e72018-03-08 09:47:21 -05004210Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004211{
Geoff Langa8cb2872018-03-09 16:09:40 -05004212 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004213}
4214
Jamie Madillbc918e72018-03-08 09:47:21 -05004215Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004216{
Geoff Langa8cb2872018-03-09 16:09:40 -05004217 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004218}
4219
Jiajia Qin5451d532017-11-16 17:16:34 +08004220void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4221{
4222 UNIMPLEMENTED();
4223}
4224
Jamie Madillc20ab272016-06-09 07:20:46 -07004225void Context::activeTexture(GLenum texture)
4226{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004227 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004228}
4229
Jamie Madill876429b2017-04-20 15:46:24 -04004230void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004231{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004232 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004233}
4234
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004235void Context::blendEquation(GLenum mode)
4236{
4237 mGLState.setBlendEquation(mode, mode);
4238}
4239
Jamie Madillc20ab272016-06-09 07:20:46 -07004240void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4241{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004242 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004243}
4244
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004245void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4246{
4247 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4248}
4249
Jamie Madillc20ab272016-06-09 07:20:46 -07004250void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004252 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004253}
4254
Jamie Madill876429b2017-04-20 15:46:24 -04004255void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004256{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004257 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004258}
4259
Jamie Madill876429b2017-04-20 15:46:24 -04004260void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004261{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004262 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004263}
4264
4265void Context::clearStencil(GLint s)
4266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004267 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004268}
4269
4270void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4271{
Geoff Lang92019432017-11-20 13:09:34 -05004272 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4273 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004274}
4275
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004276void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004277{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004278 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004279}
4280
4281void Context::depthFunc(GLenum func)
4282{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004283 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004284}
4285
4286void Context::depthMask(GLboolean flag)
4287{
Geoff Lang92019432017-11-20 13:09:34 -05004288 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004289}
4290
Jamie Madill876429b2017-04-20 15:46:24 -04004291void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004292{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004293 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004294}
4295
4296void Context::disable(GLenum cap)
4297{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004298 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004299}
4300
4301void Context::disableVertexAttribArray(GLuint index)
4302{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004303 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004304}
4305
4306void Context::enable(GLenum cap)
4307{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309}
4310
4311void Context::enableVertexAttribArray(GLuint index)
4312{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004314}
4315
4316void Context::frontFace(GLenum mode)
4317{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004319}
4320
4321void Context::hint(GLenum target, GLenum mode)
4322{
4323 switch (target)
4324 {
4325 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004326 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004327 break;
4328
4329 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331 break;
4332
4333 default:
4334 UNREACHABLE();
4335 return;
4336 }
4337}
4338
4339void Context::lineWidth(GLfloat width)
4340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004341 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004342}
4343
4344void Context::pixelStorei(GLenum pname, GLint param)
4345{
4346 switch (pname)
4347 {
4348 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004349 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004350 break;
4351
4352 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354 break;
4355
4356 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004357 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004358 break;
4359
4360 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004361 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004362 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004363 break;
4364
4365 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004366 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004367 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004368 break;
4369
4370 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004371 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004372 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004373 break;
4374
4375 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004376 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378 break;
4379
4380 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004381 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383 break;
4384
4385 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004386 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004388 break;
4389
4390 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004391 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393 break;
4394
4395 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004396 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398 break;
4399
4400 default:
4401 UNREACHABLE();
4402 return;
4403 }
4404}
4405
4406void Context::polygonOffset(GLfloat factor, GLfloat units)
4407{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004408 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004409}
4410
Jamie Madill876429b2017-04-20 15:46:24 -04004411void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004412{
Geoff Lang92019432017-11-20 13:09:34 -05004413 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004414}
4415
Jiawei Shaodb342272017-09-27 10:21:45 +08004416void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4417{
4418 mGLState.setSampleMaskParams(maskNumber, mask);
4419}
4420
Jamie Madillc20ab272016-06-09 07:20:46 -07004421void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4422{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
4426void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4427{
4428 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4429 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431 }
4432
4433 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4434 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436 }
4437}
4438
4439void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4440{
4441 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4442 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004443 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004444 }
4445
4446 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4447 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449 }
4450}
4451
4452void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4453{
4454 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4455 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457 }
4458
4459 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4460 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462 }
4463}
4464
4465void Context::vertexAttrib1f(GLuint index, GLfloat x)
4466{
4467 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004469}
4470
4471void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4472{
4473 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004475}
4476
4477void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4478{
4479 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
4483void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4484{
4485 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487}
4488
4489void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4490{
4491 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
4495void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4496{
4497 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499}
4500
4501void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4502{
4503 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505}
4506
4507void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
4512void Context::vertexAttribPointer(GLuint index,
4513 GLint size,
4514 GLenum type,
4515 GLboolean normalized,
4516 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004517 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004518{
Corentin Wallez336129f2017-10-17 15:55:40 -04004519 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004520 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004521}
4522
Shao80957d92017-02-20 21:25:59 +08004523void Context::vertexAttribFormat(GLuint attribIndex,
4524 GLint size,
4525 GLenum type,
4526 GLboolean normalized,
4527 GLuint relativeOffset)
4528{
Geoff Lang92019432017-11-20 13:09:34 -05004529 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004530 relativeOffset);
4531}
4532
4533void Context::vertexAttribIFormat(GLuint attribIndex,
4534 GLint size,
4535 GLenum type,
4536 GLuint relativeOffset)
4537{
4538 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4539}
4540
4541void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4542{
Shaodde78e82017-05-22 14:13:27 +08004543 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004544}
4545
Jiajia Qin5451d532017-11-16 17:16:34 +08004546void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004547{
4548 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4549}
4550
Jamie Madillc20ab272016-06-09 07:20:46 -07004551void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4552{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004553 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554}
4555
4556void Context::vertexAttribIPointer(GLuint index,
4557 GLint size,
4558 GLenum type,
4559 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004560 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004561{
Corentin Wallez336129f2017-10-17 15:55:40 -04004562 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4563 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564}
4565
4566void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4567{
4568 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570}
4571
4572void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4573{
4574 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004575 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576}
4577
4578void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004588void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4589{
4590 const VertexAttribCurrentValueData &currentValues =
4591 getGLState().getVertexAttribCurrentValue(index);
4592 const VertexArray *vao = getGLState().getVertexArray();
4593 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4594 currentValues, pname, params);
4595}
4596
Brandon Jones59770802018-04-02 13:18:42 -07004597void Context::getVertexAttribivRobust(GLuint index,
4598 GLenum pname,
4599 GLsizei bufSize,
4600 GLsizei *length,
4601 GLint *params)
4602{
4603 getVertexAttribiv(index, pname, params);
4604}
4605
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004606void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4607{
4608 const VertexAttribCurrentValueData &currentValues =
4609 getGLState().getVertexAttribCurrentValue(index);
4610 const VertexArray *vao = getGLState().getVertexArray();
4611 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4612 currentValues, pname, params);
4613}
4614
Brandon Jones59770802018-04-02 13:18:42 -07004615void Context::getVertexAttribfvRobust(GLuint index,
4616 GLenum pname,
4617 GLsizei bufSize,
4618 GLsizei *length,
4619 GLfloat *params)
4620{
4621 getVertexAttribfv(index, pname, params);
4622}
4623
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004624void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4625{
4626 const VertexAttribCurrentValueData &currentValues =
4627 getGLState().getVertexAttribCurrentValue(index);
4628 const VertexArray *vao = getGLState().getVertexArray();
4629 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4630 currentValues, pname, params);
4631}
4632
Brandon Jones59770802018-04-02 13:18:42 -07004633void Context::getVertexAttribIivRobust(GLuint index,
4634 GLenum pname,
4635 GLsizei bufSize,
4636 GLsizei *length,
4637 GLint *params)
4638{
4639 getVertexAttribIiv(index, pname, params);
4640}
4641
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004642void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4643{
4644 const VertexAttribCurrentValueData &currentValues =
4645 getGLState().getVertexAttribCurrentValue(index);
4646 const VertexArray *vao = getGLState().getVertexArray();
4647 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4648 currentValues, pname, params);
4649}
4650
Brandon Jones59770802018-04-02 13:18:42 -07004651void Context::getVertexAttribIuivRobust(GLuint index,
4652 GLenum pname,
4653 GLsizei bufSize,
4654 GLsizei *length,
4655 GLuint *params)
4656{
4657 getVertexAttribIuiv(index, pname, params);
4658}
4659
Jamie Madill876429b2017-04-20 15:46:24 -04004660void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004661{
4662 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4663 QueryVertexAttribPointerv(attrib, pname, pointer);
4664}
4665
Brandon Jones59770802018-04-02 13:18:42 -07004666void Context::getVertexAttribPointervRobust(GLuint index,
4667 GLenum pname,
4668 GLsizei bufSize,
4669 GLsizei *length,
4670 void **pointer)
4671{
4672 getVertexAttribPointerv(index, pname, pointer);
4673}
4674
Jamie Madillc20ab272016-06-09 07:20:46 -07004675void Context::debugMessageControl(GLenum source,
4676 GLenum type,
4677 GLenum severity,
4678 GLsizei count,
4679 const GLuint *ids,
4680 GLboolean enabled)
4681{
4682 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004683 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004684 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004685}
4686
4687void Context::debugMessageInsert(GLenum source,
4688 GLenum type,
4689 GLuint id,
4690 GLenum severity,
4691 GLsizei length,
4692 const GLchar *buf)
4693{
4694 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004695 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004696}
4697
4698void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004700 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004701}
4702
4703GLuint Context::getDebugMessageLog(GLuint count,
4704 GLsizei bufSize,
4705 GLenum *sources,
4706 GLenum *types,
4707 GLuint *ids,
4708 GLenum *severities,
4709 GLsizei *lengths,
4710 GLchar *messageLog)
4711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4713 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004714}
4715
4716void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4717{
4718 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004720 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004721}
4722
4723void Context::popDebugGroup()
4724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004725 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004726 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004727}
4728
Corentin Wallez336129f2017-10-17 15:55:40 -04004729void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004730{
4731 Buffer *buffer = mGLState.getTargetBuffer(target);
4732 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004733 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004734}
4735
Corentin Wallez336129f2017-10-17 15:55:40 -04004736void Context::bufferSubData(BufferBinding target,
4737 GLintptr offset,
4738 GLsizeiptr size,
4739 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004740{
4741 if (data == nullptr)
4742 {
4743 return;
4744 }
4745
4746 Buffer *buffer = mGLState.getTargetBuffer(target);
4747 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004748 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004749}
4750
Jamie Madillef300b12016-10-07 15:12:09 -04004751void Context::attachShader(GLuint program, GLuint shader)
4752{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004753 Program *programObject = mState.mShaderPrograms->getProgram(program);
4754 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004755 ASSERT(programObject && shaderObject);
4756 programObject->attachShader(shaderObject);
4757}
4758
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004759const Workarounds &Context::getWorkarounds() const
4760{
4761 return mWorkarounds;
4762}
4763
Corentin Wallez336129f2017-10-17 15:55:40 -04004764void Context::copyBufferSubData(BufferBinding readTarget,
4765 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004766 GLintptr readOffset,
4767 GLintptr writeOffset,
4768 GLsizeiptr size)
4769{
4770 // if size is zero, the copy is a successful no-op
4771 if (size == 0)
4772 {
4773 return;
4774 }
4775
4776 // TODO(jmadill): cache these.
4777 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4778 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4779
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004780 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004781}
4782
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4784{
4785 Program *programObject = getProgram(program);
4786 // TODO(jmadill): Re-use this from the validation if possible.
4787 ASSERT(programObject);
4788 programObject->bindAttributeLocation(index, name);
4789}
4790
Corentin Wallez336129f2017-10-17 15:55:40 -04004791void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004792{
Corentin Wallez336129f2017-10-17 15:55:40 -04004793 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4794 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004795}
4796
Corentin Wallez336129f2017-10-17 15:55:40 -04004797void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004798{
4799 bindBufferRange(target, index, buffer, 0, 0);
4800}
4801
Corentin Wallez336129f2017-10-17 15:55:40 -04004802void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004803 GLuint index,
4804 GLuint buffer,
4805 GLintptr offset,
4806 GLsizeiptr size)
4807{
Corentin Wallez336129f2017-10-17 15:55:40 -04004808 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4809 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004810}
4811
Jamie Madill01a80ee2016-11-07 12:06:18 -05004812void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4813{
4814 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4815 {
4816 bindReadFramebuffer(framebuffer);
4817 }
4818
4819 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4820 {
4821 bindDrawFramebuffer(framebuffer);
4822 }
4823}
4824
4825void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4826{
4827 ASSERT(target == GL_RENDERBUFFER);
4828 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004829 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004830 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004831}
4832
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004833void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004834 GLsizei samples,
4835 GLenum internalformat,
4836 GLsizei width,
4837 GLsizei height,
4838 GLboolean fixedsamplelocations)
4839{
4840 Extents size(width, height, 1);
4841 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004842 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4843 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004844}
4845
4846void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4847{
JiangYizhou5b03f472017-01-09 10:22:53 +08004848 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4849 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004850 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004851 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004852
4853 switch (pname)
4854 {
4855 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004856 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004857 break;
4858 default:
4859 UNREACHABLE();
4860 }
4861}
4862
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004863void Context::getMultisamplefvRobust(GLenum pname,
4864 GLuint index,
4865 GLsizei bufSize,
4866 GLsizei *length,
4867 GLfloat *val)
4868{
4869 UNIMPLEMENTED();
4870}
4871
Jamie Madille8fb6402017-02-14 17:56:40 -05004872void Context::renderbufferStorage(GLenum target,
4873 GLenum internalformat,
4874 GLsizei width,
4875 GLsizei height)
4876{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004877 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4878 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4879
Jamie Madille8fb6402017-02-14 17:56:40 -05004880 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004881 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004882}
4883
4884void Context::renderbufferStorageMultisample(GLenum target,
4885 GLsizei samples,
4886 GLenum internalformat,
4887 GLsizei width,
4888 GLsizei height)
4889{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004890 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4891 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004892
4893 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004894 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004895 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004896}
4897
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004898void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4899{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004900 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004901 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004902}
4903
JiangYizhoue18e6392017-02-20 10:32:23 +08004904void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4905{
4906 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4907 QueryFramebufferParameteriv(framebuffer, pname, params);
4908}
4909
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004910void Context::getFramebufferParameterivRobust(GLenum target,
4911 GLenum pname,
4912 GLsizei bufSize,
4913 GLsizei *length,
4914 GLint *params)
4915{
4916 UNIMPLEMENTED();
4917}
4918
Jiajia Qin5451d532017-11-16 17:16:34 +08004919void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004920{
4921 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4922 SetFramebufferParameteri(framebuffer, pname, param);
4923}
4924
Jamie Madillb3f26b92017-07-19 15:07:41 -04004925Error Context::getScratchBuffer(size_t requstedSizeBytes,
4926 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004927{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004928 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4929 {
4930 return OutOfMemory() << "Failed to allocate internal buffer.";
4931 }
4932 return NoError();
4933}
4934
4935Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4936 angle::MemoryBuffer **zeroBufferOut) const
4937{
4938 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004939 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004940 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004941 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004942 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004943}
4944
Xinghua Cao10a4d432017-11-28 14:46:26 +08004945Error Context::prepareForDispatch()
4946{
Geoff Langa8cb2872018-03-09 16:09:40 -05004947 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004948
4949 if (isRobustResourceInitEnabled())
4950 {
4951 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4952 }
4953
4954 return NoError();
4955}
4956
Xinghua Cao2b396592017-03-29 15:36:04 +08004957void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4958{
4959 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4960 {
4961 return;
4962 }
4963
Xinghua Cao10a4d432017-11-28 14:46:26 +08004964 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004965 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004966}
4967
Jiajia Qin5451d532017-11-16 17:16:34 +08004968void Context::dispatchComputeIndirect(GLintptr indirect)
4969{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004970 ANGLE_CONTEXT_TRY(prepareForDispatch());
4971 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004972}
4973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004974void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004975 GLsizei levels,
4976 GLenum internalFormat,
4977 GLsizei width,
4978 GLsizei height)
4979{
4980 Extents size(width, height, 1);
4981 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004982 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004983}
4984
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004985void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004986 GLsizei levels,
4987 GLenum internalFormat,
4988 GLsizei width,
4989 GLsizei height,
4990 GLsizei depth)
4991{
4992 Extents size(width, height, depth);
4993 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004994 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004995}
4996
Jiajia Qin5451d532017-11-16 17:16:34 +08004997void Context::memoryBarrier(GLbitfield barriers)
4998{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004999 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005000}
5001
5002void Context::memoryBarrierByRegion(GLbitfield barriers)
5003{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005004 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005005}
5006
Jamie Madillc1d770e2017-04-13 17:31:24 -04005007GLenum Context::checkFramebufferStatus(GLenum target)
5008{
5009 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5010 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005011 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005012}
5013
5014void Context::compileShader(GLuint shader)
5015{
5016 Shader *shaderObject = GetValidShader(this, shader);
5017 if (!shaderObject)
5018 {
5019 return;
5020 }
5021 shaderObject->compile(this);
5022}
5023
5024void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5025{
5026 for (int i = 0; i < n; i++)
5027 {
5028 deleteBuffer(buffers[i]);
5029 }
5030}
5031
5032void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5033{
5034 for (int i = 0; i < n; i++)
5035 {
5036 if (framebuffers[i] != 0)
5037 {
5038 deleteFramebuffer(framebuffers[i]);
5039 }
5040 }
5041}
5042
5043void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5044{
5045 for (int i = 0; i < n; i++)
5046 {
5047 deleteRenderbuffer(renderbuffers[i]);
5048 }
5049}
5050
5051void Context::deleteTextures(GLsizei n, const GLuint *textures)
5052{
5053 for (int i = 0; i < n; i++)
5054 {
5055 if (textures[i] != 0)
5056 {
5057 deleteTexture(textures[i]);
5058 }
5059 }
5060}
5061
5062void Context::detachShader(GLuint program, GLuint shader)
5063{
5064 Program *programObject = getProgram(program);
5065 ASSERT(programObject);
5066
5067 Shader *shaderObject = getShader(shader);
5068 ASSERT(shaderObject);
5069
5070 programObject->detachShader(this, shaderObject);
5071}
5072
5073void Context::genBuffers(GLsizei n, GLuint *buffers)
5074{
5075 for (int i = 0; i < n; i++)
5076 {
5077 buffers[i] = createBuffer();
5078 }
5079}
5080
5081void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5082{
5083 for (int i = 0; i < n; i++)
5084 {
5085 framebuffers[i] = createFramebuffer();
5086 }
5087}
5088
5089void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5090{
5091 for (int i = 0; i < n; i++)
5092 {
5093 renderbuffers[i] = createRenderbuffer();
5094 }
5095}
5096
5097void Context::genTextures(GLsizei n, GLuint *textures)
5098{
5099 for (int i = 0; i < n; i++)
5100 {
5101 textures[i] = createTexture();
5102 }
5103}
5104
5105void Context::getActiveAttrib(GLuint program,
5106 GLuint index,
5107 GLsizei bufsize,
5108 GLsizei *length,
5109 GLint *size,
5110 GLenum *type,
5111 GLchar *name)
5112{
5113 Program *programObject = getProgram(program);
5114 ASSERT(programObject);
5115 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5116}
5117
5118void Context::getActiveUniform(GLuint program,
5119 GLuint index,
5120 GLsizei bufsize,
5121 GLsizei *length,
5122 GLint *size,
5123 GLenum *type,
5124 GLchar *name)
5125{
5126 Program *programObject = getProgram(program);
5127 ASSERT(programObject);
5128 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5129}
5130
5131void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5132{
5133 Program *programObject = getProgram(program);
5134 ASSERT(programObject);
5135 programObject->getAttachedShaders(maxcount, count, shaders);
5136}
5137
5138GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5139{
5140 Program *programObject = getProgram(program);
5141 ASSERT(programObject);
5142 return programObject->getAttributeLocation(name);
5143}
5144
5145void Context::getBooleanv(GLenum pname, GLboolean *params)
5146{
5147 GLenum nativeType;
5148 unsigned int numParams = 0;
5149 getQueryParameterInfo(pname, &nativeType, &numParams);
5150
5151 if (nativeType == GL_BOOL)
5152 {
5153 getBooleanvImpl(pname, params);
5154 }
5155 else
5156 {
5157 CastStateValues(this, nativeType, pname, numParams, params);
5158 }
5159}
5160
Brandon Jones59770802018-04-02 13:18:42 -07005161void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5162{
5163 getBooleanv(pname, params);
5164}
5165
Jamie Madillc1d770e2017-04-13 17:31:24 -04005166void Context::getFloatv(GLenum pname, GLfloat *params)
5167{
5168 GLenum nativeType;
5169 unsigned int numParams = 0;
5170 getQueryParameterInfo(pname, &nativeType, &numParams);
5171
5172 if (nativeType == GL_FLOAT)
5173 {
5174 getFloatvImpl(pname, params);
5175 }
5176 else
5177 {
5178 CastStateValues(this, nativeType, pname, numParams, params);
5179 }
5180}
5181
Brandon Jones59770802018-04-02 13:18:42 -07005182void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5183{
5184 getFloatv(pname, params);
5185}
5186
Jamie Madillc1d770e2017-04-13 17:31:24 -04005187void Context::getIntegerv(GLenum pname, GLint *params)
5188{
5189 GLenum nativeType;
5190 unsigned int numParams = 0;
5191 getQueryParameterInfo(pname, &nativeType, &numParams);
5192
5193 if (nativeType == GL_INT)
5194 {
5195 getIntegervImpl(pname, params);
5196 }
5197 else
5198 {
5199 CastStateValues(this, nativeType, pname, numParams, params);
5200 }
5201}
5202
Brandon Jones59770802018-04-02 13:18:42 -07005203void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5204{
5205 getIntegerv(pname, data);
5206}
5207
Jamie Madillc1d770e2017-04-13 17:31:24 -04005208void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5209{
5210 Program *programObject = getProgram(program);
5211 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005212 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005213}
5214
Brandon Jones59770802018-04-02 13:18:42 -07005215void Context::getProgramivRobust(GLuint program,
5216 GLenum pname,
5217 GLsizei bufSize,
5218 GLsizei *length,
5219 GLint *params)
5220{
5221 getProgramiv(program, pname, params);
5222}
5223
Jiajia Qin5451d532017-11-16 17:16:34 +08005224void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5225{
5226 UNIMPLEMENTED();
5227}
5228
Jamie Madillbe849e42017-05-02 15:49:00 -04005229void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005230{
5231 Program *programObject = getProgram(program);
5232 ASSERT(programObject);
5233 programObject->getInfoLog(bufsize, length, infolog);
5234}
5235
Jiajia Qin5451d532017-11-16 17:16:34 +08005236void Context::getProgramPipelineInfoLog(GLuint pipeline,
5237 GLsizei bufSize,
5238 GLsizei *length,
5239 GLchar *infoLog)
5240{
5241 UNIMPLEMENTED();
5242}
5243
Jamie Madillc1d770e2017-04-13 17:31:24 -04005244void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5245{
5246 Shader *shaderObject = getShader(shader);
5247 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005248 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005249}
5250
Brandon Jones59770802018-04-02 13:18:42 -07005251void Context::getShaderivRobust(GLuint shader,
5252 GLenum pname,
5253 GLsizei bufSize,
5254 GLsizei *length,
5255 GLint *params)
5256{
5257 getShaderiv(shader, pname, params);
5258}
5259
Jamie Madillc1d770e2017-04-13 17:31:24 -04005260void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5261{
5262 Shader *shaderObject = getShader(shader);
5263 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005264 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005265}
5266
5267void Context::getShaderPrecisionFormat(GLenum shadertype,
5268 GLenum precisiontype,
5269 GLint *range,
5270 GLint *precision)
5271{
5272 // TODO(jmadill): Compute shaders.
5273
5274 switch (shadertype)
5275 {
5276 case GL_VERTEX_SHADER:
5277 switch (precisiontype)
5278 {
5279 case GL_LOW_FLOAT:
5280 mCaps.vertexLowpFloat.get(range, precision);
5281 break;
5282 case GL_MEDIUM_FLOAT:
5283 mCaps.vertexMediumpFloat.get(range, precision);
5284 break;
5285 case GL_HIGH_FLOAT:
5286 mCaps.vertexHighpFloat.get(range, precision);
5287 break;
5288
5289 case GL_LOW_INT:
5290 mCaps.vertexLowpInt.get(range, precision);
5291 break;
5292 case GL_MEDIUM_INT:
5293 mCaps.vertexMediumpInt.get(range, precision);
5294 break;
5295 case GL_HIGH_INT:
5296 mCaps.vertexHighpInt.get(range, precision);
5297 break;
5298
5299 default:
5300 UNREACHABLE();
5301 return;
5302 }
5303 break;
5304
5305 case GL_FRAGMENT_SHADER:
5306 switch (precisiontype)
5307 {
5308 case GL_LOW_FLOAT:
5309 mCaps.fragmentLowpFloat.get(range, precision);
5310 break;
5311 case GL_MEDIUM_FLOAT:
5312 mCaps.fragmentMediumpFloat.get(range, precision);
5313 break;
5314 case GL_HIGH_FLOAT:
5315 mCaps.fragmentHighpFloat.get(range, precision);
5316 break;
5317
5318 case GL_LOW_INT:
5319 mCaps.fragmentLowpInt.get(range, precision);
5320 break;
5321 case GL_MEDIUM_INT:
5322 mCaps.fragmentMediumpInt.get(range, precision);
5323 break;
5324 case GL_HIGH_INT:
5325 mCaps.fragmentHighpInt.get(range, precision);
5326 break;
5327
5328 default:
5329 UNREACHABLE();
5330 return;
5331 }
5332 break;
5333
5334 default:
5335 UNREACHABLE();
5336 return;
5337 }
5338}
5339
5340void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5341{
5342 Shader *shaderObject = getShader(shader);
5343 ASSERT(shaderObject);
5344 shaderObject->getSource(bufsize, length, source);
5345}
5346
5347void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5348{
5349 Program *programObject = getProgram(program);
5350 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005351 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005352}
5353
Brandon Jones59770802018-04-02 13:18:42 -07005354void Context::getUniformfvRobust(GLuint program,
5355 GLint location,
5356 GLsizei bufSize,
5357 GLsizei *length,
5358 GLfloat *params)
5359{
5360 getUniformfv(program, location, params);
5361}
5362
Jamie Madillc1d770e2017-04-13 17:31:24 -04005363void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5364{
5365 Program *programObject = getProgram(program);
5366 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005367 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368}
5369
Brandon Jones59770802018-04-02 13:18:42 -07005370void Context::getUniformivRobust(GLuint program,
5371 GLint location,
5372 GLsizei bufSize,
5373 GLsizei *length,
5374 GLint *params)
5375{
5376 getUniformiv(program, location, params);
5377}
5378
Jamie Madillc1d770e2017-04-13 17:31:24 -04005379GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5380{
5381 Program *programObject = getProgram(program);
5382 ASSERT(programObject);
5383 return programObject->getUniformLocation(name);
5384}
5385
5386GLboolean Context::isBuffer(GLuint buffer)
5387{
5388 if (buffer == 0)
5389 {
5390 return GL_FALSE;
5391 }
5392
5393 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5394}
5395
5396GLboolean Context::isEnabled(GLenum cap)
5397{
5398 return mGLState.getEnableFeature(cap);
5399}
5400
5401GLboolean Context::isFramebuffer(GLuint framebuffer)
5402{
5403 if (framebuffer == 0)
5404 {
5405 return GL_FALSE;
5406 }
5407
5408 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5409}
5410
5411GLboolean Context::isProgram(GLuint program)
5412{
5413 if (program == 0)
5414 {
5415 return GL_FALSE;
5416 }
5417
5418 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5419}
5420
5421GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5422{
5423 if (renderbuffer == 0)
5424 {
5425 return GL_FALSE;
5426 }
5427
5428 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5429}
5430
5431GLboolean Context::isShader(GLuint shader)
5432{
5433 if (shader == 0)
5434 {
5435 return GL_FALSE;
5436 }
5437
5438 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5439}
5440
5441GLboolean Context::isTexture(GLuint texture)
5442{
5443 if (texture == 0)
5444 {
5445 return GL_FALSE;
5446 }
5447
5448 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5449}
5450
5451void Context::linkProgram(GLuint program)
5452{
5453 Program *programObject = getProgram(program);
5454 ASSERT(programObject);
5455 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005456 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457}
5458
5459void Context::releaseShaderCompiler()
5460{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005461 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462}
5463
5464void Context::shaderBinary(GLsizei n,
5465 const GLuint *shaders,
5466 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005467 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005468 GLsizei length)
5469{
5470 // No binary shader formats are supported.
5471 UNIMPLEMENTED();
5472}
5473
5474void Context::shaderSource(GLuint shader,
5475 GLsizei count,
5476 const GLchar *const *string,
5477 const GLint *length)
5478{
5479 Shader *shaderObject = getShader(shader);
5480 ASSERT(shaderObject);
5481 shaderObject->setSource(count, string, length);
5482}
5483
5484void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5485{
5486 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5487}
5488
5489void Context::stencilMask(GLuint mask)
5490{
5491 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5492}
5493
5494void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5495{
5496 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5497}
5498
5499void Context::uniform1f(GLint location, GLfloat x)
5500{
5501 Program *program = mGLState.getProgram();
5502 program->setUniform1fv(location, 1, &x);
5503}
5504
5505void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5506{
5507 Program *program = mGLState.getProgram();
5508 program->setUniform1fv(location, count, v);
5509}
5510
5511void Context::uniform1i(GLint location, GLint x)
5512{
5513 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005514 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5515 {
5516 mGLState.setObjectDirty(GL_PROGRAM);
5517 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518}
5519
5520void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5521{
5522 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005523 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5524 {
5525 mGLState.setObjectDirty(GL_PROGRAM);
5526 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005527}
5528
5529void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5530{
5531 GLfloat xy[2] = {x, y};
5532 Program *program = mGLState.getProgram();
5533 program->setUniform2fv(location, 1, xy);
5534}
5535
5536void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5537{
5538 Program *program = mGLState.getProgram();
5539 program->setUniform2fv(location, count, v);
5540}
5541
5542void Context::uniform2i(GLint location, GLint x, GLint y)
5543{
5544 GLint xy[2] = {x, y};
5545 Program *program = mGLState.getProgram();
5546 program->setUniform2iv(location, 1, xy);
5547}
5548
5549void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5550{
5551 Program *program = mGLState.getProgram();
5552 program->setUniform2iv(location, count, v);
5553}
5554
5555void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5556{
5557 GLfloat xyz[3] = {x, y, z};
5558 Program *program = mGLState.getProgram();
5559 program->setUniform3fv(location, 1, xyz);
5560}
5561
5562void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5563{
5564 Program *program = mGLState.getProgram();
5565 program->setUniform3fv(location, count, v);
5566}
5567
5568void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5569{
5570 GLint xyz[3] = {x, y, z};
5571 Program *program = mGLState.getProgram();
5572 program->setUniform3iv(location, 1, xyz);
5573}
5574
5575void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5576{
5577 Program *program = mGLState.getProgram();
5578 program->setUniform3iv(location, count, v);
5579}
5580
5581void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5582{
5583 GLfloat xyzw[4] = {x, y, z, w};
5584 Program *program = mGLState.getProgram();
5585 program->setUniform4fv(location, 1, xyzw);
5586}
5587
5588void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5589{
5590 Program *program = mGLState.getProgram();
5591 program->setUniform4fv(location, count, v);
5592}
5593
5594void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5595{
5596 GLint xyzw[4] = {x, y, z, w};
5597 Program *program = mGLState.getProgram();
5598 program->setUniform4iv(location, 1, xyzw);
5599}
5600
5601void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5602{
5603 Program *program = mGLState.getProgram();
5604 program->setUniform4iv(location, count, v);
5605}
5606
5607void Context::uniformMatrix2fv(GLint location,
5608 GLsizei count,
5609 GLboolean transpose,
5610 const GLfloat *value)
5611{
5612 Program *program = mGLState.getProgram();
5613 program->setUniformMatrix2fv(location, count, transpose, value);
5614}
5615
5616void Context::uniformMatrix3fv(GLint location,
5617 GLsizei count,
5618 GLboolean transpose,
5619 const GLfloat *value)
5620{
5621 Program *program = mGLState.getProgram();
5622 program->setUniformMatrix3fv(location, count, transpose, value);
5623}
5624
5625void Context::uniformMatrix4fv(GLint location,
5626 GLsizei count,
5627 GLboolean transpose,
5628 const GLfloat *value)
5629{
5630 Program *program = mGLState.getProgram();
5631 program->setUniformMatrix4fv(location, count, transpose, value);
5632}
5633
5634void Context::validateProgram(GLuint program)
5635{
5636 Program *programObject = getProgram(program);
5637 ASSERT(programObject);
5638 programObject->validate(mCaps);
5639}
5640
Jiajia Qin5451d532017-11-16 17:16:34 +08005641void Context::validateProgramPipeline(GLuint pipeline)
5642{
5643 UNIMPLEMENTED();
5644}
5645
Jamie Madilld04908b2017-06-09 14:15:35 -04005646void Context::getProgramBinary(GLuint program,
5647 GLsizei bufSize,
5648 GLsizei *length,
5649 GLenum *binaryFormat,
5650 void *binary)
5651{
5652 Program *programObject = getProgram(program);
5653 ASSERT(programObject != nullptr);
5654
5655 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5656}
5657
5658void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5659{
5660 Program *programObject = getProgram(program);
5661 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005662
Jamie Madilld04908b2017-06-09 14:15:35 -04005663 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5664}
5665
Jamie Madillff325f12017-08-26 15:06:05 -04005666void Context::uniform1ui(GLint location, GLuint v0)
5667{
5668 Program *program = mGLState.getProgram();
5669 program->setUniform1uiv(location, 1, &v0);
5670}
5671
5672void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5673{
5674 Program *program = mGLState.getProgram();
5675 const GLuint xy[] = {v0, v1};
5676 program->setUniform2uiv(location, 1, xy);
5677}
5678
5679void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5680{
5681 Program *program = mGLState.getProgram();
5682 const GLuint xyz[] = {v0, v1, v2};
5683 program->setUniform3uiv(location, 1, xyz);
5684}
5685
5686void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5687{
5688 Program *program = mGLState.getProgram();
5689 const GLuint xyzw[] = {v0, v1, v2, v3};
5690 program->setUniform4uiv(location, 1, xyzw);
5691}
5692
5693void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5694{
5695 Program *program = mGLState.getProgram();
5696 program->setUniform1uiv(location, count, value);
5697}
5698void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5699{
5700 Program *program = mGLState.getProgram();
5701 program->setUniform2uiv(location, count, value);
5702}
5703
5704void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5705{
5706 Program *program = mGLState.getProgram();
5707 program->setUniform3uiv(location, count, value);
5708}
5709
5710void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5711{
5712 Program *program = mGLState.getProgram();
5713 program->setUniform4uiv(location, count, value);
5714}
5715
Jamie Madillf0e04492017-08-26 15:28:42 -04005716void Context::genQueries(GLsizei n, GLuint *ids)
5717{
5718 for (GLsizei i = 0; i < n; i++)
5719 {
5720 GLuint handle = mQueryHandleAllocator.allocate();
5721 mQueryMap.assign(handle, nullptr);
5722 ids[i] = handle;
5723 }
5724}
5725
5726void Context::deleteQueries(GLsizei n, const GLuint *ids)
5727{
5728 for (int i = 0; i < n; i++)
5729 {
5730 GLuint query = ids[i];
5731
5732 Query *queryObject = nullptr;
5733 if (mQueryMap.erase(query, &queryObject))
5734 {
5735 mQueryHandleAllocator.release(query);
5736 if (queryObject)
5737 {
5738 queryObject->release(this);
5739 }
5740 }
5741 }
5742}
5743
5744GLboolean Context::isQuery(GLuint id)
5745{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005746 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005747}
5748
Jamie Madillc8c95812017-08-26 18:40:09 -04005749void Context::uniformMatrix2x3fv(GLint location,
5750 GLsizei count,
5751 GLboolean transpose,
5752 const GLfloat *value)
5753{
5754 Program *program = mGLState.getProgram();
5755 program->setUniformMatrix2x3fv(location, count, transpose, value);
5756}
5757
5758void Context::uniformMatrix3x2fv(GLint location,
5759 GLsizei count,
5760 GLboolean transpose,
5761 const GLfloat *value)
5762{
5763 Program *program = mGLState.getProgram();
5764 program->setUniformMatrix3x2fv(location, count, transpose, value);
5765}
5766
5767void Context::uniformMatrix2x4fv(GLint location,
5768 GLsizei count,
5769 GLboolean transpose,
5770 const GLfloat *value)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniformMatrix2x4fv(location, count, transpose, value);
5774}
5775
5776void Context::uniformMatrix4x2fv(GLint location,
5777 GLsizei count,
5778 GLboolean transpose,
5779 const GLfloat *value)
5780{
5781 Program *program = mGLState.getProgram();
5782 program->setUniformMatrix4x2fv(location, count, transpose, value);
5783}
5784
5785void Context::uniformMatrix3x4fv(GLint location,
5786 GLsizei count,
5787 GLboolean transpose,
5788 const GLfloat *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniformMatrix3x4fv(location, count, transpose, value);
5792}
5793
5794void Context::uniformMatrix4x3fv(GLint location,
5795 GLsizei count,
5796 GLboolean transpose,
5797 const GLfloat *value)
5798{
5799 Program *program = mGLState.getProgram();
5800 program->setUniformMatrix4x3fv(location, count, transpose, value);
5801}
5802
Jamie Madilld7576732017-08-26 18:49:50 -04005803void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5804{
5805 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5806 {
5807 GLuint vertexArray = arrays[arrayIndex];
5808
5809 if (arrays[arrayIndex] != 0)
5810 {
5811 VertexArray *vertexArrayObject = nullptr;
5812 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5813 {
5814 if (vertexArrayObject != nullptr)
5815 {
5816 detachVertexArray(vertexArray);
5817 vertexArrayObject->onDestroy(this);
5818 }
5819
5820 mVertexArrayHandleAllocator.release(vertexArray);
5821 }
5822 }
5823 }
5824}
5825
5826void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5827{
5828 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5829 {
5830 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5831 mVertexArrayMap.assign(vertexArray, nullptr);
5832 arrays[arrayIndex] = vertexArray;
5833 }
5834}
5835
5836bool Context::isVertexArray(GLuint array)
5837{
5838 if (array == 0)
5839 {
5840 return GL_FALSE;
5841 }
5842
5843 VertexArray *vao = getVertexArray(array);
5844 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5845}
5846
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005847void Context::endTransformFeedback()
5848{
5849 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5850 transformFeedback->end(this);
5851}
5852
5853void Context::transformFeedbackVaryings(GLuint program,
5854 GLsizei count,
5855 const GLchar *const *varyings,
5856 GLenum bufferMode)
5857{
5858 Program *programObject = getProgram(program);
5859 ASSERT(programObject);
5860 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5861}
5862
5863void Context::getTransformFeedbackVarying(GLuint program,
5864 GLuint index,
5865 GLsizei bufSize,
5866 GLsizei *length,
5867 GLsizei *size,
5868 GLenum *type,
5869 GLchar *name)
5870{
5871 Program *programObject = getProgram(program);
5872 ASSERT(programObject);
5873 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5874}
5875
5876void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5877{
5878 for (int i = 0; i < n; i++)
5879 {
5880 GLuint transformFeedback = ids[i];
5881 if (transformFeedback == 0)
5882 {
5883 continue;
5884 }
5885
5886 TransformFeedback *transformFeedbackObject = nullptr;
5887 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5888 {
5889 if (transformFeedbackObject != nullptr)
5890 {
5891 detachTransformFeedback(transformFeedback);
5892 transformFeedbackObject->release(this);
5893 }
5894
5895 mTransformFeedbackHandleAllocator.release(transformFeedback);
5896 }
5897 }
5898}
5899
5900void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5901{
5902 for (int i = 0; i < n; i++)
5903 {
5904 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5905 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5906 ids[i] = transformFeedback;
5907 }
5908}
5909
5910bool Context::isTransformFeedback(GLuint id)
5911{
5912 if (id == 0)
5913 {
5914 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5915 // returns FALSE
5916 return GL_FALSE;
5917 }
5918
5919 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5920 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5921}
5922
5923void Context::pauseTransformFeedback()
5924{
5925 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5926 transformFeedback->pause();
5927}
5928
5929void Context::resumeTransformFeedback()
5930{
5931 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5932 transformFeedback->resume();
5933}
5934
Jamie Madill12e957f2017-08-26 21:42:26 -04005935void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5936{
5937 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005938 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005939}
5940
Brandon Jones59770802018-04-02 13:18:42 -07005941void Context::getUniformuivRobust(GLuint program,
5942 GLint location,
5943 GLsizei bufSize,
5944 GLsizei *length,
5945 GLuint *params)
5946{
5947 getUniformuiv(program, location, params);
5948}
5949
Jamie Madill12e957f2017-08-26 21:42:26 -04005950GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5951{
5952 const Program *programObject = getProgram(program);
5953 return programObject->getFragDataLocation(name);
5954}
5955
5956void Context::getUniformIndices(GLuint program,
5957 GLsizei uniformCount,
5958 const GLchar *const *uniformNames,
5959 GLuint *uniformIndices)
5960{
5961 const Program *programObject = getProgram(program);
5962 if (!programObject->isLinked())
5963 {
5964 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5965 {
5966 uniformIndices[uniformId] = GL_INVALID_INDEX;
5967 }
5968 }
5969 else
5970 {
5971 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5972 {
5973 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5974 }
5975 }
5976}
5977
5978void Context::getActiveUniformsiv(GLuint program,
5979 GLsizei uniformCount,
5980 const GLuint *uniformIndices,
5981 GLenum pname,
5982 GLint *params)
5983{
5984 const Program *programObject = getProgram(program);
5985 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5986 {
5987 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005988 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005989 }
5990}
5991
5992GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5993{
5994 const Program *programObject = getProgram(program);
5995 return programObject->getUniformBlockIndex(uniformBlockName);
5996}
5997
5998void Context::getActiveUniformBlockiv(GLuint program,
5999 GLuint uniformBlockIndex,
6000 GLenum pname,
6001 GLint *params)
6002{
6003 const Program *programObject = getProgram(program);
6004 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6005}
6006
Brandon Jones59770802018-04-02 13:18:42 -07006007void Context::getActiveUniformBlockivRobust(GLuint program,
6008 GLuint uniformBlockIndex,
6009 GLenum pname,
6010 GLsizei bufSize,
6011 GLsizei *length,
6012 GLint *params)
6013{
6014 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6015}
6016
Jamie Madill12e957f2017-08-26 21:42:26 -04006017void Context::getActiveUniformBlockName(GLuint program,
6018 GLuint uniformBlockIndex,
6019 GLsizei bufSize,
6020 GLsizei *length,
6021 GLchar *uniformBlockName)
6022{
6023 const Program *programObject = getProgram(program);
6024 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6025}
6026
6027void Context::uniformBlockBinding(GLuint program,
6028 GLuint uniformBlockIndex,
6029 GLuint uniformBlockBinding)
6030{
6031 Program *programObject = getProgram(program);
6032 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6033}
6034
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006035GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6036{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006037 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6038 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006039
Jamie Madill70b5bb02017-08-28 13:32:37 -04006040 Sync *syncObject = getSync(syncHandle);
6041 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006042 if (error.isError())
6043 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006044 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006045 handleError(error);
6046 return nullptr;
6047 }
6048
Jamie Madill70b5bb02017-08-28 13:32:37 -04006049 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006050}
6051
6052GLboolean Context::isSync(GLsync sync)
6053{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006054 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006055}
6056
6057GLenum Context::clientWaitSync(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
6061 GLenum result = GL_WAIT_FAILED;
6062 handleError(syncObject->clientWait(flags, timeout, &result));
6063 return result;
6064}
6065
6066void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6067{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006068 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006069 handleError(syncObject->serverWait(flags, timeout));
6070}
6071
6072void Context::getInteger64v(GLenum pname, GLint64 *params)
6073{
6074 GLenum nativeType = GL_NONE;
6075 unsigned int numParams = 0;
6076 getQueryParameterInfo(pname, &nativeType, &numParams);
6077
6078 if (nativeType == GL_INT_64_ANGLEX)
6079 {
6080 getInteger64vImpl(pname, params);
6081 }
6082 else
6083 {
6084 CastStateValues(this, nativeType, pname, numParams, params);
6085 }
6086}
6087
Brandon Jones59770802018-04-02 13:18:42 -07006088void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6089{
6090 getInteger64v(pname, data);
6091}
6092
Corentin Wallez336129f2017-10-17 15:55:40 -04006093void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006094{
6095 Buffer *buffer = mGLState.getTargetBuffer(target);
6096 QueryBufferParameteri64v(buffer, pname, params);
6097}
6098
Brandon Jones59770802018-04-02 13:18:42 -07006099void Context::getBufferParameteri64vRobust(BufferBinding target,
6100 GLenum pname,
6101 GLsizei bufSize,
6102 GLsizei *length,
6103 GLint64 *params)
6104{
6105 getBufferParameteri64v(target, pname, params);
6106}
6107
Jamie Madill3ef140a2017-08-26 23:11:21 -04006108void Context::genSamplers(GLsizei count, GLuint *samplers)
6109{
6110 for (int i = 0; i < count; i++)
6111 {
6112 samplers[i] = mState.mSamplers->createSampler();
6113 }
6114}
6115
6116void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6117{
6118 for (int i = 0; i < count; i++)
6119 {
6120 GLuint sampler = samplers[i];
6121
6122 if (mState.mSamplers->getSampler(sampler))
6123 {
6124 detachSampler(sampler);
6125 }
6126
6127 mState.mSamplers->deleteObject(this, sampler);
6128 }
6129}
6130
6131void Context::getInternalformativ(GLenum target,
6132 GLenum internalformat,
6133 GLenum pname,
6134 GLsizei bufSize,
6135 GLint *params)
6136{
6137 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6138 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6139}
6140
Brandon Jones59770802018-04-02 13:18:42 -07006141void Context::getInternalformativRobust(GLenum target,
6142 GLenum internalformat,
6143 GLenum pname,
6144 GLsizei bufSize,
6145 GLsizei *length,
6146 GLint *params)
6147{
6148 getInternalformativ(target, internalformat, pname, bufSize, params);
6149}
6150
Jiajia Qin5451d532017-11-16 17:16:34 +08006151void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6152{
6153 programUniform1iv(program, location, 1, &v0);
6154}
6155
6156void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6157{
6158 GLint xy[2] = {v0, v1};
6159 programUniform2iv(program, location, 1, xy);
6160}
6161
6162void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6163{
6164 GLint xyz[3] = {v0, v1, v2};
6165 programUniform3iv(program, location, 1, xyz);
6166}
6167
6168void Context::programUniform4i(GLuint program,
6169 GLint location,
6170 GLint v0,
6171 GLint v1,
6172 GLint v2,
6173 GLint v3)
6174{
6175 GLint xyzw[4] = {v0, v1, v2, v3};
6176 programUniform4iv(program, location, 1, xyzw);
6177}
6178
6179void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6180{
6181 programUniform1uiv(program, location, 1, &v0);
6182}
6183
6184void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6185{
6186 GLuint xy[2] = {v0, v1};
6187 programUniform2uiv(program, location, 1, xy);
6188}
6189
6190void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6191{
6192 GLuint xyz[3] = {v0, v1, v2};
6193 programUniform3uiv(program, location, 1, xyz);
6194}
6195
6196void Context::programUniform4ui(GLuint program,
6197 GLint location,
6198 GLuint v0,
6199 GLuint v1,
6200 GLuint v2,
6201 GLuint v3)
6202{
6203 GLuint xyzw[4] = {v0, v1, v2, v3};
6204 programUniform4uiv(program, location, 1, xyzw);
6205}
6206
6207void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6208{
6209 programUniform1fv(program, location, 1, &v0);
6210}
6211
6212void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6213{
6214 GLfloat xy[2] = {v0, v1};
6215 programUniform2fv(program, location, 1, xy);
6216}
6217
6218void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6219{
6220 GLfloat xyz[3] = {v0, v1, v2};
6221 programUniform3fv(program, location, 1, xyz);
6222}
6223
6224void Context::programUniform4f(GLuint program,
6225 GLint location,
6226 GLfloat v0,
6227 GLfloat v1,
6228 GLfloat v2,
6229 GLfloat v3)
6230{
6231 GLfloat xyzw[4] = {v0, v1, v2, v3};
6232 programUniform4fv(program, location, 1, xyzw);
6233}
6234
Jamie Madill81c2e252017-09-09 23:32:46 -04006235void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6236{
6237 Program *programObject = getProgram(program);
6238 ASSERT(programObject);
6239 if (programObject->setUniform1iv(location, count, value) ==
6240 Program::SetUniformResult::SamplerChanged)
6241 {
6242 mGLState.setObjectDirty(GL_PROGRAM);
6243 }
6244}
6245
Jiajia Qin5451d532017-11-16 17:16:34 +08006246void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6247{
6248 Program *programObject = getProgram(program);
6249 ASSERT(programObject);
6250 programObject->setUniform2iv(location, count, value);
6251}
6252
6253void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6254{
6255 Program *programObject = getProgram(program);
6256 ASSERT(programObject);
6257 programObject->setUniform3iv(location, count, value);
6258}
6259
6260void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6261{
6262 Program *programObject = getProgram(program);
6263 ASSERT(programObject);
6264 programObject->setUniform4iv(location, count, value);
6265}
6266
6267void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6268{
6269 Program *programObject = getProgram(program);
6270 ASSERT(programObject);
6271 programObject->setUniform1uiv(location, count, value);
6272}
6273
6274void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6275{
6276 Program *programObject = getProgram(program);
6277 ASSERT(programObject);
6278 programObject->setUniform2uiv(location, count, value);
6279}
6280
6281void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6282{
6283 Program *programObject = getProgram(program);
6284 ASSERT(programObject);
6285 programObject->setUniform3uiv(location, count, value);
6286}
6287
6288void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6289{
6290 Program *programObject = getProgram(program);
6291 ASSERT(programObject);
6292 programObject->setUniform4uiv(location, count, value);
6293}
6294
6295void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6296{
6297 Program *programObject = getProgram(program);
6298 ASSERT(programObject);
6299 programObject->setUniform1fv(location, count, value);
6300}
6301
6302void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6303{
6304 Program *programObject = getProgram(program);
6305 ASSERT(programObject);
6306 programObject->setUniform2fv(location, count, value);
6307}
6308
6309void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6310{
6311 Program *programObject = getProgram(program);
6312 ASSERT(programObject);
6313 programObject->setUniform3fv(location, count, value);
6314}
6315
6316void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6317{
6318 Program *programObject = getProgram(program);
6319 ASSERT(programObject);
6320 programObject->setUniform4fv(location, count, value);
6321}
6322
6323void Context::programUniformMatrix2fv(GLuint program,
6324 GLint location,
6325 GLsizei count,
6326 GLboolean transpose,
6327 const GLfloat *value)
6328{
6329 Program *programObject = getProgram(program);
6330 ASSERT(programObject);
6331 programObject->setUniformMatrix2fv(location, count, transpose, value);
6332}
6333
6334void Context::programUniformMatrix3fv(GLuint program,
6335 GLint location,
6336 GLsizei count,
6337 GLboolean transpose,
6338 const GLfloat *value)
6339{
6340 Program *programObject = getProgram(program);
6341 ASSERT(programObject);
6342 programObject->setUniformMatrix3fv(location, count, transpose, value);
6343}
6344
6345void Context::programUniformMatrix4fv(GLuint program,
6346 GLint location,
6347 GLsizei count,
6348 GLboolean transpose,
6349 const GLfloat *value)
6350{
6351 Program *programObject = getProgram(program);
6352 ASSERT(programObject);
6353 programObject->setUniformMatrix4fv(location, count, transpose, value);
6354}
6355
6356void Context::programUniformMatrix2x3fv(GLuint program,
6357 GLint location,
6358 GLsizei count,
6359 GLboolean transpose,
6360 const GLfloat *value)
6361{
6362 Program *programObject = getProgram(program);
6363 ASSERT(programObject);
6364 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6365}
6366
6367void Context::programUniformMatrix3x2fv(GLuint program,
6368 GLint location,
6369 GLsizei count,
6370 GLboolean transpose,
6371 const GLfloat *value)
6372{
6373 Program *programObject = getProgram(program);
6374 ASSERT(programObject);
6375 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6376}
6377
6378void Context::programUniformMatrix2x4fv(GLuint program,
6379 GLint location,
6380 GLsizei count,
6381 GLboolean transpose,
6382 const GLfloat *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
6386 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6387}
6388
6389void Context::programUniformMatrix4x2fv(GLuint program,
6390 GLint location,
6391 GLsizei count,
6392 GLboolean transpose,
6393 const GLfloat *value)
6394{
6395 Program *programObject = getProgram(program);
6396 ASSERT(programObject);
6397 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6398}
6399
6400void Context::programUniformMatrix3x4fv(GLuint program,
6401 GLint location,
6402 GLsizei count,
6403 GLboolean transpose,
6404 const GLfloat *value)
6405{
6406 Program *programObject = getProgram(program);
6407 ASSERT(programObject);
6408 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6409}
6410
6411void Context::programUniformMatrix4x3fv(GLuint program,
6412 GLint location,
6413 GLsizei count,
6414 GLboolean transpose,
6415 const GLfloat *value)
6416{
6417 Program *programObject = getProgram(program);
6418 ASSERT(programObject);
6419 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6420}
6421
Jamie Madill81c2e252017-09-09 23:32:46 -04006422void Context::onTextureChange(const Texture *texture)
6423{
6424 // Conservatively assume all textures are dirty.
6425 // TODO(jmadill): More fine-grained update.
6426 mGLState.setObjectDirty(GL_TEXTURE);
6427}
6428
James Darpiniane8a93c62018-01-04 18:02:24 -08006429bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6430{
6431 return mGLState.isCurrentTransformFeedback(tf);
6432}
6433bool Context::isCurrentVertexArray(const VertexArray *va) const
6434{
6435 return mGLState.isCurrentVertexArray(va);
6436}
6437
Yunchao Hea336b902017-08-02 16:05:21 +08006438void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6439{
6440 for (int i = 0; i < count; i++)
6441 {
6442 pipelines[i] = createProgramPipeline();
6443 }
6444}
6445
6446void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6447{
6448 for (int i = 0; i < count; i++)
6449 {
6450 if (pipelines[i] != 0)
6451 {
6452 deleteProgramPipeline(pipelines[i]);
6453 }
6454 }
6455}
6456
6457GLboolean Context::isProgramPipeline(GLuint pipeline)
6458{
6459 if (pipeline == 0)
6460 {
6461 return GL_FALSE;
6462 }
6463
6464 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6465}
6466
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006467void Context::finishFenceNV(GLuint fence)
6468{
6469 FenceNV *fenceObject = getFenceNV(fence);
6470
6471 ASSERT(fenceObject && fenceObject->isSet());
6472 handleError(fenceObject->finish());
6473}
6474
6475void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6476{
6477 FenceNV *fenceObject = getFenceNV(fence);
6478
6479 ASSERT(fenceObject && fenceObject->isSet());
6480
6481 switch (pname)
6482 {
6483 case GL_FENCE_STATUS_NV:
6484 {
6485 // GL_NV_fence spec:
6486 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6487 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6488 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6489 GLboolean status = GL_TRUE;
6490 if (fenceObject->getStatus() != GL_TRUE)
6491 {
6492 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6493 }
6494 *params = status;
6495 break;
6496 }
6497
6498 case GL_FENCE_CONDITION_NV:
6499 {
6500 *params = static_cast<GLint>(fenceObject->getCondition());
6501 break;
6502 }
6503
6504 default:
6505 UNREACHABLE();
6506 }
6507}
6508
6509void Context::getTranslatedShaderSource(GLuint shader,
6510 GLsizei bufsize,
6511 GLsizei *length,
6512 GLchar *source)
6513{
6514 Shader *shaderObject = getShader(shader);
6515 ASSERT(shaderObject);
6516 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6517}
6518
6519void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6520{
6521 Program *programObject = getProgram(program);
6522 ASSERT(programObject);
6523
6524 programObject->getUniformfv(this, location, params);
6525}
6526
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006527void Context::getnUniformfvRobust(GLuint program,
6528 GLint location,
6529 GLsizei bufSize,
6530 GLsizei *length,
6531 GLfloat *params)
6532{
6533 UNIMPLEMENTED();
6534}
6535
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006536void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6537{
6538 Program *programObject = getProgram(program);
6539 ASSERT(programObject);
6540
6541 programObject->getUniformiv(this, location, params);
6542}
6543
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006544void Context::getnUniformivRobust(GLuint program,
6545 GLint location,
6546 GLsizei bufSize,
6547 GLsizei *length,
6548 GLint *params)
6549{
6550 UNIMPLEMENTED();
6551}
6552
6553void Context::getnUniformuivRobust(GLuint program,
6554 GLint location,
6555 GLsizei bufSize,
6556 GLsizei *length,
6557 GLuint *params)
6558{
6559 UNIMPLEMENTED();
6560}
6561
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006562GLboolean Context::isFenceNV(GLuint fence)
6563{
6564 FenceNV *fenceObject = getFenceNV(fence);
6565
6566 if (fenceObject == nullptr)
6567 {
6568 return GL_FALSE;
6569 }
6570
6571 // GL_NV_fence spec:
6572 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6573 // existing fence.
6574 return fenceObject->isSet();
6575}
6576
6577void Context::readnPixels(GLint x,
6578 GLint y,
6579 GLsizei width,
6580 GLsizei height,
6581 GLenum format,
6582 GLenum type,
6583 GLsizei bufSize,
6584 void *data)
6585{
6586 return readPixels(x, y, width, height, format, type, data);
6587}
6588
Jamie Madill007530e2017-12-28 14:27:04 -05006589void Context::setFenceNV(GLuint fence, GLenum condition)
6590{
6591 ASSERT(condition == GL_ALL_COMPLETED_NV);
6592
6593 FenceNV *fenceObject = getFenceNV(fence);
6594 ASSERT(fenceObject != nullptr);
6595 handleError(fenceObject->set(condition));
6596}
6597
6598GLboolean Context::testFenceNV(GLuint fence)
6599{
6600 FenceNV *fenceObject = getFenceNV(fence);
6601
6602 ASSERT(fenceObject != nullptr);
6603 ASSERT(fenceObject->isSet() == GL_TRUE);
6604
6605 GLboolean result = GL_TRUE;
6606 Error error = fenceObject->test(&result);
6607 if (error.isError())
6608 {
6609 handleError(error);
6610 return GL_TRUE;
6611 }
6612
6613 return result;
6614}
6615
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006616void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006617{
6618 Texture *texture = getTargetTexture(target);
6619 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006620 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006621}
6622
Jamie Madillfa920eb2018-01-04 11:45:50 -05006623void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006624{
6625 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6626 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6627 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6628}
6629
Jamie Madillfa920eb2018-01-04 11:45:50 -05006630void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6631{
6632 UNIMPLEMENTED();
6633}
6634
Jamie Madill5b772312018-03-08 20:28:32 -05006635bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6636{
6637 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6638 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6639 // to the fact that it is stored internally as a float, and so would require conversion
6640 // if returned from Context::getIntegerv. Since this conversion is already implemented
6641 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6642 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6643 // application.
6644 switch (pname)
6645 {
6646 case GL_COMPRESSED_TEXTURE_FORMATS:
6647 {
6648 *type = GL_INT;
6649 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6650 return true;
6651 }
6652 case GL_SHADER_BINARY_FORMATS:
6653 {
6654 *type = GL_INT;
6655 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6656 return true;
6657 }
6658
6659 case GL_MAX_VERTEX_ATTRIBS:
6660 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6661 case GL_MAX_VARYING_VECTORS:
6662 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6663 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6664 case GL_MAX_TEXTURE_IMAGE_UNITS:
6665 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6666 case GL_MAX_RENDERBUFFER_SIZE:
6667 case GL_NUM_SHADER_BINARY_FORMATS:
6668 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6669 case GL_ARRAY_BUFFER_BINDING:
6670 case GL_FRAMEBUFFER_BINDING:
6671 case GL_RENDERBUFFER_BINDING:
6672 case GL_CURRENT_PROGRAM:
6673 case GL_PACK_ALIGNMENT:
6674 case GL_UNPACK_ALIGNMENT:
6675 case GL_GENERATE_MIPMAP_HINT:
6676 case GL_RED_BITS:
6677 case GL_GREEN_BITS:
6678 case GL_BLUE_BITS:
6679 case GL_ALPHA_BITS:
6680 case GL_DEPTH_BITS:
6681 case GL_STENCIL_BITS:
6682 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6683 case GL_CULL_FACE_MODE:
6684 case GL_FRONT_FACE:
6685 case GL_ACTIVE_TEXTURE:
6686 case GL_STENCIL_FUNC:
6687 case GL_STENCIL_VALUE_MASK:
6688 case GL_STENCIL_REF:
6689 case GL_STENCIL_FAIL:
6690 case GL_STENCIL_PASS_DEPTH_FAIL:
6691 case GL_STENCIL_PASS_DEPTH_PASS:
6692 case GL_STENCIL_BACK_FUNC:
6693 case GL_STENCIL_BACK_VALUE_MASK:
6694 case GL_STENCIL_BACK_REF:
6695 case GL_STENCIL_BACK_FAIL:
6696 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6697 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6698 case GL_DEPTH_FUNC:
6699 case GL_BLEND_SRC_RGB:
6700 case GL_BLEND_SRC_ALPHA:
6701 case GL_BLEND_DST_RGB:
6702 case GL_BLEND_DST_ALPHA:
6703 case GL_BLEND_EQUATION_RGB:
6704 case GL_BLEND_EQUATION_ALPHA:
6705 case GL_STENCIL_WRITEMASK:
6706 case GL_STENCIL_BACK_WRITEMASK:
6707 case GL_STENCIL_CLEAR_VALUE:
6708 case GL_SUBPIXEL_BITS:
6709 case GL_MAX_TEXTURE_SIZE:
6710 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6711 case GL_SAMPLE_BUFFERS:
6712 case GL_SAMPLES:
6713 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6714 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6715 case GL_TEXTURE_BINDING_2D:
6716 case GL_TEXTURE_BINDING_CUBE_MAP:
6717 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6718 {
6719 *type = GL_INT;
6720 *numParams = 1;
6721 return true;
6722 }
6723 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6724 {
6725 if (!getExtensions().packReverseRowOrder)
6726 {
6727 return false;
6728 }
6729 *type = GL_INT;
6730 *numParams = 1;
6731 return true;
6732 }
6733 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6734 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6735 {
6736 if (!getExtensions().textureRectangle)
6737 {
6738 return false;
6739 }
6740 *type = GL_INT;
6741 *numParams = 1;
6742 return true;
6743 }
6744 case GL_MAX_DRAW_BUFFERS_EXT:
6745 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6746 {
6747 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6748 {
6749 return false;
6750 }
6751 *type = GL_INT;
6752 *numParams = 1;
6753 return true;
6754 }
6755 case GL_MAX_VIEWPORT_DIMS:
6756 {
6757 *type = GL_INT;
6758 *numParams = 2;
6759 return true;
6760 }
6761 case GL_VIEWPORT:
6762 case GL_SCISSOR_BOX:
6763 {
6764 *type = GL_INT;
6765 *numParams = 4;
6766 return true;
6767 }
6768 case GL_SHADER_COMPILER:
6769 case GL_SAMPLE_COVERAGE_INVERT:
6770 case GL_DEPTH_WRITEMASK:
6771 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6772 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6773 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6774 // bool-natural
6775 case GL_SAMPLE_COVERAGE:
6776 case GL_SCISSOR_TEST:
6777 case GL_STENCIL_TEST:
6778 case GL_DEPTH_TEST:
6779 case GL_BLEND:
6780 case GL_DITHER:
6781 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6782 {
6783 *type = GL_BOOL;
6784 *numParams = 1;
6785 return true;
6786 }
6787 case GL_COLOR_WRITEMASK:
6788 {
6789 *type = GL_BOOL;
6790 *numParams = 4;
6791 return true;
6792 }
6793 case GL_POLYGON_OFFSET_FACTOR:
6794 case GL_POLYGON_OFFSET_UNITS:
6795 case GL_SAMPLE_COVERAGE_VALUE:
6796 case GL_DEPTH_CLEAR_VALUE:
6797 case GL_LINE_WIDTH:
6798 {
6799 *type = GL_FLOAT;
6800 *numParams = 1;
6801 return true;
6802 }
6803 case GL_ALIASED_LINE_WIDTH_RANGE:
6804 case GL_ALIASED_POINT_SIZE_RANGE:
6805 case GL_DEPTH_RANGE:
6806 {
6807 *type = GL_FLOAT;
6808 *numParams = 2;
6809 return true;
6810 }
6811 case GL_COLOR_CLEAR_VALUE:
6812 case GL_BLEND_COLOR:
6813 {
6814 *type = GL_FLOAT;
6815 *numParams = 4;
6816 return true;
6817 }
6818 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6819 if (!getExtensions().textureFilterAnisotropic)
6820 {
6821 return false;
6822 }
6823 *type = GL_FLOAT;
6824 *numParams = 1;
6825 return true;
6826 case GL_TIMESTAMP_EXT:
6827 if (!getExtensions().disjointTimerQuery)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT_64_ANGLEX;
6832 *numParams = 1;
6833 return true;
6834 case GL_GPU_DISJOINT_EXT:
6835 if (!getExtensions().disjointTimerQuery)
6836 {
6837 return false;
6838 }
6839 *type = GL_INT;
6840 *numParams = 1;
6841 return true;
6842 case GL_COVERAGE_MODULATION_CHROMIUM:
6843 if (!getExtensions().framebufferMixedSamples)
6844 {
6845 return false;
6846 }
6847 *type = GL_INT;
6848 *numParams = 1;
6849 return true;
6850 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6851 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6852 {
6853 return false;
6854 }
6855 *type = GL_INT;
6856 *numParams = 1;
6857 return true;
6858 }
6859
6860 if (getExtensions().debug)
6861 {
6862 switch (pname)
6863 {
6864 case GL_DEBUG_LOGGED_MESSAGES:
6865 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6866 case GL_DEBUG_GROUP_STACK_DEPTH:
6867 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6868 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6869 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6870 case GL_MAX_LABEL_LENGTH:
6871 *type = GL_INT;
6872 *numParams = 1;
6873 return true;
6874
6875 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6876 case GL_DEBUG_OUTPUT:
6877 *type = GL_BOOL;
6878 *numParams = 1;
6879 return true;
6880 }
6881 }
6882
6883 if (getExtensions().multisampleCompatibility)
6884 {
6885 switch (pname)
6886 {
6887 case GL_MULTISAMPLE_EXT:
6888 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6889 *type = GL_BOOL;
6890 *numParams = 1;
6891 return true;
6892 }
6893 }
6894
6895 if (getExtensions().pathRendering)
6896 {
6897 switch (pname)
6898 {
6899 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6900 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6901 *type = GL_FLOAT;
6902 *numParams = 16;
6903 return true;
6904 }
6905 }
6906
6907 if (getExtensions().bindGeneratesResource)
6908 {
6909 switch (pname)
6910 {
6911 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6912 *type = GL_BOOL;
6913 *numParams = 1;
6914 return true;
6915 }
6916 }
6917
6918 if (getExtensions().clientArrays)
6919 {
6920 switch (pname)
6921 {
6922 case GL_CLIENT_ARRAYS_ANGLE:
6923 *type = GL_BOOL;
6924 *numParams = 1;
6925 return true;
6926 }
6927 }
6928
6929 if (getExtensions().sRGBWriteControl)
6930 {
6931 switch (pname)
6932 {
6933 case GL_FRAMEBUFFER_SRGB_EXT:
6934 *type = GL_BOOL;
6935 *numParams = 1;
6936 return true;
6937 }
6938 }
6939
6940 if (getExtensions().robustResourceInitialization &&
6941 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6942 {
6943 *type = GL_BOOL;
6944 *numParams = 1;
6945 return true;
6946 }
6947
6948 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6949 {
6950 *type = GL_BOOL;
6951 *numParams = 1;
6952 return true;
6953 }
6954
6955 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6956 switch (pname)
6957 {
6958 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6959 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6960 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6961 {
6962 return false;
6963 }
6964 *type = GL_INT;
6965 *numParams = 1;
6966 return true;
6967
6968 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6969 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6970 {
6971 return false;
6972 }
6973 *type = GL_INT;
6974 *numParams = 1;
6975 return true;
6976
6977 case GL_PROGRAM_BINARY_FORMATS_OES:
6978 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6979 {
6980 return false;
6981 }
6982 *type = GL_INT;
6983 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6984 return true;
6985
6986 case GL_PACK_ROW_LENGTH:
6987 case GL_PACK_SKIP_ROWS:
6988 case GL_PACK_SKIP_PIXELS:
6989 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6990 {
6991 return false;
6992 }
6993 *type = GL_INT;
6994 *numParams = 1;
6995 return true;
6996 case GL_UNPACK_ROW_LENGTH:
6997 case GL_UNPACK_SKIP_ROWS:
6998 case GL_UNPACK_SKIP_PIXELS:
6999 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7000 {
7001 return false;
7002 }
7003 *type = GL_INT;
7004 *numParams = 1;
7005 return true;
7006 case GL_VERTEX_ARRAY_BINDING:
7007 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7008 {
7009 return false;
7010 }
7011 *type = GL_INT;
7012 *numParams = 1;
7013 return true;
7014 case GL_PIXEL_PACK_BUFFER_BINDING:
7015 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7016 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7017 {
7018 return false;
7019 }
7020 *type = GL_INT;
7021 *numParams = 1;
7022 return true;
7023 case GL_MAX_SAMPLES:
7024 {
7025 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7026 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7027 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7028 {
7029 return false;
7030 }
7031 *type = GL_INT;
7032 *numParams = 1;
7033 return true;
7034
7035 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7036 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7037 {
7038 return false;
7039 }
7040 *type = GL_INT;
7041 *numParams = 1;
7042 return true;
7043 }
7044 }
7045
7046 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7047 {
7048 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7049 {
7050 return false;
7051 }
7052 *type = GL_INT;
7053 *numParams = 1;
7054 return true;
7055 }
7056
7057 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7058 {
7059 *type = GL_INT;
7060 *numParams = 1;
7061 return true;
7062 }
7063
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007064 if (getClientVersion() < Version(2, 0))
7065 {
7066 switch (pname)
7067 {
7068 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007069 case GL_CLIENT_ACTIVE_TEXTURE:
7070 case GL_MATRIX_MODE:
7071 case GL_MAX_TEXTURE_UNITS:
7072 case GL_MAX_MODELVIEW_STACK_DEPTH:
7073 case GL_MAX_PROJECTION_STACK_DEPTH:
7074 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007075 case GL_MAX_LIGHTS:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007076 case GL_VERTEX_ARRAY_STRIDE:
7077 case GL_NORMAL_ARRAY_STRIDE:
7078 case GL_COLOR_ARRAY_STRIDE:
7079 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7080 case GL_VERTEX_ARRAY_SIZE:
7081 case GL_COLOR_ARRAY_SIZE:
7082 case GL_TEXTURE_COORD_ARRAY_SIZE:
7083 case GL_VERTEX_ARRAY_TYPE:
7084 case GL_NORMAL_ARRAY_TYPE:
7085 case GL_COLOR_ARRAY_TYPE:
7086 case GL_TEXTURE_COORD_ARRAY_TYPE:
7087 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7088 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7089 case GL_COLOR_ARRAY_BUFFER_BINDING:
7090 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7091 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7092 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7093 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007094 *type = GL_INT;
7095 *numParams = 1;
7096 return true;
7097 case GL_ALPHA_TEST_REF:
7098 *type = GL_FLOAT;
7099 *numParams = 1;
7100 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007101 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007102 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007103 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007104 *type = GL_FLOAT;
7105 *numParams = 4;
7106 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007107 case GL_CURRENT_NORMAL:
7108 *type = GL_FLOAT;
7109 *numParams = 3;
7110 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007111 case GL_MODELVIEW_MATRIX:
7112 case GL_PROJECTION_MATRIX:
7113 case GL_TEXTURE_MATRIX:
7114 *type = GL_FLOAT;
7115 *numParams = 16;
7116 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007117 case GL_LIGHT_MODEL_TWO_SIDE:
7118 *type = GL_BOOL;
7119 *numParams = 1;
7120 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007121 }
7122 }
7123
Jamie Madill5b772312018-03-08 20:28:32 -05007124 if (getClientVersion() < Version(3, 0))
7125 {
7126 return false;
7127 }
7128
7129 // Check for ES3.0+ parameter names
7130 switch (pname)
7131 {
7132 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7133 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7134 case GL_UNIFORM_BUFFER_BINDING:
7135 case GL_TRANSFORM_FEEDBACK_BINDING:
7136 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7137 case GL_COPY_READ_BUFFER_BINDING:
7138 case GL_COPY_WRITE_BUFFER_BINDING:
7139 case GL_SAMPLER_BINDING:
7140 case GL_READ_BUFFER:
7141 case GL_TEXTURE_BINDING_3D:
7142 case GL_TEXTURE_BINDING_2D_ARRAY:
7143 case GL_MAX_3D_TEXTURE_SIZE:
7144 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7145 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7146 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7147 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7148 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7149 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7150 case GL_MAX_VARYING_COMPONENTS:
7151 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7152 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7153 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7154 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7155 case GL_NUM_EXTENSIONS:
7156 case GL_MAJOR_VERSION:
7157 case GL_MINOR_VERSION:
7158 case GL_MAX_ELEMENTS_INDICES:
7159 case GL_MAX_ELEMENTS_VERTICES:
7160 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7161 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7162 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7163 case GL_UNPACK_IMAGE_HEIGHT:
7164 case GL_UNPACK_SKIP_IMAGES:
7165 {
7166 *type = GL_INT;
7167 *numParams = 1;
7168 return true;
7169 }
7170
7171 case GL_MAX_ELEMENT_INDEX:
7172 case GL_MAX_UNIFORM_BLOCK_SIZE:
7173 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7174 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7175 case GL_MAX_SERVER_WAIT_TIMEOUT:
7176 {
7177 *type = GL_INT_64_ANGLEX;
7178 *numParams = 1;
7179 return true;
7180 }
7181
7182 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7183 case GL_TRANSFORM_FEEDBACK_PAUSED:
7184 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7185 case GL_RASTERIZER_DISCARD:
7186 {
7187 *type = GL_BOOL;
7188 *numParams = 1;
7189 return true;
7190 }
7191
7192 case GL_MAX_TEXTURE_LOD_BIAS:
7193 {
7194 *type = GL_FLOAT;
7195 *numParams = 1;
7196 return true;
7197 }
7198 }
7199
7200 if (getExtensions().requestExtension)
7201 {
7202 switch (pname)
7203 {
7204 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7205 *type = GL_INT;
7206 *numParams = 1;
7207 return true;
7208 }
7209 }
7210
7211 if (getClientVersion() < Version(3, 1))
7212 {
7213 return false;
7214 }
7215
7216 switch (pname)
7217 {
7218 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7219 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7220 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7221 case GL_MAX_FRAMEBUFFER_WIDTH:
7222 case GL_MAX_FRAMEBUFFER_HEIGHT:
7223 case GL_MAX_FRAMEBUFFER_SAMPLES:
7224 case GL_MAX_SAMPLE_MASK_WORDS:
7225 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7226 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7227 case GL_MAX_INTEGER_SAMPLES:
7228 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7229 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7230 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7231 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7232 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7233 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7234 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7235 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7236 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7237 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7238 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7239 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7240 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7241 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7242 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7243 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7244 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7245 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7246 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7247 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7248 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7249 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7250 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7251 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7252 case GL_MAX_UNIFORM_LOCATIONS:
7253 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7254 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7255 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7256 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7257 case GL_MAX_IMAGE_UNITS:
7258 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7259 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7260 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7261 case GL_SHADER_STORAGE_BUFFER_BINDING:
7262 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7263 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7264 *type = GL_INT;
7265 *numParams = 1;
7266 return true;
7267 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7268 *type = GL_INT_64_ANGLEX;
7269 *numParams = 1;
7270 return true;
7271 case GL_SAMPLE_MASK:
7272 *type = GL_BOOL;
7273 *numParams = 1;
7274 return true;
7275 }
7276
7277 if (getExtensions().geometryShader)
7278 {
7279 switch (pname)
7280 {
7281 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7282 case GL_LAYER_PROVOKING_VERTEX_EXT:
7283 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7284 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7285 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7286 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7287 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7288 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7289 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7290 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7291 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7292 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7293 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7294 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7295 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7296 *type = GL_INT;
7297 *numParams = 1;
7298 return true;
7299 }
7300 }
7301
7302 return false;
7303}
7304
7305bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7306{
7307 if (getClientVersion() < Version(3, 0))
7308 {
7309 return false;
7310 }
7311
7312 switch (target)
7313 {
7314 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7315 case GL_UNIFORM_BUFFER_BINDING:
7316 {
7317 *type = GL_INT;
7318 *numParams = 1;
7319 return true;
7320 }
7321 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7322 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7323 case GL_UNIFORM_BUFFER_START:
7324 case GL_UNIFORM_BUFFER_SIZE:
7325 {
7326 *type = GL_INT_64_ANGLEX;
7327 *numParams = 1;
7328 return true;
7329 }
7330 }
7331
7332 if (getClientVersion() < Version(3, 1))
7333 {
7334 return false;
7335 }
7336
7337 switch (target)
7338 {
7339 case GL_IMAGE_BINDING_LAYERED:
7340 {
7341 *type = GL_BOOL;
7342 *numParams = 1;
7343 return true;
7344 }
7345 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7346 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7347 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7348 case GL_SHADER_STORAGE_BUFFER_BINDING:
7349 case GL_VERTEX_BINDING_BUFFER:
7350 case GL_VERTEX_BINDING_DIVISOR:
7351 case GL_VERTEX_BINDING_OFFSET:
7352 case GL_VERTEX_BINDING_STRIDE:
7353 case GL_SAMPLE_MASK_VALUE:
7354 case GL_IMAGE_BINDING_NAME:
7355 case GL_IMAGE_BINDING_LEVEL:
7356 case GL_IMAGE_BINDING_LAYER:
7357 case GL_IMAGE_BINDING_ACCESS:
7358 case GL_IMAGE_BINDING_FORMAT:
7359 {
7360 *type = GL_INT;
7361 *numParams = 1;
7362 return true;
7363 }
7364 case GL_ATOMIC_COUNTER_BUFFER_START:
7365 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7366 case GL_SHADER_STORAGE_BUFFER_START:
7367 case GL_SHADER_STORAGE_BUFFER_SIZE:
7368 {
7369 *type = GL_INT_64_ANGLEX;
7370 *numParams = 1;
7371 return true;
7372 }
7373 }
7374
7375 return false;
7376}
7377
7378Program *Context::getProgram(GLuint handle) const
7379{
7380 return mState.mShaderPrograms->getProgram(handle);
7381}
7382
7383Shader *Context::getShader(GLuint handle) const
7384{
7385 return mState.mShaderPrograms->getShader(handle);
7386}
7387
7388bool Context::isTextureGenerated(GLuint texture) const
7389{
7390 return mState.mTextures->isHandleGenerated(texture);
7391}
7392
7393bool Context::isBufferGenerated(GLuint buffer) const
7394{
7395 return mState.mBuffers->isHandleGenerated(buffer);
7396}
7397
7398bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7399{
7400 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7401}
7402
7403bool Context::isFramebufferGenerated(GLuint framebuffer) const
7404{
7405 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7406}
7407
7408bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7409{
7410 return mState.mPipelines->isHandleGenerated(pipeline);
7411}
7412
7413bool Context::usingDisplayTextureShareGroup() const
7414{
7415 return mDisplayTextureShareGroup;
7416}
7417
7418GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7419{
7420 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7421 internalformat == GL_DEPTH_STENCIL
7422 ? GL_DEPTH24_STENCIL8
7423 : internalformat;
7424}
7425
Jamie Madillc29968b2016-01-20 11:17:23 -05007426} // namespace gl