blob: e38b85de9941a650febca9df78a967f96e774f12 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070027#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030028#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080030#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050032#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050033#include "libANGLE/ResourceManager.h"
34#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050035#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050036#include "libANGLE/Texture.h"
37#include "libANGLE/TransformFeedback.h"
38#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040040#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030041#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040042#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040043#include "libANGLE/renderer/ContextImpl.h"
44#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040045#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040046#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000047
Geoff Langf6db0982015-08-25 13:04:00 -040048namespace
49{
50
Jamie Madillb6664922017-07-25 12:55:04 -040051#define ANGLE_HANDLE_ERR(X) \
52 handleError(X); \
53 return;
54#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
55
Ian Ewell3ffd78b2016-01-22 16:09:42 -050056template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050057std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030058 GLsizei numPaths,
59 const void *paths,
60 GLuint pathBase)
61{
62 std::vector<gl::Path *> ret;
63 ret.reserve(numPaths);
64
65 const auto *nameArray = static_cast<const T *>(paths);
66
67 for (GLsizei i = 0; i < numPaths; ++i)
68 {
69 const GLuint pathName = nameArray[i] + pathBase;
70
71 ret.push_back(resourceManager.getPath(pathName));
72 }
73
74 return ret;
75}
76
Geoff Lang4ddf5af2016-12-01 14:30:44 -050077std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030078 GLsizei numPaths,
79 GLenum pathNameType,
80 const void *paths,
81 GLuint pathBase)
82{
83 switch (pathNameType)
84 {
85 case GL_UNSIGNED_BYTE:
86 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_BYTE:
89 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_UNSIGNED_SHORT:
92 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_SHORT:
95 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_UNSIGNED_INT:
98 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_INT:
101 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
102 }
103
104 UNREACHABLE();
105 return std::vector<gl::Path *>();
106}
107
108template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400109gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110{
Geoff Lang2186c382016-10-14 10:54:54 -0400111 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500112
113 switch (pname)
114 {
115 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400116 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117 case GL_QUERY_RESULT_AVAILABLE_EXT:
118 {
119 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400120 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 if (!error.isError())
122 {
jchen10a99ed552017-09-22 08:10:32 +0800123 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125 return error;
126 }
127 default:
128 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500129 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill09463932018-04-04 05:26:59 -0400133void MarkTransformFeedbackBufferUsage(const gl::Context *context,
134 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Geoff Lang1a683462015-09-29 15:09:59 -0400138 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155gl::Version GetClientVersion(const egl::AttributeMap &attribs)
156{
157 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Geoff Langf6db0982015-08-25 13:04:00 -0400257} // anonymous namespace
258
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000259namespace gl
260{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000261
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400262Context::Context(rx::EGLImplFactory *implFactory,
263 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400264 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500265 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400266 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500267 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700268 const egl::DisplayExtensions &displayExtensions,
269 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500270 : mState(reinterpret_cast<ContextID>(this),
271 shareContext ? &shareContext->mState : nullptr,
272 shareTextures,
273 GetClientVersion(attribs),
274 &mGLState,
275 mCaps,
276 mTextureCaps,
277 mExtensions,
278 mLimitations),
279 mSkipValidation(GetNoError(attribs)),
280 mDisplayTextureShareGroup(shareTextures != nullptr),
281 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700282 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400283 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400284 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mClientType(EGL_OPENGL_ES_API),
286 mHasBeenCurrent(false),
287 mContextLost(false),
288 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700289 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mResetStrategy(GetResetStrategy(attribs)),
291 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400292 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
293 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500294 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500295 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400296 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400297 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400298 mScratchBuffer(1000u),
299 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000300{
Jamie Madill5b772312018-03-08 20:28:32 -0500301 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400302 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
303 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500304
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400305 mImplementation->setMemoryProgramCache(memoryProgramCache);
306
Geoff Langb433e872017-10-05 14:01:47 -0400307 bool robustResourceInit = GetRobustResourceInit(attribs);
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700308 initCaps(displayExtensions, clientExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700309 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400310
Jamie Madill4928b7c2017-06-20 12:57:39 -0400311 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400312 GetClientArraysEnabled(attribs), robustResourceInit,
313 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100314
Shannon Woods53a94a82014-06-24 15:20:36 -0400315 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400316
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400318 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000319 // and cube map texture state vectors respectively associated with them.
320 // In order that access to these initial textures not be lost, they are treated as texture
321 // objects all of whose names are 0.
322
Corentin Wallez99d492c2018-02-27 15:17:10 -0500323 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800324 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500325
Corentin Wallez99d492c2018-02-27 15:17:10 -0500326 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800327 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400328
Geoff Langeb66a6e2016-10-31 13:06:12 -0400329 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400330 {
331 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500332 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800333 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400334
Corentin Wallez99d492c2018-02-27 15:17:10 -0500335 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800336 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 }
Geoff Lang3b573612016-10-31 14:08:10 -0400338 if (getClientVersion() >= Version(3, 1))
339 {
340 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500341 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800342 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343
Jiajia Qin6eafb042016-12-27 17:04:07 +0800344 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
345 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800346 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800347 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800349 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
350 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400351 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800352 }
Geoff Lang3b573612016-10-31 14:08:10 -0400353 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000354
Geoff Langb0f917f2017-12-05 13:41:54 -0500355 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400356 {
357 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500358 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800359 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400360 }
361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400363 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500364 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800365 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400366 }
367
Jamie Madill4928b7c2017-06-20 12:57:39 -0400368 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500369
Jamie Madill57a89722013-07-02 11:57:03 -0400370 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000371
Geoff Langeb66a6e2016-10-31 13:06:12 -0400372 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400373 {
374 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
375 // In the initial state, a default transform feedback object is bound and treated as
376 // a transform feedback object with a name of zero. That object is bound any time
377 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400378 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400379 }
Geoff Langc8058452014-02-03 12:04:11 -0500380
Corentin Wallez336129f2017-10-17 15:55:40 -0400381 for (auto type : angle::AllEnums<BufferBinding>())
382 {
383 bindBuffer(type, 0);
384 }
385
386 bindRenderbuffer(GL_RENDERBUFFER, 0);
387
388 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
389 {
390 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
391 }
392
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700393 // Initialize GLES1 renderer if appropriate.
394 if (getClientVersion() < Version(2, 0))
395 {
396 mGLES1Renderer.reset(new GLES1Renderer());
397 }
398
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500401 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500402 // No dirty objects.
403
404 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500407 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
408
409 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
411 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
412 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
416 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
419 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
420 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
421
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
423 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700424 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400427
Xinghua Cao10a4d432017-11-28 14:46:26 +0800428 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
429 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
431 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
432 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
433 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800434 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800435 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800436
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400437 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438}
439
Jamie Madill4928b7c2017-06-20 12:57:39 -0400440egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700442 if (mGLES1Renderer)
443 {
444 mGLES1Renderer->onDestroy(this, &mGLState);
445 }
446
Jamie Madille7b3fe22018-04-05 09:42:46 -0400447 // Delete the Surface first to trigger a finish() in Vulkan.
Geoff Lang61107632018-05-09 11:32:46 -0400448 if (mSurfacelessFramebuffer)
449 {
450 mSurfacelessFramebuffer->onDestroy(this);
451 SafeDelete(mSurfacelessFramebuffer);
452 }
Jamie Madille7b3fe22018-04-05 09:42:46 -0400453
454 ANGLE_TRY(releaseSurface(display));
455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400460 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461
Corentin Wallez80b24112015-08-25 16:41:57 -0400462 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400464 if (query.second != nullptr)
465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400469 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000470
Corentin Wallez80b24112015-08-25 16:41:57 -0400471 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400472 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 if (vertexArray.second)
474 {
475 vertexArray.second->onDestroy(this);
476 }
Jamie Madill57a89722013-07-02 11:57:03 -0400477 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400478 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400479
Corentin Wallez80b24112015-08-25 16:41:57 -0400480 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500481 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500482 if (transformFeedback.second != nullptr)
483 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500484 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500485 }
Geoff Langc8058452014-02-03 12:04:11 -0500486 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400487 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500488
Jamie Madill5b772312018-03-08 20:28:32 -0500489 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400490 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800491 if (zeroTexture.get() != nullptr)
492 {
493 ANGLE_TRY(zeroTexture->onDestroy(this));
494 zeroTexture.set(this, nullptr);
495 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400496 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497
Jamie Madill2f348d22017-06-05 10:50:59 -0400498 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500 mGLState.reset(this);
501
Jamie Madill6c1f6712017-02-14 19:08:04 -0500502 mState.mBuffers->release(this);
503 mState.mShaderPrograms->release(this);
504 mState.mTextures->release(this);
505 mState.mRenderbuffers->release(this);
506 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400507 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500508 mState.mPaths->release(this);
509 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800510 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511
Jamie Madill76e471e2017-10-21 09:56:01 -0400512 mImplementation->onDestroy(this);
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517Context::~Context()
518{
519}
520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522{
Jamie Madill61e16b42017-06-19 11:13:23 -0400523 mCurrentDisplay = display;
524
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 if (!mHasBeenCurrent)
526 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000527 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500528 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400529 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallezc295e512017-01-27 17:47:50 -0500531 int width = 0;
532 int height = 0;
533 if (surface != nullptr)
534 {
535 width = surface->getWidth();
536 height = surface->getHeight();
537 }
538
539 mGLState.setViewportParams(0, 0, width, height);
540 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541
542 mHasBeenCurrent = true;
543 }
544
Jamie Madill1b94d432015-08-07 13:23:23 -0400545 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400547 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400548
Jamie Madill4928b7c2017-06-20 12:57:39 -0400549 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500550
551 Framebuffer *newDefault = nullptr;
552 if (surface != nullptr)
553 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400554 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500555 mCurrentSurface = surface;
556 newDefault = surface->getDefaultFramebuffer();
557 }
558 else
559 {
560 if (mSurfacelessFramebuffer == nullptr)
561 {
562 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
563 }
564
565 newDefault = mSurfacelessFramebuffer;
566 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000567
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Update default framebuffer, the binding of the previous default
569 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400570 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700571 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700573 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400574 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700575 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400576 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700577 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400578 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500579 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400580 }
Ian Ewell292f0052016-02-04 10:37:32 -0500581
582 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583 mImplementation->onMakeCurrent(this);
584 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585}
586
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400588{
Corentin Wallez37c39792015-08-20 14:19:46 -0400589 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500590 Framebuffer *currentDefault = nullptr;
591 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400592 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500593 currentDefault = mCurrentSurface->getDefaultFramebuffer();
594 }
595 else if (mSurfacelessFramebuffer != nullptr)
596 {
597 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400598 }
599
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 if (mGLState.getReadFramebuffer() == currentDefault)
601 {
602 mGLState.setReadFramebufferBinding(nullptr);
603 }
604 if (mGLState.getDrawFramebuffer() == currentDefault)
605 {
606 mGLState.setDrawFramebufferBinding(nullptr);
607 }
608 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
609
610 if (mCurrentSurface)
611 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500613 mCurrentSurface = nullptr;
614 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400615
616 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400617}
618
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619GLuint Context::createBuffer()
620{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500621 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622}
623
624GLuint Context::createProgram()
625{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500626 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627}
628
Jiawei Shao385b3e02018-03-21 09:43:28 +0800629GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500631 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632}
633
634GLuint Context::createTexture()
635{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500636 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
639GLuint Context::createRenderbuffer()
640{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500641 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Brandon Jones59770802018-04-02 13:18:42 -0700644GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300645{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500646 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300647 if (resultOrError.isError())
648 {
649 handleError(resultOrError.getError());
650 return 0;
651 }
652 return resultOrError.getResult();
653}
654
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655// Returns an unused framebuffer name
656GLuint Context::createFramebuffer()
657{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500658 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500661void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500663 for (int i = 0; i < n; i++)
664 {
665 GLuint handle = mFenceNVHandleAllocator.allocate();
666 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
667 fences[i] = handle;
668 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
Yunchao Hea336b902017-08-02 16:05:21 +0800671GLuint Context::createProgramPipeline()
672{
673 return mState.mPipelines->createProgramPipeline();
674}
675
Jiawei Shao385b3e02018-03-21 09:43:28 +0800676GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800677{
678 UNIMPLEMENTED();
679 return 0u;
680}
681
James Darpinian4d9d4832018-03-13 12:43:28 -0700682void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683{
James Darpinian4d9d4832018-03-13 12:43:28 -0700684 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
685 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000686 {
687 detachBuffer(buffer);
688 }
Jamie Madill893ab082014-05-16 16:56:10 -0400689
James Darpinian4d9d4832018-03-13 12:43:28 -0700690 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000691}
692
693void Context::deleteShader(GLuint shader)
694{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500695 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696}
697
698void Context::deleteProgram(GLuint program)
699{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500700 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000701}
702
703void Context::deleteTexture(GLuint texture)
704{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500705 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000706 {
707 detachTexture(texture);
708 }
709
Jamie Madill6c1f6712017-02-14 19:08:04 -0500710 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
713void Context::deleteRenderbuffer(GLuint renderbuffer)
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716 {
717 detachRenderbuffer(renderbuffer);
718 }
Jamie Madill893ab082014-05-16 16:56:10 -0400719
Jamie Madill6c1f6712017-02-14 19:08:04 -0500720 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400723void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400724{
725 // The spec specifies the underlying Fence object is not deleted until all current
726 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
727 // and since our API is currently designed for being called from a single thread, we can delete
728 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400729 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400730}
731
Yunchao Hea336b902017-08-02 16:05:21 +0800732void Context::deleteProgramPipeline(GLuint pipeline)
733{
734 if (mState.mPipelines->getProgramPipeline(pipeline))
735 {
736 detachProgramPipeline(pipeline);
737 }
738
739 mState.mPipelines->deleteObject(this, pipeline);
740}
741
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742void Context::deletePaths(GLuint first, GLsizei range)
743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745}
746
Brandon Jones59770802018-04-02 13:18:42 -0700747bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500749 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750 if (pathObj == nullptr)
751 return false;
752
753 return pathObj->hasPathData();
754}
755
Brandon Jones59770802018-04-02 13:18:42 -0700756bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759}
760
Brandon Jones59770802018-04-02 13:18:42 -0700761void Context::pathCommands(GLuint path,
762 GLsizei numCommands,
763 const GLubyte *commands,
764 GLsizei numCoords,
765 GLenum coordType,
766 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300767{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500768 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300769
770 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
771}
772
Jamie Madill007530e2017-12-28 14:27:04 -0500773void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Jamie Madill007530e2017-12-28 14:27:04 -0500775 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300776
777 switch (pname)
778 {
779 case GL_PATH_STROKE_WIDTH_CHROMIUM:
780 pathObj->setStrokeWidth(value);
781 break;
782 case GL_PATH_END_CAPS_CHROMIUM:
783 pathObj->setEndCaps(static_cast<GLenum>(value));
784 break;
785 case GL_PATH_JOIN_STYLE_CHROMIUM:
786 pathObj->setJoinStyle(static_cast<GLenum>(value));
787 break;
788 case GL_PATH_MITER_LIMIT_CHROMIUM:
789 pathObj->setMiterLimit(value);
790 break;
791 case GL_PATH_STROKE_BOUND_CHROMIUM:
792 pathObj->setStrokeBound(value);
793 break;
794 default:
795 UNREACHABLE();
796 break;
797 }
798}
799
Jamie Madill007530e2017-12-28 14:27:04 -0500800void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801{
Jamie Madill007530e2017-12-28 14:27:04 -0500802 // TODO(jmadill): Should use proper clamping/casting.
803 pathParameterf(path, pname, static_cast<GLfloat>(value));
804}
805
806void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
807{
808 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300809
810 switch (pname)
811 {
812 case GL_PATH_STROKE_WIDTH_CHROMIUM:
813 *value = pathObj->getStrokeWidth();
814 break;
815 case GL_PATH_END_CAPS_CHROMIUM:
816 *value = static_cast<GLfloat>(pathObj->getEndCaps());
817 break;
818 case GL_PATH_JOIN_STYLE_CHROMIUM:
819 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
820 break;
821 case GL_PATH_MITER_LIMIT_CHROMIUM:
822 *value = pathObj->getMiterLimit();
823 break;
824 case GL_PATH_STROKE_BOUND_CHROMIUM:
825 *value = pathObj->getStrokeBound();
826 break;
827 default:
828 UNREACHABLE();
829 break;
830 }
831}
832
Jamie Madill007530e2017-12-28 14:27:04 -0500833void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
834{
835 GLfloat val = 0.0f;
836 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
837 if (value)
838 *value = static_cast<GLint>(val);
839}
840
Brandon Jones59770802018-04-02 13:18:42 -0700841void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842{
843 mGLState.setPathStencilFunc(func, ref, mask);
844}
845
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846void Context::deleteFramebuffer(GLuint framebuffer)
847{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500848 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849 {
850 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500852
Jamie Madill6c1f6712017-02-14 19:08:04 -0500853 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854}
855
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500856void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500858 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500860 GLuint fence = fences[i];
861
862 FenceNV *fenceObject = nullptr;
863 if (mFenceNVMap.erase(fence, &fenceObject))
864 {
865 mFenceNVHandleAllocator.release(fence);
866 delete fenceObject;
867 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868 }
869}
870
Geoff Lang70d0f492015-12-10 17:45:46 -0500871Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500873 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874}
875
Jamie Madill570f7c82014-07-03 10:38:54 -0400876Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000877{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500878 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879}
880
Geoff Lang70d0f492015-12-10 17:45:46 -0500881Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000882{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500883 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884}
885
Jamie Madill70b5bb02017-08-28 13:32:37 -0400886Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400887{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400888 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400889}
890
Jamie Madill57a89722013-07-02 11:57:03 -0400891VertexArray *Context::getVertexArray(GLuint handle) const
892{
Jamie Madill96a483b2017-06-27 16:49:21 -0400893 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400894}
895
Jamie Madilldc356042013-07-19 16:36:57 -0400896Sampler *Context::getSampler(GLuint handle) const
897{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500898 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400899}
900
Geoff Langc8058452014-02-03 12:04:11 -0500901TransformFeedback *Context::getTransformFeedback(GLuint handle) const
902{
Jamie Madill96a483b2017-06-27 16:49:21 -0400903 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500904}
905
Yunchao Hea336b902017-08-02 16:05:21 +0800906ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
907{
908 return mState.mPipelines->getProgramPipeline(handle);
909}
910
Geoff Lang70d0f492015-12-10 17:45:46 -0500911LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
912{
913 switch (identifier)
914 {
915 case GL_BUFFER:
916 return getBuffer(name);
917 case GL_SHADER:
918 return getShader(name);
919 case GL_PROGRAM:
920 return getProgram(name);
921 case GL_VERTEX_ARRAY:
922 return getVertexArray(name);
923 case GL_QUERY:
924 return getQuery(name);
925 case GL_TRANSFORM_FEEDBACK:
926 return getTransformFeedback(name);
927 case GL_SAMPLER:
928 return getSampler(name);
929 case GL_TEXTURE:
930 return getTexture(name);
931 case GL_RENDERBUFFER:
932 return getRenderbuffer(name);
933 case GL_FRAMEBUFFER:
934 return getFramebuffer(name);
935 default:
936 UNREACHABLE();
937 return nullptr;
938 }
939}
940
941LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
942{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400943 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500944}
945
Martin Radev9d901792016-07-15 15:58:58 +0300946void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
947{
948 LabeledObject *object = getLabeledObject(identifier, name);
949 ASSERT(object != nullptr);
950
951 std::string labelName = GetObjectLabelFromPointer(length, label);
952 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400953
954 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
955 // specified object is active until we do this.
956 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300957}
958
959void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
960{
961 LabeledObject *object = getLabeledObjectFromPtr(ptr);
962 ASSERT(object != nullptr);
963
964 std::string labelName = GetObjectLabelFromPointer(length, label);
965 object->setLabel(labelName);
966}
967
968void Context::getObjectLabel(GLenum identifier,
969 GLuint name,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObject(identifier, name);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
981void Context::getObjectPtrLabel(const void *ptr,
982 GLsizei bufSize,
983 GLsizei *length,
984 GLchar *label) const
985{
986 LabeledObject *object = getLabeledObjectFromPtr(ptr);
987 ASSERT(object != nullptr);
988
989 const std::string &objectLabel = object->getLabel();
990 GetObjectLabelBase(objectLabel, bufSize, length, label);
991}
992
Jamie Madilldc356042013-07-19 16:36:57 -0400993bool Context::isSampler(GLuint samplerName) const
994{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500995 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400996}
997
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800998void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001
Jamie Madilldedd7b92014-11-05 16:30:36 -05001002 if (handle == 0)
1003 {
1004 texture = mZeroTextures[target].get();
1005 }
1006 else
1007 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001008 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009 }
1010
1011 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001013}
1014
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001015void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001017 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1018 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001019 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001020}
1021
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001022void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001024 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1025 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001026 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027}
1028
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001029void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001030{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001032 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001033}
1034
Shao80957d92017-02-20 21:25:59 +08001035void Context::bindVertexBuffer(GLuint bindingIndex,
1036 GLuint bufferHandle,
1037 GLintptr offset,
1038 GLsizei stride)
1039{
1040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001041 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001045{
Geoff Lang76b10c92014-09-05 16:28:14 -04001046 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001047 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001048 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001049 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001050}
1051
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001052void Context::bindImageTexture(GLuint unit,
1053 GLuint texture,
1054 GLint level,
1055 GLboolean layered,
1056 GLint layer,
1057 GLenum access,
1058 GLenum format)
1059{
1060 Texture *tex = mState.mTextures->getTexture(texture);
1061 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1062}
1063
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064void Context::useProgram(GLuint program)
1065{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001066 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001067}
1068
Jiajia Qin5451d532017-11-16 17:16:34 +08001069void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1070{
1071 UNIMPLEMENTED();
1072}
1073
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001074void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001075{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001076 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001077 TransformFeedback *transformFeedback =
1078 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001079 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001080}
1081
Yunchao Hea336b902017-08-02 16:05:21 +08001082void Context::bindProgramPipeline(GLuint pipelineHandle)
1083{
1084 ProgramPipeline *pipeline =
1085 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1086 mGLState.setProgramPipelineBinding(this, pipeline);
1087}
1088
Corentin Wallezad3ae902018-03-09 13:40:42 -05001089void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001092 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093
Geoff Lang5aad9672014-09-08 11:10:42 -04001094 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001095 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001096
1097 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001099}
1100
Corentin Wallezad3ae902018-03-09 13:40:42 -05001101void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001103 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001104 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001107
Geoff Lang5aad9672014-09-08 11:10:42 -04001108 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Corentin Wallezad3ae902018-03-09 13:40:42 -05001112void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001113{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001114 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115
1116 Query *queryObject = getQuery(id, true, target);
1117 ASSERT(queryObject);
1118
Jamie Madillf0e04492017-08-26 15:28:42 -04001119 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120}
1121
Corentin Wallezad3ae902018-03-09 13:40:42 -05001122void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123{
1124 switch (pname)
1125 {
1126 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001128 break;
1129 case GL_QUERY_COUNTER_BITS_EXT:
1130 switch (target)
1131 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001132 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001133 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1134 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001135 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001136 params[0] = getExtensions().queryCounterBitsTimestamp;
1137 break;
1138 default:
1139 UNREACHABLE();
1140 params[0] = 0;
1141 break;
1142 }
1143 break;
1144 default:
1145 UNREACHABLE();
1146 return;
1147 }
1148}
1149
Corentin Wallezad3ae902018-03-09 13:40:42 -05001150void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001151 GLenum pname,
1152 GLsizei bufSize,
1153 GLsizei *length,
1154 GLint *params)
1155{
1156 getQueryiv(target, pname, params);
1157}
1158
Geoff Lang2186c382016-10-14 10:54:54 -04001159void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160{
Geoff Lang2186c382016-10-14 10:54:54 -04001161 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001162}
1163
Brandon Jones59770802018-04-02 13:18:42 -07001164void Context::getQueryObjectivRobust(GLuint id,
1165 GLenum pname,
1166 GLsizei bufSize,
1167 GLsizei *length,
1168 GLint *params)
1169{
1170 getQueryObjectiv(id, pname, params);
1171}
1172
Geoff Lang2186c382016-10-14 10:54:54 -04001173void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174{
Geoff Lang2186c382016-10-14 10:54:54 -04001175 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176}
1177
Brandon Jones59770802018-04-02 13:18:42 -07001178void Context::getQueryObjectuivRobust(GLuint id,
1179 GLenum pname,
1180 GLsizei bufSize,
1181 GLsizei *length,
1182 GLuint *params)
1183{
1184 getQueryObjectuiv(id, pname, params);
1185}
1186
Geoff Lang2186c382016-10-14 10:54:54 -04001187void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188{
Geoff Lang2186c382016-10-14 10:54:54 -04001189 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190}
1191
Brandon Jones59770802018-04-02 13:18:42 -07001192void Context::getQueryObjecti64vRobust(GLuint id,
1193 GLenum pname,
1194 GLsizei bufSize,
1195 GLsizei *length,
1196 GLint64 *params)
1197{
1198 getQueryObjecti64v(id, pname, params);
1199}
1200
Geoff Lang2186c382016-10-14 10:54:54 -04001201void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202{
Geoff Lang2186c382016-10-14 10:54:54 -04001203 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204}
1205
Brandon Jones59770802018-04-02 13:18:42 -07001206void Context::getQueryObjectui64vRobust(GLuint id,
1207 GLenum pname,
1208 GLsizei bufSize,
1209 GLsizei *length,
1210 GLuint64 *params)
1211{
1212 getQueryObjectui64v(id, pname, params);
1213}
1214
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001215Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001217 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218}
1219
Jamie Madill2f348d22017-06-05 10:50:59 -04001220FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221{
Jamie Madill96a483b2017-06-27 16:49:21 -04001222 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223}
1224
Corentin Wallezad3ae902018-03-09 13:40:42 -05001225Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226{
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001229 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001231
1232 Query *query = mQueryMap.query(handle);
1233 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001234 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 query = new Query(mImplementation->createQuery(type), handle);
1237 query->addRef();
1238 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001240 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241}
1242
Geoff Lang70d0f492015-12-10 17:45:46 -05001243Query *Context::getQuery(GLuint handle) const
1244{
Jamie Madill96a483b2017-06-27 16:49:21 -04001245 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001246}
1247
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001249{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001250 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1251 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001252}
1253
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001254Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001256 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257}
1258
Geoff Lang492a7e42014-11-05 13:27:06 -05001259Compiler *Context::getCompiler() const
1260{
Jamie Madill2f348d22017-06-05 10:50:59 -04001261 if (mCompiler.get() == nullptr)
1262 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001263 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001264 }
1265 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001266}
1267
Jamie Madillc1d770e2017-04-13 17:31:24 -04001268void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
1270 switch (pname)
1271 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001272 case GL_SHADER_COMPILER:
1273 *params = GL_TRUE;
1274 break;
1275 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1276 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1277 break;
1278 default:
1279 mGLState.getBooleanv(pname, params);
1280 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282}
1283
Jamie Madillc1d770e2017-04-13 17:31:24 -04001284void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285{
Shannon Woods53a94a82014-06-24 15:20:36 -04001286 // Queries about context capabilities and maximums are answered by Context.
1287 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 switch (pname)
1289 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001290 case GL_ALIASED_LINE_WIDTH_RANGE:
1291 params[0] = mCaps.minAliasedLineWidth;
1292 params[1] = mCaps.maxAliasedLineWidth;
1293 break;
1294 case GL_ALIASED_POINT_SIZE_RANGE:
1295 params[0] = mCaps.minAliasedPointSize;
1296 params[1] = mCaps.maxAliasedPointSize;
1297 break;
1298 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1299 ASSERT(mExtensions.textureFilterAnisotropic);
1300 *params = mExtensions.maxTextureAnisotropy;
1301 break;
1302 case GL_MAX_TEXTURE_LOD_BIAS:
1303 *params = mCaps.maxLODBias;
1304 break;
1305
1306 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1307 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1308 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001309 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1310 // GLES1 constants for modelview/projection matrix.
1311 if (getClientVersion() < Version(2, 0))
1312 {
1313 mGLState.getFloatv(pname, params);
1314 }
1315 else
1316 {
1317 ASSERT(mExtensions.pathRendering);
1318 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1319 memcpy(params, m, 16 * sizeof(GLfloat));
1320 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001321 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001322 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001323
Jamie Madill231c7f52017-04-26 13:45:37 -04001324 default:
1325 mGLState.getFloatv(pname, params);
1326 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Jamie Madillc1d770e2017-04-13 17:31:24 -04001330void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
Shannon Woods53a94a82014-06-24 15:20:36 -04001332 // Queries about context capabilities and maximums are answered by Context.
1333 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001334
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 switch (pname)
1336 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001337 case GL_MAX_VERTEX_ATTRIBS:
1338 *params = mCaps.maxVertexAttributes;
1339 break;
1340 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1341 *params = mCaps.maxVertexUniformVectors;
1342 break;
1343 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1344 *params = mCaps.maxVertexUniformComponents;
1345 break;
1346 case GL_MAX_VARYING_VECTORS:
1347 *params = mCaps.maxVaryingVectors;
1348 break;
1349 case GL_MAX_VARYING_COMPONENTS:
1350 *params = mCaps.maxVertexOutputComponents;
1351 break;
1352 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1353 *params = mCaps.maxCombinedTextureImageUnits;
1354 break;
1355 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001356 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001359 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
1361 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1362 *params = mCaps.maxFragmentUniformVectors;
1363 break;
1364 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1365 *params = mCaps.maxFragmentUniformComponents;
1366 break;
1367 case GL_MAX_RENDERBUFFER_SIZE:
1368 *params = mCaps.maxRenderbufferSize;
1369 break;
1370 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1371 *params = mCaps.maxColorAttachments;
1372 break;
1373 case GL_MAX_DRAW_BUFFERS_EXT:
1374 *params = mCaps.maxDrawBuffers;
1375 break;
1376 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1377 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1378 case GL_SUBPIXEL_BITS:
1379 *params = 4;
1380 break;
1381 case GL_MAX_TEXTURE_SIZE:
1382 *params = mCaps.max2DTextureSize;
1383 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001384 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1385 *params = mCaps.maxRectangleTextureSize;
1386 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1388 *params = mCaps.maxCubeMapTextureSize;
1389 break;
1390 case GL_MAX_3D_TEXTURE_SIZE:
1391 *params = mCaps.max3DTextureSize;
1392 break;
1393 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1394 *params = mCaps.maxArrayTextureLayers;
1395 break;
1396 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1397 *params = mCaps.uniformBufferOffsetAlignment;
1398 break;
1399 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1400 *params = mCaps.maxUniformBufferBindings;
1401 break;
1402 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001403 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001404 break;
1405 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001406 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 break;
1408 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1409 *params = mCaps.maxCombinedTextureImageUnits;
1410 break;
1411 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1412 *params = mCaps.maxVertexOutputComponents;
1413 break;
1414 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1415 *params = mCaps.maxFragmentInputComponents;
1416 break;
1417 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1418 *params = mCaps.minProgramTexelOffset;
1419 break;
1420 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1421 *params = mCaps.maxProgramTexelOffset;
1422 break;
1423 case GL_MAJOR_VERSION:
1424 *params = getClientVersion().major;
1425 break;
1426 case GL_MINOR_VERSION:
1427 *params = getClientVersion().minor;
1428 break;
1429 case GL_MAX_ELEMENTS_INDICES:
1430 *params = mCaps.maxElementsIndices;
1431 break;
1432 case GL_MAX_ELEMENTS_VERTICES:
1433 *params = mCaps.maxElementsVertices;
1434 break;
1435 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1436 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1437 break;
1438 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1439 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1440 break;
1441 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1442 *params = mCaps.maxTransformFeedbackSeparateComponents;
1443 break;
1444 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1445 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1446 break;
1447 case GL_MAX_SAMPLES_ANGLE:
1448 *params = mCaps.maxSamples;
1449 break;
1450 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001451 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001452 params[0] = mCaps.maxViewportWidth;
1453 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001454 }
1455 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 case GL_COMPRESSED_TEXTURE_FORMATS:
1457 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1458 params);
1459 break;
1460 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1461 *params = mResetStrategy;
1462 break;
1463 case GL_NUM_SHADER_BINARY_FORMATS:
1464 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1465 break;
1466 case GL_SHADER_BINARY_FORMATS:
1467 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1468 break;
1469 case GL_NUM_PROGRAM_BINARY_FORMATS:
1470 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1471 break;
1472 case GL_PROGRAM_BINARY_FORMATS:
1473 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1474 break;
1475 case GL_NUM_EXTENSIONS:
1476 *params = static_cast<GLint>(mExtensionStrings.size());
1477 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001478
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 // GL_KHR_debug
1480 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1481 *params = mExtensions.maxDebugMessageLength;
1482 break;
1483 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1484 *params = mExtensions.maxDebugLoggedMessages;
1485 break;
1486 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1487 *params = mExtensions.maxDebugGroupStackDepth;
1488 break;
1489 case GL_MAX_LABEL_LENGTH:
1490 *params = mExtensions.maxLabelLength;
1491 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001492
Martin Radeve5285d22017-07-14 16:23:53 +03001493 // GL_ANGLE_multiview
1494 case GL_MAX_VIEWS_ANGLE:
1495 *params = mExtensions.maxViews;
1496 break;
1497
Jamie Madill231c7f52017-04-26 13:45:37 -04001498 // GL_EXT_disjoint_timer_query
1499 case GL_GPU_DISJOINT_EXT:
1500 *params = mImplementation->getGPUDisjoint();
1501 break;
1502 case GL_MAX_FRAMEBUFFER_WIDTH:
1503 *params = mCaps.maxFramebufferWidth;
1504 break;
1505 case GL_MAX_FRAMEBUFFER_HEIGHT:
1506 *params = mCaps.maxFramebufferHeight;
1507 break;
1508 case GL_MAX_FRAMEBUFFER_SAMPLES:
1509 *params = mCaps.maxFramebufferSamples;
1510 break;
1511 case GL_MAX_SAMPLE_MASK_WORDS:
1512 *params = mCaps.maxSampleMaskWords;
1513 break;
1514 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1515 *params = mCaps.maxColorTextureSamples;
1516 break;
1517 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1518 *params = mCaps.maxDepthTextureSamples;
1519 break;
1520 case GL_MAX_INTEGER_SAMPLES:
1521 *params = mCaps.maxIntegerSamples;
1522 break;
1523 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1524 *params = mCaps.maxVertexAttribRelativeOffset;
1525 break;
1526 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1527 *params = mCaps.maxVertexAttribBindings;
1528 break;
1529 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1530 *params = mCaps.maxVertexAttribStride;
1531 break;
1532 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1533 *params = mCaps.maxVertexAtomicCounterBuffers;
1534 break;
1535 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1536 *params = mCaps.maxVertexAtomicCounters;
1537 break;
1538 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1539 *params = mCaps.maxVertexImageUniforms;
1540 break;
1541 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001542 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1545 *params = mCaps.maxFragmentAtomicCounterBuffers;
1546 break;
1547 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1548 *params = mCaps.maxFragmentAtomicCounters;
1549 break;
1550 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1551 *params = mCaps.maxFragmentImageUniforms;
1552 break;
1553 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001554 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1557 *params = mCaps.minProgramTextureGatherOffset;
1558 break;
1559 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1560 *params = mCaps.maxProgramTextureGatherOffset;
1561 break;
1562 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1563 *params = mCaps.maxComputeWorkGroupInvocations;
1564 break;
1565 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001566 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001569 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1572 *params = mCaps.maxComputeSharedMemorySize;
1573 break;
1574 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1575 *params = mCaps.maxComputeUniformComponents;
1576 break;
1577 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1578 *params = mCaps.maxComputeAtomicCounterBuffers;
1579 break;
1580 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1581 *params = mCaps.maxComputeAtomicCounters;
1582 break;
1583 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1584 *params = mCaps.maxComputeImageUniforms;
1585 break;
1586 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1587 *params = mCaps.maxCombinedComputeUniformComponents;
1588 break;
1589 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001590 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1593 *params = mCaps.maxCombinedShaderOutputResources;
1594 break;
1595 case GL_MAX_UNIFORM_LOCATIONS:
1596 *params = mCaps.maxUniformLocations;
1597 break;
1598 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1599 *params = mCaps.maxAtomicCounterBufferBindings;
1600 break;
1601 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1602 *params = mCaps.maxAtomicCounterBufferSize;
1603 break;
1604 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1605 *params = mCaps.maxCombinedAtomicCounterBuffers;
1606 break;
1607 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1608 *params = mCaps.maxCombinedAtomicCounters;
1609 break;
1610 case GL_MAX_IMAGE_UNITS:
1611 *params = mCaps.maxImageUnits;
1612 break;
1613 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1614 *params = mCaps.maxCombinedImageUniforms;
1615 break;
1616 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1617 *params = mCaps.maxShaderStorageBufferBindings;
1618 break;
1619 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1620 *params = mCaps.maxCombinedShaderStorageBlocks;
1621 break;
1622 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1623 *params = mCaps.shaderStorageBufferOffsetAlignment;
1624 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001625
1626 // GL_EXT_geometry_shader
1627 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1628 *params = mCaps.maxFramebufferLayers;
1629 break;
1630 case GL_LAYER_PROVOKING_VERTEX_EXT:
1631 *params = mCaps.layerProvokingVertex;
1632 break;
1633 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1634 *params = mCaps.maxGeometryUniformComponents;
1635 break;
1636 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001637 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001638 break;
1639 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1640 *params = mCaps.maxCombinedGeometryUniformComponents;
1641 break;
1642 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1643 *params = mCaps.maxGeometryInputComponents;
1644 break;
1645 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1646 *params = mCaps.maxGeometryOutputComponents;
1647 break;
1648 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1649 *params = mCaps.maxGeometryOutputVertices;
1650 break;
1651 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1652 *params = mCaps.maxGeometryTotalOutputComponents;
1653 break;
1654 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1655 *params = mCaps.maxGeometryShaderInvocations;
1656 break;
1657 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001658 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001659 break;
1660 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1661 *params = mCaps.maxGeometryAtomicCounterBuffers;
1662 break;
1663 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1664 *params = mCaps.maxGeometryAtomicCounters;
1665 break;
1666 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1667 *params = mCaps.maxGeometryImageUniforms;
1668 break;
1669 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001670 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001671 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001672 // GLES1 emulation: Caps queries
1673 case GL_MAX_TEXTURE_UNITS:
1674 *params = mCaps.maxMultitextureUnits;
1675 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001676 case GL_MAX_MODELVIEW_STACK_DEPTH:
1677 *params = mCaps.maxModelviewMatrixStackDepth;
1678 break;
1679 case GL_MAX_PROJECTION_STACK_DEPTH:
1680 *params = mCaps.maxProjectionMatrixStackDepth;
1681 break;
1682 case GL_MAX_TEXTURE_STACK_DEPTH:
1683 *params = mCaps.maxTextureMatrixStackDepth;
1684 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001685 // GLES1 emulation: Vertex attribute queries
1686 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1687 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1688 case GL_COLOR_ARRAY_BUFFER_BINDING:
1689 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1690 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1691 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1692 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1693 break;
1694 case GL_VERTEX_ARRAY_STRIDE:
1695 case GL_NORMAL_ARRAY_STRIDE:
1696 case GL_COLOR_ARRAY_STRIDE:
1697 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1698 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1699 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1700 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1701 break;
1702 case GL_VERTEX_ARRAY_SIZE:
1703 case GL_COLOR_ARRAY_SIZE:
1704 case GL_TEXTURE_COORD_ARRAY_SIZE:
1705 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1706 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1707 break;
1708 case GL_VERTEX_ARRAY_TYPE:
1709 case GL_COLOR_ARRAY_TYPE:
1710 case GL_NORMAL_ARRAY_TYPE:
1711 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1712 case GL_TEXTURE_COORD_ARRAY_TYPE:
1713 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1714 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1715 break;
1716
Jamie Madill231c7f52017-04-26 13:45:37 -04001717 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001718 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001719 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001720 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001721}
1722
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001723void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001724{
Shannon Woods53a94a82014-06-24 15:20:36 -04001725 // Queries about context capabilities and maximums are answered by Context.
1726 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001727 switch (pname)
1728 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001729 case GL_MAX_ELEMENT_INDEX:
1730 *params = mCaps.maxElementIndex;
1731 break;
1732 case GL_MAX_UNIFORM_BLOCK_SIZE:
1733 *params = mCaps.maxUniformBlockSize;
1734 break;
1735 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1736 *params = mCaps.maxCombinedVertexUniformComponents;
1737 break;
1738 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1739 *params = mCaps.maxCombinedFragmentUniformComponents;
1740 break;
1741 case GL_MAX_SERVER_WAIT_TIMEOUT:
1742 *params = mCaps.maxServerWaitTimeout;
1743 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001744
Jamie Madill231c7f52017-04-26 13:45:37 -04001745 // GL_EXT_disjoint_timer_query
1746 case GL_TIMESTAMP_EXT:
1747 *params = mImplementation->getTimestamp();
1748 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001749
Jamie Madill231c7f52017-04-26 13:45:37 -04001750 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1751 *params = mCaps.maxShaderStorageBlockSize;
1752 break;
1753 default:
1754 UNREACHABLE();
1755 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001756 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001757}
1758
Geoff Lang70d0f492015-12-10 17:45:46 -05001759void Context::getPointerv(GLenum pname, void **params) const
1760{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001761 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001762}
1763
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001764void Context::getPointervRobustANGLERobust(GLenum pname,
1765 GLsizei bufSize,
1766 GLsizei *length,
1767 void **params)
1768{
1769 UNIMPLEMENTED();
1770}
1771
Martin Radev66fb8202016-07-28 11:45:20 +03001772void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001773{
Shannon Woods53a94a82014-06-24 15:20:36 -04001774 // Queries about context capabilities and maximums are answered by Context.
1775 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001776
1777 GLenum nativeType;
1778 unsigned int numParams;
1779 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1780 ASSERT(queryStatus);
1781
1782 if (nativeType == GL_INT)
1783 {
1784 switch (target)
1785 {
1786 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1787 ASSERT(index < 3u);
1788 *data = mCaps.maxComputeWorkGroupCount[index];
1789 break;
1790 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1791 ASSERT(index < 3u);
1792 *data = mCaps.maxComputeWorkGroupSize[index];
1793 break;
1794 default:
1795 mGLState.getIntegeri_v(target, index, data);
1796 }
1797 }
1798 else
1799 {
1800 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1801 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001802}
1803
Brandon Jones59770802018-04-02 13:18:42 -07001804void Context::getIntegeri_vRobust(GLenum target,
1805 GLuint index,
1806 GLsizei bufSize,
1807 GLsizei *length,
1808 GLint *data)
1809{
1810 getIntegeri_v(target, index, data);
1811}
1812
Martin Radev66fb8202016-07-28 11:45:20 +03001813void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001814{
Shannon Woods53a94a82014-06-24 15:20:36 -04001815 // Queries about context capabilities and maximums are answered by Context.
1816 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001817
1818 GLenum nativeType;
1819 unsigned int numParams;
1820 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1821 ASSERT(queryStatus);
1822
1823 if (nativeType == GL_INT_64_ANGLEX)
1824 {
1825 mGLState.getInteger64i_v(target, index, data);
1826 }
1827 else
1828 {
1829 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1830 }
1831}
1832
Brandon Jones59770802018-04-02 13:18:42 -07001833void Context::getInteger64i_vRobust(GLenum target,
1834 GLuint index,
1835 GLsizei bufSize,
1836 GLsizei *length,
1837 GLint64 *data)
1838{
1839 getInteger64i_v(target, index, data);
1840}
1841
Martin Radev66fb8202016-07-28 11:45:20 +03001842void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1843{
1844 // Queries about context capabilities and maximums are answered by Context.
1845 // Queries about current GL state values are answered by State.
1846
1847 GLenum nativeType;
1848 unsigned int numParams;
1849 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1850 ASSERT(queryStatus);
1851
1852 if (nativeType == GL_BOOL)
1853 {
1854 mGLState.getBooleani_v(target, index, data);
1855 }
1856 else
1857 {
1858 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1859 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001860}
1861
Brandon Jones59770802018-04-02 13:18:42 -07001862void Context::getBooleani_vRobust(GLenum target,
1863 GLuint index,
1864 GLsizei bufSize,
1865 GLsizei *length,
1866 GLboolean *data)
1867{
1868 getBooleani_v(target, index, data);
1869}
1870
Corentin Wallez336129f2017-10-17 15:55:40 -04001871void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001872{
1873 Buffer *buffer = mGLState.getTargetBuffer(target);
1874 QueryBufferParameteriv(buffer, pname, params);
1875}
1876
Brandon Jones59770802018-04-02 13:18:42 -07001877void Context::getBufferParameterivRobust(BufferBinding target,
1878 GLenum pname,
1879 GLsizei bufSize,
1880 GLsizei *length,
1881 GLint *params)
1882{
1883 getBufferParameteriv(target, pname, params);
1884}
1885
He Yunchao010e4db2017-03-03 14:22:06 +08001886void Context::getFramebufferAttachmentParameteriv(GLenum target,
1887 GLenum attachment,
1888 GLenum pname,
1889 GLint *params)
1890{
1891 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001892 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001893}
1894
Brandon Jones59770802018-04-02 13:18:42 -07001895void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1896 GLenum attachment,
1897 GLenum pname,
1898 GLsizei bufSize,
1899 GLsizei *length,
1900 GLint *params)
1901{
1902 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1903}
1904
He Yunchao010e4db2017-03-03 14:22:06 +08001905void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1906{
1907 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1908 QueryRenderbufferiv(this, renderbuffer, pname, params);
1909}
1910
Brandon Jones59770802018-04-02 13:18:42 -07001911void Context::getRenderbufferParameterivRobust(GLenum target,
1912 GLenum pname,
1913 GLsizei bufSize,
1914 GLsizei *length,
1915 GLint *params)
1916{
1917 getRenderbufferParameteriv(target, pname, params);
1918}
1919
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001920void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001921{
1922 Texture *texture = getTargetTexture(target);
1923 QueryTexParameterfv(texture, pname, params);
1924}
1925
Brandon Jones59770802018-04-02 13:18:42 -07001926void Context::getTexParameterfvRobust(TextureType target,
1927 GLenum pname,
1928 GLsizei bufSize,
1929 GLsizei *length,
1930 GLfloat *params)
1931{
1932 getTexParameterfv(target, pname, params);
1933}
1934
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001935void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001936{
1937 Texture *texture = getTargetTexture(target);
1938 QueryTexParameteriv(texture, pname, params);
1939}
Jiajia Qin5451d532017-11-16 17:16:34 +08001940
Brandon Jones59770802018-04-02 13:18:42 -07001941void Context::getTexParameterivRobust(TextureType target,
1942 GLenum pname,
1943 GLsizei bufSize,
1944 GLsizei *length,
1945 GLint *params)
1946{
1947 getTexParameteriv(target, pname, params);
1948}
1949
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001950void Context::getTexParameterIivRobust(TextureType target,
1951 GLenum pname,
1952 GLsizei bufSize,
1953 GLsizei *length,
1954 GLint *params)
1955{
1956 UNIMPLEMENTED();
1957}
1958
1959void Context::getTexParameterIuivRobust(TextureType target,
1960 GLenum pname,
1961 GLsizei bufSize,
1962 GLsizei *length,
1963 GLuint *params)
1964{
1965 UNIMPLEMENTED();
1966}
1967
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001968void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001969{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001970 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001971 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001972}
1973
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001974void Context::getTexLevelParameterivRobust(TextureTarget target,
1975 GLint level,
1976 GLenum pname,
1977 GLsizei bufSize,
1978 GLsizei *length,
1979 GLint *params)
1980{
1981 UNIMPLEMENTED();
1982}
1983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001984void Context::getTexLevelParameterfv(TextureTarget target,
1985 GLint level,
1986 GLenum pname,
1987 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001988{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001989 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001990 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001991}
1992
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001993void Context::getTexLevelParameterfvRobust(TextureTarget target,
1994 GLint level,
1995 GLenum pname,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLfloat *params)
1999{
2000 UNIMPLEMENTED();
2001}
2002
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002003void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002006 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002007 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002008}
2009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002010void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002011{
2012 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002013 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002014 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002015}
2016
Brandon Jones59770802018-04-02 13:18:42 -07002017void Context::texParameterfvRobust(TextureType target,
2018 GLenum pname,
2019 GLsizei bufSize,
2020 const GLfloat *params)
2021{
2022 texParameterfv(target, pname, params);
2023}
2024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002025void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002026{
2027 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002028 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002029 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002030}
2031
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002032void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002033{
2034 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002035 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002036 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002037}
2038
Brandon Jones59770802018-04-02 13:18:42 -07002039void Context::texParameterivRobust(TextureType target,
2040 GLenum pname,
2041 GLsizei bufSize,
2042 const GLint *params)
2043{
2044 texParameteriv(target, pname, params);
2045}
2046
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002047void Context::texParameterIivRobust(TextureType target,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 const GLint *params)
2051{
2052 UNIMPLEMENTED();
2053}
2054
2055void Context::texParameterIuivRobust(TextureType target,
2056 GLenum pname,
2057 GLsizei bufSize,
2058 const GLuint *params)
2059{
2060 UNIMPLEMENTED();
2061}
2062
Jamie Madill493f9572018-05-24 19:52:15 -04002063void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002064{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002065 // No-op if zero count
2066 if (count == 0)
2067 {
2068 return;
2069 }
2070
Jamie Madill05b35b22017-10-03 09:01:44 -04002071 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002072 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002073 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002074}
2075
Jamie Madill493f9572018-05-24 19:52:15 -04002076void Context::drawArraysInstanced(PrimitiveMode mode,
2077 GLint first,
2078 GLsizei count,
2079 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002080{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002081 // No-op if zero count
2082 if (count == 0 || instanceCount == 0)
2083 {
2084 return;
2085 }
2086
Jamie Madill05b35b22017-10-03 09:01:44 -04002087 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002088 ANGLE_CONTEXT_TRY(
2089 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002090 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2091 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002092}
2093
Jamie Madill493f9572018-05-24 19:52:15 -04002094void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002095{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002096 // No-op if zero count
2097 if (count == 0)
2098 {
2099 return;
2100 }
2101
Jamie Madill05b35b22017-10-03 09:01:44 -04002102 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002103 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002104}
2105
Jamie Madill493f9572018-05-24 19:52:15 -04002106void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002107 GLsizei count,
2108 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002109 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002110 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002111{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002112 // No-op if zero count
2113 if (count == 0 || instances == 0)
2114 {
2115 return;
2116 }
2117
Jamie Madill05b35b22017-10-03 09:01:44 -04002118 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002119 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002120 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002121}
2122
Jamie Madill493f9572018-05-24 19:52:15 -04002123void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002124 GLuint start,
2125 GLuint end,
2126 GLsizei count,
2127 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002128 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002129{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002130 // No-op if zero count
2131 if (count == 0)
2132 {
2133 return;
2134 }
2135
Jamie Madill05b35b22017-10-03 09:01:44 -04002136 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002137 ANGLE_CONTEXT_TRY(
2138 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002139}
2140
Jamie Madill493f9572018-05-24 19:52:15 -04002141void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002142{
Jamie Madill05b35b22017-10-03 09:01:44 -04002143 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002144 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002145}
2146
Jamie Madill493f9572018-05-24 19:52:15 -04002147void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002148{
Jamie Madill05b35b22017-10-03 09:01:44 -04002149 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002150 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002151}
2152
Jamie Madill675fe712016-12-19 13:07:54 -05002153void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002154{
Jamie Madillafa02a22017-11-23 12:57:38 -05002155 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002156}
2157
Jamie Madill675fe712016-12-19 13:07:54 -05002158void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002159{
Jamie Madillafa02a22017-11-23 12:57:38 -05002160 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002161}
2162
Austin Kinross6ee1e782015-05-29 17:05:37 -07002163void Context::insertEventMarker(GLsizei length, const char *marker)
2164{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002165 ASSERT(mImplementation);
2166 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002167}
2168
2169void Context::pushGroupMarker(GLsizei length, const char *marker)
2170{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002171 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002172
2173 if (marker == nullptr)
2174 {
2175 // From the EXT_debug_marker spec,
2176 // "If <marker> is null then an empty string is pushed on the stack."
2177 mImplementation->pushGroupMarker(length, "");
2178 }
2179 else
2180 {
2181 mImplementation->pushGroupMarker(length, marker);
2182 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002183}
2184
2185void Context::popGroupMarker()
2186{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002187 ASSERT(mImplementation);
2188 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002189}
2190
Geoff Langd8605522016-04-13 10:19:12 -04002191void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2192{
2193 Program *programObject = getProgram(program);
2194 ASSERT(programObject);
2195
2196 programObject->bindUniformLocation(location, name);
2197}
2198
Brandon Jones59770802018-04-02 13:18:42 -07002199void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002200{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002201 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002202}
2203
Brandon Jones59770802018-04-02 13:18:42 -07002204void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002205{
2206 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2207}
2208
Brandon Jones59770802018-04-02 13:18:42 -07002209void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002210{
2211 GLfloat I[16];
2212 angle::Matrix<GLfloat>::setToIdentity(I);
2213
2214 mGLState.loadPathRenderingMatrix(matrixMode, I);
2215}
2216
2217void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2218{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002219 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002220 if (!pathObj)
2221 return;
2222
2223 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002224 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002225
2226 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2227}
2228
2229void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2230{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002231 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002232 if (!pathObj)
2233 return;
2234
2235 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002236 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002237
2238 mImplementation->stencilStrokePath(pathObj, reference, mask);
2239}
2240
2241void Context::coverFillPath(GLuint path, GLenum coverMode)
2242{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002243 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002244 if (!pathObj)
2245 return;
2246
2247 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002248 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002249
2250 mImplementation->coverFillPath(pathObj, coverMode);
2251}
2252
2253void Context::coverStrokePath(GLuint path, GLenum coverMode)
2254{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002255 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002256 if (!pathObj)
2257 return;
2258
2259 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002260 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002261
2262 mImplementation->coverStrokePath(pathObj, coverMode);
2263}
2264
2265void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2266{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002267 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002268 if (!pathObj)
2269 return;
2270
2271 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002272 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002273
2274 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2275}
2276
2277void Context::stencilThenCoverStrokePath(GLuint path,
2278 GLint reference,
2279 GLuint mask,
2280 GLenum coverMode)
2281{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002282 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002283 if (!pathObj)
2284 return;
2285
2286 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002287 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002288
2289 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2290}
2291
Sami Väisänend59ca052016-06-21 16:10:00 +03002292void Context::coverFillPathInstanced(GLsizei numPaths,
2293 GLenum pathNameType,
2294 const void *paths,
2295 GLuint pathBase,
2296 GLenum coverMode,
2297 GLenum transformType,
2298 const GLfloat *transformValues)
2299{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002300 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002301
2302 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002303 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002304
2305 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2306}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002307
Sami Väisänend59ca052016-06-21 16:10:00 +03002308void Context::coverStrokePathInstanced(GLsizei numPaths,
2309 GLenum pathNameType,
2310 const void *paths,
2311 GLuint pathBase,
2312 GLenum coverMode,
2313 GLenum transformType,
2314 const GLfloat *transformValues)
2315{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002316 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002317
2318 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002319 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002320
2321 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2322 transformValues);
2323}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002324
Sami Väisänend59ca052016-06-21 16:10:00 +03002325void Context::stencilFillPathInstanced(GLsizei numPaths,
2326 GLenum pathNameType,
2327 const void *paths,
2328 GLuint pathBase,
2329 GLenum fillMode,
2330 GLuint mask,
2331 GLenum transformType,
2332 const GLfloat *transformValues)
2333{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002334 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002335
2336 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002337 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002338
2339 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2340 transformValues);
2341}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002342
Sami Väisänend59ca052016-06-21 16:10:00 +03002343void Context::stencilStrokePathInstanced(GLsizei numPaths,
2344 GLenum pathNameType,
2345 const void *paths,
2346 GLuint pathBase,
2347 GLint reference,
2348 GLuint mask,
2349 GLenum transformType,
2350 const GLfloat *transformValues)
2351{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002352 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002353
2354 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002355 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002356
2357 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2358 transformValues);
2359}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002360
Sami Väisänend59ca052016-06-21 16:10:00 +03002361void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2362 GLenum pathNameType,
2363 const void *paths,
2364 GLuint pathBase,
2365 GLenum fillMode,
2366 GLuint mask,
2367 GLenum coverMode,
2368 GLenum transformType,
2369 const GLfloat *transformValues)
2370{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002371 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002372
2373 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002374 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002375
2376 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2377 transformType, transformValues);
2378}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002379
Sami Väisänend59ca052016-06-21 16:10:00 +03002380void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2381 GLenum pathNameType,
2382 const void *paths,
2383 GLuint pathBase,
2384 GLint reference,
2385 GLuint mask,
2386 GLenum coverMode,
2387 GLenum transformType,
2388 const GLfloat *transformValues)
2389{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002390 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002391
2392 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002393 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002394
2395 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2396 transformType, transformValues);
2397}
2398
Sami Väisänen46eaa942016-06-29 10:26:37 +03002399void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2400{
2401 auto *programObject = getProgram(program);
2402
2403 programObject->bindFragmentInputLocation(location, name);
2404}
2405
2406void Context::programPathFragmentInputGen(GLuint program,
2407 GLint location,
2408 GLenum genMode,
2409 GLint components,
2410 const GLfloat *coeffs)
2411{
2412 auto *programObject = getProgram(program);
2413
Jamie Madillbd044ed2017-06-05 12:59:21 -04002414 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002415}
2416
jchen1015015f72017-03-16 13:54:21 +08002417GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2418{
jchen10fd7c3b52017-03-21 15:36:03 +08002419 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002420 return QueryProgramResourceIndex(programObject, programInterface, name);
2421}
2422
jchen10fd7c3b52017-03-21 15:36:03 +08002423void Context::getProgramResourceName(GLuint program,
2424 GLenum programInterface,
2425 GLuint index,
2426 GLsizei bufSize,
2427 GLsizei *length,
2428 GLchar *name)
2429{
2430 const auto *programObject = getProgram(program);
2431 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2432}
2433
jchen10191381f2017-04-11 13:59:04 +08002434GLint Context::getProgramResourceLocation(GLuint program,
2435 GLenum programInterface,
2436 const GLchar *name)
2437{
2438 const auto *programObject = getProgram(program);
2439 return QueryProgramResourceLocation(programObject, programInterface, name);
2440}
2441
jchen10880683b2017-04-12 16:21:55 +08002442void Context::getProgramResourceiv(GLuint program,
2443 GLenum programInterface,
2444 GLuint index,
2445 GLsizei propCount,
2446 const GLenum *props,
2447 GLsizei bufSize,
2448 GLsizei *length,
2449 GLint *params)
2450{
2451 const auto *programObject = getProgram(program);
2452 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2453 length, params);
2454}
2455
jchen10d9cd7b72017-08-30 15:04:25 +08002456void Context::getProgramInterfaceiv(GLuint program,
2457 GLenum programInterface,
2458 GLenum pname,
2459 GLint *params)
2460{
2461 const auto *programObject = getProgram(program);
2462 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2463}
2464
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002465void Context::getProgramInterfaceivRobust(GLuint program,
2466 GLenum programInterface,
2467 GLenum pname,
2468 GLsizei bufSize,
2469 GLsizei *length,
2470 GLint *params)
2471{
2472 UNIMPLEMENTED();
2473}
2474
Jamie Madill427064d2018-04-13 16:20:34 -04002475void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002476{
Geoff Lang7b19a492018-04-20 09:31:52 -04002477 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002478 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002479 GLenum code = error.getCode();
2480 mErrors.insert(code);
2481 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2482 {
2483 markContextLost();
2484 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002485
Geoff Langee6884e2017-11-09 16:51:11 -05002486 ASSERT(!error.getMessage().empty());
2487 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2488 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002489 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490}
2491
2492// Get one of the recorded errors and clear its flag, if any.
2493// [OpenGL ES 2.0.24] section 2.5 page 13.
2494GLenum Context::getError()
2495{
Geoff Langda5777c2014-07-11 09:52:58 -04002496 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002497 {
Geoff Langda5777c2014-07-11 09:52:58 -04002498 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499 }
Geoff Langda5777c2014-07-11 09:52:58 -04002500 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501 {
Geoff Langda5777c2014-07-11 09:52:58 -04002502 GLenum error = *mErrors.begin();
2503 mErrors.erase(mErrors.begin());
2504 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002506}
2507
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002508// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002509void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510{
2511 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002512 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002513 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002514 mContextLostForced = true;
2515 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002516 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002517}
2518
Jamie Madill427064d2018-04-13 16:20:34 -04002519bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002520{
2521 return mContextLost;
2522}
2523
Jamie Madillfa920eb2018-01-04 11:45:50 -05002524GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002526 // Even if the application doesn't want to know about resets, we want to know
2527 // as it will allow us to skip all the calls.
2528 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002531 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002532 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002533 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002534
2535 // EXT_robustness, section 2.6: If the reset notification behavior is
2536 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2537 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2538 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002539 }
2540
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002541 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2542 // status should be returned at least once, and GL_NO_ERROR should be returned
2543 // once the device has finished resetting.
2544 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002545 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002546 ASSERT(mResetStatus == GL_NO_ERROR);
2547 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002548
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002549 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002550 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002551 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002552 }
2553 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002554 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002556 // If markContextLost was used to mark the context lost then
2557 // assume that is not recoverable, and continue to report the
2558 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002559 mResetStatus = mImplementation->getResetStatus();
2560 }
Jamie Madill893ab082014-05-16 16:56:10 -04002561
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002562 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002563}
2564
2565bool Context::isResetNotificationEnabled()
2566{
2567 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2568}
2569
Corentin Walleze3b10e82015-05-20 11:06:25 -04002570const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002571{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002572 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002573}
2574
2575EGLenum Context::getClientType() const
2576{
2577 return mClientType;
2578}
2579
2580EGLenum Context::getRenderBuffer() const
2581{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002582 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2583 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002584 {
2585 return EGL_NONE;
2586 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002587
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002588 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002589 ASSERT(backAttachment != nullptr);
2590 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002591}
2592
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002593VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002594{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002595 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002596 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2597 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002598 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002599 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2600 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002601
Jamie Madill96a483b2017-06-27 16:49:21 -04002602 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002603 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002604
2605 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002606}
2607
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002608TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002609{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002610 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002611 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2612 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002613 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002614 transformFeedback =
2615 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002616 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002617 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002618 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002619
2620 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002621}
2622
2623bool Context::isVertexArrayGenerated(GLuint vertexArray)
2624{
Jamie Madill96a483b2017-06-27 16:49:21 -04002625 ASSERT(mVertexArrayMap.contains(0));
2626 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002627}
2628
2629bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2630{
Jamie Madill96a483b2017-06-27 16:49:21 -04002631 ASSERT(mTransformFeedbackMap.contains(0));
2632 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002633}
2634
Shannon Woods53a94a82014-06-24 15:20:36 -04002635void Context::detachTexture(GLuint texture)
2636{
2637 // Simple pass-through to State's detachTexture method, as textures do not require
2638 // allocation map management either here or in the resource manager at detach time.
2639 // Zero textures are held by the Context, and we don't attempt to request them from
2640 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002641 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002642}
2643
James Darpinian4d9d4832018-03-13 12:43:28 -07002644void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645{
Yuly Novikov5807a532015-12-03 13:01:22 -05002646 // Simple pass-through to State's detachBuffer method, since
2647 // only buffer attachments to container objects that are bound to the current context
2648 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002649
Yuly Novikov5807a532015-12-03 13:01:22 -05002650 // [OpenGL ES 3.2] section 5.1.2 page 45:
2651 // Attachments to unbound container objects, such as
2652 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2653 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002654 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002655}
2656
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002657void Context::detachFramebuffer(GLuint framebuffer)
2658{
Shannon Woods53a94a82014-06-24 15:20:36 -04002659 // Framebuffer detachment is handled by Context, because 0 is a valid
2660 // Framebuffer object, and a pointer to it must be passed from Context
2661 // to State at binding time.
2662
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002664 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2665 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2666 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002668 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002669 {
2670 bindReadFramebuffer(0);
2671 }
2672
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002673 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002674 {
2675 bindDrawFramebuffer(0);
2676 }
2677}
2678
2679void Context::detachRenderbuffer(GLuint renderbuffer)
2680{
Jamie Madilla02315b2017-02-23 14:14:47 -05002681 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002682}
2683
Jamie Madill57a89722013-07-02 11:57:03 -04002684void Context::detachVertexArray(GLuint vertexArray)
2685{
Jamie Madill77a72f62015-04-14 11:18:32 -04002686 // Vertex array detachment is handled by Context, because 0 is a valid
2687 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002688 // binding time.
2689
Jamie Madill57a89722013-07-02 11:57:03 -04002690 // [OpenGL ES 3.0.2] section 2.10 page 43:
2691 // If a vertex array object that is currently bound is deleted, the binding
2692 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002693 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002694 {
2695 bindVertexArray(0);
2696 }
2697}
2698
Geoff Langc8058452014-02-03 12:04:11 -05002699void Context::detachTransformFeedback(GLuint transformFeedback)
2700{
Corentin Walleza2257da2016-04-19 16:43:12 -04002701 // Transform feedback detachment is handled by Context, because 0 is a valid
2702 // transform feedback, and a pointer to it must be passed from Context to State at
2703 // binding time.
2704
2705 // The OpenGL specification doesn't mention what should happen when the currently bound
2706 // transform feedback object is deleted. Since it is a container object, we treat it like
2707 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002708 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002709 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002710 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002711 }
Geoff Langc8058452014-02-03 12:04:11 -05002712}
2713
Jamie Madilldc356042013-07-19 16:36:57 -04002714void Context::detachSampler(GLuint sampler)
2715{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002716 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002717}
2718
Yunchao Hea336b902017-08-02 16:05:21 +08002719void Context::detachProgramPipeline(GLuint pipeline)
2720{
2721 mGLState.detachProgramPipeline(this, pipeline);
2722}
2723
Jamie Madill3ef140a2017-08-26 23:11:21 -04002724void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002725{
Shaodde78e82017-05-22 14:13:27 +08002726 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002727}
2728
Jamie Madille29d1672013-07-19 16:36:57 -04002729void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2730{
Geoff Langc1984ed2016-10-07 12:41:00 -04002731 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002732 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002733 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002734 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002735}
Jamie Madille29d1672013-07-19 16:36:57 -04002736
Geoff Langc1984ed2016-10-07 12:41:00 -04002737void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2738{
2739 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002740 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002741 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002742 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002743}
2744
Brandon Jones59770802018-04-02 13:18:42 -07002745void Context::samplerParameterivRobust(GLuint sampler,
2746 GLenum pname,
2747 GLsizei bufSize,
2748 const GLint *param)
2749{
2750 samplerParameteriv(sampler, pname, param);
2751}
2752
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002753void Context::samplerParameterIivRobust(GLuint sampler,
2754 GLenum pname,
2755 GLsizei bufSize,
2756 const GLint *param)
2757{
2758 UNIMPLEMENTED();
2759}
2760
2761void Context::samplerParameterIuivRobust(GLuint sampler,
2762 GLenum pname,
2763 GLsizei bufSize,
2764 const GLuint *param)
2765{
2766 UNIMPLEMENTED();
2767}
2768
Jamie Madille29d1672013-07-19 16:36:57 -04002769void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2770{
Geoff Langc1984ed2016-10-07 12:41:00 -04002771 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002772 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002773 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002774 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002775}
2776
Geoff Langc1984ed2016-10-07 12:41:00 -04002777void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002778{
Geoff Langc1984ed2016-10-07 12:41:00 -04002779 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002780 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002781 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002782 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002783}
2784
Brandon Jones59770802018-04-02 13:18:42 -07002785void Context::samplerParameterfvRobust(GLuint sampler,
2786 GLenum pname,
2787 GLsizei bufSize,
2788 const GLfloat *param)
2789{
2790 samplerParameterfv(sampler, pname, param);
2791}
2792
Geoff Langc1984ed2016-10-07 12:41:00 -04002793void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002794{
Geoff Langc1984ed2016-10-07 12:41:00 -04002795 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002796 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002797 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002798 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002799}
Jamie Madill9675b802013-07-19 16:36:59 -04002800
Brandon Jones59770802018-04-02 13:18:42 -07002801void Context::getSamplerParameterivRobust(GLuint sampler,
2802 GLenum pname,
2803 GLsizei bufSize,
2804 GLsizei *length,
2805 GLint *params)
2806{
2807 getSamplerParameteriv(sampler, pname, params);
2808}
2809
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002810void Context::getSamplerParameterIivRobust(GLuint sampler,
2811 GLenum pname,
2812 GLsizei bufSize,
2813 GLsizei *length,
2814 GLint *params)
2815{
2816 UNIMPLEMENTED();
2817}
2818
2819void Context::getSamplerParameterIuivRobust(GLuint sampler,
2820 GLenum pname,
2821 GLsizei bufSize,
2822 GLsizei *length,
2823 GLuint *params)
2824{
2825 UNIMPLEMENTED();
2826}
2827
Geoff Langc1984ed2016-10-07 12:41:00 -04002828void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2829{
2830 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002831 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002832 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002833 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002834}
2835
Brandon Jones59770802018-04-02 13:18:42 -07002836void Context::getSamplerParameterfvRobust(GLuint sampler,
2837 GLenum pname,
2838 GLsizei bufSize,
2839 GLsizei *length,
2840 GLfloat *params)
2841{
2842 getSamplerParameterfv(sampler, pname, params);
2843}
2844
Olli Etuahof0fee072016-03-30 15:11:58 +03002845void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2846{
2847 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002848 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002849}
2850
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002851void Context::initRendererString()
2852{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002853 std::ostringstream rendererString;
2854 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002855 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002856 rendererString << ")";
2857
Geoff Langcec35902014-04-16 10:52:36 -04002858 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002859}
2860
Geoff Langc339c4e2016-11-29 10:37:36 -05002861void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002862{
Geoff Langc339c4e2016-11-29 10:37:36 -05002863 const Version &clientVersion = getClientVersion();
2864
2865 std::ostringstream versionString;
2866 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2867 << ANGLE_VERSION_STRING << ")";
2868 mVersionString = MakeStaticString(versionString.str());
2869
2870 std::ostringstream shadingLanguageVersionString;
2871 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2872 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2873 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2874 << ")";
2875 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002876}
2877
Geoff Langcec35902014-04-16 10:52:36 -04002878void Context::initExtensionStrings()
2879{
Geoff Langc339c4e2016-11-29 10:37:36 -05002880 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2881 std::ostringstream combinedStringStream;
2882 std::copy(strings.begin(), strings.end(),
2883 std::ostream_iterator<const char *>(combinedStringStream, " "));
2884 return MakeStaticString(combinedStringStream.str());
2885 };
2886
2887 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002888 for (const auto &extensionString : mExtensions.getStrings())
2889 {
2890 mExtensionStrings.push_back(MakeStaticString(extensionString));
2891 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002892 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002893
Geoff Langc339c4e2016-11-29 10:37:36 -05002894 mRequestableExtensionStrings.clear();
2895 for (const auto &extensionInfo : GetExtensionInfoMap())
2896 {
2897 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002898 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002899 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002900 {
2901 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2902 }
2903 }
2904 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002905}
2906
Geoff Langc339c4e2016-11-29 10:37:36 -05002907const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002908{
Geoff Langc339c4e2016-11-29 10:37:36 -05002909 switch (name)
2910 {
2911 case GL_VENDOR:
2912 return reinterpret_cast<const GLubyte *>("Google Inc.");
2913
2914 case GL_RENDERER:
2915 return reinterpret_cast<const GLubyte *>(mRendererString);
2916
2917 case GL_VERSION:
2918 return reinterpret_cast<const GLubyte *>(mVersionString);
2919
2920 case GL_SHADING_LANGUAGE_VERSION:
2921 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2922
2923 case GL_EXTENSIONS:
2924 return reinterpret_cast<const GLubyte *>(mExtensionString);
2925
2926 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2927 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2928
2929 default:
2930 UNREACHABLE();
2931 return nullptr;
2932 }
Geoff Langcec35902014-04-16 10:52:36 -04002933}
2934
Geoff Langc339c4e2016-11-29 10:37:36 -05002935const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002936{
Geoff Langc339c4e2016-11-29 10:37:36 -05002937 switch (name)
2938 {
2939 case GL_EXTENSIONS:
2940 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2941
2942 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2943 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2944
2945 default:
2946 UNREACHABLE();
2947 return nullptr;
2948 }
Geoff Langcec35902014-04-16 10:52:36 -04002949}
2950
2951size_t Context::getExtensionStringCount() const
2952{
2953 return mExtensionStrings.size();
2954}
2955
Geoff Lang111a99e2017-10-17 10:58:41 -04002956bool Context::isExtensionRequestable(const char *name)
2957{
2958 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2959 auto extension = extensionInfos.find(name);
2960
Geoff Lang111a99e2017-10-17 10:58:41 -04002961 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002962 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002963}
2964
Geoff Langc339c4e2016-11-29 10:37:36 -05002965void Context::requestExtension(const char *name)
2966{
2967 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2968 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2969 const auto &extension = extensionInfos.at(name);
2970 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002971 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002972
2973 if (mExtensions.*(extension.ExtensionsMember))
2974 {
2975 // Extension already enabled
2976 return;
2977 }
2978
2979 mExtensions.*(extension.ExtensionsMember) = true;
2980 updateCaps();
2981 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002982
Jamie Madill2f348d22017-06-05 10:50:59 -04002983 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2984 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002985
Jamie Madill81c2e252017-09-09 23:32:46 -04002986 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2987 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002988 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002989 for (auto &zeroTexture : mZeroTextures)
2990 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002991 if (zeroTexture.get() != nullptr)
2992 {
2993 zeroTexture->signalDirty(this, InitState::Initialized);
2994 }
Geoff Lang9aded172017-04-05 11:07:56 -04002995 }
2996
2997 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002998}
2999
3000size_t Context::getRequestableExtensionStringCount() const
3001{
3002 return mRequestableExtensionStrings.size();
3003}
3004
Jamie Madill493f9572018-05-24 19:52:15 -04003005void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003006{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003007 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003008 ASSERT(transformFeedback != nullptr);
3009 ASSERT(!transformFeedback->isPaused());
3010
Jamie Madill6c1f6712017-02-14 19:08:04 -05003011 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003012}
3013
3014bool Context::hasActiveTransformFeedback(GLuint program) const
3015{
3016 for (auto pair : mTransformFeedbackMap)
3017 {
3018 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3019 {
3020 return true;
3021 }
3022 }
3023 return false;
3024}
3025
Geoff Langb0f917f2017-12-05 13:41:54 -05003026Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003027 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003028 bool robustResourceInit) const
3029{
3030 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3031
3032 if (getClientVersion() < ES_2_0)
3033 {
3034 // Default extensions for GLES1
3035 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003036 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003037 }
3038
3039 if (getClientVersion() < ES_3_0)
3040 {
3041 // Disable ES3+ extensions
3042 supportedExtensions.colorBufferFloat = false;
3043 supportedExtensions.eglImageExternalEssl3 = false;
3044 supportedExtensions.textureNorm16 = false;
3045 supportedExtensions.multiview = false;
3046 supportedExtensions.maxViews = 1u;
3047 }
3048
3049 if (getClientVersion() < ES_3_1)
3050 {
3051 // Disable ES3.1+ extensions
3052 supportedExtensions.geometryShader = false;
3053 }
3054
3055 if (getClientVersion() > ES_2_0)
3056 {
3057 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3058 // supportedExtensions.sRGB = false;
3059 }
3060
3061 // Some extensions are always available because they are implemented in the GL layer.
3062 supportedExtensions.bindUniformLocation = true;
3063 supportedExtensions.vertexArrayObject = true;
3064 supportedExtensions.bindGeneratesResource = true;
3065 supportedExtensions.clientArrays = true;
3066 supportedExtensions.requestExtension = true;
3067
3068 // Enable the no error extension if the context was created with the flag.
3069 supportedExtensions.noError = mSkipValidation;
3070
3071 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3072 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3073
3074 // Explicitly enable GL_KHR_debug
3075 supportedExtensions.debug = true;
3076 supportedExtensions.maxDebugMessageLength = 1024;
3077 supportedExtensions.maxDebugLoggedMessages = 1024;
3078 supportedExtensions.maxDebugGroupStackDepth = 1024;
3079 supportedExtensions.maxLabelLength = 1024;
3080
3081 // Explicitly enable GL_ANGLE_robust_client_memory
3082 supportedExtensions.robustClientMemory = true;
3083
3084 // Determine robust resource init availability from EGL.
3085 supportedExtensions.robustResourceInitialization = robustResourceInit;
3086
3087 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3088 // supports it.
3089 supportedExtensions.robustBufferAccessBehavior =
3090 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3091
3092 // Enable the cache control query unconditionally.
3093 supportedExtensions.programCacheControl = true;
3094
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003095 // Enable EGL_ANGLE_explicit_context subextensions
3096 if (clientExtensions.explicitContext)
3097 {
3098 // GL_ANGLE_explicit_context_gles1
3099 supportedExtensions.explicitContextGles1 = true;
3100 // GL_ANGLE_explicit_context
3101 supportedExtensions.explicitContext = true;
3102 }
3103
Geoff Langb0f917f2017-12-05 13:41:54 -05003104 return supportedExtensions;
3105}
3106
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003107void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3108 const egl::ClientExtensions &clientExtensions,
3109 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003110{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003111 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003112
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003113 mSupportedExtensions =
3114 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Jamie Madill493f9572018-05-24 19:52:15 -04003115 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003116
3117 mLimitations = mImplementation->getNativeLimitations();
3118
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003119 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3120 if (getClientVersion() < Version(2, 0))
3121 {
3122 mCaps.maxMultitextureUnits = 4;
3123 mCaps.maxClipPlanes = 6;
3124 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003125 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3126 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3127 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003128 }
3129
Geoff Lang301d1612014-07-09 10:34:37 -04003130 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003131 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003132
Jamie Madill0f80ed82017-09-19 00:24:56 -04003133 if (getClientVersion() < ES_3_1)
3134 {
3135 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3136 }
3137 else
3138 {
3139 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3140 }
Geoff Lang301d1612014-07-09 10:34:37 -04003141
Jiawei Shao54aafe52018-04-27 14:54:57 +08003142 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3143 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003144 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3145 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3146
3147 // Limit textures as well, so we can use fast bitsets with texture bindings.
3148 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003149 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3150 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3151 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3152 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003153
Jiawei Shaodb342272017-09-27 10:21:45 +08003154 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3155
Geoff Langc287ea62016-09-16 14:46:51 -04003156 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003157 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003158 for (const auto &extensionInfo : GetExtensionInfoMap())
3159 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003160 // If the user has requested that extensions start disabled and they are requestable,
3161 // disable them.
3162 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003163 {
3164 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3165 }
3166 }
3167
3168 // Generate texture caps
3169 updateCaps();
3170}
3171
3172void Context::updateCaps()
3173{
Geoff Lang900013c2014-07-07 11:32:19 -04003174 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003175 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003176
Jamie Madill7b62cf92017-11-02 15:20:49 -04003177 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003178 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003179 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003180 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003181
Geoff Lang0d8b7242015-09-09 14:56:53 -04003182 // Update the format caps based on the client version and extensions.
3183 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3184 // ES3.
3185 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003186 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003187 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003188 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003189 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003190 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003191
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003192 // OpenGL ES does not support multisampling with non-rendererable formats
3193 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003194 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003195 (getClientVersion() < ES_3_1 &&
3196 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003197 {
Geoff Langd87878e2014-09-19 15:42:59 -04003198 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003199 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003200 else
3201 {
3202 // We may have limited the max samples for some required renderbuffer formats due to
3203 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3204 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3205
3206 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3207 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3208 // exception of signed and unsigned integer formats."
3209 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3210 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3211 {
3212 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3213 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3214 }
3215
3216 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3217 if (getClientVersion() >= ES_3_1)
3218 {
3219 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3220 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3221 // the exception that the signed and unsigned integer formats are required only to
3222 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3223 // multisamples, which must be at least one."
3224 if (formatInfo.componentType == GL_INT ||
3225 formatInfo.componentType == GL_UNSIGNED_INT)
3226 {
3227 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3228 }
3229
3230 // GLES 3.1 section 19.3.1.
3231 if (formatCaps.texturable)
3232 {
3233 if (formatInfo.depthBits > 0)
3234 {
3235 mCaps.maxDepthTextureSamples =
3236 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3237 }
3238 else if (formatInfo.redBits > 0)
3239 {
3240 mCaps.maxColorTextureSamples =
3241 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3242 }
3243 }
3244 }
3245 }
Geoff Langd87878e2014-09-19 15:42:59 -04003246
3247 if (formatCaps.texturable && formatInfo.compressed)
3248 {
Geoff Langca271392017-04-05 12:30:00 -04003249 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003250 }
3251
Geoff Langca271392017-04-05 12:30:00 -04003252 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003253 }
Jamie Madill32447362017-06-28 14:53:52 -04003254
3255 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003256 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003257 {
3258 mMemoryProgramCache = nullptr;
3259 }
Corentin Walleze4477002017-12-01 14:39:58 -05003260
3261 // Compute which buffer types are allowed
3262 mValidBufferBindings.reset();
3263 mValidBufferBindings.set(BufferBinding::ElementArray);
3264 mValidBufferBindings.set(BufferBinding::Array);
3265
3266 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3267 {
3268 mValidBufferBindings.set(BufferBinding::PixelPack);
3269 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3270 }
3271
3272 if (getClientVersion() >= ES_3_0)
3273 {
3274 mValidBufferBindings.set(BufferBinding::CopyRead);
3275 mValidBufferBindings.set(BufferBinding::CopyWrite);
3276 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3277 mValidBufferBindings.set(BufferBinding::Uniform);
3278 }
3279
3280 if (getClientVersion() >= ES_3_1)
3281 {
3282 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3283 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3284 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3285 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3286 }
Geoff Lang493daf52014-07-03 13:38:44 -04003287}
3288
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003289void Context::initWorkarounds()
3290{
Jamie Madill761b02c2017-06-23 16:27:06 -04003291 // Apply back-end workarounds.
3292 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3293
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003294 // Lose the context upon out of memory error if the application is
3295 // expecting to watch for those events.
3296 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3297}
3298
Jamie Madill05b35b22017-10-03 09:01:44 -04003299Error Context::prepareForDraw()
3300{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003301 if (mGLES1Renderer)
3302 {
3303 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3304 }
3305
Geoff Langa8cb2872018-03-09 16:09:40 -05003306 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003307
3308 if (isRobustResourceInitEnabled())
3309 {
3310 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3311 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3312 }
3313
Geoff Langa8cb2872018-03-09 16:09:40 -05003314 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003315 return NoError();
3316}
3317
3318Error Context::prepareForClear(GLbitfield mask)
3319{
Geoff Langa8cb2872018-03-09 16:09:40 -05003320 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003321 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003322 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003323 return NoError();
3324}
3325
3326Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3327{
Geoff Langa8cb2872018-03-09 16:09:40 -05003328 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003329 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3330 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003331 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003332 return NoError();
3333}
3334
Geoff Langa8cb2872018-03-09 16:09:40 -05003335Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003336{
Geoff Langa8cb2872018-03-09 16:09:40 -05003337 ANGLE_TRY(syncDirtyObjects());
3338 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003339 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003340}
3341
Geoff Langa8cb2872018-03-09 16:09:40 -05003342Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003343{
Geoff Langa8cb2872018-03-09 16:09:40 -05003344 ANGLE_TRY(syncDirtyObjects(objectMask));
3345 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003346 return NoError();
3347}
3348
Geoff Langa8cb2872018-03-09 16:09:40 -05003349Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003350{
3351 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3352 mImplementation->syncState(this, dirtyBits);
3353 mGLState.clearDirtyBits();
3354 return NoError();
3355}
3356
Geoff Langa8cb2872018-03-09 16:09:40 -05003357Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003359 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003360 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003361 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003362 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003363}
Jamie Madillc29968b2016-01-20 11:17:23 -05003364
Geoff Langa8cb2872018-03-09 16:09:40 -05003365Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003366{
3367 return mGLState.syncDirtyObjects(this);
3368}
3369
Geoff Langa8cb2872018-03-09 16:09:40 -05003370Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003371{
3372 return mGLState.syncDirtyObjects(this, objectMask);
3373}
3374
Jamie Madillc29968b2016-01-20 11:17:23 -05003375void Context::blitFramebuffer(GLint srcX0,
3376 GLint srcY0,
3377 GLint srcX1,
3378 GLint srcY1,
3379 GLint dstX0,
3380 GLint dstY0,
3381 GLint dstX1,
3382 GLint dstY1,
3383 GLbitfield mask,
3384 GLenum filter)
3385{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003386 if (mask == 0)
3387 {
3388 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3389 // buffers are copied.
3390 return;
3391 }
3392
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003393 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003394 ASSERT(drawFramebuffer);
3395
3396 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3397 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3398
Jamie Madillbc918e72018-03-08 09:47:21 -05003399 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003400
Jamie Madillc564c072017-06-01 12:45:42 -04003401 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003402}
Jamie Madillc29968b2016-01-20 11:17:23 -05003403
3404void Context::clear(GLbitfield mask)
3405{
Geoff Langd4fff502017-09-22 11:28:28 -04003406 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3407 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003408}
3409
3410void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3411{
Geoff Langd4fff502017-09-22 11:28:28 -04003412 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3413 ANGLE_CONTEXT_TRY(
3414 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003415}
3416
3417void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3418{
Geoff Langd4fff502017-09-22 11:28:28 -04003419 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3420 ANGLE_CONTEXT_TRY(
3421 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003422}
3423
3424void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3425{
Geoff Langd4fff502017-09-22 11:28:28 -04003426 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3427 ANGLE_CONTEXT_TRY(
3428 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003429}
3430
3431void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003433 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003434 ASSERT(framebufferObject);
3435
3436 // If a buffer is not present, the clear has no effect
3437 if (framebufferObject->getDepthbuffer() == nullptr &&
3438 framebufferObject->getStencilbuffer() == nullptr)
3439 {
3440 return;
3441 }
3442
Geoff Langd4fff502017-09-22 11:28:28 -04003443 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3444 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003445}
3446
3447void Context::readPixels(GLint x,
3448 GLint y,
3449 GLsizei width,
3450 GLsizei height,
3451 GLenum format,
3452 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003453 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003454{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003455 if (width == 0 || height == 0)
3456 {
3457 return;
3458 }
3459
Jamie Madillbc918e72018-03-08 09:47:21 -05003460 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003461
Jamie Madillb6664922017-07-25 12:55:04 -04003462 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3463 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003464
3465 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003466 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003467}
3468
Brandon Jones59770802018-04-02 13:18:42 -07003469void Context::readPixelsRobust(GLint x,
3470 GLint y,
3471 GLsizei width,
3472 GLsizei height,
3473 GLenum format,
3474 GLenum type,
3475 GLsizei bufSize,
3476 GLsizei *length,
3477 GLsizei *columns,
3478 GLsizei *rows,
3479 void *pixels)
3480{
3481 readPixels(x, y, width, height, format, type, pixels);
3482}
3483
3484void Context::readnPixelsRobust(GLint x,
3485 GLint y,
3486 GLsizei width,
3487 GLsizei height,
3488 GLenum format,
3489 GLenum type,
3490 GLsizei bufSize,
3491 GLsizei *length,
3492 GLsizei *columns,
3493 GLsizei *rows,
3494 void *data)
3495{
3496 readPixels(x, y, width, height, format, type, data);
3497}
3498
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003499void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003500 GLint level,
3501 GLenum internalformat,
3502 GLint x,
3503 GLint y,
3504 GLsizei width,
3505 GLsizei height,
3506 GLint border)
3507{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003508 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003509 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003510
Jamie Madillc29968b2016-01-20 11:17:23 -05003511 Rectangle sourceArea(x, y, width, height);
3512
Jamie Madill05b35b22017-10-03 09:01:44 -04003513 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003514 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003515 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003516}
3517
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003518void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003519 GLint level,
3520 GLint xoffset,
3521 GLint yoffset,
3522 GLint x,
3523 GLint y,
3524 GLsizei width,
3525 GLsizei height)
3526{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003527 if (width == 0 || height == 0)
3528 {
3529 return;
3530 }
3531
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003532 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003533 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003534
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 Offset destOffset(xoffset, yoffset, 0);
3536 Rectangle sourceArea(x, y, width, height);
3537
Jamie Madill05b35b22017-10-03 09:01:44 -04003538 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003539 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003540 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003541}
3542
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003543void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003544 GLint level,
3545 GLint xoffset,
3546 GLint yoffset,
3547 GLint zoffset,
3548 GLint x,
3549 GLint y,
3550 GLsizei width,
3551 GLsizei height)
3552{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003553 if (width == 0 || height == 0)
3554 {
3555 return;
3556 }
3557
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003558 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003559 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003560
Jamie Madillc29968b2016-01-20 11:17:23 -05003561 Offset destOffset(xoffset, yoffset, zoffset);
3562 Rectangle sourceArea(x, y, width, height);
3563
Jamie Madill05b35b22017-10-03 09:01:44 -04003564 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3565 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003566 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3567 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003568}
3569
3570void Context::framebufferTexture2D(GLenum target,
3571 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003572 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003573 GLuint texture,
3574 GLint level)
3575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003577 ASSERT(framebuffer);
3578
3579 if (texture != 0)
3580 {
3581 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003582 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003583 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003584 }
3585 else
3586 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003587 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003588 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003589
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003591}
3592
3593void Context::framebufferRenderbuffer(GLenum target,
3594 GLenum attachment,
3595 GLenum renderbuffertarget,
3596 GLuint renderbuffer)
3597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 ASSERT(framebuffer);
3600
3601 if (renderbuffer != 0)
3602 {
3603 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003604
Jamie Madillcc129372018-04-12 09:13:18 -04003605 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003606 renderbufferObject);
3607 }
3608 else
3609 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003610 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003611 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003612
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003614}
3615
3616void Context::framebufferTextureLayer(GLenum target,
3617 GLenum attachment,
3618 GLuint texture,
3619 GLint level,
3620 GLint layer)
3621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003622 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003623 ASSERT(framebuffer);
3624
3625 if (texture != 0)
3626 {
3627 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003628 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003629 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003630 }
3631 else
3632 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003633 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003634 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003635
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003637}
3638
Brandon Jones59770802018-04-02 13:18:42 -07003639void Context::framebufferTextureMultiviewLayered(GLenum target,
3640 GLenum attachment,
3641 GLuint texture,
3642 GLint level,
3643 GLint baseViewIndex,
3644 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003645{
Martin Radev82ef7742017-08-08 17:44:58 +03003646 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3647 ASSERT(framebuffer);
3648
3649 if (texture != 0)
3650 {
3651 Texture *textureObj = getTexture(texture);
3652
Martin Radev18b75ba2017-08-15 15:50:40 +03003653 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003654 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3655 numViews, baseViewIndex);
3656 }
3657 else
3658 {
3659 framebuffer->resetAttachment(this, attachment);
3660 }
3661
3662 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003663}
3664
Brandon Jones59770802018-04-02 13:18:42 -07003665void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3666 GLenum attachment,
3667 GLuint texture,
3668 GLint level,
3669 GLsizei numViews,
3670 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003671{
Martin Radev5dae57b2017-07-14 16:15:55 +03003672 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3673 ASSERT(framebuffer);
3674
3675 if (texture != 0)
3676 {
3677 Texture *textureObj = getTexture(texture);
3678
3679 ImageIndex index = ImageIndex::Make2D(level);
3680 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3681 textureObj, numViews, viewportOffsets);
3682 }
3683 else
3684 {
3685 framebuffer->resetAttachment(this, attachment);
3686 }
3687
3688 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003689}
3690
Jamie Madillc29968b2016-01-20 11:17:23 -05003691void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3692{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003693 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003694 ASSERT(framebuffer);
3695 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003696 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003697}
3698
3699void Context::readBuffer(GLenum mode)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003704}
3705
3706void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3707{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003708 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003709 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003710
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 ASSERT(framebuffer);
3713
3714 // The specification isn't clear what should be done when the framebuffer isn't complete.
3715 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003716 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003717}
3718
3719void Context::invalidateFramebuffer(GLenum target,
3720 GLsizei numAttachments,
3721 const GLenum *attachments)
3722{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003723 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003724 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003727 ASSERT(framebuffer);
3728
Jamie Madill427064d2018-04-13 16:20:34 -04003729 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003730 {
Jamie Madill437fa652016-05-03 15:13:24 -04003731 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 }
Jamie Madill437fa652016-05-03 15:13:24 -04003733
Jamie Madill4928b7c2017-06-20 12:57:39 -04003734 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003735}
3736
3737void Context::invalidateSubFramebuffer(GLenum target,
3738 GLsizei numAttachments,
3739 const GLenum *attachments,
3740 GLint x,
3741 GLint y,
3742 GLsizei width,
3743 GLsizei height)
3744{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003745 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003746 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 ASSERT(framebuffer);
3750
Jamie Madill427064d2018-04-13 16:20:34 -04003751 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003752 {
Jamie Madill437fa652016-05-03 15:13:24 -04003753 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003754 }
Jamie Madill437fa652016-05-03 15:13:24 -04003755
3756 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003757 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003758}
3759
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003760void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003761 GLint level,
3762 GLint internalformat,
3763 GLsizei width,
3764 GLsizei height,
3765 GLint border,
3766 GLenum format,
3767 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003768 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003769{
Jamie Madillbc918e72018-03-08 09:47:21 -05003770 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003771
3772 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003773 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003774 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3775 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003776}
3777
Brandon Jones59770802018-04-02 13:18:42 -07003778void Context::texImage2DRobust(TextureTarget target,
3779 GLint level,
3780 GLint internalformat,
3781 GLsizei width,
3782 GLsizei height,
3783 GLint border,
3784 GLenum format,
3785 GLenum type,
3786 GLsizei bufSize,
3787 const void *pixels)
3788{
3789 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3790}
3791
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003792void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003793 GLint level,
3794 GLint internalformat,
3795 GLsizei width,
3796 GLsizei height,
3797 GLsizei depth,
3798 GLint border,
3799 GLenum format,
3800 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003801 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003802{
Jamie Madillbc918e72018-03-08 09:47:21 -05003803 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003804
3805 Extents size(width, height, depth);
3806 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003807 handleError(texture->setImage(this, mGLState.getUnpackState(),
3808 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3809 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003810}
3811
Brandon Jones59770802018-04-02 13:18:42 -07003812void Context::texImage3DRobust(TextureType target,
3813 GLint level,
3814 GLint internalformat,
3815 GLsizei width,
3816 GLsizei height,
3817 GLsizei depth,
3818 GLint border,
3819 GLenum format,
3820 GLenum type,
3821 GLsizei bufSize,
3822 const void *pixels)
3823{
3824 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3825}
3826
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003827void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003828 GLint level,
3829 GLint xoffset,
3830 GLint yoffset,
3831 GLsizei width,
3832 GLsizei height,
3833 GLenum format,
3834 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003835 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003836{
3837 // Zero sized uploads are valid but no-ops
3838 if (width == 0 || height == 0)
3839 {
3840 return;
3841 }
3842
Jamie Madillbc918e72018-03-08 09:47:21 -05003843 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003844
3845 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003846 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003847 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3848 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003849}
3850
Brandon Jones59770802018-04-02 13:18:42 -07003851void Context::texSubImage2DRobust(TextureTarget target,
3852 GLint level,
3853 GLint xoffset,
3854 GLint yoffset,
3855 GLsizei width,
3856 GLsizei height,
3857 GLenum format,
3858 GLenum type,
3859 GLsizei bufSize,
3860 const void *pixels)
3861{
3862 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3863}
3864
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003865void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003866 GLint level,
3867 GLint xoffset,
3868 GLint yoffset,
3869 GLint zoffset,
3870 GLsizei width,
3871 GLsizei height,
3872 GLsizei depth,
3873 GLenum format,
3874 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003875 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003876{
3877 // Zero sized uploads are valid but no-ops
3878 if (width == 0 || height == 0 || depth == 0)
3879 {
3880 return;
3881 }
3882
Jamie Madillbc918e72018-03-08 09:47:21 -05003883 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003884
3885 Box area(xoffset, yoffset, zoffset, width, height, depth);
3886 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003887 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3888 NonCubeTextureTypeToTarget(target), level, area, format, type,
3889 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003890}
3891
Brandon Jones59770802018-04-02 13:18:42 -07003892void Context::texSubImage3DRobust(TextureType target,
3893 GLint level,
3894 GLint xoffset,
3895 GLint yoffset,
3896 GLint zoffset,
3897 GLsizei width,
3898 GLsizei height,
3899 GLsizei depth,
3900 GLenum format,
3901 GLenum type,
3902 GLsizei bufSize,
3903 const void *pixels)
3904{
3905 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3906 pixels);
3907}
3908
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003909void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003910 GLint level,
3911 GLenum internalformat,
3912 GLsizei width,
3913 GLsizei height,
3914 GLint border,
3915 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003916 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003917{
Jamie Madillbc918e72018-03-08 09:47:21 -05003918 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003919
3920 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003921 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003922 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3923 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003924 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003925}
3926
Brandon Jones59770802018-04-02 13:18:42 -07003927void Context::compressedTexImage2DRobust(TextureTarget target,
3928 GLint level,
3929 GLenum internalformat,
3930 GLsizei width,
3931 GLsizei height,
3932 GLint border,
3933 GLsizei imageSize,
3934 GLsizei dataSize,
3935 const GLvoid *data)
3936{
3937 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3938}
3939
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003940void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003941 GLint level,
3942 GLenum internalformat,
3943 GLsizei width,
3944 GLsizei height,
3945 GLsizei depth,
3946 GLint border,
3947 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003948 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003949{
Jamie Madillbc918e72018-03-08 09:47:21 -05003950 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003951
3952 Extents size(width, height, depth);
3953 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003954 handleError(texture->setCompressedImage(
3955 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3956 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003957}
3958
Brandon Jones59770802018-04-02 13:18:42 -07003959void Context::compressedTexImage3DRobust(TextureType target,
3960 GLint level,
3961 GLenum internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLsizei depth,
3965 GLint border,
3966 GLsizei imageSize,
3967 GLsizei dataSize,
3968 const GLvoid *data)
3969{
3970 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3971 data);
3972}
3973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003974void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003975 GLint level,
3976 GLint xoffset,
3977 GLint yoffset,
3978 GLsizei width,
3979 GLsizei height,
3980 GLenum format,
3981 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003982 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003983{
Jamie Madillbc918e72018-03-08 09:47:21 -05003984 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003985
3986 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003987 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003988 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3989 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003991}
3992
Brandon Jones59770802018-04-02 13:18:42 -07003993void Context::compressedTexSubImage2DRobust(TextureTarget target,
3994 GLint level,
3995 GLint xoffset,
3996 GLint yoffset,
3997 GLsizei width,
3998 GLsizei height,
3999 GLenum format,
4000 GLsizei imageSize,
4001 GLsizei dataSize,
4002 const GLvoid *data)
4003{
4004 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4005 data);
4006}
4007
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004008void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004009 GLint level,
4010 GLint xoffset,
4011 GLint yoffset,
4012 GLint zoffset,
4013 GLsizei width,
4014 GLsizei height,
4015 GLsizei depth,
4016 GLenum format,
4017 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004018 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004019{
4020 // Zero sized uploads are valid but no-ops
4021 if (width == 0 || height == 0)
4022 {
4023 return;
4024 }
4025
Jamie Madillbc918e72018-03-08 09:47:21 -05004026 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004027
4028 Box area(xoffset, yoffset, zoffset, width, height, depth);
4029 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004030 handleError(texture->setCompressedSubImage(
4031 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4032 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004033}
4034
Brandon Jones59770802018-04-02 13:18:42 -07004035void Context::compressedTexSubImage3DRobust(TextureType target,
4036 GLint level,
4037 GLint xoffset,
4038 GLint yoffset,
4039 GLint zoffset,
4040 GLsizei width,
4041 GLsizei height,
4042 GLsizei depth,
4043 GLenum format,
4044 GLsizei imageSize,
4045 GLsizei dataSize,
4046 const GLvoid *data)
4047{
4048 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4049 imageSize, data);
4050}
4051
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004052void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004053{
4054 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004055 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004056}
4057
Jamie Madill007530e2017-12-28 14:27:04 -05004058void Context::copyTexture(GLuint sourceId,
4059 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004060 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004061 GLuint destId,
4062 GLint destLevel,
4063 GLint internalFormat,
4064 GLenum destType,
4065 GLboolean unpackFlipY,
4066 GLboolean unpackPremultiplyAlpha,
4067 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004068{
Jamie Madillbc918e72018-03-08 09:47:21 -05004069 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004070
4071 gl::Texture *sourceTexture = getTexture(sourceId);
4072 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004073 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4074 sourceLevel, ConvertToBool(unpackFlipY),
4075 ConvertToBool(unpackPremultiplyAlpha),
4076 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004077}
4078
Jamie Madill007530e2017-12-28 14:27:04 -05004079void Context::copySubTexture(GLuint sourceId,
4080 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004081 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004082 GLuint destId,
4083 GLint destLevel,
4084 GLint xoffset,
4085 GLint yoffset,
4086 GLint x,
4087 GLint y,
4088 GLsizei width,
4089 GLsizei height,
4090 GLboolean unpackFlipY,
4091 GLboolean unpackPremultiplyAlpha,
4092 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004093{
4094 // Zero sized copies are valid but no-ops
4095 if (width == 0 || height == 0)
4096 {
4097 return;
4098 }
4099
Jamie Madillbc918e72018-03-08 09:47:21 -05004100 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004101
4102 gl::Texture *sourceTexture = getTexture(sourceId);
4103 gl::Texture *destTexture = getTexture(destId);
4104 Offset offset(xoffset, yoffset, 0);
4105 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004106 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4107 ConvertToBool(unpackFlipY),
4108 ConvertToBool(unpackPremultiplyAlpha),
4109 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004110}
4111
Jamie Madill007530e2017-12-28 14:27:04 -05004112void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004113{
Jamie Madillbc918e72018-03-08 09:47:21 -05004114 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004115
4116 gl::Texture *sourceTexture = getTexture(sourceId);
4117 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004118 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004119}
4120
Corentin Wallez336129f2017-10-17 15:55:40 -04004121void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004124 ASSERT(buffer);
4125
Geoff Lang496c02d2016-10-20 11:38:11 -07004126 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004127}
4128
Brandon Jones59770802018-04-02 13:18:42 -07004129void Context::getBufferPointervRobust(BufferBinding target,
4130 GLenum pname,
4131 GLsizei bufSize,
4132 GLsizei *length,
4133 void **params)
4134{
4135 getBufferPointerv(target, pname, params);
4136}
4137
Corentin Wallez336129f2017-10-17 15:55:40 -04004138void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004139{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004140 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004141 ASSERT(buffer);
4142
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004143 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004144 if (error.isError())
4145 {
Jamie Madill437fa652016-05-03 15:13:24 -04004146 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004147 return nullptr;
4148 }
4149
4150 return buffer->getMapPointer();
4151}
4152
Corentin Wallez336129f2017-10-17 15:55:40 -04004153GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004154{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004155 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004156 ASSERT(buffer);
4157
4158 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004159 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004160 if (error.isError())
4161 {
Jamie Madill437fa652016-05-03 15:13:24 -04004162 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004163 return GL_FALSE;
4164 }
4165
4166 return result;
4167}
4168
Corentin Wallez336129f2017-10-17 15:55:40 -04004169void *Context::mapBufferRange(BufferBinding target,
4170 GLintptr offset,
4171 GLsizeiptr length,
4172 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004174 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004175 ASSERT(buffer);
4176
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004177 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004178 if (error.isError())
4179 {
Jamie Madill437fa652016-05-03 15:13:24 -04004180 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004181 return nullptr;
4182 }
4183
4184 return buffer->getMapPointer();
4185}
4186
Corentin Wallez336129f2017-10-17 15:55:40 -04004187void Context::flushMappedBufferRange(BufferBinding /*target*/,
4188 GLintptr /*offset*/,
4189 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004190{
4191 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4192}
4193
Jamie Madillbc918e72018-03-08 09:47:21 -05004194Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004195{
Geoff Langa8cb2872018-03-09 16:09:40 -05004196 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004197}
4198
Jamie Madillbc918e72018-03-08 09:47:21 -05004199Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004200{
Geoff Langa8cb2872018-03-09 16:09:40 -05004201 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004202}
4203
Jamie Madillbc918e72018-03-08 09:47:21 -05004204Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004205{
Geoff Langa8cb2872018-03-09 16:09:40 -05004206 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004207}
4208
Jiajia Qin5451d532017-11-16 17:16:34 +08004209void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4210{
4211 UNIMPLEMENTED();
4212}
4213
Jamie Madillc20ab272016-06-09 07:20:46 -07004214void Context::activeTexture(GLenum texture)
4215{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004216 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004217}
4218
Jamie Madill876429b2017-04-20 15:46:24 -04004219void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004221 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004222}
4223
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004224void Context::blendEquation(GLenum mode)
4225{
4226 mGLState.setBlendEquation(mode, mode);
4227}
4228
Jamie Madillc20ab272016-06-09 07:20:46 -07004229void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4230{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004231 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004232}
4233
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004234void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4235{
4236 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4237}
4238
Jamie Madillc20ab272016-06-09 07:20:46 -07004239void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4240{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004241 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004242}
4243
Jamie Madill876429b2017-04-20 15:46:24 -04004244void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004245{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004246 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004247}
4248
Jamie Madill876429b2017-04-20 15:46:24 -04004249void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004250{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004251 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004252}
4253
4254void Context::clearStencil(GLint s)
4255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004256 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004257}
4258
4259void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4260{
Geoff Lang92019432017-11-20 13:09:34 -05004261 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4262 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004263}
4264
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004265void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004267 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004268}
4269
4270void Context::depthFunc(GLenum func)
4271{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004273}
4274
4275void Context::depthMask(GLboolean flag)
4276{
Geoff Lang92019432017-11-20 13:09:34 -05004277 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004278}
4279
Jamie Madill876429b2017-04-20 15:46:24 -04004280void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004281{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004282 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004283}
4284
4285void Context::disable(GLenum cap)
4286{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004287 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004288}
4289
4290void Context::disableVertexAttribArray(GLuint index)
4291{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004292 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004293}
4294
4295void Context::enable(GLenum cap)
4296{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004297 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004298}
4299
4300void Context::enableVertexAttribArray(GLuint index)
4301{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004303}
4304
4305void Context::frontFace(GLenum mode)
4306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004307 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004308}
4309
4310void Context::hint(GLenum target, GLenum mode)
4311{
4312 switch (target)
4313 {
4314 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316 break;
4317
4318 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004319 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004320 break;
4321
4322 default:
4323 UNREACHABLE();
4324 return;
4325 }
4326}
4327
4328void Context::lineWidth(GLfloat width)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
4333void Context::pixelStorei(GLenum pname, GLint param)
4334{
4335 switch (pname)
4336 {
4337 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339 break;
4340
4341 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004342 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004343 break;
4344
4345 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004346 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004347 break;
4348
4349 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004350 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352 break;
4353
4354 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004355 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004356 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004357 break;
4358
4359 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004360 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362 break;
4363
4364 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004365 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367 break;
4368
4369 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004370 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004371 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004372 break;
4373
4374 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004375 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004376 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004377 break;
4378
4379 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004380 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382 break;
4383
4384 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004385 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387 break;
4388
4389 default:
4390 UNREACHABLE();
4391 return;
4392 }
4393}
4394
4395void Context::polygonOffset(GLfloat factor, GLfloat units)
4396{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398}
4399
Jamie Madill876429b2017-04-20 15:46:24 -04004400void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004401{
Geoff Lang92019432017-11-20 13:09:34 -05004402 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004403}
4404
Jiawei Shaodb342272017-09-27 10:21:45 +08004405void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4406{
4407 mGLState.setSampleMaskParams(maskNumber, mask);
4408}
4409
Jamie Madillc20ab272016-06-09 07:20:46 -07004410void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4411{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
4415void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4416{
4417 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4418 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420 }
4421
4422 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4423 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425 }
4426}
4427
4428void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4429{
4430 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4431 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004432 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004433 }
4434
4435 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4436 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438 }
4439}
4440
4441void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4442{
4443 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4444 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446 }
4447
4448 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4449 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451 }
4452}
4453
4454void Context::vertexAttrib1f(GLuint index, GLfloat x)
4455{
4456 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004457 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004458}
4459
4460void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4461{
4462 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004463 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004464}
4465
4466void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4467{
4468 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004469 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004470}
4471
4472void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4473{
4474 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476}
4477
4478void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4479{
4480 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482}
4483
4484void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4485{
4486 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
4490void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4491{
4492 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494}
4495
4496void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4497{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499}
4500
4501void Context::vertexAttribPointer(GLuint index,
4502 GLint size,
4503 GLenum type,
4504 GLboolean normalized,
4505 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004506 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004507{
Corentin Wallez336129f2017-10-17 15:55:40 -04004508 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004509 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
Shao80957d92017-02-20 21:25:59 +08004512void Context::vertexAttribFormat(GLuint attribIndex,
4513 GLint size,
4514 GLenum type,
4515 GLboolean normalized,
4516 GLuint relativeOffset)
4517{
Geoff Lang92019432017-11-20 13:09:34 -05004518 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004519 relativeOffset);
4520}
4521
4522void Context::vertexAttribIFormat(GLuint attribIndex,
4523 GLint size,
4524 GLenum type,
4525 GLuint relativeOffset)
4526{
4527 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4528}
4529
4530void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4531{
Shaodde78e82017-05-22 14:13:27 +08004532 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004533}
4534
Jiajia Qin5451d532017-11-16 17:16:34 +08004535void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004536{
4537 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4538}
4539
Jamie Madillc20ab272016-06-09 07:20:46 -07004540void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4541{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543}
4544
4545void Context::vertexAttribIPointer(GLuint index,
4546 GLint size,
4547 GLenum type,
4548 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004549 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004550{
Corentin Wallez336129f2017-10-17 15:55:40 -04004551 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4552 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553}
4554
4555void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4556{
4557 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004558 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004559}
4560
4561void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4562{
4563 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004564 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004565}
4566
4567void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4568{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570}
4571
4572void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004577void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4578{
4579 const VertexAttribCurrentValueData &currentValues =
4580 getGLState().getVertexAttribCurrentValue(index);
4581 const VertexArray *vao = getGLState().getVertexArray();
4582 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4583 currentValues, pname, params);
4584}
4585
Brandon Jones59770802018-04-02 13:18:42 -07004586void Context::getVertexAttribivRobust(GLuint index,
4587 GLenum pname,
4588 GLsizei bufSize,
4589 GLsizei *length,
4590 GLint *params)
4591{
4592 getVertexAttribiv(index, pname, params);
4593}
4594
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004595void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4596{
4597 const VertexAttribCurrentValueData &currentValues =
4598 getGLState().getVertexAttribCurrentValue(index);
4599 const VertexArray *vao = getGLState().getVertexArray();
4600 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4601 currentValues, pname, params);
4602}
4603
Brandon Jones59770802018-04-02 13:18:42 -07004604void Context::getVertexAttribfvRobust(GLuint index,
4605 GLenum pname,
4606 GLsizei bufSize,
4607 GLsizei *length,
4608 GLfloat *params)
4609{
4610 getVertexAttribfv(index, pname, params);
4611}
4612
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004613void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4614{
4615 const VertexAttribCurrentValueData &currentValues =
4616 getGLState().getVertexAttribCurrentValue(index);
4617 const VertexArray *vao = getGLState().getVertexArray();
4618 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4619 currentValues, pname, params);
4620}
4621
Brandon Jones59770802018-04-02 13:18:42 -07004622void Context::getVertexAttribIivRobust(GLuint index,
4623 GLenum pname,
4624 GLsizei bufSize,
4625 GLsizei *length,
4626 GLint *params)
4627{
4628 getVertexAttribIiv(index, pname, params);
4629}
4630
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004631void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4632{
4633 const VertexAttribCurrentValueData &currentValues =
4634 getGLState().getVertexAttribCurrentValue(index);
4635 const VertexArray *vao = getGLState().getVertexArray();
4636 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4637 currentValues, pname, params);
4638}
4639
Brandon Jones59770802018-04-02 13:18:42 -07004640void Context::getVertexAttribIuivRobust(GLuint index,
4641 GLenum pname,
4642 GLsizei bufSize,
4643 GLsizei *length,
4644 GLuint *params)
4645{
4646 getVertexAttribIuiv(index, pname, params);
4647}
4648
Jamie Madill876429b2017-04-20 15:46:24 -04004649void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004650{
4651 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4652 QueryVertexAttribPointerv(attrib, pname, pointer);
4653}
4654
Brandon Jones59770802018-04-02 13:18:42 -07004655void Context::getVertexAttribPointervRobust(GLuint index,
4656 GLenum pname,
4657 GLsizei bufSize,
4658 GLsizei *length,
4659 void **pointer)
4660{
4661 getVertexAttribPointerv(index, pname, pointer);
4662}
4663
Jamie Madillc20ab272016-06-09 07:20:46 -07004664void Context::debugMessageControl(GLenum source,
4665 GLenum type,
4666 GLenum severity,
4667 GLsizei count,
4668 const GLuint *ids,
4669 GLboolean enabled)
4670{
4671 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004673 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
4676void Context::debugMessageInsert(GLenum source,
4677 GLenum type,
4678 GLuint id,
4679 GLenum severity,
4680 GLsizei length,
4681 const GLchar *buf)
4682{
4683 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004685}
4686
4687void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4688{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004689 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004690}
4691
4692GLuint Context::getDebugMessageLog(GLuint count,
4693 GLsizei bufSize,
4694 GLenum *sources,
4695 GLenum *types,
4696 GLuint *ids,
4697 GLenum *severities,
4698 GLsizei *lengths,
4699 GLchar *messageLog)
4700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004701 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4702 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004703}
4704
4705void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4706{
4707 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004708 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004709 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710}
4711
4712void Context::popDebugGroup()
4713{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004715 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004716}
4717
Corentin Wallez336129f2017-10-17 15:55:40 -04004718void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004719{
4720 Buffer *buffer = mGLState.getTargetBuffer(target);
4721 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004722 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004723}
4724
Corentin Wallez336129f2017-10-17 15:55:40 -04004725void Context::bufferSubData(BufferBinding target,
4726 GLintptr offset,
4727 GLsizeiptr size,
4728 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004729{
4730 if (data == nullptr)
4731 {
4732 return;
4733 }
4734
4735 Buffer *buffer = mGLState.getTargetBuffer(target);
4736 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004737 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004738}
4739
Jamie Madillef300b12016-10-07 15:12:09 -04004740void Context::attachShader(GLuint program, GLuint shader)
4741{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004742 Program *programObject = mState.mShaderPrograms->getProgram(program);
4743 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004744 ASSERT(programObject && shaderObject);
4745 programObject->attachShader(shaderObject);
4746}
4747
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004748const Workarounds &Context::getWorkarounds() const
4749{
4750 return mWorkarounds;
4751}
4752
Corentin Wallez336129f2017-10-17 15:55:40 -04004753void Context::copyBufferSubData(BufferBinding readTarget,
4754 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004755 GLintptr readOffset,
4756 GLintptr writeOffset,
4757 GLsizeiptr size)
4758{
4759 // if size is zero, the copy is a successful no-op
4760 if (size == 0)
4761 {
4762 return;
4763 }
4764
4765 // TODO(jmadill): cache these.
4766 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4767 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4768
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004769 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004770}
4771
Jamie Madill01a80ee2016-11-07 12:06:18 -05004772void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4773{
4774 Program *programObject = getProgram(program);
4775 // TODO(jmadill): Re-use this from the validation if possible.
4776 ASSERT(programObject);
4777 programObject->bindAttributeLocation(index, name);
4778}
4779
Corentin Wallez336129f2017-10-17 15:55:40 -04004780void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004781{
Corentin Wallez336129f2017-10-17 15:55:40 -04004782 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4783 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004784}
4785
Corentin Wallez336129f2017-10-17 15:55:40 -04004786void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004787{
4788 bindBufferRange(target, index, buffer, 0, 0);
4789}
4790
Corentin Wallez336129f2017-10-17 15:55:40 -04004791void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004792 GLuint index,
4793 GLuint buffer,
4794 GLintptr offset,
4795 GLsizeiptr size)
4796{
Corentin Wallez336129f2017-10-17 15:55:40 -04004797 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4798 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004799}
4800
Jamie Madill01a80ee2016-11-07 12:06:18 -05004801void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4802{
4803 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4804 {
4805 bindReadFramebuffer(framebuffer);
4806 }
4807
4808 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4809 {
4810 bindDrawFramebuffer(framebuffer);
4811 }
4812}
4813
4814void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4815{
4816 ASSERT(target == GL_RENDERBUFFER);
4817 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004818 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004819 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004820}
4821
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004822void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004823 GLsizei samples,
4824 GLenum internalformat,
4825 GLsizei width,
4826 GLsizei height,
4827 GLboolean fixedsamplelocations)
4828{
4829 Extents size(width, height, 1);
4830 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004831 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4832 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004833}
4834
4835void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4836{
JiangYizhou5b03f472017-01-09 10:22:53 +08004837 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4838 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004839 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004840 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004841
4842 switch (pname)
4843 {
4844 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004845 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004846 break;
4847 default:
4848 UNREACHABLE();
4849 }
4850}
4851
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004852void Context::getMultisamplefvRobust(GLenum pname,
4853 GLuint index,
4854 GLsizei bufSize,
4855 GLsizei *length,
4856 GLfloat *val)
4857{
4858 UNIMPLEMENTED();
4859}
4860
Jamie Madille8fb6402017-02-14 17:56:40 -05004861void Context::renderbufferStorage(GLenum target,
4862 GLenum internalformat,
4863 GLsizei width,
4864 GLsizei height)
4865{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004866 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4867 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4868
Jamie Madille8fb6402017-02-14 17:56:40 -05004869 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004870 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004871}
4872
4873void Context::renderbufferStorageMultisample(GLenum target,
4874 GLsizei samples,
4875 GLenum internalformat,
4876 GLsizei width,
4877 GLsizei height)
4878{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004879 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4880 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004881
4882 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004883 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004884 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004885}
4886
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004887void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4888{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004889 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004890 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004891}
4892
JiangYizhoue18e6392017-02-20 10:32:23 +08004893void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4894{
4895 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4896 QueryFramebufferParameteriv(framebuffer, pname, params);
4897}
4898
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004899void Context::getFramebufferParameterivRobust(GLenum target,
4900 GLenum pname,
4901 GLsizei bufSize,
4902 GLsizei *length,
4903 GLint *params)
4904{
4905 UNIMPLEMENTED();
4906}
4907
Jiajia Qin5451d532017-11-16 17:16:34 +08004908void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004909{
4910 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4911 SetFramebufferParameteri(framebuffer, pname, param);
4912}
4913
Jamie Madillb3f26b92017-07-19 15:07:41 -04004914Error Context::getScratchBuffer(size_t requstedSizeBytes,
4915 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004916{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004917 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4918 {
4919 return OutOfMemory() << "Failed to allocate internal buffer.";
4920 }
4921 return NoError();
4922}
4923
4924Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4925 angle::MemoryBuffer **zeroBufferOut) const
4926{
4927 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004928 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004929 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004930 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004931 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004932}
4933
Xinghua Cao10a4d432017-11-28 14:46:26 +08004934Error Context::prepareForDispatch()
4935{
Geoff Langa8cb2872018-03-09 16:09:40 -05004936 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004937
4938 if (isRobustResourceInitEnabled())
4939 {
4940 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4941 }
4942
4943 return NoError();
4944}
4945
Xinghua Cao2b396592017-03-29 15:36:04 +08004946void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4947{
4948 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4949 {
4950 return;
4951 }
4952
Xinghua Cao10a4d432017-11-28 14:46:26 +08004953 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004954 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004955}
4956
Jiajia Qin5451d532017-11-16 17:16:34 +08004957void Context::dispatchComputeIndirect(GLintptr indirect)
4958{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004959 ANGLE_CONTEXT_TRY(prepareForDispatch());
4960 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004961}
4962
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004963void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004964 GLsizei levels,
4965 GLenum internalFormat,
4966 GLsizei width,
4967 GLsizei height)
4968{
4969 Extents size(width, height, 1);
4970 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004971 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004972}
4973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004974void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004975 GLsizei levels,
4976 GLenum internalFormat,
4977 GLsizei width,
4978 GLsizei height,
4979 GLsizei depth)
4980{
4981 Extents size(width, height, depth);
4982 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004983 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004984}
4985
Jiajia Qin5451d532017-11-16 17:16:34 +08004986void Context::memoryBarrier(GLbitfield barriers)
4987{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004988 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004989}
4990
4991void Context::memoryBarrierByRegion(GLbitfield barriers)
4992{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004993 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004994}
4995
Jamie Madillc1d770e2017-04-13 17:31:24 -04004996GLenum Context::checkFramebufferStatus(GLenum target)
4997{
4998 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4999 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005000 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005001}
5002
5003void Context::compileShader(GLuint shader)
5004{
5005 Shader *shaderObject = GetValidShader(this, shader);
5006 if (!shaderObject)
5007 {
5008 return;
5009 }
5010 shaderObject->compile(this);
5011}
5012
5013void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5014{
5015 for (int i = 0; i < n; i++)
5016 {
5017 deleteBuffer(buffers[i]);
5018 }
5019}
5020
5021void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5022{
5023 for (int i = 0; i < n; i++)
5024 {
5025 if (framebuffers[i] != 0)
5026 {
5027 deleteFramebuffer(framebuffers[i]);
5028 }
5029 }
5030}
5031
5032void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5033{
5034 for (int i = 0; i < n; i++)
5035 {
5036 deleteRenderbuffer(renderbuffers[i]);
5037 }
5038}
5039
5040void Context::deleteTextures(GLsizei n, const GLuint *textures)
5041{
5042 for (int i = 0; i < n; i++)
5043 {
5044 if (textures[i] != 0)
5045 {
5046 deleteTexture(textures[i]);
5047 }
5048 }
5049}
5050
5051void Context::detachShader(GLuint program, GLuint shader)
5052{
5053 Program *programObject = getProgram(program);
5054 ASSERT(programObject);
5055
5056 Shader *shaderObject = getShader(shader);
5057 ASSERT(shaderObject);
5058
5059 programObject->detachShader(this, shaderObject);
5060}
5061
5062void Context::genBuffers(GLsizei n, GLuint *buffers)
5063{
5064 for (int i = 0; i < n; i++)
5065 {
5066 buffers[i] = createBuffer();
5067 }
5068}
5069
5070void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5071{
5072 for (int i = 0; i < n; i++)
5073 {
5074 framebuffers[i] = createFramebuffer();
5075 }
5076}
5077
5078void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5079{
5080 for (int i = 0; i < n; i++)
5081 {
5082 renderbuffers[i] = createRenderbuffer();
5083 }
5084}
5085
5086void Context::genTextures(GLsizei n, GLuint *textures)
5087{
5088 for (int i = 0; i < n; i++)
5089 {
5090 textures[i] = createTexture();
5091 }
5092}
5093
5094void Context::getActiveAttrib(GLuint program,
5095 GLuint index,
5096 GLsizei bufsize,
5097 GLsizei *length,
5098 GLint *size,
5099 GLenum *type,
5100 GLchar *name)
5101{
5102 Program *programObject = getProgram(program);
5103 ASSERT(programObject);
5104 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5105}
5106
5107void Context::getActiveUniform(GLuint program,
5108 GLuint index,
5109 GLsizei bufsize,
5110 GLsizei *length,
5111 GLint *size,
5112 GLenum *type,
5113 GLchar *name)
5114{
5115 Program *programObject = getProgram(program);
5116 ASSERT(programObject);
5117 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5118}
5119
5120void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5121{
5122 Program *programObject = getProgram(program);
5123 ASSERT(programObject);
5124 programObject->getAttachedShaders(maxcount, count, shaders);
5125}
5126
5127GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5128{
5129 Program *programObject = getProgram(program);
5130 ASSERT(programObject);
5131 return programObject->getAttributeLocation(name);
5132}
5133
5134void Context::getBooleanv(GLenum pname, GLboolean *params)
5135{
5136 GLenum nativeType;
5137 unsigned int numParams = 0;
5138 getQueryParameterInfo(pname, &nativeType, &numParams);
5139
5140 if (nativeType == GL_BOOL)
5141 {
5142 getBooleanvImpl(pname, params);
5143 }
5144 else
5145 {
5146 CastStateValues(this, nativeType, pname, numParams, params);
5147 }
5148}
5149
Brandon Jones59770802018-04-02 13:18:42 -07005150void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5151{
5152 getBooleanv(pname, params);
5153}
5154
Jamie Madillc1d770e2017-04-13 17:31:24 -04005155void Context::getFloatv(GLenum pname, GLfloat *params)
5156{
5157 GLenum nativeType;
5158 unsigned int numParams = 0;
5159 getQueryParameterInfo(pname, &nativeType, &numParams);
5160
5161 if (nativeType == GL_FLOAT)
5162 {
5163 getFloatvImpl(pname, params);
5164 }
5165 else
5166 {
5167 CastStateValues(this, nativeType, pname, numParams, params);
5168 }
5169}
5170
Brandon Jones59770802018-04-02 13:18:42 -07005171void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5172{
5173 getFloatv(pname, params);
5174}
5175
Jamie Madillc1d770e2017-04-13 17:31:24 -04005176void Context::getIntegerv(GLenum pname, GLint *params)
5177{
5178 GLenum nativeType;
5179 unsigned int numParams = 0;
5180 getQueryParameterInfo(pname, &nativeType, &numParams);
5181
5182 if (nativeType == GL_INT)
5183 {
5184 getIntegervImpl(pname, params);
5185 }
5186 else
5187 {
5188 CastStateValues(this, nativeType, pname, numParams, params);
5189 }
5190}
5191
Brandon Jones59770802018-04-02 13:18:42 -07005192void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5193{
5194 getIntegerv(pname, data);
5195}
5196
Jamie Madillc1d770e2017-04-13 17:31:24 -04005197void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5198{
5199 Program *programObject = getProgram(program);
5200 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005201 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005202}
5203
Brandon Jones59770802018-04-02 13:18:42 -07005204void Context::getProgramivRobust(GLuint program,
5205 GLenum pname,
5206 GLsizei bufSize,
5207 GLsizei *length,
5208 GLint *params)
5209{
5210 getProgramiv(program, pname, params);
5211}
5212
Jiajia Qin5451d532017-11-16 17:16:34 +08005213void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5214{
5215 UNIMPLEMENTED();
5216}
5217
Jamie Madillbe849e42017-05-02 15:49:00 -04005218void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005219{
5220 Program *programObject = getProgram(program);
5221 ASSERT(programObject);
5222 programObject->getInfoLog(bufsize, length, infolog);
5223}
5224
Jiajia Qin5451d532017-11-16 17:16:34 +08005225void Context::getProgramPipelineInfoLog(GLuint pipeline,
5226 GLsizei bufSize,
5227 GLsizei *length,
5228 GLchar *infoLog)
5229{
5230 UNIMPLEMENTED();
5231}
5232
Jamie Madillc1d770e2017-04-13 17:31:24 -04005233void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5234{
5235 Shader *shaderObject = getShader(shader);
5236 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005237 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238}
5239
Brandon Jones59770802018-04-02 13:18:42 -07005240void Context::getShaderivRobust(GLuint shader,
5241 GLenum pname,
5242 GLsizei bufSize,
5243 GLsizei *length,
5244 GLint *params)
5245{
5246 getShaderiv(shader, pname, params);
5247}
5248
Jamie Madillc1d770e2017-04-13 17:31:24 -04005249void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5250{
5251 Shader *shaderObject = getShader(shader);
5252 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005253 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005254}
5255
5256void Context::getShaderPrecisionFormat(GLenum shadertype,
5257 GLenum precisiontype,
5258 GLint *range,
5259 GLint *precision)
5260{
5261 // TODO(jmadill): Compute shaders.
5262
5263 switch (shadertype)
5264 {
5265 case GL_VERTEX_SHADER:
5266 switch (precisiontype)
5267 {
5268 case GL_LOW_FLOAT:
5269 mCaps.vertexLowpFloat.get(range, precision);
5270 break;
5271 case GL_MEDIUM_FLOAT:
5272 mCaps.vertexMediumpFloat.get(range, precision);
5273 break;
5274 case GL_HIGH_FLOAT:
5275 mCaps.vertexHighpFloat.get(range, precision);
5276 break;
5277
5278 case GL_LOW_INT:
5279 mCaps.vertexLowpInt.get(range, precision);
5280 break;
5281 case GL_MEDIUM_INT:
5282 mCaps.vertexMediumpInt.get(range, precision);
5283 break;
5284 case GL_HIGH_INT:
5285 mCaps.vertexHighpInt.get(range, precision);
5286 break;
5287
5288 default:
5289 UNREACHABLE();
5290 return;
5291 }
5292 break;
5293
5294 case GL_FRAGMENT_SHADER:
5295 switch (precisiontype)
5296 {
5297 case GL_LOW_FLOAT:
5298 mCaps.fragmentLowpFloat.get(range, precision);
5299 break;
5300 case GL_MEDIUM_FLOAT:
5301 mCaps.fragmentMediumpFloat.get(range, precision);
5302 break;
5303 case GL_HIGH_FLOAT:
5304 mCaps.fragmentHighpFloat.get(range, precision);
5305 break;
5306
5307 case GL_LOW_INT:
5308 mCaps.fragmentLowpInt.get(range, precision);
5309 break;
5310 case GL_MEDIUM_INT:
5311 mCaps.fragmentMediumpInt.get(range, precision);
5312 break;
5313 case GL_HIGH_INT:
5314 mCaps.fragmentHighpInt.get(range, precision);
5315 break;
5316
5317 default:
5318 UNREACHABLE();
5319 return;
5320 }
5321 break;
5322
5323 default:
5324 UNREACHABLE();
5325 return;
5326 }
5327}
5328
5329void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5330{
5331 Shader *shaderObject = getShader(shader);
5332 ASSERT(shaderObject);
5333 shaderObject->getSource(bufsize, length, source);
5334}
5335
5336void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5337{
5338 Program *programObject = getProgram(program);
5339 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005340 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005341}
5342
Brandon Jones59770802018-04-02 13:18:42 -07005343void Context::getUniformfvRobust(GLuint program,
5344 GLint location,
5345 GLsizei bufSize,
5346 GLsizei *length,
5347 GLfloat *params)
5348{
5349 getUniformfv(program, location, params);
5350}
5351
Jamie Madillc1d770e2017-04-13 17:31:24 -04005352void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5353{
5354 Program *programObject = getProgram(program);
5355 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005356 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005357}
5358
Brandon Jones59770802018-04-02 13:18:42 -07005359void Context::getUniformivRobust(GLuint program,
5360 GLint location,
5361 GLsizei bufSize,
5362 GLsizei *length,
5363 GLint *params)
5364{
5365 getUniformiv(program, location, params);
5366}
5367
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5369{
5370 Program *programObject = getProgram(program);
5371 ASSERT(programObject);
5372 return programObject->getUniformLocation(name);
5373}
5374
5375GLboolean Context::isBuffer(GLuint buffer)
5376{
5377 if (buffer == 0)
5378 {
5379 return GL_FALSE;
5380 }
5381
5382 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5383}
5384
5385GLboolean Context::isEnabled(GLenum cap)
5386{
5387 return mGLState.getEnableFeature(cap);
5388}
5389
5390GLboolean Context::isFramebuffer(GLuint framebuffer)
5391{
5392 if (framebuffer == 0)
5393 {
5394 return GL_FALSE;
5395 }
5396
5397 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5398}
5399
5400GLboolean Context::isProgram(GLuint program)
5401{
5402 if (program == 0)
5403 {
5404 return GL_FALSE;
5405 }
5406
5407 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5408}
5409
5410GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5411{
5412 if (renderbuffer == 0)
5413 {
5414 return GL_FALSE;
5415 }
5416
5417 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5418}
5419
5420GLboolean Context::isShader(GLuint shader)
5421{
5422 if (shader == 0)
5423 {
5424 return GL_FALSE;
5425 }
5426
5427 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5428}
5429
5430GLboolean Context::isTexture(GLuint texture)
5431{
5432 if (texture == 0)
5433 {
5434 return GL_FALSE;
5435 }
5436
5437 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5438}
5439
5440void Context::linkProgram(GLuint program)
5441{
5442 Program *programObject = getProgram(program);
5443 ASSERT(programObject);
5444 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005445 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005446}
5447
5448void Context::releaseShaderCompiler()
5449{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005450 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005451}
5452
5453void Context::shaderBinary(GLsizei n,
5454 const GLuint *shaders,
5455 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005456 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457 GLsizei length)
5458{
5459 // No binary shader formats are supported.
5460 UNIMPLEMENTED();
5461}
5462
5463void Context::shaderSource(GLuint shader,
5464 GLsizei count,
5465 const GLchar *const *string,
5466 const GLint *length)
5467{
5468 Shader *shaderObject = getShader(shader);
5469 ASSERT(shaderObject);
5470 shaderObject->setSource(count, string, length);
5471}
5472
5473void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5474{
5475 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5476}
5477
5478void Context::stencilMask(GLuint mask)
5479{
5480 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5481}
5482
5483void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5484{
5485 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5486}
5487
5488void Context::uniform1f(GLint location, GLfloat x)
5489{
5490 Program *program = mGLState.getProgram();
5491 program->setUniform1fv(location, 1, &x);
5492}
5493
5494void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5495{
5496 Program *program = mGLState.getProgram();
5497 program->setUniform1fv(location, count, v);
5498}
5499
5500void Context::uniform1i(GLint location, GLint x)
5501{
5502 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005503 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5504 {
5505 mGLState.setObjectDirty(GL_PROGRAM);
5506 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005507}
5508
5509void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5510{
5511 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005512 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5513 {
5514 mGLState.setObjectDirty(GL_PROGRAM);
5515 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005516}
5517
5518void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5519{
5520 GLfloat xy[2] = {x, y};
5521 Program *program = mGLState.getProgram();
5522 program->setUniform2fv(location, 1, xy);
5523}
5524
5525void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5526{
5527 Program *program = mGLState.getProgram();
5528 program->setUniform2fv(location, count, v);
5529}
5530
5531void Context::uniform2i(GLint location, GLint x, GLint y)
5532{
5533 GLint xy[2] = {x, y};
5534 Program *program = mGLState.getProgram();
5535 program->setUniform2iv(location, 1, xy);
5536}
5537
5538void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5539{
5540 Program *program = mGLState.getProgram();
5541 program->setUniform2iv(location, count, v);
5542}
5543
5544void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5545{
5546 GLfloat xyz[3] = {x, y, z};
5547 Program *program = mGLState.getProgram();
5548 program->setUniform3fv(location, 1, xyz);
5549}
5550
5551void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5552{
5553 Program *program = mGLState.getProgram();
5554 program->setUniform3fv(location, count, v);
5555}
5556
5557void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5558{
5559 GLint xyz[3] = {x, y, z};
5560 Program *program = mGLState.getProgram();
5561 program->setUniform3iv(location, 1, xyz);
5562}
5563
5564void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5565{
5566 Program *program = mGLState.getProgram();
5567 program->setUniform3iv(location, count, v);
5568}
5569
5570void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5571{
5572 GLfloat xyzw[4] = {x, y, z, w};
5573 Program *program = mGLState.getProgram();
5574 program->setUniform4fv(location, 1, xyzw);
5575}
5576
5577void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5578{
5579 Program *program = mGLState.getProgram();
5580 program->setUniform4fv(location, count, v);
5581}
5582
5583void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5584{
5585 GLint xyzw[4] = {x, y, z, w};
5586 Program *program = mGLState.getProgram();
5587 program->setUniform4iv(location, 1, xyzw);
5588}
5589
5590void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5591{
5592 Program *program = mGLState.getProgram();
5593 program->setUniform4iv(location, count, v);
5594}
5595
5596void Context::uniformMatrix2fv(GLint location,
5597 GLsizei count,
5598 GLboolean transpose,
5599 const GLfloat *value)
5600{
5601 Program *program = mGLState.getProgram();
5602 program->setUniformMatrix2fv(location, count, transpose, value);
5603}
5604
5605void Context::uniformMatrix3fv(GLint location,
5606 GLsizei count,
5607 GLboolean transpose,
5608 const GLfloat *value)
5609{
5610 Program *program = mGLState.getProgram();
5611 program->setUniformMatrix3fv(location, count, transpose, value);
5612}
5613
5614void Context::uniformMatrix4fv(GLint location,
5615 GLsizei count,
5616 GLboolean transpose,
5617 const GLfloat *value)
5618{
5619 Program *program = mGLState.getProgram();
5620 program->setUniformMatrix4fv(location, count, transpose, value);
5621}
5622
5623void Context::validateProgram(GLuint program)
5624{
5625 Program *programObject = getProgram(program);
5626 ASSERT(programObject);
5627 programObject->validate(mCaps);
5628}
5629
Jiajia Qin5451d532017-11-16 17:16:34 +08005630void Context::validateProgramPipeline(GLuint pipeline)
5631{
5632 UNIMPLEMENTED();
5633}
5634
Jamie Madilld04908b2017-06-09 14:15:35 -04005635void Context::getProgramBinary(GLuint program,
5636 GLsizei bufSize,
5637 GLsizei *length,
5638 GLenum *binaryFormat,
5639 void *binary)
5640{
5641 Program *programObject = getProgram(program);
5642 ASSERT(programObject != nullptr);
5643
5644 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5645}
5646
5647void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5648{
5649 Program *programObject = getProgram(program);
5650 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005651
Jamie Madilld04908b2017-06-09 14:15:35 -04005652 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5653}
5654
Jamie Madillff325f12017-08-26 15:06:05 -04005655void Context::uniform1ui(GLint location, GLuint v0)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniform1uiv(location, 1, &v0);
5659}
5660
5661void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5662{
5663 Program *program = mGLState.getProgram();
5664 const GLuint xy[] = {v0, v1};
5665 program->setUniform2uiv(location, 1, xy);
5666}
5667
5668void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5669{
5670 Program *program = mGLState.getProgram();
5671 const GLuint xyz[] = {v0, v1, v2};
5672 program->setUniform3uiv(location, 1, xyz);
5673}
5674
5675void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5676{
5677 Program *program = mGLState.getProgram();
5678 const GLuint xyzw[] = {v0, v1, v2, v3};
5679 program->setUniform4uiv(location, 1, xyzw);
5680}
5681
5682void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5683{
5684 Program *program = mGLState.getProgram();
5685 program->setUniform1uiv(location, count, value);
5686}
5687void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5688{
5689 Program *program = mGLState.getProgram();
5690 program->setUniform2uiv(location, count, value);
5691}
5692
5693void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5694{
5695 Program *program = mGLState.getProgram();
5696 program->setUniform3uiv(location, count, value);
5697}
5698
5699void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniform4uiv(location, count, value);
5703}
5704
Jamie Madillf0e04492017-08-26 15:28:42 -04005705void Context::genQueries(GLsizei n, GLuint *ids)
5706{
5707 for (GLsizei i = 0; i < n; i++)
5708 {
5709 GLuint handle = mQueryHandleAllocator.allocate();
5710 mQueryMap.assign(handle, nullptr);
5711 ids[i] = handle;
5712 }
5713}
5714
5715void Context::deleteQueries(GLsizei n, const GLuint *ids)
5716{
5717 for (int i = 0; i < n; i++)
5718 {
5719 GLuint query = ids[i];
5720
5721 Query *queryObject = nullptr;
5722 if (mQueryMap.erase(query, &queryObject))
5723 {
5724 mQueryHandleAllocator.release(query);
5725 if (queryObject)
5726 {
5727 queryObject->release(this);
5728 }
5729 }
5730 }
5731}
5732
5733GLboolean Context::isQuery(GLuint id)
5734{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005735 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005736}
5737
Jamie Madillc8c95812017-08-26 18:40:09 -04005738void Context::uniformMatrix2x3fv(GLint location,
5739 GLsizei count,
5740 GLboolean transpose,
5741 const GLfloat *value)
5742{
5743 Program *program = mGLState.getProgram();
5744 program->setUniformMatrix2x3fv(location, count, transpose, value);
5745}
5746
5747void Context::uniformMatrix3x2fv(GLint location,
5748 GLsizei count,
5749 GLboolean transpose,
5750 const GLfloat *value)
5751{
5752 Program *program = mGLState.getProgram();
5753 program->setUniformMatrix3x2fv(location, count, transpose, value);
5754}
5755
5756void Context::uniformMatrix2x4fv(GLint location,
5757 GLsizei count,
5758 GLboolean transpose,
5759 const GLfloat *value)
5760{
5761 Program *program = mGLState.getProgram();
5762 program->setUniformMatrix2x4fv(location, count, transpose, value);
5763}
5764
5765void Context::uniformMatrix4x2fv(GLint location,
5766 GLsizei count,
5767 GLboolean transpose,
5768 const GLfloat *value)
5769{
5770 Program *program = mGLState.getProgram();
5771 program->setUniformMatrix4x2fv(location, count, transpose, value);
5772}
5773
5774void Context::uniformMatrix3x4fv(GLint location,
5775 GLsizei count,
5776 GLboolean transpose,
5777 const GLfloat *value)
5778{
5779 Program *program = mGLState.getProgram();
5780 program->setUniformMatrix3x4fv(location, count, transpose, value);
5781}
5782
5783void Context::uniformMatrix4x3fv(GLint location,
5784 GLsizei count,
5785 GLboolean transpose,
5786 const GLfloat *value)
5787{
5788 Program *program = mGLState.getProgram();
5789 program->setUniformMatrix4x3fv(location, count, transpose, value);
5790}
5791
Jamie Madilld7576732017-08-26 18:49:50 -04005792void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5793{
5794 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5795 {
5796 GLuint vertexArray = arrays[arrayIndex];
5797
5798 if (arrays[arrayIndex] != 0)
5799 {
5800 VertexArray *vertexArrayObject = nullptr;
5801 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5802 {
5803 if (vertexArrayObject != nullptr)
5804 {
5805 detachVertexArray(vertexArray);
5806 vertexArrayObject->onDestroy(this);
5807 }
5808
5809 mVertexArrayHandleAllocator.release(vertexArray);
5810 }
5811 }
5812 }
5813}
5814
5815void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5816{
5817 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5818 {
5819 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5820 mVertexArrayMap.assign(vertexArray, nullptr);
5821 arrays[arrayIndex] = vertexArray;
5822 }
5823}
5824
5825bool Context::isVertexArray(GLuint array)
5826{
5827 if (array == 0)
5828 {
5829 return GL_FALSE;
5830 }
5831
5832 VertexArray *vao = getVertexArray(array);
5833 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5834}
5835
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005836void Context::endTransformFeedback()
5837{
5838 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5839 transformFeedback->end(this);
5840}
5841
5842void Context::transformFeedbackVaryings(GLuint program,
5843 GLsizei count,
5844 const GLchar *const *varyings,
5845 GLenum bufferMode)
5846{
5847 Program *programObject = getProgram(program);
5848 ASSERT(programObject);
5849 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5850}
5851
5852void Context::getTransformFeedbackVarying(GLuint program,
5853 GLuint index,
5854 GLsizei bufSize,
5855 GLsizei *length,
5856 GLsizei *size,
5857 GLenum *type,
5858 GLchar *name)
5859{
5860 Program *programObject = getProgram(program);
5861 ASSERT(programObject);
5862 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5863}
5864
5865void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5866{
5867 for (int i = 0; i < n; i++)
5868 {
5869 GLuint transformFeedback = ids[i];
5870 if (transformFeedback == 0)
5871 {
5872 continue;
5873 }
5874
5875 TransformFeedback *transformFeedbackObject = nullptr;
5876 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5877 {
5878 if (transformFeedbackObject != nullptr)
5879 {
5880 detachTransformFeedback(transformFeedback);
5881 transformFeedbackObject->release(this);
5882 }
5883
5884 mTransformFeedbackHandleAllocator.release(transformFeedback);
5885 }
5886 }
5887}
5888
5889void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5890{
5891 for (int i = 0; i < n; i++)
5892 {
5893 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5894 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5895 ids[i] = transformFeedback;
5896 }
5897}
5898
5899bool Context::isTransformFeedback(GLuint id)
5900{
5901 if (id == 0)
5902 {
5903 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5904 // returns FALSE
5905 return GL_FALSE;
5906 }
5907
5908 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5909 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5910}
5911
5912void Context::pauseTransformFeedback()
5913{
5914 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5915 transformFeedback->pause();
5916}
5917
5918void Context::resumeTransformFeedback()
5919{
5920 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5921 transformFeedback->resume();
5922}
5923
Jamie Madill12e957f2017-08-26 21:42:26 -04005924void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5925{
5926 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005927 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005928}
5929
Brandon Jones59770802018-04-02 13:18:42 -07005930void Context::getUniformuivRobust(GLuint program,
5931 GLint location,
5932 GLsizei bufSize,
5933 GLsizei *length,
5934 GLuint *params)
5935{
5936 getUniformuiv(program, location, params);
5937}
5938
Jamie Madill12e957f2017-08-26 21:42:26 -04005939GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5940{
5941 const Program *programObject = getProgram(program);
5942 return programObject->getFragDataLocation(name);
5943}
5944
5945void Context::getUniformIndices(GLuint program,
5946 GLsizei uniformCount,
5947 const GLchar *const *uniformNames,
5948 GLuint *uniformIndices)
5949{
5950 const Program *programObject = getProgram(program);
5951 if (!programObject->isLinked())
5952 {
5953 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5954 {
5955 uniformIndices[uniformId] = GL_INVALID_INDEX;
5956 }
5957 }
5958 else
5959 {
5960 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5961 {
5962 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5963 }
5964 }
5965}
5966
5967void Context::getActiveUniformsiv(GLuint program,
5968 GLsizei uniformCount,
5969 const GLuint *uniformIndices,
5970 GLenum pname,
5971 GLint *params)
5972{
5973 const Program *programObject = getProgram(program);
5974 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5975 {
5976 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005977 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005978 }
5979}
5980
5981GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5982{
5983 const Program *programObject = getProgram(program);
5984 return programObject->getUniformBlockIndex(uniformBlockName);
5985}
5986
5987void Context::getActiveUniformBlockiv(GLuint program,
5988 GLuint uniformBlockIndex,
5989 GLenum pname,
5990 GLint *params)
5991{
5992 const Program *programObject = getProgram(program);
5993 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5994}
5995
Brandon Jones59770802018-04-02 13:18:42 -07005996void Context::getActiveUniformBlockivRobust(GLuint program,
5997 GLuint uniformBlockIndex,
5998 GLenum pname,
5999 GLsizei bufSize,
6000 GLsizei *length,
6001 GLint *params)
6002{
6003 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6004}
6005
Jamie Madill12e957f2017-08-26 21:42:26 -04006006void Context::getActiveUniformBlockName(GLuint program,
6007 GLuint uniformBlockIndex,
6008 GLsizei bufSize,
6009 GLsizei *length,
6010 GLchar *uniformBlockName)
6011{
6012 const Program *programObject = getProgram(program);
6013 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6014}
6015
6016void Context::uniformBlockBinding(GLuint program,
6017 GLuint uniformBlockIndex,
6018 GLuint uniformBlockBinding)
6019{
6020 Program *programObject = getProgram(program);
6021 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6022}
6023
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006024GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6025{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006026 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6027 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006028
Jamie Madill70b5bb02017-08-28 13:32:37 -04006029 Sync *syncObject = getSync(syncHandle);
6030 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006031 if (error.isError())
6032 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006033 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006034 handleError(error);
6035 return nullptr;
6036 }
6037
Jamie Madill70b5bb02017-08-28 13:32:37 -04006038 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006039}
6040
6041GLboolean Context::isSync(GLsync sync)
6042{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006043 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006044}
6045
6046GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6047{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006048 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006049
6050 GLenum result = GL_WAIT_FAILED;
6051 handleError(syncObject->clientWait(flags, timeout, &result));
6052 return result;
6053}
6054
6055void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6056{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006057 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006058 handleError(syncObject->serverWait(flags, timeout));
6059}
6060
6061void Context::getInteger64v(GLenum pname, GLint64 *params)
6062{
6063 GLenum nativeType = GL_NONE;
6064 unsigned int numParams = 0;
6065 getQueryParameterInfo(pname, &nativeType, &numParams);
6066
6067 if (nativeType == GL_INT_64_ANGLEX)
6068 {
6069 getInteger64vImpl(pname, params);
6070 }
6071 else
6072 {
6073 CastStateValues(this, nativeType, pname, numParams, params);
6074 }
6075}
6076
Brandon Jones59770802018-04-02 13:18:42 -07006077void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6078{
6079 getInteger64v(pname, data);
6080}
6081
Corentin Wallez336129f2017-10-17 15:55:40 -04006082void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006083{
6084 Buffer *buffer = mGLState.getTargetBuffer(target);
6085 QueryBufferParameteri64v(buffer, pname, params);
6086}
6087
Brandon Jones59770802018-04-02 13:18:42 -07006088void Context::getBufferParameteri64vRobust(BufferBinding target,
6089 GLenum pname,
6090 GLsizei bufSize,
6091 GLsizei *length,
6092 GLint64 *params)
6093{
6094 getBufferParameteri64v(target, pname, params);
6095}
6096
Jamie Madill3ef140a2017-08-26 23:11:21 -04006097void Context::genSamplers(GLsizei count, GLuint *samplers)
6098{
6099 for (int i = 0; i < count; i++)
6100 {
6101 samplers[i] = mState.mSamplers->createSampler();
6102 }
6103}
6104
6105void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6106{
6107 for (int i = 0; i < count; i++)
6108 {
6109 GLuint sampler = samplers[i];
6110
6111 if (mState.mSamplers->getSampler(sampler))
6112 {
6113 detachSampler(sampler);
6114 }
6115
6116 mState.mSamplers->deleteObject(this, sampler);
6117 }
6118}
6119
6120void Context::getInternalformativ(GLenum target,
6121 GLenum internalformat,
6122 GLenum pname,
6123 GLsizei bufSize,
6124 GLint *params)
6125{
6126 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6127 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6128}
6129
Brandon Jones59770802018-04-02 13:18:42 -07006130void Context::getInternalformativRobust(GLenum target,
6131 GLenum internalformat,
6132 GLenum pname,
6133 GLsizei bufSize,
6134 GLsizei *length,
6135 GLint *params)
6136{
6137 getInternalformativ(target, internalformat, pname, bufSize, params);
6138}
6139
Jiajia Qin5451d532017-11-16 17:16:34 +08006140void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6141{
6142 programUniform1iv(program, location, 1, &v0);
6143}
6144
6145void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6146{
6147 GLint xy[2] = {v0, v1};
6148 programUniform2iv(program, location, 1, xy);
6149}
6150
6151void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6152{
6153 GLint xyz[3] = {v0, v1, v2};
6154 programUniform3iv(program, location, 1, xyz);
6155}
6156
6157void Context::programUniform4i(GLuint program,
6158 GLint location,
6159 GLint v0,
6160 GLint v1,
6161 GLint v2,
6162 GLint v3)
6163{
6164 GLint xyzw[4] = {v0, v1, v2, v3};
6165 programUniform4iv(program, location, 1, xyzw);
6166}
6167
6168void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6169{
6170 programUniform1uiv(program, location, 1, &v0);
6171}
6172
6173void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6174{
6175 GLuint xy[2] = {v0, v1};
6176 programUniform2uiv(program, location, 1, xy);
6177}
6178
6179void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6180{
6181 GLuint xyz[3] = {v0, v1, v2};
6182 programUniform3uiv(program, location, 1, xyz);
6183}
6184
6185void Context::programUniform4ui(GLuint program,
6186 GLint location,
6187 GLuint v0,
6188 GLuint v1,
6189 GLuint v2,
6190 GLuint v3)
6191{
6192 GLuint xyzw[4] = {v0, v1, v2, v3};
6193 programUniform4uiv(program, location, 1, xyzw);
6194}
6195
6196void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6197{
6198 programUniform1fv(program, location, 1, &v0);
6199}
6200
6201void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6202{
6203 GLfloat xy[2] = {v0, v1};
6204 programUniform2fv(program, location, 1, xy);
6205}
6206
6207void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6208{
6209 GLfloat xyz[3] = {v0, v1, v2};
6210 programUniform3fv(program, location, 1, xyz);
6211}
6212
6213void Context::programUniform4f(GLuint program,
6214 GLint location,
6215 GLfloat v0,
6216 GLfloat v1,
6217 GLfloat v2,
6218 GLfloat v3)
6219{
6220 GLfloat xyzw[4] = {v0, v1, v2, v3};
6221 programUniform4fv(program, location, 1, xyzw);
6222}
6223
Jamie Madill81c2e252017-09-09 23:32:46 -04006224void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6225{
6226 Program *programObject = getProgram(program);
6227 ASSERT(programObject);
6228 if (programObject->setUniform1iv(location, count, value) ==
6229 Program::SetUniformResult::SamplerChanged)
6230 {
6231 mGLState.setObjectDirty(GL_PROGRAM);
6232 }
6233}
6234
Jiajia Qin5451d532017-11-16 17:16:34 +08006235void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6236{
6237 Program *programObject = getProgram(program);
6238 ASSERT(programObject);
6239 programObject->setUniform2iv(location, count, value);
6240}
6241
6242void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6243{
6244 Program *programObject = getProgram(program);
6245 ASSERT(programObject);
6246 programObject->setUniform3iv(location, count, value);
6247}
6248
6249void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6250{
6251 Program *programObject = getProgram(program);
6252 ASSERT(programObject);
6253 programObject->setUniform4iv(location, count, value);
6254}
6255
6256void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6257{
6258 Program *programObject = getProgram(program);
6259 ASSERT(programObject);
6260 programObject->setUniform1uiv(location, count, value);
6261}
6262
6263void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6264{
6265 Program *programObject = getProgram(program);
6266 ASSERT(programObject);
6267 programObject->setUniform2uiv(location, count, value);
6268}
6269
6270void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6271{
6272 Program *programObject = getProgram(program);
6273 ASSERT(programObject);
6274 programObject->setUniform3uiv(location, count, value);
6275}
6276
6277void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6278{
6279 Program *programObject = getProgram(program);
6280 ASSERT(programObject);
6281 programObject->setUniform4uiv(location, count, value);
6282}
6283
6284void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6285{
6286 Program *programObject = getProgram(program);
6287 ASSERT(programObject);
6288 programObject->setUniform1fv(location, count, value);
6289}
6290
6291void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6292{
6293 Program *programObject = getProgram(program);
6294 ASSERT(programObject);
6295 programObject->setUniform2fv(location, count, value);
6296}
6297
6298void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6299{
6300 Program *programObject = getProgram(program);
6301 ASSERT(programObject);
6302 programObject->setUniform3fv(location, count, value);
6303}
6304
6305void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6306{
6307 Program *programObject = getProgram(program);
6308 ASSERT(programObject);
6309 programObject->setUniform4fv(location, count, value);
6310}
6311
6312void Context::programUniformMatrix2fv(GLuint program,
6313 GLint location,
6314 GLsizei count,
6315 GLboolean transpose,
6316 const GLfloat *value)
6317{
6318 Program *programObject = getProgram(program);
6319 ASSERT(programObject);
6320 programObject->setUniformMatrix2fv(location, count, transpose, value);
6321}
6322
6323void Context::programUniformMatrix3fv(GLuint program,
6324 GLint location,
6325 GLsizei count,
6326 GLboolean transpose,
6327 const GLfloat *value)
6328{
6329 Program *programObject = getProgram(program);
6330 ASSERT(programObject);
6331 programObject->setUniformMatrix3fv(location, count, transpose, value);
6332}
6333
6334void Context::programUniformMatrix4fv(GLuint program,
6335 GLint location,
6336 GLsizei count,
6337 GLboolean transpose,
6338 const GLfloat *value)
6339{
6340 Program *programObject = getProgram(program);
6341 ASSERT(programObject);
6342 programObject->setUniformMatrix4fv(location, count, transpose, value);
6343}
6344
6345void Context::programUniformMatrix2x3fv(GLuint program,
6346 GLint location,
6347 GLsizei count,
6348 GLboolean transpose,
6349 const GLfloat *value)
6350{
6351 Program *programObject = getProgram(program);
6352 ASSERT(programObject);
6353 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6354}
6355
6356void Context::programUniformMatrix3x2fv(GLuint program,
6357 GLint location,
6358 GLsizei count,
6359 GLboolean transpose,
6360 const GLfloat *value)
6361{
6362 Program *programObject = getProgram(program);
6363 ASSERT(programObject);
6364 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6365}
6366
6367void Context::programUniformMatrix2x4fv(GLuint program,
6368 GLint location,
6369 GLsizei count,
6370 GLboolean transpose,
6371 const GLfloat *value)
6372{
6373 Program *programObject = getProgram(program);
6374 ASSERT(programObject);
6375 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6376}
6377
6378void Context::programUniformMatrix4x2fv(GLuint program,
6379 GLint location,
6380 GLsizei count,
6381 GLboolean transpose,
6382 const GLfloat *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
6386 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6387}
6388
6389void Context::programUniformMatrix3x4fv(GLuint program,
6390 GLint location,
6391 GLsizei count,
6392 GLboolean transpose,
6393 const GLfloat *value)
6394{
6395 Program *programObject = getProgram(program);
6396 ASSERT(programObject);
6397 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6398}
6399
6400void Context::programUniformMatrix4x3fv(GLuint program,
6401 GLint location,
6402 GLsizei count,
6403 GLboolean transpose,
6404 const GLfloat *value)
6405{
6406 Program *programObject = getProgram(program);
6407 ASSERT(programObject);
6408 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6409}
6410
Jamie Madill81c2e252017-09-09 23:32:46 -04006411void Context::onTextureChange(const Texture *texture)
6412{
6413 // Conservatively assume all textures are dirty.
6414 // TODO(jmadill): More fine-grained update.
6415 mGLState.setObjectDirty(GL_TEXTURE);
6416}
6417
James Darpiniane8a93c62018-01-04 18:02:24 -08006418bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6419{
6420 return mGLState.isCurrentTransformFeedback(tf);
6421}
6422bool Context::isCurrentVertexArray(const VertexArray *va) const
6423{
6424 return mGLState.isCurrentVertexArray(va);
6425}
6426
Yunchao Hea336b902017-08-02 16:05:21 +08006427void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6428{
6429 for (int i = 0; i < count; i++)
6430 {
6431 pipelines[i] = createProgramPipeline();
6432 }
6433}
6434
6435void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6436{
6437 for (int i = 0; i < count; i++)
6438 {
6439 if (pipelines[i] != 0)
6440 {
6441 deleteProgramPipeline(pipelines[i]);
6442 }
6443 }
6444}
6445
6446GLboolean Context::isProgramPipeline(GLuint pipeline)
6447{
6448 if (pipeline == 0)
6449 {
6450 return GL_FALSE;
6451 }
6452
6453 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6454}
6455
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006456void Context::finishFenceNV(GLuint fence)
6457{
6458 FenceNV *fenceObject = getFenceNV(fence);
6459
6460 ASSERT(fenceObject && fenceObject->isSet());
6461 handleError(fenceObject->finish());
6462}
6463
6464void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6465{
6466 FenceNV *fenceObject = getFenceNV(fence);
6467
6468 ASSERT(fenceObject && fenceObject->isSet());
6469
6470 switch (pname)
6471 {
6472 case GL_FENCE_STATUS_NV:
6473 {
6474 // GL_NV_fence spec:
6475 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6476 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6477 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6478 GLboolean status = GL_TRUE;
6479 if (fenceObject->getStatus() != GL_TRUE)
6480 {
6481 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6482 }
6483 *params = status;
6484 break;
6485 }
6486
6487 case GL_FENCE_CONDITION_NV:
6488 {
6489 *params = static_cast<GLint>(fenceObject->getCondition());
6490 break;
6491 }
6492
6493 default:
6494 UNREACHABLE();
6495 }
6496}
6497
6498void Context::getTranslatedShaderSource(GLuint shader,
6499 GLsizei bufsize,
6500 GLsizei *length,
6501 GLchar *source)
6502{
6503 Shader *shaderObject = getShader(shader);
6504 ASSERT(shaderObject);
6505 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6506}
6507
6508void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
6512
6513 programObject->getUniformfv(this, location, params);
6514}
6515
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006516void Context::getnUniformfvRobust(GLuint program,
6517 GLint location,
6518 GLsizei bufSize,
6519 GLsizei *length,
6520 GLfloat *params)
6521{
6522 UNIMPLEMENTED();
6523}
6524
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006525void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6526{
6527 Program *programObject = getProgram(program);
6528 ASSERT(programObject);
6529
6530 programObject->getUniformiv(this, location, params);
6531}
6532
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006533void Context::getnUniformivRobust(GLuint program,
6534 GLint location,
6535 GLsizei bufSize,
6536 GLsizei *length,
6537 GLint *params)
6538{
6539 UNIMPLEMENTED();
6540}
6541
6542void Context::getnUniformuivRobust(GLuint program,
6543 GLint location,
6544 GLsizei bufSize,
6545 GLsizei *length,
6546 GLuint *params)
6547{
6548 UNIMPLEMENTED();
6549}
6550
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006551GLboolean Context::isFenceNV(GLuint fence)
6552{
6553 FenceNV *fenceObject = getFenceNV(fence);
6554
6555 if (fenceObject == nullptr)
6556 {
6557 return GL_FALSE;
6558 }
6559
6560 // GL_NV_fence spec:
6561 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6562 // existing fence.
6563 return fenceObject->isSet();
6564}
6565
6566void Context::readnPixels(GLint x,
6567 GLint y,
6568 GLsizei width,
6569 GLsizei height,
6570 GLenum format,
6571 GLenum type,
6572 GLsizei bufSize,
6573 void *data)
6574{
6575 return readPixels(x, y, width, height, format, type, data);
6576}
6577
Jamie Madill007530e2017-12-28 14:27:04 -05006578void Context::setFenceNV(GLuint fence, GLenum condition)
6579{
6580 ASSERT(condition == GL_ALL_COMPLETED_NV);
6581
6582 FenceNV *fenceObject = getFenceNV(fence);
6583 ASSERT(fenceObject != nullptr);
6584 handleError(fenceObject->set(condition));
6585}
6586
6587GLboolean Context::testFenceNV(GLuint fence)
6588{
6589 FenceNV *fenceObject = getFenceNV(fence);
6590
6591 ASSERT(fenceObject != nullptr);
6592 ASSERT(fenceObject->isSet() == GL_TRUE);
6593
6594 GLboolean result = GL_TRUE;
6595 Error error = fenceObject->test(&result);
6596 if (error.isError())
6597 {
6598 handleError(error);
6599 return GL_TRUE;
6600 }
6601
6602 return result;
6603}
6604
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006605void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006606{
6607 Texture *texture = getTargetTexture(target);
6608 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006609 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006610}
6611
Jamie Madillfa920eb2018-01-04 11:45:50 -05006612void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006613{
6614 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6615 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6616 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6617}
6618
Jamie Madillfa920eb2018-01-04 11:45:50 -05006619void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6620{
6621 UNIMPLEMENTED();
6622}
6623
Jamie Madill5b772312018-03-08 20:28:32 -05006624bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6625{
6626 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6627 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6628 // to the fact that it is stored internally as a float, and so would require conversion
6629 // if returned from Context::getIntegerv. Since this conversion is already implemented
6630 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6631 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6632 // application.
6633 switch (pname)
6634 {
6635 case GL_COMPRESSED_TEXTURE_FORMATS:
6636 {
6637 *type = GL_INT;
6638 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6639 return true;
6640 }
6641 case GL_SHADER_BINARY_FORMATS:
6642 {
6643 *type = GL_INT;
6644 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6645 return true;
6646 }
6647
6648 case GL_MAX_VERTEX_ATTRIBS:
6649 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6650 case GL_MAX_VARYING_VECTORS:
6651 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6652 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6653 case GL_MAX_TEXTURE_IMAGE_UNITS:
6654 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6655 case GL_MAX_RENDERBUFFER_SIZE:
6656 case GL_NUM_SHADER_BINARY_FORMATS:
6657 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6658 case GL_ARRAY_BUFFER_BINDING:
6659 case GL_FRAMEBUFFER_BINDING:
6660 case GL_RENDERBUFFER_BINDING:
6661 case GL_CURRENT_PROGRAM:
6662 case GL_PACK_ALIGNMENT:
6663 case GL_UNPACK_ALIGNMENT:
6664 case GL_GENERATE_MIPMAP_HINT:
6665 case GL_RED_BITS:
6666 case GL_GREEN_BITS:
6667 case GL_BLUE_BITS:
6668 case GL_ALPHA_BITS:
6669 case GL_DEPTH_BITS:
6670 case GL_STENCIL_BITS:
6671 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6672 case GL_CULL_FACE_MODE:
6673 case GL_FRONT_FACE:
6674 case GL_ACTIVE_TEXTURE:
6675 case GL_STENCIL_FUNC:
6676 case GL_STENCIL_VALUE_MASK:
6677 case GL_STENCIL_REF:
6678 case GL_STENCIL_FAIL:
6679 case GL_STENCIL_PASS_DEPTH_FAIL:
6680 case GL_STENCIL_PASS_DEPTH_PASS:
6681 case GL_STENCIL_BACK_FUNC:
6682 case GL_STENCIL_BACK_VALUE_MASK:
6683 case GL_STENCIL_BACK_REF:
6684 case GL_STENCIL_BACK_FAIL:
6685 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6686 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6687 case GL_DEPTH_FUNC:
6688 case GL_BLEND_SRC_RGB:
6689 case GL_BLEND_SRC_ALPHA:
6690 case GL_BLEND_DST_RGB:
6691 case GL_BLEND_DST_ALPHA:
6692 case GL_BLEND_EQUATION_RGB:
6693 case GL_BLEND_EQUATION_ALPHA:
6694 case GL_STENCIL_WRITEMASK:
6695 case GL_STENCIL_BACK_WRITEMASK:
6696 case GL_STENCIL_CLEAR_VALUE:
6697 case GL_SUBPIXEL_BITS:
6698 case GL_MAX_TEXTURE_SIZE:
6699 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6700 case GL_SAMPLE_BUFFERS:
6701 case GL_SAMPLES:
6702 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6703 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6704 case GL_TEXTURE_BINDING_2D:
6705 case GL_TEXTURE_BINDING_CUBE_MAP:
6706 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6707 {
6708 *type = GL_INT;
6709 *numParams = 1;
6710 return true;
6711 }
6712 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6713 {
6714 if (!getExtensions().packReverseRowOrder)
6715 {
6716 return false;
6717 }
6718 *type = GL_INT;
6719 *numParams = 1;
6720 return true;
6721 }
6722 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6723 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6724 {
6725 if (!getExtensions().textureRectangle)
6726 {
6727 return false;
6728 }
6729 *type = GL_INT;
6730 *numParams = 1;
6731 return true;
6732 }
6733 case GL_MAX_DRAW_BUFFERS_EXT:
6734 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6735 {
6736 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6737 {
6738 return false;
6739 }
6740 *type = GL_INT;
6741 *numParams = 1;
6742 return true;
6743 }
6744 case GL_MAX_VIEWPORT_DIMS:
6745 {
6746 *type = GL_INT;
6747 *numParams = 2;
6748 return true;
6749 }
6750 case GL_VIEWPORT:
6751 case GL_SCISSOR_BOX:
6752 {
6753 *type = GL_INT;
6754 *numParams = 4;
6755 return true;
6756 }
6757 case GL_SHADER_COMPILER:
6758 case GL_SAMPLE_COVERAGE_INVERT:
6759 case GL_DEPTH_WRITEMASK:
6760 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6761 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6762 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6763 // bool-natural
6764 case GL_SAMPLE_COVERAGE:
6765 case GL_SCISSOR_TEST:
6766 case GL_STENCIL_TEST:
6767 case GL_DEPTH_TEST:
6768 case GL_BLEND:
6769 case GL_DITHER:
6770 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6771 {
6772 *type = GL_BOOL;
6773 *numParams = 1;
6774 return true;
6775 }
6776 case GL_COLOR_WRITEMASK:
6777 {
6778 *type = GL_BOOL;
6779 *numParams = 4;
6780 return true;
6781 }
6782 case GL_POLYGON_OFFSET_FACTOR:
6783 case GL_POLYGON_OFFSET_UNITS:
6784 case GL_SAMPLE_COVERAGE_VALUE:
6785 case GL_DEPTH_CLEAR_VALUE:
6786 case GL_LINE_WIDTH:
6787 {
6788 *type = GL_FLOAT;
6789 *numParams = 1;
6790 return true;
6791 }
6792 case GL_ALIASED_LINE_WIDTH_RANGE:
6793 case GL_ALIASED_POINT_SIZE_RANGE:
6794 case GL_DEPTH_RANGE:
6795 {
6796 *type = GL_FLOAT;
6797 *numParams = 2;
6798 return true;
6799 }
6800 case GL_COLOR_CLEAR_VALUE:
6801 case GL_BLEND_COLOR:
6802 {
6803 *type = GL_FLOAT;
6804 *numParams = 4;
6805 return true;
6806 }
6807 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6808 if (!getExtensions().textureFilterAnisotropic)
6809 {
6810 return false;
6811 }
6812 *type = GL_FLOAT;
6813 *numParams = 1;
6814 return true;
6815 case GL_TIMESTAMP_EXT:
6816 if (!getExtensions().disjointTimerQuery)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT_64_ANGLEX;
6821 *numParams = 1;
6822 return true;
6823 case GL_GPU_DISJOINT_EXT:
6824 if (!getExtensions().disjointTimerQuery)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT;
6829 *numParams = 1;
6830 return true;
6831 case GL_COVERAGE_MODULATION_CHROMIUM:
6832 if (!getExtensions().framebufferMixedSamples)
6833 {
6834 return false;
6835 }
6836 *type = GL_INT;
6837 *numParams = 1;
6838 return true;
6839 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6840 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6841 {
6842 return false;
6843 }
6844 *type = GL_INT;
6845 *numParams = 1;
6846 return true;
6847 }
6848
6849 if (getExtensions().debug)
6850 {
6851 switch (pname)
6852 {
6853 case GL_DEBUG_LOGGED_MESSAGES:
6854 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6855 case GL_DEBUG_GROUP_STACK_DEPTH:
6856 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6857 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6858 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6859 case GL_MAX_LABEL_LENGTH:
6860 *type = GL_INT;
6861 *numParams = 1;
6862 return true;
6863
6864 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6865 case GL_DEBUG_OUTPUT:
6866 *type = GL_BOOL;
6867 *numParams = 1;
6868 return true;
6869 }
6870 }
6871
6872 if (getExtensions().multisampleCompatibility)
6873 {
6874 switch (pname)
6875 {
6876 case GL_MULTISAMPLE_EXT:
6877 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6878 *type = GL_BOOL;
6879 *numParams = 1;
6880 return true;
6881 }
6882 }
6883
6884 if (getExtensions().pathRendering)
6885 {
6886 switch (pname)
6887 {
6888 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6889 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6890 *type = GL_FLOAT;
6891 *numParams = 16;
6892 return true;
6893 }
6894 }
6895
6896 if (getExtensions().bindGeneratesResource)
6897 {
6898 switch (pname)
6899 {
6900 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6901 *type = GL_BOOL;
6902 *numParams = 1;
6903 return true;
6904 }
6905 }
6906
6907 if (getExtensions().clientArrays)
6908 {
6909 switch (pname)
6910 {
6911 case GL_CLIENT_ARRAYS_ANGLE:
6912 *type = GL_BOOL;
6913 *numParams = 1;
6914 return true;
6915 }
6916 }
6917
6918 if (getExtensions().sRGBWriteControl)
6919 {
6920 switch (pname)
6921 {
6922 case GL_FRAMEBUFFER_SRGB_EXT:
6923 *type = GL_BOOL;
6924 *numParams = 1;
6925 return true;
6926 }
6927 }
6928
6929 if (getExtensions().robustResourceInitialization &&
6930 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6931 {
6932 *type = GL_BOOL;
6933 *numParams = 1;
6934 return true;
6935 }
6936
6937 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6938 {
6939 *type = GL_BOOL;
6940 *numParams = 1;
6941 return true;
6942 }
6943
6944 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6945 switch (pname)
6946 {
6947 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6948 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6949 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6950 {
6951 return false;
6952 }
6953 *type = GL_INT;
6954 *numParams = 1;
6955 return true;
6956
6957 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6958 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6959 {
6960 return false;
6961 }
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965
6966 case GL_PROGRAM_BINARY_FORMATS_OES:
6967 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6968 {
6969 return false;
6970 }
6971 *type = GL_INT;
6972 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6973 return true;
6974
6975 case GL_PACK_ROW_LENGTH:
6976 case GL_PACK_SKIP_ROWS:
6977 case GL_PACK_SKIP_PIXELS:
6978 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6979 {
6980 return false;
6981 }
6982 *type = GL_INT;
6983 *numParams = 1;
6984 return true;
6985 case GL_UNPACK_ROW_LENGTH:
6986 case GL_UNPACK_SKIP_ROWS:
6987 case GL_UNPACK_SKIP_PIXELS:
6988 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6989 {
6990 return false;
6991 }
6992 *type = GL_INT;
6993 *numParams = 1;
6994 return true;
6995 case GL_VERTEX_ARRAY_BINDING:
6996 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6997 {
6998 return false;
6999 }
7000 *type = GL_INT;
7001 *numParams = 1;
7002 return true;
7003 case GL_PIXEL_PACK_BUFFER_BINDING:
7004 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7005 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7006 {
7007 return false;
7008 }
7009 *type = GL_INT;
7010 *numParams = 1;
7011 return true;
7012 case GL_MAX_SAMPLES:
7013 {
7014 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7015 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7016 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7017 {
7018 return false;
7019 }
7020 *type = GL_INT;
7021 *numParams = 1;
7022 return true;
7023
7024 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7025 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7026 {
7027 return false;
7028 }
7029 *type = GL_INT;
7030 *numParams = 1;
7031 return true;
7032 }
7033 }
7034
7035 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7036 {
7037 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7038 {
7039 return false;
7040 }
7041 *type = GL_INT;
7042 *numParams = 1;
7043 return true;
7044 }
7045
7046 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7047 {
7048 *type = GL_INT;
7049 *numParams = 1;
7050 return true;
7051 }
7052
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007053 if (getClientVersion() < Version(2, 0))
7054 {
7055 switch (pname)
7056 {
7057 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007058 case GL_CLIENT_ACTIVE_TEXTURE:
7059 case GL_MATRIX_MODE:
7060 case GL_MAX_TEXTURE_UNITS:
7061 case GL_MAX_MODELVIEW_STACK_DEPTH:
7062 case GL_MAX_PROJECTION_STACK_DEPTH:
7063 case GL_MAX_TEXTURE_STACK_DEPTH:
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 Yang13b708f2018-03-21 12:14:10 -07007082 *type = GL_INT;
7083 *numParams = 1;
7084 return true;
7085 case GL_ALPHA_TEST_REF:
7086 *type = GL_FLOAT;
7087 *numParams = 1;
7088 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007089 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007090 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007091 *type = GL_FLOAT;
7092 *numParams = 4;
7093 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007094 case GL_CURRENT_NORMAL:
7095 *type = GL_FLOAT;
7096 *numParams = 3;
7097 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007098 case GL_MODELVIEW_MATRIX:
7099 case GL_PROJECTION_MATRIX:
7100 case GL_TEXTURE_MATRIX:
7101 *type = GL_FLOAT;
7102 *numParams = 16;
7103 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007104 }
7105 }
7106
Jamie Madill5b772312018-03-08 20:28:32 -05007107 if (getClientVersion() < Version(3, 0))
7108 {
7109 return false;
7110 }
7111
7112 // Check for ES3.0+ parameter names
7113 switch (pname)
7114 {
7115 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7116 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7117 case GL_UNIFORM_BUFFER_BINDING:
7118 case GL_TRANSFORM_FEEDBACK_BINDING:
7119 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7120 case GL_COPY_READ_BUFFER_BINDING:
7121 case GL_COPY_WRITE_BUFFER_BINDING:
7122 case GL_SAMPLER_BINDING:
7123 case GL_READ_BUFFER:
7124 case GL_TEXTURE_BINDING_3D:
7125 case GL_TEXTURE_BINDING_2D_ARRAY:
7126 case GL_MAX_3D_TEXTURE_SIZE:
7127 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7128 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7129 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7130 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7131 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7132 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7133 case GL_MAX_VARYING_COMPONENTS:
7134 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7135 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7136 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7137 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7138 case GL_NUM_EXTENSIONS:
7139 case GL_MAJOR_VERSION:
7140 case GL_MINOR_VERSION:
7141 case GL_MAX_ELEMENTS_INDICES:
7142 case GL_MAX_ELEMENTS_VERTICES:
7143 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7144 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7145 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7146 case GL_UNPACK_IMAGE_HEIGHT:
7147 case GL_UNPACK_SKIP_IMAGES:
7148 {
7149 *type = GL_INT;
7150 *numParams = 1;
7151 return true;
7152 }
7153
7154 case GL_MAX_ELEMENT_INDEX:
7155 case GL_MAX_UNIFORM_BLOCK_SIZE:
7156 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7157 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7158 case GL_MAX_SERVER_WAIT_TIMEOUT:
7159 {
7160 *type = GL_INT_64_ANGLEX;
7161 *numParams = 1;
7162 return true;
7163 }
7164
7165 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7166 case GL_TRANSFORM_FEEDBACK_PAUSED:
7167 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7168 case GL_RASTERIZER_DISCARD:
7169 {
7170 *type = GL_BOOL;
7171 *numParams = 1;
7172 return true;
7173 }
7174
7175 case GL_MAX_TEXTURE_LOD_BIAS:
7176 {
7177 *type = GL_FLOAT;
7178 *numParams = 1;
7179 return true;
7180 }
7181 }
7182
7183 if (getExtensions().requestExtension)
7184 {
7185 switch (pname)
7186 {
7187 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7188 *type = GL_INT;
7189 *numParams = 1;
7190 return true;
7191 }
7192 }
7193
7194 if (getClientVersion() < Version(3, 1))
7195 {
7196 return false;
7197 }
7198
7199 switch (pname)
7200 {
7201 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7202 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7203 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7204 case GL_MAX_FRAMEBUFFER_WIDTH:
7205 case GL_MAX_FRAMEBUFFER_HEIGHT:
7206 case GL_MAX_FRAMEBUFFER_SAMPLES:
7207 case GL_MAX_SAMPLE_MASK_WORDS:
7208 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7209 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7210 case GL_MAX_INTEGER_SAMPLES:
7211 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7212 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7213 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7214 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7215 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7216 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7217 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7218 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7219 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7220 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7221 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7222 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7223 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7224 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7225 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7226 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7227 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7228 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7229 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7230 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7231 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7232 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7233 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7234 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7235 case GL_MAX_UNIFORM_LOCATIONS:
7236 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7237 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7238 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7239 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7240 case GL_MAX_IMAGE_UNITS:
7241 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7242 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7243 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7244 case GL_SHADER_STORAGE_BUFFER_BINDING:
7245 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7246 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7247 *type = GL_INT;
7248 *numParams = 1;
7249 return true;
7250 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7251 *type = GL_INT_64_ANGLEX;
7252 *numParams = 1;
7253 return true;
7254 case GL_SAMPLE_MASK:
7255 *type = GL_BOOL;
7256 *numParams = 1;
7257 return true;
7258 }
7259
7260 if (getExtensions().geometryShader)
7261 {
7262 switch (pname)
7263 {
7264 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7265 case GL_LAYER_PROVOKING_VERTEX_EXT:
7266 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7267 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7268 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7269 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7270 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7271 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7272 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7273 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7274 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7275 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7276 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7277 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7278 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7279 *type = GL_INT;
7280 *numParams = 1;
7281 return true;
7282 }
7283 }
7284
7285 return false;
7286}
7287
7288bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7289{
7290 if (getClientVersion() < Version(3, 0))
7291 {
7292 return false;
7293 }
7294
7295 switch (target)
7296 {
7297 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7298 case GL_UNIFORM_BUFFER_BINDING:
7299 {
7300 *type = GL_INT;
7301 *numParams = 1;
7302 return true;
7303 }
7304 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7305 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7306 case GL_UNIFORM_BUFFER_START:
7307 case GL_UNIFORM_BUFFER_SIZE:
7308 {
7309 *type = GL_INT_64_ANGLEX;
7310 *numParams = 1;
7311 return true;
7312 }
7313 }
7314
7315 if (getClientVersion() < Version(3, 1))
7316 {
7317 return false;
7318 }
7319
7320 switch (target)
7321 {
7322 case GL_IMAGE_BINDING_LAYERED:
7323 {
7324 *type = GL_BOOL;
7325 *numParams = 1;
7326 return true;
7327 }
7328 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7329 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7330 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7331 case GL_SHADER_STORAGE_BUFFER_BINDING:
7332 case GL_VERTEX_BINDING_BUFFER:
7333 case GL_VERTEX_BINDING_DIVISOR:
7334 case GL_VERTEX_BINDING_OFFSET:
7335 case GL_VERTEX_BINDING_STRIDE:
7336 case GL_SAMPLE_MASK_VALUE:
7337 case GL_IMAGE_BINDING_NAME:
7338 case GL_IMAGE_BINDING_LEVEL:
7339 case GL_IMAGE_BINDING_LAYER:
7340 case GL_IMAGE_BINDING_ACCESS:
7341 case GL_IMAGE_BINDING_FORMAT:
7342 {
7343 *type = GL_INT;
7344 *numParams = 1;
7345 return true;
7346 }
7347 case GL_ATOMIC_COUNTER_BUFFER_START:
7348 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7349 case GL_SHADER_STORAGE_BUFFER_START:
7350 case GL_SHADER_STORAGE_BUFFER_SIZE:
7351 {
7352 *type = GL_INT_64_ANGLEX;
7353 *numParams = 1;
7354 return true;
7355 }
7356 }
7357
7358 return false;
7359}
7360
7361Program *Context::getProgram(GLuint handle) const
7362{
7363 return mState.mShaderPrograms->getProgram(handle);
7364}
7365
7366Shader *Context::getShader(GLuint handle) const
7367{
7368 return mState.mShaderPrograms->getShader(handle);
7369}
7370
7371bool Context::isTextureGenerated(GLuint texture) const
7372{
7373 return mState.mTextures->isHandleGenerated(texture);
7374}
7375
7376bool Context::isBufferGenerated(GLuint buffer) const
7377{
7378 return mState.mBuffers->isHandleGenerated(buffer);
7379}
7380
7381bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7382{
7383 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7384}
7385
7386bool Context::isFramebufferGenerated(GLuint framebuffer) const
7387{
7388 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7389}
7390
7391bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7392{
7393 return mState.mPipelines->isHandleGenerated(pipeline);
7394}
7395
7396bool Context::usingDisplayTextureShareGroup() const
7397{
7398 return mDisplayTextureShareGroup;
7399}
7400
7401GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7402{
7403 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7404 internalformat == GL_DEPTH_STENCIL
7405 ? GL_DEPTH24_STENCIL8
7406 : internalformat;
7407}
7408
Jamie Madillc29968b2016-01-20 11:17:23 -05007409} // namespace gl