blob: d41594df242c447f959ff04517a5fa51925b2e9c [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 Madille14951e2017-03-09 18:55:16 -0500294 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400295 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400296 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400297 mScratchBuffer(1000u),
298 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000299{
Jamie Madill5b772312018-03-08 20:28:32 -0500300 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400301 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
302 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500303
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400304 mImplementation->setMemoryProgramCache(memoryProgramCache);
305
Geoff Langb433e872017-10-05 14:01:47 -0400306 bool robustResourceInit = GetRobustResourceInit(attribs);
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700307 initCaps(displayExtensions, clientExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700308 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400309
Jamie Madill4928b7c2017-06-20 12:57:39 -0400310 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400311 GetClientArraysEnabled(attribs), robustResourceInit,
312 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100313
Shannon Woods53a94a82014-06-24 15:20:36 -0400314 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400315
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000316 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400317 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000318 // and cube map texture state vectors respectively associated with them.
319 // In order that access to these initial textures not be lost, they are treated as texture
320 // objects all of whose names are 0.
321
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500324
Corentin Wallez99d492c2018-02-27 15:17:10 -0500325 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327
Geoff Langeb66a6e2016-10-31 13:06:12 -0400328 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400329 {
330 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400333
Corentin Wallez99d492c2018-02-27 15:17:10 -0500334 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800335 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400336 }
Geoff Lang3b573612016-10-31 14:08:10 -0400337 if (getClientVersion() >= Version(3, 1))
338 {
339 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500340 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800342
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
344 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800345 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800346 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800347
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
349 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400350 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800351 }
Geoff Lang3b573612016-10-31 14:08:10 -0400352 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000353
Geoff Langb0f917f2017-12-05 13:41:54 -0500354 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400355 {
356 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400359 }
360
Geoff Langb0f917f2017-12-05 13:41:54 -0500361 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400362 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400365 }
366
Jamie Madill4928b7c2017-06-20 12:57:39 -0400367 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500368
Jamie Madill57a89722013-07-02 11:57:03 -0400369 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400377 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Corentin Wallez336129f2017-10-17 15:55:40 -0400380 for (auto type : angle::AllEnums<BufferBinding>())
381 {
382 bindBuffer(type, 0);
383 }
384
385 bindRenderbuffer(GL_RENDERBUFFER, 0);
386
387 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
388 {
389 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
390 }
391
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700392 // Initialize GLES1 renderer if appropriate.
393 if (getClientVersion() < Version(2, 0))
394 {
395 mGLES1Renderer.reset(new GLES1Renderer());
396 }
397
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400399 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500401 // No dirty objects.
402
403 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
407
408 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
409 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
411 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
412 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
415 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
416 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
419 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
420
421 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700423 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500424 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400426
Xinghua Cao10a4d432017-11-28 14:46:26 +0800427 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
428 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
429 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
431 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
432 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800433 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800434 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800435
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400436 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437}
438
Jamie Madill4928b7c2017-06-20 12:57:39 -0400439egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700441 if (mGLES1Renderer)
442 {
443 mGLES1Renderer->onDestroy(this, &mGLState);
444 }
445
Jamie Madille7b3fe22018-04-05 09:42:46 -0400446 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400447 ANGLE_TRY(releaseSurface(display));
448
Corentin Wallez80b24112015-08-25 16:41:57 -0400449 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000450 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400451 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400453 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000456 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400457 if (query.second != nullptr)
458 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400459 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400460 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400462 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463
Corentin Wallez80b24112015-08-25 16:41:57 -0400464 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 if (vertexArray.second)
467 {
468 vertexArray.second->onDestroy(this);
469 }
Jamie Madill57a89722013-07-02 11:57:03 -0400470 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400471 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400472
Corentin Wallez80b24112015-08-25 16:41:57 -0400473 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500474 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500475 if (transformFeedback.second != nullptr)
476 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500477 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500478 }
Geoff Langc8058452014-02-03 12:04:11 -0500479 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400480 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500481
Jamie Madill5b772312018-03-08 20:28:32 -0500482 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400483 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800484 if (zeroTexture.get() != nullptr)
485 {
486 ANGLE_TRY(zeroTexture->onDestroy(this));
487 zeroTexture.set(this, nullptr);
488 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400489 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000490
Jamie Madill2f348d22017-06-05 10:50:59 -0400491 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493 mGLState.reset(this);
494
Jamie Madill6c1f6712017-02-14 19:08:04 -0500495 mState.mBuffers->release(this);
496 mState.mShaderPrograms->release(this);
497 mState.mTextures->release(this);
498 mState.mRenderbuffers->release(this);
499 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400500 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500501 mState.mPaths->release(this);
502 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800503 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400504
Jamie Madill76e471e2017-10-21 09:56:01 -0400505 mImplementation->onDestroy(this);
506
Jamie Madill4928b7c2017-06-20 12:57:39 -0400507 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508}
509
Jamie Madill70ee0f62017-02-06 16:04:20 -0500510Context::~Context()
511{
512}
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515{
Jamie Madill61e16b42017-06-19 11:13:23 -0400516 mCurrentDisplay = display;
517
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000518 if (!mHasBeenCurrent)
519 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500521 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400522 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523
Corentin Wallezc295e512017-01-27 17:47:50 -0500524 int width = 0;
525 int height = 0;
526 if (surface != nullptr)
527 {
528 width = surface->getWidth();
529 height = surface->getHeight();
530 }
531
532 mGLState.setViewportParams(0, 0, width, height);
533 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000534
535 mHasBeenCurrent = true;
536 }
537
Jamie Madill1b94d432015-08-07 13:23:23 -0400538 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700539 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400540 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400541
Jamie Madill4928b7c2017-06-20 12:57:39 -0400542 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500543
544 Framebuffer *newDefault = nullptr;
545 if (surface != nullptr)
546 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400547 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500548 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400549 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500550 }
551 else
552 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400553 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500554 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000555
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 // Update default framebuffer, the binding of the previous default
557 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400558 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700559 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700561 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700563 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400564 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700565 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400566 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500567 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400568 }
Ian Ewell292f0052016-02-04 10:37:32 -0500569
570 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571 mImplementation->onMakeCurrent(this);
572 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000573}
574
Jamie Madill4928b7c2017-06-20 12:57:39 -0400575egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400576{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400577 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400578
Geoff Langbf7b95d2018-05-01 16:48:21 -0400579 // Remove the default framebuffer
580 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500581 {
582 mGLState.setReadFramebufferBinding(nullptr);
583 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400584
585 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500586 {
587 mGLState.setDrawFramebufferBinding(nullptr);
588 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400589
590 if (defaultFramebuffer)
591 {
592 defaultFramebuffer->onDestroy(this);
593 delete defaultFramebuffer;
594 }
595
Corentin Wallezc295e512017-01-27 17:47:50 -0500596 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
597
598 if (mCurrentSurface)
599 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400600 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500601 mCurrentSurface = nullptr;
602 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400603
604 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400605}
606
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607GLuint Context::createBuffer()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
612GLuint Context::createProgram()
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
Jiawei Shao385b3e02018-03-21 09:43:28 +0800617GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620}
621
622GLuint Context::createTexture()
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625}
626
627GLuint Context::createRenderbuffer()
628{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500629 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630}
631
Brandon Jones59770802018-04-02 13:18:42 -0700632GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300633{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500634 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300635 if (resultOrError.isError())
636 {
637 handleError(resultOrError.getError());
638 return 0;
639 }
640 return resultOrError.getResult();
641}
642
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643// Returns an unused framebuffer name
644GLuint Context::createFramebuffer()
645{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500646 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000647}
648
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500649void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500651 for (int i = 0; i < n; i++)
652 {
653 GLuint handle = mFenceNVHandleAllocator.allocate();
654 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
655 fences[i] = handle;
656 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657}
658
Yunchao Hea336b902017-08-02 16:05:21 +0800659GLuint Context::createProgramPipeline()
660{
661 return mState.mPipelines->createProgramPipeline();
662}
663
Jiawei Shao385b3e02018-03-21 09:43:28 +0800664GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800665{
666 UNIMPLEMENTED();
667 return 0u;
668}
669
James Darpinian4d9d4832018-03-13 12:43:28 -0700670void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671{
James Darpinian4d9d4832018-03-13 12:43:28 -0700672 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
673 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674 {
675 detachBuffer(buffer);
676 }
Jamie Madill893ab082014-05-16 16:56:10 -0400677
James Darpinian4d9d4832018-03-13 12:43:28 -0700678 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteShader(GLuint shader)
682{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500683 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686void Context::deleteProgram(GLuint program)
687{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691void Context::deleteTexture(GLuint texture)
692{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500693 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694 {
695 detachTexture(texture);
696 }
697
Jamie Madill6c1f6712017-02-14 19:08:04 -0500698 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699}
700
701void Context::deleteRenderbuffer(GLuint renderbuffer)
702{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500703 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704 {
705 detachRenderbuffer(renderbuffer);
706 }
Jamie Madill893ab082014-05-16 16:56:10 -0400707
Jamie Madill6c1f6712017-02-14 19:08:04 -0500708 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000709}
710
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400711void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400712{
713 // The spec specifies the underlying Fence object is not deleted until all current
714 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
715 // and since our API is currently designed for being called from a single thread, we can delete
716 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400717 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400718}
719
Yunchao Hea336b902017-08-02 16:05:21 +0800720void Context::deleteProgramPipeline(GLuint pipeline)
721{
722 if (mState.mPipelines->getProgramPipeline(pipeline))
723 {
724 detachProgramPipeline(pipeline);
725 }
726
727 mState.mPipelines->deleteObject(this, pipeline);
728}
729
Sami Väisänene45e53b2016-05-25 10:36:04 +0300730void Context::deletePaths(GLuint first, GLsizei range)
731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300733}
734
Brandon Jones59770802018-04-02 13:18:42 -0700735bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738 if (pathObj == nullptr)
739 return false;
740
741 return pathObj->hasPathData();
742}
743
Brandon Jones59770802018-04-02 13:18:42 -0700744bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500746 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747}
748
Brandon Jones59770802018-04-02 13:18:42 -0700749void Context::pathCommands(GLuint path,
750 GLsizei numCommands,
751 const GLubyte *commands,
752 GLsizei numCoords,
753 GLenum coordType,
754 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757
758 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
759}
760
Jamie Madill007530e2017-12-28 14:27:04 -0500761void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300762{
Jamie Madill007530e2017-12-28 14:27:04 -0500763 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300764
765 switch (pname)
766 {
767 case GL_PATH_STROKE_WIDTH_CHROMIUM:
768 pathObj->setStrokeWidth(value);
769 break;
770 case GL_PATH_END_CAPS_CHROMIUM:
771 pathObj->setEndCaps(static_cast<GLenum>(value));
772 break;
773 case GL_PATH_JOIN_STYLE_CHROMIUM:
774 pathObj->setJoinStyle(static_cast<GLenum>(value));
775 break;
776 case GL_PATH_MITER_LIMIT_CHROMIUM:
777 pathObj->setMiterLimit(value);
778 break;
779 case GL_PATH_STROKE_BOUND_CHROMIUM:
780 pathObj->setStrokeBound(value);
781 break;
782 default:
783 UNREACHABLE();
784 break;
785 }
786}
787
Jamie Madill007530e2017-12-28 14:27:04 -0500788void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300789{
Jamie Madill007530e2017-12-28 14:27:04 -0500790 // TODO(jmadill): Should use proper clamping/casting.
791 pathParameterf(path, pname, static_cast<GLfloat>(value));
792}
793
794void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
795{
796 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797
798 switch (pname)
799 {
800 case GL_PATH_STROKE_WIDTH_CHROMIUM:
801 *value = pathObj->getStrokeWidth();
802 break;
803 case GL_PATH_END_CAPS_CHROMIUM:
804 *value = static_cast<GLfloat>(pathObj->getEndCaps());
805 break;
806 case GL_PATH_JOIN_STYLE_CHROMIUM:
807 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
808 break;
809 case GL_PATH_MITER_LIMIT_CHROMIUM:
810 *value = pathObj->getMiterLimit();
811 break;
812 case GL_PATH_STROKE_BOUND_CHROMIUM:
813 *value = pathObj->getStrokeBound();
814 break;
815 default:
816 UNREACHABLE();
817 break;
818 }
819}
820
Jamie Madill007530e2017-12-28 14:27:04 -0500821void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
822{
823 GLfloat val = 0.0f;
824 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
825 if (value)
826 *value = static_cast<GLint>(val);
827}
828
Brandon Jones59770802018-04-02 13:18:42 -0700829void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300830{
831 mGLState.setPathStencilFunc(func, ref, mask);
832}
833
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834void Context::deleteFramebuffer(GLuint framebuffer)
835{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500836 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 {
838 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000839 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500840
Jamie Madill6c1f6712017-02-14 19:08:04 -0500841 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842}
843
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500844void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500846 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500848 GLuint fence = fences[i];
849
850 FenceNV *fenceObject = nullptr;
851 if (mFenceNVMap.erase(fence, &fenceObject))
852 {
853 mFenceNVHandleAllocator.release(fence);
854 delete fenceObject;
855 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856 }
857}
858
Geoff Lang70d0f492015-12-10 17:45:46 -0500859Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Jamie Madill570f7c82014-07-03 10:38:54 -0400864Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867}
868
Geoff Lang70d0f492015-12-10 17:45:46 -0500869Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500871 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872}
873
Jamie Madill70b5bb02017-08-28 13:32:37 -0400874Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400875{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400876 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400877}
878
Jamie Madill57a89722013-07-02 11:57:03 -0400879VertexArray *Context::getVertexArray(GLuint handle) const
880{
Jamie Madill96a483b2017-06-27 16:49:21 -0400881 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400882}
883
Jamie Madilldc356042013-07-19 16:36:57 -0400884Sampler *Context::getSampler(GLuint handle) const
885{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500886 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400887}
888
Geoff Langc8058452014-02-03 12:04:11 -0500889TransformFeedback *Context::getTransformFeedback(GLuint handle) const
890{
Jamie Madill96a483b2017-06-27 16:49:21 -0400891 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500892}
893
Yunchao Hea336b902017-08-02 16:05:21 +0800894ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
895{
896 return mState.mPipelines->getProgramPipeline(handle);
897}
898
Geoff Lang70d0f492015-12-10 17:45:46 -0500899LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
900{
901 switch (identifier)
902 {
903 case GL_BUFFER:
904 return getBuffer(name);
905 case GL_SHADER:
906 return getShader(name);
907 case GL_PROGRAM:
908 return getProgram(name);
909 case GL_VERTEX_ARRAY:
910 return getVertexArray(name);
911 case GL_QUERY:
912 return getQuery(name);
913 case GL_TRANSFORM_FEEDBACK:
914 return getTransformFeedback(name);
915 case GL_SAMPLER:
916 return getSampler(name);
917 case GL_TEXTURE:
918 return getTexture(name);
919 case GL_RENDERBUFFER:
920 return getRenderbuffer(name);
921 case GL_FRAMEBUFFER:
922 return getFramebuffer(name);
923 default:
924 UNREACHABLE();
925 return nullptr;
926 }
927}
928
929LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
930{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400931 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500932}
933
Martin Radev9d901792016-07-15 15:58:58 +0300934void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
935{
936 LabeledObject *object = getLabeledObject(identifier, name);
937 ASSERT(object != nullptr);
938
939 std::string labelName = GetObjectLabelFromPointer(length, label);
940 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400941
942 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
943 // specified object is active until we do this.
944 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300945}
946
947void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
948{
949 LabeledObject *object = getLabeledObjectFromPtr(ptr);
950 ASSERT(object != nullptr);
951
952 std::string labelName = GetObjectLabelFromPointer(length, label);
953 object->setLabel(labelName);
954}
955
956void Context::getObjectLabel(GLenum identifier,
957 GLuint name,
958 GLsizei bufSize,
959 GLsizei *length,
960 GLchar *label) const
961{
962 LabeledObject *object = getLabeledObject(identifier, name);
963 ASSERT(object != nullptr);
964
965 const std::string &objectLabel = object->getLabel();
966 GetObjectLabelBase(objectLabel, bufSize, length, label);
967}
968
969void Context::getObjectPtrLabel(const void *ptr,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObjectFromPtr(ptr);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
Jamie Madilldc356042013-07-19 16:36:57 -0400981bool Context::isSampler(GLuint samplerName) const
982{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400984}
985
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800986void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500988 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989
Jamie Madilldedd7b92014-11-05 16:30:36 -0500990 if (handle == 0)
991 {
992 texture = mZeroTextures[target].get();
993 }
994 else
995 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500996 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500997 }
998
999 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001000 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001001}
1002
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001003void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001005 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1006 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001007 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008}
1009
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001010void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001012 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1013 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001014 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001015}
1016
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001017void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001018{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001019 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001020 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001021}
1022
Shao80957d92017-02-20 21:25:59 +08001023void Context::bindVertexBuffer(GLuint bindingIndex,
1024 GLuint bufferHandle,
1025 GLintptr offset,
1026 GLsizei stride)
1027{
1028 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001029 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001030}
1031
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001032void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001033{
Geoff Lang76b10c92014-09-05 16:28:14 -04001034 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001035 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001036 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001037 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001038}
1039
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001040void Context::bindImageTexture(GLuint unit,
1041 GLuint texture,
1042 GLint level,
1043 GLboolean layered,
1044 GLint layer,
1045 GLenum access,
1046 GLenum format)
1047{
1048 Texture *tex = mState.mTextures->getTexture(texture);
1049 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1050}
1051
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001052void Context::useProgram(GLuint program)
1053{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001054 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001055}
1056
Jiajia Qin5451d532017-11-16 17:16:34 +08001057void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1058{
1059 UNIMPLEMENTED();
1060}
1061
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001062void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001063{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001064 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001065 TransformFeedback *transformFeedback =
1066 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001067 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001068}
1069
Yunchao Hea336b902017-08-02 16:05:21 +08001070void Context::bindProgramPipeline(GLuint pipelineHandle)
1071{
1072 ProgramPipeline *pipeline =
1073 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1074 mGLState.setProgramPipelineBinding(this, pipeline);
1075}
1076
Corentin Wallezad3ae902018-03-09 13:40:42 -05001077void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001080 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081
Geoff Lang5aad9672014-09-08 11:10:42 -04001082 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001083 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001084
1085 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001087}
1088
Corentin Wallezad3ae902018-03-09 13:40:42 -05001089void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001091 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001092 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093
Jamie Madillf0e04492017-08-26 15:28:42 -04001094 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095
Geoff Lang5aad9672014-09-08 11:10:42 -04001096 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001097 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098}
1099
Corentin Wallezad3ae902018-03-09 13:40:42 -05001100void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001101{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001102 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001103
1104 Query *queryObject = getQuery(id, true, target);
1105 ASSERT(queryObject);
1106
Jamie Madillf0e04492017-08-26 15:28:42 -04001107 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001108}
1109
Corentin Wallezad3ae902018-03-09 13:40:42 -05001110void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111{
1112 switch (pname)
1113 {
1114 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001115 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116 break;
1117 case GL_QUERY_COUNTER_BITS_EXT:
1118 switch (target)
1119 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001120 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001121 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1122 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001123 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124 params[0] = getExtensions().queryCounterBitsTimestamp;
1125 break;
1126 default:
1127 UNREACHABLE();
1128 params[0] = 0;
1129 break;
1130 }
1131 break;
1132 default:
1133 UNREACHABLE();
1134 return;
1135 }
1136}
1137
Corentin Wallezad3ae902018-03-09 13:40:42 -05001138void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001139 GLenum pname,
1140 GLsizei bufSize,
1141 GLsizei *length,
1142 GLint *params)
1143{
1144 getQueryiv(target, pname, params);
1145}
1146
Geoff Lang2186c382016-10-14 10:54:54 -04001147void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001148{
Geoff Lang2186c382016-10-14 10:54:54 -04001149 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001150}
1151
Brandon Jones59770802018-04-02 13:18:42 -07001152void Context::getQueryObjectivRobust(GLuint id,
1153 GLenum pname,
1154 GLsizei bufSize,
1155 GLsizei *length,
1156 GLint *params)
1157{
1158 getQueryObjectiv(id, pname, params);
1159}
1160
Geoff Lang2186c382016-10-14 10:54:54 -04001161void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001162{
Geoff Lang2186c382016-10-14 10:54:54 -04001163 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001164}
1165
Brandon Jones59770802018-04-02 13:18:42 -07001166void Context::getQueryObjectuivRobust(GLuint id,
1167 GLenum pname,
1168 GLsizei bufSize,
1169 GLsizei *length,
1170 GLuint *params)
1171{
1172 getQueryObjectuiv(id, pname, params);
1173}
1174
Geoff Lang2186c382016-10-14 10:54:54 -04001175void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176{
Geoff Lang2186c382016-10-14 10:54:54 -04001177 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178}
1179
Brandon Jones59770802018-04-02 13:18:42 -07001180void Context::getQueryObjecti64vRobust(GLuint id,
1181 GLenum pname,
1182 GLsizei bufSize,
1183 GLsizei *length,
1184 GLint64 *params)
1185{
1186 getQueryObjecti64v(id, pname, params);
1187}
1188
Geoff Lang2186c382016-10-14 10:54:54 -04001189void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190{
Geoff Lang2186c382016-10-14 10:54:54 -04001191 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001192}
1193
Brandon Jones59770802018-04-02 13:18:42 -07001194void Context::getQueryObjectui64vRobust(GLuint id,
1195 GLenum pname,
1196 GLsizei bufSize,
1197 GLsizei *length,
1198 GLuint64 *params)
1199{
1200 getQueryObjectui64v(id, pname, params);
1201}
1202
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001203Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001204{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001205 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206}
1207
Jamie Madill2f348d22017-06-05 10:50:59 -04001208FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
Jamie Madill96a483b2017-06-27 16:49:21 -04001210 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211}
1212
Corentin Wallezad3ae902018-03-09 13:40:42 -05001213Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214{
Jamie Madill96a483b2017-06-27 16:49:21 -04001215 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001217 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001219
1220 Query *query = mQueryMap.query(handle);
1221 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001223 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001224 query = new Query(mImplementation->createQuery(type), handle);
1225 query->addRef();
1226 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229}
1230
Geoff Lang70d0f492015-12-10 17:45:46 -05001231Query *Context::getQuery(GLuint handle) const
1232{
Jamie Madill96a483b2017-06-27 16:49:21 -04001233 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001234}
1235
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001236Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001237{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001238 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1239 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001240}
1241
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001242Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001243{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001244 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245}
1246
Geoff Lang492a7e42014-11-05 13:27:06 -05001247Compiler *Context::getCompiler() const
1248{
Jamie Madill2f348d22017-06-05 10:50:59 -04001249 if (mCompiler.get() == nullptr)
1250 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001251 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001252 }
1253 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001254}
1255
Jamie Madillc1d770e2017-04-13 17:31:24 -04001256void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257{
1258 switch (pname)
1259 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001260 case GL_SHADER_COMPILER:
1261 *params = GL_TRUE;
1262 break;
1263 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1264 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1265 break;
1266 default:
1267 mGLState.getBooleanv(pname, params);
1268 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001270}
1271
Jamie Madillc1d770e2017-04-13 17:31:24 -04001272void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273{
Shannon Woods53a94a82014-06-24 15:20:36 -04001274 // Queries about context capabilities and maximums are answered by Context.
1275 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276 switch (pname)
1277 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001278 case GL_ALIASED_LINE_WIDTH_RANGE:
1279 params[0] = mCaps.minAliasedLineWidth;
1280 params[1] = mCaps.maxAliasedLineWidth;
1281 break;
1282 case GL_ALIASED_POINT_SIZE_RANGE:
1283 params[0] = mCaps.minAliasedPointSize;
1284 params[1] = mCaps.maxAliasedPointSize;
1285 break;
1286 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1287 ASSERT(mExtensions.textureFilterAnisotropic);
1288 *params = mExtensions.maxTextureAnisotropy;
1289 break;
1290 case GL_MAX_TEXTURE_LOD_BIAS:
1291 *params = mCaps.maxLODBias;
1292 break;
1293
1294 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1295 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1296 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001297 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1298 // GLES1 constants for modelview/projection matrix.
1299 if (getClientVersion() < Version(2, 0))
1300 {
1301 mGLState.getFloatv(pname, params);
1302 }
1303 else
1304 {
1305 ASSERT(mExtensions.pathRendering);
1306 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1307 memcpy(params, m, 16 * sizeof(GLfloat));
1308 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001309 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001310 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001311
Jamie Madill231c7f52017-04-26 13:45:37 -04001312 default:
1313 mGLState.getFloatv(pname, params);
1314 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001316}
1317
Jamie Madillc1d770e2017-04-13 17:31:24 -04001318void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319{
Shannon Woods53a94a82014-06-24 15:20:36 -04001320 // Queries about context capabilities and maximums are answered by Context.
1321 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001322
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323 switch (pname)
1324 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001325 case GL_MAX_VERTEX_ATTRIBS:
1326 *params = mCaps.maxVertexAttributes;
1327 break;
1328 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1329 *params = mCaps.maxVertexUniformVectors;
1330 break;
1331 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001332 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001333 break;
1334 case GL_MAX_VARYING_VECTORS:
1335 *params = mCaps.maxVaryingVectors;
1336 break;
1337 case GL_MAX_VARYING_COMPONENTS:
1338 *params = mCaps.maxVertexOutputComponents;
1339 break;
1340 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1341 *params = mCaps.maxCombinedTextureImageUnits;
1342 break;
1343 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001344 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001345 break;
1346 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001347 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001348 break;
1349 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1350 *params = mCaps.maxFragmentUniformVectors;
1351 break;
1352 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001353 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 break;
1355 case GL_MAX_RENDERBUFFER_SIZE:
1356 *params = mCaps.maxRenderbufferSize;
1357 break;
1358 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1359 *params = mCaps.maxColorAttachments;
1360 break;
1361 case GL_MAX_DRAW_BUFFERS_EXT:
1362 *params = mCaps.maxDrawBuffers;
1363 break;
1364 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1365 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1366 case GL_SUBPIXEL_BITS:
1367 *params = 4;
1368 break;
1369 case GL_MAX_TEXTURE_SIZE:
1370 *params = mCaps.max2DTextureSize;
1371 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001372 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1373 *params = mCaps.maxRectangleTextureSize;
1374 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1376 *params = mCaps.maxCubeMapTextureSize;
1377 break;
1378 case GL_MAX_3D_TEXTURE_SIZE:
1379 *params = mCaps.max3DTextureSize;
1380 break;
1381 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1382 *params = mCaps.maxArrayTextureLayers;
1383 break;
1384 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1385 *params = mCaps.uniformBufferOffsetAlignment;
1386 break;
1387 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1388 *params = mCaps.maxUniformBufferBindings;
1389 break;
1390 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001391 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 break;
1393 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001394 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 break;
1396 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1397 *params = mCaps.maxCombinedTextureImageUnits;
1398 break;
1399 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1400 *params = mCaps.maxVertexOutputComponents;
1401 break;
1402 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1403 *params = mCaps.maxFragmentInputComponents;
1404 break;
1405 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1406 *params = mCaps.minProgramTexelOffset;
1407 break;
1408 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1409 *params = mCaps.maxProgramTexelOffset;
1410 break;
1411 case GL_MAJOR_VERSION:
1412 *params = getClientVersion().major;
1413 break;
1414 case GL_MINOR_VERSION:
1415 *params = getClientVersion().minor;
1416 break;
1417 case GL_MAX_ELEMENTS_INDICES:
1418 *params = mCaps.maxElementsIndices;
1419 break;
1420 case GL_MAX_ELEMENTS_VERTICES:
1421 *params = mCaps.maxElementsVertices;
1422 break;
1423 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1424 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1425 break;
1426 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1427 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1428 break;
1429 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1430 *params = mCaps.maxTransformFeedbackSeparateComponents;
1431 break;
1432 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1433 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1434 break;
1435 case GL_MAX_SAMPLES_ANGLE:
1436 *params = mCaps.maxSamples;
1437 break;
1438 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001439 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001440 params[0] = mCaps.maxViewportWidth;
1441 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442 }
1443 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001444 case GL_COMPRESSED_TEXTURE_FORMATS:
1445 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1446 params);
1447 break;
1448 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1449 *params = mResetStrategy;
1450 break;
1451 case GL_NUM_SHADER_BINARY_FORMATS:
1452 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1453 break;
1454 case GL_SHADER_BINARY_FORMATS:
1455 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1456 break;
1457 case GL_NUM_PROGRAM_BINARY_FORMATS:
1458 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1459 break;
1460 case GL_PROGRAM_BINARY_FORMATS:
1461 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1462 break;
1463 case GL_NUM_EXTENSIONS:
1464 *params = static_cast<GLint>(mExtensionStrings.size());
1465 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001466
Jamie Madill231c7f52017-04-26 13:45:37 -04001467 // GL_KHR_debug
1468 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1469 *params = mExtensions.maxDebugMessageLength;
1470 break;
1471 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1472 *params = mExtensions.maxDebugLoggedMessages;
1473 break;
1474 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1475 *params = mExtensions.maxDebugGroupStackDepth;
1476 break;
1477 case GL_MAX_LABEL_LENGTH:
1478 *params = mExtensions.maxLabelLength;
1479 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001480
Martin Radeve5285d22017-07-14 16:23:53 +03001481 // GL_ANGLE_multiview
1482 case GL_MAX_VIEWS_ANGLE:
1483 *params = mExtensions.maxViews;
1484 break;
1485
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 // GL_EXT_disjoint_timer_query
1487 case GL_GPU_DISJOINT_EXT:
1488 *params = mImplementation->getGPUDisjoint();
1489 break;
1490 case GL_MAX_FRAMEBUFFER_WIDTH:
1491 *params = mCaps.maxFramebufferWidth;
1492 break;
1493 case GL_MAX_FRAMEBUFFER_HEIGHT:
1494 *params = mCaps.maxFramebufferHeight;
1495 break;
1496 case GL_MAX_FRAMEBUFFER_SAMPLES:
1497 *params = mCaps.maxFramebufferSamples;
1498 break;
1499 case GL_MAX_SAMPLE_MASK_WORDS:
1500 *params = mCaps.maxSampleMaskWords;
1501 break;
1502 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1503 *params = mCaps.maxColorTextureSamples;
1504 break;
1505 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1506 *params = mCaps.maxDepthTextureSamples;
1507 break;
1508 case GL_MAX_INTEGER_SAMPLES:
1509 *params = mCaps.maxIntegerSamples;
1510 break;
1511 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1512 *params = mCaps.maxVertexAttribRelativeOffset;
1513 break;
1514 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1515 *params = mCaps.maxVertexAttribBindings;
1516 break;
1517 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1518 *params = mCaps.maxVertexAttribStride;
1519 break;
1520 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001521 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001522 break;
1523 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001524 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 break;
1526 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001527 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001528 break;
1529 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001530 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001531 break;
1532 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001533 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001536 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001537 break;
1538 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001539 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001540 break;
1541 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001542 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1545 *params = mCaps.minProgramTextureGatherOffset;
1546 break;
1547 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1548 *params = mCaps.maxProgramTextureGatherOffset;
1549 break;
1550 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1551 *params = mCaps.maxComputeWorkGroupInvocations;
1552 break;
1553 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001554 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001557 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1560 *params = mCaps.maxComputeSharedMemorySize;
1561 break;
1562 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001563 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 break;
1565 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001566 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001569 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001572 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001573 break;
1574 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001575 *params =
1576 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001577 break;
1578 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001579 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001580 break;
1581 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1582 *params = mCaps.maxCombinedShaderOutputResources;
1583 break;
1584 case GL_MAX_UNIFORM_LOCATIONS:
1585 *params = mCaps.maxUniformLocations;
1586 break;
1587 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1588 *params = mCaps.maxAtomicCounterBufferBindings;
1589 break;
1590 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1591 *params = mCaps.maxAtomicCounterBufferSize;
1592 break;
1593 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1594 *params = mCaps.maxCombinedAtomicCounterBuffers;
1595 break;
1596 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1597 *params = mCaps.maxCombinedAtomicCounters;
1598 break;
1599 case GL_MAX_IMAGE_UNITS:
1600 *params = mCaps.maxImageUnits;
1601 break;
1602 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1603 *params = mCaps.maxCombinedImageUniforms;
1604 break;
1605 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1606 *params = mCaps.maxShaderStorageBufferBindings;
1607 break;
1608 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1609 *params = mCaps.maxCombinedShaderStorageBlocks;
1610 break;
1611 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1612 *params = mCaps.shaderStorageBufferOffsetAlignment;
1613 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001614
1615 // GL_EXT_geometry_shader
1616 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1617 *params = mCaps.maxFramebufferLayers;
1618 break;
1619 case GL_LAYER_PROVOKING_VERTEX_EXT:
1620 *params = mCaps.layerProvokingVertex;
1621 break;
1622 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001623 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001624 break;
1625 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001626 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001627 break;
1628 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001629 *params =
1630 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001631 break;
1632 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1633 *params = mCaps.maxGeometryInputComponents;
1634 break;
1635 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1636 *params = mCaps.maxGeometryOutputComponents;
1637 break;
1638 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1639 *params = mCaps.maxGeometryOutputVertices;
1640 break;
1641 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1642 *params = mCaps.maxGeometryTotalOutputComponents;
1643 break;
1644 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1645 *params = mCaps.maxGeometryShaderInvocations;
1646 break;
1647 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001648 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001649 break;
1650 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001652 break;
1653 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001655 break;
1656 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
1659 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001660 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001661 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001662 // GLES1 emulation: Caps queries
1663 case GL_MAX_TEXTURE_UNITS:
1664 *params = mCaps.maxMultitextureUnits;
1665 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001666 case GL_MAX_MODELVIEW_STACK_DEPTH:
1667 *params = mCaps.maxModelviewMatrixStackDepth;
1668 break;
1669 case GL_MAX_PROJECTION_STACK_DEPTH:
1670 *params = mCaps.maxProjectionMatrixStackDepth;
1671 break;
1672 case GL_MAX_TEXTURE_STACK_DEPTH:
1673 *params = mCaps.maxTextureMatrixStackDepth;
1674 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001675 case GL_MAX_LIGHTS:
1676 *params = mCaps.maxLights;
1677 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001678 // GLES1 emulation: Vertex attribute queries
1679 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1680 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1681 case GL_COLOR_ARRAY_BUFFER_BINDING:
1682 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1683 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1684 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1685 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1686 break;
1687 case GL_VERTEX_ARRAY_STRIDE:
1688 case GL_NORMAL_ARRAY_STRIDE:
1689 case GL_COLOR_ARRAY_STRIDE:
1690 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1691 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1692 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1693 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1694 break;
1695 case GL_VERTEX_ARRAY_SIZE:
1696 case GL_COLOR_ARRAY_SIZE:
1697 case GL_TEXTURE_COORD_ARRAY_SIZE:
1698 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1699 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1700 break;
1701 case GL_VERTEX_ARRAY_TYPE:
1702 case GL_COLOR_ARRAY_TYPE:
1703 case GL_NORMAL_ARRAY_TYPE:
1704 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1705 case GL_TEXTURE_COORD_ARRAY_TYPE:
1706 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1707 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1708 break;
1709
Jamie Madill231c7f52017-04-26 13:45:37 -04001710 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001711 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001712 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001713 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001714}
1715
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001716void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001717{
Shannon Woods53a94a82014-06-24 15:20:36 -04001718 // Queries about context capabilities and maximums are answered by Context.
1719 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001720 switch (pname)
1721 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001722 case GL_MAX_ELEMENT_INDEX:
1723 *params = mCaps.maxElementIndex;
1724 break;
1725 case GL_MAX_UNIFORM_BLOCK_SIZE:
1726 *params = mCaps.maxUniformBlockSize;
1727 break;
1728 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001729 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001730 break;
1731 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001732 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 break;
1734 case GL_MAX_SERVER_WAIT_TIMEOUT:
1735 *params = mCaps.maxServerWaitTimeout;
1736 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001737
Jamie Madill231c7f52017-04-26 13:45:37 -04001738 // GL_EXT_disjoint_timer_query
1739 case GL_TIMESTAMP_EXT:
1740 *params = mImplementation->getTimestamp();
1741 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001742
Jamie Madill231c7f52017-04-26 13:45:37 -04001743 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1744 *params = mCaps.maxShaderStorageBlockSize;
1745 break;
1746 default:
1747 UNREACHABLE();
1748 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001749 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001750}
1751
Geoff Lang70d0f492015-12-10 17:45:46 -05001752void Context::getPointerv(GLenum pname, void **params) const
1753{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001754 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001755}
1756
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001757void Context::getPointervRobustANGLERobust(GLenum pname,
1758 GLsizei bufSize,
1759 GLsizei *length,
1760 void **params)
1761{
1762 UNIMPLEMENTED();
1763}
1764
Martin Radev66fb8202016-07-28 11:45:20 +03001765void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001766{
Shannon Woods53a94a82014-06-24 15:20:36 -04001767 // Queries about context capabilities and maximums are answered by Context.
1768 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001769
1770 GLenum nativeType;
1771 unsigned int numParams;
1772 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1773 ASSERT(queryStatus);
1774
1775 if (nativeType == GL_INT)
1776 {
1777 switch (target)
1778 {
1779 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1780 ASSERT(index < 3u);
1781 *data = mCaps.maxComputeWorkGroupCount[index];
1782 break;
1783 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1784 ASSERT(index < 3u);
1785 *data = mCaps.maxComputeWorkGroupSize[index];
1786 break;
1787 default:
1788 mGLState.getIntegeri_v(target, index, data);
1789 }
1790 }
1791 else
1792 {
1793 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1794 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001795}
1796
Brandon Jones59770802018-04-02 13:18:42 -07001797void Context::getIntegeri_vRobust(GLenum target,
1798 GLuint index,
1799 GLsizei bufSize,
1800 GLsizei *length,
1801 GLint *data)
1802{
1803 getIntegeri_v(target, index, data);
1804}
1805
Martin Radev66fb8202016-07-28 11:45:20 +03001806void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001807{
Shannon Woods53a94a82014-06-24 15:20:36 -04001808 // Queries about context capabilities and maximums are answered by Context.
1809 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001810
1811 GLenum nativeType;
1812 unsigned int numParams;
1813 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1814 ASSERT(queryStatus);
1815
1816 if (nativeType == GL_INT_64_ANGLEX)
1817 {
1818 mGLState.getInteger64i_v(target, index, data);
1819 }
1820 else
1821 {
1822 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1823 }
1824}
1825
Brandon Jones59770802018-04-02 13:18:42 -07001826void Context::getInteger64i_vRobust(GLenum target,
1827 GLuint index,
1828 GLsizei bufSize,
1829 GLsizei *length,
1830 GLint64 *data)
1831{
1832 getInteger64i_v(target, index, data);
1833}
1834
Martin Radev66fb8202016-07-28 11:45:20 +03001835void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1836{
1837 // Queries about context capabilities and maximums are answered by Context.
1838 // Queries about current GL state values are answered by State.
1839
1840 GLenum nativeType;
1841 unsigned int numParams;
1842 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1843 ASSERT(queryStatus);
1844
1845 if (nativeType == GL_BOOL)
1846 {
1847 mGLState.getBooleani_v(target, index, data);
1848 }
1849 else
1850 {
1851 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1852 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001853}
1854
Brandon Jones59770802018-04-02 13:18:42 -07001855void Context::getBooleani_vRobust(GLenum target,
1856 GLuint index,
1857 GLsizei bufSize,
1858 GLsizei *length,
1859 GLboolean *data)
1860{
1861 getBooleani_v(target, index, data);
1862}
1863
Corentin Wallez336129f2017-10-17 15:55:40 -04001864void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001865{
1866 Buffer *buffer = mGLState.getTargetBuffer(target);
1867 QueryBufferParameteriv(buffer, pname, params);
1868}
1869
Brandon Jones59770802018-04-02 13:18:42 -07001870void Context::getBufferParameterivRobust(BufferBinding target,
1871 GLenum pname,
1872 GLsizei bufSize,
1873 GLsizei *length,
1874 GLint *params)
1875{
1876 getBufferParameteriv(target, pname, params);
1877}
1878
He Yunchao010e4db2017-03-03 14:22:06 +08001879void Context::getFramebufferAttachmentParameteriv(GLenum target,
1880 GLenum attachment,
1881 GLenum pname,
1882 GLint *params)
1883{
1884 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001885 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001886}
1887
Brandon Jones59770802018-04-02 13:18:42 -07001888void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1889 GLenum attachment,
1890 GLenum pname,
1891 GLsizei bufSize,
1892 GLsizei *length,
1893 GLint *params)
1894{
1895 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1896}
1897
He Yunchao010e4db2017-03-03 14:22:06 +08001898void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1899{
1900 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1901 QueryRenderbufferiv(this, renderbuffer, pname, params);
1902}
1903
Brandon Jones59770802018-04-02 13:18:42 -07001904void Context::getRenderbufferParameterivRobust(GLenum target,
1905 GLenum pname,
1906 GLsizei bufSize,
1907 GLsizei *length,
1908 GLint *params)
1909{
1910 getRenderbufferParameteriv(target, pname, params);
1911}
1912
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001913void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001914{
1915 Texture *texture = getTargetTexture(target);
1916 QueryTexParameterfv(texture, pname, params);
1917}
1918
Brandon Jones59770802018-04-02 13:18:42 -07001919void Context::getTexParameterfvRobust(TextureType target,
1920 GLenum pname,
1921 GLsizei bufSize,
1922 GLsizei *length,
1923 GLfloat *params)
1924{
1925 getTexParameterfv(target, pname, params);
1926}
1927
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001928void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001929{
1930 Texture *texture = getTargetTexture(target);
1931 QueryTexParameteriv(texture, pname, params);
1932}
Jiajia Qin5451d532017-11-16 17:16:34 +08001933
Brandon Jones59770802018-04-02 13:18:42 -07001934void Context::getTexParameterivRobust(TextureType target,
1935 GLenum pname,
1936 GLsizei bufSize,
1937 GLsizei *length,
1938 GLint *params)
1939{
1940 getTexParameteriv(target, pname, params);
1941}
1942
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001943void Context::getTexParameterIivRobust(TextureType target,
1944 GLenum pname,
1945 GLsizei bufSize,
1946 GLsizei *length,
1947 GLint *params)
1948{
1949 UNIMPLEMENTED();
1950}
1951
1952void Context::getTexParameterIuivRobust(TextureType target,
1953 GLenum pname,
1954 GLsizei bufSize,
1955 GLsizei *length,
1956 GLuint *params)
1957{
1958 UNIMPLEMENTED();
1959}
1960
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001961void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001962{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001963 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001964 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001965}
1966
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001967void Context::getTexLevelParameterivRobust(TextureTarget target,
1968 GLint level,
1969 GLenum pname,
1970 GLsizei bufSize,
1971 GLsizei *length,
1972 GLint *params)
1973{
1974 UNIMPLEMENTED();
1975}
1976
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001977void Context::getTexLevelParameterfv(TextureTarget target,
1978 GLint level,
1979 GLenum pname,
1980 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001981{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001982 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001983 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001984}
1985
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001986void Context::getTexLevelParameterfvRobust(TextureTarget target,
1987 GLint level,
1988 GLenum pname,
1989 GLsizei bufSize,
1990 GLsizei *length,
1991 GLfloat *params)
1992{
1993 UNIMPLEMENTED();
1994}
1995
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001996void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001997{
1998 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001999 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002000 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002001}
2002
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002003void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002006 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002007 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002008}
2009
Brandon Jones59770802018-04-02 13:18:42 -07002010void Context::texParameterfvRobust(TextureType target,
2011 GLenum pname,
2012 GLsizei bufSize,
2013 const GLfloat *params)
2014{
2015 texParameterfv(target, pname, params);
2016}
2017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002018void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002019{
2020 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002021 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002022 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002023}
2024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002025void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002026{
2027 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002028 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002029 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002030}
2031
Brandon Jones59770802018-04-02 13:18:42 -07002032void Context::texParameterivRobust(TextureType target,
2033 GLenum pname,
2034 GLsizei bufSize,
2035 const GLint *params)
2036{
2037 texParameteriv(target, pname, params);
2038}
2039
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002040void Context::texParameterIivRobust(TextureType target,
2041 GLenum pname,
2042 GLsizei bufSize,
2043 const GLint *params)
2044{
2045 UNIMPLEMENTED();
2046}
2047
2048void Context::texParameterIuivRobust(TextureType target,
2049 GLenum pname,
2050 GLsizei bufSize,
2051 const GLuint *params)
2052{
2053 UNIMPLEMENTED();
2054}
2055
Jamie Madill493f9572018-05-24 19:52:15 -04002056void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002057{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002058 // No-op if zero count
2059 if (count == 0)
2060 {
2061 return;
2062 }
2063
Jamie Madill05b35b22017-10-03 09:01:44 -04002064 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002065 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002066 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002067}
2068
Jamie Madill493f9572018-05-24 19:52:15 -04002069void Context::drawArraysInstanced(PrimitiveMode mode,
2070 GLint first,
2071 GLsizei count,
2072 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002073{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002074 // No-op if zero count
2075 if (count == 0 || instanceCount == 0)
2076 {
2077 return;
2078 }
2079
Jamie Madill05b35b22017-10-03 09:01:44 -04002080 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002081 ANGLE_CONTEXT_TRY(
2082 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002083 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2084 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002085}
2086
Jamie Madill493f9572018-05-24 19:52:15 -04002087void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002088{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002089 // No-op if zero count
2090 if (count == 0)
2091 {
2092 return;
2093 }
2094
Jamie Madill05b35b22017-10-03 09:01:44 -04002095 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002096 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002097}
2098
Jamie Madill493f9572018-05-24 19:52:15 -04002099void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002100 GLsizei count,
2101 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002102 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002103 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002104{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002105 // No-op if zero count
2106 if (count == 0 || instances == 0)
2107 {
2108 return;
2109 }
2110
Jamie Madill05b35b22017-10-03 09:01:44 -04002111 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002112 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002113 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002114}
2115
Jamie Madill493f9572018-05-24 19:52:15 -04002116void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002117 GLuint start,
2118 GLuint end,
2119 GLsizei count,
2120 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002121 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002122{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002123 // No-op if zero count
2124 if (count == 0)
2125 {
2126 return;
2127 }
2128
Jamie Madill05b35b22017-10-03 09:01:44 -04002129 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002130 ANGLE_CONTEXT_TRY(
2131 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002132}
2133
Jamie Madill493f9572018-05-24 19:52:15 -04002134void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002135{
Jamie Madill05b35b22017-10-03 09:01:44 -04002136 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002137 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002138}
2139
Jamie Madill493f9572018-05-24 19:52:15 -04002140void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002141{
Jamie Madill05b35b22017-10-03 09:01:44 -04002142 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002143 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002144}
2145
Jamie Madill675fe712016-12-19 13:07:54 -05002146void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002147{
Jamie Madillafa02a22017-11-23 12:57:38 -05002148 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002149}
2150
Jamie Madill675fe712016-12-19 13:07:54 -05002151void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002152{
Jamie Madillafa02a22017-11-23 12:57:38 -05002153 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002154}
2155
Austin Kinross6ee1e782015-05-29 17:05:37 -07002156void Context::insertEventMarker(GLsizei length, const char *marker)
2157{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002158 ASSERT(mImplementation);
2159 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002160}
2161
2162void Context::pushGroupMarker(GLsizei length, const char *marker)
2163{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002164 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002165
2166 if (marker == nullptr)
2167 {
2168 // From the EXT_debug_marker spec,
2169 // "If <marker> is null then an empty string is pushed on the stack."
2170 mImplementation->pushGroupMarker(length, "");
2171 }
2172 else
2173 {
2174 mImplementation->pushGroupMarker(length, marker);
2175 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002176}
2177
2178void Context::popGroupMarker()
2179{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002180 ASSERT(mImplementation);
2181 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002182}
2183
Geoff Langd8605522016-04-13 10:19:12 -04002184void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2185{
2186 Program *programObject = getProgram(program);
2187 ASSERT(programObject);
2188
2189 programObject->bindUniformLocation(location, name);
2190}
2191
Brandon Jones59770802018-04-02 13:18:42 -07002192void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002193{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002194 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002195}
2196
Brandon Jones59770802018-04-02 13:18:42 -07002197void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002198{
2199 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2200}
2201
Brandon Jones59770802018-04-02 13:18:42 -07002202void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002203{
2204 GLfloat I[16];
2205 angle::Matrix<GLfloat>::setToIdentity(I);
2206
2207 mGLState.loadPathRenderingMatrix(matrixMode, I);
2208}
2209
2210void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2211{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002212 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002213 if (!pathObj)
2214 return;
2215
2216 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002217 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002218
2219 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2220}
2221
2222void Context::stencilStrokePath(GLuint path, GLint reference, 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->stencilStrokePath(pathObj, reference, mask);
2232}
2233
2234void Context::coverFillPath(GLuint path, GLenum coverMode)
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->coverFillPath(pathObj, coverMode);
2244}
2245
2246void Context::coverStrokePath(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->coverStrokePath(pathObj, coverMode);
2256}
2257
2258void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, 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->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2268}
2269
2270void Context::stencilThenCoverStrokePath(GLuint path,
2271 GLint reference,
2272 GLuint mask,
2273 GLenum coverMode)
2274{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002275 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002276 if (!pathObj)
2277 return;
2278
2279 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002280 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002281
2282 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2283}
2284
Sami Väisänend59ca052016-06-21 16:10:00 +03002285void Context::coverFillPathInstanced(GLsizei numPaths,
2286 GLenum pathNameType,
2287 const void *paths,
2288 GLuint pathBase,
2289 GLenum coverMode,
2290 GLenum transformType,
2291 const GLfloat *transformValues)
2292{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002293 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002294
2295 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002296 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002297
2298 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2299}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002300
Sami Väisänend59ca052016-06-21 16:10:00 +03002301void Context::coverStrokePathInstanced(GLsizei numPaths,
2302 GLenum pathNameType,
2303 const void *paths,
2304 GLuint pathBase,
2305 GLenum coverMode,
2306 GLenum transformType,
2307 const GLfloat *transformValues)
2308{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002309 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002310
2311 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002312 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002313
2314 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2315 transformValues);
2316}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002317
Sami Väisänend59ca052016-06-21 16:10:00 +03002318void Context::stencilFillPathInstanced(GLsizei numPaths,
2319 GLenum pathNameType,
2320 const void *paths,
2321 GLuint pathBase,
2322 GLenum fillMode,
2323 GLuint mask,
2324 GLenum transformType,
2325 const GLfloat *transformValues)
2326{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002327 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002328
2329 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002330 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002331
2332 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2333 transformValues);
2334}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002335
Sami Väisänend59ca052016-06-21 16:10:00 +03002336void Context::stencilStrokePathInstanced(GLsizei numPaths,
2337 GLenum pathNameType,
2338 const void *paths,
2339 GLuint pathBase,
2340 GLint reference,
2341 GLuint mask,
2342 GLenum transformType,
2343 const GLfloat *transformValues)
2344{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002345 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002346
2347 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002348 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002349
2350 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2351 transformValues);
2352}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002353
Sami Väisänend59ca052016-06-21 16:10:00 +03002354void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2355 GLenum pathNameType,
2356 const void *paths,
2357 GLuint pathBase,
2358 GLenum fillMode,
2359 GLuint mask,
2360 GLenum coverMode,
2361 GLenum transformType,
2362 const GLfloat *transformValues)
2363{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002364 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002365
2366 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002367 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002368
2369 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2370 transformType, transformValues);
2371}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002372
Sami Väisänend59ca052016-06-21 16:10:00 +03002373void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2374 GLenum pathNameType,
2375 const void *paths,
2376 GLuint pathBase,
2377 GLint reference,
2378 GLuint mask,
2379 GLenum coverMode,
2380 GLenum transformType,
2381 const GLfloat *transformValues)
2382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002384
2385 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002386 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2389 transformType, transformValues);
2390}
2391
Sami Väisänen46eaa942016-06-29 10:26:37 +03002392void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2393{
2394 auto *programObject = getProgram(program);
2395
2396 programObject->bindFragmentInputLocation(location, name);
2397}
2398
2399void Context::programPathFragmentInputGen(GLuint program,
2400 GLint location,
2401 GLenum genMode,
2402 GLint components,
2403 const GLfloat *coeffs)
2404{
2405 auto *programObject = getProgram(program);
2406
Jamie Madillbd044ed2017-06-05 12:59:21 -04002407 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002408}
2409
jchen1015015f72017-03-16 13:54:21 +08002410GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2411{
jchen10fd7c3b52017-03-21 15:36:03 +08002412 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002413 return QueryProgramResourceIndex(programObject, programInterface, name);
2414}
2415
jchen10fd7c3b52017-03-21 15:36:03 +08002416void Context::getProgramResourceName(GLuint program,
2417 GLenum programInterface,
2418 GLuint index,
2419 GLsizei bufSize,
2420 GLsizei *length,
2421 GLchar *name)
2422{
2423 const auto *programObject = getProgram(program);
2424 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2425}
2426
jchen10191381f2017-04-11 13:59:04 +08002427GLint Context::getProgramResourceLocation(GLuint program,
2428 GLenum programInterface,
2429 const GLchar *name)
2430{
2431 const auto *programObject = getProgram(program);
2432 return QueryProgramResourceLocation(programObject, programInterface, name);
2433}
2434
jchen10880683b2017-04-12 16:21:55 +08002435void Context::getProgramResourceiv(GLuint program,
2436 GLenum programInterface,
2437 GLuint index,
2438 GLsizei propCount,
2439 const GLenum *props,
2440 GLsizei bufSize,
2441 GLsizei *length,
2442 GLint *params)
2443{
2444 const auto *programObject = getProgram(program);
2445 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2446 length, params);
2447}
2448
jchen10d9cd7b72017-08-30 15:04:25 +08002449void Context::getProgramInterfaceiv(GLuint program,
2450 GLenum programInterface,
2451 GLenum pname,
2452 GLint *params)
2453{
2454 const auto *programObject = getProgram(program);
2455 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2456}
2457
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002458void Context::getProgramInterfaceivRobust(GLuint program,
2459 GLenum programInterface,
2460 GLenum pname,
2461 GLsizei bufSize,
2462 GLsizei *length,
2463 GLint *params)
2464{
2465 UNIMPLEMENTED();
2466}
2467
Jamie Madill427064d2018-04-13 16:20:34 -04002468void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002469{
Geoff Lang7b19a492018-04-20 09:31:52 -04002470 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002471 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002472 GLenum code = error.getCode();
2473 mErrors.insert(code);
2474 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2475 {
2476 markContextLost();
2477 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002478
Geoff Langee6884e2017-11-09 16:51:11 -05002479 ASSERT(!error.getMessage().empty());
2480 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2481 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002482 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002483}
2484
2485// Get one of the recorded errors and clear its flag, if any.
2486// [OpenGL ES 2.0.24] section 2.5 page 13.
2487GLenum Context::getError()
2488{
Geoff Langda5777c2014-07-11 09:52:58 -04002489 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490 {
Geoff Langda5777c2014-07-11 09:52:58 -04002491 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002492 }
Geoff Langda5777c2014-07-11 09:52:58 -04002493 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002494 {
Geoff Langda5777c2014-07-11 09:52:58 -04002495 GLenum error = *mErrors.begin();
2496 mErrors.erase(mErrors.begin());
2497 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499}
2500
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002501// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002502void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002503{
2504 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002505 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002506 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002507 mContextLostForced = true;
2508 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002509 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510}
2511
Jamie Madill427064d2018-04-13 16:20:34 -04002512bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513{
2514 return mContextLost;
2515}
2516
Jamie Madillfa920eb2018-01-04 11:45:50 -05002517GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002518{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002519 // Even if the application doesn't want to know about resets, we want to know
2520 // as it will allow us to skip all the calls.
2521 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002522 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002523 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002524 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002525 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002526 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002527
2528 // EXT_robustness, section 2.6: If the reset notification behavior is
2529 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2530 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2531 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002532 }
2533
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002534 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2535 // status should be returned at least once, and GL_NO_ERROR should be returned
2536 // once the device has finished resetting.
2537 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002538 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539 ASSERT(mResetStatus == GL_NO_ERROR);
2540 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002541
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002543 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002544 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002545 }
2546 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002547 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002548 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002549 // If markContextLost was used to mark the context lost then
2550 // assume that is not recoverable, and continue to report the
2551 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002552 mResetStatus = mImplementation->getResetStatus();
2553 }
Jamie Madill893ab082014-05-16 16:56:10 -04002554
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002556}
2557
2558bool Context::isResetNotificationEnabled()
2559{
2560 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2561}
2562
Corentin Walleze3b10e82015-05-20 11:06:25 -04002563const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002564{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002565 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002566}
2567
2568EGLenum Context::getClientType() const
2569{
2570 return mClientType;
2571}
2572
2573EGLenum Context::getRenderBuffer() const
2574{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002575 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2576 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002577 {
2578 return EGL_NONE;
2579 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002580
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002581 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002582 ASSERT(backAttachment != nullptr);
2583 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002584}
2585
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002586VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002587{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002588 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002589 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2590 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002591 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002592 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2593 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002594
Jamie Madill96a483b2017-06-27 16:49:21 -04002595 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002596 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002597
2598 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002599}
2600
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002601TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002602{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002603 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002604 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2605 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002606 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002607 transformFeedback =
2608 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002609 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002610 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002611 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612
2613 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002614}
2615
2616bool Context::isVertexArrayGenerated(GLuint vertexArray)
2617{
Jamie Madill96a483b2017-06-27 16:49:21 -04002618 ASSERT(mVertexArrayMap.contains(0));
2619 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002620}
2621
2622bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2623{
Jamie Madill96a483b2017-06-27 16:49:21 -04002624 ASSERT(mTransformFeedbackMap.contains(0));
2625 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002626}
2627
Shannon Woods53a94a82014-06-24 15:20:36 -04002628void Context::detachTexture(GLuint texture)
2629{
2630 // Simple pass-through to State's detachTexture method, as textures do not require
2631 // allocation map management either here or in the resource manager at detach time.
2632 // Zero textures are held by the Context, and we don't attempt to request them from
2633 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002634 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002635}
2636
James Darpinian4d9d4832018-03-13 12:43:28 -07002637void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638{
Yuly Novikov5807a532015-12-03 13:01:22 -05002639 // Simple pass-through to State's detachBuffer method, since
2640 // only buffer attachments to container objects that are bound to the current context
2641 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002642
Yuly Novikov5807a532015-12-03 13:01:22 -05002643 // [OpenGL ES 3.2] section 5.1.2 page 45:
2644 // Attachments to unbound container objects, such as
2645 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2646 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002647 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002648}
2649
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002650void Context::detachFramebuffer(GLuint framebuffer)
2651{
Shannon Woods53a94a82014-06-24 15:20:36 -04002652 // Framebuffer detachment is handled by Context, because 0 is a valid
2653 // Framebuffer object, and a pointer to it must be passed from Context
2654 // to State at binding time.
2655
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002657 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2658 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2659 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002661 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662 {
2663 bindReadFramebuffer(0);
2664 }
2665
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002666 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667 {
2668 bindDrawFramebuffer(0);
2669 }
2670}
2671
2672void Context::detachRenderbuffer(GLuint renderbuffer)
2673{
Jamie Madilla02315b2017-02-23 14:14:47 -05002674 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002675}
2676
Jamie Madill57a89722013-07-02 11:57:03 -04002677void Context::detachVertexArray(GLuint vertexArray)
2678{
Jamie Madill77a72f62015-04-14 11:18:32 -04002679 // Vertex array detachment is handled by Context, because 0 is a valid
2680 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002681 // binding time.
2682
Jamie Madill57a89722013-07-02 11:57:03 -04002683 // [OpenGL ES 3.0.2] section 2.10 page 43:
2684 // If a vertex array object that is currently bound is deleted, the binding
2685 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002686 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002687 {
2688 bindVertexArray(0);
2689 }
2690}
2691
Geoff Langc8058452014-02-03 12:04:11 -05002692void Context::detachTransformFeedback(GLuint transformFeedback)
2693{
Corentin Walleza2257da2016-04-19 16:43:12 -04002694 // Transform feedback detachment is handled by Context, because 0 is a valid
2695 // transform feedback, and a pointer to it must be passed from Context to State at
2696 // binding time.
2697
2698 // The OpenGL specification doesn't mention what should happen when the currently bound
2699 // transform feedback object is deleted. Since it is a container object, we treat it like
2700 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002701 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002702 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002703 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002704 }
Geoff Langc8058452014-02-03 12:04:11 -05002705}
2706
Jamie Madilldc356042013-07-19 16:36:57 -04002707void Context::detachSampler(GLuint sampler)
2708{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002709 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002710}
2711
Yunchao Hea336b902017-08-02 16:05:21 +08002712void Context::detachProgramPipeline(GLuint pipeline)
2713{
2714 mGLState.detachProgramPipeline(this, pipeline);
2715}
2716
Jamie Madill3ef140a2017-08-26 23:11:21 -04002717void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002718{
Shaodde78e82017-05-22 14:13:27 +08002719 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002720}
2721
Jamie Madille29d1672013-07-19 16:36:57 -04002722void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2723{
Geoff Langc1984ed2016-10-07 12:41:00 -04002724 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002725 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002726 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002727 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002728}
Jamie Madille29d1672013-07-19 16:36:57 -04002729
Geoff Langc1984ed2016-10-07 12:41:00 -04002730void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2731{
2732 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002733 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002734 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002735 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002736}
2737
Brandon Jones59770802018-04-02 13:18:42 -07002738void Context::samplerParameterivRobust(GLuint sampler,
2739 GLenum pname,
2740 GLsizei bufSize,
2741 const GLint *param)
2742{
2743 samplerParameteriv(sampler, pname, param);
2744}
2745
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002746void Context::samplerParameterIivRobust(GLuint sampler,
2747 GLenum pname,
2748 GLsizei bufSize,
2749 const GLint *param)
2750{
2751 UNIMPLEMENTED();
2752}
2753
2754void Context::samplerParameterIuivRobust(GLuint sampler,
2755 GLenum pname,
2756 GLsizei bufSize,
2757 const GLuint *param)
2758{
2759 UNIMPLEMENTED();
2760}
2761
Jamie Madille29d1672013-07-19 16:36:57 -04002762void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2763{
Geoff Langc1984ed2016-10-07 12:41:00 -04002764 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002765 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002766 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002767 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002768}
2769
Geoff Langc1984ed2016-10-07 12:41:00 -04002770void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002771{
Geoff Langc1984ed2016-10-07 12:41:00 -04002772 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002773 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002774 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002775 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002776}
2777
Brandon Jones59770802018-04-02 13:18:42 -07002778void Context::samplerParameterfvRobust(GLuint sampler,
2779 GLenum pname,
2780 GLsizei bufSize,
2781 const GLfloat *param)
2782{
2783 samplerParameterfv(sampler, pname, param);
2784}
2785
Geoff Langc1984ed2016-10-07 12:41:00 -04002786void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002787{
Geoff Langc1984ed2016-10-07 12:41:00 -04002788 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002789 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002790 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002791 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002792}
Jamie Madill9675b802013-07-19 16:36:59 -04002793
Brandon Jones59770802018-04-02 13:18:42 -07002794void Context::getSamplerParameterivRobust(GLuint sampler,
2795 GLenum pname,
2796 GLsizei bufSize,
2797 GLsizei *length,
2798 GLint *params)
2799{
2800 getSamplerParameteriv(sampler, pname, params);
2801}
2802
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002803void Context::getSamplerParameterIivRobust(GLuint sampler,
2804 GLenum pname,
2805 GLsizei bufSize,
2806 GLsizei *length,
2807 GLint *params)
2808{
2809 UNIMPLEMENTED();
2810}
2811
2812void Context::getSamplerParameterIuivRobust(GLuint sampler,
2813 GLenum pname,
2814 GLsizei bufSize,
2815 GLsizei *length,
2816 GLuint *params)
2817{
2818 UNIMPLEMENTED();
2819}
2820
Geoff Langc1984ed2016-10-07 12:41:00 -04002821void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2822{
2823 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002824 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002825 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002826 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002827}
2828
Brandon Jones59770802018-04-02 13:18:42 -07002829void Context::getSamplerParameterfvRobust(GLuint sampler,
2830 GLenum pname,
2831 GLsizei bufSize,
2832 GLsizei *length,
2833 GLfloat *params)
2834{
2835 getSamplerParameterfv(sampler, pname, params);
2836}
2837
Olli Etuahof0fee072016-03-30 15:11:58 +03002838void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2839{
2840 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002841 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002842}
2843
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002844void Context::initRendererString()
2845{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002846 std::ostringstream rendererString;
2847 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002848 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002849 rendererString << ")";
2850
Geoff Langcec35902014-04-16 10:52:36 -04002851 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002852}
2853
Geoff Langc339c4e2016-11-29 10:37:36 -05002854void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855{
Geoff Langc339c4e2016-11-29 10:37:36 -05002856 const Version &clientVersion = getClientVersion();
2857
2858 std::ostringstream versionString;
2859 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2860 << ANGLE_VERSION_STRING << ")";
2861 mVersionString = MakeStaticString(versionString.str());
2862
2863 std::ostringstream shadingLanguageVersionString;
2864 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2865 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2866 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2867 << ")";
2868 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002869}
2870
Geoff Langcec35902014-04-16 10:52:36 -04002871void Context::initExtensionStrings()
2872{
Geoff Langc339c4e2016-11-29 10:37:36 -05002873 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2874 std::ostringstream combinedStringStream;
2875 std::copy(strings.begin(), strings.end(),
2876 std::ostream_iterator<const char *>(combinedStringStream, " "));
2877 return MakeStaticString(combinedStringStream.str());
2878 };
2879
2880 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002881 for (const auto &extensionString : mExtensions.getStrings())
2882 {
2883 mExtensionStrings.push_back(MakeStaticString(extensionString));
2884 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002885 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002886
Geoff Langc339c4e2016-11-29 10:37:36 -05002887 mRequestableExtensionStrings.clear();
2888 for (const auto &extensionInfo : GetExtensionInfoMap())
2889 {
2890 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002891 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002892 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002893 {
2894 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2895 }
2896 }
2897 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002898}
2899
Geoff Langc339c4e2016-11-29 10:37:36 -05002900const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002901{
Geoff Langc339c4e2016-11-29 10:37:36 -05002902 switch (name)
2903 {
2904 case GL_VENDOR:
2905 return reinterpret_cast<const GLubyte *>("Google Inc.");
2906
2907 case GL_RENDERER:
2908 return reinterpret_cast<const GLubyte *>(mRendererString);
2909
2910 case GL_VERSION:
2911 return reinterpret_cast<const GLubyte *>(mVersionString);
2912
2913 case GL_SHADING_LANGUAGE_VERSION:
2914 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2915
2916 case GL_EXTENSIONS:
2917 return reinterpret_cast<const GLubyte *>(mExtensionString);
2918
2919 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2920 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2921
2922 default:
2923 UNREACHABLE();
2924 return nullptr;
2925 }
Geoff Langcec35902014-04-16 10:52:36 -04002926}
2927
Geoff Langc339c4e2016-11-29 10:37:36 -05002928const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002929{
Geoff Langc339c4e2016-11-29 10:37:36 -05002930 switch (name)
2931 {
2932 case GL_EXTENSIONS:
2933 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2934
2935 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2936 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2937
2938 default:
2939 UNREACHABLE();
2940 return nullptr;
2941 }
Geoff Langcec35902014-04-16 10:52:36 -04002942}
2943
2944size_t Context::getExtensionStringCount() const
2945{
2946 return mExtensionStrings.size();
2947}
2948
Geoff Lang111a99e2017-10-17 10:58:41 -04002949bool Context::isExtensionRequestable(const char *name)
2950{
2951 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2952 auto extension = extensionInfos.find(name);
2953
Geoff Lang111a99e2017-10-17 10:58:41 -04002954 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002955 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002956}
2957
Geoff Langc339c4e2016-11-29 10:37:36 -05002958void Context::requestExtension(const char *name)
2959{
2960 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2961 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2962 const auto &extension = extensionInfos.at(name);
2963 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002964 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002965
2966 if (mExtensions.*(extension.ExtensionsMember))
2967 {
2968 // Extension already enabled
2969 return;
2970 }
2971
2972 mExtensions.*(extension.ExtensionsMember) = true;
2973 updateCaps();
2974 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002975
Jamie Madill2f348d22017-06-05 10:50:59 -04002976 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2977 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002978
Jamie Madill81c2e252017-09-09 23:32:46 -04002979 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2980 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002981 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002982 for (auto &zeroTexture : mZeroTextures)
2983 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002984 if (zeroTexture.get() != nullptr)
2985 {
2986 zeroTexture->signalDirty(this, InitState::Initialized);
2987 }
Geoff Lang9aded172017-04-05 11:07:56 -04002988 }
2989
2990 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002991}
2992
2993size_t Context::getRequestableExtensionStringCount() const
2994{
2995 return mRequestableExtensionStrings.size();
2996}
2997
Jamie Madill493f9572018-05-24 19:52:15 -04002998void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002999{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003000 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003001 ASSERT(transformFeedback != nullptr);
3002 ASSERT(!transformFeedback->isPaused());
3003
Jamie Madill6c1f6712017-02-14 19:08:04 -05003004 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003005}
3006
3007bool Context::hasActiveTransformFeedback(GLuint program) const
3008{
3009 for (auto pair : mTransformFeedbackMap)
3010 {
3011 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3012 {
3013 return true;
3014 }
3015 }
3016 return false;
3017}
3018
Geoff Langb0f917f2017-12-05 13:41:54 -05003019Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003020 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003021 bool robustResourceInit) const
3022{
3023 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3024
3025 if (getClientVersion() < ES_2_0)
3026 {
3027 // Default extensions for GLES1
3028 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003029 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003030 }
3031
3032 if (getClientVersion() < ES_3_0)
3033 {
3034 // Disable ES3+ extensions
3035 supportedExtensions.colorBufferFloat = false;
3036 supportedExtensions.eglImageExternalEssl3 = false;
3037 supportedExtensions.textureNorm16 = false;
3038 supportedExtensions.multiview = false;
3039 supportedExtensions.maxViews = 1u;
3040 }
3041
3042 if (getClientVersion() < ES_3_1)
3043 {
3044 // Disable ES3.1+ extensions
3045 supportedExtensions.geometryShader = false;
3046 }
3047
3048 if (getClientVersion() > ES_2_0)
3049 {
3050 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3051 // supportedExtensions.sRGB = false;
3052 }
3053
3054 // Some extensions are always available because they are implemented in the GL layer.
3055 supportedExtensions.bindUniformLocation = true;
3056 supportedExtensions.vertexArrayObject = true;
3057 supportedExtensions.bindGeneratesResource = true;
3058 supportedExtensions.clientArrays = true;
3059 supportedExtensions.requestExtension = true;
3060
3061 // Enable the no error extension if the context was created with the flag.
3062 supportedExtensions.noError = mSkipValidation;
3063
3064 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3065 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3066
3067 // Explicitly enable GL_KHR_debug
3068 supportedExtensions.debug = true;
3069 supportedExtensions.maxDebugMessageLength = 1024;
3070 supportedExtensions.maxDebugLoggedMessages = 1024;
3071 supportedExtensions.maxDebugGroupStackDepth = 1024;
3072 supportedExtensions.maxLabelLength = 1024;
3073
3074 // Explicitly enable GL_ANGLE_robust_client_memory
3075 supportedExtensions.robustClientMemory = true;
3076
3077 // Determine robust resource init availability from EGL.
3078 supportedExtensions.robustResourceInitialization = robustResourceInit;
3079
3080 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3081 // supports it.
3082 supportedExtensions.robustBufferAccessBehavior =
3083 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3084
3085 // Enable the cache control query unconditionally.
3086 supportedExtensions.programCacheControl = true;
3087
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003088 // Enable EGL_ANGLE_explicit_context subextensions
3089 if (clientExtensions.explicitContext)
3090 {
3091 // GL_ANGLE_explicit_context_gles1
3092 supportedExtensions.explicitContextGles1 = true;
3093 // GL_ANGLE_explicit_context
3094 supportedExtensions.explicitContext = true;
3095 }
3096
Geoff Langb0f917f2017-12-05 13:41:54 -05003097 return supportedExtensions;
3098}
3099
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003100void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3101 const egl::ClientExtensions &clientExtensions,
3102 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003103{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003104 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003105
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003106 mSupportedExtensions =
3107 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Jamie Madill493f9572018-05-24 19:52:15 -04003108 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003109
3110 mLimitations = mImplementation->getNativeLimitations();
3111
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003112 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3113 if (getClientVersion() < Version(2, 0))
3114 {
3115 mCaps.maxMultitextureUnits = 4;
3116 mCaps.maxClipPlanes = 6;
3117 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003118 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3119 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3120 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003121 }
3122
Geoff Lang301d1612014-07-09 10:34:37 -04003123 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003124 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003125
Jamie Madill0f80ed82017-09-19 00:24:56 -04003126 if (getClientVersion() < ES_3_1)
3127 {
3128 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3129 }
3130 else
3131 {
3132 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3133 }
Geoff Lang301d1612014-07-09 10:34:37 -04003134
Jiawei Shao54aafe52018-04-27 14:54:57 +08003135 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3136 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003137 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3138 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3139
3140 // Limit textures as well, so we can use fast bitsets with texture bindings.
3141 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003142 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3143 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3144 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3145 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003146
Jiawei Shaodb342272017-09-27 10:21:45 +08003147 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3148
Geoff Langc287ea62016-09-16 14:46:51 -04003149 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003150 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003151 for (const auto &extensionInfo : GetExtensionInfoMap())
3152 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003153 // If the user has requested that extensions start disabled and they are requestable,
3154 // disable them.
3155 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003156 {
3157 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3158 }
3159 }
3160
3161 // Generate texture caps
3162 updateCaps();
3163}
3164
3165void Context::updateCaps()
3166{
Geoff Lang900013c2014-07-07 11:32:19 -04003167 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003168 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003169
Jamie Madill7b62cf92017-11-02 15:20:49 -04003170 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003171 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003172 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003173 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003174
Geoff Lang0d8b7242015-09-09 14:56:53 -04003175 // Update the format caps based on the client version and extensions.
3176 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3177 // ES3.
3178 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003179 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003180 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003181 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003182 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003183 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003184
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003185 // OpenGL ES does not support multisampling with non-rendererable formats
3186 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003187 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003188 (getClientVersion() < ES_3_1 &&
3189 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003190 {
Geoff Langd87878e2014-09-19 15:42:59 -04003191 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003192 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003193 else
3194 {
3195 // We may have limited the max samples for some required renderbuffer formats due to
3196 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3197 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3198
3199 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3200 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3201 // exception of signed and unsigned integer formats."
3202 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3203 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3204 {
3205 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3206 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3207 }
3208
3209 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3210 if (getClientVersion() >= ES_3_1)
3211 {
3212 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3213 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3214 // the exception that the signed and unsigned integer formats are required only to
3215 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3216 // multisamples, which must be at least one."
3217 if (formatInfo.componentType == GL_INT ||
3218 formatInfo.componentType == GL_UNSIGNED_INT)
3219 {
3220 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3221 }
3222
3223 // GLES 3.1 section 19.3.1.
3224 if (formatCaps.texturable)
3225 {
3226 if (formatInfo.depthBits > 0)
3227 {
3228 mCaps.maxDepthTextureSamples =
3229 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3230 }
3231 else if (formatInfo.redBits > 0)
3232 {
3233 mCaps.maxColorTextureSamples =
3234 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3235 }
3236 }
3237 }
3238 }
Geoff Langd87878e2014-09-19 15:42:59 -04003239
3240 if (formatCaps.texturable && formatInfo.compressed)
3241 {
Geoff Langca271392017-04-05 12:30:00 -04003242 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003243 }
3244
Geoff Langca271392017-04-05 12:30:00 -04003245 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003246 }
Jamie Madill32447362017-06-28 14:53:52 -04003247
3248 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003249 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003250 {
3251 mMemoryProgramCache = nullptr;
3252 }
Corentin Walleze4477002017-12-01 14:39:58 -05003253
3254 // Compute which buffer types are allowed
3255 mValidBufferBindings.reset();
3256 mValidBufferBindings.set(BufferBinding::ElementArray);
3257 mValidBufferBindings.set(BufferBinding::Array);
3258
3259 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3260 {
3261 mValidBufferBindings.set(BufferBinding::PixelPack);
3262 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3263 }
3264
3265 if (getClientVersion() >= ES_3_0)
3266 {
3267 mValidBufferBindings.set(BufferBinding::CopyRead);
3268 mValidBufferBindings.set(BufferBinding::CopyWrite);
3269 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3270 mValidBufferBindings.set(BufferBinding::Uniform);
3271 }
3272
3273 if (getClientVersion() >= ES_3_1)
3274 {
3275 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3276 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3277 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3278 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3279 }
Geoff Lang493daf52014-07-03 13:38:44 -04003280}
3281
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003282void Context::initWorkarounds()
3283{
Jamie Madill761b02c2017-06-23 16:27:06 -04003284 // Apply back-end workarounds.
3285 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3286
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003287 // Lose the context upon out of memory error if the application is
3288 // expecting to watch for those events.
3289 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3290}
3291
Jamie Madill05b35b22017-10-03 09:01:44 -04003292Error Context::prepareForDraw()
3293{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003294 if (mGLES1Renderer)
3295 {
3296 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3297 }
3298
Geoff Langa8cb2872018-03-09 16:09:40 -05003299 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003300
3301 if (isRobustResourceInitEnabled())
3302 {
3303 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3304 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3305 }
3306
Geoff Langa8cb2872018-03-09 16:09:40 -05003307 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003308 return NoError();
3309}
3310
3311Error Context::prepareForClear(GLbitfield mask)
3312{
Geoff Langa8cb2872018-03-09 16:09:40 -05003313 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003314 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003315 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003316 return NoError();
3317}
3318
3319Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3320{
Geoff Langa8cb2872018-03-09 16:09:40 -05003321 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003322 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3323 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003324 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003325 return NoError();
3326}
3327
Geoff Langa8cb2872018-03-09 16:09:40 -05003328Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003329{
Geoff Langa8cb2872018-03-09 16:09:40 -05003330 ANGLE_TRY(syncDirtyObjects());
3331 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003332 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003333}
3334
Geoff Langa8cb2872018-03-09 16:09:40 -05003335Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003336{
Geoff Langa8cb2872018-03-09 16:09:40 -05003337 ANGLE_TRY(syncDirtyObjects(objectMask));
3338 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003339 return NoError();
3340}
3341
Geoff Langa8cb2872018-03-09 16:09:40 -05003342Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003343{
3344 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3345 mImplementation->syncState(this, dirtyBits);
3346 mGLState.clearDirtyBits();
3347 return NoError();
3348}
3349
Geoff Langa8cb2872018-03-09 16:09:40 -05003350Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003351{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003352 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003353 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003354 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003355 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003356}
Jamie Madillc29968b2016-01-20 11:17:23 -05003357
Geoff Langa8cb2872018-03-09 16:09:40 -05003358Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003359{
3360 return mGLState.syncDirtyObjects(this);
3361}
3362
Geoff Langa8cb2872018-03-09 16:09:40 -05003363Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003364{
3365 return mGLState.syncDirtyObjects(this, objectMask);
3366}
3367
Jamie Madillc29968b2016-01-20 11:17:23 -05003368void Context::blitFramebuffer(GLint srcX0,
3369 GLint srcY0,
3370 GLint srcX1,
3371 GLint srcY1,
3372 GLint dstX0,
3373 GLint dstY0,
3374 GLint dstX1,
3375 GLint dstY1,
3376 GLbitfield mask,
3377 GLenum filter)
3378{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003379 if (mask == 0)
3380 {
3381 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3382 // buffers are copied.
3383 return;
3384 }
3385
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003386 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003387 ASSERT(drawFramebuffer);
3388
3389 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3390 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3391
Jamie Madillbc918e72018-03-08 09:47:21 -05003392 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003393
Jamie Madillc564c072017-06-01 12:45:42 -04003394 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003395}
Jamie Madillc29968b2016-01-20 11:17:23 -05003396
3397void Context::clear(GLbitfield mask)
3398{
Geoff Langd4fff502017-09-22 11:28:28 -04003399 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3400 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003401}
3402
3403void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3404{
Geoff Langd4fff502017-09-22 11:28:28 -04003405 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3406 ANGLE_CONTEXT_TRY(
3407 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003408}
3409
3410void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3411{
Geoff Langd4fff502017-09-22 11:28:28 -04003412 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3413 ANGLE_CONTEXT_TRY(
3414 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003415}
3416
3417void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3418{
Geoff Langd4fff502017-09-22 11:28:28 -04003419 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3420 ANGLE_CONTEXT_TRY(
3421 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003422}
3423
3424void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3425{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003426 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003427 ASSERT(framebufferObject);
3428
3429 // If a buffer is not present, the clear has no effect
3430 if (framebufferObject->getDepthbuffer() == nullptr &&
3431 framebufferObject->getStencilbuffer() == nullptr)
3432 {
3433 return;
3434 }
3435
Geoff Langd4fff502017-09-22 11:28:28 -04003436 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3437 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003438}
3439
3440void Context::readPixels(GLint x,
3441 GLint y,
3442 GLsizei width,
3443 GLsizei height,
3444 GLenum format,
3445 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003446 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003447{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003448 if (width == 0 || height == 0)
3449 {
3450 return;
3451 }
3452
Jamie Madillbc918e72018-03-08 09:47:21 -05003453 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003454
Jamie Madillb6664922017-07-25 12:55:04 -04003455 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3456 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003457
3458 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003459 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003460}
3461
Brandon Jones59770802018-04-02 13:18:42 -07003462void Context::readPixelsRobust(GLint x,
3463 GLint y,
3464 GLsizei width,
3465 GLsizei height,
3466 GLenum format,
3467 GLenum type,
3468 GLsizei bufSize,
3469 GLsizei *length,
3470 GLsizei *columns,
3471 GLsizei *rows,
3472 void *pixels)
3473{
3474 readPixels(x, y, width, height, format, type, pixels);
3475}
3476
3477void Context::readnPixelsRobust(GLint x,
3478 GLint y,
3479 GLsizei width,
3480 GLsizei height,
3481 GLenum format,
3482 GLenum type,
3483 GLsizei bufSize,
3484 GLsizei *length,
3485 GLsizei *columns,
3486 GLsizei *rows,
3487 void *data)
3488{
3489 readPixels(x, y, width, height, format, type, data);
3490}
3491
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003492void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003493 GLint level,
3494 GLenum internalformat,
3495 GLint x,
3496 GLint y,
3497 GLsizei width,
3498 GLsizei height,
3499 GLint border)
3500{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003501 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003502 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003503
Jamie Madillc29968b2016-01-20 11:17:23 -05003504 Rectangle sourceArea(x, y, width, height);
3505
Jamie Madill05b35b22017-10-03 09:01:44 -04003506 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003507 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003508 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003509}
3510
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003511void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003512 GLint level,
3513 GLint xoffset,
3514 GLint yoffset,
3515 GLint x,
3516 GLint y,
3517 GLsizei width,
3518 GLsizei height)
3519{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003520 if (width == 0 || height == 0)
3521 {
3522 return;
3523 }
3524
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003525 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003526 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003527
Jamie Madillc29968b2016-01-20 11:17:23 -05003528 Offset destOffset(xoffset, yoffset, 0);
3529 Rectangle sourceArea(x, y, width, height);
3530
Jamie Madill05b35b22017-10-03 09:01:44 -04003531 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003532 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003533 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003534}
3535
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003536void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003537 GLint level,
3538 GLint xoffset,
3539 GLint yoffset,
3540 GLint zoffset,
3541 GLint x,
3542 GLint y,
3543 GLsizei width,
3544 GLsizei height)
3545{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003546 if (width == 0 || height == 0)
3547 {
3548 return;
3549 }
3550
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003551 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003552 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003553
Jamie Madillc29968b2016-01-20 11:17:23 -05003554 Offset destOffset(xoffset, yoffset, zoffset);
3555 Rectangle sourceArea(x, y, width, height);
3556
Jamie Madill05b35b22017-10-03 09:01:44 -04003557 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3558 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003559 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3560 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003561}
3562
3563void Context::framebufferTexture2D(GLenum target,
3564 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003565 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003566 GLuint texture,
3567 GLint level)
3568{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003569 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003570 ASSERT(framebuffer);
3571
3572 if (texture != 0)
3573 {
3574 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003575 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003576 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003577 }
3578 else
3579 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003580 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003581 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003582
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003583 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003584}
3585
3586void Context::framebufferRenderbuffer(GLenum target,
3587 GLenum attachment,
3588 GLenum renderbuffertarget,
3589 GLuint renderbuffer)
3590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 ASSERT(framebuffer);
3593
3594 if (renderbuffer != 0)
3595 {
3596 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003597
Jamie Madillcc129372018-04-12 09:13:18 -04003598 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 renderbufferObject);
3600 }
3601 else
3602 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003603 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003604 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003605
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003606 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003607}
3608
3609void Context::framebufferTextureLayer(GLenum target,
3610 GLenum attachment,
3611 GLuint texture,
3612 GLint level,
3613 GLint layer)
3614{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003616 ASSERT(framebuffer);
3617
3618 if (texture != 0)
3619 {
3620 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003621 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003622 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003623 }
3624 else
3625 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003626 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003627 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003628
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003629 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003630}
3631
Brandon Jones59770802018-04-02 13:18:42 -07003632void Context::framebufferTextureMultiviewLayered(GLenum target,
3633 GLenum attachment,
3634 GLuint texture,
3635 GLint level,
3636 GLint baseViewIndex,
3637 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003638{
Martin Radev82ef7742017-08-08 17:44:58 +03003639 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3640 ASSERT(framebuffer);
3641
3642 if (texture != 0)
3643 {
3644 Texture *textureObj = getTexture(texture);
3645
Martin Radev18b75ba2017-08-15 15:50:40 +03003646 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003647 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3648 numViews, baseViewIndex);
3649 }
3650 else
3651 {
3652 framebuffer->resetAttachment(this, attachment);
3653 }
3654
3655 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003656}
3657
Brandon Jones59770802018-04-02 13:18:42 -07003658void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3659 GLenum attachment,
3660 GLuint texture,
3661 GLint level,
3662 GLsizei numViews,
3663 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003664{
Martin Radev5dae57b2017-07-14 16:15:55 +03003665 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3666 ASSERT(framebuffer);
3667
3668 if (texture != 0)
3669 {
3670 Texture *textureObj = getTexture(texture);
3671
3672 ImageIndex index = ImageIndex::Make2D(level);
3673 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3674 textureObj, numViews, viewportOffsets);
3675 }
3676 else
3677 {
3678 framebuffer->resetAttachment(this, attachment);
3679 }
3680
3681 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003682}
3683
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003684// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3685void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3686{
3687 UNIMPLEMENTED();
3688}
3689
Jamie Madillc29968b2016-01-20 11:17:23 -05003690void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3691{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003693 ASSERT(framebuffer);
3694 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003696}
3697
3698void Context::readBuffer(GLenum mode)
3699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003703}
3704
3705void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3706{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003707 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003708 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003709
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 ASSERT(framebuffer);
3712
3713 // The specification isn't clear what should be done when the framebuffer isn't complete.
3714 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003715 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003716}
3717
3718void Context::invalidateFramebuffer(GLenum target,
3719 GLsizei numAttachments,
3720 const GLenum *attachments)
3721{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003722 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003723 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003724
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003726 ASSERT(framebuffer);
3727
Jamie Madill427064d2018-04-13 16:20:34 -04003728 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 {
Jamie Madill437fa652016-05-03 15:13:24 -04003730 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003731 }
Jamie Madill437fa652016-05-03 15:13:24 -04003732
Jamie Madill4928b7c2017-06-20 12:57:39 -04003733 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003734}
3735
3736void Context::invalidateSubFramebuffer(GLenum target,
3737 GLsizei numAttachments,
3738 const GLenum *attachments,
3739 GLint x,
3740 GLint y,
3741 GLsizei width,
3742 GLsizei height)
3743{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003744 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003745 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003746
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003748 ASSERT(framebuffer);
3749
Jamie Madill427064d2018-04-13 16:20:34 -04003750 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 {
Jamie Madill437fa652016-05-03 15:13:24 -04003752 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 }
Jamie Madill437fa652016-05-03 15:13:24 -04003754
3755 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003756 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003757}
3758
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003759void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003760 GLint level,
3761 GLint internalformat,
3762 GLsizei width,
3763 GLsizei height,
3764 GLint border,
3765 GLenum format,
3766 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003767 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003768{
Jamie Madillbc918e72018-03-08 09:47:21 -05003769 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003770
3771 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003772 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003773 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3774 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003775}
3776
Brandon Jones59770802018-04-02 13:18:42 -07003777void Context::texImage2DRobust(TextureTarget target,
3778 GLint level,
3779 GLint internalformat,
3780 GLsizei width,
3781 GLsizei height,
3782 GLint border,
3783 GLenum format,
3784 GLenum type,
3785 GLsizei bufSize,
3786 const void *pixels)
3787{
3788 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3789}
3790
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003791void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003792 GLint level,
3793 GLint internalformat,
3794 GLsizei width,
3795 GLsizei height,
3796 GLsizei depth,
3797 GLint border,
3798 GLenum format,
3799 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003800 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003801{
Jamie Madillbc918e72018-03-08 09:47:21 -05003802 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003803
3804 Extents size(width, height, depth);
3805 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003806 handleError(texture->setImage(this, mGLState.getUnpackState(),
3807 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3808 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003809}
3810
Brandon Jones59770802018-04-02 13:18:42 -07003811void Context::texImage3DRobust(TextureType target,
3812 GLint level,
3813 GLint internalformat,
3814 GLsizei width,
3815 GLsizei height,
3816 GLsizei depth,
3817 GLint border,
3818 GLenum format,
3819 GLenum type,
3820 GLsizei bufSize,
3821 const void *pixels)
3822{
3823 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3824}
3825
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003826void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003827 GLint level,
3828 GLint xoffset,
3829 GLint yoffset,
3830 GLsizei width,
3831 GLsizei height,
3832 GLenum format,
3833 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003834 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003835{
3836 // Zero sized uploads are valid but no-ops
3837 if (width == 0 || height == 0)
3838 {
3839 return;
3840 }
3841
Jamie Madillbc918e72018-03-08 09:47:21 -05003842 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003843
3844 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003845 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003846 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3847 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003848}
3849
Brandon Jones59770802018-04-02 13:18:42 -07003850void Context::texSubImage2DRobust(TextureTarget target,
3851 GLint level,
3852 GLint xoffset,
3853 GLint yoffset,
3854 GLsizei width,
3855 GLsizei height,
3856 GLenum format,
3857 GLenum type,
3858 GLsizei bufSize,
3859 const void *pixels)
3860{
3861 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3862}
3863
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003864void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003865 GLint level,
3866 GLint xoffset,
3867 GLint yoffset,
3868 GLint zoffset,
3869 GLsizei width,
3870 GLsizei height,
3871 GLsizei depth,
3872 GLenum format,
3873 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003874 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003875{
3876 // Zero sized uploads are valid but no-ops
3877 if (width == 0 || height == 0 || depth == 0)
3878 {
3879 return;
3880 }
3881
Jamie Madillbc918e72018-03-08 09:47:21 -05003882 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003883
3884 Box area(xoffset, yoffset, zoffset, width, height, depth);
3885 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003886 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3887 NonCubeTextureTypeToTarget(target), level, area, format, type,
3888 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003889}
3890
Brandon Jones59770802018-04-02 13:18:42 -07003891void Context::texSubImage3DRobust(TextureType target,
3892 GLint level,
3893 GLint xoffset,
3894 GLint yoffset,
3895 GLint zoffset,
3896 GLsizei width,
3897 GLsizei height,
3898 GLsizei depth,
3899 GLenum format,
3900 GLenum type,
3901 GLsizei bufSize,
3902 const void *pixels)
3903{
3904 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3905 pixels);
3906}
3907
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003908void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003909 GLint level,
3910 GLenum internalformat,
3911 GLsizei width,
3912 GLsizei height,
3913 GLint border,
3914 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003915 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003916{
Jamie Madillbc918e72018-03-08 09:47:21 -05003917 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003918
3919 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003920 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003921 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3922 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003923 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003924}
3925
Brandon Jones59770802018-04-02 13:18:42 -07003926void Context::compressedTexImage2DRobust(TextureTarget target,
3927 GLint level,
3928 GLenum internalformat,
3929 GLsizei width,
3930 GLsizei height,
3931 GLint border,
3932 GLsizei imageSize,
3933 GLsizei dataSize,
3934 const GLvoid *data)
3935{
3936 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3937}
3938
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003939void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003940 GLint level,
3941 GLenum internalformat,
3942 GLsizei width,
3943 GLsizei height,
3944 GLsizei depth,
3945 GLint border,
3946 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003947 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003948{
Jamie Madillbc918e72018-03-08 09:47:21 -05003949 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003950
3951 Extents size(width, height, depth);
3952 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003953 handleError(texture->setCompressedImage(
3954 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3955 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003956}
3957
Brandon Jones59770802018-04-02 13:18:42 -07003958void Context::compressedTexImage3DRobust(TextureType target,
3959 GLint level,
3960 GLenum internalformat,
3961 GLsizei width,
3962 GLsizei height,
3963 GLsizei depth,
3964 GLint border,
3965 GLsizei imageSize,
3966 GLsizei dataSize,
3967 const GLvoid *data)
3968{
3969 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3970 data);
3971}
3972
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003973void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003974 GLint level,
3975 GLint xoffset,
3976 GLint yoffset,
3977 GLsizei width,
3978 GLsizei height,
3979 GLenum format,
3980 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003981 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003982{
Jamie Madillbc918e72018-03-08 09:47:21 -05003983 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003984
3985 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003986 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003987 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3988 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003989 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003990}
3991
Brandon Jones59770802018-04-02 13:18:42 -07003992void Context::compressedTexSubImage2DRobust(TextureTarget target,
3993 GLint level,
3994 GLint xoffset,
3995 GLint yoffset,
3996 GLsizei width,
3997 GLsizei height,
3998 GLenum format,
3999 GLsizei imageSize,
4000 GLsizei dataSize,
4001 const GLvoid *data)
4002{
4003 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4004 data);
4005}
4006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004007void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004008 GLint level,
4009 GLint xoffset,
4010 GLint yoffset,
4011 GLint zoffset,
4012 GLsizei width,
4013 GLsizei height,
4014 GLsizei depth,
4015 GLenum format,
4016 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004017 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004018{
4019 // Zero sized uploads are valid but no-ops
4020 if (width == 0 || height == 0)
4021 {
4022 return;
4023 }
4024
Jamie Madillbc918e72018-03-08 09:47:21 -05004025 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004026
4027 Box area(xoffset, yoffset, zoffset, width, height, depth);
4028 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004029 handleError(texture->setCompressedSubImage(
4030 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4031 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004032}
4033
Brandon Jones59770802018-04-02 13:18:42 -07004034void Context::compressedTexSubImage3DRobust(TextureType target,
4035 GLint level,
4036 GLint xoffset,
4037 GLint yoffset,
4038 GLint zoffset,
4039 GLsizei width,
4040 GLsizei height,
4041 GLsizei depth,
4042 GLenum format,
4043 GLsizei imageSize,
4044 GLsizei dataSize,
4045 const GLvoid *data)
4046{
4047 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4048 imageSize, data);
4049}
4050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004051void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004052{
4053 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004054 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004055}
4056
Jamie Madill007530e2017-12-28 14:27:04 -05004057void Context::copyTexture(GLuint sourceId,
4058 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004059 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004060 GLuint destId,
4061 GLint destLevel,
4062 GLint internalFormat,
4063 GLenum destType,
4064 GLboolean unpackFlipY,
4065 GLboolean unpackPremultiplyAlpha,
4066 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004067{
Jamie Madillbc918e72018-03-08 09:47:21 -05004068 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004069
4070 gl::Texture *sourceTexture = getTexture(sourceId);
4071 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004072 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4073 sourceLevel, ConvertToBool(unpackFlipY),
4074 ConvertToBool(unpackPremultiplyAlpha),
4075 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004076}
4077
Jamie Madill007530e2017-12-28 14:27:04 -05004078void Context::copySubTexture(GLuint sourceId,
4079 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004080 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004081 GLuint destId,
4082 GLint destLevel,
4083 GLint xoffset,
4084 GLint yoffset,
4085 GLint x,
4086 GLint y,
4087 GLsizei width,
4088 GLsizei height,
4089 GLboolean unpackFlipY,
4090 GLboolean unpackPremultiplyAlpha,
4091 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004092{
4093 // Zero sized copies are valid but no-ops
4094 if (width == 0 || height == 0)
4095 {
4096 return;
4097 }
4098
Jamie Madillbc918e72018-03-08 09:47:21 -05004099 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004100
4101 gl::Texture *sourceTexture = getTexture(sourceId);
4102 gl::Texture *destTexture = getTexture(destId);
4103 Offset offset(xoffset, yoffset, 0);
4104 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004105 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4106 ConvertToBool(unpackFlipY),
4107 ConvertToBool(unpackPremultiplyAlpha),
4108 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004109}
4110
Jamie Madill007530e2017-12-28 14:27:04 -05004111void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004112{
Jamie Madillbc918e72018-03-08 09:47:21 -05004113 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004114
4115 gl::Texture *sourceTexture = getTexture(sourceId);
4116 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004117 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004118}
4119
Corentin Wallez336129f2017-10-17 15:55:40 -04004120void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004121{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004122 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004123 ASSERT(buffer);
4124
Geoff Lang496c02d2016-10-20 11:38:11 -07004125 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004126}
4127
Brandon Jones59770802018-04-02 13:18:42 -07004128void Context::getBufferPointervRobust(BufferBinding target,
4129 GLenum pname,
4130 GLsizei bufSize,
4131 GLsizei *length,
4132 void **params)
4133{
4134 getBufferPointerv(target, pname, params);
4135}
4136
Corentin Wallez336129f2017-10-17 15:55:40 -04004137void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004138{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004139 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004140 ASSERT(buffer);
4141
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004142 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004143 if (error.isError())
4144 {
Jamie Madill437fa652016-05-03 15:13:24 -04004145 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004146 return nullptr;
4147 }
4148
4149 return buffer->getMapPointer();
4150}
4151
Corentin Wallez336129f2017-10-17 15:55:40 -04004152GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004153{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004154 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004155 ASSERT(buffer);
4156
4157 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004158 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004159 if (error.isError())
4160 {
Jamie Madill437fa652016-05-03 15:13:24 -04004161 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004162 return GL_FALSE;
4163 }
4164
4165 return result;
4166}
4167
Corentin Wallez336129f2017-10-17 15:55:40 -04004168void *Context::mapBufferRange(BufferBinding target,
4169 GLintptr offset,
4170 GLsizeiptr length,
4171 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004172{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004173 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004174 ASSERT(buffer);
4175
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004176 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004177 if (error.isError())
4178 {
Jamie Madill437fa652016-05-03 15:13:24 -04004179 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 return nullptr;
4181 }
4182
4183 return buffer->getMapPointer();
4184}
4185
Corentin Wallez336129f2017-10-17 15:55:40 -04004186void Context::flushMappedBufferRange(BufferBinding /*target*/,
4187 GLintptr /*offset*/,
4188 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004189{
4190 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4191}
4192
Jamie Madillbc918e72018-03-08 09:47:21 -05004193Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004194{
Geoff Langa8cb2872018-03-09 16:09:40 -05004195 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004196}
4197
Jamie Madillbc918e72018-03-08 09:47:21 -05004198Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004199{
Geoff Langa8cb2872018-03-09 16:09:40 -05004200 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004201}
4202
Jamie Madillbc918e72018-03-08 09:47:21 -05004203Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004204{
Geoff Langa8cb2872018-03-09 16:09:40 -05004205 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004206}
4207
Jiajia Qin5451d532017-11-16 17:16:34 +08004208void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4209{
4210 UNIMPLEMENTED();
4211}
4212
Jamie Madillc20ab272016-06-09 07:20:46 -07004213void Context::activeTexture(GLenum texture)
4214{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004215 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004216}
4217
Jamie Madill876429b2017-04-20 15:46:24 -04004218void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004219{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004220 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004221}
4222
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004223void Context::blendEquation(GLenum mode)
4224{
4225 mGLState.setBlendEquation(mode, mode);
4226}
4227
Jamie Madillc20ab272016-06-09 07:20:46 -07004228void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4229{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004230 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004231}
4232
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004233void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4234{
4235 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4236}
4237
Jamie Madillc20ab272016-06-09 07:20:46 -07004238void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4239{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004240 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004241}
4242
Jamie Madill876429b2017-04-20 15:46:24 -04004243void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004244{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004245 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004246}
4247
Jamie Madill876429b2017-04-20 15:46:24 -04004248void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004249{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004250 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004251}
4252
4253void Context::clearStencil(GLint s)
4254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004256}
4257
4258void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4259{
Geoff Lang92019432017-11-20 13:09:34 -05004260 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4261 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004262}
4263
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004264void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004265{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004266 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004267}
4268
4269void Context::depthFunc(GLenum func)
4270{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004271 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004272}
4273
4274void Context::depthMask(GLboolean flag)
4275{
Geoff Lang92019432017-11-20 13:09:34 -05004276 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004277}
4278
Jamie Madill876429b2017-04-20 15:46:24 -04004279void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004280{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004282}
4283
4284void Context::disable(GLenum cap)
4285{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004286 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004287}
4288
4289void Context::disableVertexAttribArray(GLuint index)
4290{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004291 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004292}
4293
4294void Context::enable(GLenum cap)
4295{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004297}
4298
4299void Context::enableVertexAttribArray(GLuint index)
4300{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004301 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004302}
4303
4304void Context::frontFace(GLenum mode)
4305{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004306 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004307}
4308
4309void Context::hint(GLenum target, GLenum mode)
4310{
4311 switch (target)
4312 {
4313 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004314 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004315 break;
4316
4317 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004319 break;
4320
4321 default:
4322 UNREACHABLE();
4323 return;
4324 }
4325}
4326
4327void Context::lineWidth(GLfloat width)
4328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004330}
4331
4332void Context::pixelStorei(GLenum pname, GLint param)
4333{
4334 switch (pname)
4335 {
4336 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004337 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004338 break;
4339
4340 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004341 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004342 break;
4343
4344 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346 break;
4347
4348 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004349 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351 break;
4352
4353 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004354 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356 break;
4357
4358 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004359 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004360 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004361 break;
4362
4363 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004364 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004365 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004366 break;
4367
4368 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004369 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004370 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004371 break;
4372
4373 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004374 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376 break;
4377
4378 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004379 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004380 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004381 break;
4382
4383 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004384 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386 break;
4387
4388 default:
4389 UNREACHABLE();
4390 return;
4391 }
4392}
4393
4394void Context::polygonOffset(GLfloat factor, GLfloat units)
4395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
Jamie Madill876429b2017-04-20 15:46:24 -04004399void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004400{
Geoff Lang92019432017-11-20 13:09:34 -05004401 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
Jiawei Shaodb342272017-09-27 10:21:45 +08004404void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4405{
4406 mGLState.setSampleMaskParams(maskNumber, mask);
4407}
4408
Jamie Madillc20ab272016-06-09 07:20:46 -07004409void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4410{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
4414void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4415{
4416 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4417 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419 }
4420
4421 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4422 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424 }
4425}
4426
4427void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4428{
4429 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4430 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004431 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004432 }
4433
4434 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4435 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004437 }
4438}
4439
4440void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4441{
4442 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4443 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004444 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004445 }
4446
4447 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4448 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004449 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004450 }
4451}
4452
4453void Context::vertexAttrib1f(GLuint index, GLfloat x)
4454{
4455 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
4459void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4460{
4461 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004462 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004463}
4464
4465void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4466{
4467 GLfloat vals[4] = {x, y, 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::vertexAttrib2fv(GLuint index, const GLfloat *values)
4472{
4473 GLfloat vals[4] = {values[0], values[1], 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::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4478{
4479 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
4483void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4484{
4485 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487}
4488
4489void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4490{
4491 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
4495void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498}
4499
4500void Context::vertexAttribPointer(GLuint index,
4501 GLint size,
4502 GLenum type,
4503 GLboolean normalized,
4504 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004505 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004506{
Corentin Wallez336129f2017-10-17 15:55:40 -04004507 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004508 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004509}
4510
Shao80957d92017-02-20 21:25:59 +08004511void Context::vertexAttribFormat(GLuint attribIndex,
4512 GLint size,
4513 GLenum type,
4514 GLboolean normalized,
4515 GLuint relativeOffset)
4516{
Geoff Lang92019432017-11-20 13:09:34 -05004517 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004518 relativeOffset);
4519}
4520
4521void Context::vertexAttribIFormat(GLuint attribIndex,
4522 GLint size,
4523 GLenum type,
4524 GLuint relativeOffset)
4525{
4526 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4527}
4528
4529void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4530{
Shaodde78e82017-05-22 14:13:27 +08004531 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004532}
4533
Jiajia Qin5451d532017-11-16 17:16:34 +08004534void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004535{
4536 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4537}
4538
Jamie Madillc20ab272016-06-09 07:20:46 -07004539void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4540{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::vertexAttribIPointer(GLuint index,
4545 GLint size,
4546 GLenum type,
4547 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004548 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004549{
Corentin Wallez336129f2017-10-17 15:55:40 -04004550 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4551 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004552}
4553
4554void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4555{
4556 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
4560void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4561{
4562 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564}
4565
4566void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004576void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4577{
4578 const VertexAttribCurrentValueData &currentValues =
4579 getGLState().getVertexAttribCurrentValue(index);
4580 const VertexArray *vao = getGLState().getVertexArray();
4581 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4582 currentValues, pname, params);
4583}
4584
Brandon Jones59770802018-04-02 13:18:42 -07004585void Context::getVertexAttribivRobust(GLuint index,
4586 GLenum pname,
4587 GLsizei bufSize,
4588 GLsizei *length,
4589 GLint *params)
4590{
4591 getVertexAttribiv(index, pname, params);
4592}
4593
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004594void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4595{
4596 const VertexAttribCurrentValueData &currentValues =
4597 getGLState().getVertexAttribCurrentValue(index);
4598 const VertexArray *vao = getGLState().getVertexArray();
4599 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4600 currentValues, pname, params);
4601}
4602
Brandon Jones59770802018-04-02 13:18:42 -07004603void Context::getVertexAttribfvRobust(GLuint index,
4604 GLenum pname,
4605 GLsizei bufSize,
4606 GLsizei *length,
4607 GLfloat *params)
4608{
4609 getVertexAttribfv(index, pname, params);
4610}
4611
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004612void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4613{
4614 const VertexAttribCurrentValueData &currentValues =
4615 getGLState().getVertexAttribCurrentValue(index);
4616 const VertexArray *vao = getGLState().getVertexArray();
4617 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4618 currentValues, pname, params);
4619}
4620
Brandon Jones59770802018-04-02 13:18:42 -07004621void Context::getVertexAttribIivRobust(GLuint index,
4622 GLenum pname,
4623 GLsizei bufSize,
4624 GLsizei *length,
4625 GLint *params)
4626{
4627 getVertexAttribIiv(index, pname, params);
4628}
4629
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004630void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4631{
4632 const VertexAttribCurrentValueData &currentValues =
4633 getGLState().getVertexAttribCurrentValue(index);
4634 const VertexArray *vao = getGLState().getVertexArray();
4635 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4636 currentValues, pname, params);
4637}
4638
Brandon Jones59770802018-04-02 13:18:42 -07004639void Context::getVertexAttribIuivRobust(GLuint index,
4640 GLenum pname,
4641 GLsizei bufSize,
4642 GLsizei *length,
4643 GLuint *params)
4644{
4645 getVertexAttribIuiv(index, pname, params);
4646}
4647
Jamie Madill876429b2017-04-20 15:46:24 -04004648void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004649{
4650 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4651 QueryVertexAttribPointerv(attrib, pname, pointer);
4652}
4653
Brandon Jones59770802018-04-02 13:18:42 -07004654void Context::getVertexAttribPointervRobust(GLuint index,
4655 GLenum pname,
4656 GLsizei bufSize,
4657 GLsizei *length,
4658 void **pointer)
4659{
4660 getVertexAttribPointerv(index, pname, pointer);
4661}
4662
Jamie Madillc20ab272016-06-09 07:20:46 -07004663void Context::debugMessageControl(GLenum source,
4664 GLenum type,
4665 GLenum severity,
4666 GLsizei count,
4667 const GLuint *ids,
4668 GLboolean enabled)
4669{
4670 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004671 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004672 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
4675void Context::debugMessageInsert(GLenum source,
4676 GLenum type,
4677 GLuint id,
4678 GLenum severity,
4679 GLsizei length,
4680 const GLchar *buf)
4681{
4682 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004683 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004684}
4685
4686void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4687{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004688 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004689}
4690
4691GLuint Context::getDebugMessageLog(GLuint count,
4692 GLsizei bufSize,
4693 GLenum *sources,
4694 GLenum *types,
4695 GLuint *ids,
4696 GLenum *severities,
4697 GLsizei *lengths,
4698 GLchar *messageLog)
4699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004700 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4701 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004702}
4703
4704void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4705{
4706 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004708 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709}
4710
4711void Context::popDebugGroup()
4712{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004713 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004714 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004715}
4716
Corentin Wallez336129f2017-10-17 15:55:40 -04004717void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004718{
4719 Buffer *buffer = mGLState.getTargetBuffer(target);
4720 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004721 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004722}
4723
Corentin Wallez336129f2017-10-17 15:55:40 -04004724void Context::bufferSubData(BufferBinding target,
4725 GLintptr offset,
4726 GLsizeiptr size,
4727 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004728{
4729 if (data == nullptr)
4730 {
4731 return;
4732 }
4733
4734 Buffer *buffer = mGLState.getTargetBuffer(target);
4735 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004736 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004737}
4738
Jamie Madillef300b12016-10-07 15:12:09 -04004739void Context::attachShader(GLuint program, GLuint shader)
4740{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004741 Program *programObject = mState.mShaderPrograms->getProgram(program);
4742 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004743 ASSERT(programObject && shaderObject);
4744 programObject->attachShader(shaderObject);
4745}
4746
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004747const Workarounds &Context::getWorkarounds() const
4748{
4749 return mWorkarounds;
4750}
4751
Corentin Wallez336129f2017-10-17 15:55:40 -04004752void Context::copyBufferSubData(BufferBinding readTarget,
4753 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004754 GLintptr readOffset,
4755 GLintptr writeOffset,
4756 GLsizeiptr size)
4757{
4758 // if size is zero, the copy is a successful no-op
4759 if (size == 0)
4760 {
4761 return;
4762 }
4763
4764 // TODO(jmadill): cache these.
4765 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4766 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4767
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004768 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004769}
4770
Jamie Madill01a80ee2016-11-07 12:06:18 -05004771void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4772{
4773 Program *programObject = getProgram(program);
4774 // TODO(jmadill): Re-use this from the validation if possible.
4775 ASSERT(programObject);
4776 programObject->bindAttributeLocation(index, name);
4777}
4778
Corentin Wallez336129f2017-10-17 15:55:40 -04004779void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004780{
Corentin Wallez336129f2017-10-17 15:55:40 -04004781 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4782 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783}
4784
Corentin Wallez336129f2017-10-17 15:55:40 -04004785void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004786{
4787 bindBufferRange(target, index, buffer, 0, 0);
4788}
4789
Corentin Wallez336129f2017-10-17 15:55:40 -04004790void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004791 GLuint index,
4792 GLuint buffer,
4793 GLintptr offset,
4794 GLsizeiptr size)
4795{
Corentin Wallez336129f2017-10-17 15:55:40 -04004796 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4797 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004798}
4799
Jamie Madill01a80ee2016-11-07 12:06:18 -05004800void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4801{
4802 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4803 {
4804 bindReadFramebuffer(framebuffer);
4805 }
4806
4807 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4808 {
4809 bindDrawFramebuffer(framebuffer);
4810 }
4811}
4812
4813void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4814{
4815 ASSERT(target == GL_RENDERBUFFER);
4816 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004817 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004818 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004819}
4820
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004821void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004822 GLsizei samples,
4823 GLenum internalformat,
4824 GLsizei width,
4825 GLsizei height,
4826 GLboolean fixedsamplelocations)
4827{
4828 Extents size(width, height, 1);
4829 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004830 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4831 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004832}
4833
4834void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4835{
JiangYizhou5b03f472017-01-09 10:22:53 +08004836 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4837 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004838 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004839 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004840
4841 switch (pname)
4842 {
4843 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004844 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004845 break;
4846 default:
4847 UNREACHABLE();
4848 }
4849}
4850
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004851void Context::getMultisamplefvRobust(GLenum pname,
4852 GLuint index,
4853 GLsizei bufSize,
4854 GLsizei *length,
4855 GLfloat *val)
4856{
4857 UNIMPLEMENTED();
4858}
4859
Jamie Madille8fb6402017-02-14 17:56:40 -05004860void Context::renderbufferStorage(GLenum target,
4861 GLenum internalformat,
4862 GLsizei width,
4863 GLsizei height)
4864{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004865 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4866 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4867
Jamie Madille8fb6402017-02-14 17:56:40 -05004868 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004869 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004870}
4871
4872void Context::renderbufferStorageMultisample(GLenum target,
4873 GLsizei samples,
4874 GLenum internalformat,
4875 GLsizei width,
4876 GLsizei height)
4877{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004878 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4879 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004880
4881 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004882 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004883 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004884}
4885
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004886void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4887{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004888 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004889 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004890}
4891
JiangYizhoue18e6392017-02-20 10:32:23 +08004892void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4893{
4894 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4895 QueryFramebufferParameteriv(framebuffer, pname, params);
4896}
4897
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004898void Context::getFramebufferParameterivRobust(GLenum target,
4899 GLenum pname,
4900 GLsizei bufSize,
4901 GLsizei *length,
4902 GLint *params)
4903{
4904 UNIMPLEMENTED();
4905}
4906
Jiajia Qin5451d532017-11-16 17:16:34 +08004907void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004908{
4909 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4910 SetFramebufferParameteri(framebuffer, pname, param);
4911}
4912
Jamie Madillb3f26b92017-07-19 15:07:41 -04004913Error Context::getScratchBuffer(size_t requstedSizeBytes,
4914 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004915{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004916 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4917 {
4918 return OutOfMemory() << "Failed to allocate internal buffer.";
4919 }
4920 return NoError();
4921}
4922
4923Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4924 angle::MemoryBuffer **zeroBufferOut) const
4925{
4926 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004927 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004928 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004929 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004930 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004931}
4932
Xinghua Cao10a4d432017-11-28 14:46:26 +08004933Error Context::prepareForDispatch()
4934{
Geoff Langa8cb2872018-03-09 16:09:40 -05004935 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004936
4937 if (isRobustResourceInitEnabled())
4938 {
4939 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4940 }
4941
4942 return NoError();
4943}
4944
Xinghua Cao2b396592017-03-29 15:36:04 +08004945void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4946{
4947 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4948 {
4949 return;
4950 }
4951
Xinghua Cao10a4d432017-11-28 14:46:26 +08004952 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004953 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004954}
4955
Jiajia Qin5451d532017-11-16 17:16:34 +08004956void Context::dispatchComputeIndirect(GLintptr indirect)
4957{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004958 ANGLE_CONTEXT_TRY(prepareForDispatch());
4959 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004960}
4961
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004962void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004963 GLsizei levels,
4964 GLenum internalFormat,
4965 GLsizei width,
4966 GLsizei height)
4967{
4968 Extents size(width, height, 1);
4969 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004970 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004971}
4972
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004973void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004974 GLsizei levels,
4975 GLenum internalFormat,
4976 GLsizei width,
4977 GLsizei height,
4978 GLsizei depth)
4979{
4980 Extents size(width, height, depth);
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
Jiajia Qin5451d532017-11-16 17:16:34 +08004985void Context::memoryBarrier(GLbitfield barriers)
4986{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004987 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004988}
4989
4990void Context::memoryBarrierByRegion(GLbitfield barriers)
4991{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004992 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004993}
4994
Jamie Madillc1d770e2017-04-13 17:31:24 -04004995GLenum Context::checkFramebufferStatus(GLenum target)
4996{
4997 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4998 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004999 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005000}
5001
5002void Context::compileShader(GLuint shader)
5003{
5004 Shader *shaderObject = GetValidShader(this, shader);
5005 if (!shaderObject)
5006 {
5007 return;
5008 }
5009 shaderObject->compile(this);
5010}
5011
5012void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5013{
5014 for (int i = 0; i < n; i++)
5015 {
5016 deleteBuffer(buffers[i]);
5017 }
5018}
5019
5020void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5021{
5022 for (int i = 0; i < n; i++)
5023 {
5024 if (framebuffers[i] != 0)
5025 {
5026 deleteFramebuffer(framebuffers[i]);
5027 }
5028 }
5029}
5030
5031void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5032{
5033 for (int i = 0; i < n; i++)
5034 {
5035 deleteRenderbuffer(renderbuffers[i]);
5036 }
5037}
5038
5039void Context::deleteTextures(GLsizei n, const GLuint *textures)
5040{
5041 for (int i = 0; i < n; i++)
5042 {
5043 if (textures[i] != 0)
5044 {
5045 deleteTexture(textures[i]);
5046 }
5047 }
5048}
5049
5050void Context::detachShader(GLuint program, GLuint shader)
5051{
5052 Program *programObject = getProgram(program);
5053 ASSERT(programObject);
5054
5055 Shader *shaderObject = getShader(shader);
5056 ASSERT(shaderObject);
5057
5058 programObject->detachShader(this, shaderObject);
5059}
5060
5061void Context::genBuffers(GLsizei n, GLuint *buffers)
5062{
5063 for (int i = 0; i < n; i++)
5064 {
5065 buffers[i] = createBuffer();
5066 }
5067}
5068
5069void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5070{
5071 for (int i = 0; i < n; i++)
5072 {
5073 framebuffers[i] = createFramebuffer();
5074 }
5075}
5076
5077void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5078{
5079 for (int i = 0; i < n; i++)
5080 {
5081 renderbuffers[i] = createRenderbuffer();
5082 }
5083}
5084
5085void Context::genTextures(GLsizei n, GLuint *textures)
5086{
5087 for (int i = 0; i < n; i++)
5088 {
5089 textures[i] = createTexture();
5090 }
5091}
5092
5093void Context::getActiveAttrib(GLuint program,
5094 GLuint index,
5095 GLsizei bufsize,
5096 GLsizei *length,
5097 GLint *size,
5098 GLenum *type,
5099 GLchar *name)
5100{
5101 Program *programObject = getProgram(program);
5102 ASSERT(programObject);
5103 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5104}
5105
5106void Context::getActiveUniform(GLuint program,
5107 GLuint index,
5108 GLsizei bufsize,
5109 GLsizei *length,
5110 GLint *size,
5111 GLenum *type,
5112 GLchar *name)
5113{
5114 Program *programObject = getProgram(program);
5115 ASSERT(programObject);
5116 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5117}
5118
5119void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5120{
5121 Program *programObject = getProgram(program);
5122 ASSERT(programObject);
5123 programObject->getAttachedShaders(maxcount, count, shaders);
5124}
5125
5126GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5127{
5128 Program *programObject = getProgram(program);
5129 ASSERT(programObject);
5130 return programObject->getAttributeLocation(name);
5131}
5132
5133void Context::getBooleanv(GLenum pname, GLboolean *params)
5134{
5135 GLenum nativeType;
5136 unsigned int numParams = 0;
5137 getQueryParameterInfo(pname, &nativeType, &numParams);
5138
5139 if (nativeType == GL_BOOL)
5140 {
5141 getBooleanvImpl(pname, params);
5142 }
5143 else
5144 {
5145 CastStateValues(this, nativeType, pname, numParams, params);
5146 }
5147}
5148
Brandon Jones59770802018-04-02 13:18:42 -07005149void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5150{
5151 getBooleanv(pname, params);
5152}
5153
Jamie Madillc1d770e2017-04-13 17:31:24 -04005154void Context::getFloatv(GLenum pname, GLfloat *params)
5155{
5156 GLenum nativeType;
5157 unsigned int numParams = 0;
5158 getQueryParameterInfo(pname, &nativeType, &numParams);
5159
5160 if (nativeType == GL_FLOAT)
5161 {
5162 getFloatvImpl(pname, params);
5163 }
5164 else
5165 {
5166 CastStateValues(this, nativeType, pname, numParams, params);
5167 }
5168}
5169
Brandon Jones59770802018-04-02 13:18:42 -07005170void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5171{
5172 getFloatv(pname, params);
5173}
5174
Jamie Madillc1d770e2017-04-13 17:31:24 -04005175void Context::getIntegerv(GLenum pname, GLint *params)
5176{
5177 GLenum nativeType;
5178 unsigned int numParams = 0;
5179 getQueryParameterInfo(pname, &nativeType, &numParams);
5180
5181 if (nativeType == GL_INT)
5182 {
5183 getIntegervImpl(pname, params);
5184 }
5185 else
5186 {
5187 CastStateValues(this, nativeType, pname, numParams, params);
5188 }
5189}
5190
Brandon Jones59770802018-04-02 13:18:42 -07005191void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5192{
5193 getIntegerv(pname, data);
5194}
5195
Jamie Madillc1d770e2017-04-13 17:31:24 -04005196void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5197{
5198 Program *programObject = getProgram(program);
5199 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005200 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005201}
5202
Brandon Jones59770802018-04-02 13:18:42 -07005203void Context::getProgramivRobust(GLuint program,
5204 GLenum pname,
5205 GLsizei bufSize,
5206 GLsizei *length,
5207 GLint *params)
5208{
5209 getProgramiv(program, pname, params);
5210}
5211
Jiajia Qin5451d532017-11-16 17:16:34 +08005212void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5213{
5214 UNIMPLEMENTED();
5215}
5216
Jamie Madillbe849e42017-05-02 15:49:00 -04005217void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005218{
5219 Program *programObject = getProgram(program);
5220 ASSERT(programObject);
5221 programObject->getInfoLog(bufsize, length, infolog);
5222}
5223
Jiajia Qin5451d532017-11-16 17:16:34 +08005224void Context::getProgramPipelineInfoLog(GLuint pipeline,
5225 GLsizei bufSize,
5226 GLsizei *length,
5227 GLchar *infoLog)
5228{
5229 UNIMPLEMENTED();
5230}
5231
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5233{
5234 Shader *shaderObject = getShader(shader);
5235 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005236 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005237}
5238
Brandon Jones59770802018-04-02 13:18:42 -07005239void Context::getShaderivRobust(GLuint shader,
5240 GLenum pname,
5241 GLsizei bufSize,
5242 GLsizei *length,
5243 GLint *params)
5244{
5245 getShaderiv(shader, pname, params);
5246}
5247
Jamie Madillc1d770e2017-04-13 17:31:24 -04005248void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5249{
5250 Shader *shaderObject = getShader(shader);
5251 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005252 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005253}
5254
5255void Context::getShaderPrecisionFormat(GLenum shadertype,
5256 GLenum precisiontype,
5257 GLint *range,
5258 GLint *precision)
5259{
5260 // TODO(jmadill): Compute shaders.
5261
5262 switch (shadertype)
5263 {
5264 case GL_VERTEX_SHADER:
5265 switch (precisiontype)
5266 {
5267 case GL_LOW_FLOAT:
5268 mCaps.vertexLowpFloat.get(range, precision);
5269 break;
5270 case GL_MEDIUM_FLOAT:
5271 mCaps.vertexMediumpFloat.get(range, precision);
5272 break;
5273 case GL_HIGH_FLOAT:
5274 mCaps.vertexHighpFloat.get(range, precision);
5275 break;
5276
5277 case GL_LOW_INT:
5278 mCaps.vertexLowpInt.get(range, precision);
5279 break;
5280 case GL_MEDIUM_INT:
5281 mCaps.vertexMediumpInt.get(range, precision);
5282 break;
5283 case GL_HIGH_INT:
5284 mCaps.vertexHighpInt.get(range, precision);
5285 break;
5286
5287 default:
5288 UNREACHABLE();
5289 return;
5290 }
5291 break;
5292
5293 case GL_FRAGMENT_SHADER:
5294 switch (precisiontype)
5295 {
5296 case GL_LOW_FLOAT:
5297 mCaps.fragmentLowpFloat.get(range, precision);
5298 break;
5299 case GL_MEDIUM_FLOAT:
5300 mCaps.fragmentMediumpFloat.get(range, precision);
5301 break;
5302 case GL_HIGH_FLOAT:
5303 mCaps.fragmentHighpFloat.get(range, precision);
5304 break;
5305
5306 case GL_LOW_INT:
5307 mCaps.fragmentLowpInt.get(range, precision);
5308 break;
5309 case GL_MEDIUM_INT:
5310 mCaps.fragmentMediumpInt.get(range, precision);
5311 break;
5312 case GL_HIGH_INT:
5313 mCaps.fragmentHighpInt.get(range, precision);
5314 break;
5315
5316 default:
5317 UNREACHABLE();
5318 return;
5319 }
5320 break;
5321
5322 default:
5323 UNREACHABLE();
5324 return;
5325 }
5326}
5327
5328void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5329{
5330 Shader *shaderObject = getShader(shader);
5331 ASSERT(shaderObject);
5332 shaderObject->getSource(bufsize, length, source);
5333}
5334
5335void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5336{
5337 Program *programObject = getProgram(program);
5338 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005339 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340}
5341
Brandon Jones59770802018-04-02 13:18:42 -07005342void Context::getUniformfvRobust(GLuint program,
5343 GLint location,
5344 GLsizei bufSize,
5345 GLsizei *length,
5346 GLfloat *params)
5347{
5348 getUniformfv(program, location, params);
5349}
5350
Jamie Madillc1d770e2017-04-13 17:31:24 -04005351void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5352{
5353 Program *programObject = getProgram(program);
5354 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005355 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005356}
5357
Brandon Jones59770802018-04-02 13:18:42 -07005358void Context::getUniformivRobust(GLuint program,
5359 GLint location,
5360 GLsizei bufSize,
5361 GLsizei *length,
5362 GLint *params)
5363{
5364 getUniformiv(program, location, params);
5365}
5366
Jamie Madillc1d770e2017-04-13 17:31:24 -04005367GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5368{
5369 Program *programObject = getProgram(program);
5370 ASSERT(programObject);
5371 return programObject->getUniformLocation(name);
5372}
5373
5374GLboolean Context::isBuffer(GLuint buffer)
5375{
5376 if (buffer == 0)
5377 {
5378 return GL_FALSE;
5379 }
5380
5381 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5382}
5383
5384GLboolean Context::isEnabled(GLenum cap)
5385{
5386 return mGLState.getEnableFeature(cap);
5387}
5388
5389GLboolean Context::isFramebuffer(GLuint framebuffer)
5390{
5391 if (framebuffer == 0)
5392 {
5393 return GL_FALSE;
5394 }
5395
5396 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5397}
5398
5399GLboolean Context::isProgram(GLuint program)
5400{
5401 if (program == 0)
5402 {
5403 return GL_FALSE;
5404 }
5405
5406 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5407}
5408
5409GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5410{
5411 if (renderbuffer == 0)
5412 {
5413 return GL_FALSE;
5414 }
5415
5416 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5417}
5418
5419GLboolean Context::isShader(GLuint shader)
5420{
5421 if (shader == 0)
5422 {
5423 return GL_FALSE;
5424 }
5425
5426 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5427}
5428
5429GLboolean Context::isTexture(GLuint texture)
5430{
5431 if (texture == 0)
5432 {
5433 return GL_FALSE;
5434 }
5435
5436 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5437}
5438
5439void Context::linkProgram(GLuint program)
5440{
5441 Program *programObject = getProgram(program);
5442 ASSERT(programObject);
5443 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005444 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005445}
5446
5447void Context::releaseShaderCompiler()
5448{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005449 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450}
5451
5452void Context::shaderBinary(GLsizei n,
5453 const GLuint *shaders,
5454 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005455 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005456 GLsizei length)
5457{
5458 // No binary shader formats are supported.
5459 UNIMPLEMENTED();
5460}
5461
5462void Context::shaderSource(GLuint shader,
5463 GLsizei count,
5464 const GLchar *const *string,
5465 const GLint *length)
5466{
5467 Shader *shaderObject = getShader(shader);
5468 ASSERT(shaderObject);
5469 shaderObject->setSource(count, string, length);
5470}
5471
5472void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5473{
5474 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5475}
5476
5477void Context::stencilMask(GLuint mask)
5478{
5479 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5480}
5481
5482void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5483{
5484 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5485}
5486
5487void Context::uniform1f(GLint location, GLfloat x)
5488{
5489 Program *program = mGLState.getProgram();
5490 program->setUniform1fv(location, 1, &x);
5491}
5492
5493void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5494{
5495 Program *program = mGLState.getProgram();
5496 program->setUniform1fv(location, count, v);
5497}
5498
5499void Context::uniform1i(GLint location, GLint x)
5500{
5501 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005502 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5503 {
5504 mGLState.setObjectDirty(GL_PROGRAM);
5505 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005506}
5507
5508void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5509{
5510 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005511 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5512 {
5513 mGLState.setObjectDirty(GL_PROGRAM);
5514 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005515}
5516
5517void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5518{
5519 GLfloat xy[2] = {x, y};
5520 Program *program = mGLState.getProgram();
5521 program->setUniform2fv(location, 1, xy);
5522}
5523
5524void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5525{
5526 Program *program = mGLState.getProgram();
5527 program->setUniform2fv(location, count, v);
5528}
5529
5530void Context::uniform2i(GLint location, GLint x, GLint y)
5531{
5532 GLint xy[2] = {x, y};
5533 Program *program = mGLState.getProgram();
5534 program->setUniform2iv(location, 1, xy);
5535}
5536
5537void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5538{
5539 Program *program = mGLState.getProgram();
5540 program->setUniform2iv(location, count, v);
5541}
5542
5543void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5544{
5545 GLfloat xyz[3] = {x, y, z};
5546 Program *program = mGLState.getProgram();
5547 program->setUniform3fv(location, 1, xyz);
5548}
5549
5550void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5551{
5552 Program *program = mGLState.getProgram();
5553 program->setUniform3fv(location, count, v);
5554}
5555
5556void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5557{
5558 GLint xyz[3] = {x, y, z};
5559 Program *program = mGLState.getProgram();
5560 program->setUniform3iv(location, 1, xyz);
5561}
5562
5563void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5564{
5565 Program *program = mGLState.getProgram();
5566 program->setUniform3iv(location, count, v);
5567}
5568
5569void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5570{
5571 GLfloat xyzw[4] = {x, y, z, w};
5572 Program *program = mGLState.getProgram();
5573 program->setUniform4fv(location, 1, xyzw);
5574}
5575
5576void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5577{
5578 Program *program = mGLState.getProgram();
5579 program->setUniform4fv(location, count, v);
5580}
5581
5582void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5583{
5584 GLint xyzw[4] = {x, y, z, w};
5585 Program *program = mGLState.getProgram();
5586 program->setUniform4iv(location, 1, xyzw);
5587}
5588
5589void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5590{
5591 Program *program = mGLState.getProgram();
5592 program->setUniform4iv(location, count, v);
5593}
5594
5595void Context::uniformMatrix2fv(GLint location,
5596 GLsizei count,
5597 GLboolean transpose,
5598 const GLfloat *value)
5599{
5600 Program *program = mGLState.getProgram();
5601 program->setUniformMatrix2fv(location, count, transpose, value);
5602}
5603
5604void Context::uniformMatrix3fv(GLint location,
5605 GLsizei count,
5606 GLboolean transpose,
5607 const GLfloat *value)
5608{
5609 Program *program = mGLState.getProgram();
5610 program->setUniformMatrix3fv(location, count, transpose, value);
5611}
5612
5613void Context::uniformMatrix4fv(GLint location,
5614 GLsizei count,
5615 GLboolean transpose,
5616 const GLfloat *value)
5617{
5618 Program *program = mGLState.getProgram();
5619 program->setUniformMatrix4fv(location, count, transpose, value);
5620}
5621
5622void Context::validateProgram(GLuint program)
5623{
5624 Program *programObject = getProgram(program);
5625 ASSERT(programObject);
5626 programObject->validate(mCaps);
5627}
5628
Jiajia Qin5451d532017-11-16 17:16:34 +08005629void Context::validateProgramPipeline(GLuint pipeline)
5630{
5631 UNIMPLEMENTED();
5632}
5633
Jamie Madilld04908b2017-06-09 14:15:35 -04005634void Context::getProgramBinary(GLuint program,
5635 GLsizei bufSize,
5636 GLsizei *length,
5637 GLenum *binaryFormat,
5638 void *binary)
5639{
5640 Program *programObject = getProgram(program);
5641 ASSERT(programObject != nullptr);
5642
5643 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5644}
5645
5646void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5647{
5648 Program *programObject = getProgram(program);
5649 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005650
Jamie Madilld04908b2017-06-09 14:15:35 -04005651 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5652}
5653
Jamie Madillff325f12017-08-26 15:06:05 -04005654void Context::uniform1ui(GLint location, GLuint v0)
5655{
5656 Program *program = mGLState.getProgram();
5657 program->setUniform1uiv(location, 1, &v0);
5658}
5659
5660void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5661{
5662 Program *program = mGLState.getProgram();
5663 const GLuint xy[] = {v0, v1};
5664 program->setUniform2uiv(location, 1, xy);
5665}
5666
5667void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5668{
5669 Program *program = mGLState.getProgram();
5670 const GLuint xyz[] = {v0, v1, v2};
5671 program->setUniform3uiv(location, 1, xyz);
5672}
5673
5674void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5675{
5676 Program *program = mGLState.getProgram();
5677 const GLuint xyzw[] = {v0, v1, v2, v3};
5678 program->setUniform4uiv(location, 1, xyzw);
5679}
5680
5681void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5682{
5683 Program *program = mGLState.getProgram();
5684 program->setUniform1uiv(location, count, value);
5685}
5686void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5687{
5688 Program *program = mGLState.getProgram();
5689 program->setUniform2uiv(location, count, value);
5690}
5691
5692void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5693{
5694 Program *program = mGLState.getProgram();
5695 program->setUniform3uiv(location, count, value);
5696}
5697
5698void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5699{
5700 Program *program = mGLState.getProgram();
5701 program->setUniform4uiv(location, count, value);
5702}
5703
Jamie Madillf0e04492017-08-26 15:28:42 -04005704void Context::genQueries(GLsizei n, GLuint *ids)
5705{
5706 for (GLsizei i = 0; i < n; i++)
5707 {
5708 GLuint handle = mQueryHandleAllocator.allocate();
5709 mQueryMap.assign(handle, nullptr);
5710 ids[i] = handle;
5711 }
5712}
5713
5714void Context::deleteQueries(GLsizei n, const GLuint *ids)
5715{
5716 for (int i = 0; i < n; i++)
5717 {
5718 GLuint query = ids[i];
5719
5720 Query *queryObject = nullptr;
5721 if (mQueryMap.erase(query, &queryObject))
5722 {
5723 mQueryHandleAllocator.release(query);
5724 if (queryObject)
5725 {
5726 queryObject->release(this);
5727 }
5728 }
5729 }
5730}
5731
5732GLboolean Context::isQuery(GLuint id)
5733{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005734 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005735}
5736
Jamie Madillc8c95812017-08-26 18:40:09 -04005737void Context::uniformMatrix2x3fv(GLint location,
5738 GLsizei count,
5739 GLboolean transpose,
5740 const GLfloat *value)
5741{
5742 Program *program = mGLState.getProgram();
5743 program->setUniformMatrix2x3fv(location, count, transpose, value);
5744}
5745
5746void Context::uniformMatrix3x2fv(GLint location,
5747 GLsizei count,
5748 GLboolean transpose,
5749 const GLfloat *value)
5750{
5751 Program *program = mGLState.getProgram();
5752 program->setUniformMatrix3x2fv(location, count, transpose, value);
5753}
5754
5755void Context::uniformMatrix2x4fv(GLint location,
5756 GLsizei count,
5757 GLboolean transpose,
5758 const GLfloat *value)
5759{
5760 Program *program = mGLState.getProgram();
5761 program->setUniformMatrix2x4fv(location, count, transpose, value);
5762}
5763
5764void Context::uniformMatrix4x2fv(GLint location,
5765 GLsizei count,
5766 GLboolean transpose,
5767 const GLfloat *value)
5768{
5769 Program *program = mGLState.getProgram();
5770 program->setUniformMatrix4x2fv(location, count, transpose, value);
5771}
5772
5773void Context::uniformMatrix3x4fv(GLint location,
5774 GLsizei count,
5775 GLboolean transpose,
5776 const GLfloat *value)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniformMatrix3x4fv(location, count, transpose, value);
5780}
5781
5782void Context::uniformMatrix4x3fv(GLint location,
5783 GLsizei count,
5784 GLboolean transpose,
5785 const GLfloat *value)
5786{
5787 Program *program = mGLState.getProgram();
5788 program->setUniformMatrix4x3fv(location, count, transpose, value);
5789}
5790
Jamie Madilld7576732017-08-26 18:49:50 -04005791void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5792{
5793 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5794 {
5795 GLuint vertexArray = arrays[arrayIndex];
5796
5797 if (arrays[arrayIndex] != 0)
5798 {
5799 VertexArray *vertexArrayObject = nullptr;
5800 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5801 {
5802 if (vertexArrayObject != nullptr)
5803 {
5804 detachVertexArray(vertexArray);
5805 vertexArrayObject->onDestroy(this);
5806 }
5807
5808 mVertexArrayHandleAllocator.release(vertexArray);
5809 }
5810 }
5811 }
5812}
5813
5814void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5815{
5816 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5817 {
5818 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5819 mVertexArrayMap.assign(vertexArray, nullptr);
5820 arrays[arrayIndex] = vertexArray;
5821 }
5822}
5823
5824bool Context::isVertexArray(GLuint array)
5825{
5826 if (array == 0)
5827 {
5828 return GL_FALSE;
5829 }
5830
5831 VertexArray *vao = getVertexArray(array);
5832 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5833}
5834
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005835void Context::endTransformFeedback()
5836{
5837 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5838 transformFeedback->end(this);
5839}
5840
5841void Context::transformFeedbackVaryings(GLuint program,
5842 GLsizei count,
5843 const GLchar *const *varyings,
5844 GLenum bufferMode)
5845{
5846 Program *programObject = getProgram(program);
5847 ASSERT(programObject);
5848 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5849}
5850
5851void Context::getTransformFeedbackVarying(GLuint program,
5852 GLuint index,
5853 GLsizei bufSize,
5854 GLsizei *length,
5855 GLsizei *size,
5856 GLenum *type,
5857 GLchar *name)
5858{
5859 Program *programObject = getProgram(program);
5860 ASSERT(programObject);
5861 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5862}
5863
5864void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5865{
5866 for (int i = 0; i < n; i++)
5867 {
5868 GLuint transformFeedback = ids[i];
5869 if (transformFeedback == 0)
5870 {
5871 continue;
5872 }
5873
5874 TransformFeedback *transformFeedbackObject = nullptr;
5875 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5876 {
5877 if (transformFeedbackObject != nullptr)
5878 {
5879 detachTransformFeedback(transformFeedback);
5880 transformFeedbackObject->release(this);
5881 }
5882
5883 mTransformFeedbackHandleAllocator.release(transformFeedback);
5884 }
5885 }
5886}
5887
5888void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5889{
5890 for (int i = 0; i < n; i++)
5891 {
5892 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5893 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5894 ids[i] = transformFeedback;
5895 }
5896}
5897
5898bool Context::isTransformFeedback(GLuint id)
5899{
5900 if (id == 0)
5901 {
5902 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5903 // returns FALSE
5904 return GL_FALSE;
5905 }
5906
5907 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5908 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5909}
5910
5911void Context::pauseTransformFeedback()
5912{
5913 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5914 transformFeedback->pause();
5915}
5916
5917void Context::resumeTransformFeedback()
5918{
5919 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5920 transformFeedback->resume();
5921}
5922
Jamie Madill12e957f2017-08-26 21:42:26 -04005923void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5924{
5925 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005926 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005927}
5928
Brandon Jones59770802018-04-02 13:18:42 -07005929void Context::getUniformuivRobust(GLuint program,
5930 GLint location,
5931 GLsizei bufSize,
5932 GLsizei *length,
5933 GLuint *params)
5934{
5935 getUniformuiv(program, location, params);
5936}
5937
Jamie Madill12e957f2017-08-26 21:42:26 -04005938GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5939{
5940 const Program *programObject = getProgram(program);
5941 return programObject->getFragDataLocation(name);
5942}
5943
5944void Context::getUniformIndices(GLuint program,
5945 GLsizei uniformCount,
5946 const GLchar *const *uniformNames,
5947 GLuint *uniformIndices)
5948{
5949 const Program *programObject = getProgram(program);
5950 if (!programObject->isLinked())
5951 {
5952 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5953 {
5954 uniformIndices[uniformId] = GL_INVALID_INDEX;
5955 }
5956 }
5957 else
5958 {
5959 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5960 {
5961 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5962 }
5963 }
5964}
5965
5966void Context::getActiveUniformsiv(GLuint program,
5967 GLsizei uniformCount,
5968 const GLuint *uniformIndices,
5969 GLenum pname,
5970 GLint *params)
5971{
5972 const Program *programObject = getProgram(program);
5973 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5974 {
5975 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005976 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005977 }
5978}
5979
5980GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5981{
5982 const Program *programObject = getProgram(program);
5983 return programObject->getUniformBlockIndex(uniformBlockName);
5984}
5985
5986void Context::getActiveUniformBlockiv(GLuint program,
5987 GLuint uniformBlockIndex,
5988 GLenum pname,
5989 GLint *params)
5990{
5991 const Program *programObject = getProgram(program);
5992 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5993}
5994
Brandon Jones59770802018-04-02 13:18:42 -07005995void Context::getActiveUniformBlockivRobust(GLuint program,
5996 GLuint uniformBlockIndex,
5997 GLenum pname,
5998 GLsizei bufSize,
5999 GLsizei *length,
6000 GLint *params)
6001{
6002 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6003}
6004
Jamie Madill12e957f2017-08-26 21:42:26 -04006005void Context::getActiveUniformBlockName(GLuint program,
6006 GLuint uniformBlockIndex,
6007 GLsizei bufSize,
6008 GLsizei *length,
6009 GLchar *uniformBlockName)
6010{
6011 const Program *programObject = getProgram(program);
6012 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6013}
6014
6015void Context::uniformBlockBinding(GLuint program,
6016 GLuint uniformBlockIndex,
6017 GLuint uniformBlockBinding)
6018{
6019 Program *programObject = getProgram(program);
6020 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6021}
6022
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006023GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6024{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006025 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6026 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006027
Jamie Madill70b5bb02017-08-28 13:32:37 -04006028 Sync *syncObject = getSync(syncHandle);
6029 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006030 if (error.isError())
6031 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006032 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006033 handleError(error);
6034 return nullptr;
6035 }
6036
Jamie Madill70b5bb02017-08-28 13:32:37 -04006037 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006038}
6039
6040GLboolean Context::isSync(GLsync sync)
6041{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006042 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006043}
6044
6045GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6046{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006047 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006048
6049 GLenum result = GL_WAIT_FAILED;
6050 handleError(syncObject->clientWait(flags, timeout, &result));
6051 return result;
6052}
6053
6054void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6055{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006056 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006057 handleError(syncObject->serverWait(flags, timeout));
6058}
6059
6060void Context::getInteger64v(GLenum pname, GLint64 *params)
6061{
6062 GLenum nativeType = GL_NONE;
6063 unsigned int numParams = 0;
6064 getQueryParameterInfo(pname, &nativeType, &numParams);
6065
6066 if (nativeType == GL_INT_64_ANGLEX)
6067 {
6068 getInteger64vImpl(pname, params);
6069 }
6070 else
6071 {
6072 CastStateValues(this, nativeType, pname, numParams, params);
6073 }
6074}
6075
Brandon Jones59770802018-04-02 13:18:42 -07006076void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6077{
6078 getInteger64v(pname, data);
6079}
6080
Corentin Wallez336129f2017-10-17 15:55:40 -04006081void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006082{
6083 Buffer *buffer = mGLState.getTargetBuffer(target);
6084 QueryBufferParameteri64v(buffer, pname, params);
6085}
6086
Brandon Jones59770802018-04-02 13:18:42 -07006087void Context::getBufferParameteri64vRobust(BufferBinding target,
6088 GLenum pname,
6089 GLsizei bufSize,
6090 GLsizei *length,
6091 GLint64 *params)
6092{
6093 getBufferParameteri64v(target, pname, params);
6094}
6095
Jamie Madill3ef140a2017-08-26 23:11:21 -04006096void Context::genSamplers(GLsizei count, GLuint *samplers)
6097{
6098 for (int i = 0; i < count; i++)
6099 {
6100 samplers[i] = mState.mSamplers->createSampler();
6101 }
6102}
6103
6104void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6105{
6106 for (int i = 0; i < count; i++)
6107 {
6108 GLuint sampler = samplers[i];
6109
6110 if (mState.mSamplers->getSampler(sampler))
6111 {
6112 detachSampler(sampler);
6113 }
6114
6115 mState.mSamplers->deleteObject(this, sampler);
6116 }
6117}
6118
6119void Context::getInternalformativ(GLenum target,
6120 GLenum internalformat,
6121 GLenum pname,
6122 GLsizei bufSize,
6123 GLint *params)
6124{
6125 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6126 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6127}
6128
Brandon Jones59770802018-04-02 13:18:42 -07006129void Context::getInternalformativRobust(GLenum target,
6130 GLenum internalformat,
6131 GLenum pname,
6132 GLsizei bufSize,
6133 GLsizei *length,
6134 GLint *params)
6135{
6136 getInternalformativ(target, internalformat, pname, bufSize, params);
6137}
6138
Jiajia Qin5451d532017-11-16 17:16:34 +08006139void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6140{
6141 programUniform1iv(program, location, 1, &v0);
6142}
6143
6144void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6145{
6146 GLint xy[2] = {v0, v1};
6147 programUniform2iv(program, location, 1, xy);
6148}
6149
6150void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6151{
6152 GLint xyz[3] = {v0, v1, v2};
6153 programUniform3iv(program, location, 1, xyz);
6154}
6155
6156void Context::programUniform4i(GLuint program,
6157 GLint location,
6158 GLint v0,
6159 GLint v1,
6160 GLint v2,
6161 GLint v3)
6162{
6163 GLint xyzw[4] = {v0, v1, v2, v3};
6164 programUniform4iv(program, location, 1, xyzw);
6165}
6166
6167void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6168{
6169 programUniform1uiv(program, location, 1, &v0);
6170}
6171
6172void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6173{
6174 GLuint xy[2] = {v0, v1};
6175 programUniform2uiv(program, location, 1, xy);
6176}
6177
6178void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6179{
6180 GLuint xyz[3] = {v0, v1, v2};
6181 programUniform3uiv(program, location, 1, xyz);
6182}
6183
6184void Context::programUniform4ui(GLuint program,
6185 GLint location,
6186 GLuint v0,
6187 GLuint v1,
6188 GLuint v2,
6189 GLuint v3)
6190{
6191 GLuint xyzw[4] = {v0, v1, v2, v3};
6192 programUniform4uiv(program, location, 1, xyzw);
6193}
6194
6195void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6196{
6197 programUniform1fv(program, location, 1, &v0);
6198}
6199
6200void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6201{
6202 GLfloat xy[2] = {v0, v1};
6203 programUniform2fv(program, location, 1, xy);
6204}
6205
6206void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6207{
6208 GLfloat xyz[3] = {v0, v1, v2};
6209 programUniform3fv(program, location, 1, xyz);
6210}
6211
6212void Context::programUniform4f(GLuint program,
6213 GLint location,
6214 GLfloat v0,
6215 GLfloat v1,
6216 GLfloat v2,
6217 GLfloat v3)
6218{
6219 GLfloat xyzw[4] = {v0, v1, v2, v3};
6220 programUniform4fv(program, location, 1, xyzw);
6221}
6222
Jamie Madill81c2e252017-09-09 23:32:46 -04006223void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6224{
6225 Program *programObject = getProgram(program);
6226 ASSERT(programObject);
6227 if (programObject->setUniform1iv(location, count, value) ==
6228 Program::SetUniformResult::SamplerChanged)
6229 {
6230 mGLState.setObjectDirty(GL_PROGRAM);
6231 }
6232}
6233
Jiajia Qin5451d532017-11-16 17:16:34 +08006234void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6235{
6236 Program *programObject = getProgram(program);
6237 ASSERT(programObject);
6238 programObject->setUniform2iv(location, count, value);
6239}
6240
6241void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6242{
6243 Program *programObject = getProgram(program);
6244 ASSERT(programObject);
6245 programObject->setUniform3iv(location, count, value);
6246}
6247
6248void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6249{
6250 Program *programObject = getProgram(program);
6251 ASSERT(programObject);
6252 programObject->setUniform4iv(location, count, value);
6253}
6254
6255void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6256{
6257 Program *programObject = getProgram(program);
6258 ASSERT(programObject);
6259 programObject->setUniform1uiv(location, count, value);
6260}
6261
6262void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6263{
6264 Program *programObject = getProgram(program);
6265 ASSERT(programObject);
6266 programObject->setUniform2uiv(location, count, value);
6267}
6268
6269void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6270{
6271 Program *programObject = getProgram(program);
6272 ASSERT(programObject);
6273 programObject->setUniform3uiv(location, count, value);
6274}
6275
6276void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6277{
6278 Program *programObject = getProgram(program);
6279 ASSERT(programObject);
6280 programObject->setUniform4uiv(location, count, value);
6281}
6282
6283void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6284{
6285 Program *programObject = getProgram(program);
6286 ASSERT(programObject);
6287 programObject->setUniform1fv(location, count, value);
6288}
6289
6290void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6291{
6292 Program *programObject = getProgram(program);
6293 ASSERT(programObject);
6294 programObject->setUniform2fv(location, count, value);
6295}
6296
6297void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6298{
6299 Program *programObject = getProgram(program);
6300 ASSERT(programObject);
6301 programObject->setUniform3fv(location, count, value);
6302}
6303
6304void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6305{
6306 Program *programObject = getProgram(program);
6307 ASSERT(programObject);
6308 programObject->setUniform4fv(location, count, value);
6309}
6310
6311void Context::programUniformMatrix2fv(GLuint program,
6312 GLint location,
6313 GLsizei count,
6314 GLboolean transpose,
6315 const GLfloat *value)
6316{
6317 Program *programObject = getProgram(program);
6318 ASSERT(programObject);
6319 programObject->setUniformMatrix2fv(location, count, transpose, value);
6320}
6321
6322void Context::programUniformMatrix3fv(GLuint program,
6323 GLint location,
6324 GLsizei count,
6325 GLboolean transpose,
6326 const GLfloat *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 programObject->setUniformMatrix3fv(location, count, transpose, value);
6331}
6332
6333void Context::programUniformMatrix4fv(GLuint program,
6334 GLint location,
6335 GLsizei count,
6336 GLboolean transpose,
6337 const GLfloat *value)
6338{
6339 Program *programObject = getProgram(program);
6340 ASSERT(programObject);
6341 programObject->setUniformMatrix4fv(location, count, transpose, value);
6342}
6343
6344void Context::programUniformMatrix2x3fv(GLuint program,
6345 GLint location,
6346 GLsizei count,
6347 GLboolean transpose,
6348 const GLfloat *value)
6349{
6350 Program *programObject = getProgram(program);
6351 ASSERT(programObject);
6352 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6353}
6354
6355void Context::programUniformMatrix3x2fv(GLuint program,
6356 GLint location,
6357 GLsizei count,
6358 GLboolean transpose,
6359 const GLfloat *value)
6360{
6361 Program *programObject = getProgram(program);
6362 ASSERT(programObject);
6363 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6364}
6365
6366void Context::programUniformMatrix2x4fv(GLuint program,
6367 GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *programObject = getProgram(program);
6373 ASSERT(programObject);
6374 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6375}
6376
6377void Context::programUniformMatrix4x2fv(GLuint program,
6378 GLint location,
6379 GLsizei count,
6380 GLboolean transpose,
6381 const GLfloat *value)
6382{
6383 Program *programObject = getProgram(program);
6384 ASSERT(programObject);
6385 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6386}
6387
6388void Context::programUniformMatrix3x4fv(GLuint program,
6389 GLint location,
6390 GLsizei count,
6391 GLboolean transpose,
6392 const GLfloat *value)
6393{
6394 Program *programObject = getProgram(program);
6395 ASSERT(programObject);
6396 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6397}
6398
6399void Context::programUniformMatrix4x3fv(GLuint program,
6400 GLint location,
6401 GLsizei count,
6402 GLboolean transpose,
6403 const GLfloat *value)
6404{
6405 Program *programObject = getProgram(program);
6406 ASSERT(programObject);
6407 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6408}
6409
Jamie Madill81c2e252017-09-09 23:32:46 -04006410void Context::onTextureChange(const Texture *texture)
6411{
6412 // Conservatively assume all textures are dirty.
6413 // TODO(jmadill): More fine-grained update.
6414 mGLState.setObjectDirty(GL_TEXTURE);
6415}
6416
James Darpiniane8a93c62018-01-04 18:02:24 -08006417bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6418{
6419 return mGLState.isCurrentTransformFeedback(tf);
6420}
6421bool Context::isCurrentVertexArray(const VertexArray *va) const
6422{
6423 return mGLState.isCurrentVertexArray(va);
6424}
6425
Yunchao Hea336b902017-08-02 16:05:21 +08006426void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6427{
6428 for (int i = 0; i < count; i++)
6429 {
6430 pipelines[i] = createProgramPipeline();
6431 }
6432}
6433
6434void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6435{
6436 for (int i = 0; i < count; i++)
6437 {
6438 if (pipelines[i] != 0)
6439 {
6440 deleteProgramPipeline(pipelines[i]);
6441 }
6442 }
6443}
6444
6445GLboolean Context::isProgramPipeline(GLuint pipeline)
6446{
6447 if (pipeline == 0)
6448 {
6449 return GL_FALSE;
6450 }
6451
6452 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6453}
6454
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006455void Context::finishFenceNV(GLuint fence)
6456{
6457 FenceNV *fenceObject = getFenceNV(fence);
6458
6459 ASSERT(fenceObject && fenceObject->isSet());
6460 handleError(fenceObject->finish());
6461}
6462
6463void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6464{
6465 FenceNV *fenceObject = getFenceNV(fence);
6466
6467 ASSERT(fenceObject && fenceObject->isSet());
6468
6469 switch (pname)
6470 {
6471 case GL_FENCE_STATUS_NV:
6472 {
6473 // GL_NV_fence spec:
6474 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6475 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6476 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6477 GLboolean status = GL_TRUE;
6478 if (fenceObject->getStatus() != GL_TRUE)
6479 {
6480 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6481 }
6482 *params = status;
6483 break;
6484 }
6485
6486 case GL_FENCE_CONDITION_NV:
6487 {
6488 *params = static_cast<GLint>(fenceObject->getCondition());
6489 break;
6490 }
6491
6492 default:
6493 UNREACHABLE();
6494 }
6495}
6496
6497void Context::getTranslatedShaderSource(GLuint shader,
6498 GLsizei bufsize,
6499 GLsizei *length,
6500 GLchar *source)
6501{
6502 Shader *shaderObject = getShader(shader);
6503 ASSERT(shaderObject);
6504 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6505}
6506
6507void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6508{
6509 Program *programObject = getProgram(program);
6510 ASSERT(programObject);
6511
6512 programObject->getUniformfv(this, location, params);
6513}
6514
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006515void Context::getnUniformfvRobust(GLuint program,
6516 GLint location,
6517 GLsizei bufSize,
6518 GLsizei *length,
6519 GLfloat *params)
6520{
6521 UNIMPLEMENTED();
6522}
6523
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006524void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6525{
6526 Program *programObject = getProgram(program);
6527 ASSERT(programObject);
6528
6529 programObject->getUniformiv(this, location, params);
6530}
6531
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006532void Context::getnUniformivRobust(GLuint program,
6533 GLint location,
6534 GLsizei bufSize,
6535 GLsizei *length,
6536 GLint *params)
6537{
6538 UNIMPLEMENTED();
6539}
6540
6541void Context::getnUniformuivRobust(GLuint program,
6542 GLint location,
6543 GLsizei bufSize,
6544 GLsizei *length,
6545 GLuint *params)
6546{
6547 UNIMPLEMENTED();
6548}
6549
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006550GLboolean Context::isFenceNV(GLuint fence)
6551{
6552 FenceNV *fenceObject = getFenceNV(fence);
6553
6554 if (fenceObject == nullptr)
6555 {
6556 return GL_FALSE;
6557 }
6558
6559 // GL_NV_fence spec:
6560 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6561 // existing fence.
6562 return fenceObject->isSet();
6563}
6564
6565void Context::readnPixels(GLint x,
6566 GLint y,
6567 GLsizei width,
6568 GLsizei height,
6569 GLenum format,
6570 GLenum type,
6571 GLsizei bufSize,
6572 void *data)
6573{
6574 return readPixels(x, y, width, height, format, type, data);
6575}
6576
Jamie Madill007530e2017-12-28 14:27:04 -05006577void Context::setFenceNV(GLuint fence, GLenum condition)
6578{
6579 ASSERT(condition == GL_ALL_COMPLETED_NV);
6580
6581 FenceNV *fenceObject = getFenceNV(fence);
6582 ASSERT(fenceObject != nullptr);
6583 handleError(fenceObject->set(condition));
6584}
6585
6586GLboolean Context::testFenceNV(GLuint fence)
6587{
6588 FenceNV *fenceObject = getFenceNV(fence);
6589
6590 ASSERT(fenceObject != nullptr);
6591 ASSERT(fenceObject->isSet() == GL_TRUE);
6592
6593 GLboolean result = GL_TRUE;
6594 Error error = fenceObject->test(&result);
6595 if (error.isError())
6596 {
6597 handleError(error);
6598 return GL_TRUE;
6599 }
6600
6601 return result;
6602}
6603
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006604void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006605{
6606 Texture *texture = getTargetTexture(target);
6607 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006608 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006609}
6610
Jamie Madillfa920eb2018-01-04 11:45:50 -05006611void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006612{
6613 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6614 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6615 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6616}
6617
Jamie Madillfa920eb2018-01-04 11:45:50 -05006618void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6619{
6620 UNIMPLEMENTED();
6621}
6622
Jamie Madill5b772312018-03-08 20:28:32 -05006623bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6624{
6625 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6626 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6627 // to the fact that it is stored internally as a float, and so would require conversion
6628 // if returned from Context::getIntegerv. Since this conversion is already implemented
6629 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6630 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6631 // application.
6632 switch (pname)
6633 {
6634 case GL_COMPRESSED_TEXTURE_FORMATS:
6635 {
6636 *type = GL_INT;
6637 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6638 return true;
6639 }
6640 case GL_SHADER_BINARY_FORMATS:
6641 {
6642 *type = GL_INT;
6643 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6644 return true;
6645 }
6646
6647 case GL_MAX_VERTEX_ATTRIBS:
6648 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6649 case GL_MAX_VARYING_VECTORS:
6650 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6651 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6652 case GL_MAX_TEXTURE_IMAGE_UNITS:
6653 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6654 case GL_MAX_RENDERBUFFER_SIZE:
6655 case GL_NUM_SHADER_BINARY_FORMATS:
6656 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6657 case GL_ARRAY_BUFFER_BINDING:
6658 case GL_FRAMEBUFFER_BINDING:
6659 case GL_RENDERBUFFER_BINDING:
6660 case GL_CURRENT_PROGRAM:
6661 case GL_PACK_ALIGNMENT:
6662 case GL_UNPACK_ALIGNMENT:
6663 case GL_GENERATE_MIPMAP_HINT:
6664 case GL_RED_BITS:
6665 case GL_GREEN_BITS:
6666 case GL_BLUE_BITS:
6667 case GL_ALPHA_BITS:
6668 case GL_DEPTH_BITS:
6669 case GL_STENCIL_BITS:
6670 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6671 case GL_CULL_FACE_MODE:
6672 case GL_FRONT_FACE:
6673 case GL_ACTIVE_TEXTURE:
6674 case GL_STENCIL_FUNC:
6675 case GL_STENCIL_VALUE_MASK:
6676 case GL_STENCIL_REF:
6677 case GL_STENCIL_FAIL:
6678 case GL_STENCIL_PASS_DEPTH_FAIL:
6679 case GL_STENCIL_PASS_DEPTH_PASS:
6680 case GL_STENCIL_BACK_FUNC:
6681 case GL_STENCIL_BACK_VALUE_MASK:
6682 case GL_STENCIL_BACK_REF:
6683 case GL_STENCIL_BACK_FAIL:
6684 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6685 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6686 case GL_DEPTH_FUNC:
6687 case GL_BLEND_SRC_RGB:
6688 case GL_BLEND_SRC_ALPHA:
6689 case GL_BLEND_DST_RGB:
6690 case GL_BLEND_DST_ALPHA:
6691 case GL_BLEND_EQUATION_RGB:
6692 case GL_BLEND_EQUATION_ALPHA:
6693 case GL_STENCIL_WRITEMASK:
6694 case GL_STENCIL_BACK_WRITEMASK:
6695 case GL_STENCIL_CLEAR_VALUE:
6696 case GL_SUBPIXEL_BITS:
6697 case GL_MAX_TEXTURE_SIZE:
6698 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6699 case GL_SAMPLE_BUFFERS:
6700 case GL_SAMPLES:
6701 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6702 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6703 case GL_TEXTURE_BINDING_2D:
6704 case GL_TEXTURE_BINDING_CUBE_MAP:
6705 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6706 {
6707 *type = GL_INT;
6708 *numParams = 1;
6709 return true;
6710 }
6711 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6712 {
6713 if (!getExtensions().packReverseRowOrder)
6714 {
6715 return false;
6716 }
6717 *type = GL_INT;
6718 *numParams = 1;
6719 return true;
6720 }
6721 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6722 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6723 {
6724 if (!getExtensions().textureRectangle)
6725 {
6726 return false;
6727 }
6728 *type = GL_INT;
6729 *numParams = 1;
6730 return true;
6731 }
6732 case GL_MAX_DRAW_BUFFERS_EXT:
6733 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6734 {
6735 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6736 {
6737 return false;
6738 }
6739 *type = GL_INT;
6740 *numParams = 1;
6741 return true;
6742 }
6743 case GL_MAX_VIEWPORT_DIMS:
6744 {
6745 *type = GL_INT;
6746 *numParams = 2;
6747 return true;
6748 }
6749 case GL_VIEWPORT:
6750 case GL_SCISSOR_BOX:
6751 {
6752 *type = GL_INT;
6753 *numParams = 4;
6754 return true;
6755 }
6756 case GL_SHADER_COMPILER:
6757 case GL_SAMPLE_COVERAGE_INVERT:
6758 case GL_DEPTH_WRITEMASK:
6759 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6760 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6761 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6762 // bool-natural
6763 case GL_SAMPLE_COVERAGE:
6764 case GL_SCISSOR_TEST:
6765 case GL_STENCIL_TEST:
6766 case GL_DEPTH_TEST:
6767 case GL_BLEND:
6768 case GL_DITHER:
6769 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6770 {
6771 *type = GL_BOOL;
6772 *numParams = 1;
6773 return true;
6774 }
6775 case GL_COLOR_WRITEMASK:
6776 {
6777 *type = GL_BOOL;
6778 *numParams = 4;
6779 return true;
6780 }
6781 case GL_POLYGON_OFFSET_FACTOR:
6782 case GL_POLYGON_OFFSET_UNITS:
6783 case GL_SAMPLE_COVERAGE_VALUE:
6784 case GL_DEPTH_CLEAR_VALUE:
6785 case GL_LINE_WIDTH:
6786 {
6787 *type = GL_FLOAT;
6788 *numParams = 1;
6789 return true;
6790 }
6791 case GL_ALIASED_LINE_WIDTH_RANGE:
6792 case GL_ALIASED_POINT_SIZE_RANGE:
6793 case GL_DEPTH_RANGE:
6794 {
6795 *type = GL_FLOAT;
6796 *numParams = 2;
6797 return true;
6798 }
6799 case GL_COLOR_CLEAR_VALUE:
6800 case GL_BLEND_COLOR:
6801 {
6802 *type = GL_FLOAT;
6803 *numParams = 4;
6804 return true;
6805 }
6806 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6807 if (!getExtensions().textureFilterAnisotropic)
6808 {
6809 return false;
6810 }
6811 *type = GL_FLOAT;
6812 *numParams = 1;
6813 return true;
6814 case GL_TIMESTAMP_EXT:
6815 if (!getExtensions().disjointTimerQuery)
6816 {
6817 return false;
6818 }
6819 *type = GL_INT_64_ANGLEX;
6820 *numParams = 1;
6821 return true;
6822 case GL_GPU_DISJOINT_EXT:
6823 if (!getExtensions().disjointTimerQuery)
6824 {
6825 return false;
6826 }
6827 *type = GL_INT;
6828 *numParams = 1;
6829 return true;
6830 case GL_COVERAGE_MODULATION_CHROMIUM:
6831 if (!getExtensions().framebufferMixedSamples)
6832 {
6833 return false;
6834 }
6835 *type = GL_INT;
6836 *numParams = 1;
6837 return true;
6838 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6839 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6840 {
6841 return false;
6842 }
6843 *type = GL_INT;
6844 *numParams = 1;
6845 return true;
6846 }
6847
6848 if (getExtensions().debug)
6849 {
6850 switch (pname)
6851 {
6852 case GL_DEBUG_LOGGED_MESSAGES:
6853 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6854 case GL_DEBUG_GROUP_STACK_DEPTH:
6855 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6856 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6857 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6858 case GL_MAX_LABEL_LENGTH:
6859 *type = GL_INT;
6860 *numParams = 1;
6861 return true;
6862
6863 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6864 case GL_DEBUG_OUTPUT:
6865 *type = GL_BOOL;
6866 *numParams = 1;
6867 return true;
6868 }
6869 }
6870
6871 if (getExtensions().multisampleCompatibility)
6872 {
6873 switch (pname)
6874 {
6875 case GL_MULTISAMPLE_EXT:
6876 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6877 *type = GL_BOOL;
6878 *numParams = 1;
6879 return true;
6880 }
6881 }
6882
6883 if (getExtensions().pathRendering)
6884 {
6885 switch (pname)
6886 {
6887 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6888 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6889 *type = GL_FLOAT;
6890 *numParams = 16;
6891 return true;
6892 }
6893 }
6894
6895 if (getExtensions().bindGeneratesResource)
6896 {
6897 switch (pname)
6898 {
6899 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6900 *type = GL_BOOL;
6901 *numParams = 1;
6902 return true;
6903 }
6904 }
6905
6906 if (getExtensions().clientArrays)
6907 {
6908 switch (pname)
6909 {
6910 case GL_CLIENT_ARRAYS_ANGLE:
6911 *type = GL_BOOL;
6912 *numParams = 1;
6913 return true;
6914 }
6915 }
6916
6917 if (getExtensions().sRGBWriteControl)
6918 {
6919 switch (pname)
6920 {
6921 case GL_FRAMEBUFFER_SRGB_EXT:
6922 *type = GL_BOOL;
6923 *numParams = 1;
6924 return true;
6925 }
6926 }
6927
6928 if (getExtensions().robustResourceInitialization &&
6929 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6930 {
6931 *type = GL_BOOL;
6932 *numParams = 1;
6933 return true;
6934 }
6935
6936 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6937 {
6938 *type = GL_BOOL;
6939 *numParams = 1;
6940 return true;
6941 }
6942
6943 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6944 switch (pname)
6945 {
6946 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6947 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6948 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6949 {
6950 return false;
6951 }
6952 *type = GL_INT;
6953 *numParams = 1;
6954 return true;
6955
6956 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6957 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6958 {
6959 return false;
6960 }
6961 *type = GL_INT;
6962 *numParams = 1;
6963 return true;
6964
6965 case GL_PROGRAM_BINARY_FORMATS_OES:
6966 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6967 {
6968 return false;
6969 }
6970 *type = GL_INT;
6971 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6972 return true;
6973
6974 case GL_PACK_ROW_LENGTH:
6975 case GL_PACK_SKIP_ROWS:
6976 case GL_PACK_SKIP_PIXELS:
6977 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6978 {
6979 return false;
6980 }
6981 *type = GL_INT;
6982 *numParams = 1;
6983 return true;
6984 case GL_UNPACK_ROW_LENGTH:
6985 case GL_UNPACK_SKIP_ROWS:
6986 case GL_UNPACK_SKIP_PIXELS:
6987 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6988 {
6989 return false;
6990 }
6991 *type = GL_INT;
6992 *numParams = 1;
6993 return true;
6994 case GL_VERTEX_ARRAY_BINDING:
6995 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6996 {
6997 return false;
6998 }
6999 *type = GL_INT;
7000 *numParams = 1;
7001 return true;
7002 case GL_PIXEL_PACK_BUFFER_BINDING:
7003 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7004 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7005 {
7006 return false;
7007 }
7008 *type = GL_INT;
7009 *numParams = 1;
7010 return true;
7011 case GL_MAX_SAMPLES:
7012 {
7013 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7014 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7015 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7016 {
7017 return false;
7018 }
7019 *type = GL_INT;
7020 *numParams = 1;
7021 return true;
7022
7023 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7024 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7025 {
7026 return false;
7027 }
7028 *type = GL_INT;
7029 *numParams = 1;
7030 return true;
7031 }
7032 }
7033
7034 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7035 {
7036 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7037 {
7038 return false;
7039 }
7040 *type = GL_INT;
7041 *numParams = 1;
7042 return true;
7043 }
7044
7045 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7046 {
7047 *type = GL_INT;
7048 *numParams = 1;
7049 return true;
7050 }
7051
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007052 if (getClientVersion() < Version(2, 0))
7053 {
7054 switch (pname)
7055 {
7056 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007057 case GL_CLIENT_ACTIVE_TEXTURE:
7058 case GL_MATRIX_MODE:
7059 case GL_MAX_TEXTURE_UNITS:
7060 case GL_MAX_MODELVIEW_STACK_DEPTH:
7061 case GL_MAX_PROJECTION_STACK_DEPTH:
7062 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007063 case GL_MAX_LIGHTS:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007064 case GL_VERTEX_ARRAY_STRIDE:
7065 case GL_NORMAL_ARRAY_STRIDE:
7066 case GL_COLOR_ARRAY_STRIDE:
7067 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7068 case GL_VERTEX_ARRAY_SIZE:
7069 case GL_COLOR_ARRAY_SIZE:
7070 case GL_TEXTURE_COORD_ARRAY_SIZE:
7071 case GL_VERTEX_ARRAY_TYPE:
7072 case GL_NORMAL_ARRAY_TYPE:
7073 case GL_COLOR_ARRAY_TYPE:
7074 case GL_TEXTURE_COORD_ARRAY_TYPE:
7075 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7076 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7077 case GL_COLOR_ARRAY_BUFFER_BINDING:
7078 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7079 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7080 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7081 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007082 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007083 *type = GL_INT;
7084 *numParams = 1;
7085 return true;
7086 case GL_ALPHA_TEST_REF:
7087 *type = GL_FLOAT;
7088 *numParams = 1;
7089 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007090 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007091 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007092 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007093 *type = GL_FLOAT;
7094 *numParams = 4;
7095 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007096 case GL_CURRENT_NORMAL:
7097 *type = GL_FLOAT;
7098 *numParams = 3;
7099 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007100 case GL_MODELVIEW_MATRIX:
7101 case GL_PROJECTION_MATRIX:
7102 case GL_TEXTURE_MATRIX:
7103 *type = GL_FLOAT;
7104 *numParams = 16;
7105 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007106 case GL_LIGHT_MODEL_TWO_SIDE:
7107 *type = GL_BOOL;
7108 *numParams = 1;
7109 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007110 }
7111 }
7112
Jamie Madill5b772312018-03-08 20:28:32 -05007113 if (getClientVersion() < Version(3, 0))
7114 {
7115 return false;
7116 }
7117
7118 // Check for ES3.0+ parameter names
7119 switch (pname)
7120 {
7121 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7122 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7123 case GL_UNIFORM_BUFFER_BINDING:
7124 case GL_TRANSFORM_FEEDBACK_BINDING:
7125 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7126 case GL_COPY_READ_BUFFER_BINDING:
7127 case GL_COPY_WRITE_BUFFER_BINDING:
7128 case GL_SAMPLER_BINDING:
7129 case GL_READ_BUFFER:
7130 case GL_TEXTURE_BINDING_3D:
7131 case GL_TEXTURE_BINDING_2D_ARRAY:
7132 case GL_MAX_3D_TEXTURE_SIZE:
7133 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7134 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7135 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7136 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7137 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7138 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7139 case GL_MAX_VARYING_COMPONENTS:
7140 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7141 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7142 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7143 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7144 case GL_NUM_EXTENSIONS:
7145 case GL_MAJOR_VERSION:
7146 case GL_MINOR_VERSION:
7147 case GL_MAX_ELEMENTS_INDICES:
7148 case GL_MAX_ELEMENTS_VERTICES:
7149 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7150 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7151 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7152 case GL_UNPACK_IMAGE_HEIGHT:
7153 case GL_UNPACK_SKIP_IMAGES:
7154 {
7155 *type = GL_INT;
7156 *numParams = 1;
7157 return true;
7158 }
7159
7160 case GL_MAX_ELEMENT_INDEX:
7161 case GL_MAX_UNIFORM_BLOCK_SIZE:
7162 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7163 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7164 case GL_MAX_SERVER_WAIT_TIMEOUT:
7165 {
7166 *type = GL_INT_64_ANGLEX;
7167 *numParams = 1;
7168 return true;
7169 }
7170
7171 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7172 case GL_TRANSFORM_FEEDBACK_PAUSED:
7173 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7174 case GL_RASTERIZER_DISCARD:
7175 {
7176 *type = GL_BOOL;
7177 *numParams = 1;
7178 return true;
7179 }
7180
7181 case GL_MAX_TEXTURE_LOD_BIAS:
7182 {
7183 *type = GL_FLOAT;
7184 *numParams = 1;
7185 return true;
7186 }
7187 }
7188
7189 if (getExtensions().requestExtension)
7190 {
7191 switch (pname)
7192 {
7193 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7194 *type = GL_INT;
7195 *numParams = 1;
7196 return true;
7197 }
7198 }
7199
7200 if (getClientVersion() < Version(3, 1))
7201 {
7202 return false;
7203 }
7204
7205 switch (pname)
7206 {
7207 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7208 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7209 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7210 case GL_MAX_FRAMEBUFFER_WIDTH:
7211 case GL_MAX_FRAMEBUFFER_HEIGHT:
7212 case GL_MAX_FRAMEBUFFER_SAMPLES:
7213 case GL_MAX_SAMPLE_MASK_WORDS:
7214 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7215 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7216 case GL_MAX_INTEGER_SAMPLES:
7217 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7218 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7219 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7220 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7221 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7222 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7223 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7224 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7225 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7226 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7227 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7228 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7229 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7230 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7231 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7232 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7233 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7234 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7235 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7236 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7237 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7238 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7239 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7240 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7241 case GL_MAX_UNIFORM_LOCATIONS:
7242 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7243 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7244 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7245 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7246 case GL_MAX_IMAGE_UNITS:
7247 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7248 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7249 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7250 case GL_SHADER_STORAGE_BUFFER_BINDING:
7251 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7252 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7253 *type = GL_INT;
7254 *numParams = 1;
7255 return true;
7256 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7257 *type = GL_INT_64_ANGLEX;
7258 *numParams = 1;
7259 return true;
7260 case GL_SAMPLE_MASK:
7261 *type = GL_BOOL;
7262 *numParams = 1;
7263 return true;
7264 }
7265
7266 if (getExtensions().geometryShader)
7267 {
7268 switch (pname)
7269 {
7270 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7271 case GL_LAYER_PROVOKING_VERTEX_EXT:
7272 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7273 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7274 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7275 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7276 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7277 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7278 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7279 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7280 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7281 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7282 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7283 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7284 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7285 *type = GL_INT;
7286 *numParams = 1;
7287 return true;
7288 }
7289 }
7290
7291 return false;
7292}
7293
7294bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7295{
7296 if (getClientVersion() < Version(3, 0))
7297 {
7298 return false;
7299 }
7300
7301 switch (target)
7302 {
7303 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7304 case GL_UNIFORM_BUFFER_BINDING:
7305 {
7306 *type = GL_INT;
7307 *numParams = 1;
7308 return true;
7309 }
7310 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7311 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7312 case GL_UNIFORM_BUFFER_START:
7313 case GL_UNIFORM_BUFFER_SIZE:
7314 {
7315 *type = GL_INT_64_ANGLEX;
7316 *numParams = 1;
7317 return true;
7318 }
7319 }
7320
7321 if (getClientVersion() < Version(3, 1))
7322 {
7323 return false;
7324 }
7325
7326 switch (target)
7327 {
7328 case GL_IMAGE_BINDING_LAYERED:
7329 {
7330 *type = GL_BOOL;
7331 *numParams = 1;
7332 return true;
7333 }
7334 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7335 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7336 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7337 case GL_SHADER_STORAGE_BUFFER_BINDING:
7338 case GL_VERTEX_BINDING_BUFFER:
7339 case GL_VERTEX_BINDING_DIVISOR:
7340 case GL_VERTEX_BINDING_OFFSET:
7341 case GL_VERTEX_BINDING_STRIDE:
7342 case GL_SAMPLE_MASK_VALUE:
7343 case GL_IMAGE_BINDING_NAME:
7344 case GL_IMAGE_BINDING_LEVEL:
7345 case GL_IMAGE_BINDING_LAYER:
7346 case GL_IMAGE_BINDING_ACCESS:
7347 case GL_IMAGE_BINDING_FORMAT:
7348 {
7349 *type = GL_INT;
7350 *numParams = 1;
7351 return true;
7352 }
7353 case GL_ATOMIC_COUNTER_BUFFER_START:
7354 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7355 case GL_SHADER_STORAGE_BUFFER_START:
7356 case GL_SHADER_STORAGE_BUFFER_SIZE:
7357 {
7358 *type = GL_INT_64_ANGLEX;
7359 *numParams = 1;
7360 return true;
7361 }
7362 }
7363
7364 return false;
7365}
7366
7367Program *Context::getProgram(GLuint handle) const
7368{
7369 return mState.mShaderPrograms->getProgram(handle);
7370}
7371
7372Shader *Context::getShader(GLuint handle) const
7373{
7374 return mState.mShaderPrograms->getShader(handle);
7375}
7376
7377bool Context::isTextureGenerated(GLuint texture) const
7378{
7379 return mState.mTextures->isHandleGenerated(texture);
7380}
7381
7382bool Context::isBufferGenerated(GLuint buffer) const
7383{
7384 return mState.mBuffers->isHandleGenerated(buffer);
7385}
7386
7387bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7388{
7389 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7390}
7391
7392bool Context::isFramebufferGenerated(GLuint framebuffer) const
7393{
7394 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7395}
7396
7397bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7398{
7399 return mState.mPipelines->isHandleGenerated(pipeline);
7400}
7401
7402bool Context::usingDisplayTextureShareGroup() const
7403{
7404 return mDisplayTextureShareGroup;
7405}
7406
7407GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7408{
7409 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7410 internalformat == GL_DEPTH_STENCIL
7411 ? GL_DEPTH24_STENCIL8
7412 : internalformat;
7413}
7414
Jamie Madillc29968b2016-01-20 11:17:23 -05007415} // namespace gl