blob: 54bc41d01b4e0ffeeaaa52312f700f041fb03edf [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,
Geoff Langb433e872017-10-05 14:01:47 -0400268 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500269 : mState(reinterpret_cast<ContextID>(this),
270 shareContext ? &shareContext->mState : nullptr,
271 shareTextures,
272 GetClientVersion(attribs),
273 &mGLState,
274 mCaps,
275 mTextureCaps,
276 mExtensions,
277 mLimitations),
278 mSkipValidation(GetNoError(attribs)),
279 mDisplayTextureShareGroup(shareTextures != nullptr),
280 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700281 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400282 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400283 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500284 mClientType(EGL_OPENGL_ES_API),
285 mHasBeenCurrent(false),
286 mContextLost(false),
287 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700288 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500289 mResetStrategy(GetResetStrategy(attribs)),
290 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400291 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
292 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500293 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500294 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400295 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400296 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400297 mScratchBuffer(1000u),
298 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000299{
Jamie Madill5b772312018-03-08 20:28:32 -0500300 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400301 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
302 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500303
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400304 mImplementation->setMemoryProgramCache(memoryProgramCache);
305
Geoff Langb433e872017-10-05 14:01:47 -0400306 bool robustResourceInit = GetRobustResourceInit(attribs);
307 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700308 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400309
Jamie Madill4928b7c2017-06-20 12:57:39 -0400310 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400311 GetClientArraysEnabled(attribs), robustResourceInit,
312 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100313
Shannon Woods53a94a82014-06-24 15:20:36 -0400314 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400315
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000316 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400317 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000318 // and cube map texture state vectors respectively associated with them.
319 // In order that access to these initial textures not be lost, they are treated as texture
320 // objects all of whose names are 0.
321
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500324
Corentin Wallez99d492c2018-02-27 15:17:10 -0500325 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327
Geoff Langeb66a6e2016-10-31 13:06:12 -0400328 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400329 {
330 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400333
Corentin Wallez99d492c2018-02-27 15:17:10 -0500334 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800335 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400336 }
Geoff Lang3b573612016-10-31 14:08:10 -0400337 if (getClientVersion() >= Version(3, 1))
338 {
339 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500340 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800341 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800342
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
344 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800345 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800346 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800347
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
349 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400350 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800351 }
Geoff Lang3b573612016-10-31 14:08:10 -0400352 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000353
Geoff Langb0f917f2017-12-05 13:41:54 -0500354 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400355 {
356 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400359 }
360
Geoff Langb0f917f2017-12-05 13:41:54 -0500361 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400362 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400365 }
366
Jamie Madill4928b7c2017-06-20 12:57:39 -0400367 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500368
Jamie Madill57a89722013-07-02 11:57:03 -0400369 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400377 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Corentin Wallez336129f2017-10-17 15:55:40 -0400380 for (auto type : angle::AllEnums<BufferBinding>())
381 {
382 bindBuffer(type, 0);
383 }
384
385 bindRenderbuffer(GL_RENDERBUFFER, 0);
386
387 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
388 {
389 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
390 }
391
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700392 // Initialize GLES1 renderer if appropriate.
393 if (getClientVersion() < Version(2, 0))
394 {
395 mGLES1Renderer.reset(new GLES1Renderer());
396 }
397
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400399 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500401 // No dirty objects.
402
403 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
407
408 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
409 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
411 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
412 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
415 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
416 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
419 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
420
421 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700423 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500424 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400426
Xinghua Cao10a4d432017-11-28 14:46:26 +0800427 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
428 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
429 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
431 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
432 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800433 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800434 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800435
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400436 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437}
438
Jamie Madill4928b7c2017-06-20 12:57:39 -0400439egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700441 if (mGLES1Renderer)
442 {
443 mGLES1Renderer->onDestroy(this, &mGLState);
444 }
445
Jamie Madille7b3fe22018-04-05 09:42:46 -0400446 // Delete the Surface first to trigger a finish() in Vulkan.
Geoff Lang61107632018-05-09 11:32:46 -0400447 if (mSurfacelessFramebuffer)
448 {
449 mSurfacelessFramebuffer->onDestroy(this);
450 SafeDelete(mSurfacelessFramebuffer);
451 }
Jamie Madille7b3fe22018-04-05 09:42:46 -0400452
453 ANGLE_TRY(releaseSurface(display));
454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000456 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400457 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400459 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000460
Corentin Wallez80b24112015-08-25 16:41:57 -0400461 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400463 if (query.second != nullptr)
464 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400465 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400466 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000467 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400468 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000469
Corentin Wallez80b24112015-08-25 16:41:57 -0400470 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400471 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400472 if (vertexArray.second)
473 {
474 vertexArray.second->onDestroy(this);
475 }
Jamie Madill57a89722013-07-02 11:57:03 -0400476 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400477 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400478
Corentin Wallez80b24112015-08-25 16:41:57 -0400479 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500480 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500481 if (transformFeedback.second != nullptr)
482 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500483 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500484 }
Geoff Langc8058452014-02-03 12:04:11 -0500485 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400486 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500487
Jamie Madill5b772312018-03-08 20:28:32 -0500488 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400489 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800490 if (zeroTexture.get() != nullptr)
491 {
492 ANGLE_TRY(zeroTexture->onDestroy(this));
493 zeroTexture.set(this, nullptr);
494 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400495 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496
Jamie Madill2f348d22017-06-05 10:50:59 -0400497 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500498
Jamie Madill4928b7c2017-06-20 12:57:39 -0400499 mGLState.reset(this);
500
Jamie Madill6c1f6712017-02-14 19:08:04 -0500501 mState.mBuffers->release(this);
502 mState.mShaderPrograms->release(this);
503 mState.mTextures->release(this);
504 mState.mRenderbuffers->release(this);
505 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400506 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500507 mState.mPaths->release(this);
508 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800509 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400510
Jamie Madill76e471e2017-10-21 09:56:01 -0400511 mImplementation->onDestroy(this);
512
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514}
515
Jamie Madill70ee0f62017-02-06 16:04:20 -0500516Context::~Context()
517{
518}
519
Jamie Madill4928b7c2017-06-20 12:57:39 -0400520egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521{
Jamie Madill61e16b42017-06-19 11:13:23 -0400522 mCurrentDisplay = display;
523
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000524 if (!mHasBeenCurrent)
525 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000526 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500527 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400528 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000529
Corentin Wallezc295e512017-01-27 17:47:50 -0500530 int width = 0;
531 int height = 0;
532 if (surface != nullptr)
533 {
534 width = surface->getWidth();
535 height = surface->getHeight();
536 }
537
538 mGLState.setViewportParams(0, 0, width, height);
539 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000540
541 mHasBeenCurrent = true;
542 }
543
Jamie Madill1b94d432015-08-07 13:23:23 -0400544 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400546 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400547
Jamie Madill4928b7c2017-06-20 12:57:39 -0400548 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500549
550 Framebuffer *newDefault = nullptr;
551 if (surface != nullptr)
552 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400553 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500554 mCurrentSurface = surface;
555 newDefault = surface->getDefaultFramebuffer();
556 }
557 else
558 {
559 if (mSurfacelessFramebuffer == nullptr)
560 {
561 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
562 }
563
564 newDefault = mSurfacelessFramebuffer;
565 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000566
Corentin Wallez37c39792015-08-20 14:19:46 -0400567 // Update default framebuffer, the binding of the previous default
568 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400569 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700570 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400571 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700572 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400573 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700574 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400575 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700576 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400577 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500578 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400579 }
Ian Ewell292f0052016-02-04 10:37:32 -0500580
581 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400582 mImplementation->onMakeCurrent(this);
583 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584}
585
Jamie Madill4928b7c2017-06-20 12:57:39 -0400586egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400587{
Corentin Wallez37c39792015-08-20 14:19:46 -0400588 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 Framebuffer *currentDefault = nullptr;
590 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400591 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500592 currentDefault = mCurrentSurface->getDefaultFramebuffer();
593 }
594 else if (mSurfacelessFramebuffer != nullptr)
595 {
596 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400597 }
598
Corentin Wallezc295e512017-01-27 17:47:50 -0500599 if (mGLState.getReadFramebuffer() == currentDefault)
600 {
601 mGLState.setReadFramebufferBinding(nullptr);
602 }
603 if (mGLState.getDrawFramebuffer() == currentDefault)
604 {
605 mGLState.setDrawFramebufferBinding(nullptr);
606 }
607 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
608
609 if (mCurrentSurface)
610 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400611 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500612 mCurrentSurface = nullptr;
613 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400614
615 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400616}
617
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618GLuint Context::createBuffer()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
623GLuint Context::createProgram()
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626}
627
Jiawei Shao385b3e02018-03-21 09:43:28 +0800628GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500630 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631}
632
633GLuint Context::createTexture()
634{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500635 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636}
637
638GLuint Context::createRenderbuffer()
639{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500640 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641}
642
Brandon Jones59770802018-04-02 13:18:42 -0700643GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300644{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500645 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300646 if (resultOrError.isError())
647 {
648 handleError(resultOrError.getError());
649 return 0;
650 }
651 return resultOrError.getResult();
652}
653
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654// Returns an unused framebuffer name
655GLuint Context::createFramebuffer()
656{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500657 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658}
659
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500660void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500662 for (int i = 0; i < n; i++)
663 {
664 GLuint handle = mFenceNVHandleAllocator.allocate();
665 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
666 fences[i] = handle;
667 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
Yunchao Hea336b902017-08-02 16:05:21 +0800670GLuint Context::createProgramPipeline()
671{
672 return mState.mPipelines->createProgramPipeline();
673}
674
Jiawei Shao385b3e02018-03-21 09:43:28 +0800675GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800676{
677 UNIMPLEMENTED();
678 return 0u;
679}
680
James Darpinian4d9d4832018-03-13 12:43:28 -0700681void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682{
James Darpinian4d9d4832018-03-13 12:43:28 -0700683 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
684 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685 {
686 detachBuffer(buffer);
687 }
Jamie Madill893ab082014-05-16 16:56:10 -0400688
James Darpinian4d9d4832018-03-13 12:43:28 -0700689 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692void Context::deleteShader(GLuint shader)
693{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500694 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697void Context::deleteProgram(GLuint program)
698{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500699 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700}
701
702void Context::deleteTexture(GLuint texture)
703{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500704 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000705 {
706 detachTexture(texture);
707 }
708
Jamie Madill6c1f6712017-02-14 19:08:04 -0500709 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000710}
711
712void Context::deleteRenderbuffer(GLuint renderbuffer)
713{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500714 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715 {
716 detachRenderbuffer(renderbuffer);
717 }
Jamie Madill893ab082014-05-16 16:56:10 -0400718
Jamie Madill6c1f6712017-02-14 19:08:04 -0500719 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720}
721
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400722void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400723{
724 // The spec specifies the underlying Fence object is not deleted until all current
725 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
726 // and since our API is currently designed for being called from a single thread, we can delete
727 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400728 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400729}
730
Yunchao Hea336b902017-08-02 16:05:21 +0800731void Context::deleteProgramPipeline(GLuint pipeline)
732{
733 if (mState.mPipelines->getProgramPipeline(pipeline))
734 {
735 detachProgramPipeline(pipeline);
736 }
737
738 mState.mPipelines->deleteObject(this, pipeline);
739}
740
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741void Context::deletePaths(GLuint first, GLsizei range)
742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744}
745
Brandon Jones59770802018-04-02 13:18:42 -0700746bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500748 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300749 if (pathObj == nullptr)
750 return false;
751
752 return pathObj->hasPathData();
753}
754
Brandon Jones59770802018-04-02 13:18:42 -0700755bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300756{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500757 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300758}
759
Brandon Jones59770802018-04-02 13:18:42 -0700760void Context::pathCommands(GLuint path,
761 GLsizei numCommands,
762 const GLubyte *commands,
763 GLsizei numCoords,
764 GLenum coordType,
765 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300766{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500767 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300768
769 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
770}
771
Jamie Madill007530e2017-12-28 14:27:04 -0500772void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300773{
Jamie Madill007530e2017-12-28 14:27:04 -0500774 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300775
776 switch (pname)
777 {
778 case GL_PATH_STROKE_WIDTH_CHROMIUM:
779 pathObj->setStrokeWidth(value);
780 break;
781 case GL_PATH_END_CAPS_CHROMIUM:
782 pathObj->setEndCaps(static_cast<GLenum>(value));
783 break;
784 case GL_PATH_JOIN_STYLE_CHROMIUM:
785 pathObj->setJoinStyle(static_cast<GLenum>(value));
786 break;
787 case GL_PATH_MITER_LIMIT_CHROMIUM:
788 pathObj->setMiterLimit(value);
789 break;
790 case GL_PATH_STROKE_BOUND_CHROMIUM:
791 pathObj->setStrokeBound(value);
792 break;
793 default:
794 UNREACHABLE();
795 break;
796 }
797}
798
Jamie Madill007530e2017-12-28 14:27:04 -0500799void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300800{
Jamie Madill007530e2017-12-28 14:27:04 -0500801 // TODO(jmadill): Should use proper clamping/casting.
802 pathParameterf(path, pname, static_cast<GLfloat>(value));
803}
804
805void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
806{
807 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808
809 switch (pname)
810 {
811 case GL_PATH_STROKE_WIDTH_CHROMIUM:
812 *value = pathObj->getStrokeWidth();
813 break;
814 case GL_PATH_END_CAPS_CHROMIUM:
815 *value = static_cast<GLfloat>(pathObj->getEndCaps());
816 break;
817 case GL_PATH_JOIN_STYLE_CHROMIUM:
818 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
819 break;
820 case GL_PATH_MITER_LIMIT_CHROMIUM:
821 *value = pathObj->getMiterLimit();
822 break;
823 case GL_PATH_STROKE_BOUND_CHROMIUM:
824 *value = pathObj->getStrokeBound();
825 break;
826 default:
827 UNREACHABLE();
828 break;
829 }
830}
831
Jamie Madill007530e2017-12-28 14:27:04 -0500832void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
833{
834 GLfloat val = 0.0f;
835 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
836 if (value)
837 *value = static_cast<GLint>(val);
838}
839
Brandon Jones59770802018-04-02 13:18:42 -0700840void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300841{
842 mGLState.setPathStencilFunc(func, ref, mask);
843}
844
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845void Context::deleteFramebuffer(GLuint framebuffer)
846{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500847 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848 {
849 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500851
Jamie Madill6c1f6712017-02-14 19:08:04 -0500852 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853}
854
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500855void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500857 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500859 GLuint fence = fences[i];
860
861 FenceNV *fenceObject = nullptr;
862 if (mFenceNVMap.erase(fence, &fenceObject))
863 {
864 mFenceNVHandleAllocator.release(fence);
865 delete fenceObject;
866 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867 }
868}
869
Geoff Lang70d0f492015-12-10 17:45:46 -0500870Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000871{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500872 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873}
874
Jamie Madill570f7c82014-07-03 10:38:54 -0400875Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000876{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500877 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000878}
879
Geoff Lang70d0f492015-12-10 17:45:46 -0500880Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500882 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000883}
884
Jamie Madill70b5bb02017-08-28 13:32:37 -0400885Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400886{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400887 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400888}
889
Jamie Madill57a89722013-07-02 11:57:03 -0400890VertexArray *Context::getVertexArray(GLuint handle) const
891{
Jamie Madill96a483b2017-06-27 16:49:21 -0400892 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400893}
894
Jamie Madilldc356042013-07-19 16:36:57 -0400895Sampler *Context::getSampler(GLuint handle) const
896{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500897 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400898}
899
Geoff Langc8058452014-02-03 12:04:11 -0500900TransformFeedback *Context::getTransformFeedback(GLuint handle) const
901{
Jamie Madill96a483b2017-06-27 16:49:21 -0400902 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500903}
904
Yunchao Hea336b902017-08-02 16:05:21 +0800905ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
906{
907 return mState.mPipelines->getProgramPipeline(handle);
908}
909
Geoff Lang70d0f492015-12-10 17:45:46 -0500910LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
911{
912 switch (identifier)
913 {
914 case GL_BUFFER:
915 return getBuffer(name);
916 case GL_SHADER:
917 return getShader(name);
918 case GL_PROGRAM:
919 return getProgram(name);
920 case GL_VERTEX_ARRAY:
921 return getVertexArray(name);
922 case GL_QUERY:
923 return getQuery(name);
924 case GL_TRANSFORM_FEEDBACK:
925 return getTransformFeedback(name);
926 case GL_SAMPLER:
927 return getSampler(name);
928 case GL_TEXTURE:
929 return getTexture(name);
930 case GL_RENDERBUFFER:
931 return getRenderbuffer(name);
932 case GL_FRAMEBUFFER:
933 return getFramebuffer(name);
934 default:
935 UNREACHABLE();
936 return nullptr;
937 }
938}
939
940LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
941{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400942 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500943}
944
Martin Radev9d901792016-07-15 15:58:58 +0300945void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
946{
947 LabeledObject *object = getLabeledObject(identifier, name);
948 ASSERT(object != nullptr);
949
950 std::string labelName = GetObjectLabelFromPointer(length, label);
951 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400952
953 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
954 // specified object is active until we do this.
955 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300956}
957
958void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
959{
960 LabeledObject *object = getLabeledObjectFromPtr(ptr);
961 ASSERT(object != nullptr);
962
963 std::string labelName = GetObjectLabelFromPointer(length, label);
964 object->setLabel(labelName);
965}
966
967void Context::getObjectLabel(GLenum identifier,
968 GLuint name,
969 GLsizei bufSize,
970 GLsizei *length,
971 GLchar *label) const
972{
973 LabeledObject *object = getLabeledObject(identifier, name);
974 ASSERT(object != nullptr);
975
976 const std::string &objectLabel = object->getLabel();
977 GetObjectLabelBase(objectLabel, bufSize, length, label);
978}
979
980void Context::getObjectPtrLabel(const void *ptr,
981 GLsizei bufSize,
982 GLsizei *length,
983 GLchar *label) const
984{
985 LabeledObject *object = getLabeledObjectFromPtr(ptr);
986 ASSERT(object != nullptr);
987
988 const std::string &objectLabel = object->getLabel();
989 GetObjectLabelBase(objectLabel, bufSize, length, label);
990}
991
Jamie Madilldc356042013-07-19 16:36:57 -0400992bool Context::isSampler(GLuint samplerName) const
993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400995}
996
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800997void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500999 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001000
Jamie Madilldedd7b92014-11-05 16:30:36 -05001001 if (handle == 0)
1002 {
1003 texture = mZeroTextures[target].get();
1004 }
1005 else
1006 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001007 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001008 }
1009
1010 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001011 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001012}
1013
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001014void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001015{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001016 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1017 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001018 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001019}
1020
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001021void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001022{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001023 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1024 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001025 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001026}
1027
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001028void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001029{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001030 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001031 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001032}
1033
Shao80957d92017-02-20 21:25:59 +08001034void Context::bindVertexBuffer(GLuint bindingIndex,
1035 GLuint bufferHandle,
1036 GLintptr offset,
1037 GLsizei stride)
1038{
1039 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001040 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001041}
1042
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001043void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001044{
Geoff Lang76b10c92014-09-05 16:28:14 -04001045 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001046 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001047 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001048 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001049}
1050
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001051void Context::bindImageTexture(GLuint unit,
1052 GLuint texture,
1053 GLint level,
1054 GLboolean layered,
1055 GLint layer,
1056 GLenum access,
1057 GLenum format)
1058{
1059 Texture *tex = mState.mTextures->getTexture(texture);
1060 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1061}
1062
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001063void Context::useProgram(GLuint program)
1064{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001065 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001066}
1067
Jiajia Qin5451d532017-11-16 17:16:34 +08001068void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1069{
1070 UNIMPLEMENTED();
1071}
1072
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001073void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001074{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001075 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001076 TransformFeedback *transformFeedback =
1077 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001078 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001079}
1080
Yunchao Hea336b902017-08-02 16:05:21 +08001081void Context::bindProgramPipeline(GLuint pipelineHandle)
1082{
1083 ProgramPipeline *pipeline =
1084 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1085 mGLState.setProgramPipelineBinding(this, pipeline);
1086}
1087
Corentin Wallezad3ae902018-03-09 13:40:42 -05001088void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001091 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001092
Geoff Lang5aad9672014-09-08 11:10:42 -04001093 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001094 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001095
1096 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001097 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098}
1099
Corentin Wallezad3ae902018-03-09 13:40:42 -05001100void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001102 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001103 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001104
Jamie Madillf0e04492017-08-26 15:28:42 -04001105 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106
Geoff Lang5aad9672014-09-08 11:10:42 -04001107 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001109}
1110
Corentin Wallezad3ae902018-03-09 13:40:42 -05001111void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001112{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001113 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001114
1115 Query *queryObject = getQuery(id, true, target);
1116 ASSERT(queryObject);
1117
Jamie Madillf0e04492017-08-26 15:28:42 -04001118 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001119}
1120
Corentin Wallezad3ae902018-03-09 13:40:42 -05001121void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001122{
1123 switch (pname)
1124 {
1125 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001126 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127 break;
1128 case GL_QUERY_COUNTER_BITS_EXT:
1129 switch (target)
1130 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001131 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1133 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001134 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135 params[0] = getExtensions().queryCounterBitsTimestamp;
1136 break;
1137 default:
1138 UNREACHABLE();
1139 params[0] = 0;
1140 break;
1141 }
1142 break;
1143 default:
1144 UNREACHABLE();
1145 return;
1146 }
1147}
1148
Corentin Wallezad3ae902018-03-09 13:40:42 -05001149void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001150 GLenum pname,
1151 GLsizei bufSize,
1152 GLsizei *length,
1153 GLint *params)
1154{
1155 getQueryiv(target, pname, params);
1156}
1157
Geoff Lang2186c382016-10-14 10:54:54 -04001158void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001159{
Geoff Lang2186c382016-10-14 10:54:54 -04001160 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001161}
1162
Brandon Jones59770802018-04-02 13:18:42 -07001163void Context::getQueryObjectivRobust(GLuint id,
1164 GLenum pname,
1165 GLsizei bufSize,
1166 GLsizei *length,
1167 GLint *params)
1168{
1169 getQueryObjectiv(id, pname, params);
1170}
1171
Geoff Lang2186c382016-10-14 10:54:54 -04001172void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173{
Geoff Lang2186c382016-10-14 10:54:54 -04001174 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175}
1176
Brandon Jones59770802018-04-02 13:18:42 -07001177void Context::getQueryObjectuivRobust(GLuint id,
1178 GLenum pname,
1179 GLsizei bufSize,
1180 GLsizei *length,
1181 GLuint *params)
1182{
1183 getQueryObjectuiv(id, pname, params);
1184}
1185
Geoff Lang2186c382016-10-14 10:54:54 -04001186void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187{
Geoff Lang2186c382016-10-14 10:54:54 -04001188 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189}
1190
Brandon Jones59770802018-04-02 13:18:42 -07001191void Context::getQueryObjecti64vRobust(GLuint id,
1192 GLenum pname,
1193 GLsizei bufSize,
1194 GLsizei *length,
1195 GLint64 *params)
1196{
1197 getQueryObjecti64v(id, pname, params);
1198}
1199
Geoff Lang2186c382016-10-14 10:54:54 -04001200void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201{
Geoff Lang2186c382016-10-14 10:54:54 -04001202 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001203}
1204
Brandon Jones59770802018-04-02 13:18:42 -07001205void Context::getQueryObjectui64vRobust(GLuint id,
1206 GLenum pname,
1207 GLsizei bufSize,
1208 GLsizei *length,
1209 GLuint64 *params)
1210{
1211 getQueryObjectui64v(id, pname, params);
1212}
1213
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001214Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001216 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217}
1218
Jamie Madill2f348d22017-06-05 10:50:59 -04001219FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220{
Jamie Madill96a483b2017-06-27 16:49:21 -04001221 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222}
1223
Corentin Wallezad3ae902018-03-09 13:40:42 -05001224Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225{
Jamie Madill96a483b2017-06-27 16:49:21 -04001226 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001228 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001230
1231 Query *query = mQueryMap.query(handle);
1232 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001234 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001235 query = new Query(mImplementation->createQuery(type), handle);
1236 query->addRef();
1237 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001238 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001239 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240}
1241
Geoff Lang70d0f492015-12-10 17:45:46 -05001242Query *Context::getQuery(GLuint handle) const
1243{
Jamie Madill96a483b2017-06-27 16:49:21 -04001244 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001245}
1246
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001247Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001248{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001249 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1250 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001251}
1252
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001253Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001255 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001256}
1257
Geoff Lang492a7e42014-11-05 13:27:06 -05001258Compiler *Context::getCompiler() const
1259{
Jamie Madill2f348d22017-06-05 10:50:59 -04001260 if (mCompiler.get() == nullptr)
1261 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001262 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001263 }
1264 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001265}
1266
Jamie Madillc1d770e2017-04-13 17:31:24 -04001267void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268{
1269 switch (pname)
1270 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001271 case GL_SHADER_COMPILER:
1272 *params = GL_TRUE;
1273 break;
1274 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1275 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1276 break;
1277 default:
1278 mGLState.getBooleanv(pname, params);
1279 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281}
1282
Jamie Madillc1d770e2017-04-13 17:31:24 -04001283void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284{
Shannon Woods53a94a82014-06-24 15:20:36 -04001285 // Queries about context capabilities and maximums are answered by Context.
1286 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287 switch (pname)
1288 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001289 case GL_ALIASED_LINE_WIDTH_RANGE:
1290 params[0] = mCaps.minAliasedLineWidth;
1291 params[1] = mCaps.maxAliasedLineWidth;
1292 break;
1293 case GL_ALIASED_POINT_SIZE_RANGE:
1294 params[0] = mCaps.minAliasedPointSize;
1295 params[1] = mCaps.maxAliasedPointSize;
1296 break;
1297 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1298 ASSERT(mExtensions.textureFilterAnisotropic);
1299 *params = mExtensions.maxTextureAnisotropy;
1300 break;
1301 case GL_MAX_TEXTURE_LOD_BIAS:
1302 *params = mCaps.maxLODBias;
1303 break;
1304
1305 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1306 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1307 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001308 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1309 // GLES1 constants for modelview/projection matrix.
1310 if (getClientVersion() < Version(2, 0))
1311 {
1312 mGLState.getFloatv(pname, params);
1313 }
1314 else
1315 {
1316 ASSERT(mExtensions.pathRendering);
1317 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1318 memcpy(params, m, 16 * sizeof(GLfloat));
1319 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001321 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001322
Jamie Madill231c7f52017-04-26 13:45:37 -04001323 default:
1324 mGLState.getFloatv(pname, params);
1325 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327}
1328
Jamie Madillc1d770e2017-04-13 17:31:24 -04001329void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330{
Shannon Woods53a94a82014-06-24 15:20:36 -04001331 // Queries about context capabilities and maximums are answered by Context.
1332 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001333
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001334 switch (pname)
1335 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001336 case GL_MAX_VERTEX_ATTRIBS:
1337 *params = mCaps.maxVertexAttributes;
1338 break;
1339 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1340 *params = mCaps.maxVertexUniformVectors;
1341 break;
1342 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1343 *params = mCaps.maxVertexUniformComponents;
1344 break;
1345 case GL_MAX_VARYING_VECTORS:
1346 *params = mCaps.maxVaryingVectors;
1347 break;
1348 case GL_MAX_VARYING_COMPONENTS:
1349 *params = mCaps.maxVertexOutputComponents;
1350 break;
1351 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1352 *params = mCaps.maxCombinedTextureImageUnits;
1353 break;
1354 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001355 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001358 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001359 break;
1360 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1361 *params = mCaps.maxFragmentUniformVectors;
1362 break;
1363 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1364 *params = mCaps.maxFragmentUniformComponents;
1365 break;
1366 case GL_MAX_RENDERBUFFER_SIZE:
1367 *params = mCaps.maxRenderbufferSize;
1368 break;
1369 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1370 *params = mCaps.maxColorAttachments;
1371 break;
1372 case GL_MAX_DRAW_BUFFERS_EXT:
1373 *params = mCaps.maxDrawBuffers;
1374 break;
1375 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1376 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1377 case GL_SUBPIXEL_BITS:
1378 *params = 4;
1379 break;
1380 case GL_MAX_TEXTURE_SIZE:
1381 *params = mCaps.max2DTextureSize;
1382 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001383 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1384 *params = mCaps.maxRectangleTextureSize;
1385 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001386 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1387 *params = mCaps.maxCubeMapTextureSize;
1388 break;
1389 case GL_MAX_3D_TEXTURE_SIZE:
1390 *params = mCaps.max3DTextureSize;
1391 break;
1392 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1393 *params = mCaps.maxArrayTextureLayers;
1394 break;
1395 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1396 *params = mCaps.uniformBufferOffsetAlignment;
1397 break;
1398 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1399 *params = mCaps.maxUniformBufferBindings;
1400 break;
1401 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001402 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001403 break;
1404 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001405 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001406 break;
1407 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1408 *params = mCaps.maxCombinedTextureImageUnits;
1409 break;
1410 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1411 *params = mCaps.maxVertexOutputComponents;
1412 break;
1413 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1414 *params = mCaps.maxFragmentInputComponents;
1415 break;
1416 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1417 *params = mCaps.minProgramTexelOffset;
1418 break;
1419 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1420 *params = mCaps.maxProgramTexelOffset;
1421 break;
1422 case GL_MAJOR_VERSION:
1423 *params = getClientVersion().major;
1424 break;
1425 case GL_MINOR_VERSION:
1426 *params = getClientVersion().minor;
1427 break;
1428 case GL_MAX_ELEMENTS_INDICES:
1429 *params = mCaps.maxElementsIndices;
1430 break;
1431 case GL_MAX_ELEMENTS_VERTICES:
1432 *params = mCaps.maxElementsVertices;
1433 break;
1434 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1435 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1436 break;
1437 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1438 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1439 break;
1440 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1441 *params = mCaps.maxTransformFeedbackSeparateComponents;
1442 break;
1443 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1444 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1445 break;
1446 case GL_MAX_SAMPLES_ANGLE:
1447 *params = mCaps.maxSamples;
1448 break;
1449 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001450 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001451 params[0] = mCaps.maxViewportWidth;
1452 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001453 }
1454 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001455 case GL_COMPRESSED_TEXTURE_FORMATS:
1456 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1457 params);
1458 break;
1459 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1460 *params = mResetStrategy;
1461 break;
1462 case GL_NUM_SHADER_BINARY_FORMATS:
1463 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1464 break;
1465 case GL_SHADER_BINARY_FORMATS:
1466 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1467 break;
1468 case GL_NUM_PROGRAM_BINARY_FORMATS:
1469 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1470 break;
1471 case GL_PROGRAM_BINARY_FORMATS:
1472 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1473 break;
1474 case GL_NUM_EXTENSIONS:
1475 *params = static_cast<GLint>(mExtensionStrings.size());
1476 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001477
Jamie Madill231c7f52017-04-26 13:45:37 -04001478 // GL_KHR_debug
1479 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1480 *params = mExtensions.maxDebugMessageLength;
1481 break;
1482 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1483 *params = mExtensions.maxDebugLoggedMessages;
1484 break;
1485 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1486 *params = mExtensions.maxDebugGroupStackDepth;
1487 break;
1488 case GL_MAX_LABEL_LENGTH:
1489 *params = mExtensions.maxLabelLength;
1490 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001491
Martin Radeve5285d22017-07-14 16:23:53 +03001492 // GL_ANGLE_multiview
1493 case GL_MAX_VIEWS_ANGLE:
1494 *params = mExtensions.maxViews;
1495 break;
1496
Jamie Madill231c7f52017-04-26 13:45:37 -04001497 // GL_EXT_disjoint_timer_query
1498 case GL_GPU_DISJOINT_EXT:
1499 *params = mImplementation->getGPUDisjoint();
1500 break;
1501 case GL_MAX_FRAMEBUFFER_WIDTH:
1502 *params = mCaps.maxFramebufferWidth;
1503 break;
1504 case GL_MAX_FRAMEBUFFER_HEIGHT:
1505 *params = mCaps.maxFramebufferHeight;
1506 break;
1507 case GL_MAX_FRAMEBUFFER_SAMPLES:
1508 *params = mCaps.maxFramebufferSamples;
1509 break;
1510 case GL_MAX_SAMPLE_MASK_WORDS:
1511 *params = mCaps.maxSampleMaskWords;
1512 break;
1513 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1514 *params = mCaps.maxColorTextureSamples;
1515 break;
1516 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1517 *params = mCaps.maxDepthTextureSamples;
1518 break;
1519 case GL_MAX_INTEGER_SAMPLES:
1520 *params = mCaps.maxIntegerSamples;
1521 break;
1522 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1523 *params = mCaps.maxVertexAttribRelativeOffset;
1524 break;
1525 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1526 *params = mCaps.maxVertexAttribBindings;
1527 break;
1528 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1529 *params = mCaps.maxVertexAttribStride;
1530 break;
1531 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1532 *params = mCaps.maxVertexAtomicCounterBuffers;
1533 break;
1534 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1535 *params = mCaps.maxVertexAtomicCounters;
1536 break;
1537 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1538 *params = mCaps.maxVertexImageUniforms;
1539 break;
1540 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001541 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1544 *params = mCaps.maxFragmentAtomicCounterBuffers;
1545 break;
1546 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1547 *params = mCaps.maxFragmentAtomicCounters;
1548 break;
1549 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1550 *params = mCaps.maxFragmentImageUniforms;
1551 break;
1552 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001553 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001554 break;
1555 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1556 *params = mCaps.minProgramTextureGatherOffset;
1557 break;
1558 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1559 *params = mCaps.maxProgramTextureGatherOffset;
1560 break;
1561 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1562 *params = mCaps.maxComputeWorkGroupInvocations;
1563 break;
1564 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001565 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 break;
1567 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001568 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001569 break;
1570 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1571 *params = mCaps.maxComputeSharedMemorySize;
1572 break;
1573 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1574 *params = mCaps.maxComputeUniformComponents;
1575 break;
1576 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1577 *params = mCaps.maxComputeAtomicCounterBuffers;
1578 break;
1579 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1580 *params = mCaps.maxComputeAtomicCounters;
1581 break;
1582 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1583 *params = mCaps.maxComputeImageUniforms;
1584 break;
1585 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1586 *params = mCaps.maxCombinedComputeUniformComponents;
1587 break;
1588 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001589 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1592 *params = mCaps.maxCombinedShaderOutputResources;
1593 break;
1594 case GL_MAX_UNIFORM_LOCATIONS:
1595 *params = mCaps.maxUniformLocations;
1596 break;
1597 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1598 *params = mCaps.maxAtomicCounterBufferBindings;
1599 break;
1600 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1601 *params = mCaps.maxAtomicCounterBufferSize;
1602 break;
1603 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1604 *params = mCaps.maxCombinedAtomicCounterBuffers;
1605 break;
1606 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1607 *params = mCaps.maxCombinedAtomicCounters;
1608 break;
1609 case GL_MAX_IMAGE_UNITS:
1610 *params = mCaps.maxImageUnits;
1611 break;
1612 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1613 *params = mCaps.maxCombinedImageUniforms;
1614 break;
1615 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1616 *params = mCaps.maxShaderStorageBufferBindings;
1617 break;
1618 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1619 *params = mCaps.maxCombinedShaderStorageBlocks;
1620 break;
1621 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1622 *params = mCaps.shaderStorageBufferOffsetAlignment;
1623 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001624
1625 // GL_EXT_geometry_shader
1626 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1627 *params = mCaps.maxFramebufferLayers;
1628 break;
1629 case GL_LAYER_PROVOKING_VERTEX_EXT:
1630 *params = mCaps.layerProvokingVertex;
1631 break;
1632 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1633 *params = mCaps.maxGeometryUniformComponents;
1634 break;
1635 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001636 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001637 break;
1638 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1639 *params = mCaps.maxCombinedGeometryUniformComponents;
1640 break;
1641 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1642 *params = mCaps.maxGeometryInputComponents;
1643 break;
1644 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1645 *params = mCaps.maxGeometryOutputComponents;
1646 break;
1647 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1648 *params = mCaps.maxGeometryOutputVertices;
1649 break;
1650 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1651 *params = mCaps.maxGeometryTotalOutputComponents;
1652 break;
1653 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1654 *params = mCaps.maxGeometryShaderInvocations;
1655 break;
1656 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001657 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
1659 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1660 *params = mCaps.maxGeometryAtomicCounterBuffers;
1661 break;
1662 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1663 *params = mCaps.maxGeometryAtomicCounters;
1664 break;
1665 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1666 *params = mCaps.maxGeometryImageUniforms;
1667 break;
1668 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001669 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001670 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001671 // GLES1 emulation: Caps queries
1672 case GL_MAX_TEXTURE_UNITS:
1673 *params = mCaps.maxMultitextureUnits;
1674 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001675 case GL_MAX_MODELVIEW_STACK_DEPTH:
1676 *params = mCaps.maxModelviewMatrixStackDepth;
1677 break;
1678 case GL_MAX_PROJECTION_STACK_DEPTH:
1679 *params = mCaps.maxProjectionMatrixStackDepth;
1680 break;
1681 case GL_MAX_TEXTURE_STACK_DEPTH:
1682 *params = mCaps.maxTextureMatrixStackDepth;
1683 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001684 // GLES1 emulation: Vertex attribute queries
1685 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1686 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1687 case GL_COLOR_ARRAY_BUFFER_BINDING:
1688 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1689 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1690 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1691 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1692 break;
1693 case GL_VERTEX_ARRAY_STRIDE:
1694 case GL_NORMAL_ARRAY_STRIDE:
1695 case GL_COLOR_ARRAY_STRIDE:
1696 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1697 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1698 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1699 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1700 break;
1701 case GL_VERTEX_ARRAY_SIZE:
1702 case GL_COLOR_ARRAY_SIZE:
1703 case GL_TEXTURE_COORD_ARRAY_SIZE:
1704 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1705 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1706 break;
1707 case GL_VERTEX_ARRAY_TYPE:
1708 case GL_COLOR_ARRAY_TYPE:
1709 case GL_NORMAL_ARRAY_TYPE:
1710 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1711 case GL_TEXTURE_COORD_ARRAY_TYPE:
1712 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1713 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1714 break;
1715
Jamie Madill231c7f52017-04-26 13:45:37 -04001716 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001717 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001718 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001719 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001720}
1721
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001722void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001723{
Shannon Woods53a94a82014-06-24 15:20:36 -04001724 // Queries about context capabilities and maximums are answered by Context.
1725 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001726 switch (pname)
1727 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001728 case GL_MAX_ELEMENT_INDEX:
1729 *params = mCaps.maxElementIndex;
1730 break;
1731 case GL_MAX_UNIFORM_BLOCK_SIZE:
1732 *params = mCaps.maxUniformBlockSize;
1733 break;
1734 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1735 *params = mCaps.maxCombinedVertexUniformComponents;
1736 break;
1737 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1738 *params = mCaps.maxCombinedFragmentUniformComponents;
1739 break;
1740 case GL_MAX_SERVER_WAIT_TIMEOUT:
1741 *params = mCaps.maxServerWaitTimeout;
1742 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001743
Jamie Madill231c7f52017-04-26 13:45:37 -04001744 // GL_EXT_disjoint_timer_query
1745 case GL_TIMESTAMP_EXT:
1746 *params = mImplementation->getTimestamp();
1747 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001748
Jamie Madill231c7f52017-04-26 13:45:37 -04001749 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1750 *params = mCaps.maxShaderStorageBlockSize;
1751 break;
1752 default:
1753 UNREACHABLE();
1754 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001755 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001756}
1757
Geoff Lang70d0f492015-12-10 17:45:46 -05001758void Context::getPointerv(GLenum pname, void **params) const
1759{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001760 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001761}
1762
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001763void Context::getPointervRobustANGLERobust(GLenum pname,
1764 GLsizei bufSize,
1765 GLsizei *length,
1766 void **params)
1767{
1768 UNIMPLEMENTED();
1769}
1770
Martin Radev66fb8202016-07-28 11:45:20 +03001771void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001772{
Shannon Woods53a94a82014-06-24 15:20:36 -04001773 // Queries about context capabilities and maximums are answered by Context.
1774 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001775
1776 GLenum nativeType;
1777 unsigned int numParams;
1778 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1779 ASSERT(queryStatus);
1780
1781 if (nativeType == GL_INT)
1782 {
1783 switch (target)
1784 {
1785 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1786 ASSERT(index < 3u);
1787 *data = mCaps.maxComputeWorkGroupCount[index];
1788 break;
1789 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1790 ASSERT(index < 3u);
1791 *data = mCaps.maxComputeWorkGroupSize[index];
1792 break;
1793 default:
1794 mGLState.getIntegeri_v(target, index, data);
1795 }
1796 }
1797 else
1798 {
1799 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1800 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001801}
1802
Brandon Jones59770802018-04-02 13:18:42 -07001803void Context::getIntegeri_vRobust(GLenum target,
1804 GLuint index,
1805 GLsizei bufSize,
1806 GLsizei *length,
1807 GLint *data)
1808{
1809 getIntegeri_v(target, index, data);
1810}
1811
Martin Radev66fb8202016-07-28 11:45:20 +03001812void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001813{
Shannon Woods53a94a82014-06-24 15:20:36 -04001814 // Queries about context capabilities and maximums are answered by Context.
1815 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001816
1817 GLenum nativeType;
1818 unsigned int numParams;
1819 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1820 ASSERT(queryStatus);
1821
1822 if (nativeType == GL_INT_64_ANGLEX)
1823 {
1824 mGLState.getInteger64i_v(target, index, data);
1825 }
1826 else
1827 {
1828 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1829 }
1830}
1831
Brandon Jones59770802018-04-02 13:18:42 -07001832void Context::getInteger64i_vRobust(GLenum target,
1833 GLuint index,
1834 GLsizei bufSize,
1835 GLsizei *length,
1836 GLint64 *data)
1837{
1838 getInteger64i_v(target, index, data);
1839}
1840
Martin Radev66fb8202016-07-28 11:45:20 +03001841void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1842{
1843 // Queries about context capabilities and maximums are answered by Context.
1844 // Queries about current GL state values are answered by State.
1845
1846 GLenum nativeType;
1847 unsigned int numParams;
1848 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1849 ASSERT(queryStatus);
1850
1851 if (nativeType == GL_BOOL)
1852 {
1853 mGLState.getBooleani_v(target, index, data);
1854 }
1855 else
1856 {
1857 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1858 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001859}
1860
Brandon Jones59770802018-04-02 13:18:42 -07001861void Context::getBooleani_vRobust(GLenum target,
1862 GLuint index,
1863 GLsizei bufSize,
1864 GLsizei *length,
1865 GLboolean *data)
1866{
1867 getBooleani_v(target, index, data);
1868}
1869
Corentin Wallez336129f2017-10-17 15:55:40 -04001870void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001871{
1872 Buffer *buffer = mGLState.getTargetBuffer(target);
1873 QueryBufferParameteriv(buffer, pname, params);
1874}
1875
Brandon Jones59770802018-04-02 13:18:42 -07001876void Context::getBufferParameterivRobust(BufferBinding target,
1877 GLenum pname,
1878 GLsizei bufSize,
1879 GLsizei *length,
1880 GLint *params)
1881{
1882 getBufferParameteriv(target, pname, params);
1883}
1884
He Yunchao010e4db2017-03-03 14:22:06 +08001885void Context::getFramebufferAttachmentParameteriv(GLenum target,
1886 GLenum attachment,
1887 GLenum pname,
1888 GLint *params)
1889{
1890 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001891 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001892}
1893
Brandon Jones59770802018-04-02 13:18:42 -07001894void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1895 GLenum attachment,
1896 GLenum pname,
1897 GLsizei bufSize,
1898 GLsizei *length,
1899 GLint *params)
1900{
1901 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1902}
1903
He Yunchao010e4db2017-03-03 14:22:06 +08001904void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1905{
1906 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1907 QueryRenderbufferiv(this, renderbuffer, pname, params);
1908}
1909
Brandon Jones59770802018-04-02 13:18:42 -07001910void Context::getRenderbufferParameterivRobust(GLenum target,
1911 GLenum pname,
1912 GLsizei bufSize,
1913 GLsizei *length,
1914 GLint *params)
1915{
1916 getRenderbufferParameteriv(target, pname, params);
1917}
1918
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001919void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001920{
1921 Texture *texture = getTargetTexture(target);
1922 QueryTexParameterfv(texture, pname, params);
1923}
1924
Brandon Jones59770802018-04-02 13:18:42 -07001925void Context::getTexParameterfvRobust(TextureType target,
1926 GLenum pname,
1927 GLsizei bufSize,
1928 GLsizei *length,
1929 GLfloat *params)
1930{
1931 getTexParameterfv(target, pname, params);
1932}
1933
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001934void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001935{
1936 Texture *texture = getTargetTexture(target);
1937 QueryTexParameteriv(texture, pname, params);
1938}
Jiajia Qin5451d532017-11-16 17:16:34 +08001939
Brandon Jones59770802018-04-02 13:18:42 -07001940void Context::getTexParameterivRobust(TextureType target,
1941 GLenum pname,
1942 GLsizei bufSize,
1943 GLsizei *length,
1944 GLint *params)
1945{
1946 getTexParameteriv(target, pname, params);
1947}
1948
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001949void Context::getTexParameterIivRobust(TextureType target,
1950 GLenum pname,
1951 GLsizei bufSize,
1952 GLsizei *length,
1953 GLint *params)
1954{
1955 UNIMPLEMENTED();
1956}
1957
1958void Context::getTexParameterIuivRobust(TextureType target,
1959 GLenum pname,
1960 GLsizei bufSize,
1961 GLsizei *length,
1962 GLuint *params)
1963{
1964 UNIMPLEMENTED();
1965}
1966
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001967void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001968{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001969 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001970 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001971}
1972
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001973void Context::getTexLevelParameterivRobust(TextureTarget target,
1974 GLint level,
1975 GLenum pname,
1976 GLsizei bufSize,
1977 GLsizei *length,
1978 GLint *params)
1979{
1980 UNIMPLEMENTED();
1981}
1982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001983void Context::getTexLevelParameterfv(TextureTarget target,
1984 GLint level,
1985 GLenum pname,
1986 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001987{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001988 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001989 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001990}
1991
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001992void Context::getTexLevelParameterfvRobust(TextureTarget target,
1993 GLint level,
1994 GLenum pname,
1995 GLsizei bufSize,
1996 GLsizei *length,
1997 GLfloat *params)
1998{
1999 UNIMPLEMENTED();
2000}
2001
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002002void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002003{
2004 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002005 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002006 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002007}
2008
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002009void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002010{
2011 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002012 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002013 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002014}
2015
Brandon Jones59770802018-04-02 13:18:42 -07002016void Context::texParameterfvRobust(TextureType target,
2017 GLenum pname,
2018 GLsizei bufSize,
2019 const GLfloat *params)
2020{
2021 texParameterfv(target, pname, params);
2022}
2023
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002024void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002025{
2026 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002027 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002028 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002029}
2030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002031void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002032{
2033 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002034 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002035 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002036}
2037
Brandon Jones59770802018-04-02 13:18:42 -07002038void Context::texParameterivRobust(TextureType target,
2039 GLenum pname,
2040 GLsizei bufSize,
2041 const GLint *params)
2042{
2043 texParameteriv(target, pname, params);
2044}
2045
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002046void Context::texParameterIivRobust(TextureType target,
2047 GLenum pname,
2048 GLsizei bufSize,
2049 const GLint *params)
2050{
2051 UNIMPLEMENTED();
2052}
2053
2054void Context::texParameterIuivRobust(TextureType target,
2055 GLenum pname,
2056 GLsizei bufSize,
2057 const GLuint *params)
2058{
2059 UNIMPLEMENTED();
2060}
2061
Jamie Madill675fe712016-12-19 13:07:54 -05002062void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002063{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002064 // No-op if zero count
2065 if (count == 0)
2066 {
2067 return;
2068 }
2069
Jamie Madill05b35b22017-10-03 09:01:44 -04002070 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002071 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002072 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002073}
2074
Jamie Madill675fe712016-12-19 13:07:54 -05002075void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002076{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002077 // No-op if zero count
2078 if (count == 0 || instanceCount == 0)
2079 {
2080 return;
2081 }
2082
Jamie Madill05b35b22017-10-03 09:01:44 -04002083 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002084 ANGLE_CONTEXT_TRY(
2085 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002086 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2087 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002088}
2089
Jamie Madill876429b2017-04-20 15:46:24 -04002090void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002091{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002092 // No-op if zero count
2093 if (count == 0)
2094 {
2095 return;
2096 }
2097
Jamie Madill05b35b22017-10-03 09:01:44 -04002098 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002099 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002100}
2101
Jamie Madill675fe712016-12-19 13:07:54 -05002102void Context::drawElementsInstanced(GLenum mode,
2103 GLsizei count,
2104 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002105 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002106 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002107{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002108 // No-op if zero count
2109 if (count == 0 || instances == 0)
2110 {
2111 return;
2112 }
2113
Jamie Madill05b35b22017-10-03 09:01:44 -04002114 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002115 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002116 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002117}
2118
Jamie Madill675fe712016-12-19 13:07:54 -05002119void Context::drawRangeElements(GLenum mode,
2120 GLuint start,
2121 GLuint end,
2122 GLsizei count,
2123 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002124 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002125{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002126 // No-op if zero count
2127 if (count == 0)
2128 {
2129 return;
2130 }
2131
Jamie Madill05b35b22017-10-03 09:01:44 -04002132 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002133 ANGLE_CONTEXT_TRY(
2134 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002135}
2136
Jamie Madill876429b2017-04-20 15:46:24 -04002137void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002138{
Jamie Madill05b35b22017-10-03 09:01:44 -04002139 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002140 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002141}
2142
Jamie Madill876429b2017-04-20 15:46:24 -04002143void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002144{
Jamie Madill05b35b22017-10-03 09:01:44 -04002145 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002146 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002147}
2148
Jamie Madill675fe712016-12-19 13:07:54 -05002149void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002150{
Jamie Madillafa02a22017-11-23 12:57:38 -05002151 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002152}
2153
Jamie Madill675fe712016-12-19 13:07:54 -05002154void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002155{
Jamie Madillafa02a22017-11-23 12:57:38 -05002156 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002157}
2158
Austin Kinross6ee1e782015-05-29 17:05:37 -07002159void Context::insertEventMarker(GLsizei length, const char *marker)
2160{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002161 ASSERT(mImplementation);
2162 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002163}
2164
2165void Context::pushGroupMarker(GLsizei length, const char *marker)
2166{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002167 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002168
2169 if (marker == nullptr)
2170 {
2171 // From the EXT_debug_marker spec,
2172 // "If <marker> is null then an empty string is pushed on the stack."
2173 mImplementation->pushGroupMarker(length, "");
2174 }
2175 else
2176 {
2177 mImplementation->pushGroupMarker(length, marker);
2178 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002179}
2180
2181void Context::popGroupMarker()
2182{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002183 ASSERT(mImplementation);
2184 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002185}
2186
Geoff Langd8605522016-04-13 10:19:12 -04002187void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2188{
2189 Program *programObject = getProgram(program);
2190 ASSERT(programObject);
2191
2192 programObject->bindUniformLocation(location, name);
2193}
2194
Brandon Jones59770802018-04-02 13:18:42 -07002195void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002197 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002198}
2199
Brandon Jones59770802018-04-02 13:18:42 -07002200void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002201{
2202 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2203}
2204
Brandon Jones59770802018-04-02 13:18:42 -07002205void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002206{
2207 GLfloat I[16];
2208 angle::Matrix<GLfloat>::setToIdentity(I);
2209
2210 mGLState.loadPathRenderingMatrix(matrixMode, I);
2211}
2212
2213void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2214{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002215 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002216 if (!pathObj)
2217 return;
2218
2219 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002220 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002221
2222 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2223}
2224
2225void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2226{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002227 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228 if (!pathObj)
2229 return;
2230
2231 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002232 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233
2234 mImplementation->stencilStrokePath(pathObj, reference, mask);
2235}
2236
2237void Context::coverFillPath(GLuint path, GLenum coverMode)
2238{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002239 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240 if (!pathObj)
2241 return;
2242
2243 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002244 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002245
2246 mImplementation->coverFillPath(pathObj, coverMode);
2247}
2248
2249void Context::coverStrokePath(GLuint path, GLenum coverMode)
2250{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002251 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252 if (!pathObj)
2253 return;
2254
2255 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002256 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002257
2258 mImplementation->coverStrokePath(pathObj, coverMode);
2259}
2260
2261void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2262{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002263 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002264 if (!pathObj)
2265 return;
2266
2267 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002268 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002269
2270 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2271}
2272
2273void Context::stencilThenCoverStrokePath(GLuint path,
2274 GLint reference,
2275 GLuint mask,
2276 GLenum coverMode)
2277{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002278 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002279 if (!pathObj)
2280 return;
2281
2282 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002283 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002284
2285 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2286}
2287
Sami Väisänend59ca052016-06-21 16:10:00 +03002288void Context::coverFillPathInstanced(GLsizei numPaths,
2289 GLenum pathNameType,
2290 const void *paths,
2291 GLuint pathBase,
2292 GLenum coverMode,
2293 GLenum transformType,
2294 const GLfloat *transformValues)
2295{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002296 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002297
2298 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002299 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002300
2301 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2302}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002303
Sami Väisänend59ca052016-06-21 16:10:00 +03002304void Context::coverStrokePathInstanced(GLsizei numPaths,
2305 GLenum pathNameType,
2306 const void *paths,
2307 GLuint pathBase,
2308 GLenum coverMode,
2309 GLenum transformType,
2310 const GLfloat *transformValues)
2311{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002312 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002313
2314 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002315 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002316
2317 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2318 transformValues);
2319}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002320
Sami Väisänend59ca052016-06-21 16:10:00 +03002321void Context::stencilFillPathInstanced(GLsizei numPaths,
2322 GLenum pathNameType,
2323 const void *paths,
2324 GLuint pathBase,
2325 GLenum fillMode,
2326 GLuint mask,
2327 GLenum transformType,
2328 const GLfloat *transformValues)
2329{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002330 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002331
2332 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002333 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002334
2335 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2336 transformValues);
2337}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002338
Sami Väisänend59ca052016-06-21 16:10:00 +03002339void Context::stencilStrokePathInstanced(GLsizei numPaths,
2340 GLenum pathNameType,
2341 const void *paths,
2342 GLuint pathBase,
2343 GLint reference,
2344 GLuint mask,
2345 GLenum transformType,
2346 const GLfloat *transformValues)
2347{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002348 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002349
2350 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002351 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002352
2353 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2354 transformValues);
2355}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002356
Sami Väisänend59ca052016-06-21 16:10:00 +03002357void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2358 GLenum pathNameType,
2359 const void *paths,
2360 GLuint pathBase,
2361 GLenum fillMode,
2362 GLuint mask,
2363 GLenum coverMode,
2364 GLenum transformType,
2365 const GLfloat *transformValues)
2366{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002367 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002368
2369 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002370 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2373 transformType, transformValues);
2374}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002375
Sami Väisänend59ca052016-06-21 16:10:00 +03002376void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2377 GLenum pathNameType,
2378 const void *paths,
2379 GLuint pathBase,
2380 GLint reference,
2381 GLuint mask,
2382 GLenum coverMode,
2383 GLenum transformType,
2384 const GLfloat *transformValues)
2385{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002386 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002389 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002390
2391 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2392 transformType, transformValues);
2393}
2394
Sami Väisänen46eaa942016-06-29 10:26:37 +03002395void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2396{
2397 auto *programObject = getProgram(program);
2398
2399 programObject->bindFragmentInputLocation(location, name);
2400}
2401
2402void Context::programPathFragmentInputGen(GLuint program,
2403 GLint location,
2404 GLenum genMode,
2405 GLint components,
2406 const GLfloat *coeffs)
2407{
2408 auto *programObject = getProgram(program);
2409
Jamie Madillbd044ed2017-06-05 12:59:21 -04002410 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002411}
2412
jchen1015015f72017-03-16 13:54:21 +08002413GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2414{
jchen10fd7c3b52017-03-21 15:36:03 +08002415 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002416 return QueryProgramResourceIndex(programObject, programInterface, name);
2417}
2418
jchen10fd7c3b52017-03-21 15:36:03 +08002419void Context::getProgramResourceName(GLuint program,
2420 GLenum programInterface,
2421 GLuint index,
2422 GLsizei bufSize,
2423 GLsizei *length,
2424 GLchar *name)
2425{
2426 const auto *programObject = getProgram(program);
2427 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2428}
2429
jchen10191381f2017-04-11 13:59:04 +08002430GLint Context::getProgramResourceLocation(GLuint program,
2431 GLenum programInterface,
2432 const GLchar *name)
2433{
2434 const auto *programObject = getProgram(program);
2435 return QueryProgramResourceLocation(programObject, programInterface, name);
2436}
2437
jchen10880683b2017-04-12 16:21:55 +08002438void Context::getProgramResourceiv(GLuint program,
2439 GLenum programInterface,
2440 GLuint index,
2441 GLsizei propCount,
2442 const GLenum *props,
2443 GLsizei bufSize,
2444 GLsizei *length,
2445 GLint *params)
2446{
2447 const auto *programObject = getProgram(program);
2448 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2449 length, params);
2450}
2451
jchen10d9cd7b72017-08-30 15:04:25 +08002452void Context::getProgramInterfaceiv(GLuint program,
2453 GLenum programInterface,
2454 GLenum pname,
2455 GLint *params)
2456{
2457 const auto *programObject = getProgram(program);
2458 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2459}
2460
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002461void Context::getProgramInterfaceivRobust(GLuint program,
2462 GLenum programInterface,
2463 GLenum pname,
2464 GLsizei bufSize,
2465 GLsizei *length,
2466 GLint *params)
2467{
2468 UNIMPLEMENTED();
2469}
2470
Jamie Madill427064d2018-04-13 16:20:34 -04002471void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002472{
Geoff Lang7b19a492018-04-20 09:31:52 -04002473 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002474 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002475 GLenum code = error.getCode();
2476 mErrors.insert(code);
2477 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2478 {
2479 markContextLost();
2480 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002481
Geoff Langee6884e2017-11-09 16:51:11 -05002482 ASSERT(!error.getMessage().empty());
2483 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2484 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002485 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486}
2487
2488// Get one of the recorded errors and clear its flag, if any.
2489// [OpenGL ES 2.0.24] section 2.5 page 13.
2490GLenum Context::getError()
2491{
Geoff Langda5777c2014-07-11 09:52:58 -04002492 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002493 {
Geoff Langda5777c2014-07-11 09:52:58 -04002494 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002495 }
Geoff Langda5777c2014-07-11 09:52:58 -04002496 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002497 {
Geoff Langda5777c2014-07-11 09:52:58 -04002498 GLenum error = *mErrors.begin();
2499 mErrors.erase(mErrors.begin());
2500 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502}
2503
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002504// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002505void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002506{
2507 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002508 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002509 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002510 mContextLostForced = true;
2511 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002512 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513}
2514
Jamie Madill427064d2018-04-13 16:20:34 -04002515bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002516{
2517 return mContextLost;
2518}
2519
Jamie Madillfa920eb2018-01-04 11:45:50 -05002520GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002522 // Even if the application doesn't want to know about resets, we want to know
2523 // as it will allow us to skip all the calls.
2524 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002526 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002527 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002528 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002529 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530
2531 // EXT_robustness, section 2.6: If the reset notification behavior is
2532 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2533 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2534 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002535 }
2536
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002537 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2538 // status should be returned at least once, and GL_NO_ERROR should be returned
2539 // once the device has finished resetting.
2540 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002541 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 ASSERT(mResetStatus == GL_NO_ERROR);
2543 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002544
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002546 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002547 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548 }
2549 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002550 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002551 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002552 // If markContextLost was used to mark the context lost then
2553 // assume that is not recoverable, and continue to report the
2554 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 mResetStatus = mImplementation->getResetStatus();
2556 }
Jamie Madill893ab082014-05-16 16:56:10 -04002557
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002558 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002559}
2560
2561bool Context::isResetNotificationEnabled()
2562{
2563 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2564}
2565
Corentin Walleze3b10e82015-05-20 11:06:25 -04002566const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002567{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002568 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002569}
2570
2571EGLenum Context::getClientType() const
2572{
2573 return mClientType;
2574}
2575
2576EGLenum Context::getRenderBuffer() const
2577{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002578 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2579 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002580 {
2581 return EGL_NONE;
2582 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002583
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002584 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002585 ASSERT(backAttachment != nullptr);
2586 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002587}
2588
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002589VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002590{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002591 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002592 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2593 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002594 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002595 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2596 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002597
Jamie Madill96a483b2017-06-27 16:49:21 -04002598 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002599 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002600
2601 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002602}
2603
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002604TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002605{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002606 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002607 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2608 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002609 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002610 transformFeedback =
2611 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002613 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002614 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002615
2616 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002617}
2618
2619bool Context::isVertexArrayGenerated(GLuint vertexArray)
2620{
Jamie Madill96a483b2017-06-27 16:49:21 -04002621 ASSERT(mVertexArrayMap.contains(0));
2622 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002623}
2624
2625bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2626{
Jamie Madill96a483b2017-06-27 16:49:21 -04002627 ASSERT(mTransformFeedbackMap.contains(0));
2628 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002629}
2630
Shannon Woods53a94a82014-06-24 15:20:36 -04002631void Context::detachTexture(GLuint texture)
2632{
2633 // Simple pass-through to State's detachTexture method, as textures do not require
2634 // allocation map management either here or in the resource manager at detach time.
2635 // Zero textures are held by the Context, and we don't attempt to request them from
2636 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002637 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002638}
2639
James Darpinian4d9d4832018-03-13 12:43:28 -07002640void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641{
Yuly Novikov5807a532015-12-03 13:01:22 -05002642 // Simple pass-through to State's detachBuffer method, since
2643 // only buffer attachments to container objects that are bound to the current context
2644 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002645
Yuly Novikov5807a532015-12-03 13:01:22 -05002646 // [OpenGL ES 3.2] section 5.1.2 page 45:
2647 // Attachments to unbound container objects, such as
2648 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2649 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002650 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002651}
2652
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002653void Context::detachFramebuffer(GLuint framebuffer)
2654{
Shannon Woods53a94a82014-06-24 15:20:36 -04002655 // Framebuffer detachment is handled by Context, because 0 is a valid
2656 // Framebuffer object, and a pointer to it must be passed from Context
2657 // to State at binding time.
2658
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2661 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2662 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002664 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002665 {
2666 bindReadFramebuffer(0);
2667 }
2668
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002669 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670 {
2671 bindDrawFramebuffer(0);
2672 }
2673}
2674
2675void Context::detachRenderbuffer(GLuint renderbuffer)
2676{
Jamie Madilla02315b2017-02-23 14:14:47 -05002677 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678}
2679
Jamie Madill57a89722013-07-02 11:57:03 -04002680void Context::detachVertexArray(GLuint vertexArray)
2681{
Jamie Madill77a72f62015-04-14 11:18:32 -04002682 // Vertex array detachment is handled by Context, because 0 is a valid
2683 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002684 // binding time.
2685
Jamie Madill57a89722013-07-02 11:57:03 -04002686 // [OpenGL ES 3.0.2] section 2.10 page 43:
2687 // If a vertex array object that is currently bound is deleted, the binding
2688 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002689 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002690 {
2691 bindVertexArray(0);
2692 }
2693}
2694
Geoff Langc8058452014-02-03 12:04:11 -05002695void Context::detachTransformFeedback(GLuint transformFeedback)
2696{
Corentin Walleza2257da2016-04-19 16:43:12 -04002697 // Transform feedback detachment is handled by Context, because 0 is a valid
2698 // transform feedback, and a pointer to it must be passed from Context to State at
2699 // binding time.
2700
2701 // The OpenGL specification doesn't mention what should happen when the currently bound
2702 // transform feedback object is deleted. Since it is a container object, we treat it like
2703 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002704 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002705 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002706 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002707 }
Geoff Langc8058452014-02-03 12:04:11 -05002708}
2709
Jamie Madilldc356042013-07-19 16:36:57 -04002710void Context::detachSampler(GLuint sampler)
2711{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002712 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002713}
2714
Yunchao Hea336b902017-08-02 16:05:21 +08002715void Context::detachProgramPipeline(GLuint pipeline)
2716{
2717 mGLState.detachProgramPipeline(this, pipeline);
2718}
2719
Jamie Madill3ef140a2017-08-26 23:11:21 -04002720void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002721{
Shaodde78e82017-05-22 14:13:27 +08002722 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002723}
2724
Jamie Madille29d1672013-07-19 16:36:57 -04002725void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2726{
Geoff Langc1984ed2016-10-07 12:41:00 -04002727 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002728 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002729 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002730 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002731}
Jamie Madille29d1672013-07-19 16:36:57 -04002732
Geoff Langc1984ed2016-10-07 12:41:00 -04002733void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2734{
2735 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002736 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002737 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002738 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002739}
2740
Brandon Jones59770802018-04-02 13:18:42 -07002741void Context::samplerParameterivRobust(GLuint sampler,
2742 GLenum pname,
2743 GLsizei bufSize,
2744 const GLint *param)
2745{
2746 samplerParameteriv(sampler, pname, param);
2747}
2748
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002749void Context::samplerParameterIivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 const GLint *param)
2753{
2754 UNIMPLEMENTED();
2755}
2756
2757void Context::samplerParameterIuivRobust(GLuint sampler,
2758 GLenum pname,
2759 GLsizei bufSize,
2760 const GLuint *param)
2761{
2762 UNIMPLEMENTED();
2763}
2764
Jamie Madille29d1672013-07-19 16:36:57 -04002765void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2766{
Geoff Langc1984ed2016-10-07 12:41:00 -04002767 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002768 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002769 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002770 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002771}
2772
Geoff Langc1984ed2016-10-07 12:41:00 -04002773void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002779}
2780
Brandon Jones59770802018-04-02 13:18:42 -07002781void Context::samplerParameterfvRobust(GLuint sampler,
2782 GLenum pname,
2783 GLsizei bufSize,
2784 const GLfloat *param)
2785{
2786 samplerParameterfv(sampler, pname, param);
2787}
2788
Geoff Langc1984ed2016-10-07 12:41:00 -04002789void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002790{
Geoff Langc1984ed2016-10-07 12:41:00 -04002791 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002792 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002793 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002794 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002795}
Jamie Madill9675b802013-07-19 16:36:59 -04002796
Brandon Jones59770802018-04-02 13:18:42 -07002797void Context::getSamplerParameterivRobust(GLuint sampler,
2798 GLenum pname,
2799 GLsizei bufSize,
2800 GLsizei *length,
2801 GLint *params)
2802{
2803 getSamplerParameteriv(sampler, pname, params);
2804}
2805
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002806void Context::getSamplerParameterIivRobust(GLuint sampler,
2807 GLenum pname,
2808 GLsizei bufSize,
2809 GLsizei *length,
2810 GLint *params)
2811{
2812 UNIMPLEMENTED();
2813}
2814
2815void Context::getSamplerParameterIuivRobust(GLuint sampler,
2816 GLenum pname,
2817 GLsizei bufSize,
2818 GLsizei *length,
2819 GLuint *params)
2820{
2821 UNIMPLEMENTED();
2822}
2823
Geoff Langc1984ed2016-10-07 12:41:00 -04002824void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2825{
2826 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002827 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002828 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002829 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002830}
2831
Brandon Jones59770802018-04-02 13:18:42 -07002832void Context::getSamplerParameterfvRobust(GLuint sampler,
2833 GLenum pname,
2834 GLsizei bufSize,
2835 GLsizei *length,
2836 GLfloat *params)
2837{
2838 getSamplerParameterfv(sampler, pname, params);
2839}
2840
Olli Etuahof0fee072016-03-30 15:11:58 +03002841void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2842{
2843 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002844 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002845}
2846
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002847void Context::initRendererString()
2848{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002849 std::ostringstream rendererString;
2850 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002851 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002852 rendererString << ")";
2853
Geoff Langcec35902014-04-16 10:52:36 -04002854 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855}
2856
Geoff Langc339c4e2016-11-29 10:37:36 -05002857void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002858{
Geoff Langc339c4e2016-11-29 10:37:36 -05002859 const Version &clientVersion = getClientVersion();
2860
2861 std::ostringstream versionString;
2862 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2863 << ANGLE_VERSION_STRING << ")";
2864 mVersionString = MakeStaticString(versionString.str());
2865
2866 std::ostringstream shadingLanguageVersionString;
2867 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2868 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2869 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2870 << ")";
2871 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002872}
2873
Geoff Langcec35902014-04-16 10:52:36 -04002874void Context::initExtensionStrings()
2875{
Geoff Langc339c4e2016-11-29 10:37:36 -05002876 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2877 std::ostringstream combinedStringStream;
2878 std::copy(strings.begin(), strings.end(),
2879 std::ostream_iterator<const char *>(combinedStringStream, " "));
2880 return MakeStaticString(combinedStringStream.str());
2881 };
2882
2883 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002884 for (const auto &extensionString : mExtensions.getStrings())
2885 {
2886 mExtensionStrings.push_back(MakeStaticString(extensionString));
2887 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002888 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002889
Geoff Langc339c4e2016-11-29 10:37:36 -05002890 mRequestableExtensionStrings.clear();
2891 for (const auto &extensionInfo : GetExtensionInfoMap())
2892 {
2893 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002894 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002895 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002896 {
2897 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2898 }
2899 }
2900 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002901}
2902
Geoff Langc339c4e2016-11-29 10:37:36 -05002903const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002904{
Geoff Langc339c4e2016-11-29 10:37:36 -05002905 switch (name)
2906 {
2907 case GL_VENDOR:
2908 return reinterpret_cast<const GLubyte *>("Google Inc.");
2909
2910 case GL_RENDERER:
2911 return reinterpret_cast<const GLubyte *>(mRendererString);
2912
2913 case GL_VERSION:
2914 return reinterpret_cast<const GLubyte *>(mVersionString);
2915
2916 case GL_SHADING_LANGUAGE_VERSION:
2917 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2918
2919 case GL_EXTENSIONS:
2920 return reinterpret_cast<const GLubyte *>(mExtensionString);
2921
2922 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2923 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2924
2925 default:
2926 UNREACHABLE();
2927 return nullptr;
2928 }
Geoff Langcec35902014-04-16 10:52:36 -04002929}
2930
Geoff Langc339c4e2016-11-29 10:37:36 -05002931const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002932{
Geoff Langc339c4e2016-11-29 10:37:36 -05002933 switch (name)
2934 {
2935 case GL_EXTENSIONS:
2936 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2937
2938 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2939 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2940
2941 default:
2942 UNREACHABLE();
2943 return nullptr;
2944 }
Geoff Langcec35902014-04-16 10:52:36 -04002945}
2946
2947size_t Context::getExtensionStringCount() const
2948{
2949 return mExtensionStrings.size();
2950}
2951
Geoff Lang111a99e2017-10-17 10:58:41 -04002952bool Context::isExtensionRequestable(const char *name)
2953{
2954 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2955 auto extension = extensionInfos.find(name);
2956
Geoff Lang111a99e2017-10-17 10:58:41 -04002957 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002958 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002959}
2960
Geoff Langc339c4e2016-11-29 10:37:36 -05002961void Context::requestExtension(const char *name)
2962{
2963 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2964 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2965 const auto &extension = extensionInfos.at(name);
2966 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002967 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002968
2969 if (mExtensions.*(extension.ExtensionsMember))
2970 {
2971 // Extension already enabled
2972 return;
2973 }
2974
2975 mExtensions.*(extension.ExtensionsMember) = true;
2976 updateCaps();
2977 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002978
Jamie Madill2f348d22017-06-05 10:50:59 -04002979 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2980 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002981
Jamie Madill81c2e252017-09-09 23:32:46 -04002982 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2983 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002984 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002985 for (auto &zeroTexture : mZeroTextures)
2986 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002987 if (zeroTexture.get() != nullptr)
2988 {
2989 zeroTexture->signalDirty(this, InitState::Initialized);
2990 }
Geoff Lang9aded172017-04-05 11:07:56 -04002991 }
2992
2993 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002994}
2995
2996size_t Context::getRequestableExtensionStringCount() const
2997{
2998 return mRequestableExtensionStrings.size();
2999}
3000
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003001void Context::beginTransformFeedback(GLenum primitiveMode)
3002{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003003 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003004 ASSERT(transformFeedback != nullptr);
3005 ASSERT(!transformFeedback->isPaused());
3006
Jamie Madill6c1f6712017-02-14 19:08:04 -05003007 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003008}
3009
3010bool Context::hasActiveTransformFeedback(GLuint program) const
3011{
3012 for (auto pair : mTransformFeedbackMap)
3013 {
3014 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3015 {
3016 return true;
3017 }
3018 }
3019 return false;
3020}
3021
Geoff Langb0f917f2017-12-05 13:41:54 -05003022Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
3023 bool robustResourceInit) const
3024{
3025 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3026
3027 if (getClientVersion() < ES_2_0)
3028 {
3029 // Default extensions for GLES1
3030 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003031 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003032 }
3033
3034 if (getClientVersion() < ES_3_0)
3035 {
3036 // Disable ES3+ extensions
3037 supportedExtensions.colorBufferFloat = false;
3038 supportedExtensions.eglImageExternalEssl3 = false;
3039 supportedExtensions.textureNorm16 = false;
3040 supportedExtensions.multiview = false;
3041 supportedExtensions.maxViews = 1u;
3042 }
3043
3044 if (getClientVersion() < ES_3_1)
3045 {
3046 // Disable ES3.1+ extensions
3047 supportedExtensions.geometryShader = false;
3048 }
3049
3050 if (getClientVersion() > ES_2_0)
3051 {
3052 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3053 // supportedExtensions.sRGB = false;
3054 }
3055
3056 // Some extensions are always available because they are implemented in the GL layer.
3057 supportedExtensions.bindUniformLocation = true;
3058 supportedExtensions.vertexArrayObject = true;
3059 supportedExtensions.bindGeneratesResource = true;
3060 supportedExtensions.clientArrays = true;
3061 supportedExtensions.requestExtension = true;
3062
3063 // Enable the no error extension if the context was created with the flag.
3064 supportedExtensions.noError = mSkipValidation;
3065
3066 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3067 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3068
3069 // Explicitly enable GL_KHR_debug
3070 supportedExtensions.debug = true;
3071 supportedExtensions.maxDebugMessageLength = 1024;
3072 supportedExtensions.maxDebugLoggedMessages = 1024;
3073 supportedExtensions.maxDebugGroupStackDepth = 1024;
3074 supportedExtensions.maxLabelLength = 1024;
3075
3076 // Explicitly enable GL_ANGLE_robust_client_memory
3077 supportedExtensions.robustClientMemory = true;
3078
3079 // Determine robust resource init availability from EGL.
3080 supportedExtensions.robustResourceInitialization = robustResourceInit;
3081
3082 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3083 // supports it.
3084 supportedExtensions.robustBufferAccessBehavior =
3085 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3086
3087 // Enable the cache control query unconditionally.
3088 supportedExtensions.programCacheControl = true;
3089
3090 return supportedExtensions;
3091}
3092
Geoff Langb433e872017-10-05 14:01:47 -04003093void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003094{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003095 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003096
Geoff Langb0f917f2017-12-05 13:41:54 -05003097 mSupportedExtensions = generateSupportedExtensions(displayExtensions, robustResourceInit);
3098 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003099
3100 mLimitations = mImplementation->getNativeLimitations();
3101
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003102 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3103 if (getClientVersion() < Version(2, 0))
3104 {
3105 mCaps.maxMultitextureUnits = 4;
3106 mCaps.maxClipPlanes = 6;
3107 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003108 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3109 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3110 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003111 }
3112
Geoff Lang301d1612014-07-09 10:34:37 -04003113 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003114 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003115
Jamie Madill0f80ed82017-09-19 00:24:56 -04003116 if (getClientVersion() < ES_3_1)
3117 {
3118 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3119 }
3120 else
3121 {
3122 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3123 }
Geoff Lang301d1612014-07-09 10:34:37 -04003124
Jiawei Shao54aafe52018-04-27 14:54:57 +08003125 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3126 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003127 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3128 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3129
3130 // Limit textures as well, so we can use fast bitsets with texture bindings.
3131 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003132 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3133 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3134 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3135 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003136
Jiawei Shaodb342272017-09-27 10:21:45 +08003137 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3138
Geoff Langc287ea62016-09-16 14:46:51 -04003139 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003140 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003141 for (const auto &extensionInfo : GetExtensionInfoMap())
3142 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003143 // If the user has requested that extensions start disabled and they are requestable,
3144 // disable them.
3145 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003146 {
3147 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3148 }
3149 }
3150
3151 // Generate texture caps
3152 updateCaps();
3153}
3154
3155void Context::updateCaps()
3156{
Geoff Lang900013c2014-07-07 11:32:19 -04003157 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003158 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003159
Jamie Madill7b62cf92017-11-02 15:20:49 -04003160 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003161 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003162 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003163 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003164
Geoff Lang0d8b7242015-09-09 14:56:53 -04003165 // Update the format caps based on the client version and extensions.
3166 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3167 // ES3.
3168 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003169 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003170 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003171 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003172 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003173 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003174
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003175 // OpenGL ES does not support multisampling with non-rendererable formats
3176 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003177 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003178 (getClientVersion() < ES_3_1 &&
3179 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003180 {
Geoff Langd87878e2014-09-19 15:42:59 -04003181 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003182 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003183 else
3184 {
3185 // We may have limited the max samples for some required renderbuffer formats due to
3186 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3187 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3188
3189 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3190 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3191 // exception of signed and unsigned integer formats."
3192 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3193 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3194 {
3195 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3196 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3197 }
3198
3199 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3200 if (getClientVersion() >= ES_3_1)
3201 {
3202 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3203 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3204 // the exception that the signed and unsigned integer formats are required only to
3205 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3206 // multisamples, which must be at least one."
3207 if (formatInfo.componentType == GL_INT ||
3208 formatInfo.componentType == GL_UNSIGNED_INT)
3209 {
3210 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3211 }
3212
3213 // GLES 3.1 section 19.3.1.
3214 if (formatCaps.texturable)
3215 {
3216 if (formatInfo.depthBits > 0)
3217 {
3218 mCaps.maxDepthTextureSamples =
3219 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3220 }
3221 else if (formatInfo.redBits > 0)
3222 {
3223 mCaps.maxColorTextureSamples =
3224 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3225 }
3226 }
3227 }
3228 }
Geoff Langd87878e2014-09-19 15:42:59 -04003229
3230 if (formatCaps.texturable && formatInfo.compressed)
3231 {
Geoff Langca271392017-04-05 12:30:00 -04003232 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003233 }
3234
Geoff Langca271392017-04-05 12:30:00 -04003235 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003236 }
Jamie Madill32447362017-06-28 14:53:52 -04003237
3238 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003239 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003240 {
3241 mMemoryProgramCache = nullptr;
3242 }
Corentin Walleze4477002017-12-01 14:39:58 -05003243
3244 // Compute which buffer types are allowed
3245 mValidBufferBindings.reset();
3246 mValidBufferBindings.set(BufferBinding::ElementArray);
3247 mValidBufferBindings.set(BufferBinding::Array);
3248
3249 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3250 {
3251 mValidBufferBindings.set(BufferBinding::PixelPack);
3252 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3253 }
3254
3255 if (getClientVersion() >= ES_3_0)
3256 {
3257 mValidBufferBindings.set(BufferBinding::CopyRead);
3258 mValidBufferBindings.set(BufferBinding::CopyWrite);
3259 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3260 mValidBufferBindings.set(BufferBinding::Uniform);
3261 }
3262
3263 if (getClientVersion() >= ES_3_1)
3264 {
3265 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3266 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3267 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3268 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3269 }
Geoff Lang493daf52014-07-03 13:38:44 -04003270}
3271
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003272void Context::initWorkarounds()
3273{
Jamie Madill761b02c2017-06-23 16:27:06 -04003274 // Apply back-end workarounds.
3275 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3276
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003277 // Lose the context upon out of memory error if the application is
3278 // expecting to watch for those events.
3279 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3280}
3281
Jamie Madill05b35b22017-10-03 09:01:44 -04003282Error Context::prepareForDraw()
3283{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003284 if (mGLES1Renderer)
3285 {
3286 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3287 }
3288
Geoff Langa8cb2872018-03-09 16:09:40 -05003289 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003290
3291 if (isRobustResourceInitEnabled())
3292 {
3293 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3294 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3295 }
3296
Geoff Langa8cb2872018-03-09 16:09:40 -05003297 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003298 return NoError();
3299}
3300
3301Error Context::prepareForClear(GLbitfield mask)
3302{
Geoff Langa8cb2872018-03-09 16:09:40 -05003303 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003304 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003305 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003306 return NoError();
3307}
3308
3309Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3310{
Geoff Langa8cb2872018-03-09 16:09:40 -05003311 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003312 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3313 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003314 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003315 return NoError();
3316}
3317
Geoff Langa8cb2872018-03-09 16:09:40 -05003318Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003319{
Geoff Langa8cb2872018-03-09 16:09:40 -05003320 ANGLE_TRY(syncDirtyObjects());
3321 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003322 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003323}
3324
Geoff Langa8cb2872018-03-09 16:09:40 -05003325Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003326{
Geoff Langa8cb2872018-03-09 16:09:40 -05003327 ANGLE_TRY(syncDirtyObjects(objectMask));
3328 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003329 return NoError();
3330}
3331
Geoff Langa8cb2872018-03-09 16:09:40 -05003332Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003333{
3334 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3335 mImplementation->syncState(this, dirtyBits);
3336 mGLState.clearDirtyBits();
3337 return NoError();
3338}
3339
Geoff Langa8cb2872018-03-09 16:09:40 -05003340Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003341{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003342 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003343 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003344 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003345 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003346}
Jamie Madillc29968b2016-01-20 11:17:23 -05003347
Geoff Langa8cb2872018-03-09 16:09:40 -05003348Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003349{
3350 return mGLState.syncDirtyObjects(this);
3351}
3352
Geoff Langa8cb2872018-03-09 16:09:40 -05003353Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003354{
3355 return mGLState.syncDirtyObjects(this, objectMask);
3356}
3357
Jamie Madillc29968b2016-01-20 11:17:23 -05003358void Context::blitFramebuffer(GLint srcX0,
3359 GLint srcY0,
3360 GLint srcX1,
3361 GLint srcY1,
3362 GLint dstX0,
3363 GLint dstY0,
3364 GLint dstX1,
3365 GLint dstY1,
3366 GLbitfield mask,
3367 GLenum filter)
3368{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003369 if (mask == 0)
3370 {
3371 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3372 // buffers are copied.
3373 return;
3374 }
3375
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003376 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003377 ASSERT(drawFramebuffer);
3378
3379 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3380 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3381
Jamie Madillbc918e72018-03-08 09:47:21 -05003382 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003383
Jamie Madillc564c072017-06-01 12:45:42 -04003384 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003385}
Jamie Madillc29968b2016-01-20 11:17:23 -05003386
3387void Context::clear(GLbitfield mask)
3388{
Geoff Langd4fff502017-09-22 11:28:28 -04003389 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3390 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003391}
3392
3393void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3394{
Geoff Langd4fff502017-09-22 11:28:28 -04003395 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3396 ANGLE_CONTEXT_TRY(
3397 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003398}
3399
3400void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3401{
Geoff Langd4fff502017-09-22 11:28:28 -04003402 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3403 ANGLE_CONTEXT_TRY(
3404 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003405}
3406
3407void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3408{
Geoff Langd4fff502017-09-22 11:28:28 -04003409 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3410 ANGLE_CONTEXT_TRY(
3411 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003412}
3413
3414void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003416 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003417 ASSERT(framebufferObject);
3418
3419 // If a buffer is not present, the clear has no effect
3420 if (framebufferObject->getDepthbuffer() == nullptr &&
3421 framebufferObject->getStencilbuffer() == nullptr)
3422 {
3423 return;
3424 }
3425
Geoff Langd4fff502017-09-22 11:28:28 -04003426 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3427 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003428}
3429
3430void Context::readPixels(GLint x,
3431 GLint y,
3432 GLsizei width,
3433 GLsizei height,
3434 GLenum format,
3435 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003436 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003437{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003438 if (width == 0 || height == 0)
3439 {
3440 return;
3441 }
3442
Jamie Madillbc918e72018-03-08 09:47:21 -05003443 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003444
Jamie Madillb6664922017-07-25 12:55:04 -04003445 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3446 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003447
3448 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003449 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003450}
3451
Brandon Jones59770802018-04-02 13:18:42 -07003452void Context::readPixelsRobust(GLint x,
3453 GLint y,
3454 GLsizei width,
3455 GLsizei height,
3456 GLenum format,
3457 GLenum type,
3458 GLsizei bufSize,
3459 GLsizei *length,
3460 GLsizei *columns,
3461 GLsizei *rows,
3462 void *pixels)
3463{
3464 readPixels(x, y, width, height, format, type, pixels);
3465}
3466
3467void Context::readnPixelsRobust(GLint x,
3468 GLint y,
3469 GLsizei width,
3470 GLsizei height,
3471 GLenum format,
3472 GLenum type,
3473 GLsizei bufSize,
3474 GLsizei *length,
3475 GLsizei *columns,
3476 GLsizei *rows,
3477 void *data)
3478{
3479 readPixels(x, y, width, height, format, type, data);
3480}
3481
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003482void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003483 GLint level,
3484 GLenum internalformat,
3485 GLint x,
3486 GLint y,
3487 GLsizei width,
3488 GLsizei height,
3489 GLint border)
3490{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003491 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003492 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003493
Jamie Madillc29968b2016-01-20 11:17:23 -05003494 Rectangle sourceArea(x, y, width, height);
3495
Jamie Madill05b35b22017-10-03 09:01:44 -04003496 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003497 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003498 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003499}
3500
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003501void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 GLint level,
3503 GLint xoffset,
3504 GLint yoffset,
3505 GLint x,
3506 GLint y,
3507 GLsizei width,
3508 GLsizei height)
3509{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003510 if (width == 0 || height == 0)
3511 {
3512 return;
3513 }
3514
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003515 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003516 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003517
Jamie Madillc29968b2016-01-20 11:17:23 -05003518 Offset destOffset(xoffset, yoffset, 0);
3519 Rectangle sourceArea(x, y, width, height);
3520
Jamie Madill05b35b22017-10-03 09:01:44 -04003521 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003522 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003523 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003524}
3525
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003526void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003527 GLint level,
3528 GLint xoffset,
3529 GLint yoffset,
3530 GLint zoffset,
3531 GLint x,
3532 GLint y,
3533 GLsizei width,
3534 GLsizei height)
3535{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003536 if (width == 0 || height == 0)
3537 {
3538 return;
3539 }
3540
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003541 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003542 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003543
Jamie Madillc29968b2016-01-20 11:17:23 -05003544 Offset destOffset(xoffset, yoffset, zoffset);
3545 Rectangle sourceArea(x, y, width, height);
3546
Jamie Madill05b35b22017-10-03 09:01:44 -04003547 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3548 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003549 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3550 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003551}
3552
3553void Context::framebufferTexture2D(GLenum target,
3554 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003555 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003556 GLuint texture,
3557 GLint level)
3558{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003559 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003560 ASSERT(framebuffer);
3561
3562 if (texture != 0)
3563 {
3564 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003565 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003566 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003567 }
3568 else
3569 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003570 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003571 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003572
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003574}
3575
3576void Context::framebufferRenderbuffer(GLenum target,
3577 GLenum attachment,
3578 GLenum renderbuffertarget,
3579 GLuint renderbuffer)
3580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003581 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003582 ASSERT(framebuffer);
3583
3584 if (renderbuffer != 0)
3585 {
3586 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003587
Jamie Madillcc129372018-04-12 09:13:18 -04003588 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003589 renderbufferObject);
3590 }
3591 else
3592 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003593 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003594 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003595
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003597}
3598
3599void Context::framebufferTextureLayer(GLenum target,
3600 GLenum attachment,
3601 GLuint texture,
3602 GLint level,
3603 GLint layer)
3604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003606 ASSERT(framebuffer);
3607
3608 if (texture != 0)
3609 {
3610 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003611 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003612 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003613 }
3614 else
3615 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003616 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003617 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003618
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003619 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003620}
3621
Brandon Jones59770802018-04-02 13:18:42 -07003622void Context::framebufferTextureMultiviewLayered(GLenum target,
3623 GLenum attachment,
3624 GLuint texture,
3625 GLint level,
3626 GLint baseViewIndex,
3627 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003628{
Martin Radev82ef7742017-08-08 17:44:58 +03003629 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3630 ASSERT(framebuffer);
3631
3632 if (texture != 0)
3633 {
3634 Texture *textureObj = getTexture(texture);
3635
Martin Radev18b75ba2017-08-15 15:50:40 +03003636 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003637 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3638 numViews, baseViewIndex);
3639 }
3640 else
3641 {
3642 framebuffer->resetAttachment(this, attachment);
3643 }
3644
3645 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003646}
3647
Brandon Jones59770802018-04-02 13:18:42 -07003648void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3649 GLenum attachment,
3650 GLuint texture,
3651 GLint level,
3652 GLsizei numViews,
3653 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003654{
Martin Radev5dae57b2017-07-14 16:15:55 +03003655 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3656 ASSERT(framebuffer);
3657
3658 if (texture != 0)
3659 {
3660 Texture *textureObj = getTexture(texture);
3661
3662 ImageIndex index = ImageIndex::Make2D(level);
3663 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3664 textureObj, numViews, viewportOffsets);
3665 }
3666 else
3667 {
3668 framebuffer->resetAttachment(this, attachment);
3669 }
3670
3671 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003672}
3673
Jamie Madillc29968b2016-01-20 11:17:23 -05003674void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3675{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003677 ASSERT(framebuffer);
3678 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003679 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003680}
3681
3682void Context::readBuffer(GLenum mode)
3683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003687}
3688
3689void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3690{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003692 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003693
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003695 ASSERT(framebuffer);
3696
3697 // The specification isn't clear what should be done when the framebuffer isn't complete.
3698 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003699 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003700}
3701
3702void Context::invalidateFramebuffer(GLenum target,
3703 GLsizei numAttachments,
3704 const GLenum *attachments)
3705{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003706 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003707 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003708
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003710 ASSERT(framebuffer);
3711
Jamie Madill427064d2018-04-13 16:20:34 -04003712 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 {
Jamie Madill437fa652016-05-03 15:13:24 -04003714 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003715 }
Jamie Madill437fa652016-05-03 15:13:24 -04003716
Jamie Madill4928b7c2017-06-20 12:57:39 -04003717 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003718}
3719
3720void Context::invalidateSubFramebuffer(GLenum target,
3721 GLsizei numAttachments,
3722 const GLenum *attachments,
3723 GLint x,
3724 GLint y,
3725 GLsizei width,
3726 GLsizei height)
3727{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003728 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003729 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003730
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 ASSERT(framebuffer);
3733
Jamie Madill427064d2018-04-13 16:20:34 -04003734 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 {
Jamie Madill437fa652016-05-03 15:13:24 -04003736 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003737 }
Jamie Madill437fa652016-05-03 15:13:24 -04003738
3739 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003740 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003741}
3742
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003743void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003744 GLint level,
3745 GLint internalformat,
3746 GLsizei width,
3747 GLsizei height,
3748 GLint border,
3749 GLenum format,
3750 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003751 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003752{
Jamie Madillbc918e72018-03-08 09:47:21 -05003753 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003754
3755 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003756 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003757 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3758 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003759}
3760
Brandon Jones59770802018-04-02 13:18:42 -07003761void Context::texImage2DRobust(TextureTarget target,
3762 GLint level,
3763 GLint internalformat,
3764 GLsizei width,
3765 GLsizei height,
3766 GLint border,
3767 GLenum format,
3768 GLenum type,
3769 GLsizei bufSize,
3770 const void *pixels)
3771{
3772 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3773}
3774
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003775void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003776 GLint level,
3777 GLint internalformat,
3778 GLsizei width,
3779 GLsizei height,
3780 GLsizei depth,
3781 GLint border,
3782 GLenum format,
3783 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003784 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003785{
Jamie Madillbc918e72018-03-08 09:47:21 -05003786 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003787
3788 Extents size(width, height, depth);
3789 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003790 handleError(texture->setImage(this, mGLState.getUnpackState(),
3791 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3792 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003793}
3794
Brandon Jones59770802018-04-02 13:18:42 -07003795void Context::texImage3DRobust(TextureType target,
3796 GLint level,
3797 GLint internalformat,
3798 GLsizei width,
3799 GLsizei height,
3800 GLsizei depth,
3801 GLint border,
3802 GLenum format,
3803 GLenum type,
3804 GLsizei bufSize,
3805 const void *pixels)
3806{
3807 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3808}
3809
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003810void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003811 GLint level,
3812 GLint xoffset,
3813 GLint yoffset,
3814 GLsizei width,
3815 GLsizei height,
3816 GLenum format,
3817 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003818 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003819{
3820 // Zero sized uploads are valid but no-ops
3821 if (width == 0 || height == 0)
3822 {
3823 return;
3824 }
3825
Jamie Madillbc918e72018-03-08 09:47:21 -05003826 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003827
3828 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003829 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003830 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3831 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003832}
3833
Brandon Jones59770802018-04-02 13:18:42 -07003834void Context::texSubImage2DRobust(TextureTarget target,
3835 GLint level,
3836 GLint xoffset,
3837 GLint yoffset,
3838 GLsizei width,
3839 GLsizei height,
3840 GLenum format,
3841 GLenum type,
3842 GLsizei bufSize,
3843 const void *pixels)
3844{
3845 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3846}
3847
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003848void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003849 GLint level,
3850 GLint xoffset,
3851 GLint yoffset,
3852 GLint zoffset,
3853 GLsizei width,
3854 GLsizei height,
3855 GLsizei depth,
3856 GLenum format,
3857 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003858 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003859{
3860 // Zero sized uploads are valid but no-ops
3861 if (width == 0 || height == 0 || depth == 0)
3862 {
3863 return;
3864 }
3865
Jamie Madillbc918e72018-03-08 09:47:21 -05003866 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003867
3868 Box area(xoffset, yoffset, zoffset, width, height, depth);
3869 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003870 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3871 NonCubeTextureTypeToTarget(target), level, area, format, type,
3872 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003873}
3874
Brandon Jones59770802018-04-02 13:18:42 -07003875void Context::texSubImage3DRobust(TextureType target,
3876 GLint level,
3877 GLint xoffset,
3878 GLint yoffset,
3879 GLint zoffset,
3880 GLsizei width,
3881 GLsizei height,
3882 GLsizei depth,
3883 GLenum format,
3884 GLenum type,
3885 GLsizei bufSize,
3886 const void *pixels)
3887{
3888 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3889 pixels);
3890}
3891
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003892void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003893 GLint level,
3894 GLenum internalformat,
3895 GLsizei width,
3896 GLsizei height,
3897 GLint border,
3898 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003899 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003900{
Jamie Madillbc918e72018-03-08 09:47:21 -05003901 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003902
3903 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003904 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003905 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3906 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003907 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003908}
3909
Brandon Jones59770802018-04-02 13:18:42 -07003910void Context::compressedTexImage2DRobust(TextureTarget target,
3911 GLint level,
3912 GLenum internalformat,
3913 GLsizei width,
3914 GLsizei height,
3915 GLint border,
3916 GLsizei imageSize,
3917 GLsizei dataSize,
3918 const GLvoid *data)
3919{
3920 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3921}
3922
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003923void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003924 GLint level,
3925 GLenum internalformat,
3926 GLsizei width,
3927 GLsizei height,
3928 GLsizei depth,
3929 GLint border,
3930 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003931 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003932{
Jamie Madillbc918e72018-03-08 09:47:21 -05003933 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003934
3935 Extents size(width, height, depth);
3936 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003937 handleError(texture->setCompressedImage(
3938 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3939 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003940}
3941
Brandon Jones59770802018-04-02 13:18:42 -07003942void Context::compressedTexImage3DRobust(TextureType target,
3943 GLint level,
3944 GLenum internalformat,
3945 GLsizei width,
3946 GLsizei height,
3947 GLsizei depth,
3948 GLint border,
3949 GLsizei imageSize,
3950 GLsizei dataSize,
3951 const GLvoid *data)
3952{
3953 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3954 data);
3955}
3956
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003957void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003958 GLint level,
3959 GLint xoffset,
3960 GLint yoffset,
3961 GLsizei width,
3962 GLsizei height,
3963 GLenum format,
3964 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003965 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003966{
Jamie Madillbc918e72018-03-08 09:47:21 -05003967 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003968
3969 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003970 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003971 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3972 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003974}
3975
Brandon Jones59770802018-04-02 13:18:42 -07003976void Context::compressedTexSubImage2DRobust(TextureTarget target,
3977 GLint level,
3978 GLint xoffset,
3979 GLint yoffset,
3980 GLsizei width,
3981 GLsizei height,
3982 GLenum format,
3983 GLsizei imageSize,
3984 GLsizei dataSize,
3985 const GLvoid *data)
3986{
3987 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3988 data);
3989}
3990
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003991void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003992 GLint level,
3993 GLint xoffset,
3994 GLint yoffset,
3995 GLint zoffset,
3996 GLsizei width,
3997 GLsizei height,
3998 GLsizei depth,
3999 GLenum format,
4000 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004001 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004002{
4003 // Zero sized uploads are valid but no-ops
4004 if (width == 0 || height == 0)
4005 {
4006 return;
4007 }
4008
Jamie Madillbc918e72018-03-08 09:47:21 -05004009 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004010
4011 Box area(xoffset, yoffset, zoffset, width, height, depth);
4012 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004013 handleError(texture->setCompressedSubImage(
4014 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4015 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004016}
4017
Brandon Jones59770802018-04-02 13:18:42 -07004018void Context::compressedTexSubImage3DRobust(TextureType target,
4019 GLint level,
4020 GLint xoffset,
4021 GLint yoffset,
4022 GLint zoffset,
4023 GLsizei width,
4024 GLsizei height,
4025 GLsizei depth,
4026 GLenum format,
4027 GLsizei imageSize,
4028 GLsizei dataSize,
4029 const GLvoid *data)
4030{
4031 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4032 imageSize, data);
4033}
4034
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004035void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004036{
4037 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004038 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004039}
4040
Jamie Madill007530e2017-12-28 14:27:04 -05004041void Context::copyTexture(GLuint sourceId,
4042 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004043 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004044 GLuint destId,
4045 GLint destLevel,
4046 GLint internalFormat,
4047 GLenum destType,
4048 GLboolean unpackFlipY,
4049 GLboolean unpackPremultiplyAlpha,
4050 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004051{
Jamie Madillbc918e72018-03-08 09:47:21 -05004052 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004053
4054 gl::Texture *sourceTexture = getTexture(sourceId);
4055 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004056 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4057 sourceLevel, ConvertToBool(unpackFlipY),
4058 ConvertToBool(unpackPremultiplyAlpha),
4059 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004060}
4061
Jamie Madill007530e2017-12-28 14:27:04 -05004062void Context::copySubTexture(GLuint sourceId,
4063 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004064 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004065 GLuint destId,
4066 GLint destLevel,
4067 GLint xoffset,
4068 GLint yoffset,
4069 GLint x,
4070 GLint y,
4071 GLsizei width,
4072 GLsizei height,
4073 GLboolean unpackFlipY,
4074 GLboolean unpackPremultiplyAlpha,
4075 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004076{
4077 // Zero sized copies are valid but no-ops
4078 if (width == 0 || height == 0)
4079 {
4080 return;
4081 }
4082
Jamie Madillbc918e72018-03-08 09:47:21 -05004083 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004084
4085 gl::Texture *sourceTexture = getTexture(sourceId);
4086 gl::Texture *destTexture = getTexture(destId);
4087 Offset offset(xoffset, yoffset, 0);
4088 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004089 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4090 ConvertToBool(unpackFlipY),
4091 ConvertToBool(unpackPremultiplyAlpha),
4092 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004093}
4094
Jamie Madill007530e2017-12-28 14:27:04 -05004095void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004096{
Jamie Madillbc918e72018-03-08 09:47:21 -05004097 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004098
4099 gl::Texture *sourceTexture = getTexture(sourceId);
4100 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004101 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004102}
4103
Corentin Wallez336129f2017-10-17 15:55:40 -04004104void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004105{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004106 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004107 ASSERT(buffer);
4108
Geoff Lang496c02d2016-10-20 11:38:11 -07004109 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004110}
4111
Brandon Jones59770802018-04-02 13:18:42 -07004112void Context::getBufferPointervRobust(BufferBinding target,
4113 GLenum pname,
4114 GLsizei bufSize,
4115 GLsizei *length,
4116 void **params)
4117{
4118 getBufferPointerv(target, pname, params);
4119}
4120
Corentin Wallez336129f2017-10-17 15:55:40 -04004121void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004124 ASSERT(buffer);
4125
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004126 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004127 if (error.isError())
4128 {
Jamie Madill437fa652016-05-03 15:13:24 -04004129 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004130 return nullptr;
4131 }
4132
4133 return buffer->getMapPointer();
4134}
4135
Corentin Wallez336129f2017-10-17 15:55:40 -04004136GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004137{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004138 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004139 ASSERT(buffer);
4140
4141 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004142 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004143 if (error.isError())
4144 {
Jamie Madill437fa652016-05-03 15:13:24 -04004145 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004146 return GL_FALSE;
4147 }
4148
4149 return result;
4150}
4151
Corentin Wallez336129f2017-10-17 15:55:40 -04004152void *Context::mapBufferRange(BufferBinding target,
4153 GLintptr offset,
4154 GLsizeiptr length,
4155 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004157 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004158 ASSERT(buffer);
4159
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004160 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004161 if (error.isError())
4162 {
Jamie Madill437fa652016-05-03 15:13:24 -04004163 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004164 return nullptr;
4165 }
4166
4167 return buffer->getMapPointer();
4168}
4169
Corentin Wallez336129f2017-10-17 15:55:40 -04004170void Context::flushMappedBufferRange(BufferBinding /*target*/,
4171 GLintptr /*offset*/,
4172 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004173{
4174 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4175}
4176
Jamie Madillbc918e72018-03-08 09:47:21 -05004177Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004178{
Geoff Langa8cb2872018-03-09 16:09:40 -05004179 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004180}
4181
Jamie Madillbc918e72018-03-08 09:47:21 -05004182Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004183{
Geoff Langa8cb2872018-03-09 16:09:40 -05004184 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004185}
4186
Jamie Madillbc918e72018-03-08 09:47:21 -05004187Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004188{
Geoff Langa8cb2872018-03-09 16:09:40 -05004189 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004190}
4191
Jiajia Qin5451d532017-11-16 17:16:34 +08004192void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4193{
4194 UNIMPLEMENTED();
4195}
4196
Jamie Madillc20ab272016-06-09 07:20:46 -07004197void Context::activeTexture(GLenum texture)
4198{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004199 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004200}
4201
Jamie Madill876429b2017-04-20 15:46:24 -04004202void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004204 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004205}
4206
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004207void Context::blendEquation(GLenum mode)
4208{
4209 mGLState.setBlendEquation(mode, mode);
4210}
4211
Jamie Madillc20ab272016-06-09 07:20:46 -07004212void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4213{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004214 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004215}
4216
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004217void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4218{
4219 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4220}
4221
Jamie Madillc20ab272016-06-09 07:20:46 -07004222void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004224 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004225}
4226
Jamie Madill876429b2017-04-20 15:46:24 -04004227void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004229 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004230}
4231
Jamie Madill876429b2017-04-20 15:46:24 -04004232void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004234 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004235}
4236
4237void Context::clearStencil(GLint s)
4238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
4242void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4243{
Geoff Lang92019432017-11-20 13:09:34 -05004244 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4245 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004246}
4247
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004248void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004249{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004250 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004251}
4252
4253void Context::depthFunc(GLenum func)
4254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004256}
4257
4258void Context::depthMask(GLboolean flag)
4259{
Geoff Lang92019432017-11-20 13:09:34 -05004260 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004261}
4262
Jamie Madill876429b2017-04-20 15:46:24 -04004263void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004264{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004265 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004266}
4267
4268void Context::disable(GLenum cap)
4269{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004270 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004271}
4272
4273void Context::disableVertexAttribArray(GLuint index)
4274{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004275 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004276}
4277
4278void Context::enable(GLenum cap)
4279{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004280 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004281}
4282
4283void Context::enableVertexAttribArray(GLuint index)
4284{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004285 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004286}
4287
4288void Context::frontFace(GLenum mode)
4289{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004290 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004291}
4292
4293void Context::hint(GLenum target, GLenum mode)
4294{
4295 switch (target)
4296 {
4297 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004298 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004299 break;
4300
4301 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004303 break;
4304
4305 default:
4306 UNREACHABLE();
4307 return;
4308 }
4309}
4310
4311void Context::lineWidth(GLfloat width)
4312{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004314}
4315
4316void Context::pixelStorei(GLenum pname, GLint param)
4317{
4318 switch (pname)
4319 {
4320 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004321 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004322 break;
4323
4324 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004326 break;
4327
4328 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004330 break;
4331
4332 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004333 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004335 break;
4336
4337 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004338 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340 break;
4341
4342 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004343 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345 break;
4346
4347 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004348 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004349 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004350 break;
4351
4352 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004353 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004354 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004355 break;
4356
4357 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004358 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004359 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004360 break;
4361
4362 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004363 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004364 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004365 break;
4366
4367 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004368 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004369 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004370 break;
4371
4372 default:
4373 UNREACHABLE();
4374 return;
4375 }
4376}
4377
4378void Context::polygonOffset(GLfloat factor, GLfloat units)
4379{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004380 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004381}
4382
Jamie Madill876429b2017-04-20 15:46:24 -04004383void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004384{
Geoff Lang92019432017-11-20 13:09:34 -05004385 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004386}
4387
Jiawei Shaodb342272017-09-27 10:21:45 +08004388void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4389{
4390 mGLState.setSampleMaskParams(maskNumber, mask);
4391}
4392
Jamie Madillc20ab272016-06-09 07:20:46 -07004393void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4394{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004395 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004396}
4397
4398void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4399{
4400 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4401 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403 }
4404
4405 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4406 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408 }
4409}
4410
4411void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4412{
4413 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4414 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004415 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004416 }
4417
4418 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4419 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421 }
4422}
4423
4424void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4425{
4426 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4427 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429 }
4430
4431 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4432 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434 }
4435}
4436
4437void Context::vertexAttrib1f(GLuint index, GLfloat x)
4438{
4439 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
4443void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4444{
4445 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447}
4448
4449void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4450{
4451 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004452 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004453}
4454
4455void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4456{
4457 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004458 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004459}
4460
4461void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4462{
4463 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004465}
4466
4467void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4468{
4469 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004471}
4472
4473void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4474{
4475 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
4479void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482}
4483
4484void Context::vertexAttribPointer(GLuint index,
4485 GLint size,
4486 GLenum type,
4487 GLboolean normalized,
4488 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004489 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004490{
Corentin Wallez336129f2017-10-17 15:55:40 -04004491 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004492 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
Shao80957d92017-02-20 21:25:59 +08004495void Context::vertexAttribFormat(GLuint attribIndex,
4496 GLint size,
4497 GLenum type,
4498 GLboolean normalized,
4499 GLuint relativeOffset)
4500{
Geoff Lang92019432017-11-20 13:09:34 -05004501 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004502 relativeOffset);
4503}
4504
4505void Context::vertexAttribIFormat(GLuint attribIndex,
4506 GLint size,
4507 GLenum type,
4508 GLuint relativeOffset)
4509{
4510 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4511}
4512
4513void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4514{
Shaodde78e82017-05-22 14:13:27 +08004515 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004516}
4517
Jiajia Qin5451d532017-11-16 17:16:34 +08004518void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004519{
4520 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4521}
4522
Jamie Madillc20ab272016-06-09 07:20:46 -07004523void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004525 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004526}
4527
4528void Context::vertexAttribIPointer(GLuint index,
4529 GLint size,
4530 GLenum type,
4531 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004532 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004533{
Corentin Wallez336129f2017-10-17 15:55:40 -04004534 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4535 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536}
4537
4538void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4539{
4540 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4545{
4546 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
4550void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4551{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004552 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553}
4554
4555void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4556{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004560void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4561{
4562 const VertexAttribCurrentValueData &currentValues =
4563 getGLState().getVertexAttribCurrentValue(index);
4564 const VertexArray *vao = getGLState().getVertexArray();
4565 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4566 currentValues, pname, params);
4567}
4568
Brandon Jones59770802018-04-02 13:18:42 -07004569void Context::getVertexAttribivRobust(GLuint index,
4570 GLenum pname,
4571 GLsizei bufSize,
4572 GLsizei *length,
4573 GLint *params)
4574{
4575 getVertexAttribiv(index, pname, params);
4576}
4577
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004578void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4579{
4580 const VertexAttribCurrentValueData &currentValues =
4581 getGLState().getVertexAttribCurrentValue(index);
4582 const VertexArray *vao = getGLState().getVertexArray();
4583 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4584 currentValues, pname, params);
4585}
4586
Brandon Jones59770802018-04-02 13:18:42 -07004587void Context::getVertexAttribfvRobust(GLuint index,
4588 GLenum pname,
4589 GLsizei bufSize,
4590 GLsizei *length,
4591 GLfloat *params)
4592{
4593 getVertexAttribfv(index, pname, params);
4594}
4595
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004596void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4597{
4598 const VertexAttribCurrentValueData &currentValues =
4599 getGLState().getVertexAttribCurrentValue(index);
4600 const VertexArray *vao = getGLState().getVertexArray();
4601 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4602 currentValues, pname, params);
4603}
4604
Brandon Jones59770802018-04-02 13:18:42 -07004605void Context::getVertexAttribIivRobust(GLuint index,
4606 GLenum pname,
4607 GLsizei bufSize,
4608 GLsizei *length,
4609 GLint *params)
4610{
4611 getVertexAttribIiv(index, pname, params);
4612}
4613
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004614void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4615{
4616 const VertexAttribCurrentValueData &currentValues =
4617 getGLState().getVertexAttribCurrentValue(index);
4618 const VertexArray *vao = getGLState().getVertexArray();
4619 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4620 currentValues, pname, params);
4621}
4622
Brandon Jones59770802018-04-02 13:18:42 -07004623void Context::getVertexAttribIuivRobust(GLuint index,
4624 GLenum pname,
4625 GLsizei bufSize,
4626 GLsizei *length,
4627 GLuint *params)
4628{
4629 getVertexAttribIuiv(index, pname, params);
4630}
4631
Jamie Madill876429b2017-04-20 15:46:24 -04004632void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004633{
4634 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4635 QueryVertexAttribPointerv(attrib, pname, pointer);
4636}
4637
Brandon Jones59770802018-04-02 13:18:42 -07004638void Context::getVertexAttribPointervRobust(GLuint index,
4639 GLenum pname,
4640 GLsizei bufSize,
4641 GLsizei *length,
4642 void **pointer)
4643{
4644 getVertexAttribPointerv(index, pname, pointer);
4645}
4646
Jamie Madillc20ab272016-06-09 07:20:46 -07004647void Context::debugMessageControl(GLenum source,
4648 GLenum type,
4649 GLenum severity,
4650 GLsizei count,
4651 const GLuint *ids,
4652 GLboolean enabled)
4653{
4654 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004656 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::debugMessageInsert(GLenum source,
4660 GLenum type,
4661 GLuint id,
4662 GLenum severity,
4663 GLsizei length,
4664 const GLchar *buf)
4665{
4666 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
4675GLuint Context::getDebugMessageLog(GLuint count,
4676 GLsizei bufSize,
4677 GLenum *sources,
4678 GLenum *types,
4679 GLuint *ids,
4680 GLenum *severities,
4681 GLsizei *lengths,
4682 GLchar *messageLog)
4683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4685 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004686}
4687
4688void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4689{
4690 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004691 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004692 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004693}
4694
4695void Context::popDebugGroup()
4696{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004698 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
Corentin Wallez336129f2017-10-17 15:55:40 -04004701void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004702{
4703 Buffer *buffer = mGLState.getTargetBuffer(target);
4704 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004705 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004706}
4707
Corentin Wallez336129f2017-10-17 15:55:40 -04004708void Context::bufferSubData(BufferBinding target,
4709 GLintptr offset,
4710 GLsizeiptr size,
4711 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004712{
4713 if (data == nullptr)
4714 {
4715 return;
4716 }
4717
4718 Buffer *buffer = mGLState.getTargetBuffer(target);
4719 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004720 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004721}
4722
Jamie Madillef300b12016-10-07 15:12:09 -04004723void Context::attachShader(GLuint program, GLuint shader)
4724{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004725 Program *programObject = mState.mShaderPrograms->getProgram(program);
4726 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004727 ASSERT(programObject && shaderObject);
4728 programObject->attachShader(shaderObject);
4729}
4730
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004731const Workarounds &Context::getWorkarounds() const
4732{
4733 return mWorkarounds;
4734}
4735
Corentin Wallez336129f2017-10-17 15:55:40 -04004736void Context::copyBufferSubData(BufferBinding readTarget,
4737 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004738 GLintptr readOffset,
4739 GLintptr writeOffset,
4740 GLsizeiptr size)
4741{
4742 // if size is zero, the copy is a successful no-op
4743 if (size == 0)
4744 {
4745 return;
4746 }
4747
4748 // TODO(jmadill): cache these.
4749 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4750 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4751
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004752 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004753}
4754
Jamie Madill01a80ee2016-11-07 12:06:18 -05004755void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4756{
4757 Program *programObject = getProgram(program);
4758 // TODO(jmadill): Re-use this from the validation if possible.
4759 ASSERT(programObject);
4760 programObject->bindAttributeLocation(index, name);
4761}
4762
Corentin Wallez336129f2017-10-17 15:55:40 -04004763void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004764{
Corentin Wallez336129f2017-10-17 15:55:40 -04004765 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4766 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004767}
4768
Corentin Wallez336129f2017-10-17 15:55:40 -04004769void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004770{
4771 bindBufferRange(target, index, buffer, 0, 0);
4772}
4773
Corentin Wallez336129f2017-10-17 15:55:40 -04004774void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004775 GLuint index,
4776 GLuint buffer,
4777 GLintptr offset,
4778 GLsizeiptr size)
4779{
Corentin Wallez336129f2017-10-17 15:55:40 -04004780 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4781 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004782}
4783
Jamie Madill01a80ee2016-11-07 12:06:18 -05004784void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4785{
4786 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4787 {
4788 bindReadFramebuffer(framebuffer);
4789 }
4790
4791 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4792 {
4793 bindDrawFramebuffer(framebuffer);
4794 }
4795}
4796
4797void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4798{
4799 ASSERT(target == GL_RENDERBUFFER);
4800 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004801 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004802 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004803}
4804
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004805void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004806 GLsizei samples,
4807 GLenum internalformat,
4808 GLsizei width,
4809 GLsizei height,
4810 GLboolean fixedsamplelocations)
4811{
4812 Extents size(width, height, 1);
4813 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004814 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4815 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004816}
4817
4818void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4819{
JiangYizhou5b03f472017-01-09 10:22:53 +08004820 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4821 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004822 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004823 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004824
4825 switch (pname)
4826 {
4827 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004828 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004829 break;
4830 default:
4831 UNREACHABLE();
4832 }
4833}
4834
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004835void Context::getMultisamplefvRobust(GLenum pname,
4836 GLuint index,
4837 GLsizei bufSize,
4838 GLsizei *length,
4839 GLfloat *val)
4840{
4841 UNIMPLEMENTED();
4842}
4843
Jamie Madille8fb6402017-02-14 17:56:40 -05004844void Context::renderbufferStorage(GLenum target,
4845 GLenum internalformat,
4846 GLsizei width,
4847 GLsizei height)
4848{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004849 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4850 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4851
Jamie Madille8fb6402017-02-14 17:56:40 -05004852 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004853 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004854}
4855
4856void Context::renderbufferStorageMultisample(GLenum target,
4857 GLsizei samples,
4858 GLenum internalformat,
4859 GLsizei width,
4860 GLsizei height)
4861{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004862 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4863 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004864
4865 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004866 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004867 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004868}
4869
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004870void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4871{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004872 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004873 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004874}
4875
JiangYizhoue18e6392017-02-20 10:32:23 +08004876void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4877{
4878 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4879 QueryFramebufferParameteriv(framebuffer, pname, params);
4880}
4881
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004882void Context::getFramebufferParameterivRobust(GLenum target,
4883 GLenum pname,
4884 GLsizei bufSize,
4885 GLsizei *length,
4886 GLint *params)
4887{
4888 UNIMPLEMENTED();
4889}
4890
Jiajia Qin5451d532017-11-16 17:16:34 +08004891void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004892{
4893 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4894 SetFramebufferParameteri(framebuffer, pname, param);
4895}
4896
Jamie Madillb3f26b92017-07-19 15:07:41 -04004897Error Context::getScratchBuffer(size_t requstedSizeBytes,
4898 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004899{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004900 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4901 {
4902 return OutOfMemory() << "Failed to allocate internal buffer.";
4903 }
4904 return NoError();
4905}
4906
4907Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4908 angle::MemoryBuffer **zeroBufferOut) const
4909{
4910 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004911 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004912 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004913 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004914 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004915}
4916
Xinghua Cao10a4d432017-11-28 14:46:26 +08004917Error Context::prepareForDispatch()
4918{
Geoff Langa8cb2872018-03-09 16:09:40 -05004919 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004920
4921 if (isRobustResourceInitEnabled())
4922 {
4923 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4924 }
4925
4926 return NoError();
4927}
4928
Xinghua Cao2b396592017-03-29 15:36:04 +08004929void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4930{
4931 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4932 {
4933 return;
4934 }
4935
Xinghua Cao10a4d432017-11-28 14:46:26 +08004936 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004937 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004938}
4939
Jiajia Qin5451d532017-11-16 17:16:34 +08004940void Context::dispatchComputeIndirect(GLintptr indirect)
4941{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004942 ANGLE_CONTEXT_TRY(prepareForDispatch());
4943 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004944}
4945
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004946void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004947 GLsizei levels,
4948 GLenum internalFormat,
4949 GLsizei width,
4950 GLsizei height)
4951{
4952 Extents size(width, height, 1);
4953 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004954 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004955}
4956
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004957void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004958 GLsizei levels,
4959 GLenum internalFormat,
4960 GLsizei width,
4961 GLsizei height,
4962 GLsizei depth)
4963{
4964 Extents size(width, height, depth);
4965 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004966 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004967}
4968
Jiajia Qin5451d532017-11-16 17:16:34 +08004969void Context::memoryBarrier(GLbitfield barriers)
4970{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004971 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004972}
4973
4974void Context::memoryBarrierByRegion(GLbitfield barriers)
4975{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004976 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004977}
4978
Jamie Madillc1d770e2017-04-13 17:31:24 -04004979GLenum Context::checkFramebufferStatus(GLenum target)
4980{
4981 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4982 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004983 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004984}
4985
4986void Context::compileShader(GLuint shader)
4987{
4988 Shader *shaderObject = GetValidShader(this, shader);
4989 if (!shaderObject)
4990 {
4991 return;
4992 }
4993 shaderObject->compile(this);
4994}
4995
4996void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4997{
4998 for (int i = 0; i < n; i++)
4999 {
5000 deleteBuffer(buffers[i]);
5001 }
5002}
5003
5004void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5005{
5006 for (int i = 0; i < n; i++)
5007 {
5008 if (framebuffers[i] != 0)
5009 {
5010 deleteFramebuffer(framebuffers[i]);
5011 }
5012 }
5013}
5014
5015void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5016{
5017 for (int i = 0; i < n; i++)
5018 {
5019 deleteRenderbuffer(renderbuffers[i]);
5020 }
5021}
5022
5023void Context::deleteTextures(GLsizei n, const GLuint *textures)
5024{
5025 for (int i = 0; i < n; i++)
5026 {
5027 if (textures[i] != 0)
5028 {
5029 deleteTexture(textures[i]);
5030 }
5031 }
5032}
5033
5034void Context::detachShader(GLuint program, GLuint shader)
5035{
5036 Program *programObject = getProgram(program);
5037 ASSERT(programObject);
5038
5039 Shader *shaderObject = getShader(shader);
5040 ASSERT(shaderObject);
5041
5042 programObject->detachShader(this, shaderObject);
5043}
5044
5045void Context::genBuffers(GLsizei n, GLuint *buffers)
5046{
5047 for (int i = 0; i < n; i++)
5048 {
5049 buffers[i] = createBuffer();
5050 }
5051}
5052
5053void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5054{
5055 for (int i = 0; i < n; i++)
5056 {
5057 framebuffers[i] = createFramebuffer();
5058 }
5059}
5060
5061void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5062{
5063 for (int i = 0; i < n; i++)
5064 {
5065 renderbuffers[i] = createRenderbuffer();
5066 }
5067}
5068
5069void Context::genTextures(GLsizei n, GLuint *textures)
5070{
5071 for (int i = 0; i < n; i++)
5072 {
5073 textures[i] = createTexture();
5074 }
5075}
5076
5077void Context::getActiveAttrib(GLuint program,
5078 GLuint index,
5079 GLsizei bufsize,
5080 GLsizei *length,
5081 GLint *size,
5082 GLenum *type,
5083 GLchar *name)
5084{
5085 Program *programObject = getProgram(program);
5086 ASSERT(programObject);
5087 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5088}
5089
5090void Context::getActiveUniform(GLuint program,
5091 GLuint index,
5092 GLsizei bufsize,
5093 GLsizei *length,
5094 GLint *size,
5095 GLenum *type,
5096 GLchar *name)
5097{
5098 Program *programObject = getProgram(program);
5099 ASSERT(programObject);
5100 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5101}
5102
5103void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5104{
5105 Program *programObject = getProgram(program);
5106 ASSERT(programObject);
5107 programObject->getAttachedShaders(maxcount, count, shaders);
5108}
5109
5110GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5111{
5112 Program *programObject = getProgram(program);
5113 ASSERT(programObject);
5114 return programObject->getAttributeLocation(name);
5115}
5116
5117void Context::getBooleanv(GLenum pname, GLboolean *params)
5118{
5119 GLenum nativeType;
5120 unsigned int numParams = 0;
5121 getQueryParameterInfo(pname, &nativeType, &numParams);
5122
5123 if (nativeType == GL_BOOL)
5124 {
5125 getBooleanvImpl(pname, params);
5126 }
5127 else
5128 {
5129 CastStateValues(this, nativeType, pname, numParams, params);
5130 }
5131}
5132
Brandon Jones59770802018-04-02 13:18:42 -07005133void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5134{
5135 getBooleanv(pname, params);
5136}
5137
Jamie Madillc1d770e2017-04-13 17:31:24 -04005138void Context::getFloatv(GLenum pname, GLfloat *params)
5139{
5140 GLenum nativeType;
5141 unsigned int numParams = 0;
5142 getQueryParameterInfo(pname, &nativeType, &numParams);
5143
5144 if (nativeType == GL_FLOAT)
5145 {
5146 getFloatvImpl(pname, params);
5147 }
5148 else
5149 {
5150 CastStateValues(this, nativeType, pname, numParams, params);
5151 }
5152}
5153
Brandon Jones59770802018-04-02 13:18:42 -07005154void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5155{
5156 getFloatv(pname, params);
5157}
5158
Jamie Madillc1d770e2017-04-13 17:31:24 -04005159void Context::getIntegerv(GLenum pname, GLint *params)
5160{
5161 GLenum nativeType;
5162 unsigned int numParams = 0;
5163 getQueryParameterInfo(pname, &nativeType, &numParams);
5164
5165 if (nativeType == GL_INT)
5166 {
5167 getIntegervImpl(pname, params);
5168 }
5169 else
5170 {
5171 CastStateValues(this, nativeType, pname, numParams, params);
5172 }
5173}
5174
Brandon Jones59770802018-04-02 13:18:42 -07005175void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5176{
5177 getIntegerv(pname, data);
5178}
5179
Jamie Madillc1d770e2017-04-13 17:31:24 -04005180void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5181{
5182 Program *programObject = getProgram(program);
5183 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005184 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005185}
5186
Brandon Jones59770802018-04-02 13:18:42 -07005187void Context::getProgramivRobust(GLuint program,
5188 GLenum pname,
5189 GLsizei bufSize,
5190 GLsizei *length,
5191 GLint *params)
5192{
5193 getProgramiv(program, pname, params);
5194}
5195
Jiajia Qin5451d532017-11-16 17:16:34 +08005196void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5197{
5198 UNIMPLEMENTED();
5199}
5200
Jamie Madillbe849e42017-05-02 15:49:00 -04005201void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005202{
5203 Program *programObject = getProgram(program);
5204 ASSERT(programObject);
5205 programObject->getInfoLog(bufsize, length, infolog);
5206}
5207
Jiajia Qin5451d532017-11-16 17:16:34 +08005208void Context::getProgramPipelineInfoLog(GLuint pipeline,
5209 GLsizei bufSize,
5210 GLsizei *length,
5211 GLchar *infoLog)
5212{
5213 UNIMPLEMENTED();
5214}
5215
Jamie Madillc1d770e2017-04-13 17:31:24 -04005216void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5217{
5218 Shader *shaderObject = getShader(shader);
5219 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005220 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221}
5222
Brandon Jones59770802018-04-02 13:18:42 -07005223void Context::getShaderivRobust(GLuint shader,
5224 GLenum pname,
5225 GLsizei bufSize,
5226 GLsizei *length,
5227 GLint *params)
5228{
5229 getShaderiv(shader, pname, params);
5230}
5231
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5233{
5234 Shader *shaderObject = getShader(shader);
5235 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005236 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005237}
5238
5239void Context::getShaderPrecisionFormat(GLenum shadertype,
5240 GLenum precisiontype,
5241 GLint *range,
5242 GLint *precision)
5243{
5244 // TODO(jmadill): Compute shaders.
5245
5246 switch (shadertype)
5247 {
5248 case GL_VERTEX_SHADER:
5249 switch (precisiontype)
5250 {
5251 case GL_LOW_FLOAT:
5252 mCaps.vertexLowpFloat.get(range, precision);
5253 break;
5254 case GL_MEDIUM_FLOAT:
5255 mCaps.vertexMediumpFloat.get(range, precision);
5256 break;
5257 case GL_HIGH_FLOAT:
5258 mCaps.vertexHighpFloat.get(range, precision);
5259 break;
5260
5261 case GL_LOW_INT:
5262 mCaps.vertexLowpInt.get(range, precision);
5263 break;
5264 case GL_MEDIUM_INT:
5265 mCaps.vertexMediumpInt.get(range, precision);
5266 break;
5267 case GL_HIGH_INT:
5268 mCaps.vertexHighpInt.get(range, precision);
5269 break;
5270
5271 default:
5272 UNREACHABLE();
5273 return;
5274 }
5275 break;
5276
5277 case GL_FRAGMENT_SHADER:
5278 switch (precisiontype)
5279 {
5280 case GL_LOW_FLOAT:
5281 mCaps.fragmentLowpFloat.get(range, precision);
5282 break;
5283 case GL_MEDIUM_FLOAT:
5284 mCaps.fragmentMediumpFloat.get(range, precision);
5285 break;
5286 case GL_HIGH_FLOAT:
5287 mCaps.fragmentHighpFloat.get(range, precision);
5288 break;
5289
5290 case GL_LOW_INT:
5291 mCaps.fragmentLowpInt.get(range, precision);
5292 break;
5293 case GL_MEDIUM_INT:
5294 mCaps.fragmentMediumpInt.get(range, precision);
5295 break;
5296 case GL_HIGH_INT:
5297 mCaps.fragmentHighpInt.get(range, precision);
5298 break;
5299
5300 default:
5301 UNREACHABLE();
5302 return;
5303 }
5304 break;
5305
5306 default:
5307 UNREACHABLE();
5308 return;
5309 }
5310}
5311
5312void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5313{
5314 Shader *shaderObject = getShader(shader);
5315 ASSERT(shaderObject);
5316 shaderObject->getSource(bufsize, length, source);
5317}
5318
5319void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5320{
5321 Program *programObject = getProgram(program);
5322 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005323 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324}
5325
Brandon Jones59770802018-04-02 13:18:42 -07005326void Context::getUniformfvRobust(GLuint program,
5327 GLint location,
5328 GLsizei bufSize,
5329 GLsizei *length,
5330 GLfloat *params)
5331{
5332 getUniformfv(program, location, params);
5333}
5334
Jamie Madillc1d770e2017-04-13 17:31:24 -04005335void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5336{
5337 Program *programObject = getProgram(program);
5338 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005339 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340}
5341
Brandon Jones59770802018-04-02 13:18:42 -07005342void Context::getUniformivRobust(GLuint program,
5343 GLint location,
5344 GLsizei bufSize,
5345 GLsizei *length,
5346 GLint *params)
5347{
5348 getUniformiv(program, location, params);
5349}
5350
Jamie Madillc1d770e2017-04-13 17:31:24 -04005351GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5352{
5353 Program *programObject = getProgram(program);
5354 ASSERT(programObject);
5355 return programObject->getUniformLocation(name);
5356}
5357
5358GLboolean Context::isBuffer(GLuint buffer)
5359{
5360 if (buffer == 0)
5361 {
5362 return GL_FALSE;
5363 }
5364
5365 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5366}
5367
5368GLboolean Context::isEnabled(GLenum cap)
5369{
5370 return mGLState.getEnableFeature(cap);
5371}
5372
5373GLboolean Context::isFramebuffer(GLuint framebuffer)
5374{
5375 if (framebuffer == 0)
5376 {
5377 return GL_FALSE;
5378 }
5379
5380 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5381}
5382
5383GLboolean Context::isProgram(GLuint program)
5384{
5385 if (program == 0)
5386 {
5387 return GL_FALSE;
5388 }
5389
5390 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5391}
5392
5393GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5394{
5395 if (renderbuffer == 0)
5396 {
5397 return GL_FALSE;
5398 }
5399
5400 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5401}
5402
5403GLboolean Context::isShader(GLuint shader)
5404{
5405 if (shader == 0)
5406 {
5407 return GL_FALSE;
5408 }
5409
5410 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5411}
5412
5413GLboolean Context::isTexture(GLuint texture)
5414{
5415 if (texture == 0)
5416 {
5417 return GL_FALSE;
5418 }
5419
5420 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5421}
5422
5423void Context::linkProgram(GLuint program)
5424{
5425 Program *programObject = getProgram(program);
5426 ASSERT(programObject);
5427 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005428 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005429}
5430
5431void Context::releaseShaderCompiler()
5432{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005433 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005434}
5435
5436void Context::shaderBinary(GLsizei n,
5437 const GLuint *shaders,
5438 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005439 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005440 GLsizei length)
5441{
5442 // No binary shader formats are supported.
5443 UNIMPLEMENTED();
5444}
5445
5446void Context::shaderSource(GLuint shader,
5447 GLsizei count,
5448 const GLchar *const *string,
5449 const GLint *length)
5450{
5451 Shader *shaderObject = getShader(shader);
5452 ASSERT(shaderObject);
5453 shaderObject->setSource(count, string, length);
5454}
5455
5456void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5457{
5458 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5459}
5460
5461void Context::stencilMask(GLuint mask)
5462{
5463 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5464}
5465
5466void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5467{
5468 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5469}
5470
5471void Context::uniform1f(GLint location, GLfloat x)
5472{
5473 Program *program = mGLState.getProgram();
5474 program->setUniform1fv(location, 1, &x);
5475}
5476
5477void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5478{
5479 Program *program = mGLState.getProgram();
5480 program->setUniform1fv(location, count, v);
5481}
5482
5483void Context::uniform1i(GLint location, GLint x)
5484{
5485 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005486 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5487 {
5488 mGLState.setObjectDirty(GL_PROGRAM);
5489 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005490}
5491
5492void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5493{
5494 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005495 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5496 {
5497 mGLState.setObjectDirty(GL_PROGRAM);
5498 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005499}
5500
5501void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5502{
5503 GLfloat xy[2] = {x, y};
5504 Program *program = mGLState.getProgram();
5505 program->setUniform2fv(location, 1, xy);
5506}
5507
5508void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5509{
5510 Program *program = mGLState.getProgram();
5511 program->setUniform2fv(location, count, v);
5512}
5513
5514void Context::uniform2i(GLint location, GLint x, GLint y)
5515{
5516 GLint xy[2] = {x, y};
5517 Program *program = mGLState.getProgram();
5518 program->setUniform2iv(location, 1, xy);
5519}
5520
5521void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5522{
5523 Program *program = mGLState.getProgram();
5524 program->setUniform2iv(location, count, v);
5525}
5526
5527void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5528{
5529 GLfloat xyz[3] = {x, y, z};
5530 Program *program = mGLState.getProgram();
5531 program->setUniform3fv(location, 1, xyz);
5532}
5533
5534void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5535{
5536 Program *program = mGLState.getProgram();
5537 program->setUniform3fv(location, count, v);
5538}
5539
5540void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5541{
5542 GLint xyz[3] = {x, y, z};
5543 Program *program = mGLState.getProgram();
5544 program->setUniform3iv(location, 1, xyz);
5545}
5546
5547void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5548{
5549 Program *program = mGLState.getProgram();
5550 program->setUniform3iv(location, count, v);
5551}
5552
5553void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5554{
5555 GLfloat xyzw[4] = {x, y, z, w};
5556 Program *program = mGLState.getProgram();
5557 program->setUniform4fv(location, 1, xyzw);
5558}
5559
5560void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5561{
5562 Program *program = mGLState.getProgram();
5563 program->setUniform4fv(location, count, v);
5564}
5565
5566void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5567{
5568 GLint xyzw[4] = {x, y, z, w};
5569 Program *program = mGLState.getProgram();
5570 program->setUniform4iv(location, 1, xyzw);
5571}
5572
5573void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5574{
5575 Program *program = mGLState.getProgram();
5576 program->setUniform4iv(location, count, v);
5577}
5578
5579void Context::uniformMatrix2fv(GLint location,
5580 GLsizei count,
5581 GLboolean transpose,
5582 const GLfloat *value)
5583{
5584 Program *program = mGLState.getProgram();
5585 program->setUniformMatrix2fv(location, count, transpose, value);
5586}
5587
5588void Context::uniformMatrix3fv(GLint location,
5589 GLsizei count,
5590 GLboolean transpose,
5591 const GLfloat *value)
5592{
5593 Program *program = mGLState.getProgram();
5594 program->setUniformMatrix3fv(location, count, transpose, value);
5595}
5596
5597void Context::uniformMatrix4fv(GLint location,
5598 GLsizei count,
5599 GLboolean transpose,
5600 const GLfloat *value)
5601{
5602 Program *program = mGLState.getProgram();
5603 program->setUniformMatrix4fv(location, count, transpose, value);
5604}
5605
5606void Context::validateProgram(GLuint program)
5607{
5608 Program *programObject = getProgram(program);
5609 ASSERT(programObject);
5610 programObject->validate(mCaps);
5611}
5612
Jiajia Qin5451d532017-11-16 17:16:34 +08005613void Context::validateProgramPipeline(GLuint pipeline)
5614{
5615 UNIMPLEMENTED();
5616}
5617
Jamie Madilld04908b2017-06-09 14:15:35 -04005618void Context::getProgramBinary(GLuint program,
5619 GLsizei bufSize,
5620 GLsizei *length,
5621 GLenum *binaryFormat,
5622 void *binary)
5623{
5624 Program *programObject = getProgram(program);
5625 ASSERT(programObject != nullptr);
5626
5627 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5628}
5629
5630void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5631{
5632 Program *programObject = getProgram(program);
5633 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005634
Jamie Madilld04908b2017-06-09 14:15:35 -04005635 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5636}
5637
Jamie Madillff325f12017-08-26 15:06:05 -04005638void Context::uniform1ui(GLint location, GLuint v0)
5639{
5640 Program *program = mGLState.getProgram();
5641 program->setUniform1uiv(location, 1, &v0);
5642}
5643
5644void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5645{
5646 Program *program = mGLState.getProgram();
5647 const GLuint xy[] = {v0, v1};
5648 program->setUniform2uiv(location, 1, xy);
5649}
5650
5651void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5652{
5653 Program *program = mGLState.getProgram();
5654 const GLuint xyz[] = {v0, v1, v2};
5655 program->setUniform3uiv(location, 1, xyz);
5656}
5657
5658void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5659{
5660 Program *program = mGLState.getProgram();
5661 const GLuint xyzw[] = {v0, v1, v2, v3};
5662 program->setUniform4uiv(location, 1, xyzw);
5663}
5664
5665void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5666{
5667 Program *program = mGLState.getProgram();
5668 program->setUniform1uiv(location, count, value);
5669}
5670void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5671{
5672 Program *program = mGLState.getProgram();
5673 program->setUniform2uiv(location, count, value);
5674}
5675
5676void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5677{
5678 Program *program = mGLState.getProgram();
5679 program->setUniform3uiv(location, count, value);
5680}
5681
5682void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5683{
5684 Program *program = mGLState.getProgram();
5685 program->setUniform4uiv(location, count, value);
5686}
5687
Jamie Madillf0e04492017-08-26 15:28:42 -04005688void Context::genQueries(GLsizei n, GLuint *ids)
5689{
5690 for (GLsizei i = 0; i < n; i++)
5691 {
5692 GLuint handle = mQueryHandleAllocator.allocate();
5693 mQueryMap.assign(handle, nullptr);
5694 ids[i] = handle;
5695 }
5696}
5697
5698void Context::deleteQueries(GLsizei n, const GLuint *ids)
5699{
5700 for (int i = 0; i < n; i++)
5701 {
5702 GLuint query = ids[i];
5703
5704 Query *queryObject = nullptr;
5705 if (mQueryMap.erase(query, &queryObject))
5706 {
5707 mQueryHandleAllocator.release(query);
5708 if (queryObject)
5709 {
5710 queryObject->release(this);
5711 }
5712 }
5713 }
5714}
5715
5716GLboolean Context::isQuery(GLuint id)
5717{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005718 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005719}
5720
Jamie Madillc8c95812017-08-26 18:40:09 -04005721void Context::uniformMatrix2x3fv(GLint location,
5722 GLsizei count,
5723 GLboolean transpose,
5724 const GLfloat *value)
5725{
5726 Program *program = mGLState.getProgram();
5727 program->setUniformMatrix2x3fv(location, count, transpose, value);
5728}
5729
5730void Context::uniformMatrix3x2fv(GLint location,
5731 GLsizei count,
5732 GLboolean transpose,
5733 const GLfloat *value)
5734{
5735 Program *program = mGLState.getProgram();
5736 program->setUniformMatrix3x2fv(location, count, transpose, value);
5737}
5738
5739void Context::uniformMatrix2x4fv(GLint location,
5740 GLsizei count,
5741 GLboolean transpose,
5742 const GLfloat *value)
5743{
5744 Program *program = mGLState.getProgram();
5745 program->setUniformMatrix2x4fv(location, count, transpose, value);
5746}
5747
5748void Context::uniformMatrix4x2fv(GLint location,
5749 GLsizei count,
5750 GLboolean transpose,
5751 const GLfloat *value)
5752{
5753 Program *program = mGLState.getProgram();
5754 program->setUniformMatrix4x2fv(location, count, transpose, value);
5755}
5756
5757void Context::uniformMatrix3x4fv(GLint location,
5758 GLsizei count,
5759 GLboolean transpose,
5760 const GLfloat *value)
5761{
5762 Program *program = mGLState.getProgram();
5763 program->setUniformMatrix3x4fv(location, count, transpose, value);
5764}
5765
5766void Context::uniformMatrix4x3fv(GLint location,
5767 GLsizei count,
5768 GLboolean transpose,
5769 const GLfloat *value)
5770{
5771 Program *program = mGLState.getProgram();
5772 program->setUniformMatrix4x3fv(location, count, transpose, value);
5773}
5774
Jamie Madilld7576732017-08-26 18:49:50 -04005775void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5776{
5777 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5778 {
5779 GLuint vertexArray = arrays[arrayIndex];
5780
5781 if (arrays[arrayIndex] != 0)
5782 {
5783 VertexArray *vertexArrayObject = nullptr;
5784 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5785 {
5786 if (vertexArrayObject != nullptr)
5787 {
5788 detachVertexArray(vertexArray);
5789 vertexArrayObject->onDestroy(this);
5790 }
5791
5792 mVertexArrayHandleAllocator.release(vertexArray);
5793 }
5794 }
5795 }
5796}
5797
5798void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5799{
5800 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5801 {
5802 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5803 mVertexArrayMap.assign(vertexArray, nullptr);
5804 arrays[arrayIndex] = vertexArray;
5805 }
5806}
5807
5808bool Context::isVertexArray(GLuint array)
5809{
5810 if (array == 0)
5811 {
5812 return GL_FALSE;
5813 }
5814
5815 VertexArray *vao = getVertexArray(array);
5816 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5817}
5818
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005819void Context::endTransformFeedback()
5820{
5821 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5822 transformFeedback->end(this);
5823}
5824
5825void Context::transformFeedbackVaryings(GLuint program,
5826 GLsizei count,
5827 const GLchar *const *varyings,
5828 GLenum bufferMode)
5829{
5830 Program *programObject = getProgram(program);
5831 ASSERT(programObject);
5832 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5833}
5834
5835void Context::getTransformFeedbackVarying(GLuint program,
5836 GLuint index,
5837 GLsizei bufSize,
5838 GLsizei *length,
5839 GLsizei *size,
5840 GLenum *type,
5841 GLchar *name)
5842{
5843 Program *programObject = getProgram(program);
5844 ASSERT(programObject);
5845 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5846}
5847
5848void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5849{
5850 for (int i = 0; i < n; i++)
5851 {
5852 GLuint transformFeedback = ids[i];
5853 if (transformFeedback == 0)
5854 {
5855 continue;
5856 }
5857
5858 TransformFeedback *transformFeedbackObject = nullptr;
5859 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5860 {
5861 if (transformFeedbackObject != nullptr)
5862 {
5863 detachTransformFeedback(transformFeedback);
5864 transformFeedbackObject->release(this);
5865 }
5866
5867 mTransformFeedbackHandleAllocator.release(transformFeedback);
5868 }
5869 }
5870}
5871
5872void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5873{
5874 for (int i = 0; i < n; i++)
5875 {
5876 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5877 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5878 ids[i] = transformFeedback;
5879 }
5880}
5881
5882bool Context::isTransformFeedback(GLuint id)
5883{
5884 if (id == 0)
5885 {
5886 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5887 // returns FALSE
5888 return GL_FALSE;
5889 }
5890
5891 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5892 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5893}
5894
5895void Context::pauseTransformFeedback()
5896{
5897 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5898 transformFeedback->pause();
5899}
5900
5901void Context::resumeTransformFeedback()
5902{
5903 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5904 transformFeedback->resume();
5905}
5906
Jamie Madill12e957f2017-08-26 21:42:26 -04005907void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5908{
5909 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005910 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005911}
5912
Brandon Jones59770802018-04-02 13:18:42 -07005913void Context::getUniformuivRobust(GLuint program,
5914 GLint location,
5915 GLsizei bufSize,
5916 GLsizei *length,
5917 GLuint *params)
5918{
5919 getUniformuiv(program, location, params);
5920}
5921
Jamie Madill12e957f2017-08-26 21:42:26 -04005922GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5923{
5924 const Program *programObject = getProgram(program);
5925 return programObject->getFragDataLocation(name);
5926}
5927
5928void Context::getUniformIndices(GLuint program,
5929 GLsizei uniformCount,
5930 const GLchar *const *uniformNames,
5931 GLuint *uniformIndices)
5932{
5933 const Program *programObject = getProgram(program);
5934 if (!programObject->isLinked())
5935 {
5936 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5937 {
5938 uniformIndices[uniformId] = GL_INVALID_INDEX;
5939 }
5940 }
5941 else
5942 {
5943 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5944 {
5945 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5946 }
5947 }
5948}
5949
5950void Context::getActiveUniformsiv(GLuint program,
5951 GLsizei uniformCount,
5952 const GLuint *uniformIndices,
5953 GLenum pname,
5954 GLint *params)
5955{
5956 const Program *programObject = getProgram(program);
5957 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5958 {
5959 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005960 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005961 }
5962}
5963
5964GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5965{
5966 const Program *programObject = getProgram(program);
5967 return programObject->getUniformBlockIndex(uniformBlockName);
5968}
5969
5970void Context::getActiveUniformBlockiv(GLuint program,
5971 GLuint uniformBlockIndex,
5972 GLenum pname,
5973 GLint *params)
5974{
5975 const Program *programObject = getProgram(program);
5976 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5977}
5978
Brandon Jones59770802018-04-02 13:18:42 -07005979void Context::getActiveUniformBlockivRobust(GLuint program,
5980 GLuint uniformBlockIndex,
5981 GLenum pname,
5982 GLsizei bufSize,
5983 GLsizei *length,
5984 GLint *params)
5985{
5986 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5987}
5988
Jamie Madill12e957f2017-08-26 21:42:26 -04005989void Context::getActiveUniformBlockName(GLuint program,
5990 GLuint uniformBlockIndex,
5991 GLsizei bufSize,
5992 GLsizei *length,
5993 GLchar *uniformBlockName)
5994{
5995 const Program *programObject = getProgram(program);
5996 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5997}
5998
5999void Context::uniformBlockBinding(GLuint program,
6000 GLuint uniformBlockIndex,
6001 GLuint uniformBlockBinding)
6002{
6003 Program *programObject = getProgram(program);
6004 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6005}
6006
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006007GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6008{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006009 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6010 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006011
Jamie Madill70b5bb02017-08-28 13:32:37 -04006012 Sync *syncObject = getSync(syncHandle);
6013 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006014 if (error.isError())
6015 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006016 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006017 handleError(error);
6018 return nullptr;
6019 }
6020
Jamie Madill70b5bb02017-08-28 13:32:37 -04006021 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006022}
6023
6024GLboolean Context::isSync(GLsync sync)
6025{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006026 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006027}
6028
6029GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6030{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006031 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006032
6033 GLenum result = GL_WAIT_FAILED;
6034 handleError(syncObject->clientWait(flags, timeout, &result));
6035 return result;
6036}
6037
6038void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6039{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006040 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006041 handleError(syncObject->serverWait(flags, timeout));
6042}
6043
6044void Context::getInteger64v(GLenum pname, GLint64 *params)
6045{
6046 GLenum nativeType = GL_NONE;
6047 unsigned int numParams = 0;
6048 getQueryParameterInfo(pname, &nativeType, &numParams);
6049
6050 if (nativeType == GL_INT_64_ANGLEX)
6051 {
6052 getInteger64vImpl(pname, params);
6053 }
6054 else
6055 {
6056 CastStateValues(this, nativeType, pname, numParams, params);
6057 }
6058}
6059
Brandon Jones59770802018-04-02 13:18:42 -07006060void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6061{
6062 getInteger64v(pname, data);
6063}
6064
Corentin Wallez336129f2017-10-17 15:55:40 -04006065void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006066{
6067 Buffer *buffer = mGLState.getTargetBuffer(target);
6068 QueryBufferParameteri64v(buffer, pname, params);
6069}
6070
Brandon Jones59770802018-04-02 13:18:42 -07006071void Context::getBufferParameteri64vRobust(BufferBinding target,
6072 GLenum pname,
6073 GLsizei bufSize,
6074 GLsizei *length,
6075 GLint64 *params)
6076{
6077 getBufferParameteri64v(target, pname, params);
6078}
6079
Jamie Madill3ef140a2017-08-26 23:11:21 -04006080void Context::genSamplers(GLsizei count, GLuint *samplers)
6081{
6082 for (int i = 0; i < count; i++)
6083 {
6084 samplers[i] = mState.mSamplers->createSampler();
6085 }
6086}
6087
6088void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6089{
6090 for (int i = 0; i < count; i++)
6091 {
6092 GLuint sampler = samplers[i];
6093
6094 if (mState.mSamplers->getSampler(sampler))
6095 {
6096 detachSampler(sampler);
6097 }
6098
6099 mState.mSamplers->deleteObject(this, sampler);
6100 }
6101}
6102
6103void Context::getInternalformativ(GLenum target,
6104 GLenum internalformat,
6105 GLenum pname,
6106 GLsizei bufSize,
6107 GLint *params)
6108{
6109 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6110 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6111}
6112
Brandon Jones59770802018-04-02 13:18:42 -07006113void Context::getInternalformativRobust(GLenum target,
6114 GLenum internalformat,
6115 GLenum pname,
6116 GLsizei bufSize,
6117 GLsizei *length,
6118 GLint *params)
6119{
6120 getInternalformativ(target, internalformat, pname, bufSize, params);
6121}
6122
Jiajia Qin5451d532017-11-16 17:16:34 +08006123void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6124{
6125 programUniform1iv(program, location, 1, &v0);
6126}
6127
6128void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6129{
6130 GLint xy[2] = {v0, v1};
6131 programUniform2iv(program, location, 1, xy);
6132}
6133
6134void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6135{
6136 GLint xyz[3] = {v0, v1, v2};
6137 programUniform3iv(program, location, 1, xyz);
6138}
6139
6140void Context::programUniform4i(GLuint program,
6141 GLint location,
6142 GLint v0,
6143 GLint v1,
6144 GLint v2,
6145 GLint v3)
6146{
6147 GLint xyzw[4] = {v0, v1, v2, v3};
6148 programUniform4iv(program, location, 1, xyzw);
6149}
6150
6151void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6152{
6153 programUniform1uiv(program, location, 1, &v0);
6154}
6155
6156void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6157{
6158 GLuint xy[2] = {v0, v1};
6159 programUniform2uiv(program, location, 1, xy);
6160}
6161
6162void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6163{
6164 GLuint xyz[3] = {v0, v1, v2};
6165 programUniform3uiv(program, location, 1, xyz);
6166}
6167
6168void Context::programUniform4ui(GLuint program,
6169 GLint location,
6170 GLuint v0,
6171 GLuint v1,
6172 GLuint v2,
6173 GLuint v3)
6174{
6175 GLuint xyzw[4] = {v0, v1, v2, v3};
6176 programUniform4uiv(program, location, 1, xyzw);
6177}
6178
6179void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6180{
6181 programUniform1fv(program, location, 1, &v0);
6182}
6183
6184void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6185{
6186 GLfloat xy[2] = {v0, v1};
6187 programUniform2fv(program, location, 1, xy);
6188}
6189
6190void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6191{
6192 GLfloat xyz[3] = {v0, v1, v2};
6193 programUniform3fv(program, location, 1, xyz);
6194}
6195
6196void Context::programUniform4f(GLuint program,
6197 GLint location,
6198 GLfloat v0,
6199 GLfloat v1,
6200 GLfloat v2,
6201 GLfloat v3)
6202{
6203 GLfloat xyzw[4] = {v0, v1, v2, v3};
6204 programUniform4fv(program, location, 1, xyzw);
6205}
6206
Jamie Madill81c2e252017-09-09 23:32:46 -04006207void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6208{
6209 Program *programObject = getProgram(program);
6210 ASSERT(programObject);
6211 if (programObject->setUniform1iv(location, count, value) ==
6212 Program::SetUniformResult::SamplerChanged)
6213 {
6214 mGLState.setObjectDirty(GL_PROGRAM);
6215 }
6216}
6217
Jiajia Qin5451d532017-11-16 17:16:34 +08006218void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6219{
6220 Program *programObject = getProgram(program);
6221 ASSERT(programObject);
6222 programObject->setUniform2iv(location, count, value);
6223}
6224
6225void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6226{
6227 Program *programObject = getProgram(program);
6228 ASSERT(programObject);
6229 programObject->setUniform3iv(location, count, value);
6230}
6231
6232void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6233{
6234 Program *programObject = getProgram(program);
6235 ASSERT(programObject);
6236 programObject->setUniform4iv(location, count, value);
6237}
6238
6239void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6240{
6241 Program *programObject = getProgram(program);
6242 ASSERT(programObject);
6243 programObject->setUniform1uiv(location, count, value);
6244}
6245
6246void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6247{
6248 Program *programObject = getProgram(program);
6249 ASSERT(programObject);
6250 programObject->setUniform2uiv(location, count, value);
6251}
6252
6253void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6254{
6255 Program *programObject = getProgram(program);
6256 ASSERT(programObject);
6257 programObject->setUniform3uiv(location, count, value);
6258}
6259
6260void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6261{
6262 Program *programObject = getProgram(program);
6263 ASSERT(programObject);
6264 programObject->setUniform4uiv(location, count, value);
6265}
6266
6267void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6268{
6269 Program *programObject = getProgram(program);
6270 ASSERT(programObject);
6271 programObject->setUniform1fv(location, count, value);
6272}
6273
6274void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6275{
6276 Program *programObject = getProgram(program);
6277 ASSERT(programObject);
6278 programObject->setUniform2fv(location, count, value);
6279}
6280
6281void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6282{
6283 Program *programObject = getProgram(program);
6284 ASSERT(programObject);
6285 programObject->setUniform3fv(location, count, value);
6286}
6287
6288void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6289{
6290 Program *programObject = getProgram(program);
6291 ASSERT(programObject);
6292 programObject->setUniform4fv(location, count, value);
6293}
6294
6295void Context::programUniformMatrix2fv(GLuint program,
6296 GLint location,
6297 GLsizei count,
6298 GLboolean transpose,
6299 const GLfloat *value)
6300{
6301 Program *programObject = getProgram(program);
6302 ASSERT(programObject);
6303 programObject->setUniformMatrix2fv(location, count, transpose, value);
6304}
6305
6306void Context::programUniformMatrix3fv(GLuint program,
6307 GLint location,
6308 GLsizei count,
6309 GLboolean transpose,
6310 const GLfloat *value)
6311{
6312 Program *programObject = getProgram(program);
6313 ASSERT(programObject);
6314 programObject->setUniformMatrix3fv(location, count, transpose, value);
6315}
6316
6317void Context::programUniformMatrix4fv(GLuint program,
6318 GLint location,
6319 GLsizei count,
6320 GLboolean transpose,
6321 const GLfloat *value)
6322{
6323 Program *programObject = getProgram(program);
6324 ASSERT(programObject);
6325 programObject->setUniformMatrix4fv(location, count, transpose, value);
6326}
6327
6328void Context::programUniformMatrix2x3fv(GLuint program,
6329 GLint location,
6330 GLsizei count,
6331 GLboolean transpose,
6332 const GLfloat *value)
6333{
6334 Program *programObject = getProgram(program);
6335 ASSERT(programObject);
6336 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6337}
6338
6339void Context::programUniformMatrix3x2fv(GLuint program,
6340 GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *programObject = getProgram(program);
6346 ASSERT(programObject);
6347 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6348}
6349
6350void Context::programUniformMatrix2x4fv(GLuint program,
6351 GLint location,
6352 GLsizei count,
6353 GLboolean transpose,
6354 const GLfloat *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6359}
6360
6361void Context::programUniformMatrix4x2fv(GLuint program,
6362 GLint location,
6363 GLsizei count,
6364 GLboolean transpose,
6365 const GLfloat *value)
6366{
6367 Program *programObject = getProgram(program);
6368 ASSERT(programObject);
6369 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6370}
6371
6372void Context::programUniformMatrix3x4fv(GLuint program,
6373 GLint location,
6374 GLsizei count,
6375 GLboolean transpose,
6376 const GLfloat *value)
6377{
6378 Program *programObject = getProgram(program);
6379 ASSERT(programObject);
6380 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6381}
6382
6383void Context::programUniformMatrix4x3fv(GLuint program,
6384 GLint location,
6385 GLsizei count,
6386 GLboolean transpose,
6387 const GLfloat *value)
6388{
6389 Program *programObject = getProgram(program);
6390 ASSERT(programObject);
6391 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6392}
6393
Jamie Madill81c2e252017-09-09 23:32:46 -04006394void Context::onTextureChange(const Texture *texture)
6395{
6396 // Conservatively assume all textures are dirty.
6397 // TODO(jmadill): More fine-grained update.
6398 mGLState.setObjectDirty(GL_TEXTURE);
6399}
6400
James Darpiniane8a93c62018-01-04 18:02:24 -08006401bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6402{
6403 return mGLState.isCurrentTransformFeedback(tf);
6404}
6405bool Context::isCurrentVertexArray(const VertexArray *va) const
6406{
6407 return mGLState.isCurrentVertexArray(va);
6408}
6409
Yunchao Hea336b902017-08-02 16:05:21 +08006410void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6411{
6412 for (int i = 0; i < count; i++)
6413 {
6414 pipelines[i] = createProgramPipeline();
6415 }
6416}
6417
6418void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6419{
6420 for (int i = 0; i < count; i++)
6421 {
6422 if (pipelines[i] != 0)
6423 {
6424 deleteProgramPipeline(pipelines[i]);
6425 }
6426 }
6427}
6428
6429GLboolean Context::isProgramPipeline(GLuint pipeline)
6430{
6431 if (pipeline == 0)
6432 {
6433 return GL_FALSE;
6434 }
6435
6436 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6437}
6438
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006439void Context::finishFenceNV(GLuint fence)
6440{
6441 FenceNV *fenceObject = getFenceNV(fence);
6442
6443 ASSERT(fenceObject && fenceObject->isSet());
6444 handleError(fenceObject->finish());
6445}
6446
6447void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6448{
6449 FenceNV *fenceObject = getFenceNV(fence);
6450
6451 ASSERT(fenceObject && fenceObject->isSet());
6452
6453 switch (pname)
6454 {
6455 case GL_FENCE_STATUS_NV:
6456 {
6457 // GL_NV_fence spec:
6458 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6459 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6460 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6461 GLboolean status = GL_TRUE;
6462 if (fenceObject->getStatus() != GL_TRUE)
6463 {
6464 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6465 }
6466 *params = status;
6467 break;
6468 }
6469
6470 case GL_FENCE_CONDITION_NV:
6471 {
6472 *params = static_cast<GLint>(fenceObject->getCondition());
6473 break;
6474 }
6475
6476 default:
6477 UNREACHABLE();
6478 }
6479}
6480
6481void Context::getTranslatedShaderSource(GLuint shader,
6482 GLsizei bufsize,
6483 GLsizei *length,
6484 GLchar *source)
6485{
6486 Shader *shaderObject = getShader(shader);
6487 ASSERT(shaderObject);
6488 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6489}
6490
6491void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6492{
6493 Program *programObject = getProgram(program);
6494 ASSERT(programObject);
6495
6496 programObject->getUniformfv(this, location, params);
6497}
6498
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006499void Context::getnUniformfvRobust(GLuint program,
6500 GLint location,
6501 GLsizei bufSize,
6502 GLsizei *length,
6503 GLfloat *params)
6504{
6505 UNIMPLEMENTED();
6506}
6507
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006508void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
6512
6513 programObject->getUniformiv(this, location, params);
6514}
6515
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006516void Context::getnUniformivRobust(GLuint program,
6517 GLint location,
6518 GLsizei bufSize,
6519 GLsizei *length,
6520 GLint *params)
6521{
6522 UNIMPLEMENTED();
6523}
6524
6525void Context::getnUniformuivRobust(GLuint program,
6526 GLint location,
6527 GLsizei bufSize,
6528 GLsizei *length,
6529 GLuint *params)
6530{
6531 UNIMPLEMENTED();
6532}
6533
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006534GLboolean Context::isFenceNV(GLuint fence)
6535{
6536 FenceNV *fenceObject = getFenceNV(fence);
6537
6538 if (fenceObject == nullptr)
6539 {
6540 return GL_FALSE;
6541 }
6542
6543 // GL_NV_fence spec:
6544 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6545 // existing fence.
6546 return fenceObject->isSet();
6547}
6548
6549void Context::readnPixels(GLint x,
6550 GLint y,
6551 GLsizei width,
6552 GLsizei height,
6553 GLenum format,
6554 GLenum type,
6555 GLsizei bufSize,
6556 void *data)
6557{
6558 return readPixels(x, y, width, height, format, type, data);
6559}
6560
Jamie Madill007530e2017-12-28 14:27:04 -05006561void Context::setFenceNV(GLuint fence, GLenum condition)
6562{
6563 ASSERT(condition == GL_ALL_COMPLETED_NV);
6564
6565 FenceNV *fenceObject = getFenceNV(fence);
6566 ASSERT(fenceObject != nullptr);
6567 handleError(fenceObject->set(condition));
6568}
6569
6570GLboolean Context::testFenceNV(GLuint fence)
6571{
6572 FenceNV *fenceObject = getFenceNV(fence);
6573
6574 ASSERT(fenceObject != nullptr);
6575 ASSERT(fenceObject->isSet() == GL_TRUE);
6576
6577 GLboolean result = GL_TRUE;
6578 Error error = fenceObject->test(&result);
6579 if (error.isError())
6580 {
6581 handleError(error);
6582 return GL_TRUE;
6583 }
6584
6585 return result;
6586}
6587
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006588void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006589{
6590 Texture *texture = getTargetTexture(target);
6591 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006592 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006593}
6594
Jamie Madillfa920eb2018-01-04 11:45:50 -05006595void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006596{
6597 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6598 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6599 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6600}
6601
Jamie Madillfa920eb2018-01-04 11:45:50 -05006602void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6603{
6604 UNIMPLEMENTED();
6605}
6606
Jamie Madill5b772312018-03-08 20:28:32 -05006607bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6608{
6609 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6610 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6611 // to the fact that it is stored internally as a float, and so would require conversion
6612 // if returned from Context::getIntegerv. Since this conversion is already implemented
6613 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6614 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6615 // application.
6616 switch (pname)
6617 {
6618 case GL_COMPRESSED_TEXTURE_FORMATS:
6619 {
6620 *type = GL_INT;
6621 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6622 return true;
6623 }
6624 case GL_SHADER_BINARY_FORMATS:
6625 {
6626 *type = GL_INT;
6627 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6628 return true;
6629 }
6630
6631 case GL_MAX_VERTEX_ATTRIBS:
6632 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6633 case GL_MAX_VARYING_VECTORS:
6634 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6635 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6636 case GL_MAX_TEXTURE_IMAGE_UNITS:
6637 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6638 case GL_MAX_RENDERBUFFER_SIZE:
6639 case GL_NUM_SHADER_BINARY_FORMATS:
6640 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6641 case GL_ARRAY_BUFFER_BINDING:
6642 case GL_FRAMEBUFFER_BINDING:
6643 case GL_RENDERBUFFER_BINDING:
6644 case GL_CURRENT_PROGRAM:
6645 case GL_PACK_ALIGNMENT:
6646 case GL_UNPACK_ALIGNMENT:
6647 case GL_GENERATE_MIPMAP_HINT:
6648 case GL_RED_BITS:
6649 case GL_GREEN_BITS:
6650 case GL_BLUE_BITS:
6651 case GL_ALPHA_BITS:
6652 case GL_DEPTH_BITS:
6653 case GL_STENCIL_BITS:
6654 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6655 case GL_CULL_FACE_MODE:
6656 case GL_FRONT_FACE:
6657 case GL_ACTIVE_TEXTURE:
6658 case GL_STENCIL_FUNC:
6659 case GL_STENCIL_VALUE_MASK:
6660 case GL_STENCIL_REF:
6661 case GL_STENCIL_FAIL:
6662 case GL_STENCIL_PASS_DEPTH_FAIL:
6663 case GL_STENCIL_PASS_DEPTH_PASS:
6664 case GL_STENCIL_BACK_FUNC:
6665 case GL_STENCIL_BACK_VALUE_MASK:
6666 case GL_STENCIL_BACK_REF:
6667 case GL_STENCIL_BACK_FAIL:
6668 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6669 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6670 case GL_DEPTH_FUNC:
6671 case GL_BLEND_SRC_RGB:
6672 case GL_BLEND_SRC_ALPHA:
6673 case GL_BLEND_DST_RGB:
6674 case GL_BLEND_DST_ALPHA:
6675 case GL_BLEND_EQUATION_RGB:
6676 case GL_BLEND_EQUATION_ALPHA:
6677 case GL_STENCIL_WRITEMASK:
6678 case GL_STENCIL_BACK_WRITEMASK:
6679 case GL_STENCIL_CLEAR_VALUE:
6680 case GL_SUBPIXEL_BITS:
6681 case GL_MAX_TEXTURE_SIZE:
6682 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6683 case GL_SAMPLE_BUFFERS:
6684 case GL_SAMPLES:
6685 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6686 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6687 case GL_TEXTURE_BINDING_2D:
6688 case GL_TEXTURE_BINDING_CUBE_MAP:
6689 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6690 {
6691 *type = GL_INT;
6692 *numParams = 1;
6693 return true;
6694 }
6695 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6696 {
6697 if (!getExtensions().packReverseRowOrder)
6698 {
6699 return false;
6700 }
6701 *type = GL_INT;
6702 *numParams = 1;
6703 return true;
6704 }
6705 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6706 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6707 {
6708 if (!getExtensions().textureRectangle)
6709 {
6710 return false;
6711 }
6712 *type = GL_INT;
6713 *numParams = 1;
6714 return true;
6715 }
6716 case GL_MAX_DRAW_BUFFERS_EXT:
6717 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6718 {
6719 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6720 {
6721 return false;
6722 }
6723 *type = GL_INT;
6724 *numParams = 1;
6725 return true;
6726 }
6727 case GL_MAX_VIEWPORT_DIMS:
6728 {
6729 *type = GL_INT;
6730 *numParams = 2;
6731 return true;
6732 }
6733 case GL_VIEWPORT:
6734 case GL_SCISSOR_BOX:
6735 {
6736 *type = GL_INT;
6737 *numParams = 4;
6738 return true;
6739 }
6740 case GL_SHADER_COMPILER:
6741 case GL_SAMPLE_COVERAGE_INVERT:
6742 case GL_DEPTH_WRITEMASK:
6743 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6744 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6745 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6746 // bool-natural
6747 case GL_SAMPLE_COVERAGE:
6748 case GL_SCISSOR_TEST:
6749 case GL_STENCIL_TEST:
6750 case GL_DEPTH_TEST:
6751 case GL_BLEND:
6752 case GL_DITHER:
6753 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6754 {
6755 *type = GL_BOOL;
6756 *numParams = 1;
6757 return true;
6758 }
6759 case GL_COLOR_WRITEMASK:
6760 {
6761 *type = GL_BOOL;
6762 *numParams = 4;
6763 return true;
6764 }
6765 case GL_POLYGON_OFFSET_FACTOR:
6766 case GL_POLYGON_OFFSET_UNITS:
6767 case GL_SAMPLE_COVERAGE_VALUE:
6768 case GL_DEPTH_CLEAR_VALUE:
6769 case GL_LINE_WIDTH:
6770 {
6771 *type = GL_FLOAT;
6772 *numParams = 1;
6773 return true;
6774 }
6775 case GL_ALIASED_LINE_WIDTH_RANGE:
6776 case GL_ALIASED_POINT_SIZE_RANGE:
6777 case GL_DEPTH_RANGE:
6778 {
6779 *type = GL_FLOAT;
6780 *numParams = 2;
6781 return true;
6782 }
6783 case GL_COLOR_CLEAR_VALUE:
6784 case GL_BLEND_COLOR:
6785 {
6786 *type = GL_FLOAT;
6787 *numParams = 4;
6788 return true;
6789 }
6790 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6791 if (!getExtensions().textureFilterAnisotropic)
6792 {
6793 return false;
6794 }
6795 *type = GL_FLOAT;
6796 *numParams = 1;
6797 return true;
6798 case GL_TIMESTAMP_EXT:
6799 if (!getExtensions().disjointTimerQuery)
6800 {
6801 return false;
6802 }
6803 *type = GL_INT_64_ANGLEX;
6804 *numParams = 1;
6805 return true;
6806 case GL_GPU_DISJOINT_EXT:
6807 if (!getExtensions().disjointTimerQuery)
6808 {
6809 return false;
6810 }
6811 *type = GL_INT;
6812 *numParams = 1;
6813 return true;
6814 case GL_COVERAGE_MODULATION_CHROMIUM:
6815 if (!getExtensions().framebufferMixedSamples)
6816 {
6817 return false;
6818 }
6819 *type = GL_INT;
6820 *numParams = 1;
6821 return true;
6822 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6823 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6824 {
6825 return false;
6826 }
6827 *type = GL_INT;
6828 *numParams = 1;
6829 return true;
6830 }
6831
6832 if (getExtensions().debug)
6833 {
6834 switch (pname)
6835 {
6836 case GL_DEBUG_LOGGED_MESSAGES:
6837 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6838 case GL_DEBUG_GROUP_STACK_DEPTH:
6839 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6840 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6841 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6842 case GL_MAX_LABEL_LENGTH:
6843 *type = GL_INT;
6844 *numParams = 1;
6845 return true;
6846
6847 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6848 case GL_DEBUG_OUTPUT:
6849 *type = GL_BOOL;
6850 *numParams = 1;
6851 return true;
6852 }
6853 }
6854
6855 if (getExtensions().multisampleCompatibility)
6856 {
6857 switch (pname)
6858 {
6859 case GL_MULTISAMPLE_EXT:
6860 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6861 *type = GL_BOOL;
6862 *numParams = 1;
6863 return true;
6864 }
6865 }
6866
6867 if (getExtensions().pathRendering)
6868 {
6869 switch (pname)
6870 {
6871 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6872 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6873 *type = GL_FLOAT;
6874 *numParams = 16;
6875 return true;
6876 }
6877 }
6878
6879 if (getExtensions().bindGeneratesResource)
6880 {
6881 switch (pname)
6882 {
6883 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6884 *type = GL_BOOL;
6885 *numParams = 1;
6886 return true;
6887 }
6888 }
6889
6890 if (getExtensions().clientArrays)
6891 {
6892 switch (pname)
6893 {
6894 case GL_CLIENT_ARRAYS_ANGLE:
6895 *type = GL_BOOL;
6896 *numParams = 1;
6897 return true;
6898 }
6899 }
6900
6901 if (getExtensions().sRGBWriteControl)
6902 {
6903 switch (pname)
6904 {
6905 case GL_FRAMEBUFFER_SRGB_EXT:
6906 *type = GL_BOOL;
6907 *numParams = 1;
6908 return true;
6909 }
6910 }
6911
6912 if (getExtensions().robustResourceInitialization &&
6913 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6914 {
6915 *type = GL_BOOL;
6916 *numParams = 1;
6917 return true;
6918 }
6919
6920 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6921 {
6922 *type = GL_BOOL;
6923 *numParams = 1;
6924 return true;
6925 }
6926
6927 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6928 switch (pname)
6929 {
6930 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6931 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6932 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6933 {
6934 return false;
6935 }
6936 *type = GL_INT;
6937 *numParams = 1;
6938 return true;
6939
6940 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6941 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6942 {
6943 return false;
6944 }
6945 *type = GL_INT;
6946 *numParams = 1;
6947 return true;
6948
6949 case GL_PROGRAM_BINARY_FORMATS_OES:
6950 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6951 {
6952 return false;
6953 }
6954 *type = GL_INT;
6955 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6956 return true;
6957
6958 case GL_PACK_ROW_LENGTH:
6959 case GL_PACK_SKIP_ROWS:
6960 case GL_PACK_SKIP_PIXELS:
6961 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6962 {
6963 return false;
6964 }
6965 *type = GL_INT;
6966 *numParams = 1;
6967 return true;
6968 case GL_UNPACK_ROW_LENGTH:
6969 case GL_UNPACK_SKIP_ROWS:
6970 case GL_UNPACK_SKIP_PIXELS:
6971 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6972 {
6973 return false;
6974 }
6975 *type = GL_INT;
6976 *numParams = 1;
6977 return true;
6978 case GL_VERTEX_ARRAY_BINDING:
6979 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6980 {
6981 return false;
6982 }
6983 *type = GL_INT;
6984 *numParams = 1;
6985 return true;
6986 case GL_PIXEL_PACK_BUFFER_BINDING:
6987 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6988 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6989 {
6990 return false;
6991 }
6992 *type = GL_INT;
6993 *numParams = 1;
6994 return true;
6995 case GL_MAX_SAMPLES:
6996 {
6997 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6998 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6999 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7000 {
7001 return false;
7002 }
7003 *type = GL_INT;
7004 *numParams = 1;
7005 return true;
7006
7007 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7008 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7009 {
7010 return false;
7011 }
7012 *type = GL_INT;
7013 *numParams = 1;
7014 return true;
7015 }
7016 }
7017
7018 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7019 {
7020 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7021 {
7022 return false;
7023 }
7024 *type = GL_INT;
7025 *numParams = 1;
7026 return true;
7027 }
7028
7029 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7030 {
7031 *type = GL_INT;
7032 *numParams = 1;
7033 return true;
7034 }
7035
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007036 if (getClientVersion() < Version(2, 0))
7037 {
7038 switch (pname)
7039 {
7040 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007041 case GL_CLIENT_ACTIVE_TEXTURE:
7042 case GL_MATRIX_MODE:
7043 case GL_MAX_TEXTURE_UNITS:
7044 case GL_MAX_MODELVIEW_STACK_DEPTH:
7045 case GL_MAX_PROJECTION_STACK_DEPTH:
7046 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007047 case GL_VERTEX_ARRAY_STRIDE:
7048 case GL_NORMAL_ARRAY_STRIDE:
7049 case GL_COLOR_ARRAY_STRIDE:
7050 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7051 case GL_VERTEX_ARRAY_SIZE:
7052 case GL_COLOR_ARRAY_SIZE:
7053 case GL_TEXTURE_COORD_ARRAY_SIZE:
7054 case GL_VERTEX_ARRAY_TYPE:
7055 case GL_NORMAL_ARRAY_TYPE:
7056 case GL_COLOR_ARRAY_TYPE:
7057 case GL_TEXTURE_COORD_ARRAY_TYPE:
7058 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7059 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7060 case GL_COLOR_ARRAY_BUFFER_BINDING:
7061 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7062 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7063 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7064 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007065 *type = GL_INT;
7066 *numParams = 1;
7067 return true;
7068 case GL_ALPHA_TEST_REF:
7069 *type = GL_FLOAT;
7070 *numParams = 1;
7071 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007072 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007073 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007074 *type = GL_FLOAT;
7075 *numParams = 4;
7076 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007077 case GL_CURRENT_NORMAL:
7078 *type = GL_FLOAT;
7079 *numParams = 3;
7080 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007081 case GL_MODELVIEW_MATRIX:
7082 case GL_PROJECTION_MATRIX:
7083 case GL_TEXTURE_MATRIX:
7084 *type = GL_FLOAT;
7085 *numParams = 16;
7086 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007087 }
7088 }
7089
Jamie Madill5b772312018-03-08 20:28:32 -05007090 if (getClientVersion() < Version(3, 0))
7091 {
7092 return false;
7093 }
7094
7095 // Check for ES3.0+ parameter names
7096 switch (pname)
7097 {
7098 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7099 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7100 case GL_UNIFORM_BUFFER_BINDING:
7101 case GL_TRANSFORM_FEEDBACK_BINDING:
7102 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7103 case GL_COPY_READ_BUFFER_BINDING:
7104 case GL_COPY_WRITE_BUFFER_BINDING:
7105 case GL_SAMPLER_BINDING:
7106 case GL_READ_BUFFER:
7107 case GL_TEXTURE_BINDING_3D:
7108 case GL_TEXTURE_BINDING_2D_ARRAY:
7109 case GL_MAX_3D_TEXTURE_SIZE:
7110 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7111 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7112 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7113 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7114 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7115 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7116 case GL_MAX_VARYING_COMPONENTS:
7117 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7118 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7119 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7120 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7121 case GL_NUM_EXTENSIONS:
7122 case GL_MAJOR_VERSION:
7123 case GL_MINOR_VERSION:
7124 case GL_MAX_ELEMENTS_INDICES:
7125 case GL_MAX_ELEMENTS_VERTICES:
7126 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7127 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7128 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7129 case GL_UNPACK_IMAGE_HEIGHT:
7130 case GL_UNPACK_SKIP_IMAGES:
7131 {
7132 *type = GL_INT;
7133 *numParams = 1;
7134 return true;
7135 }
7136
7137 case GL_MAX_ELEMENT_INDEX:
7138 case GL_MAX_UNIFORM_BLOCK_SIZE:
7139 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7140 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7141 case GL_MAX_SERVER_WAIT_TIMEOUT:
7142 {
7143 *type = GL_INT_64_ANGLEX;
7144 *numParams = 1;
7145 return true;
7146 }
7147
7148 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7149 case GL_TRANSFORM_FEEDBACK_PAUSED:
7150 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7151 case GL_RASTERIZER_DISCARD:
7152 {
7153 *type = GL_BOOL;
7154 *numParams = 1;
7155 return true;
7156 }
7157
7158 case GL_MAX_TEXTURE_LOD_BIAS:
7159 {
7160 *type = GL_FLOAT;
7161 *numParams = 1;
7162 return true;
7163 }
7164 }
7165
7166 if (getExtensions().requestExtension)
7167 {
7168 switch (pname)
7169 {
7170 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7171 *type = GL_INT;
7172 *numParams = 1;
7173 return true;
7174 }
7175 }
7176
7177 if (getClientVersion() < Version(3, 1))
7178 {
7179 return false;
7180 }
7181
7182 switch (pname)
7183 {
7184 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7185 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7186 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7187 case GL_MAX_FRAMEBUFFER_WIDTH:
7188 case GL_MAX_FRAMEBUFFER_HEIGHT:
7189 case GL_MAX_FRAMEBUFFER_SAMPLES:
7190 case GL_MAX_SAMPLE_MASK_WORDS:
7191 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7192 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7193 case GL_MAX_INTEGER_SAMPLES:
7194 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7195 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7196 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7197 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7198 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7199 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7200 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7201 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7202 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7203 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7204 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7205 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7206 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7207 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7208 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7209 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7210 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7211 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7212 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7213 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7214 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7215 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7216 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7217 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7218 case GL_MAX_UNIFORM_LOCATIONS:
7219 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7220 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7221 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7222 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7223 case GL_MAX_IMAGE_UNITS:
7224 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7225 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7226 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7227 case GL_SHADER_STORAGE_BUFFER_BINDING:
7228 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7229 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7230 *type = GL_INT;
7231 *numParams = 1;
7232 return true;
7233 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7234 *type = GL_INT_64_ANGLEX;
7235 *numParams = 1;
7236 return true;
7237 case GL_SAMPLE_MASK:
7238 *type = GL_BOOL;
7239 *numParams = 1;
7240 return true;
7241 }
7242
7243 if (getExtensions().geometryShader)
7244 {
7245 switch (pname)
7246 {
7247 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7248 case GL_LAYER_PROVOKING_VERTEX_EXT:
7249 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7250 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7251 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7252 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7253 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7254 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7255 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7256 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7257 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7258 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7259 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7260 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7261 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7262 *type = GL_INT;
7263 *numParams = 1;
7264 return true;
7265 }
7266 }
7267
7268 return false;
7269}
7270
7271bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7272{
7273 if (getClientVersion() < Version(3, 0))
7274 {
7275 return false;
7276 }
7277
7278 switch (target)
7279 {
7280 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7281 case GL_UNIFORM_BUFFER_BINDING:
7282 {
7283 *type = GL_INT;
7284 *numParams = 1;
7285 return true;
7286 }
7287 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7288 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7289 case GL_UNIFORM_BUFFER_START:
7290 case GL_UNIFORM_BUFFER_SIZE:
7291 {
7292 *type = GL_INT_64_ANGLEX;
7293 *numParams = 1;
7294 return true;
7295 }
7296 }
7297
7298 if (getClientVersion() < Version(3, 1))
7299 {
7300 return false;
7301 }
7302
7303 switch (target)
7304 {
7305 case GL_IMAGE_BINDING_LAYERED:
7306 {
7307 *type = GL_BOOL;
7308 *numParams = 1;
7309 return true;
7310 }
7311 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7312 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7313 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7314 case GL_SHADER_STORAGE_BUFFER_BINDING:
7315 case GL_VERTEX_BINDING_BUFFER:
7316 case GL_VERTEX_BINDING_DIVISOR:
7317 case GL_VERTEX_BINDING_OFFSET:
7318 case GL_VERTEX_BINDING_STRIDE:
7319 case GL_SAMPLE_MASK_VALUE:
7320 case GL_IMAGE_BINDING_NAME:
7321 case GL_IMAGE_BINDING_LEVEL:
7322 case GL_IMAGE_BINDING_LAYER:
7323 case GL_IMAGE_BINDING_ACCESS:
7324 case GL_IMAGE_BINDING_FORMAT:
7325 {
7326 *type = GL_INT;
7327 *numParams = 1;
7328 return true;
7329 }
7330 case GL_ATOMIC_COUNTER_BUFFER_START:
7331 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7332 case GL_SHADER_STORAGE_BUFFER_START:
7333 case GL_SHADER_STORAGE_BUFFER_SIZE:
7334 {
7335 *type = GL_INT_64_ANGLEX;
7336 *numParams = 1;
7337 return true;
7338 }
7339 }
7340
7341 return false;
7342}
7343
7344Program *Context::getProgram(GLuint handle) const
7345{
7346 return mState.mShaderPrograms->getProgram(handle);
7347}
7348
7349Shader *Context::getShader(GLuint handle) const
7350{
7351 return mState.mShaderPrograms->getShader(handle);
7352}
7353
7354bool Context::isTextureGenerated(GLuint texture) const
7355{
7356 return mState.mTextures->isHandleGenerated(texture);
7357}
7358
7359bool Context::isBufferGenerated(GLuint buffer) const
7360{
7361 return mState.mBuffers->isHandleGenerated(buffer);
7362}
7363
7364bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7365{
7366 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7367}
7368
7369bool Context::isFramebufferGenerated(GLuint framebuffer) const
7370{
7371 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7372}
7373
7374bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7375{
7376 return mState.mPipelines->isHandleGenerated(pipeline);
7377}
7378
7379bool Context::usingDisplayTextureShareGroup() const
7380{
7381 return mDisplayTextureShareGroup;
7382}
7383
7384GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7385{
7386 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7387 internalformat == GL_DEPTH_STENCIL
7388 ? GL_DEPTH24_STENCIL8
7389 : internalformat;
7390}
7391
Jamie Madillc29968b2016-01-20 11:17:23 -05007392} // namespace gl