blob: 1441f71b0c591fd5b592ac99d8e9584b04cbf288 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070027#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030028#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080030#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050032#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050033#include "libANGLE/ResourceManager.h"
34#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050035#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050036#include "libANGLE/Texture.h"
37#include "libANGLE/TransformFeedback.h"
38#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040040#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030041#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040042#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040043#include "libANGLE/renderer/ContextImpl.h"
44#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040045#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040046#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000047
Geoff Langf6db0982015-08-25 13:04:00 -040048namespace
49{
50
Jamie Madillb6664922017-07-25 12:55:04 -040051#define ANGLE_HANDLE_ERR(X) \
52 handleError(X); \
53 return;
54#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
55
Ian Ewell3ffd78b2016-01-22 16:09:42 -050056template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050057std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030058 GLsizei numPaths,
59 const void *paths,
60 GLuint pathBase)
61{
62 std::vector<gl::Path *> ret;
63 ret.reserve(numPaths);
64
65 const auto *nameArray = static_cast<const T *>(paths);
66
67 for (GLsizei i = 0; i < numPaths; ++i)
68 {
69 const GLuint pathName = nameArray[i] + pathBase;
70
71 ret.push_back(resourceManager.getPath(pathName));
72 }
73
74 return ret;
75}
76
Geoff Lang4ddf5af2016-12-01 14:30:44 -050077std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030078 GLsizei numPaths,
79 GLenum pathNameType,
80 const void *paths,
81 GLuint pathBase)
82{
83 switch (pathNameType)
84 {
85 case GL_UNSIGNED_BYTE:
86 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_BYTE:
89 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_UNSIGNED_SHORT:
92 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_SHORT:
95 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_UNSIGNED_INT:
98 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_INT:
101 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
102 }
103
104 UNREACHABLE();
105 return std::vector<gl::Path *>();
106}
107
108template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400109gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110{
Geoff Lang2186c382016-10-14 10:54:54 -0400111 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500112
113 switch (pname)
114 {
115 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400116 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117 case GL_QUERY_RESULT_AVAILABLE_EXT:
118 {
119 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400120 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 if (!error.isError())
122 {
jchen10a99ed552017-09-22 08:10:32 +0800123 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125 return error;
126 }
127 default:
128 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500129 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill09463932018-04-04 05:26:59 -0400133void MarkTransformFeedbackBufferUsage(const gl::Context *context,
134 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Geoff Lang1a683462015-09-29 15:09:59 -0400138 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155gl::Version GetClientVersion(const egl::AttributeMap &attribs)
156{
157 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Geoff Langf6db0982015-08-25 13:04:00 -0400257} // anonymous namespace
258
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000259namespace gl
260{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000261
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400262Context::Context(rx::EGLImplFactory *implFactory,
263 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400264 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500265 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400266 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500267 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700268 const egl::DisplayExtensions &displayExtensions,
269 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500270 : mState(reinterpret_cast<ContextID>(this),
271 shareContext ? &shareContext->mState : nullptr,
272 shareTextures,
273 GetClientVersion(attribs),
274 &mGLState,
275 mCaps,
276 mTextureCaps,
277 mExtensions,
278 mLimitations),
279 mSkipValidation(GetNoError(attribs)),
280 mDisplayTextureShareGroup(shareTextures != nullptr),
281 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700282 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400283 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400284 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mClientType(EGL_OPENGL_ES_API),
286 mHasBeenCurrent(false),
287 mContextLost(false),
288 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700289 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mResetStrategy(GetResetStrategy(attribs)),
291 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400292 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
293 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500294 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500295 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400296 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400297 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400298 mScratchBuffer(1000u),
299 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000300{
Jamie Madill5b772312018-03-08 20:28:32 -0500301 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400302 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
303 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500304
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400305 mImplementation->setMemoryProgramCache(memoryProgramCache);
306
Geoff Langb433e872017-10-05 14:01:47 -0400307 bool robustResourceInit = GetRobustResourceInit(attribs);
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700308 initCaps(displayExtensions, clientExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700309 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400310
Jamie Madill4928b7c2017-06-20 12:57:39 -0400311 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400312 GetClientArraysEnabled(attribs), robustResourceInit,
313 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100314
Shannon Woods53a94a82014-06-24 15:20:36 -0400315 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400316
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400318 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000319 // and cube map texture state vectors respectively associated with them.
320 // In order that access to these initial textures not be lost, they are treated as texture
321 // objects all of whose names are 0.
322
Corentin Wallez99d492c2018-02-27 15:17:10 -0500323 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800324 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500325
Corentin Wallez99d492c2018-02-27 15:17:10 -0500326 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800327 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400328
Geoff Langeb66a6e2016-10-31 13:06:12 -0400329 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400330 {
331 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500332 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800333 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400334
Corentin Wallez99d492c2018-02-27 15:17:10 -0500335 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800336 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 }
Geoff Lang3b573612016-10-31 14:08:10 -0400338 if (getClientVersion() >= Version(3, 1))
339 {
340 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500341 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800342 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343
Jiajia Qin6eafb042016-12-27 17:04:07 +0800344 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
345 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800346 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800347 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800349 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
350 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400351 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800352 }
Geoff Lang3b573612016-10-31 14:08:10 -0400353 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000354
Geoff Langb0f917f2017-12-05 13:41:54 -0500355 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400356 {
357 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500358 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800359 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400360 }
361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400363 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500364 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800365 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400366 }
367
Jamie Madill4928b7c2017-06-20 12:57:39 -0400368 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500369
Jamie Madill57a89722013-07-02 11:57:03 -0400370 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000371
Geoff Langeb66a6e2016-10-31 13:06:12 -0400372 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400373 {
374 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
375 // In the initial state, a default transform feedback object is bound and treated as
376 // a transform feedback object with a name of zero. That object is bound any time
377 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400378 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400379 }
Geoff Langc8058452014-02-03 12:04:11 -0500380
Corentin Wallez336129f2017-10-17 15:55:40 -0400381 for (auto type : angle::AllEnums<BufferBinding>())
382 {
383 bindBuffer(type, 0);
384 }
385
386 bindRenderbuffer(GL_RENDERBUFFER, 0);
387
388 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
389 {
390 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
391 }
392
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700393 // Initialize GLES1 renderer if appropriate.
394 if (getClientVersion() < Version(2, 0))
395 {
396 mGLES1Renderer.reset(new GLES1Renderer());
397 }
398
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500401 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500402 // No dirty objects.
403
404 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500407 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
408
409 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
411 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
412 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
416 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
419 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
420 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
421
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
423 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700424 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400427
Xinghua Cao10a4d432017-11-28 14:46:26 +0800428 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
429 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
431 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
432 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
433 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800434 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800435 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800436
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400437 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438}
439
Jamie Madill4928b7c2017-06-20 12:57:39 -0400440egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700442 if (mGLES1Renderer)
443 {
444 mGLES1Renderer->onDestroy(this, &mGLState);
445 }
446
Jamie Madille7b3fe22018-04-05 09:42:46 -0400447 // Delete the Surface first to trigger a finish() in Vulkan.
Geoff Lang61107632018-05-09 11:32:46 -0400448 if (mSurfacelessFramebuffer)
449 {
450 mSurfacelessFramebuffer->onDestroy(this);
451 SafeDelete(mSurfacelessFramebuffer);
452 }
Jamie Madille7b3fe22018-04-05 09:42:46 -0400453
454 ANGLE_TRY(releaseSurface(display));
455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400460 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461
Corentin Wallez80b24112015-08-25 16:41:57 -0400462 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400464 if (query.second != nullptr)
465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400469 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000470
Corentin Wallez80b24112015-08-25 16:41:57 -0400471 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400472 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 if (vertexArray.second)
474 {
475 vertexArray.second->onDestroy(this);
476 }
Jamie Madill57a89722013-07-02 11:57:03 -0400477 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400478 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400479
Corentin Wallez80b24112015-08-25 16:41:57 -0400480 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500481 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500482 if (transformFeedback.second != nullptr)
483 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500484 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500485 }
Geoff Langc8058452014-02-03 12:04:11 -0500486 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400487 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500488
Jamie Madill5b772312018-03-08 20:28:32 -0500489 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400490 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800491 if (zeroTexture.get() != nullptr)
492 {
493 ANGLE_TRY(zeroTexture->onDestroy(this));
494 zeroTexture.set(this, nullptr);
495 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400496 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497
Jamie Madill2f348d22017-06-05 10:50:59 -0400498 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500 mGLState.reset(this);
501
Jamie Madill6c1f6712017-02-14 19:08:04 -0500502 mState.mBuffers->release(this);
503 mState.mShaderPrograms->release(this);
504 mState.mTextures->release(this);
505 mState.mRenderbuffers->release(this);
506 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400507 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500508 mState.mPaths->release(this);
509 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800510 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511
Jamie Madill76e471e2017-10-21 09:56:01 -0400512 mImplementation->onDestroy(this);
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517Context::~Context()
518{
519}
520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522{
Jamie Madill61e16b42017-06-19 11:13:23 -0400523 mCurrentDisplay = display;
524
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 if (!mHasBeenCurrent)
526 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000527 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500528 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400529 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallezc295e512017-01-27 17:47:50 -0500531 int width = 0;
532 int height = 0;
533 if (surface != nullptr)
534 {
535 width = surface->getWidth();
536 height = surface->getHeight();
537 }
538
539 mGLState.setViewportParams(0, 0, width, height);
540 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541
542 mHasBeenCurrent = true;
543 }
544
Jamie Madill1b94d432015-08-07 13:23:23 -0400545 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400547 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400548
Jamie Madill4928b7c2017-06-20 12:57:39 -0400549 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500550
551 Framebuffer *newDefault = nullptr;
552 if (surface != nullptr)
553 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400554 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500555 mCurrentSurface = surface;
556 newDefault = surface->getDefaultFramebuffer();
557 }
558 else
559 {
560 if (mSurfacelessFramebuffer == nullptr)
561 {
562 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
563 }
564
565 newDefault = mSurfacelessFramebuffer;
566 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000567
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Update default framebuffer, the binding of the previous default
569 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400570 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700571 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700573 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400574 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700575 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400576 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700577 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400578 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500579 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400580 }
Ian Ewell292f0052016-02-04 10:37:32 -0500581
582 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583 mImplementation->onMakeCurrent(this);
584 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585}
586
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400588{
Corentin Wallez37c39792015-08-20 14:19:46 -0400589 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500590 Framebuffer *currentDefault = nullptr;
591 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400592 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500593 currentDefault = mCurrentSurface->getDefaultFramebuffer();
594 }
595 else if (mSurfacelessFramebuffer != nullptr)
596 {
597 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400598 }
599
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 if (mGLState.getReadFramebuffer() == currentDefault)
601 {
602 mGLState.setReadFramebufferBinding(nullptr);
603 }
604 if (mGLState.getDrawFramebuffer() == currentDefault)
605 {
606 mGLState.setDrawFramebufferBinding(nullptr);
607 }
608 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
609
610 if (mCurrentSurface)
611 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500613 mCurrentSurface = nullptr;
614 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400615
616 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400617}
618
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619GLuint Context::createBuffer()
620{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500621 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622}
623
624GLuint Context::createProgram()
625{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500626 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627}
628
Jiawei Shao385b3e02018-03-21 09:43:28 +0800629GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500631 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632}
633
634GLuint Context::createTexture()
635{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500636 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
639GLuint Context::createRenderbuffer()
640{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500641 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Brandon Jones59770802018-04-02 13:18:42 -0700644GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300645{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500646 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300647 if (resultOrError.isError())
648 {
649 handleError(resultOrError.getError());
650 return 0;
651 }
652 return resultOrError.getResult();
653}
654
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655// Returns an unused framebuffer name
656GLuint Context::createFramebuffer()
657{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500658 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500661void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500663 for (int i = 0; i < n; i++)
664 {
665 GLuint handle = mFenceNVHandleAllocator.allocate();
666 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
667 fences[i] = handle;
668 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
Yunchao Hea336b902017-08-02 16:05:21 +0800671GLuint Context::createProgramPipeline()
672{
673 return mState.mPipelines->createProgramPipeline();
674}
675
Jiawei Shao385b3e02018-03-21 09:43:28 +0800676GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800677{
678 UNIMPLEMENTED();
679 return 0u;
680}
681
James Darpinian4d9d4832018-03-13 12:43:28 -0700682void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683{
James Darpinian4d9d4832018-03-13 12:43:28 -0700684 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
685 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000686 {
687 detachBuffer(buffer);
688 }
Jamie Madill893ab082014-05-16 16:56:10 -0400689
James Darpinian4d9d4832018-03-13 12:43:28 -0700690 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000691}
692
693void Context::deleteShader(GLuint shader)
694{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500695 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696}
697
698void Context::deleteProgram(GLuint program)
699{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500700 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000701}
702
703void Context::deleteTexture(GLuint texture)
704{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500705 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000706 {
707 detachTexture(texture);
708 }
709
Jamie Madill6c1f6712017-02-14 19:08:04 -0500710 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
713void Context::deleteRenderbuffer(GLuint renderbuffer)
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716 {
717 detachRenderbuffer(renderbuffer);
718 }
Jamie Madill893ab082014-05-16 16:56:10 -0400719
Jamie Madill6c1f6712017-02-14 19:08:04 -0500720 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400723void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400724{
725 // The spec specifies the underlying Fence object is not deleted until all current
726 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
727 // and since our API is currently designed for being called from a single thread, we can delete
728 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400729 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400730}
731
Yunchao Hea336b902017-08-02 16:05:21 +0800732void Context::deleteProgramPipeline(GLuint pipeline)
733{
734 if (mState.mPipelines->getProgramPipeline(pipeline))
735 {
736 detachProgramPipeline(pipeline);
737 }
738
739 mState.mPipelines->deleteObject(this, pipeline);
740}
741
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742void Context::deletePaths(GLuint first, GLsizei range)
743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745}
746
Brandon Jones59770802018-04-02 13:18:42 -0700747bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500749 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750 if (pathObj == nullptr)
751 return false;
752
753 return pathObj->hasPathData();
754}
755
Brandon Jones59770802018-04-02 13:18:42 -0700756bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759}
760
Brandon Jones59770802018-04-02 13:18:42 -0700761void Context::pathCommands(GLuint path,
762 GLsizei numCommands,
763 const GLubyte *commands,
764 GLsizei numCoords,
765 GLenum coordType,
766 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300767{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500768 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300769
770 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
771}
772
Jamie Madill007530e2017-12-28 14:27:04 -0500773void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Jamie Madill007530e2017-12-28 14:27:04 -0500775 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300776
777 switch (pname)
778 {
779 case GL_PATH_STROKE_WIDTH_CHROMIUM:
780 pathObj->setStrokeWidth(value);
781 break;
782 case GL_PATH_END_CAPS_CHROMIUM:
783 pathObj->setEndCaps(static_cast<GLenum>(value));
784 break;
785 case GL_PATH_JOIN_STYLE_CHROMIUM:
786 pathObj->setJoinStyle(static_cast<GLenum>(value));
787 break;
788 case GL_PATH_MITER_LIMIT_CHROMIUM:
789 pathObj->setMiterLimit(value);
790 break;
791 case GL_PATH_STROKE_BOUND_CHROMIUM:
792 pathObj->setStrokeBound(value);
793 break;
794 default:
795 UNREACHABLE();
796 break;
797 }
798}
799
Jamie Madill007530e2017-12-28 14:27:04 -0500800void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801{
Jamie Madill007530e2017-12-28 14:27:04 -0500802 // TODO(jmadill): Should use proper clamping/casting.
803 pathParameterf(path, pname, static_cast<GLfloat>(value));
804}
805
806void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
807{
808 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300809
810 switch (pname)
811 {
812 case GL_PATH_STROKE_WIDTH_CHROMIUM:
813 *value = pathObj->getStrokeWidth();
814 break;
815 case GL_PATH_END_CAPS_CHROMIUM:
816 *value = static_cast<GLfloat>(pathObj->getEndCaps());
817 break;
818 case GL_PATH_JOIN_STYLE_CHROMIUM:
819 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
820 break;
821 case GL_PATH_MITER_LIMIT_CHROMIUM:
822 *value = pathObj->getMiterLimit();
823 break;
824 case GL_PATH_STROKE_BOUND_CHROMIUM:
825 *value = pathObj->getStrokeBound();
826 break;
827 default:
828 UNREACHABLE();
829 break;
830 }
831}
832
Jamie Madill007530e2017-12-28 14:27:04 -0500833void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
834{
835 GLfloat val = 0.0f;
836 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
837 if (value)
838 *value = static_cast<GLint>(val);
839}
840
Brandon Jones59770802018-04-02 13:18:42 -0700841void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842{
843 mGLState.setPathStencilFunc(func, ref, mask);
844}
845
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846void Context::deleteFramebuffer(GLuint framebuffer)
847{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500848 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849 {
850 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500852
Jamie Madill6c1f6712017-02-14 19:08:04 -0500853 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854}
855
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500856void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500858 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500860 GLuint fence = fences[i];
861
862 FenceNV *fenceObject = nullptr;
863 if (mFenceNVMap.erase(fence, &fenceObject))
864 {
865 mFenceNVHandleAllocator.release(fence);
866 delete fenceObject;
867 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868 }
869}
870
Geoff Lang70d0f492015-12-10 17:45:46 -0500871Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500873 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874}
875
Jamie Madill570f7c82014-07-03 10:38:54 -0400876Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000877{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500878 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879}
880
Geoff Lang70d0f492015-12-10 17:45:46 -0500881Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000882{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500883 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884}
885
Jamie Madill70b5bb02017-08-28 13:32:37 -0400886Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400887{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400888 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400889}
890
Jamie Madill57a89722013-07-02 11:57:03 -0400891VertexArray *Context::getVertexArray(GLuint handle) const
892{
Jamie Madill96a483b2017-06-27 16:49:21 -0400893 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400894}
895
Jamie Madilldc356042013-07-19 16:36:57 -0400896Sampler *Context::getSampler(GLuint handle) const
897{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500898 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400899}
900
Geoff Langc8058452014-02-03 12:04:11 -0500901TransformFeedback *Context::getTransformFeedback(GLuint handle) const
902{
Jamie Madill96a483b2017-06-27 16:49:21 -0400903 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500904}
905
Yunchao Hea336b902017-08-02 16:05:21 +0800906ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
907{
908 return mState.mPipelines->getProgramPipeline(handle);
909}
910
Geoff Lang70d0f492015-12-10 17:45:46 -0500911LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
912{
913 switch (identifier)
914 {
915 case GL_BUFFER:
916 return getBuffer(name);
917 case GL_SHADER:
918 return getShader(name);
919 case GL_PROGRAM:
920 return getProgram(name);
921 case GL_VERTEX_ARRAY:
922 return getVertexArray(name);
923 case GL_QUERY:
924 return getQuery(name);
925 case GL_TRANSFORM_FEEDBACK:
926 return getTransformFeedback(name);
927 case GL_SAMPLER:
928 return getSampler(name);
929 case GL_TEXTURE:
930 return getTexture(name);
931 case GL_RENDERBUFFER:
932 return getRenderbuffer(name);
933 case GL_FRAMEBUFFER:
934 return getFramebuffer(name);
935 default:
936 UNREACHABLE();
937 return nullptr;
938 }
939}
940
941LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
942{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400943 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500944}
945
Martin Radev9d901792016-07-15 15:58:58 +0300946void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
947{
948 LabeledObject *object = getLabeledObject(identifier, name);
949 ASSERT(object != nullptr);
950
951 std::string labelName = GetObjectLabelFromPointer(length, label);
952 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400953
954 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
955 // specified object is active until we do this.
956 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300957}
958
959void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
960{
961 LabeledObject *object = getLabeledObjectFromPtr(ptr);
962 ASSERT(object != nullptr);
963
964 std::string labelName = GetObjectLabelFromPointer(length, label);
965 object->setLabel(labelName);
966}
967
968void Context::getObjectLabel(GLenum identifier,
969 GLuint name,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObject(identifier, name);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
981void Context::getObjectPtrLabel(const void *ptr,
982 GLsizei bufSize,
983 GLsizei *length,
984 GLchar *label) const
985{
986 LabeledObject *object = getLabeledObjectFromPtr(ptr);
987 ASSERT(object != nullptr);
988
989 const std::string &objectLabel = object->getLabel();
990 GetObjectLabelBase(objectLabel, bufSize, length, label);
991}
992
Jamie Madilldc356042013-07-19 16:36:57 -0400993bool Context::isSampler(GLuint samplerName) const
994{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500995 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400996}
997
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800998void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001
Jamie Madilldedd7b92014-11-05 16:30:36 -05001002 if (handle == 0)
1003 {
1004 texture = mZeroTextures[target].get();
1005 }
1006 else
1007 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001008 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009 }
1010
1011 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001013}
1014
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001015void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001017 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1018 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001019 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001020}
1021
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001022void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001024 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1025 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001026 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027}
1028
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001029void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001030{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001032 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001033}
1034
Shao80957d92017-02-20 21:25:59 +08001035void Context::bindVertexBuffer(GLuint bindingIndex,
1036 GLuint bufferHandle,
1037 GLintptr offset,
1038 GLsizei stride)
1039{
1040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001041 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001045{
Geoff Lang76b10c92014-09-05 16:28:14 -04001046 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001047 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001048 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001049 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001050}
1051
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001052void Context::bindImageTexture(GLuint unit,
1053 GLuint texture,
1054 GLint level,
1055 GLboolean layered,
1056 GLint layer,
1057 GLenum access,
1058 GLenum format)
1059{
1060 Texture *tex = mState.mTextures->getTexture(texture);
1061 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1062}
1063
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064void Context::useProgram(GLuint program)
1065{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001066 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001067}
1068
Jiajia Qin5451d532017-11-16 17:16:34 +08001069void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1070{
1071 UNIMPLEMENTED();
1072}
1073
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001074void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001075{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001076 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001077 TransformFeedback *transformFeedback =
1078 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001079 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001080}
1081
Yunchao Hea336b902017-08-02 16:05:21 +08001082void Context::bindProgramPipeline(GLuint pipelineHandle)
1083{
1084 ProgramPipeline *pipeline =
1085 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1086 mGLState.setProgramPipelineBinding(this, pipeline);
1087}
1088
Corentin Wallezad3ae902018-03-09 13:40:42 -05001089void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001092 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093
Geoff Lang5aad9672014-09-08 11:10:42 -04001094 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001095 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001096
1097 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001099}
1100
Corentin Wallezad3ae902018-03-09 13:40:42 -05001101void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001103 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001104 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001107
Geoff Lang5aad9672014-09-08 11:10:42 -04001108 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Corentin Wallezad3ae902018-03-09 13:40:42 -05001112void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001113{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001114 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115
1116 Query *queryObject = getQuery(id, true, target);
1117 ASSERT(queryObject);
1118
Jamie Madillf0e04492017-08-26 15:28:42 -04001119 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120}
1121
Corentin Wallezad3ae902018-03-09 13:40:42 -05001122void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123{
1124 switch (pname)
1125 {
1126 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001128 break;
1129 case GL_QUERY_COUNTER_BITS_EXT:
1130 switch (target)
1131 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001132 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001133 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1134 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001135 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001136 params[0] = getExtensions().queryCounterBitsTimestamp;
1137 break;
1138 default:
1139 UNREACHABLE();
1140 params[0] = 0;
1141 break;
1142 }
1143 break;
1144 default:
1145 UNREACHABLE();
1146 return;
1147 }
1148}
1149
Corentin Wallezad3ae902018-03-09 13:40:42 -05001150void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001151 GLenum pname,
1152 GLsizei bufSize,
1153 GLsizei *length,
1154 GLint *params)
1155{
1156 getQueryiv(target, pname, params);
1157}
1158
Geoff Lang2186c382016-10-14 10:54:54 -04001159void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160{
Geoff Lang2186c382016-10-14 10:54:54 -04001161 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001162}
1163
Brandon Jones59770802018-04-02 13:18:42 -07001164void Context::getQueryObjectivRobust(GLuint id,
1165 GLenum pname,
1166 GLsizei bufSize,
1167 GLsizei *length,
1168 GLint *params)
1169{
1170 getQueryObjectiv(id, pname, params);
1171}
1172
Geoff Lang2186c382016-10-14 10:54:54 -04001173void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174{
Geoff Lang2186c382016-10-14 10:54:54 -04001175 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176}
1177
Brandon Jones59770802018-04-02 13:18:42 -07001178void Context::getQueryObjectuivRobust(GLuint id,
1179 GLenum pname,
1180 GLsizei bufSize,
1181 GLsizei *length,
1182 GLuint *params)
1183{
1184 getQueryObjectuiv(id, pname, params);
1185}
1186
Geoff Lang2186c382016-10-14 10:54:54 -04001187void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188{
Geoff Lang2186c382016-10-14 10:54:54 -04001189 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190}
1191
Brandon Jones59770802018-04-02 13:18:42 -07001192void Context::getQueryObjecti64vRobust(GLuint id,
1193 GLenum pname,
1194 GLsizei bufSize,
1195 GLsizei *length,
1196 GLint64 *params)
1197{
1198 getQueryObjecti64v(id, pname, params);
1199}
1200
Geoff Lang2186c382016-10-14 10:54:54 -04001201void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202{
Geoff Lang2186c382016-10-14 10:54:54 -04001203 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204}
1205
Brandon Jones59770802018-04-02 13:18:42 -07001206void Context::getQueryObjectui64vRobust(GLuint id,
1207 GLenum pname,
1208 GLsizei bufSize,
1209 GLsizei *length,
1210 GLuint64 *params)
1211{
1212 getQueryObjectui64v(id, pname, params);
1213}
1214
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001215Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001217 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218}
1219
Jamie Madill2f348d22017-06-05 10:50:59 -04001220FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221{
Jamie Madill96a483b2017-06-27 16:49:21 -04001222 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223}
1224
Corentin Wallezad3ae902018-03-09 13:40:42 -05001225Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226{
Jamie Madill96a483b2017-06-27 16:49:21 -04001227 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001229 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001231
1232 Query *query = mQueryMap.query(handle);
1233 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001234 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 query = new Query(mImplementation->createQuery(type), handle);
1237 query->addRef();
1238 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001240 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241}
1242
Geoff Lang70d0f492015-12-10 17:45:46 -05001243Query *Context::getQuery(GLuint handle) const
1244{
Jamie Madill96a483b2017-06-27 16:49:21 -04001245 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001246}
1247
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001248Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001249{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001250 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1251 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001252}
1253
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001254Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001256 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257}
1258
Geoff Lang492a7e42014-11-05 13:27:06 -05001259Compiler *Context::getCompiler() const
1260{
Jamie Madill2f348d22017-06-05 10:50:59 -04001261 if (mCompiler.get() == nullptr)
1262 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001263 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001264 }
1265 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001266}
1267
Jamie Madillc1d770e2017-04-13 17:31:24 -04001268void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
1270 switch (pname)
1271 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001272 case GL_SHADER_COMPILER:
1273 *params = GL_TRUE;
1274 break;
1275 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1276 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1277 break;
1278 default:
1279 mGLState.getBooleanv(pname, params);
1280 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282}
1283
Jamie Madillc1d770e2017-04-13 17:31:24 -04001284void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285{
Shannon Woods53a94a82014-06-24 15:20:36 -04001286 // Queries about context capabilities and maximums are answered by Context.
1287 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 switch (pname)
1289 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001290 case GL_ALIASED_LINE_WIDTH_RANGE:
1291 params[0] = mCaps.minAliasedLineWidth;
1292 params[1] = mCaps.maxAliasedLineWidth;
1293 break;
1294 case GL_ALIASED_POINT_SIZE_RANGE:
1295 params[0] = mCaps.minAliasedPointSize;
1296 params[1] = mCaps.maxAliasedPointSize;
1297 break;
1298 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1299 ASSERT(mExtensions.textureFilterAnisotropic);
1300 *params = mExtensions.maxTextureAnisotropy;
1301 break;
1302 case GL_MAX_TEXTURE_LOD_BIAS:
1303 *params = mCaps.maxLODBias;
1304 break;
1305
1306 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1307 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1308 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001309 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1310 // GLES1 constants for modelview/projection matrix.
1311 if (getClientVersion() < Version(2, 0))
1312 {
1313 mGLState.getFloatv(pname, params);
1314 }
1315 else
1316 {
1317 ASSERT(mExtensions.pathRendering);
1318 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1319 memcpy(params, m, 16 * sizeof(GLfloat));
1320 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001321 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001322 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001323
Jamie Madill231c7f52017-04-26 13:45:37 -04001324 default:
1325 mGLState.getFloatv(pname, params);
1326 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Jamie Madillc1d770e2017-04-13 17:31:24 -04001330void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
Shannon Woods53a94a82014-06-24 15:20:36 -04001332 // Queries about context capabilities and maximums are answered by Context.
1333 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001334
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 switch (pname)
1336 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001337 case GL_MAX_VERTEX_ATTRIBS:
1338 *params = mCaps.maxVertexAttributes;
1339 break;
1340 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1341 *params = mCaps.maxVertexUniformVectors;
1342 break;
1343 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1344 *params = mCaps.maxVertexUniformComponents;
1345 break;
1346 case GL_MAX_VARYING_VECTORS:
1347 *params = mCaps.maxVaryingVectors;
1348 break;
1349 case GL_MAX_VARYING_COMPONENTS:
1350 *params = mCaps.maxVertexOutputComponents;
1351 break;
1352 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1353 *params = mCaps.maxCombinedTextureImageUnits;
1354 break;
1355 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001356 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 break;
1358 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001359 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
1361 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1362 *params = mCaps.maxFragmentUniformVectors;
1363 break;
1364 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1365 *params = mCaps.maxFragmentUniformComponents;
1366 break;
1367 case GL_MAX_RENDERBUFFER_SIZE:
1368 *params = mCaps.maxRenderbufferSize;
1369 break;
1370 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1371 *params = mCaps.maxColorAttachments;
1372 break;
1373 case GL_MAX_DRAW_BUFFERS_EXT:
1374 *params = mCaps.maxDrawBuffers;
1375 break;
1376 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1377 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1378 case GL_SUBPIXEL_BITS:
1379 *params = 4;
1380 break;
1381 case GL_MAX_TEXTURE_SIZE:
1382 *params = mCaps.max2DTextureSize;
1383 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001384 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1385 *params = mCaps.maxRectangleTextureSize;
1386 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1388 *params = mCaps.maxCubeMapTextureSize;
1389 break;
1390 case GL_MAX_3D_TEXTURE_SIZE:
1391 *params = mCaps.max3DTextureSize;
1392 break;
1393 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1394 *params = mCaps.maxArrayTextureLayers;
1395 break;
1396 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1397 *params = mCaps.uniformBufferOffsetAlignment;
1398 break;
1399 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1400 *params = mCaps.maxUniformBufferBindings;
1401 break;
1402 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001403 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001404 break;
1405 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001406 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 break;
1408 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1409 *params = mCaps.maxCombinedTextureImageUnits;
1410 break;
1411 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1412 *params = mCaps.maxVertexOutputComponents;
1413 break;
1414 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1415 *params = mCaps.maxFragmentInputComponents;
1416 break;
1417 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1418 *params = mCaps.minProgramTexelOffset;
1419 break;
1420 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1421 *params = mCaps.maxProgramTexelOffset;
1422 break;
1423 case GL_MAJOR_VERSION:
1424 *params = getClientVersion().major;
1425 break;
1426 case GL_MINOR_VERSION:
1427 *params = getClientVersion().minor;
1428 break;
1429 case GL_MAX_ELEMENTS_INDICES:
1430 *params = mCaps.maxElementsIndices;
1431 break;
1432 case GL_MAX_ELEMENTS_VERTICES:
1433 *params = mCaps.maxElementsVertices;
1434 break;
1435 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1436 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1437 break;
1438 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1439 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1440 break;
1441 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1442 *params = mCaps.maxTransformFeedbackSeparateComponents;
1443 break;
1444 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1445 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1446 break;
1447 case GL_MAX_SAMPLES_ANGLE:
1448 *params = mCaps.maxSamples;
1449 break;
1450 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001451 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001452 params[0] = mCaps.maxViewportWidth;
1453 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001454 }
1455 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 case GL_COMPRESSED_TEXTURE_FORMATS:
1457 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1458 params);
1459 break;
1460 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1461 *params = mResetStrategy;
1462 break;
1463 case GL_NUM_SHADER_BINARY_FORMATS:
1464 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1465 break;
1466 case GL_SHADER_BINARY_FORMATS:
1467 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1468 break;
1469 case GL_NUM_PROGRAM_BINARY_FORMATS:
1470 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1471 break;
1472 case GL_PROGRAM_BINARY_FORMATS:
1473 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1474 break;
1475 case GL_NUM_EXTENSIONS:
1476 *params = static_cast<GLint>(mExtensionStrings.size());
1477 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001478
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 // GL_KHR_debug
1480 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1481 *params = mExtensions.maxDebugMessageLength;
1482 break;
1483 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1484 *params = mExtensions.maxDebugLoggedMessages;
1485 break;
1486 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1487 *params = mExtensions.maxDebugGroupStackDepth;
1488 break;
1489 case GL_MAX_LABEL_LENGTH:
1490 *params = mExtensions.maxLabelLength;
1491 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001492
Martin Radeve5285d22017-07-14 16:23:53 +03001493 // GL_ANGLE_multiview
1494 case GL_MAX_VIEWS_ANGLE:
1495 *params = mExtensions.maxViews;
1496 break;
1497
Jamie Madill231c7f52017-04-26 13:45:37 -04001498 // GL_EXT_disjoint_timer_query
1499 case GL_GPU_DISJOINT_EXT:
1500 *params = mImplementation->getGPUDisjoint();
1501 break;
1502 case GL_MAX_FRAMEBUFFER_WIDTH:
1503 *params = mCaps.maxFramebufferWidth;
1504 break;
1505 case GL_MAX_FRAMEBUFFER_HEIGHT:
1506 *params = mCaps.maxFramebufferHeight;
1507 break;
1508 case GL_MAX_FRAMEBUFFER_SAMPLES:
1509 *params = mCaps.maxFramebufferSamples;
1510 break;
1511 case GL_MAX_SAMPLE_MASK_WORDS:
1512 *params = mCaps.maxSampleMaskWords;
1513 break;
1514 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1515 *params = mCaps.maxColorTextureSamples;
1516 break;
1517 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1518 *params = mCaps.maxDepthTextureSamples;
1519 break;
1520 case GL_MAX_INTEGER_SAMPLES:
1521 *params = mCaps.maxIntegerSamples;
1522 break;
1523 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1524 *params = mCaps.maxVertexAttribRelativeOffset;
1525 break;
1526 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1527 *params = mCaps.maxVertexAttribBindings;
1528 break;
1529 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1530 *params = mCaps.maxVertexAttribStride;
1531 break;
1532 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1533 *params = mCaps.maxVertexAtomicCounterBuffers;
1534 break;
1535 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1536 *params = mCaps.maxVertexAtomicCounters;
1537 break;
1538 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1539 *params = mCaps.maxVertexImageUniforms;
1540 break;
1541 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001542 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001543 break;
1544 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1545 *params = mCaps.maxFragmentAtomicCounterBuffers;
1546 break;
1547 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1548 *params = mCaps.maxFragmentAtomicCounters;
1549 break;
1550 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1551 *params = mCaps.maxFragmentImageUniforms;
1552 break;
1553 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001554 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1557 *params = mCaps.minProgramTextureGatherOffset;
1558 break;
1559 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1560 *params = mCaps.maxProgramTextureGatherOffset;
1561 break;
1562 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1563 *params = mCaps.maxComputeWorkGroupInvocations;
1564 break;
1565 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001566 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001569 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1572 *params = mCaps.maxComputeSharedMemorySize;
1573 break;
1574 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1575 *params = mCaps.maxComputeUniformComponents;
1576 break;
1577 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1578 *params = mCaps.maxComputeAtomicCounterBuffers;
1579 break;
1580 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1581 *params = mCaps.maxComputeAtomicCounters;
1582 break;
1583 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1584 *params = mCaps.maxComputeImageUniforms;
1585 break;
1586 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1587 *params = mCaps.maxCombinedComputeUniformComponents;
1588 break;
1589 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001590 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1593 *params = mCaps.maxCombinedShaderOutputResources;
1594 break;
1595 case GL_MAX_UNIFORM_LOCATIONS:
1596 *params = mCaps.maxUniformLocations;
1597 break;
1598 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1599 *params = mCaps.maxAtomicCounterBufferBindings;
1600 break;
1601 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1602 *params = mCaps.maxAtomicCounterBufferSize;
1603 break;
1604 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1605 *params = mCaps.maxCombinedAtomicCounterBuffers;
1606 break;
1607 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1608 *params = mCaps.maxCombinedAtomicCounters;
1609 break;
1610 case GL_MAX_IMAGE_UNITS:
1611 *params = mCaps.maxImageUnits;
1612 break;
1613 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1614 *params = mCaps.maxCombinedImageUniforms;
1615 break;
1616 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1617 *params = mCaps.maxShaderStorageBufferBindings;
1618 break;
1619 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1620 *params = mCaps.maxCombinedShaderStorageBlocks;
1621 break;
1622 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1623 *params = mCaps.shaderStorageBufferOffsetAlignment;
1624 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001625
1626 // GL_EXT_geometry_shader
1627 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1628 *params = mCaps.maxFramebufferLayers;
1629 break;
1630 case GL_LAYER_PROVOKING_VERTEX_EXT:
1631 *params = mCaps.layerProvokingVertex;
1632 break;
1633 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1634 *params = mCaps.maxGeometryUniformComponents;
1635 break;
1636 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001637 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001638 break;
1639 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1640 *params = mCaps.maxCombinedGeometryUniformComponents;
1641 break;
1642 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1643 *params = mCaps.maxGeometryInputComponents;
1644 break;
1645 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1646 *params = mCaps.maxGeometryOutputComponents;
1647 break;
1648 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1649 *params = mCaps.maxGeometryOutputVertices;
1650 break;
1651 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1652 *params = mCaps.maxGeometryTotalOutputComponents;
1653 break;
1654 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1655 *params = mCaps.maxGeometryShaderInvocations;
1656 break;
1657 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001658 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001659 break;
1660 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1661 *params = mCaps.maxGeometryAtomicCounterBuffers;
1662 break;
1663 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1664 *params = mCaps.maxGeometryAtomicCounters;
1665 break;
1666 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1667 *params = mCaps.maxGeometryImageUniforms;
1668 break;
1669 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001670 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001671 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001672 // GLES1 emulation: Caps queries
1673 case GL_MAX_TEXTURE_UNITS:
1674 *params = mCaps.maxMultitextureUnits;
1675 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001676 case GL_MAX_MODELVIEW_STACK_DEPTH:
1677 *params = mCaps.maxModelviewMatrixStackDepth;
1678 break;
1679 case GL_MAX_PROJECTION_STACK_DEPTH:
1680 *params = mCaps.maxProjectionMatrixStackDepth;
1681 break;
1682 case GL_MAX_TEXTURE_STACK_DEPTH:
1683 *params = mCaps.maxTextureMatrixStackDepth;
1684 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001685 // GLES1 emulation: Vertex attribute queries
1686 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1687 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1688 case GL_COLOR_ARRAY_BUFFER_BINDING:
1689 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1690 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1691 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1692 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1693 break;
1694 case GL_VERTEX_ARRAY_STRIDE:
1695 case GL_NORMAL_ARRAY_STRIDE:
1696 case GL_COLOR_ARRAY_STRIDE:
1697 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1698 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1699 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1700 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1701 break;
1702 case GL_VERTEX_ARRAY_SIZE:
1703 case GL_COLOR_ARRAY_SIZE:
1704 case GL_TEXTURE_COORD_ARRAY_SIZE:
1705 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1706 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1707 break;
1708 case GL_VERTEX_ARRAY_TYPE:
1709 case GL_COLOR_ARRAY_TYPE:
1710 case GL_NORMAL_ARRAY_TYPE:
1711 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1712 case GL_TEXTURE_COORD_ARRAY_TYPE:
1713 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1714 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1715 break;
1716
Jamie Madill231c7f52017-04-26 13:45:37 -04001717 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001718 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001719 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001720 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001721}
1722
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001723void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001724{
Shannon Woods53a94a82014-06-24 15:20:36 -04001725 // Queries about context capabilities and maximums are answered by Context.
1726 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001727 switch (pname)
1728 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001729 case GL_MAX_ELEMENT_INDEX:
1730 *params = mCaps.maxElementIndex;
1731 break;
1732 case GL_MAX_UNIFORM_BLOCK_SIZE:
1733 *params = mCaps.maxUniformBlockSize;
1734 break;
1735 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1736 *params = mCaps.maxCombinedVertexUniformComponents;
1737 break;
1738 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1739 *params = mCaps.maxCombinedFragmentUniformComponents;
1740 break;
1741 case GL_MAX_SERVER_WAIT_TIMEOUT:
1742 *params = mCaps.maxServerWaitTimeout;
1743 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001744
Jamie Madill231c7f52017-04-26 13:45:37 -04001745 // GL_EXT_disjoint_timer_query
1746 case GL_TIMESTAMP_EXT:
1747 *params = mImplementation->getTimestamp();
1748 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001749
Jamie Madill231c7f52017-04-26 13:45:37 -04001750 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1751 *params = mCaps.maxShaderStorageBlockSize;
1752 break;
1753 default:
1754 UNREACHABLE();
1755 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001756 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001757}
1758
Geoff Lang70d0f492015-12-10 17:45:46 -05001759void Context::getPointerv(GLenum pname, void **params) const
1760{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001761 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001762}
1763
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001764void Context::getPointervRobustANGLERobust(GLenum pname,
1765 GLsizei bufSize,
1766 GLsizei *length,
1767 void **params)
1768{
1769 UNIMPLEMENTED();
1770}
1771
Martin Radev66fb8202016-07-28 11:45:20 +03001772void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001773{
Shannon Woods53a94a82014-06-24 15:20:36 -04001774 // Queries about context capabilities and maximums are answered by Context.
1775 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001776
1777 GLenum nativeType;
1778 unsigned int numParams;
1779 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1780 ASSERT(queryStatus);
1781
1782 if (nativeType == GL_INT)
1783 {
1784 switch (target)
1785 {
1786 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1787 ASSERT(index < 3u);
1788 *data = mCaps.maxComputeWorkGroupCount[index];
1789 break;
1790 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1791 ASSERT(index < 3u);
1792 *data = mCaps.maxComputeWorkGroupSize[index];
1793 break;
1794 default:
1795 mGLState.getIntegeri_v(target, index, data);
1796 }
1797 }
1798 else
1799 {
1800 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1801 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001802}
1803
Brandon Jones59770802018-04-02 13:18:42 -07001804void Context::getIntegeri_vRobust(GLenum target,
1805 GLuint index,
1806 GLsizei bufSize,
1807 GLsizei *length,
1808 GLint *data)
1809{
1810 getIntegeri_v(target, index, data);
1811}
1812
Martin Radev66fb8202016-07-28 11:45:20 +03001813void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001814{
Shannon Woods53a94a82014-06-24 15:20:36 -04001815 // Queries about context capabilities and maximums are answered by Context.
1816 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001817
1818 GLenum nativeType;
1819 unsigned int numParams;
1820 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1821 ASSERT(queryStatus);
1822
1823 if (nativeType == GL_INT_64_ANGLEX)
1824 {
1825 mGLState.getInteger64i_v(target, index, data);
1826 }
1827 else
1828 {
1829 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1830 }
1831}
1832
Brandon Jones59770802018-04-02 13:18:42 -07001833void Context::getInteger64i_vRobust(GLenum target,
1834 GLuint index,
1835 GLsizei bufSize,
1836 GLsizei *length,
1837 GLint64 *data)
1838{
1839 getInteger64i_v(target, index, data);
1840}
1841
Martin Radev66fb8202016-07-28 11:45:20 +03001842void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1843{
1844 // Queries about context capabilities and maximums are answered by Context.
1845 // Queries about current GL state values are answered by State.
1846
1847 GLenum nativeType;
1848 unsigned int numParams;
1849 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1850 ASSERT(queryStatus);
1851
1852 if (nativeType == GL_BOOL)
1853 {
1854 mGLState.getBooleani_v(target, index, data);
1855 }
1856 else
1857 {
1858 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1859 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001860}
1861
Brandon Jones59770802018-04-02 13:18:42 -07001862void Context::getBooleani_vRobust(GLenum target,
1863 GLuint index,
1864 GLsizei bufSize,
1865 GLsizei *length,
1866 GLboolean *data)
1867{
1868 getBooleani_v(target, index, data);
1869}
1870
Corentin Wallez336129f2017-10-17 15:55:40 -04001871void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001872{
1873 Buffer *buffer = mGLState.getTargetBuffer(target);
1874 QueryBufferParameteriv(buffer, pname, params);
1875}
1876
Brandon Jones59770802018-04-02 13:18:42 -07001877void Context::getBufferParameterivRobust(BufferBinding target,
1878 GLenum pname,
1879 GLsizei bufSize,
1880 GLsizei *length,
1881 GLint *params)
1882{
1883 getBufferParameteriv(target, pname, params);
1884}
1885
He Yunchao010e4db2017-03-03 14:22:06 +08001886void Context::getFramebufferAttachmentParameteriv(GLenum target,
1887 GLenum attachment,
1888 GLenum pname,
1889 GLint *params)
1890{
1891 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001892 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001893}
1894
Brandon Jones59770802018-04-02 13:18:42 -07001895void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1896 GLenum attachment,
1897 GLenum pname,
1898 GLsizei bufSize,
1899 GLsizei *length,
1900 GLint *params)
1901{
1902 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1903}
1904
He Yunchao010e4db2017-03-03 14:22:06 +08001905void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1906{
1907 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1908 QueryRenderbufferiv(this, renderbuffer, pname, params);
1909}
1910
Brandon Jones59770802018-04-02 13:18:42 -07001911void Context::getRenderbufferParameterivRobust(GLenum target,
1912 GLenum pname,
1913 GLsizei bufSize,
1914 GLsizei *length,
1915 GLint *params)
1916{
1917 getRenderbufferParameteriv(target, pname, params);
1918}
1919
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001920void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001921{
1922 Texture *texture = getTargetTexture(target);
1923 QueryTexParameterfv(texture, pname, params);
1924}
1925
Brandon Jones59770802018-04-02 13:18:42 -07001926void Context::getTexParameterfvRobust(TextureType target,
1927 GLenum pname,
1928 GLsizei bufSize,
1929 GLsizei *length,
1930 GLfloat *params)
1931{
1932 getTexParameterfv(target, pname, params);
1933}
1934
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001935void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001936{
1937 Texture *texture = getTargetTexture(target);
1938 QueryTexParameteriv(texture, pname, params);
1939}
Jiajia Qin5451d532017-11-16 17:16:34 +08001940
Brandon Jones59770802018-04-02 13:18:42 -07001941void Context::getTexParameterivRobust(TextureType target,
1942 GLenum pname,
1943 GLsizei bufSize,
1944 GLsizei *length,
1945 GLint *params)
1946{
1947 getTexParameteriv(target, pname, params);
1948}
1949
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001950void Context::getTexParameterIivRobust(TextureType target,
1951 GLenum pname,
1952 GLsizei bufSize,
1953 GLsizei *length,
1954 GLint *params)
1955{
1956 UNIMPLEMENTED();
1957}
1958
1959void Context::getTexParameterIuivRobust(TextureType target,
1960 GLenum pname,
1961 GLsizei bufSize,
1962 GLsizei *length,
1963 GLuint *params)
1964{
1965 UNIMPLEMENTED();
1966}
1967
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001968void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001969{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001970 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001971 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001972}
1973
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001974void Context::getTexLevelParameterivRobust(TextureTarget target,
1975 GLint level,
1976 GLenum pname,
1977 GLsizei bufSize,
1978 GLsizei *length,
1979 GLint *params)
1980{
1981 UNIMPLEMENTED();
1982}
1983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001984void Context::getTexLevelParameterfv(TextureTarget target,
1985 GLint level,
1986 GLenum pname,
1987 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001988{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001989 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001990 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001991}
1992
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001993void Context::getTexLevelParameterfvRobust(TextureTarget target,
1994 GLint level,
1995 GLenum pname,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLfloat *params)
1999{
2000 UNIMPLEMENTED();
2001}
2002
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002003void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002006 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002007 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002008}
2009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002010void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002011{
2012 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002013 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002014 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002015}
2016
Brandon Jones59770802018-04-02 13:18:42 -07002017void Context::texParameterfvRobust(TextureType target,
2018 GLenum pname,
2019 GLsizei bufSize,
2020 const GLfloat *params)
2021{
2022 texParameterfv(target, pname, params);
2023}
2024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002025void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002026{
2027 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002028 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002029 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002030}
2031
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002032void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002033{
2034 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002035 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002036 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002037}
2038
Brandon Jones59770802018-04-02 13:18:42 -07002039void Context::texParameterivRobust(TextureType target,
2040 GLenum pname,
2041 GLsizei bufSize,
2042 const GLint *params)
2043{
2044 texParameteriv(target, pname, params);
2045}
2046
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002047void Context::texParameterIivRobust(TextureType target,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 const GLint *params)
2051{
2052 UNIMPLEMENTED();
2053}
2054
2055void Context::texParameterIuivRobust(TextureType target,
2056 GLenum pname,
2057 GLsizei bufSize,
2058 const GLuint *params)
2059{
2060 UNIMPLEMENTED();
2061}
2062
Jamie Madill675fe712016-12-19 13:07:54 -05002063void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002064{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002065 // No-op if zero count
2066 if (count == 0)
2067 {
2068 return;
2069 }
2070
Jamie Madill05b35b22017-10-03 09:01:44 -04002071 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002072 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002073 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002074}
2075
Jamie Madill675fe712016-12-19 13:07:54 -05002076void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002077{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002078 // No-op if zero count
2079 if (count == 0 || instanceCount == 0)
2080 {
2081 return;
2082 }
2083
Jamie Madill05b35b22017-10-03 09:01:44 -04002084 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002085 ANGLE_CONTEXT_TRY(
2086 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002087 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2088 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002089}
2090
Jamie Madill876429b2017-04-20 15:46:24 -04002091void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002092{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002093 // No-op if zero count
2094 if (count == 0)
2095 {
2096 return;
2097 }
2098
Jamie Madill05b35b22017-10-03 09:01:44 -04002099 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002100 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002101}
2102
Jamie Madill675fe712016-12-19 13:07:54 -05002103void Context::drawElementsInstanced(GLenum mode,
2104 GLsizei count,
2105 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002106 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002107 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002108{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002109 // No-op if zero count
2110 if (count == 0 || instances == 0)
2111 {
2112 return;
2113 }
2114
Jamie Madill05b35b22017-10-03 09:01:44 -04002115 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002116 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002117 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002118}
2119
Jamie Madill675fe712016-12-19 13:07:54 -05002120void Context::drawRangeElements(GLenum mode,
2121 GLuint start,
2122 GLuint end,
2123 GLsizei count,
2124 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002125 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002126{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002127 // No-op if zero count
2128 if (count == 0)
2129 {
2130 return;
2131 }
2132
Jamie Madill05b35b22017-10-03 09:01:44 -04002133 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002134 ANGLE_CONTEXT_TRY(
2135 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002136}
2137
Jamie Madill876429b2017-04-20 15:46:24 -04002138void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002139{
Jamie Madill05b35b22017-10-03 09:01:44 -04002140 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002141 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002142}
2143
Jamie Madill876429b2017-04-20 15:46:24 -04002144void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002145{
Jamie Madill05b35b22017-10-03 09:01:44 -04002146 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002147 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002148}
2149
Jamie Madill675fe712016-12-19 13:07:54 -05002150void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002151{
Jamie Madillafa02a22017-11-23 12:57:38 -05002152 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002153}
2154
Jamie Madill675fe712016-12-19 13:07:54 -05002155void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002156{
Jamie Madillafa02a22017-11-23 12:57:38 -05002157 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002158}
2159
Austin Kinross6ee1e782015-05-29 17:05:37 -07002160void Context::insertEventMarker(GLsizei length, const char *marker)
2161{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002162 ASSERT(mImplementation);
2163 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002164}
2165
2166void Context::pushGroupMarker(GLsizei length, const char *marker)
2167{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002168 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002169
2170 if (marker == nullptr)
2171 {
2172 // From the EXT_debug_marker spec,
2173 // "If <marker> is null then an empty string is pushed on the stack."
2174 mImplementation->pushGroupMarker(length, "");
2175 }
2176 else
2177 {
2178 mImplementation->pushGroupMarker(length, marker);
2179 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002180}
2181
2182void Context::popGroupMarker()
2183{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002184 ASSERT(mImplementation);
2185 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002186}
2187
Geoff Langd8605522016-04-13 10:19:12 -04002188void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2189{
2190 Program *programObject = getProgram(program);
2191 ASSERT(programObject);
2192
2193 programObject->bindUniformLocation(location, name);
2194}
2195
Brandon Jones59770802018-04-02 13:18:42 -07002196void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002197{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002198 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002199}
2200
Brandon Jones59770802018-04-02 13:18:42 -07002201void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002202{
2203 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2204}
2205
Brandon Jones59770802018-04-02 13:18:42 -07002206void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002207{
2208 GLfloat I[16];
2209 angle::Matrix<GLfloat>::setToIdentity(I);
2210
2211 mGLState.loadPathRenderingMatrix(matrixMode, I);
2212}
2213
2214void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2215{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002216 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002217 if (!pathObj)
2218 return;
2219
2220 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002221 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002222
2223 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2224}
2225
2226void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2227{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002228 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229 if (!pathObj)
2230 return;
2231
2232 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002233 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002234
2235 mImplementation->stencilStrokePath(pathObj, reference, mask);
2236}
2237
2238void Context::coverFillPath(GLuint path, GLenum coverMode)
2239{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002240 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002241 if (!pathObj)
2242 return;
2243
2244 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002245 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002246
2247 mImplementation->coverFillPath(pathObj, coverMode);
2248}
2249
2250void Context::coverStrokePath(GLuint path, GLenum coverMode)
2251{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002252 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002253 if (!pathObj)
2254 return;
2255
2256 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002257 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002258
2259 mImplementation->coverStrokePath(pathObj, coverMode);
2260}
2261
2262void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2263{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002264 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002265 if (!pathObj)
2266 return;
2267
2268 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002269 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002270
2271 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2272}
2273
2274void Context::stencilThenCoverStrokePath(GLuint path,
2275 GLint reference,
2276 GLuint mask,
2277 GLenum coverMode)
2278{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002279 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002280 if (!pathObj)
2281 return;
2282
2283 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002284 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002285
2286 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2287}
2288
Sami Väisänend59ca052016-06-21 16:10:00 +03002289void Context::coverFillPathInstanced(GLsizei numPaths,
2290 GLenum pathNameType,
2291 const void *paths,
2292 GLuint pathBase,
2293 GLenum coverMode,
2294 GLenum transformType,
2295 const GLfloat *transformValues)
2296{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002297 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002298
2299 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002300 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002301
2302 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2303}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002304
Sami Väisänend59ca052016-06-21 16:10:00 +03002305void Context::coverStrokePathInstanced(GLsizei numPaths,
2306 GLenum pathNameType,
2307 const void *paths,
2308 GLuint pathBase,
2309 GLenum coverMode,
2310 GLenum transformType,
2311 const GLfloat *transformValues)
2312{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002313 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002314
2315 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002316 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002317
2318 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2319 transformValues);
2320}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002321
Sami Väisänend59ca052016-06-21 16:10:00 +03002322void Context::stencilFillPathInstanced(GLsizei numPaths,
2323 GLenum pathNameType,
2324 const void *paths,
2325 GLuint pathBase,
2326 GLenum fillMode,
2327 GLuint mask,
2328 GLenum transformType,
2329 const GLfloat *transformValues)
2330{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002331 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002332
2333 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002334 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002335
2336 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2337 transformValues);
2338}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002339
Sami Väisänend59ca052016-06-21 16:10:00 +03002340void Context::stencilStrokePathInstanced(GLsizei numPaths,
2341 GLenum pathNameType,
2342 const void *paths,
2343 GLuint pathBase,
2344 GLint reference,
2345 GLuint mask,
2346 GLenum transformType,
2347 const GLfloat *transformValues)
2348{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002349 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002350
2351 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002352 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002353
2354 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2355 transformValues);
2356}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002357
Sami Väisänend59ca052016-06-21 16:10:00 +03002358void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2359 GLenum pathNameType,
2360 const void *paths,
2361 GLuint pathBase,
2362 GLenum fillMode,
2363 GLuint mask,
2364 GLenum coverMode,
2365 GLenum transformType,
2366 const GLfloat *transformValues)
2367{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002368 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002369
2370 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002371 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002372
2373 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2374 transformType, transformValues);
2375}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002376
Sami Väisänend59ca052016-06-21 16:10:00 +03002377void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2378 GLenum pathNameType,
2379 const void *paths,
2380 GLuint pathBase,
2381 GLint reference,
2382 GLuint mask,
2383 GLenum coverMode,
2384 GLenum transformType,
2385 const GLfloat *transformValues)
2386{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002387 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002388
2389 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002390 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002391
2392 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2393 transformType, transformValues);
2394}
2395
Sami Väisänen46eaa942016-06-29 10:26:37 +03002396void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2397{
2398 auto *programObject = getProgram(program);
2399
2400 programObject->bindFragmentInputLocation(location, name);
2401}
2402
2403void Context::programPathFragmentInputGen(GLuint program,
2404 GLint location,
2405 GLenum genMode,
2406 GLint components,
2407 const GLfloat *coeffs)
2408{
2409 auto *programObject = getProgram(program);
2410
Jamie Madillbd044ed2017-06-05 12:59:21 -04002411 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002412}
2413
jchen1015015f72017-03-16 13:54:21 +08002414GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2415{
jchen10fd7c3b52017-03-21 15:36:03 +08002416 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002417 return QueryProgramResourceIndex(programObject, programInterface, name);
2418}
2419
jchen10fd7c3b52017-03-21 15:36:03 +08002420void Context::getProgramResourceName(GLuint program,
2421 GLenum programInterface,
2422 GLuint index,
2423 GLsizei bufSize,
2424 GLsizei *length,
2425 GLchar *name)
2426{
2427 const auto *programObject = getProgram(program);
2428 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2429}
2430
jchen10191381f2017-04-11 13:59:04 +08002431GLint Context::getProgramResourceLocation(GLuint program,
2432 GLenum programInterface,
2433 const GLchar *name)
2434{
2435 const auto *programObject = getProgram(program);
2436 return QueryProgramResourceLocation(programObject, programInterface, name);
2437}
2438
jchen10880683b2017-04-12 16:21:55 +08002439void Context::getProgramResourceiv(GLuint program,
2440 GLenum programInterface,
2441 GLuint index,
2442 GLsizei propCount,
2443 const GLenum *props,
2444 GLsizei bufSize,
2445 GLsizei *length,
2446 GLint *params)
2447{
2448 const auto *programObject = getProgram(program);
2449 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2450 length, params);
2451}
2452
jchen10d9cd7b72017-08-30 15:04:25 +08002453void Context::getProgramInterfaceiv(GLuint program,
2454 GLenum programInterface,
2455 GLenum pname,
2456 GLint *params)
2457{
2458 const auto *programObject = getProgram(program);
2459 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2460}
2461
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002462void Context::getProgramInterfaceivRobust(GLuint program,
2463 GLenum programInterface,
2464 GLenum pname,
2465 GLsizei bufSize,
2466 GLsizei *length,
2467 GLint *params)
2468{
2469 UNIMPLEMENTED();
2470}
2471
Jamie Madill427064d2018-04-13 16:20:34 -04002472void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002473{
Geoff Lang7b19a492018-04-20 09:31:52 -04002474 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002475 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002476 GLenum code = error.getCode();
2477 mErrors.insert(code);
2478 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2479 {
2480 markContextLost();
2481 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002482
Geoff Langee6884e2017-11-09 16:51:11 -05002483 ASSERT(!error.getMessage().empty());
2484 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2485 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002486 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002487}
2488
2489// Get one of the recorded errors and clear its flag, if any.
2490// [OpenGL ES 2.0.24] section 2.5 page 13.
2491GLenum Context::getError()
2492{
Geoff Langda5777c2014-07-11 09:52:58 -04002493 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002494 {
Geoff Langda5777c2014-07-11 09:52:58 -04002495 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496 }
Geoff Langda5777c2014-07-11 09:52:58 -04002497 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498 {
Geoff Langda5777c2014-07-11 09:52:58 -04002499 GLenum error = *mErrors.begin();
2500 mErrors.erase(mErrors.begin());
2501 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503}
2504
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002505// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002506void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002507{
2508 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002509 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002510 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002511 mContextLostForced = true;
2512 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002513 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514}
2515
Jamie Madill427064d2018-04-13 16:20:34 -04002516bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002517{
2518 return mContextLost;
2519}
2520
Jamie Madillfa920eb2018-01-04 11:45:50 -05002521GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002522{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002523 // Even if the application doesn't want to know about resets, we want to know
2524 // as it will allow us to skip all the calls.
2525 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002526 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002527 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002528 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002529 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002530 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531
2532 // EXT_robustness, section 2.6: If the reset notification behavior is
2533 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2534 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2535 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002536 }
2537
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002538 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2539 // status should be returned at least once, and GL_NO_ERROR should be returned
2540 // once the device has finished resetting.
2541 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002542 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002543 ASSERT(mResetStatus == GL_NO_ERROR);
2544 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002545
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002546 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002547 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002548 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002549 }
2550 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002551 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002552 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002553 // If markContextLost was used to mark the context lost then
2554 // assume that is not recoverable, and continue to report the
2555 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002556 mResetStatus = mImplementation->getResetStatus();
2557 }
Jamie Madill893ab082014-05-16 16:56:10 -04002558
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002559 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002560}
2561
2562bool Context::isResetNotificationEnabled()
2563{
2564 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2565}
2566
Corentin Walleze3b10e82015-05-20 11:06:25 -04002567const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002568{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002569 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002570}
2571
2572EGLenum Context::getClientType() const
2573{
2574 return mClientType;
2575}
2576
2577EGLenum Context::getRenderBuffer() const
2578{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002579 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2580 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002581 {
2582 return EGL_NONE;
2583 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002584
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002585 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002586 ASSERT(backAttachment != nullptr);
2587 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002588}
2589
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002590VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002591{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002592 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002593 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2594 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002595 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002596 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2597 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002598
Jamie Madill96a483b2017-06-27 16:49:21 -04002599 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002600 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002601
2602 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002603}
2604
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002605TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002606{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002607 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002608 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2609 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002610 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002611 transformFeedback =
2612 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002613 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002614 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002615 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002616
2617 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002618}
2619
2620bool Context::isVertexArrayGenerated(GLuint vertexArray)
2621{
Jamie Madill96a483b2017-06-27 16:49:21 -04002622 ASSERT(mVertexArrayMap.contains(0));
2623 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002624}
2625
2626bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2627{
Jamie Madill96a483b2017-06-27 16:49:21 -04002628 ASSERT(mTransformFeedbackMap.contains(0));
2629 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002630}
2631
Shannon Woods53a94a82014-06-24 15:20:36 -04002632void Context::detachTexture(GLuint texture)
2633{
2634 // Simple pass-through to State's detachTexture method, as textures do not require
2635 // allocation map management either here or in the resource manager at detach time.
2636 // Zero textures are held by the Context, and we don't attempt to request them from
2637 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002638 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002639}
2640
James Darpinian4d9d4832018-03-13 12:43:28 -07002641void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642{
Yuly Novikov5807a532015-12-03 13:01:22 -05002643 // Simple pass-through to State's detachBuffer method, since
2644 // only buffer attachments to container objects that are bound to the current context
2645 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002646
Yuly Novikov5807a532015-12-03 13:01:22 -05002647 // [OpenGL ES 3.2] section 5.1.2 page 45:
2648 // Attachments to unbound container objects, such as
2649 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2650 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002651 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002652}
2653
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654void Context::detachFramebuffer(GLuint framebuffer)
2655{
Shannon Woods53a94a82014-06-24 15:20:36 -04002656 // Framebuffer detachment is handled by Context, because 0 is a valid
2657 // Framebuffer object, and a pointer to it must be passed from Context
2658 // to State at binding time.
2659
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002661 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2662 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2663 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002665 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
2667 bindReadFramebuffer(0);
2668 }
2669
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002670 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671 {
2672 bindDrawFramebuffer(0);
2673 }
2674}
2675
2676void Context::detachRenderbuffer(GLuint renderbuffer)
2677{
Jamie Madilla02315b2017-02-23 14:14:47 -05002678 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679}
2680
Jamie Madill57a89722013-07-02 11:57:03 -04002681void Context::detachVertexArray(GLuint vertexArray)
2682{
Jamie Madill77a72f62015-04-14 11:18:32 -04002683 // Vertex array detachment is handled by Context, because 0 is a valid
2684 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002685 // binding time.
2686
Jamie Madill57a89722013-07-02 11:57:03 -04002687 // [OpenGL ES 3.0.2] section 2.10 page 43:
2688 // If a vertex array object that is currently bound is deleted, the binding
2689 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002690 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002691 {
2692 bindVertexArray(0);
2693 }
2694}
2695
Geoff Langc8058452014-02-03 12:04:11 -05002696void Context::detachTransformFeedback(GLuint transformFeedback)
2697{
Corentin Walleza2257da2016-04-19 16:43:12 -04002698 // Transform feedback detachment is handled by Context, because 0 is a valid
2699 // transform feedback, and a pointer to it must be passed from Context to State at
2700 // binding time.
2701
2702 // The OpenGL specification doesn't mention what should happen when the currently bound
2703 // transform feedback object is deleted. Since it is a container object, we treat it like
2704 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002705 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002706 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002707 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002708 }
Geoff Langc8058452014-02-03 12:04:11 -05002709}
2710
Jamie Madilldc356042013-07-19 16:36:57 -04002711void Context::detachSampler(GLuint sampler)
2712{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002713 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002714}
2715
Yunchao Hea336b902017-08-02 16:05:21 +08002716void Context::detachProgramPipeline(GLuint pipeline)
2717{
2718 mGLState.detachProgramPipeline(this, pipeline);
2719}
2720
Jamie Madill3ef140a2017-08-26 23:11:21 -04002721void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002722{
Shaodde78e82017-05-22 14:13:27 +08002723 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002724}
2725
Jamie Madille29d1672013-07-19 16:36:57 -04002726void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2727{
Geoff Langc1984ed2016-10-07 12:41:00 -04002728 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002729 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002730 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002731 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002732}
Jamie Madille29d1672013-07-19 16:36:57 -04002733
Geoff Langc1984ed2016-10-07 12:41:00 -04002734void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2735{
2736 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002737 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002738 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002739 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002740}
2741
Brandon Jones59770802018-04-02 13:18:42 -07002742void Context::samplerParameterivRobust(GLuint sampler,
2743 GLenum pname,
2744 GLsizei bufSize,
2745 const GLint *param)
2746{
2747 samplerParameteriv(sampler, pname, param);
2748}
2749
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002750void Context::samplerParameterIivRobust(GLuint sampler,
2751 GLenum pname,
2752 GLsizei bufSize,
2753 const GLint *param)
2754{
2755 UNIMPLEMENTED();
2756}
2757
2758void Context::samplerParameterIuivRobust(GLuint sampler,
2759 GLenum pname,
2760 GLsizei bufSize,
2761 const GLuint *param)
2762{
2763 UNIMPLEMENTED();
2764}
2765
Jamie Madille29d1672013-07-19 16:36:57 -04002766void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2767{
Geoff Langc1984ed2016-10-07 12:41:00 -04002768 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002769 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002770 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002771 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002772}
2773
Geoff Langc1984ed2016-10-07 12:41:00 -04002774void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002775{
Geoff Langc1984ed2016-10-07 12:41:00 -04002776 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002777 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002778 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002779 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002780}
2781
Brandon Jones59770802018-04-02 13:18:42 -07002782void Context::samplerParameterfvRobust(GLuint sampler,
2783 GLenum pname,
2784 GLsizei bufSize,
2785 const GLfloat *param)
2786{
2787 samplerParameterfv(sampler, pname, param);
2788}
2789
Geoff Langc1984ed2016-10-07 12:41:00 -04002790void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002791{
Geoff Langc1984ed2016-10-07 12:41:00 -04002792 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002793 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002794 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002795 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002796}
Jamie Madill9675b802013-07-19 16:36:59 -04002797
Brandon Jones59770802018-04-02 13:18:42 -07002798void Context::getSamplerParameterivRobust(GLuint sampler,
2799 GLenum pname,
2800 GLsizei bufSize,
2801 GLsizei *length,
2802 GLint *params)
2803{
2804 getSamplerParameteriv(sampler, pname, params);
2805}
2806
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002807void Context::getSamplerParameterIivRobust(GLuint sampler,
2808 GLenum pname,
2809 GLsizei bufSize,
2810 GLsizei *length,
2811 GLint *params)
2812{
2813 UNIMPLEMENTED();
2814}
2815
2816void Context::getSamplerParameterIuivRobust(GLuint sampler,
2817 GLenum pname,
2818 GLsizei bufSize,
2819 GLsizei *length,
2820 GLuint *params)
2821{
2822 UNIMPLEMENTED();
2823}
2824
Geoff Langc1984ed2016-10-07 12:41:00 -04002825void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2826{
2827 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002828 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002829 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002830 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002831}
2832
Brandon Jones59770802018-04-02 13:18:42 -07002833void Context::getSamplerParameterfvRobust(GLuint sampler,
2834 GLenum pname,
2835 GLsizei bufSize,
2836 GLsizei *length,
2837 GLfloat *params)
2838{
2839 getSamplerParameterfv(sampler, pname, params);
2840}
2841
Olli Etuahof0fee072016-03-30 15:11:58 +03002842void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2843{
2844 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002845 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002846}
2847
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002848void Context::initRendererString()
2849{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002850 std::ostringstream rendererString;
2851 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002852 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002853 rendererString << ")";
2854
Geoff Langcec35902014-04-16 10:52:36 -04002855 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002856}
2857
Geoff Langc339c4e2016-11-29 10:37:36 -05002858void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002859{
Geoff Langc339c4e2016-11-29 10:37:36 -05002860 const Version &clientVersion = getClientVersion();
2861
2862 std::ostringstream versionString;
2863 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2864 << ANGLE_VERSION_STRING << ")";
2865 mVersionString = MakeStaticString(versionString.str());
2866
2867 std::ostringstream shadingLanguageVersionString;
2868 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2869 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2870 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2871 << ")";
2872 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002873}
2874
Geoff Langcec35902014-04-16 10:52:36 -04002875void Context::initExtensionStrings()
2876{
Geoff Langc339c4e2016-11-29 10:37:36 -05002877 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2878 std::ostringstream combinedStringStream;
2879 std::copy(strings.begin(), strings.end(),
2880 std::ostream_iterator<const char *>(combinedStringStream, " "));
2881 return MakeStaticString(combinedStringStream.str());
2882 };
2883
2884 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002885 for (const auto &extensionString : mExtensions.getStrings())
2886 {
2887 mExtensionStrings.push_back(MakeStaticString(extensionString));
2888 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002889 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002890
Geoff Langc339c4e2016-11-29 10:37:36 -05002891 mRequestableExtensionStrings.clear();
2892 for (const auto &extensionInfo : GetExtensionInfoMap())
2893 {
2894 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002895 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002896 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002897 {
2898 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2899 }
2900 }
2901 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002902}
2903
Geoff Langc339c4e2016-11-29 10:37:36 -05002904const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002905{
Geoff Langc339c4e2016-11-29 10:37:36 -05002906 switch (name)
2907 {
2908 case GL_VENDOR:
2909 return reinterpret_cast<const GLubyte *>("Google Inc.");
2910
2911 case GL_RENDERER:
2912 return reinterpret_cast<const GLubyte *>(mRendererString);
2913
2914 case GL_VERSION:
2915 return reinterpret_cast<const GLubyte *>(mVersionString);
2916
2917 case GL_SHADING_LANGUAGE_VERSION:
2918 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2919
2920 case GL_EXTENSIONS:
2921 return reinterpret_cast<const GLubyte *>(mExtensionString);
2922
2923 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2924 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2925
2926 default:
2927 UNREACHABLE();
2928 return nullptr;
2929 }
Geoff Langcec35902014-04-16 10:52:36 -04002930}
2931
Geoff Langc339c4e2016-11-29 10:37:36 -05002932const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002933{
Geoff Langc339c4e2016-11-29 10:37:36 -05002934 switch (name)
2935 {
2936 case GL_EXTENSIONS:
2937 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2938
2939 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2940 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2941
2942 default:
2943 UNREACHABLE();
2944 return nullptr;
2945 }
Geoff Langcec35902014-04-16 10:52:36 -04002946}
2947
2948size_t Context::getExtensionStringCount() const
2949{
2950 return mExtensionStrings.size();
2951}
2952
Geoff Lang111a99e2017-10-17 10:58:41 -04002953bool Context::isExtensionRequestable(const char *name)
2954{
2955 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2956 auto extension = extensionInfos.find(name);
2957
Geoff Lang111a99e2017-10-17 10:58:41 -04002958 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002959 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002960}
2961
Geoff Langc339c4e2016-11-29 10:37:36 -05002962void Context::requestExtension(const char *name)
2963{
2964 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2965 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2966 const auto &extension = extensionInfos.at(name);
2967 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002968 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002969
2970 if (mExtensions.*(extension.ExtensionsMember))
2971 {
2972 // Extension already enabled
2973 return;
2974 }
2975
2976 mExtensions.*(extension.ExtensionsMember) = true;
2977 updateCaps();
2978 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002979
Jamie Madill2f348d22017-06-05 10:50:59 -04002980 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2981 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002982
Jamie Madill81c2e252017-09-09 23:32:46 -04002983 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2984 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002985 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002986 for (auto &zeroTexture : mZeroTextures)
2987 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002988 if (zeroTexture.get() != nullptr)
2989 {
2990 zeroTexture->signalDirty(this, InitState::Initialized);
2991 }
Geoff Lang9aded172017-04-05 11:07:56 -04002992 }
2993
2994 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002995}
2996
2997size_t Context::getRequestableExtensionStringCount() const
2998{
2999 return mRequestableExtensionStrings.size();
3000}
3001
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003002void Context::beginTransformFeedback(GLenum primitiveMode)
3003{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003004 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003005 ASSERT(transformFeedback != nullptr);
3006 ASSERT(!transformFeedback->isPaused());
3007
Jamie Madill6c1f6712017-02-14 19:08:04 -05003008 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003009}
3010
3011bool Context::hasActiveTransformFeedback(GLuint program) const
3012{
3013 for (auto pair : mTransformFeedbackMap)
3014 {
3015 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3016 {
3017 return true;
3018 }
3019 }
3020 return false;
3021}
3022
Geoff Langb0f917f2017-12-05 13:41:54 -05003023Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003024 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003025 bool robustResourceInit) const
3026{
3027 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3028
3029 if (getClientVersion() < ES_2_0)
3030 {
3031 // Default extensions for GLES1
3032 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003033 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003034 }
3035
3036 if (getClientVersion() < ES_3_0)
3037 {
3038 // Disable ES3+ extensions
3039 supportedExtensions.colorBufferFloat = false;
3040 supportedExtensions.eglImageExternalEssl3 = false;
3041 supportedExtensions.textureNorm16 = false;
3042 supportedExtensions.multiview = false;
3043 supportedExtensions.maxViews = 1u;
3044 }
3045
3046 if (getClientVersion() < ES_3_1)
3047 {
3048 // Disable ES3.1+ extensions
3049 supportedExtensions.geometryShader = false;
3050 }
3051
3052 if (getClientVersion() > ES_2_0)
3053 {
3054 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3055 // supportedExtensions.sRGB = false;
3056 }
3057
3058 // Some extensions are always available because they are implemented in the GL layer.
3059 supportedExtensions.bindUniformLocation = true;
3060 supportedExtensions.vertexArrayObject = true;
3061 supportedExtensions.bindGeneratesResource = true;
3062 supportedExtensions.clientArrays = true;
3063 supportedExtensions.requestExtension = true;
3064
3065 // Enable the no error extension if the context was created with the flag.
3066 supportedExtensions.noError = mSkipValidation;
3067
3068 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3069 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3070
3071 // Explicitly enable GL_KHR_debug
3072 supportedExtensions.debug = true;
3073 supportedExtensions.maxDebugMessageLength = 1024;
3074 supportedExtensions.maxDebugLoggedMessages = 1024;
3075 supportedExtensions.maxDebugGroupStackDepth = 1024;
3076 supportedExtensions.maxLabelLength = 1024;
3077
3078 // Explicitly enable GL_ANGLE_robust_client_memory
3079 supportedExtensions.robustClientMemory = true;
3080
3081 // Determine robust resource init availability from EGL.
3082 supportedExtensions.robustResourceInitialization = robustResourceInit;
3083
3084 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3085 // supports it.
3086 supportedExtensions.robustBufferAccessBehavior =
3087 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3088
3089 // Enable the cache control query unconditionally.
3090 supportedExtensions.programCacheControl = true;
3091
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003092 // Enable EGL_ANGLE_explicit_context subextensions
3093 if (clientExtensions.explicitContext)
3094 {
3095 // GL_ANGLE_explicit_context_gles1
3096 supportedExtensions.explicitContextGles1 = true;
3097 // GL_ANGLE_explicit_context
3098 supportedExtensions.explicitContext = true;
3099 }
3100
Geoff Langb0f917f2017-12-05 13:41:54 -05003101 return supportedExtensions;
3102}
3103
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003104void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3105 const egl::ClientExtensions &clientExtensions,
3106 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003107{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003108 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003109
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003110 mSupportedExtensions =
3111 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Geoff Langb0f917f2017-12-05 13:41:54 -05003112 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003113
3114 mLimitations = mImplementation->getNativeLimitations();
3115
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003116 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3117 if (getClientVersion() < Version(2, 0))
3118 {
3119 mCaps.maxMultitextureUnits = 4;
3120 mCaps.maxClipPlanes = 6;
3121 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003122 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3123 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3124 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003125 }
3126
Geoff Lang301d1612014-07-09 10:34:37 -04003127 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003128 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003129
Jamie Madill0f80ed82017-09-19 00:24:56 -04003130 if (getClientVersion() < ES_3_1)
3131 {
3132 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3133 }
3134 else
3135 {
3136 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3137 }
Geoff Lang301d1612014-07-09 10:34:37 -04003138
Jiawei Shao54aafe52018-04-27 14:54:57 +08003139 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3140 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003141 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3142 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3143
3144 // Limit textures as well, so we can use fast bitsets with texture bindings.
3145 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003146 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3147 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3148 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3149 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003150
Jiawei Shaodb342272017-09-27 10:21:45 +08003151 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3152
Geoff Langc287ea62016-09-16 14:46:51 -04003153 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003154 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003155 for (const auto &extensionInfo : GetExtensionInfoMap())
3156 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003157 // If the user has requested that extensions start disabled and they are requestable,
3158 // disable them.
3159 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003160 {
3161 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3162 }
3163 }
3164
3165 // Generate texture caps
3166 updateCaps();
3167}
3168
3169void Context::updateCaps()
3170{
Geoff Lang900013c2014-07-07 11:32:19 -04003171 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003172 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003173
Jamie Madill7b62cf92017-11-02 15:20:49 -04003174 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003175 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003176 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003177 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003178
Geoff Lang0d8b7242015-09-09 14:56:53 -04003179 // Update the format caps based on the client version and extensions.
3180 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3181 // ES3.
3182 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003183 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003184 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003185 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003186 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003187 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003188
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003189 // OpenGL ES does not support multisampling with non-rendererable formats
3190 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003191 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003192 (getClientVersion() < ES_3_1 &&
3193 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003194 {
Geoff Langd87878e2014-09-19 15:42:59 -04003195 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003196 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003197 else
3198 {
3199 // We may have limited the max samples for some required renderbuffer formats due to
3200 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3201 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3202
3203 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3204 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3205 // exception of signed and unsigned integer formats."
3206 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3207 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3208 {
3209 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3210 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3211 }
3212
3213 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3214 if (getClientVersion() >= ES_3_1)
3215 {
3216 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3217 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3218 // the exception that the signed and unsigned integer formats are required only to
3219 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3220 // multisamples, which must be at least one."
3221 if (formatInfo.componentType == GL_INT ||
3222 formatInfo.componentType == GL_UNSIGNED_INT)
3223 {
3224 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3225 }
3226
3227 // GLES 3.1 section 19.3.1.
3228 if (formatCaps.texturable)
3229 {
3230 if (formatInfo.depthBits > 0)
3231 {
3232 mCaps.maxDepthTextureSamples =
3233 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3234 }
3235 else if (formatInfo.redBits > 0)
3236 {
3237 mCaps.maxColorTextureSamples =
3238 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3239 }
3240 }
3241 }
3242 }
Geoff Langd87878e2014-09-19 15:42:59 -04003243
3244 if (formatCaps.texturable && formatInfo.compressed)
3245 {
Geoff Langca271392017-04-05 12:30:00 -04003246 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003247 }
3248
Geoff Langca271392017-04-05 12:30:00 -04003249 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003250 }
Jamie Madill32447362017-06-28 14:53:52 -04003251
3252 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003253 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003254 {
3255 mMemoryProgramCache = nullptr;
3256 }
Corentin Walleze4477002017-12-01 14:39:58 -05003257
3258 // Compute which buffer types are allowed
3259 mValidBufferBindings.reset();
3260 mValidBufferBindings.set(BufferBinding::ElementArray);
3261 mValidBufferBindings.set(BufferBinding::Array);
3262
3263 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3264 {
3265 mValidBufferBindings.set(BufferBinding::PixelPack);
3266 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3267 }
3268
3269 if (getClientVersion() >= ES_3_0)
3270 {
3271 mValidBufferBindings.set(BufferBinding::CopyRead);
3272 mValidBufferBindings.set(BufferBinding::CopyWrite);
3273 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3274 mValidBufferBindings.set(BufferBinding::Uniform);
3275 }
3276
3277 if (getClientVersion() >= ES_3_1)
3278 {
3279 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3280 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3281 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3282 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3283 }
Geoff Lang493daf52014-07-03 13:38:44 -04003284}
3285
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003286void Context::initWorkarounds()
3287{
Jamie Madill761b02c2017-06-23 16:27:06 -04003288 // Apply back-end workarounds.
3289 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3290
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003291 // Lose the context upon out of memory error if the application is
3292 // expecting to watch for those events.
3293 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3294}
3295
Jamie Madill05b35b22017-10-03 09:01:44 -04003296Error Context::prepareForDraw()
3297{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003298 if (mGLES1Renderer)
3299 {
3300 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3301 }
3302
Geoff Langa8cb2872018-03-09 16:09:40 -05003303 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003304
3305 if (isRobustResourceInitEnabled())
3306 {
3307 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3308 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3309 }
3310
Geoff Langa8cb2872018-03-09 16:09:40 -05003311 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003312 return NoError();
3313}
3314
3315Error Context::prepareForClear(GLbitfield mask)
3316{
Geoff Langa8cb2872018-03-09 16:09:40 -05003317 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003318 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003319 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003320 return NoError();
3321}
3322
3323Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3324{
Geoff Langa8cb2872018-03-09 16:09:40 -05003325 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003326 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3327 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003328 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003329 return NoError();
3330}
3331
Geoff Langa8cb2872018-03-09 16:09:40 -05003332Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003333{
Geoff Langa8cb2872018-03-09 16:09:40 -05003334 ANGLE_TRY(syncDirtyObjects());
3335 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003336 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003337}
3338
Geoff Langa8cb2872018-03-09 16:09:40 -05003339Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003340{
Geoff Langa8cb2872018-03-09 16:09:40 -05003341 ANGLE_TRY(syncDirtyObjects(objectMask));
3342 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003343 return NoError();
3344}
3345
Geoff Langa8cb2872018-03-09 16:09:40 -05003346Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003347{
3348 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3349 mImplementation->syncState(this, dirtyBits);
3350 mGLState.clearDirtyBits();
3351 return NoError();
3352}
3353
Geoff Langa8cb2872018-03-09 16:09:40 -05003354Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003355{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003356 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003357 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003358 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003359 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003360}
Jamie Madillc29968b2016-01-20 11:17:23 -05003361
Geoff Langa8cb2872018-03-09 16:09:40 -05003362Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003363{
3364 return mGLState.syncDirtyObjects(this);
3365}
3366
Geoff Langa8cb2872018-03-09 16:09:40 -05003367Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003368{
3369 return mGLState.syncDirtyObjects(this, objectMask);
3370}
3371
Jamie Madillc29968b2016-01-20 11:17:23 -05003372void Context::blitFramebuffer(GLint srcX0,
3373 GLint srcY0,
3374 GLint srcX1,
3375 GLint srcY1,
3376 GLint dstX0,
3377 GLint dstY0,
3378 GLint dstX1,
3379 GLint dstY1,
3380 GLbitfield mask,
3381 GLenum filter)
3382{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003383 if (mask == 0)
3384 {
3385 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3386 // buffers are copied.
3387 return;
3388 }
3389
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003390 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003391 ASSERT(drawFramebuffer);
3392
3393 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3394 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3395
Jamie Madillbc918e72018-03-08 09:47:21 -05003396 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003397
Jamie Madillc564c072017-06-01 12:45:42 -04003398 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003399}
Jamie Madillc29968b2016-01-20 11:17:23 -05003400
3401void Context::clear(GLbitfield mask)
3402{
Geoff Langd4fff502017-09-22 11:28:28 -04003403 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3404 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003405}
3406
3407void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3408{
Geoff Langd4fff502017-09-22 11:28:28 -04003409 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3410 ANGLE_CONTEXT_TRY(
3411 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003412}
3413
3414void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3415{
Geoff Langd4fff502017-09-22 11:28:28 -04003416 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3417 ANGLE_CONTEXT_TRY(
3418 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003419}
3420
3421void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3422{
Geoff Langd4fff502017-09-22 11:28:28 -04003423 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3424 ANGLE_CONTEXT_TRY(
3425 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003426}
3427
3428void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003430 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003431 ASSERT(framebufferObject);
3432
3433 // If a buffer is not present, the clear has no effect
3434 if (framebufferObject->getDepthbuffer() == nullptr &&
3435 framebufferObject->getStencilbuffer() == nullptr)
3436 {
3437 return;
3438 }
3439
Geoff Langd4fff502017-09-22 11:28:28 -04003440 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3441 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003442}
3443
3444void Context::readPixels(GLint x,
3445 GLint y,
3446 GLsizei width,
3447 GLsizei height,
3448 GLenum format,
3449 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003450 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003451{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003452 if (width == 0 || height == 0)
3453 {
3454 return;
3455 }
3456
Jamie Madillbc918e72018-03-08 09:47:21 -05003457 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003458
Jamie Madillb6664922017-07-25 12:55:04 -04003459 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3460 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003461
3462 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003463 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003464}
3465
Brandon Jones59770802018-04-02 13:18:42 -07003466void Context::readPixelsRobust(GLint x,
3467 GLint y,
3468 GLsizei width,
3469 GLsizei height,
3470 GLenum format,
3471 GLenum type,
3472 GLsizei bufSize,
3473 GLsizei *length,
3474 GLsizei *columns,
3475 GLsizei *rows,
3476 void *pixels)
3477{
3478 readPixels(x, y, width, height, format, type, pixels);
3479}
3480
3481void Context::readnPixelsRobust(GLint x,
3482 GLint y,
3483 GLsizei width,
3484 GLsizei height,
3485 GLenum format,
3486 GLenum type,
3487 GLsizei bufSize,
3488 GLsizei *length,
3489 GLsizei *columns,
3490 GLsizei *rows,
3491 void *data)
3492{
3493 readPixels(x, y, width, height, format, type, data);
3494}
3495
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003496void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003497 GLint level,
3498 GLenum internalformat,
3499 GLint x,
3500 GLint y,
3501 GLsizei width,
3502 GLsizei height,
3503 GLint border)
3504{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003505 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003506 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003507
Jamie Madillc29968b2016-01-20 11:17:23 -05003508 Rectangle sourceArea(x, y, width, height);
3509
Jamie Madill05b35b22017-10-03 09:01:44 -04003510 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003511 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003512 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003513}
3514
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003515void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003516 GLint level,
3517 GLint xoffset,
3518 GLint yoffset,
3519 GLint x,
3520 GLint y,
3521 GLsizei width,
3522 GLsizei height)
3523{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003524 if (width == 0 || height == 0)
3525 {
3526 return;
3527 }
3528
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003529 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003530 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003531
Jamie Madillc29968b2016-01-20 11:17:23 -05003532 Offset destOffset(xoffset, yoffset, 0);
3533 Rectangle sourceArea(x, y, width, height);
3534
Jamie Madill05b35b22017-10-03 09:01:44 -04003535 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003536 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003537 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003538}
3539
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003540void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003541 GLint level,
3542 GLint xoffset,
3543 GLint yoffset,
3544 GLint zoffset,
3545 GLint x,
3546 GLint y,
3547 GLsizei width,
3548 GLsizei height)
3549{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003550 if (width == 0 || height == 0)
3551 {
3552 return;
3553 }
3554
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003555 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003556 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003557
Jamie Madillc29968b2016-01-20 11:17:23 -05003558 Offset destOffset(xoffset, yoffset, zoffset);
3559 Rectangle sourceArea(x, y, width, height);
3560
Jamie Madill05b35b22017-10-03 09:01:44 -04003561 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3562 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003563 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3564 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003565}
3566
3567void Context::framebufferTexture2D(GLenum target,
3568 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003569 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003570 GLuint texture,
3571 GLint level)
3572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003574 ASSERT(framebuffer);
3575
3576 if (texture != 0)
3577 {
3578 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003579 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003580 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003581 }
3582 else
3583 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003584 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003585 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003586
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003588}
3589
3590void Context::framebufferRenderbuffer(GLenum target,
3591 GLenum attachment,
3592 GLenum renderbuffertarget,
3593 GLuint renderbuffer)
3594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 ASSERT(framebuffer);
3597
3598 if (renderbuffer != 0)
3599 {
3600 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003601
Jamie Madillcc129372018-04-12 09:13:18 -04003602 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003603 renderbufferObject);
3604 }
3605 else
3606 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003607 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003609
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003611}
3612
3613void Context::framebufferTextureLayer(GLenum target,
3614 GLenum attachment,
3615 GLuint texture,
3616 GLint level,
3617 GLint layer)
3618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003619 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003620 ASSERT(framebuffer);
3621
3622 if (texture != 0)
3623 {
3624 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003625 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003626 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003627 }
3628 else
3629 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003630 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003631 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003632
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003634}
3635
Brandon Jones59770802018-04-02 13:18:42 -07003636void Context::framebufferTextureMultiviewLayered(GLenum target,
3637 GLenum attachment,
3638 GLuint texture,
3639 GLint level,
3640 GLint baseViewIndex,
3641 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003642{
Martin Radev82ef7742017-08-08 17:44:58 +03003643 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3644 ASSERT(framebuffer);
3645
3646 if (texture != 0)
3647 {
3648 Texture *textureObj = getTexture(texture);
3649
Martin Radev18b75ba2017-08-15 15:50:40 +03003650 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003651 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3652 numViews, baseViewIndex);
3653 }
3654 else
3655 {
3656 framebuffer->resetAttachment(this, attachment);
3657 }
3658
3659 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003660}
3661
Brandon Jones59770802018-04-02 13:18:42 -07003662void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3663 GLenum attachment,
3664 GLuint texture,
3665 GLint level,
3666 GLsizei numViews,
3667 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003668{
Martin Radev5dae57b2017-07-14 16:15:55 +03003669 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3670 ASSERT(framebuffer);
3671
3672 if (texture != 0)
3673 {
3674 Texture *textureObj = getTexture(texture);
3675
3676 ImageIndex index = ImageIndex::Make2D(level);
3677 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3678 textureObj, numViews, viewportOffsets);
3679 }
3680 else
3681 {
3682 framebuffer->resetAttachment(this, attachment);
3683 }
3684
3685 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003686}
3687
Jamie Madillc29968b2016-01-20 11:17:23 -05003688void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003691 ASSERT(framebuffer);
3692 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003693 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003694}
3695
3696void Context::readBuffer(GLenum mode)
3697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003699 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003701}
3702
3703void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3704{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003705 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003706 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003707
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 ASSERT(framebuffer);
3710
3711 // The specification isn't clear what should be done when the framebuffer isn't complete.
3712 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003713 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003714}
3715
3716void Context::invalidateFramebuffer(GLenum target,
3717 GLsizei numAttachments,
3718 const GLenum *attachments)
3719{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003720 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003721 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003722
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003724 ASSERT(framebuffer);
3725
Jamie Madill427064d2018-04-13 16:20:34 -04003726 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003727 {
Jamie Madill437fa652016-05-03 15:13:24 -04003728 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 }
Jamie Madill437fa652016-05-03 15:13:24 -04003730
Jamie Madill4928b7c2017-06-20 12:57:39 -04003731 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003732}
3733
3734void Context::invalidateSubFramebuffer(GLenum target,
3735 GLsizei numAttachments,
3736 const GLenum *attachments,
3737 GLint x,
3738 GLint y,
3739 GLsizei width,
3740 GLsizei height)
3741{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003742 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003743 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003744
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 ASSERT(framebuffer);
3747
Jamie Madill427064d2018-04-13 16:20:34 -04003748 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 {
Jamie Madill437fa652016-05-03 15:13:24 -04003750 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 }
Jamie Madill437fa652016-05-03 15:13:24 -04003752
3753 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003754 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003755}
3756
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003757void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003758 GLint level,
3759 GLint internalformat,
3760 GLsizei width,
3761 GLsizei height,
3762 GLint border,
3763 GLenum format,
3764 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003765 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003766{
Jamie Madillbc918e72018-03-08 09:47:21 -05003767 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003768
3769 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003770 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003771 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3772 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003773}
3774
Brandon Jones59770802018-04-02 13:18:42 -07003775void Context::texImage2DRobust(TextureTarget target,
3776 GLint level,
3777 GLint internalformat,
3778 GLsizei width,
3779 GLsizei height,
3780 GLint border,
3781 GLenum format,
3782 GLenum type,
3783 GLsizei bufSize,
3784 const void *pixels)
3785{
3786 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3787}
3788
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003789void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003790 GLint level,
3791 GLint internalformat,
3792 GLsizei width,
3793 GLsizei height,
3794 GLsizei depth,
3795 GLint border,
3796 GLenum format,
3797 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003798 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003799{
Jamie Madillbc918e72018-03-08 09:47:21 -05003800 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003801
3802 Extents size(width, height, depth);
3803 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003804 handleError(texture->setImage(this, mGLState.getUnpackState(),
3805 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3806 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003807}
3808
Brandon Jones59770802018-04-02 13:18:42 -07003809void Context::texImage3DRobust(TextureType target,
3810 GLint level,
3811 GLint internalformat,
3812 GLsizei width,
3813 GLsizei height,
3814 GLsizei depth,
3815 GLint border,
3816 GLenum format,
3817 GLenum type,
3818 GLsizei bufSize,
3819 const void *pixels)
3820{
3821 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3822}
3823
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003824void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003825 GLint level,
3826 GLint xoffset,
3827 GLint yoffset,
3828 GLsizei width,
3829 GLsizei height,
3830 GLenum format,
3831 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003832 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003833{
3834 // Zero sized uploads are valid but no-ops
3835 if (width == 0 || height == 0)
3836 {
3837 return;
3838 }
3839
Jamie Madillbc918e72018-03-08 09:47:21 -05003840 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003841
3842 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003843 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003844 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3845 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003846}
3847
Brandon Jones59770802018-04-02 13:18:42 -07003848void Context::texSubImage2DRobust(TextureTarget target,
3849 GLint level,
3850 GLint xoffset,
3851 GLint yoffset,
3852 GLsizei width,
3853 GLsizei height,
3854 GLenum format,
3855 GLenum type,
3856 GLsizei bufSize,
3857 const void *pixels)
3858{
3859 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3860}
3861
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003862void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003863 GLint level,
3864 GLint xoffset,
3865 GLint yoffset,
3866 GLint zoffset,
3867 GLsizei width,
3868 GLsizei height,
3869 GLsizei depth,
3870 GLenum format,
3871 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003872 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003873{
3874 // Zero sized uploads are valid but no-ops
3875 if (width == 0 || height == 0 || depth == 0)
3876 {
3877 return;
3878 }
3879
Jamie Madillbc918e72018-03-08 09:47:21 -05003880 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003881
3882 Box area(xoffset, yoffset, zoffset, width, height, depth);
3883 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003884 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3885 NonCubeTextureTypeToTarget(target), level, area, format, type,
3886 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003887}
3888
Brandon Jones59770802018-04-02 13:18:42 -07003889void Context::texSubImage3DRobust(TextureType target,
3890 GLint level,
3891 GLint xoffset,
3892 GLint yoffset,
3893 GLint zoffset,
3894 GLsizei width,
3895 GLsizei height,
3896 GLsizei depth,
3897 GLenum format,
3898 GLenum type,
3899 GLsizei bufSize,
3900 const void *pixels)
3901{
3902 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3903 pixels);
3904}
3905
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003906void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003907 GLint level,
3908 GLenum internalformat,
3909 GLsizei width,
3910 GLsizei height,
3911 GLint border,
3912 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003913 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003914{
Jamie Madillbc918e72018-03-08 09:47:21 -05003915 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003916
3917 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003918 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003919 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3920 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003921 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003922}
3923
Brandon Jones59770802018-04-02 13:18:42 -07003924void Context::compressedTexImage2DRobust(TextureTarget target,
3925 GLint level,
3926 GLenum internalformat,
3927 GLsizei width,
3928 GLsizei height,
3929 GLint border,
3930 GLsizei imageSize,
3931 GLsizei dataSize,
3932 const GLvoid *data)
3933{
3934 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3935}
3936
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003937void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003938 GLint level,
3939 GLenum internalformat,
3940 GLsizei width,
3941 GLsizei height,
3942 GLsizei depth,
3943 GLint border,
3944 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003945 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003946{
Jamie Madillbc918e72018-03-08 09:47:21 -05003947 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003948
3949 Extents size(width, height, depth);
3950 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003951 handleError(texture->setCompressedImage(
3952 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3953 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003954}
3955
Brandon Jones59770802018-04-02 13:18:42 -07003956void Context::compressedTexImage3DRobust(TextureType target,
3957 GLint level,
3958 GLenum internalformat,
3959 GLsizei width,
3960 GLsizei height,
3961 GLsizei depth,
3962 GLint border,
3963 GLsizei imageSize,
3964 GLsizei dataSize,
3965 const GLvoid *data)
3966{
3967 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3968 data);
3969}
3970
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003971void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003972 GLint level,
3973 GLint xoffset,
3974 GLint yoffset,
3975 GLsizei width,
3976 GLsizei height,
3977 GLenum format,
3978 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003979 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003980{
Jamie Madillbc918e72018-03-08 09:47:21 -05003981 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003982
3983 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003984 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003985 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3986 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003987 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003988}
3989
Brandon Jones59770802018-04-02 13:18:42 -07003990void Context::compressedTexSubImage2DRobust(TextureTarget target,
3991 GLint level,
3992 GLint xoffset,
3993 GLint yoffset,
3994 GLsizei width,
3995 GLsizei height,
3996 GLenum format,
3997 GLsizei imageSize,
3998 GLsizei dataSize,
3999 const GLvoid *data)
4000{
4001 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4002 data);
4003}
4004
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004005void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004006 GLint level,
4007 GLint xoffset,
4008 GLint yoffset,
4009 GLint zoffset,
4010 GLsizei width,
4011 GLsizei height,
4012 GLsizei depth,
4013 GLenum format,
4014 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004015 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004016{
4017 // Zero sized uploads are valid but no-ops
4018 if (width == 0 || height == 0)
4019 {
4020 return;
4021 }
4022
Jamie Madillbc918e72018-03-08 09:47:21 -05004023 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004024
4025 Box area(xoffset, yoffset, zoffset, width, height, depth);
4026 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004027 handleError(texture->setCompressedSubImage(
4028 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4029 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004030}
4031
Brandon Jones59770802018-04-02 13:18:42 -07004032void Context::compressedTexSubImage3DRobust(TextureType target,
4033 GLint level,
4034 GLint xoffset,
4035 GLint yoffset,
4036 GLint zoffset,
4037 GLsizei width,
4038 GLsizei height,
4039 GLsizei depth,
4040 GLenum format,
4041 GLsizei imageSize,
4042 GLsizei dataSize,
4043 const GLvoid *data)
4044{
4045 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4046 imageSize, data);
4047}
4048
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004049void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004050{
4051 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004052 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004053}
4054
Jamie Madill007530e2017-12-28 14:27:04 -05004055void Context::copyTexture(GLuint sourceId,
4056 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004057 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004058 GLuint destId,
4059 GLint destLevel,
4060 GLint internalFormat,
4061 GLenum destType,
4062 GLboolean unpackFlipY,
4063 GLboolean unpackPremultiplyAlpha,
4064 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004065{
Jamie Madillbc918e72018-03-08 09:47:21 -05004066 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004067
4068 gl::Texture *sourceTexture = getTexture(sourceId);
4069 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004070 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4071 sourceLevel, ConvertToBool(unpackFlipY),
4072 ConvertToBool(unpackPremultiplyAlpha),
4073 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004074}
4075
Jamie Madill007530e2017-12-28 14:27:04 -05004076void Context::copySubTexture(GLuint sourceId,
4077 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004078 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004079 GLuint destId,
4080 GLint destLevel,
4081 GLint xoffset,
4082 GLint yoffset,
4083 GLint x,
4084 GLint y,
4085 GLsizei width,
4086 GLsizei height,
4087 GLboolean unpackFlipY,
4088 GLboolean unpackPremultiplyAlpha,
4089 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004090{
4091 // Zero sized copies are valid but no-ops
4092 if (width == 0 || height == 0)
4093 {
4094 return;
4095 }
4096
Jamie Madillbc918e72018-03-08 09:47:21 -05004097 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004098
4099 gl::Texture *sourceTexture = getTexture(sourceId);
4100 gl::Texture *destTexture = getTexture(destId);
4101 Offset offset(xoffset, yoffset, 0);
4102 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004103 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4104 ConvertToBool(unpackFlipY),
4105 ConvertToBool(unpackPremultiplyAlpha),
4106 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004107}
4108
Jamie Madill007530e2017-12-28 14:27:04 -05004109void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004110{
Jamie Madillbc918e72018-03-08 09:47:21 -05004111 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004112
4113 gl::Texture *sourceTexture = getTexture(sourceId);
4114 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004115 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004116}
4117
Corentin Wallez336129f2017-10-17 15:55:40 -04004118void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004119{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004120 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004121 ASSERT(buffer);
4122
Geoff Lang496c02d2016-10-20 11:38:11 -07004123 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004124}
4125
Brandon Jones59770802018-04-02 13:18:42 -07004126void Context::getBufferPointervRobust(BufferBinding target,
4127 GLenum pname,
4128 GLsizei bufSize,
4129 GLsizei *length,
4130 void **params)
4131{
4132 getBufferPointerv(target, pname, params);
4133}
4134
Corentin Wallez336129f2017-10-17 15:55:40 -04004135void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004136{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004137 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004138 ASSERT(buffer);
4139
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004140 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004141 if (error.isError())
4142 {
Jamie Madill437fa652016-05-03 15:13:24 -04004143 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004144 return nullptr;
4145 }
4146
4147 return buffer->getMapPointer();
4148}
4149
Corentin Wallez336129f2017-10-17 15:55:40 -04004150GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004151{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004152 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004153 ASSERT(buffer);
4154
4155 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004156 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004157 if (error.isError())
4158 {
Jamie Madill437fa652016-05-03 15:13:24 -04004159 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004160 return GL_FALSE;
4161 }
4162
4163 return result;
4164}
4165
Corentin Wallez336129f2017-10-17 15:55:40 -04004166void *Context::mapBufferRange(BufferBinding target,
4167 GLintptr offset,
4168 GLsizeiptr length,
4169 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004170{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004171 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004172 ASSERT(buffer);
4173
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004174 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004175 if (error.isError())
4176 {
Jamie Madill437fa652016-05-03 15:13:24 -04004177 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004178 return nullptr;
4179 }
4180
4181 return buffer->getMapPointer();
4182}
4183
Corentin Wallez336129f2017-10-17 15:55:40 -04004184void Context::flushMappedBufferRange(BufferBinding /*target*/,
4185 GLintptr /*offset*/,
4186 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004187{
4188 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4189}
4190
Jamie Madillbc918e72018-03-08 09:47:21 -05004191Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004192{
Geoff Langa8cb2872018-03-09 16:09:40 -05004193 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004194}
4195
Jamie Madillbc918e72018-03-08 09:47:21 -05004196Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004197{
Geoff Langa8cb2872018-03-09 16:09:40 -05004198 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004199}
4200
Jamie Madillbc918e72018-03-08 09:47:21 -05004201Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004202{
Geoff Langa8cb2872018-03-09 16:09:40 -05004203 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004204}
4205
Jiajia Qin5451d532017-11-16 17:16:34 +08004206void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4207{
4208 UNIMPLEMENTED();
4209}
4210
Jamie Madillc20ab272016-06-09 07:20:46 -07004211void Context::activeTexture(GLenum texture)
4212{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004213 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004214}
4215
Jamie Madill876429b2017-04-20 15:46:24 -04004216void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004217{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004218 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004219}
4220
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004221void Context::blendEquation(GLenum mode)
4222{
4223 mGLState.setBlendEquation(mode, mode);
4224}
4225
Jamie Madillc20ab272016-06-09 07:20:46 -07004226void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4227{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004228 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004229}
4230
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004231void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4232{
4233 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4234}
4235
Jamie Madillc20ab272016-06-09 07:20:46 -07004236void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4237{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004238 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004239}
4240
Jamie Madill876429b2017-04-20 15:46:24 -04004241void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004242{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004243 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004244}
4245
Jamie Madill876429b2017-04-20 15:46:24 -04004246void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
4251void Context::clearStencil(GLint s)
4252{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004253 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004254}
4255
4256void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4257{
Geoff Lang92019432017-11-20 13:09:34 -05004258 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4259 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004260}
4261
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004262void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
4267void Context::depthFunc(GLenum func)
4268{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270}
4271
4272void Context::depthMask(GLboolean flag)
4273{
Geoff Lang92019432017-11-20 13:09:34 -05004274 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004275}
4276
Jamie Madill876429b2017-04-20 15:46:24 -04004277void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004278{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004279 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004280}
4281
4282void Context::disable(GLenum cap)
4283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285}
4286
4287void Context::disableVertexAttribArray(GLuint index)
4288{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004289 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004290}
4291
4292void Context::enable(GLenum cap)
4293{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004294 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004295}
4296
4297void Context::enableVertexAttribArray(GLuint index)
4298{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300}
4301
4302void Context::frontFace(GLenum mode)
4303{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305}
4306
4307void Context::hint(GLenum target, GLenum mode)
4308{
4309 switch (target)
4310 {
4311 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004312 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004313 break;
4314
4315 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004316 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004317 break;
4318
4319 default:
4320 UNREACHABLE();
4321 return;
4322 }
4323}
4324
4325void Context::lineWidth(GLfloat width)
4326{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004327 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004328}
4329
4330void Context::pixelStorei(GLenum pname, GLint param)
4331{
4332 switch (pname)
4333 {
4334 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004335 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004336 break;
4337
4338 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340 break;
4341
4342 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344 break;
4345
4346 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004347 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349 break;
4350
4351 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004352 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354 break;
4355
4356 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004357 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359 break;
4360
4361 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004362 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364 break;
4365
4366 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004367 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369 break;
4370
4371 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004372 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374 break;
4375
4376 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004377 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379 break;
4380
4381 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004382 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004383 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004384 break;
4385
4386 default:
4387 UNREACHABLE();
4388 return;
4389 }
4390}
4391
4392void Context::polygonOffset(GLfloat factor, GLfloat units)
4393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
Jamie Madill876429b2017-04-20 15:46:24 -04004397void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004398{
Geoff Lang92019432017-11-20 13:09:34 -05004399 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
Jiawei Shaodb342272017-09-27 10:21:45 +08004402void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4403{
4404 mGLState.setSampleMaskParams(maskNumber, mask);
4405}
4406
Jamie Madillc20ab272016-06-09 07:20:46 -07004407void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4408{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004410}
4411
4412void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4413{
4414 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4415 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417 }
4418
4419 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4420 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422 }
4423}
4424
4425void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4426{
4427 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4428 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430 }
4431
4432 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4433 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004434 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004435 }
4436}
4437
4438void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4439{
4440 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4441 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 }
4444
4445 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4446 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448 }
4449}
4450
4451void Context::vertexAttrib1f(GLuint index, GLfloat x)
4452{
4453 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004454 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004455}
4456
4457void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4458{
4459 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461}
4462
4463void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4464{
4465 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4470{
4471 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004472 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004473}
4474
4475void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4476{
4477 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004478 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004479}
4480
4481void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4482{
4483 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485}
4486
4487void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4488{
4489 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004490 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004491}
4492
4493void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4494{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004495 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
4498void Context::vertexAttribPointer(GLuint index,
4499 GLint size,
4500 GLenum type,
4501 GLboolean normalized,
4502 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004503 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004504{
Corentin Wallez336129f2017-10-17 15:55:40 -04004505 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004506 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
Shao80957d92017-02-20 21:25:59 +08004509void Context::vertexAttribFormat(GLuint attribIndex,
4510 GLint size,
4511 GLenum type,
4512 GLboolean normalized,
4513 GLuint relativeOffset)
4514{
Geoff Lang92019432017-11-20 13:09:34 -05004515 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004516 relativeOffset);
4517}
4518
4519void Context::vertexAttribIFormat(GLuint attribIndex,
4520 GLint size,
4521 GLenum type,
4522 GLuint relativeOffset)
4523{
4524 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4525}
4526
4527void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4528{
Shaodde78e82017-05-22 14:13:27 +08004529 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004530}
4531
Jiajia Qin5451d532017-11-16 17:16:34 +08004532void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004533{
4534 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4535}
4536
Jamie Madillc20ab272016-06-09 07:20:46 -07004537void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4538{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004539 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004540}
4541
4542void Context::vertexAttribIPointer(GLuint index,
4543 GLint size,
4544 GLenum type,
4545 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004546 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004547{
Corentin Wallez336129f2017-10-17 15:55:40 -04004548 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4549 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550}
4551
4552void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4553{
4554 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556}
4557
4558void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4559{
4560 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004561 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562}
4563
4564void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572}
4573
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004574void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4575{
4576 const VertexAttribCurrentValueData &currentValues =
4577 getGLState().getVertexAttribCurrentValue(index);
4578 const VertexArray *vao = getGLState().getVertexArray();
4579 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4580 currentValues, pname, params);
4581}
4582
Brandon Jones59770802018-04-02 13:18:42 -07004583void Context::getVertexAttribivRobust(GLuint index,
4584 GLenum pname,
4585 GLsizei bufSize,
4586 GLsizei *length,
4587 GLint *params)
4588{
4589 getVertexAttribiv(index, pname, params);
4590}
4591
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004592void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4593{
4594 const VertexAttribCurrentValueData &currentValues =
4595 getGLState().getVertexAttribCurrentValue(index);
4596 const VertexArray *vao = getGLState().getVertexArray();
4597 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4598 currentValues, pname, params);
4599}
4600
Brandon Jones59770802018-04-02 13:18:42 -07004601void Context::getVertexAttribfvRobust(GLuint index,
4602 GLenum pname,
4603 GLsizei bufSize,
4604 GLsizei *length,
4605 GLfloat *params)
4606{
4607 getVertexAttribfv(index, pname, params);
4608}
4609
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004610void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4611{
4612 const VertexAttribCurrentValueData &currentValues =
4613 getGLState().getVertexAttribCurrentValue(index);
4614 const VertexArray *vao = getGLState().getVertexArray();
4615 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4616 currentValues, pname, params);
4617}
4618
Brandon Jones59770802018-04-02 13:18:42 -07004619void Context::getVertexAttribIivRobust(GLuint index,
4620 GLenum pname,
4621 GLsizei bufSize,
4622 GLsizei *length,
4623 GLint *params)
4624{
4625 getVertexAttribIiv(index, pname, params);
4626}
4627
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004628void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4629{
4630 const VertexAttribCurrentValueData &currentValues =
4631 getGLState().getVertexAttribCurrentValue(index);
4632 const VertexArray *vao = getGLState().getVertexArray();
4633 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4634 currentValues, pname, params);
4635}
4636
Brandon Jones59770802018-04-02 13:18:42 -07004637void Context::getVertexAttribIuivRobust(GLuint index,
4638 GLenum pname,
4639 GLsizei bufSize,
4640 GLsizei *length,
4641 GLuint *params)
4642{
4643 getVertexAttribIuiv(index, pname, params);
4644}
4645
Jamie Madill876429b2017-04-20 15:46:24 -04004646void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004647{
4648 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4649 QueryVertexAttribPointerv(attrib, pname, pointer);
4650}
4651
Brandon Jones59770802018-04-02 13:18:42 -07004652void Context::getVertexAttribPointervRobust(GLuint index,
4653 GLenum pname,
4654 GLsizei bufSize,
4655 GLsizei *length,
4656 void **pointer)
4657{
4658 getVertexAttribPointerv(index, pname, pointer);
4659}
4660
Jamie Madillc20ab272016-06-09 07:20:46 -07004661void Context::debugMessageControl(GLenum source,
4662 GLenum type,
4663 GLenum severity,
4664 GLsizei count,
4665 const GLuint *ids,
4666 GLboolean enabled)
4667{
4668 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004670 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004671}
4672
4673void Context::debugMessageInsert(GLenum source,
4674 GLenum type,
4675 GLuint id,
4676 GLenum severity,
4677 GLsizei length,
4678 const GLchar *buf)
4679{
4680 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4685{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004687}
4688
4689GLuint Context::getDebugMessageLog(GLuint count,
4690 GLsizei bufSize,
4691 GLenum *sources,
4692 GLenum *types,
4693 GLuint *ids,
4694 GLenum *severities,
4695 GLsizei *lengths,
4696 GLchar *messageLog)
4697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4699 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004700}
4701
4702void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4703{
4704 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004705 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004706 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004707}
4708
4709void Context::popDebugGroup()
4710{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004711 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004712 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004713}
4714
Corentin Wallez336129f2017-10-17 15:55:40 -04004715void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004716{
4717 Buffer *buffer = mGLState.getTargetBuffer(target);
4718 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004719 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004720}
4721
Corentin Wallez336129f2017-10-17 15:55:40 -04004722void Context::bufferSubData(BufferBinding target,
4723 GLintptr offset,
4724 GLsizeiptr size,
4725 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004726{
4727 if (data == nullptr)
4728 {
4729 return;
4730 }
4731
4732 Buffer *buffer = mGLState.getTargetBuffer(target);
4733 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004734 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004735}
4736
Jamie Madillef300b12016-10-07 15:12:09 -04004737void Context::attachShader(GLuint program, GLuint shader)
4738{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004739 Program *programObject = mState.mShaderPrograms->getProgram(program);
4740 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004741 ASSERT(programObject && shaderObject);
4742 programObject->attachShader(shaderObject);
4743}
4744
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004745const Workarounds &Context::getWorkarounds() const
4746{
4747 return mWorkarounds;
4748}
4749
Corentin Wallez336129f2017-10-17 15:55:40 -04004750void Context::copyBufferSubData(BufferBinding readTarget,
4751 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004752 GLintptr readOffset,
4753 GLintptr writeOffset,
4754 GLsizeiptr size)
4755{
4756 // if size is zero, the copy is a successful no-op
4757 if (size == 0)
4758 {
4759 return;
4760 }
4761
4762 // TODO(jmadill): cache these.
4763 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4764 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4765
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004766 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004767}
4768
Jamie Madill01a80ee2016-11-07 12:06:18 -05004769void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4770{
4771 Program *programObject = getProgram(program);
4772 // TODO(jmadill): Re-use this from the validation if possible.
4773 ASSERT(programObject);
4774 programObject->bindAttributeLocation(index, name);
4775}
4776
Corentin Wallez336129f2017-10-17 15:55:40 -04004777void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004778{
Corentin Wallez336129f2017-10-17 15:55:40 -04004779 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4780 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004781}
4782
Corentin Wallez336129f2017-10-17 15:55:40 -04004783void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004784{
4785 bindBufferRange(target, index, buffer, 0, 0);
4786}
4787
Corentin Wallez336129f2017-10-17 15:55:40 -04004788void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004789 GLuint index,
4790 GLuint buffer,
4791 GLintptr offset,
4792 GLsizeiptr size)
4793{
Corentin Wallez336129f2017-10-17 15:55:40 -04004794 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4795 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004796}
4797
Jamie Madill01a80ee2016-11-07 12:06:18 -05004798void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4799{
4800 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4801 {
4802 bindReadFramebuffer(framebuffer);
4803 }
4804
4805 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4806 {
4807 bindDrawFramebuffer(framebuffer);
4808 }
4809}
4810
4811void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4812{
4813 ASSERT(target == GL_RENDERBUFFER);
4814 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004815 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004816 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004817}
4818
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004819void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004820 GLsizei samples,
4821 GLenum internalformat,
4822 GLsizei width,
4823 GLsizei height,
4824 GLboolean fixedsamplelocations)
4825{
4826 Extents size(width, height, 1);
4827 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004828 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4829 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004830}
4831
4832void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4833{
JiangYizhou5b03f472017-01-09 10:22:53 +08004834 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4835 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004836 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004837 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004838
4839 switch (pname)
4840 {
4841 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004842 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004843 break;
4844 default:
4845 UNREACHABLE();
4846 }
4847}
4848
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004849void Context::getMultisamplefvRobust(GLenum pname,
4850 GLuint index,
4851 GLsizei bufSize,
4852 GLsizei *length,
4853 GLfloat *val)
4854{
4855 UNIMPLEMENTED();
4856}
4857
Jamie Madille8fb6402017-02-14 17:56:40 -05004858void Context::renderbufferStorage(GLenum target,
4859 GLenum internalformat,
4860 GLsizei width,
4861 GLsizei height)
4862{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004863 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4864 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4865
Jamie Madille8fb6402017-02-14 17:56:40 -05004866 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004867 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004868}
4869
4870void Context::renderbufferStorageMultisample(GLenum target,
4871 GLsizei samples,
4872 GLenum internalformat,
4873 GLsizei width,
4874 GLsizei height)
4875{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004876 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4877 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004878
4879 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004880 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004881 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004882}
4883
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004884void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4885{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004886 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004887 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004888}
4889
JiangYizhoue18e6392017-02-20 10:32:23 +08004890void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4891{
4892 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4893 QueryFramebufferParameteriv(framebuffer, pname, params);
4894}
4895
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004896void Context::getFramebufferParameterivRobust(GLenum target,
4897 GLenum pname,
4898 GLsizei bufSize,
4899 GLsizei *length,
4900 GLint *params)
4901{
4902 UNIMPLEMENTED();
4903}
4904
Jiajia Qin5451d532017-11-16 17:16:34 +08004905void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004906{
4907 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4908 SetFramebufferParameteri(framebuffer, pname, param);
4909}
4910
Jamie Madillb3f26b92017-07-19 15:07:41 -04004911Error Context::getScratchBuffer(size_t requstedSizeBytes,
4912 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004913{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004914 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4915 {
4916 return OutOfMemory() << "Failed to allocate internal buffer.";
4917 }
4918 return NoError();
4919}
4920
4921Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4922 angle::MemoryBuffer **zeroBufferOut) const
4923{
4924 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004925 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004926 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004927 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004928 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004929}
4930
Xinghua Cao10a4d432017-11-28 14:46:26 +08004931Error Context::prepareForDispatch()
4932{
Geoff Langa8cb2872018-03-09 16:09:40 -05004933 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004934
4935 if (isRobustResourceInitEnabled())
4936 {
4937 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4938 }
4939
4940 return NoError();
4941}
4942
Xinghua Cao2b396592017-03-29 15:36:04 +08004943void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4944{
4945 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4946 {
4947 return;
4948 }
4949
Xinghua Cao10a4d432017-11-28 14:46:26 +08004950 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004951 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004952}
4953
Jiajia Qin5451d532017-11-16 17:16:34 +08004954void Context::dispatchComputeIndirect(GLintptr indirect)
4955{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004956 ANGLE_CONTEXT_TRY(prepareForDispatch());
4957 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004958}
4959
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004960void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004961 GLsizei levels,
4962 GLenum internalFormat,
4963 GLsizei width,
4964 GLsizei height)
4965{
4966 Extents size(width, height, 1);
4967 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004968 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004969}
4970
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004971void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004972 GLsizei levels,
4973 GLenum internalFormat,
4974 GLsizei width,
4975 GLsizei height,
4976 GLsizei depth)
4977{
4978 Extents size(width, height, depth);
4979 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004980 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004981}
4982
Jiajia Qin5451d532017-11-16 17:16:34 +08004983void Context::memoryBarrier(GLbitfield barriers)
4984{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004985 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004986}
4987
4988void Context::memoryBarrierByRegion(GLbitfield barriers)
4989{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004990 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004991}
4992
Jamie Madillc1d770e2017-04-13 17:31:24 -04004993GLenum Context::checkFramebufferStatus(GLenum target)
4994{
4995 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4996 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004997 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004998}
4999
5000void Context::compileShader(GLuint shader)
5001{
5002 Shader *shaderObject = GetValidShader(this, shader);
5003 if (!shaderObject)
5004 {
5005 return;
5006 }
5007 shaderObject->compile(this);
5008}
5009
5010void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5011{
5012 for (int i = 0; i < n; i++)
5013 {
5014 deleteBuffer(buffers[i]);
5015 }
5016}
5017
5018void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5019{
5020 for (int i = 0; i < n; i++)
5021 {
5022 if (framebuffers[i] != 0)
5023 {
5024 deleteFramebuffer(framebuffers[i]);
5025 }
5026 }
5027}
5028
5029void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5030{
5031 for (int i = 0; i < n; i++)
5032 {
5033 deleteRenderbuffer(renderbuffers[i]);
5034 }
5035}
5036
5037void Context::deleteTextures(GLsizei n, const GLuint *textures)
5038{
5039 for (int i = 0; i < n; i++)
5040 {
5041 if (textures[i] != 0)
5042 {
5043 deleteTexture(textures[i]);
5044 }
5045 }
5046}
5047
5048void Context::detachShader(GLuint program, GLuint shader)
5049{
5050 Program *programObject = getProgram(program);
5051 ASSERT(programObject);
5052
5053 Shader *shaderObject = getShader(shader);
5054 ASSERT(shaderObject);
5055
5056 programObject->detachShader(this, shaderObject);
5057}
5058
5059void Context::genBuffers(GLsizei n, GLuint *buffers)
5060{
5061 for (int i = 0; i < n; i++)
5062 {
5063 buffers[i] = createBuffer();
5064 }
5065}
5066
5067void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5068{
5069 for (int i = 0; i < n; i++)
5070 {
5071 framebuffers[i] = createFramebuffer();
5072 }
5073}
5074
5075void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5076{
5077 for (int i = 0; i < n; i++)
5078 {
5079 renderbuffers[i] = createRenderbuffer();
5080 }
5081}
5082
5083void Context::genTextures(GLsizei n, GLuint *textures)
5084{
5085 for (int i = 0; i < n; i++)
5086 {
5087 textures[i] = createTexture();
5088 }
5089}
5090
5091void Context::getActiveAttrib(GLuint program,
5092 GLuint index,
5093 GLsizei bufsize,
5094 GLsizei *length,
5095 GLint *size,
5096 GLenum *type,
5097 GLchar *name)
5098{
5099 Program *programObject = getProgram(program);
5100 ASSERT(programObject);
5101 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5102}
5103
5104void Context::getActiveUniform(GLuint program,
5105 GLuint index,
5106 GLsizei bufsize,
5107 GLsizei *length,
5108 GLint *size,
5109 GLenum *type,
5110 GLchar *name)
5111{
5112 Program *programObject = getProgram(program);
5113 ASSERT(programObject);
5114 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5115}
5116
5117void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5118{
5119 Program *programObject = getProgram(program);
5120 ASSERT(programObject);
5121 programObject->getAttachedShaders(maxcount, count, shaders);
5122}
5123
5124GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5125{
5126 Program *programObject = getProgram(program);
5127 ASSERT(programObject);
5128 return programObject->getAttributeLocation(name);
5129}
5130
5131void Context::getBooleanv(GLenum pname, GLboolean *params)
5132{
5133 GLenum nativeType;
5134 unsigned int numParams = 0;
5135 getQueryParameterInfo(pname, &nativeType, &numParams);
5136
5137 if (nativeType == GL_BOOL)
5138 {
5139 getBooleanvImpl(pname, params);
5140 }
5141 else
5142 {
5143 CastStateValues(this, nativeType, pname, numParams, params);
5144 }
5145}
5146
Brandon Jones59770802018-04-02 13:18:42 -07005147void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5148{
5149 getBooleanv(pname, params);
5150}
5151
Jamie Madillc1d770e2017-04-13 17:31:24 -04005152void Context::getFloatv(GLenum pname, GLfloat *params)
5153{
5154 GLenum nativeType;
5155 unsigned int numParams = 0;
5156 getQueryParameterInfo(pname, &nativeType, &numParams);
5157
5158 if (nativeType == GL_FLOAT)
5159 {
5160 getFloatvImpl(pname, params);
5161 }
5162 else
5163 {
5164 CastStateValues(this, nativeType, pname, numParams, params);
5165 }
5166}
5167
Brandon Jones59770802018-04-02 13:18:42 -07005168void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5169{
5170 getFloatv(pname, params);
5171}
5172
Jamie Madillc1d770e2017-04-13 17:31:24 -04005173void Context::getIntegerv(GLenum pname, GLint *params)
5174{
5175 GLenum nativeType;
5176 unsigned int numParams = 0;
5177 getQueryParameterInfo(pname, &nativeType, &numParams);
5178
5179 if (nativeType == GL_INT)
5180 {
5181 getIntegervImpl(pname, params);
5182 }
5183 else
5184 {
5185 CastStateValues(this, nativeType, pname, numParams, params);
5186 }
5187}
5188
Brandon Jones59770802018-04-02 13:18:42 -07005189void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5190{
5191 getIntegerv(pname, data);
5192}
5193
Jamie Madillc1d770e2017-04-13 17:31:24 -04005194void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5195{
5196 Program *programObject = getProgram(program);
5197 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005198 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199}
5200
Brandon Jones59770802018-04-02 13:18:42 -07005201void Context::getProgramivRobust(GLuint program,
5202 GLenum pname,
5203 GLsizei bufSize,
5204 GLsizei *length,
5205 GLint *params)
5206{
5207 getProgramiv(program, pname, params);
5208}
5209
Jiajia Qin5451d532017-11-16 17:16:34 +08005210void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5211{
5212 UNIMPLEMENTED();
5213}
5214
Jamie Madillbe849e42017-05-02 15:49:00 -04005215void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005216{
5217 Program *programObject = getProgram(program);
5218 ASSERT(programObject);
5219 programObject->getInfoLog(bufsize, length, infolog);
5220}
5221
Jiajia Qin5451d532017-11-16 17:16:34 +08005222void Context::getProgramPipelineInfoLog(GLuint pipeline,
5223 GLsizei bufSize,
5224 GLsizei *length,
5225 GLchar *infoLog)
5226{
5227 UNIMPLEMENTED();
5228}
5229
Jamie Madillc1d770e2017-04-13 17:31:24 -04005230void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5231{
5232 Shader *shaderObject = getShader(shader);
5233 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005234 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005235}
5236
Brandon Jones59770802018-04-02 13:18:42 -07005237void Context::getShaderivRobust(GLuint shader,
5238 GLenum pname,
5239 GLsizei bufSize,
5240 GLsizei *length,
5241 GLint *params)
5242{
5243 getShaderiv(shader, pname, params);
5244}
5245
Jamie Madillc1d770e2017-04-13 17:31:24 -04005246void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5247{
5248 Shader *shaderObject = getShader(shader);
5249 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005250 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005251}
5252
5253void Context::getShaderPrecisionFormat(GLenum shadertype,
5254 GLenum precisiontype,
5255 GLint *range,
5256 GLint *precision)
5257{
5258 // TODO(jmadill): Compute shaders.
5259
5260 switch (shadertype)
5261 {
5262 case GL_VERTEX_SHADER:
5263 switch (precisiontype)
5264 {
5265 case GL_LOW_FLOAT:
5266 mCaps.vertexLowpFloat.get(range, precision);
5267 break;
5268 case GL_MEDIUM_FLOAT:
5269 mCaps.vertexMediumpFloat.get(range, precision);
5270 break;
5271 case GL_HIGH_FLOAT:
5272 mCaps.vertexHighpFloat.get(range, precision);
5273 break;
5274
5275 case GL_LOW_INT:
5276 mCaps.vertexLowpInt.get(range, precision);
5277 break;
5278 case GL_MEDIUM_INT:
5279 mCaps.vertexMediumpInt.get(range, precision);
5280 break;
5281 case GL_HIGH_INT:
5282 mCaps.vertexHighpInt.get(range, precision);
5283 break;
5284
5285 default:
5286 UNREACHABLE();
5287 return;
5288 }
5289 break;
5290
5291 case GL_FRAGMENT_SHADER:
5292 switch (precisiontype)
5293 {
5294 case GL_LOW_FLOAT:
5295 mCaps.fragmentLowpFloat.get(range, precision);
5296 break;
5297 case GL_MEDIUM_FLOAT:
5298 mCaps.fragmentMediumpFloat.get(range, precision);
5299 break;
5300 case GL_HIGH_FLOAT:
5301 mCaps.fragmentHighpFloat.get(range, precision);
5302 break;
5303
5304 case GL_LOW_INT:
5305 mCaps.fragmentLowpInt.get(range, precision);
5306 break;
5307 case GL_MEDIUM_INT:
5308 mCaps.fragmentMediumpInt.get(range, precision);
5309 break;
5310 case GL_HIGH_INT:
5311 mCaps.fragmentHighpInt.get(range, precision);
5312 break;
5313
5314 default:
5315 UNREACHABLE();
5316 return;
5317 }
5318 break;
5319
5320 default:
5321 UNREACHABLE();
5322 return;
5323 }
5324}
5325
5326void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5327{
5328 Shader *shaderObject = getShader(shader);
5329 ASSERT(shaderObject);
5330 shaderObject->getSource(bufsize, length, source);
5331}
5332
5333void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5334{
5335 Program *programObject = getProgram(program);
5336 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005337 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005338}
5339
Brandon Jones59770802018-04-02 13:18:42 -07005340void Context::getUniformfvRobust(GLuint program,
5341 GLint location,
5342 GLsizei bufSize,
5343 GLsizei *length,
5344 GLfloat *params)
5345{
5346 getUniformfv(program, location, params);
5347}
5348
Jamie Madillc1d770e2017-04-13 17:31:24 -04005349void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5350{
5351 Program *programObject = getProgram(program);
5352 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005353 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354}
5355
Brandon Jones59770802018-04-02 13:18:42 -07005356void Context::getUniformivRobust(GLuint program,
5357 GLint location,
5358 GLsizei bufSize,
5359 GLsizei *length,
5360 GLint *params)
5361{
5362 getUniformiv(program, location, params);
5363}
5364
Jamie Madillc1d770e2017-04-13 17:31:24 -04005365GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5366{
5367 Program *programObject = getProgram(program);
5368 ASSERT(programObject);
5369 return programObject->getUniformLocation(name);
5370}
5371
5372GLboolean Context::isBuffer(GLuint buffer)
5373{
5374 if (buffer == 0)
5375 {
5376 return GL_FALSE;
5377 }
5378
5379 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5380}
5381
5382GLboolean Context::isEnabled(GLenum cap)
5383{
5384 return mGLState.getEnableFeature(cap);
5385}
5386
5387GLboolean Context::isFramebuffer(GLuint framebuffer)
5388{
5389 if (framebuffer == 0)
5390 {
5391 return GL_FALSE;
5392 }
5393
5394 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5395}
5396
5397GLboolean Context::isProgram(GLuint program)
5398{
5399 if (program == 0)
5400 {
5401 return GL_FALSE;
5402 }
5403
5404 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5405}
5406
5407GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5408{
5409 if (renderbuffer == 0)
5410 {
5411 return GL_FALSE;
5412 }
5413
5414 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5415}
5416
5417GLboolean Context::isShader(GLuint shader)
5418{
5419 if (shader == 0)
5420 {
5421 return GL_FALSE;
5422 }
5423
5424 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5425}
5426
5427GLboolean Context::isTexture(GLuint texture)
5428{
5429 if (texture == 0)
5430 {
5431 return GL_FALSE;
5432 }
5433
5434 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5435}
5436
5437void Context::linkProgram(GLuint program)
5438{
5439 Program *programObject = getProgram(program);
5440 ASSERT(programObject);
5441 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005442 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443}
5444
5445void Context::releaseShaderCompiler()
5446{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005447 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448}
5449
5450void Context::shaderBinary(GLsizei n,
5451 const GLuint *shaders,
5452 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005453 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454 GLsizei length)
5455{
5456 // No binary shader formats are supported.
5457 UNIMPLEMENTED();
5458}
5459
5460void Context::shaderSource(GLuint shader,
5461 GLsizei count,
5462 const GLchar *const *string,
5463 const GLint *length)
5464{
5465 Shader *shaderObject = getShader(shader);
5466 ASSERT(shaderObject);
5467 shaderObject->setSource(count, string, length);
5468}
5469
5470void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5471{
5472 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5473}
5474
5475void Context::stencilMask(GLuint mask)
5476{
5477 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5478}
5479
5480void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5481{
5482 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5483}
5484
5485void Context::uniform1f(GLint location, GLfloat x)
5486{
5487 Program *program = mGLState.getProgram();
5488 program->setUniform1fv(location, 1, &x);
5489}
5490
5491void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5492{
5493 Program *program = mGLState.getProgram();
5494 program->setUniform1fv(location, count, v);
5495}
5496
5497void Context::uniform1i(GLint location, GLint x)
5498{
5499 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005500 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5501 {
5502 mGLState.setObjectDirty(GL_PROGRAM);
5503 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005504}
5505
5506void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5507{
5508 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005509 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5510 {
5511 mGLState.setObjectDirty(GL_PROGRAM);
5512 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005513}
5514
5515void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5516{
5517 GLfloat xy[2] = {x, y};
5518 Program *program = mGLState.getProgram();
5519 program->setUniform2fv(location, 1, xy);
5520}
5521
5522void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5523{
5524 Program *program = mGLState.getProgram();
5525 program->setUniform2fv(location, count, v);
5526}
5527
5528void Context::uniform2i(GLint location, GLint x, GLint y)
5529{
5530 GLint xy[2] = {x, y};
5531 Program *program = mGLState.getProgram();
5532 program->setUniform2iv(location, 1, xy);
5533}
5534
5535void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5536{
5537 Program *program = mGLState.getProgram();
5538 program->setUniform2iv(location, count, v);
5539}
5540
5541void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5542{
5543 GLfloat xyz[3] = {x, y, z};
5544 Program *program = mGLState.getProgram();
5545 program->setUniform3fv(location, 1, xyz);
5546}
5547
5548void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5549{
5550 Program *program = mGLState.getProgram();
5551 program->setUniform3fv(location, count, v);
5552}
5553
5554void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5555{
5556 GLint xyz[3] = {x, y, z};
5557 Program *program = mGLState.getProgram();
5558 program->setUniform3iv(location, 1, xyz);
5559}
5560
5561void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5562{
5563 Program *program = mGLState.getProgram();
5564 program->setUniform3iv(location, count, v);
5565}
5566
5567void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5568{
5569 GLfloat xyzw[4] = {x, y, z, w};
5570 Program *program = mGLState.getProgram();
5571 program->setUniform4fv(location, 1, xyzw);
5572}
5573
5574void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5575{
5576 Program *program = mGLState.getProgram();
5577 program->setUniform4fv(location, count, v);
5578}
5579
5580void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5581{
5582 GLint xyzw[4] = {x, y, z, w};
5583 Program *program = mGLState.getProgram();
5584 program->setUniform4iv(location, 1, xyzw);
5585}
5586
5587void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5588{
5589 Program *program = mGLState.getProgram();
5590 program->setUniform4iv(location, count, v);
5591}
5592
5593void Context::uniformMatrix2fv(GLint location,
5594 GLsizei count,
5595 GLboolean transpose,
5596 const GLfloat *value)
5597{
5598 Program *program = mGLState.getProgram();
5599 program->setUniformMatrix2fv(location, count, transpose, value);
5600}
5601
5602void Context::uniformMatrix3fv(GLint location,
5603 GLsizei count,
5604 GLboolean transpose,
5605 const GLfloat *value)
5606{
5607 Program *program = mGLState.getProgram();
5608 program->setUniformMatrix3fv(location, count, transpose, value);
5609}
5610
5611void Context::uniformMatrix4fv(GLint location,
5612 GLsizei count,
5613 GLboolean transpose,
5614 const GLfloat *value)
5615{
5616 Program *program = mGLState.getProgram();
5617 program->setUniformMatrix4fv(location, count, transpose, value);
5618}
5619
5620void Context::validateProgram(GLuint program)
5621{
5622 Program *programObject = getProgram(program);
5623 ASSERT(programObject);
5624 programObject->validate(mCaps);
5625}
5626
Jiajia Qin5451d532017-11-16 17:16:34 +08005627void Context::validateProgramPipeline(GLuint pipeline)
5628{
5629 UNIMPLEMENTED();
5630}
5631
Jamie Madilld04908b2017-06-09 14:15:35 -04005632void Context::getProgramBinary(GLuint program,
5633 GLsizei bufSize,
5634 GLsizei *length,
5635 GLenum *binaryFormat,
5636 void *binary)
5637{
5638 Program *programObject = getProgram(program);
5639 ASSERT(programObject != nullptr);
5640
5641 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5642}
5643
5644void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5645{
5646 Program *programObject = getProgram(program);
5647 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005648
Jamie Madilld04908b2017-06-09 14:15:35 -04005649 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5650}
5651
Jamie Madillff325f12017-08-26 15:06:05 -04005652void Context::uniform1ui(GLint location, GLuint v0)
5653{
5654 Program *program = mGLState.getProgram();
5655 program->setUniform1uiv(location, 1, &v0);
5656}
5657
5658void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5659{
5660 Program *program = mGLState.getProgram();
5661 const GLuint xy[] = {v0, v1};
5662 program->setUniform2uiv(location, 1, xy);
5663}
5664
5665void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5666{
5667 Program *program = mGLState.getProgram();
5668 const GLuint xyz[] = {v0, v1, v2};
5669 program->setUniform3uiv(location, 1, xyz);
5670}
5671
5672void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5673{
5674 Program *program = mGLState.getProgram();
5675 const GLuint xyzw[] = {v0, v1, v2, v3};
5676 program->setUniform4uiv(location, 1, xyzw);
5677}
5678
5679void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5680{
5681 Program *program = mGLState.getProgram();
5682 program->setUniform1uiv(location, count, value);
5683}
5684void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5685{
5686 Program *program = mGLState.getProgram();
5687 program->setUniform2uiv(location, count, value);
5688}
5689
5690void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5691{
5692 Program *program = mGLState.getProgram();
5693 program->setUniform3uiv(location, count, value);
5694}
5695
5696void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5697{
5698 Program *program = mGLState.getProgram();
5699 program->setUniform4uiv(location, count, value);
5700}
5701
Jamie Madillf0e04492017-08-26 15:28:42 -04005702void Context::genQueries(GLsizei n, GLuint *ids)
5703{
5704 for (GLsizei i = 0; i < n; i++)
5705 {
5706 GLuint handle = mQueryHandleAllocator.allocate();
5707 mQueryMap.assign(handle, nullptr);
5708 ids[i] = handle;
5709 }
5710}
5711
5712void Context::deleteQueries(GLsizei n, const GLuint *ids)
5713{
5714 for (int i = 0; i < n; i++)
5715 {
5716 GLuint query = ids[i];
5717
5718 Query *queryObject = nullptr;
5719 if (mQueryMap.erase(query, &queryObject))
5720 {
5721 mQueryHandleAllocator.release(query);
5722 if (queryObject)
5723 {
5724 queryObject->release(this);
5725 }
5726 }
5727 }
5728}
5729
5730GLboolean Context::isQuery(GLuint id)
5731{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005732 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005733}
5734
Jamie Madillc8c95812017-08-26 18:40:09 -04005735void Context::uniformMatrix2x3fv(GLint location,
5736 GLsizei count,
5737 GLboolean transpose,
5738 const GLfloat *value)
5739{
5740 Program *program = mGLState.getProgram();
5741 program->setUniformMatrix2x3fv(location, count, transpose, value);
5742}
5743
5744void Context::uniformMatrix3x2fv(GLint location,
5745 GLsizei count,
5746 GLboolean transpose,
5747 const GLfloat *value)
5748{
5749 Program *program = mGLState.getProgram();
5750 program->setUniformMatrix3x2fv(location, count, transpose, value);
5751}
5752
5753void Context::uniformMatrix2x4fv(GLint location,
5754 GLsizei count,
5755 GLboolean transpose,
5756 const GLfloat *value)
5757{
5758 Program *program = mGLState.getProgram();
5759 program->setUniformMatrix2x4fv(location, count, transpose, value);
5760}
5761
5762void Context::uniformMatrix4x2fv(GLint location,
5763 GLsizei count,
5764 GLboolean transpose,
5765 const GLfloat *value)
5766{
5767 Program *program = mGLState.getProgram();
5768 program->setUniformMatrix4x2fv(location, count, transpose, value);
5769}
5770
5771void Context::uniformMatrix3x4fv(GLint location,
5772 GLsizei count,
5773 GLboolean transpose,
5774 const GLfloat *value)
5775{
5776 Program *program = mGLState.getProgram();
5777 program->setUniformMatrix3x4fv(location, count, transpose, value);
5778}
5779
5780void Context::uniformMatrix4x3fv(GLint location,
5781 GLsizei count,
5782 GLboolean transpose,
5783 const GLfloat *value)
5784{
5785 Program *program = mGLState.getProgram();
5786 program->setUniformMatrix4x3fv(location, count, transpose, value);
5787}
5788
Jamie Madilld7576732017-08-26 18:49:50 -04005789void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5790{
5791 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5792 {
5793 GLuint vertexArray = arrays[arrayIndex];
5794
5795 if (arrays[arrayIndex] != 0)
5796 {
5797 VertexArray *vertexArrayObject = nullptr;
5798 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5799 {
5800 if (vertexArrayObject != nullptr)
5801 {
5802 detachVertexArray(vertexArray);
5803 vertexArrayObject->onDestroy(this);
5804 }
5805
5806 mVertexArrayHandleAllocator.release(vertexArray);
5807 }
5808 }
5809 }
5810}
5811
5812void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5813{
5814 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5815 {
5816 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5817 mVertexArrayMap.assign(vertexArray, nullptr);
5818 arrays[arrayIndex] = vertexArray;
5819 }
5820}
5821
5822bool Context::isVertexArray(GLuint array)
5823{
5824 if (array == 0)
5825 {
5826 return GL_FALSE;
5827 }
5828
5829 VertexArray *vao = getVertexArray(array);
5830 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5831}
5832
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005833void Context::endTransformFeedback()
5834{
5835 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5836 transformFeedback->end(this);
5837}
5838
5839void Context::transformFeedbackVaryings(GLuint program,
5840 GLsizei count,
5841 const GLchar *const *varyings,
5842 GLenum bufferMode)
5843{
5844 Program *programObject = getProgram(program);
5845 ASSERT(programObject);
5846 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5847}
5848
5849void Context::getTransformFeedbackVarying(GLuint program,
5850 GLuint index,
5851 GLsizei bufSize,
5852 GLsizei *length,
5853 GLsizei *size,
5854 GLenum *type,
5855 GLchar *name)
5856{
5857 Program *programObject = getProgram(program);
5858 ASSERT(programObject);
5859 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5860}
5861
5862void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5863{
5864 for (int i = 0; i < n; i++)
5865 {
5866 GLuint transformFeedback = ids[i];
5867 if (transformFeedback == 0)
5868 {
5869 continue;
5870 }
5871
5872 TransformFeedback *transformFeedbackObject = nullptr;
5873 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5874 {
5875 if (transformFeedbackObject != nullptr)
5876 {
5877 detachTransformFeedback(transformFeedback);
5878 transformFeedbackObject->release(this);
5879 }
5880
5881 mTransformFeedbackHandleAllocator.release(transformFeedback);
5882 }
5883 }
5884}
5885
5886void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5887{
5888 for (int i = 0; i < n; i++)
5889 {
5890 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5891 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5892 ids[i] = transformFeedback;
5893 }
5894}
5895
5896bool Context::isTransformFeedback(GLuint id)
5897{
5898 if (id == 0)
5899 {
5900 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5901 // returns FALSE
5902 return GL_FALSE;
5903 }
5904
5905 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5906 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5907}
5908
5909void Context::pauseTransformFeedback()
5910{
5911 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5912 transformFeedback->pause();
5913}
5914
5915void Context::resumeTransformFeedback()
5916{
5917 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5918 transformFeedback->resume();
5919}
5920
Jamie Madill12e957f2017-08-26 21:42:26 -04005921void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5922{
5923 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005924 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005925}
5926
Brandon Jones59770802018-04-02 13:18:42 -07005927void Context::getUniformuivRobust(GLuint program,
5928 GLint location,
5929 GLsizei bufSize,
5930 GLsizei *length,
5931 GLuint *params)
5932{
5933 getUniformuiv(program, location, params);
5934}
5935
Jamie Madill12e957f2017-08-26 21:42:26 -04005936GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5937{
5938 const Program *programObject = getProgram(program);
5939 return programObject->getFragDataLocation(name);
5940}
5941
5942void Context::getUniformIndices(GLuint program,
5943 GLsizei uniformCount,
5944 const GLchar *const *uniformNames,
5945 GLuint *uniformIndices)
5946{
5947 const Program *programObject = getProgram(program);
5948 if (!programObject->isLinked())
5949 {
5950 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5951 {
5952 uniformIndices[uniformId] = GL_INVALID_INDEX;
5953 }
5954 }
5955 else
5956 {
5957 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5958 {
5959 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5960 }
5961 }
5962}
5963
5964void Context::getActiveUniformsiv(GLuint program,
5965 GLsizei uniformCount,
5966 const GLuint *uniformIndices,
5967 GLenum pname,
5968 GLint *params)
5969{
5970 const Program *programObject = getProgram(program);
5971 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5972 {
5973 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005974 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005975 }
5976}
5977
5978GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5979{
5980 const Program *programObject = getProgram(program);
5981 return programObject->getUniformBlockIndex(uniformBlockName);
5982}
5983
5984void Context::getActiveUniformBlockiv(GLuint program,
5985 GLuint uniformBlockIndex,
5986 GLenum pname,
5987 GLint *params)
5988{
5989 const Program *programObject = getProgram(program);
5990 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5991}
5992
Brandon Jones59770802018-04-02 13:18:42 -07005993void Context::getActiveUniformBlockivRobust(GLuint program,
5994 GLuint uniformBlockIndex,
5995 GLenum pname,
5996 GLsizei bufSize,
5997 GLsizei *length,
5998 GLint *params)
5999{
6000 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6001}
6002
Jamie Madill12e957f2017-08-26 21:42:26 -04006003void Context::getActiveUniformBlockName(GLuint program,
6004 GLuint uniformBlockIndex,
6005 GLsizei bufSize,
6006 GLsizei *length,
6007 GLchar *uniformBlockName)
6008{
6009 const Program *programObject = getProgram(program);
6010 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6011}
6012
6013void Context::uniformBlockBinding(GLuint program,
6014 GLuint uniformBlockIndex,
6015 GLuint uniformBlockBinding)
6016{
6017 Program *programObject = getProgram(program);
6018 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6019}
6020
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006021GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6022{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006023 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6024 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006025
Jamie Madill70b5bb02017-08-28 13:32:37 -04006026 Sync *syncObject = getSync(syncHandle);
6027 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006028 if (error.isError())
6029 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006030 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006031 handleError(error);
6032 return nullptr;
6033 }
6034
Jamie Madill70b5bb02017-08-28 13:32:37 -04006035 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006036}
6037
6038GLboolean Context::isSync(GLsync sync)
6039{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006040 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006041}
6042
6043GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6044{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006045 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006046
6047 GLenum result = GL_WAIT_FAILED;
6048 handleError(syncObject->clientWait(flags, timeout, &result));
6049 return result;
6050}
6051
6052void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6053{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006054 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006055 handleError(syncObject->serverWait(flags, timeout));
6056}
6057
6058void Context::getInteger64v(GLenum pname, GLint64 *params)
6059{
6060 GLenum nativeType = GL_NONE;
6061 unsigned int numParams = 0;
6062 getQueryParameterInfo(pname, &nativeType, &numParams);
6063
6064 if (nativeType == GL_INT_64_ANGLEX)
6065 {
6066 getInteger64vImpl(pname, params);
6067 }
6068 else
6069 {
6070 CastStateValues(this, nativeType, pname, numParams, params);
6071 }
6072}
6073
Brandon Jones59770802018-04-02 13:18:42 -07006074void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6075{
6076 getInteger64v(pname, data);
6077}
6078
Corentin Wallez336129f2017-10-17 15:55:40 -04006079void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006080{
6081 Buffer *buffer = mGLState.getTargetBuffer(target);
6082 QueryBufferParameteri64v(buffer, pname, params);
6083}
6084
Brandon Jones59770802018-04-02 13:18:42 -07006085void Context::getBufferParameteri64vRobust(BufferBinding target,
6086 GLenum pname,
6087 GLsizei bufSize,
6088 GLsizei *length,
6089 GLint64 *params)
6090{
6091 getBufferParameteri64v(target, pname, params);
6092}
6093
Jamie Madill3ef140a2017-08-26 23:11:21 -04006094void Context::genSamplers(GLsizei count, GLuint *samplers)
6095{
6096 for (int i = 0; i < count; i++)
6097 {
6098 samplers[i] = mState.mSamplers->createSampler();
6099 }
6100}
6101
6102void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6103{
6104 for (int i = 0; i < count; i++)
6105 {
6106 GLuint sampler = samplers[i];
6107
6108 if (mState.mSamplers->getSampler(sampler))
6109 {
6110 detachSampler(sampler);
6111 }
6112
6113 mState.mSamplers->deleteObject(this, sampler);
6114 }
6115}
6116
6117void Context::getInternalformativ(GLenum target,
6118 GLenum internalformat,
6119 GLenum pname,
6120 GLsizei bufSize,
6121 GLint *params)
6122{
6123 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6124 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6125}
6126
Brandon Jones59770802018-04-02 13:18:42 -07006127void Context::getInternalformativRobust(GLenum target,
6128 GLenum internalformat,
6129 GLenum pname,
6130 GLsizei bufSize,
6131 GLsizei *length,
6132 GLint *params)
6133{
6134 getInternalformativ(target, internalformat, pname, bufSize, params);
6135}
6136
Jiajia Qin5451d532017-11-16 17:16:34 +08006137void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6138{
6139 programUniform1iv(program, location, 1, &v0);
6140}
6141
6142void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6143{
6144 GLint xy[2] = {v0, v1};
6145 programUniform2iv(program, location, 1, xy);
6146}
6147
6148void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6149{
6150 GLint xyz[3] = {v0, v1, v2};
6151 programUniform3iv(program, location, 1, xyz);
6152}
6153
6154void Context::programUniform4i(GLuint program,
6155 GLint location,
6156 GLint v0,
6157 GLint v1,
6158 GLint v2,
6159 GLint v3)
6160{
6161 GLint xyzw[4] = {v0, v1, v2, v3};
6162 programUniform4iv(program, location, 1, xyzw);
6163}
6164
6165void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6166{
6167 programUniform1uiv(program, location, 1, &v0);
6168}
6169
6170void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6171{
6172 GLuint xy[2] = {v0, v1};
6173 programUniform2uiv(program, location, 1, xy);
6174}
6175
6176void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6177{
6178 GLuint xyz[3] = {v0, v1, v2};
6179 programUniform3uiv(program, location, 1, xyz);
6180}
6181
6182void Context::programUniform4ui(GLuint program,
6183 GLint location,
6184 GLuint v0,
6185 GLuint v1,
6186 GLuint v2,
6187 GLuint v3)
6188{
6189 GLuint xyzw[4] = {v0, v1, v2, v3};
6190 programUniform4uiv(program, location, 1, xyzw);
6191}
6192
6193void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6194{
6195 programUniform1fv(program, location, 1, &v0);
6196}
6197
6198void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6199{
6200 GLfloat xy[2] = {v0, v1};
6201 programUniform2fv(program, location, 1, xy);
6202}
6203
6204void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6205{
6206 GLfloat xyz[3] = {v0, v1, v2};
6207 programUniform3fv(program, location, 1, xyz);
6208}
6209
6210void Context::programUniform4f(GLuint program,
6211 GLint location,
6212 GLfloat v0,
6213 GLfloat v1,
6214 GLfloat v2,
6215 GLfloat v3)
6216{
6217 GLfloat xyzw[4] = {v0, v1, v2, v3};
6218 programUniform4fv(program, location, 1, xyzw);
6219}
6220
Jamie Madill81c2e252017-09-09 23:32:46 -04006221void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6222{
6223 Program *programObject = getProgram(program);
6224 ASSERT(programObject);
6225 if (programObject->setUniform1iv(location, count, value) ==
6226 Program::SetUniformResult::SamplerChanged)
6227 {
6228 mGLState.setObjectDirty(GL_PROGRAM);
6229 }
6230}
6231
Jiajia Qin5451d532017-11-16 17:16:34 +08006232void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6233{
6234 Program *programObject = getProgram(program);
6235 ASSERT(programObject);
6236 programObject->setUniform2iv(location, count, value);
6237}
6238
6239void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6240{
6241 Program *programObject = getProgram(program);
6242 ASSERT(programObject);
6243 programObject->setUniform3iv(location, count, value);
6244}
6245
6246void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6247{
6248 Program *programObject = getProgram(program);
6249 ASSERT(programObject);
6250 programObject->setUniform4iv(location, count, value);
6251}
6252
6253void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6254{
6255 Program *programObject = getProgram(program);
6256 ASSERT(programObject);
6257 programObject->setUniform1uiv(location, count, value);
6258}
6259
6260void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6261{
6262 Program *programObject = getProgram(program);
6263 ASSERT(programObject);
6264 programObject->setUniform2uiv(location, count, value);
6265}
6266
6267void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6268{
6269 Program *programObject = getProgram(program);
6270 ASSERT(programObject);
6271 programObject->setUniform3uiv(location, count, value);
6272}
6273
6274void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6275{
6276 Program *programObject = getProgram(program);
6277 ASSERT(programObject);
6278 programObject->setUniform4uiv(location, count, value);
6279}
6280
6281void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6282{
6283 Program *programObject = getProgram(program);
6284 ASSERT(programObject);
6285 programObject->setUniform1fv(location, count, value);
6286}
6287
6288void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6289{
6290 Program *programObject = getProgram(program);
6291 ASSERT(programObject);
6292 programObject->setUniform2fv(location, count, value);
6293}
6294
6295void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6296{
6297 Program *programObject = getProgram(program);
6298 ASSERT(programObject);
6299 programObject->setUniform3fv(location, count, value);
6300}
6301
6302void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6303{
6304 Program *programObject = getProgram(program);
6305 ASSERT(programObject);
6306 programObject->setUniform4fv(location, count, value);
6307}
6308
6309void Context::programUniformMatrix2fv(GLuint program,
6310 GLint location,
6311 GLsizei count,
6312 GLboolean transpose,
6313 const GLfloat *value)
6314{
6315 Program *programObject = getProgram(program);
6316 ASSERT(programObject);
6317 programObject->setUniformMatrix2fv(location, count, transpose, value);
6318}
6319
6320void Context::programUniformMatrix3fv(GLuint program,
6321 GLint location,
6322 GLsizei count,
6323 GLboolean transpose,
6324 const GLfloat *value)
6325{
6326 Program *programObject = getProgram(program);
6327 ASSERT(programObject);
6328 programObject->setUniformMatrix3fv(location, count, transpose, value);
6329}
6330
6331void Context::programUniformMatrix4fv(GLuint program,
6332 GLint location,
6333 GLsizei count,
6334 GLboolean transpose,
6335 const GLfloat *value)
6336{
6337 Program *programObject = getProgram(program);
6338 ASSERT(programObject);
6339 programObject->setUniformMatrix4fv(location, count, transpose, value);
6340}
6341
6342void Context::programUniformMatrix2x3fv(GLuint program,
6343 GLint location,
6344 GLsizei count,
6345 GLboolean transpose,
6346 const GLfloat *value)
6347{
6348 Program *programObject = getProgram(program);
6349 ASSERT(programObject);
6350 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6351}
6352
6353void Context::programUniformMatrix3x2fv(GLuint program,
6354 GLint location,
6355 GLsizei count,
6356 GLboolean transpose,
6357 const GLfloat *value)
6358{
6359 Program *programObject = getProgram(program);
6360 ASSERT(programObject);
6361 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6362}
6363
6364void Context::programUniformMatrix2x4fv(GLuint program,
6365 GLint location,
6366 GLsizei count,
6367 GLboolean transpose,
6368 const GLfloat *value)
6369{
6370 Program *programObject = getProgram(program);
6371 ASSERT(programObject);
6372 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6373}
6374
6375void Context::programUniformMatrix4x2fv(GLuint program,
6376 GLint location,
6377 GLsizei count,
6378 GLboolean transpose,
6379 const GLfloat *value)
6380{
6381 Program *programObject = getProgram(program);
6382 ASSERT(programObject);
6383 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6384}
6385
6386void Context::programUniformMatrix3x4fv(GLuint program,
6387 GLint location,
6388 GLsizei count,
6389 GLboolean transpose,
6390 const GLfloat *value)
6391{
6392 Program *programObject = getProgram(program);
6393 ASSERT(programObject);
6394 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6395}
6396
6397void Context::programUniformMatrix4x3fv(GLuint program,
6398 GLint location,
6399 GLsizei count,
6400 GLboolean transpose,
6401 const GLfloat *value)
6402{
6403 Program *programObject = getProgram(program);
6404 ASSERT(programObject);
6405 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6406}
6407
Jamie Madill81c2e252017-09-09 23:32:46 -04006408void Context::onTextureChange(const Texture *texture)
6409{
6410 // Conservatively assume all textures are dirty.
6411 // TODO(jmadill): More fine-grained update.
6412 mGLState.setObjectDirty(GL_TEXTURE);
6413}
6414
James Darpiniane8a93c62018-01-04 18:02:24 -08006415bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6416{
6417 return mGLState.isCurrentTransformFeedback(tf);
6418}
6419bool Context::isCurrentVertexArray(const VertexArray *va) const
6420{
6421 return mGLState.isCurrentVertexArray(va);
6422}
6423
Yunchao Hea336b902017-08-02 16:05:21 +08006424void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6425{
6426 for (int i = 0; i < count; i++)
6427 {
6428 pipelines[i] = createProgramPipeline();
6429 }
6430}
6431
6432void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6433{
6434 for (int i = 0; i < count; i++)
6435 {
6436 if (pipelines[i] != 0)
6437 {
6438 deleteProgramPipeline(pipelines[i]);
6439 }
6440 }
6441}
6442
6443GLboolean Context::isProgramPipeline(GLuint pipeline)
6444{
6445 if (pipeline == 0)
6446 {
6447 return GL_FALSE;
6448 }
6449
6450 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6451}
6452
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006453void Context::finishFenceNV(GLuint fence)
6454{
6455 FenceNV *fenceObject = getFenceNV(fence);
6456
6457 ASSERT(fenceObject && fenceObject->isSet());
6458 handleError(fenceObject->finish());
6459}
6460
6461void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6462{
6463 FenceNV *fenceObject = getFenceNV(fence);
6464
6465 ASSERT(fenceObject && fenceObject->isSet());
6466
6467 switch (pname)
6468 {
6469 case GL_FENCE_STATUS_NV:
6470 {
6471 // GL_NV_fence spec:
6472 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6473 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6474 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6475 GLboolean status = GL_TRUE;
6476 if (fenceObject->getStatus() != GL_TRUE)
6477 {
6478 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6479 }
6480 *params = status;
6481 break;
6482 }
6483
6484 case GL_FENCE_CONDITION_NV:
6485 {
6486 *params = static_cast<GLint>(fenceObject->getCondition());
6487 break;
6488 }
6489
6490 default:
6491 UNREACHABLE();
6492 }
6493}
6494
6495void Context::getTranslatedShaderSource(GLuint shader,
6496 GLsizei bufsize,
6497 GLsizei *length,
6498 GLchar *source)
6499{
6500 Shader *shaderObject = getShader(shader);
6501 ASSERT(shaderObject);
6502 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6503}
6504
6505void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6506{
6507 Program *programObject = getProgram(program);
6508 ASSERT(programObject);
6509
6510 programObject->getUniformfv(this, location, params);
6511}
6512
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006513void Context::getnUniformfvRobust(GLuint program,
6514 GLint location,
6515 GLsizei bufSize,
6516 GLsizei *length,
6517 GLfloat *params)
6518{
6519 UNIMPLEMENTED();
6520}
6521
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006522void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6523{
6524 Program *programObject = getProgram(program);
6525 ASSERT(programObject);
6526
6527 programObject->getUniformiv(this, location, params);
6528}
6529
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006530void Context::getnUniformivRobust(GLuint program,
6531 GLint location,
6532 GLsizei bufSize,
6533 GLsizei *length,
6534 GLint *params)
6535{
6536 UNIMPLEMENTED();
6537}
6538
6539void Context::getnUniformuivRobust(GLuint program,
6540 GLint location,
6541 GLsizei bufSize,
6542 GLsizei *length,
6543 GLuint *params)
6544{
6545 UNIMPLEMENTED();
6546}
6547
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006548GLboolean Context::isFenceNV(GLuint fence)
6549{
6550 FenceNV *fenceObject = getFenceNV(fence);
6551
6552 if (fenceObject == nullptr)
6553 {
6554 return GL_FALSE;
6555 }
6556
6557 // GL_NV_fence spec:
6558 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6559 // existing fence.
6560 return fenceObject->isSet();
6561}
6562
6563void Context::readnPixels(GLint x,
6564 GLint y,
6565 GLsizei width,
6566 GLsizei height,
6567 GLenum format,
6568 GLenum type,
6569 GLsizei bufSize,
6570 void *data)
6571{
6572 return readPixels(x, y, width, height, format, type, data);
6573}
6574
Jamie Madill007530e2017-12-28 14:27:04 -05006575void Context::setFenceNV(GLuint fence, GLenum condition)
6576{
6577 ASSERT(condition == GL_ALL_COMPLETED_NV);
6578
6579 FenceNV *fenceObject = getFenceNV(fence);
6580 ASSERT(fenceObject != nullptr);
6581 handleError(fenceObject->set(condition));
6582}
6583
6584GLboolean Context::testFenceNV(GLuint fence)
6585{
6586 FenceNV *fenceObject = getFenceNV(fence);
6587
6588 ASSERT(fenceObject != nullptr);
6589 ASSERT(fenceObject->isSet() == GL_TRUE);
6590
6591 GLboolean result = GL_TRUE;
6592 Error error = fenceObject->test(&result);
6593 if (error.isError())
6594 {
6595 handleError(error);
6596 return GL_TRUE;
6597 }
6598
6599 return result;
6600}
6601
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006602void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006603{
6604 Texture *texture = getTargetTexture(target);
6605 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006606 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006607}
6608
Jamie Madillfa920eb2018-01-04 11:45:50 -05006609void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006610{
6611 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6612 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6613 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6614}
6615
Jamie Madillfa920eb2018-01-04 11:45:50 -05006616void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6617{
6618 UNIMPLEMENTED();
6619}
6620
Jamie Madill5b772312018-03-08 20:28:32 -05006621bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6622{
6623 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6624 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6625 // to the fact that it is stored internally as a float, and so would require conversion
6626 // if returned from Context::getIntegerv. Since this conversion is already implemented
6627 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6628 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6629 // application.
6630 switch (pname)
6631 {
6632 case GL_COMPRESSED_TEXTURE_FORMATS:
6633 {
6634 *type = GL_INT;
6635 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6636 return true;
6637 }
6638 case GL_SHADER_BINARY_FORMATS:
6639 {
6640 *type = GL_INT;
6641 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6642 return true;
6643 }
6644
6645 case GL_MAX_VERTEX_ATTRIBS:
6646 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6647 case GL_MAX_VARYING_VECTORS:
6648 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6649 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6650 case GL_MAX_TEXTURE_IMAGE_UNITS:
6651 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6652 case GL_MAX_RENDERBUFFER_SIZE:
6653 case GL_NUM_SHADER_BINARY_FORMATS:
6654 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6655 case GL_ARRAY_BUFFER_BINDING:
6656 case GL_FRAMEBUFFER_BINDING:
6657 case GL_RENDERBUFFER_BINDING:
6658 case GL_CURRENT_PROGRAM:
6659 case GL_PACK_ALIGNMENT:
6660 case GL_UNPACK_ALIGNMENT:
6661 case GL_GENERATE_MIPMAP_HINT:
6662 case GL_RED_BITS:
6663 case GL_GREEN_BITS:
6664 case GL_BLUE_BITS:
6665 case GL_ALPHA_BITS:
6666 case GL_DEPTH_BITS:
6667 case GL_STENCIL_BITS:
6668 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6669 case GL_CULL_FACE_MODE:
6670 case GL_FRONT_FACE:
6671 case GL_ACTIVE_TEXTURE:
6672 case GL_STENCIL_FUNC:
6673 case GL_STENCIL_VALUE_MASK:
6674 case GL_STENCIL_REF:
6675 case GL_STENCIL_FAIL:
6676 case GL_STENCIL_PASS_DEPTH_FAIL:
6677 case GL_STENCIL_PASS_DEPTH_PASS:
6678 case GL_STENCIL_BACK_FUNC:
6679 case GL_STENCIL_BACK_VALUE_MASK:
6680 case GL_STENCIL_BACK_REF:
6681 case GL_STENCIL_BACK_FAIL:
6682 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6683 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6684 case GL_DEPTH_FUNC:
6685 case GL_BLEND_SRC_RGB:
6686 case GL_BLEND_SRC_ALPHA:
6687 case GL_BLEND_DST_RGB:
6688 case GL_BLEND_DST_ALPHA:
6689 case GL_BLEND_EQUATION_RGB:
6690 case GL_BLEND_EQUATION_ALPHA:
6691 case GL_STENCIL_WRITEMASK:
6692 case GL_STENCIL_BACK_WRITEMASK:
6693 case GL_STENCIL_CLEAR_VALUE:
6694 case GL_SUBPIXEL_BITS:
6695 case GL_MAX_TEXTURE_SIZE:
6696 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6697 case GL_SAMPLE_BUFFERS:
6698 case GL_SAMPLES:
6699 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6700 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6701 case GL_TEXTURE_BINDING_2D:
6702 case GL_TEXTURE_BINDING_CUBE_MAP:
6703 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6704 {
6705 *type = GL_INT;
6706 *numParams = 1;
6707 return true;
6708 }
6709 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6710 {
6711 if (!getExtensions().packReverseRowOrder)
6712 {
6713 return false;
6714 }
6715 *type = GL_INT;
6716 *numParams = 1;
6717 return true;
6718 }
6719 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6720 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6721 {
6722 if (!getExtensions().textureRectangle)
6723 {
6724 return false;
6725 }
6726 *type = GL_INT;
6727 *numParams = 1;
6728 return true;
6729 }
6730 case GL_MAX_DRAW_BUFFERS_EXT:
6731 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6732 {
6733 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6734 {
6735 return false;
6736 }
6737 *type = GL_INT;
6738 *numParams = 1;
6739 return true;
6740 }
6741 case GL_MAX_VIEWPORT_DIMS:
6742 {
6743 *type = GL_INT;
6744 *numParams = 2;
6745 return true;
6746 }
6747 case GL_VIEWPORT:
6748 case GL_SCISSOR_BOX:
6749 {
6750 *type = GL_INT;
6751 *numParams = 4;
6752 return true;
6753 }
6754 case GL_SHADER_COMPILER:
6755 case GL_SAMPLE_COVERAGE_INVERT:
6756 case GL_DEPTH_WRITEMASK:
6757 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6758 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6759 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6760 // bool-natural
6761 case GL_SAMPLE_COVERAGE:
6762 case GL_SCISSOR_TEST:
6763 case GL_STENCIL_TEST:
6764 case GL_DEPTH_TEST:
6765 case GL_BLEND:
6766 case GL_DITHER:
6767 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6768 {
6769 *type = GL_BOOL;
6770 *numParams = 1;
6771 return true;
6772 }
6773 case GL_COLOR_WRITEMASK:
6774 {
6775 *type = GL_BOOL;
6776 *numParams = 4;
6777 return true;
6778 }
6779 case GL_POLYGON_OFFSET_FACTOR:
6780 case GL_POLYGON_OFFSET_UNITS:
6781 case GL_SAMPLE_COVERAGE_VALUE:
6782 case GL_DEPTH_CLEAR_VALUE:
6783 case GL_LINE_WIDTH:
6784 {
6785 *type = GL_FLOAT;
6786 *numParams = 1;
6787 return true;
6788 }
6789 case GL_ALIASED_LINE_WIDTH_RANGE:
6790 case GL_ALIASED_POINT_SIZE_RANGE:
6791 case GL_DEPTH_RANGE:
6792 {
6793 *type = GL_FLOAT;
6794 *numParams = 2;
6795 return true;
6796 }
6797 case GL_COLOR_CLEAR_VALUE:
6798 case GL_BLEND_COLOR:
6799 {
6800 *type = GL_FLOAT;
6801 *numParams = 4;
6802 return true;
6803 }
6804 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6805 if (!getExtensions().textureFilterAnisotropic)
6806 {
6807 return false;
6808 }
6809 *type = GL_FLOAT;
6810 *numParams = 1;
6811 return true;
6812 case GL_TIMESTAMP_EXT:
6813 if (!getExtensions().disjointTimerQuery)
6814 {
6815 return false;
6816 }
6817 *type = GL_INT_64_ANGLEX;
6818 *numParams = 1;
6819 return true;
6820 case GL_GPU_DISJOINT_EXT:
6821 if (!getExtensions().disjointTimerQuery)
6822 {
6823 return false;
6824 }
6825 *type = GL_INT;
6826 *numParams = 1;
6827 return true;
6828 case GL_COVERAGE_MODULATION_CHROMIUM:
6829 if (!getExtensions().framebufferMixedSamples)
6830 {
6831 return false;
6832 }
6833 *type = GL_INT;
6834 *numParams = 1;
6835 return true;
6836 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6837 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6838 {
6839 return false;
6840 }
6841 *type = GL_INT;
6842 *numParams = 1;
6843 return true;
6844 }
6845
6846 if (getExtensions().debug)
6847 {
6848 switch (pname)
6849 {
6850 case GL_DEBUG_LOGGED_MESSAGES:
6851 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6852 case GL_DEBUG_GROUP_STACK_DEPTH:
6853 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6854 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6855 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6856 case GL_MAX_LABEL_LENGTH:
6857 *type = GL_INT;
6858 *numParams = 1;
6859 return true;
6860
6861 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6862 case GL_DEBUG_OUTPUT:
6863 *type = GL_BOOL;
6864 *numParams = 1;
6865 return true;
6866 }
6867 }
6868
6869 if (getExtensions().multisampleCompatibility)
6870 {
6871 switch (pname)
6872 {
6873 case GL_MULTISAMPLE_EXT:
6874 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6875 *type = GL_BOOL;
6876 *numParams = 1;
6877 return true;
6878 }
6879 }
6880
6881 if (getExtensions().pathRendering)
6882 {
6883 switch (pname)
6884 {
6885 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6886 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6887 *type = GL_FLOAT;
6888 *numParams = 16;
6889 return true;
6890 }
6891 }
6892
6893 if (getExtensions().bindGeneratesResource)
6894 {
6895 switch (pname)
6896 {
6897 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6898 *type = GL_BOOL;
6899 *numParams = 1;
6900 return true;
6901 }
6902 }
6903
6904 if (getExtensions().clientArrays)
6905 {
6906 switch (pname)
6907 {
6908 case GL_CLIENT_ARRAYS_ANGLE:
6909 *type = GL_BOOL;
6910 *numParams = 1;
6911 return true;
6912 }
6913 }
6914
6915 if (getExtensions().sRGBWriteControl)
6916 {
6917 switch (pname)
6918 {
6919 case GL_FRAMEBUFFER_SRGB_EXT:
6920 *type = GL_BOOL;
6921 *numParams = 1;
6922 return true;
6923 }
6924 }
6925
6926 if (getExtensions().robustResourceInitialization &&
6927 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6928 {
6929 *type = GL_BOOL;
6930 *numParams = 1;
6931 return true;
6932 }
6933
6934 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6935 {
6936 *type = GL_BOOL;
6937 *numParams = 1;
6938 return true;
6939 }
6940
6941 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6942 switch (pname)
6943 {
6944 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6945 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6946 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6947 {
6948 return false;
6949 }
6950 *type = GL_INT;
6951 *numParams = 1;
6952 return true;
6953
6954 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6955 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6956 {
6957 return false;
6958 }
6959 *type = GL_INT;
6960 *numParams = 1;
6961 return true;
6962
6963 case GL_PROGRAM_BINARY_FORMATS_OES:
6964 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6965 {
6966 return false;
6967 }
6968 *type = GL_INT;
6969 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6970 return true;
6971
6972 case GL_PACK_ROW_LENGTH:
6973 case GL_PACK_SKIP_ROWS:
6974 case GL_PACK_SKIP_PIXELS:
6975 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6976 {
6977 return false;
6978 }
6979 *type = GL_INT;
6980 *numParams = 1;
6981 return true;
6982 case GL_UNPACK_ROW_LENGTH:
6983 case GL_UNPACK_SKIP_ROWS:
6984 case GL_UNPACK_SKIP_PIXELS:
6985 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6986 {
6987 return false;
6988 }
6989 *type = GL_INT;
6990 *numParams = 1;
6991 return true;
6992 case GL_VERTEX_ARRAY_BINDING:
6993 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6994 {
6995 return false;
6996 }
6997 *type = GL_INT;
6998 *numParams = 1;
6999 return true;
7000 case GL_PIXEL_PACK_BUFFER_BINDING:
7001 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7002 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7003 {
7004 return false;
7005 }
7006 *type = GL_INT;
7007 *numParams = 1;
7008 return true;
7009 case GL_MAX_SAMPLES:
7010 {
7011 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7012 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7013 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7014 {
7015 return false;
7016 }
7017 *type = GL_INT;
7018 *numParams = 1;
7019 return true;
7020
7021 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7022 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7023 {
7024 return false;
7025 }
7026 *type = GL_INT;
7027 *numParams = 1;
7028 return true;
7029 }
7030 }
7031
7032 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7033 {
7034 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7035 {
7036 return false;
7037 }
7038 *type = GL_INT;
7039 *numParams = 1;
7040 return true;
7041 }
7042
7043 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7044 {
7045 *type = GL_INT;
7046 *numParams = 1;
7047 return true;
7048 }
7049
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007050 if (getClientVersion() < Version(2, 0))
7051 {
7052 switch (pname)
7053 {
7054 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007055 case GL_CLIENT_ACTIVE_TEXTURE:
7056 case GL_MATRIX_MODE:
7057 case GL_MAX_TEXTURE_UNITS:
7058 case GL_MAX_MODELVIEW_STACK_DEPTH:
7059 case GL_MAX_PROJECTION_STACK_DEPTH:
7060 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007061 case GL_VERTEX_ARRAY_STRIDE:
7062 case GL_NORMAL_ARRAY_STRIDE:
7063 case GL_COLOR_ARRAY_STRIDE:
7064 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7065 case GL_VERTEX_ARRAY_SIZE:
7066 case GL_COLOR_ARRAY_SIZE:
7067 case GL_TEXTURE_COORD_ARRAY_SIZE:
7068 case GL_VERTEX_ARRAY_TYPE:
7069 case GL_NORMAL_ARRAY_TYPE:
7070 case GL_COLOR_ARRAY_TYPE:
7071 case GL_TEXTURE_COORD_ARRAY_TYPE:
7072 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7073 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7074 case GL_COLOR_ARRAY_BUFFER_BINDING:
7075 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7076 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7077 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7078 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007079 *type = GL_INT;
7080 *numParams = 1;
7081 return true;
7082 case GL_ALPHA_TEST_REF:
7083 *type = GL_FLOAT;
7084 *numParams = 1;
7085 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007086 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007087 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007088 *type = GL_FLOAT;
7089 *numParams = 4;
7090 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007091 case GL_CURRENT_NORMAL:
7092 *type = GL_FLOAT;
7093 *numParams = 3;
7094 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007095 case GL_MODELVIEW_MATRIX:
7096 case GL_PROJECTION_MATRIX:
7097 case GL_TEXTURE_MATRIX:
7098 *type = GL_FLOAT;
7099 *numParams = 16;
7100 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007101 }
7102 }
7103
Jamie Madill5b772312018-03-08 20:28:32 -05007104 if (getClientVersion() < Version(3, 0))
7105 {
7106 return false;
7107 }
7108
7109 // Check for ES3.0+ parameter names
7110 switch (pname)
7111 {
7112 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7113 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7114 case GL_UNIFORM_BUFFER_BINDING:
7115 case GL_TRANSFORM_FEEDBACK_BINDING:
7116 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7117 case GL_COPY_READ_BUFFER_BINDING:
7118 case GL_COPY_WRITE_BUFFER_BINDING:
7119 case GL_SAMPLER_BINDING:
7120 case GL_READ_BUFFER:
7121 case GL_TEXTURE_BINDING_3D:
7122 case GL_TEXTURE_BINDING_2D_ARRAY:
7123 case GL_MAX_3D_TEXTURE_SIZE:
7124 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7125 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7126 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7127 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7128 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7129 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7130 case GL_MAX_VARYING_COMPONENTS:
7131 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7132 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7133 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7134 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7135 case GL_NUM_EXTENSIONS:
7136 case GL_MAJOR_VERSION:
7137 case GL_MINOR_VERSION:
7138 case GL_MAX_ELEMENTS_INDICES:
7139 case GL_MAX_ELEMENTS_VERTICES:
7140 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7141 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7142 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7143 case GL_UNPACK_IMAGE_HEIGHT:
7144 case GL_UNPACK_SKIP_IMAGES:
7145 {
7146 *type = GL_INT;
7147 *numParams = 1;
7148 return true;
7149 }
7150
7151 case GL_MAX_ELEMENT_INDEX:
7152 case GL_MAX_UNIFORM_BLOCK_SIZE:
7153 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7154 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7155 case GL_MAX_SERVER_WAIT_TIMEOUT:
7156 {
7157 *type = GL_INT_64_ANGLEX;
7158 *numParams = 1;
7159 return true;
7160 }
7161
7162 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7163 case GL_TRANSFORM_FEEDBACK_PAUSED:
7164 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7165 case GL_RASTERIZER_DISCARD:
7166 {
7167 *type = GL_BOOL;
7168 *numParams = 1;
7169 return true;
7170 }
7171
7172 case GL_MAX_TEXTURE_LOD_BIAS:
7173 {
7174 *type = GL_FLOAT;
7175 *numParams = 1;
7176 return true;
7177 }
7178 }
7179
7180 if (getExtensions().requestExtension)
7181 {
7182 switch (pname)
7183 {
7184 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7185 *type = GL_INT;
7186 *numParams = 1;
7187 return true;
7188 }
7189 }
7190
7191 if (getClientVersion() < Version(3, 1))
7192 {
7193 return false;
7194 }
7195
7196 switch (pname)
7197 {
7198 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7199 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7200 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7201 case GL_MAX_FRAMEBUFFER_WIDTH:
7202 case GL_MAX_FRAMEBUFFER_HEIGHT:
7203 case GL_MAX_FRAMEBUFFER_SAMPLES:
7204 case GL_MAX_SAMPLE_MASK_WORDS:
7205 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7206 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7207 case GL_MAX_INTEGER_SAMPLES:
7208 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7209 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7210 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7211 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7212 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7213 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7214 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7215 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7216 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7217 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7218 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7219 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7220 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7221 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7222 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7223 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7224 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7225 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7226 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7227 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7228 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7229 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7230 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7231 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7232 case GL_MAX_UNIFORM_LOCATIONS:
7233 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7234 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7235 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7236 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7237 case GL_MAX_IMAGE_UNITS:
7238 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7239 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7240 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7241 case GL_SHADER_STORAGE_BUFFER_BINDING:
7242 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7243 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7244 *type = GL_INT;
7245 *numParams = 1;
7246 return true;
7247 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7248 *type = GL_INT_64_ANGLEX;
7249 *numParams = 1;
7250 return true;
7251 case GL_SAMPLE_MASK:
7252 *type = GL_BOOL;
7253 *numParams = 1;
7254 return true;
7255 }
7256
7257 if (getExtensions().geometryShader)
7258 {
7259 switch (pname)
7260 {
7261 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7262 case GL_LAYER_PROVOKING_VERTEX_EXT:
7263 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7264 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7265 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7266 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7267 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7268 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7269 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7270 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7271 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7272 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7273 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7274 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7275 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7276 *type = GL_INT;
7277 *numParams = 1;
7278 return true;
7279 }
7280 }
7281
7282 return false;
7283}
7284
7285bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7286{
7287 if (getClientVersion() < Version(3, 0))
7288 {
7289 return false;
7290 }
7291
7292 switch (target)
7293 {
7294 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7295 case GL_UNIFORM_BUFFER_BINDING:
7296 {
7297 *type = GL_INT;
7298 *numParams = 1;
7299 return true;
7300 }
7301 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7302 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7303 case GL_UNIFORM_BUFFER_START:
7304 case GL_UNIFORM_BUFFER_SIZE:
7305 {
7306 *type = GL_INT_64_ANGLEX;
7307 *numParams = 1;
7308 return true;
7309 }
7310 }
7311
7312 if (getClientVersion() < Version(3, 1))
7313 {
7314 return false;
7315 }
7316
7317 switch (target)
7318 {
7319 case GL_IMAGE_BINDING_LAYERED:
7320 {
7321 *type = GL_BOOL;
7322 *numParams = 1;
7323 return true;
7324 }
7325 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7326 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7327 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7328 case GL_SHADER_STORAGE_BUFFER_BINDING:
7329 case GL_VERTEX_BINDING_BUFFER:
7330 case GL_VERTEX_BINDING_DIVISOR:
7331 case GL_VERTEX_BINDING_OFFSET:
7332 case GL_VERTEX_BINDING_STRIDE:
7333 case GL_SAMPLE_MASK_VALUE:
7334 case GL_IMAGE_BINDING_NAME:
7335 case GL_IMAGE_BINDING_LEVEL:
7336 case GL_IMAGE_BINDING_LAYER:
7337 case GL_IMAGE_BINDING_ACCESS:
7338 case GL_IMAGE_BINDING_FORMAT:
7339 {
7340 *type = GL_INT;
7341 *numParams = 1;
7342 return true;
7343 }
7344 case GL_ATOMIC_COUNTER_BUFFER_START:
7345 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7346 case GL_SHADER_STORAGE_BUFFER_START:
7347 case GL_SHADER_STORAGE_BUFFER_SIZE:
7348 {
7349 *type = GL_INT_64_ANGLEX;
7350 *numParams = 1;
7351 return true;
7352 }
7353 }
7354
7355 return false;
7356}
7357
7358Program *Context::getProgram(GLuint handle) const
7359{
7360 return mState.mShaderPrograms->getProgram(handle);
7361}
7362
7363Shader *Context::getShader(GLuint handle) const
7364{
7365 return mState.mShaderPrograms->getShader(handle);
7366}
7367
7368bool Context::isTextureGenerated(GLuint texture) const
7369{
7370 return mState.mTextures->isHandleGenerated(texture);
7371}
7372
7373bool Context::isBufferGenerated(GLuint buffer) const
7374{
7375 return mState.mBuffers->isHandleGenerated(buffer);
7376}
7377
7378bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7379{
7380 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7381}
7382
7383bool Context::isFramebufferGenerated(GLuint framebuffer) const
7384{
7385 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7386}
7387
7388bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7389{
7390 return mState.mPipelines->isHandleGenerated(pipeline);
7391}
7392
7393bool Context::usingDisplayTextureShareGroup() const
7394{
7395 return mDisplayTextureShareGroup;
7396}
7397
7398GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7399{
7400 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7401 internalformat == GL_DEPTH_STENCIL
7402 ? GL_DEPTH24_STENCIL8
7403 : internalformat;
7404}
7405
Jamie Madillc29968b2016-01-20 11:17:23 -05007406} // namespace gl