blob: 236f133df4297e5b1ffa65238eede8b5f1dfad0d [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 Yangd0febe72018-05-17 22:36:52 -07001685 case GL_MAX_LIGHTS:
1686 *params = mCaps.maxLights;
1687 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001688 // GLES1 emulation: Vertex attribute queries
1689 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1690 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1691 case GL_COLOR_ARRAY_BUFFER_BINDING:
1692 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1693 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1694 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1695 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1696 break;
1697 case GL_VERTEX_ARRAY_STRIDE:
1698 case GL_NORMAL_ARRAY_STRIDE:
1699 case GL_COLOR_ARRAY_STRIDE:
1700 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1701 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1702 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1703 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1704 break;
1705 case GL_VERTEX_ARRAY_SIZE:
1706 case GL_COLOR_ARRAY_SIZE:
1707 case GL_TEXTURE_COORD_ARRAY_SIZE:
1708 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1709 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1710 break;
1711 case GL_VERTEX_ARRAY_TYPE:
1712 case GL_COLOR_ARRAY_TYPE:
1713 case GL_NORMAL_ARRAY_TYPE:
1714 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1715 case GL_TEXTURE_COORD_ARRAY_TYPE:
1716 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1717 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1718 break;
1719
Jamie Madill231c7f52017-04-26 13:45:37 -04001720 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001721 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001722 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001723 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001724}
1725
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001726void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001727{
Shannon Woods53a94a82014-06-24 15:20:36 -04001728 // Queries about context capabilities and maximums are answered by Context.
1729 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001730 switch (pname)
1731 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001732 case GL_MAX_ELEMENT_INDEX:
1733 *params = mCaps.maxElementIndex;
1734 break;
1735 case GL_MAX_UNIFORM_BLOCK_SIZE:
1736 *params = mCaps.maxUniformBlockSize;
1737 break;
1738 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1739 *params = mCaps.maxCombinedVertexUniformComponents;
1740 break;
1741 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1742 *params = mCaps.maxCombinedFragmentUniformComponents;
1743 break;
1744 case GL_MAX_SERVER_WAIT_TIMEOUT:
1745 *params = mCaps.maxServerWaitTimeout;
1746 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001747
Jamie Madill231c7f52017-04-26 13:45:37 -04001748 // GL_EXT_disjoint_timer_query
1749 case GL_TIMESTAMP_EXT:
1750 *params = mImplementation->getTimestamp();
1751 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001752
Jamie Madill231c7f52017-04-26 13:45:37 -04001753 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1754 *params = mCaps.maxShaderStorageBlockSize;
1755 break;
1756 default:
1757 UNREACHABLE();
1758 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001759 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001760}
1761
Geoff Lang70d0f492015-12-10 17:45:46 -05001762void Context::getPointerv(GLenum pname, void **params) const
1763{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001764 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001765}
1766
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001767void Context::getPointervRobustANGLERobust(GLenum pname,
1768 GLsizei bufSize,
1769 GLsizei *length,
1770 void **params)
1771{
1772 UNIMPLEMENTED();
1773}
1774
Martin Radev66fb8202016-07-28 11:45:20 +03001775void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001776{
Shannon Woods53a94a82014-06-24 15:20:36 -04001777 // Queries about context capabilities and maximums are answered by Context.
1778 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001779
1780 GLenum nativeType;
1781 unsigned int numParams;
1782 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1783 ASSERT(queryStatus);
1784
1785 if (nativeType == GL_INT)
1786 {
1787 switch (target)
1788 {
1789 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1790 ASSERT(index < 3u);
1791 *data = mCaps.maxComputeWorkGroupCount[index];
1792 break;
1793 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1794 ASSERT(index < 3u);
1795 *data = mCaps.maxComputeWorkGroupSize[index];
1796 break;
1797 default:
1798 mGLState.getIntegeri_v(target, index, data);
1799 }
1800 }
1801 else
1802 {
1803 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1804 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001805}
1806
Brandon Jones59770802018-04-02 13:18:42 -07001807void Context::getIntegeri_vRobust(GLenum target,
1808 GLuint index,
1809 GLsizei bufSize,
1810 GLsizei *length,
1811 GLint *data)
1812{
1813 getIntegeri_v(target, index, data);
1814}
1815
Martin Radev66fb8202016-07-28 11:45:20 +03001816void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001817{
Shannon Woods53a94a82014-06-24 15:20:36 -04001818 // Queries about context capabilities and maximums are answered by Context.
1819 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001820
1821 GLenum nativeType;
1822 unsigned int numParams;
1823 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1824 ASSERT(queryStatus);
1825
1826 if (nativeType == GL_INT_64_ANGLEX)
1827 {
1828 mGLState.getInteger64i_v(target, index, data);
1829 }
1830 else
1831 {
1832 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1833 }
1834}
1835
Brandon Jones59770802018-04-02 13:18:42 -07001836void Context::getInteger64i_vRobust(GLenum target,
1837 GLuint index,
1838 GLsizei bufSize,
1839 GLsizei *length,
1840 GLint64 *data)
1841{
1842 getInteger64i_v(target, index, data);
1843}
1844
Martin Radev66fb8202016-07-28 11:45:20 +03001845void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1846{
1847 // Queries about context capabilities and maximums are answered by Context.
1848 // Queries about current GL state values are answered by State.
1849
1850 GLenum nativeType;
1851 unsigned int numParams;
1852 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1853 ASSERT(queryStatus);
1854
1855 if (nativeType == GL_BOOL)
1856 {
1857 mGLState.getBooleani_v(target, index, data);
1858 }
1859 else
1860 {
1861 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1862 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001863}
1864
Brandon Jones59770802018-04-02 13:18:42 -07001865void Context::getBooleani_vRobust(GLenum target,
1866 GLuint index,
1867 GLsizei bufSize,
1868 GLsizei *length,
1869 GLboolean *data)
1870{
1871 getBooleani_v(target, index, data);
1872}
1873
Corentin Wallez336129f2017-10-17 15:55:40 -04001874void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001875{
1876 Buffer *buffer = mGLState.getTargetBuffer(target);
1877 QueryBufferParameteriv(buffer, pname, params);
1878}
1879
Brandon Jones59770802018-04-02 13:18:42 -07001880void Context::getBufferParameterivRobust(BufferBinding target,
1881 GLenum pname,
1882 GLsizei bufSize,
1883 GLsizei *length,
1884 GLint *params)
1885{
1886 getBufferParameteriv(target, pname, params);
1887}
1888
He Yunchao010e4db2017-03-03 14:22:06 +08001889void Context::getFramebufferAttachmentParameteriv(GLenum target,
1890 GLenum attachment,
1891 GLenum pname,
1892 GLint *params)
1893{
1894 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001895 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001896}
1897
Brandon Jones59770802018-04-02 13:18:42 -07001898void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1899 GLenum attachment,
1900 GLenum pname,
1901 GLsizei bufSize,
1902 GLsizei *length,
1903 GLint *params)
1904{
1905 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1906}
1907
He Yunchao010e4db2017-03-03 14:22:06 +08001908void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1909{
1910 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1911 QueryRenderbufferiv(this, renderbuffer, pname, params);
1912}
1913
Brandon Jones59770802018-04-02 13:18:42 -07001914void Context::getRenderbufferParameterivRobust(GLenum target,
1915 GLenum pname,
1916 GLsizei bufSize,
1917 GLsizei *length,
1918 GLint *params)
1919{
1920 getRenderbufferParameteriv(target, pname, params);
1921}
1922
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001923void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001924{
1925 Texture *texture = getTargetTexture(target);
1926 QueryTexParameterfv(texture, pname, params);
1927}
1928
Brandon Jones59770802018-04-02 13:18:42 -07001929void Context::getTexParameterfvRobust(TextureType target,
1930 GLenum pname,
1931 GLsizei bufSize,
1932 GLsizei *length,
1933 GLfloat *params)
1934{
1935 getTexParameterfv(target, pname, params);
1936}
1937
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001938void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001939{
1940 Texture *texture = getTargetTexture(target);
1941 QueryTexParameteriv(texture, pname, params);
1942}
Jiajia Qin5451d532017-11-16 17:16:34 +08001943
Brandon Jones59770802018-04-02 13:18:42 -07001944void Context::getTexParameterivRobust(TextureType target,
1945 GLenum pname,
1946 GLsizei bufSize,
1947 GLsizei *length,
1948 GLint *params)
1949{
1950 getTexParameteriv(target, pname, params);
1951}
1952
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001953void Context::getTexParameterIivRobust(TextureType target,
1954 GLenum pname,
1955 GLsizei bufSize,
1956 GLsizei *length,
1957 GLint *params)
1958{
1959 UNIMPLEMENTED();
1960}
1961
1962void Context::getTexParameterIuivRobust(TextureType target,
1963 GLenum pname,
1964 GLsizei bufSize,
1965 GLsizei *length,
1966 GLuint *params)
1967{
1968 UNIMPLEMENTED();
1969}
1970
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001971void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001972{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001973 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001974 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001975}
1976
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001977void Context::getTexLevelParameterivRobust(TextureTarget target,
1978 GLint level,
1979 GLenum pname,
1980 GLsizei bufSize,
1981 GLsizei *length,
1982 GLint *params)
1983{
1984 UNIMPLEMENTED();
1985}
1986
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001987void Context::getTexLevelParameterfv(TextureTarget target,
1988 GLint level,
1989 GLenum pname,
1990 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001991{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001992 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001993 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001994}
1995
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001996void Context::getTexLevelParameterfvRobust(TextureTarget target,
1997 GLint level,
1998 GLenum pname,
1999 GLsizei bufSize,
2000 GLsizei *length,
2001 GLfloat *params)
2002{
2003 UNIMPLEMENTED();
2004}
2005
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002006void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002007{
2008 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002009 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002010 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002011}
2012
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002013void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002014{
2015 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002016 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002017 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002018}
2019
Brandon Jones59770802018-04-02 13:18:42 -07002020void Context::texParameterfvRobust(TextureType target,
2021 GLenum pname,
2022 GLsizei bufSize,
2023 const GLfloat *params)
2024{
2025 texParameterfv(target, pname, params);
2026}
2027
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002028void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002029{
2030 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002031 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002032 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002033}
2034
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002035void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002036{
2037 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002038 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002039 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002040}
2041
Brandon Jones59770802018-04-02 13:18:42 -07002042void Context::texParameterivRobust(TextureType target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 const GLint *params)
2046{
2047 texParameteriv(target, pname, params);
2048}
2049
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002050void Context::texParameterIivRobust(TextureType target,
2051 GLenum pname,
2052 GLsizei bufSize,
2053 const GLint *params)
2054{
2055 UNIMPLEMENTED();
2056}
2057
2058void Context::texParameterIuivRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 const GLuint *params)
2062{
2063 UNIMPLEMENTED();
2064}
2065
Jamie Madill493f9572018-05-24 19:52:15 -04002066void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002067{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002068 // No-op if zero count
2069 if (count == 0)
2070 {
2071 return;
2072 }
2073
Jamie Madill05b35b22017-10-03 09:01:44 -04002074 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002075 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002076 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002077}
2078
Jamie Madill493f9572018-05-24 19:52:15 -04002079void Context::drawArraysInstanced(PrimitiveMode mode,
2080 GLint first,
2081 GLsizei count,
2082 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002083{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002084 // No-op if zero count
2085 if (count == 0 || instanceCount == 0)
2086 {
2087 return;
2088 }
2089
Jamie Madill05b35b22017-10-03 09:01:44 -04002090 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002091 ANGLE_CONTEXT_TRY(
2092 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002093 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2094 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002095}
2096
Jamie Madill493f9572018-05-24 19:52:15 -04002097void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002098{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002099 // No-op if zero count
2100 if (count == 0)
2101 {
2102 return;
2103 }
2104
Jamie Madill05b35b22017-10-03 09:01:44 -04002105 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002106 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002107}
2108
Jamie Madill493f9572018-05-24 19:52:15 -04002109void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002110 GLsizei count,
2111 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002112 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002113 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002114{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002115 // No-op if zero count
2116 if (count == 0 || instances == 0)
2117 {
2118 return;
2119 }
2120
Jamie Madill05b35b22017-10-03 09:01:44 -04002121 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002122 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002123 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002124}
2125
Jamie Madill493f9572018-05-24 19:52:15 -04002126void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002127 GLuint start,
2128 GLuint end,
2129 GLsizei count,
2130 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002131 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002132{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002133 // No-op if zero count
2134 if (count == 0)
2135 {
2136 return;
2137 }
2138
Jamie Madill05b35b22017-10-03 09:01:44 -04002139 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002140 ANGLE_CONTEXT_TRY(
2141 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002142}
2143
Jamie Madill493f9572018-05-24 19:52:15 -04002144void Context::drawArraysIndirect(PrimitiveMode mode, 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->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002148}
2149
Jamie Madill493f9572018-05-24 19:52:15 -04002150void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002151{
Jamie Madill05b35b22017-10-03 09:01:44 -04002152 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002153 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002154}
2155
Jamie Madill675fe712016-12-19 13:07:54 -05002156void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002157{
Jamie Madillafa02a22017-11-23 12:57:38 -05002158 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002159}
2160
Jamie Madill675fe712016-12-19 13:07:54 -05002161void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002162{
Jamie Madillafa02a22017-11-23 12:57:38 -05002163 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002164}
2165
Austin Kinross6ee1e782015-05-29 17:05:37 -07002166void Context::insertEventMarker(GLsizei length, const char *marker)
2167{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002168 ASSERT(mImplementation);
2169 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002170}
2171
2172void Context::pushGroupMarker(GLsizei length, const char *marker)
2173{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002174 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002175
2176 if (marker == nullptr)
2177 {
2178 // From the EXT_debug_marker spec,
2179 // "If <marker> is null then an empty string is pushed on the stack."
2180 mImplementation->pushGroupMarker(length, "");
2181 }
2182 else
2183 {
2184 mImplementation->pushGroupMarker(length, marker);
2185 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002186}
2187
2188void Context::popGroupMarker()
2189{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002190 ASSERT(mImplementation);
2191 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002192}
2193
Geoff Langd8605522016-04-13 10:19:12 -04002194void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2195{
2196 Program *programObject = getProgram(program);
2197 ASSERT(programObject);
2198
2199 programObject->bindUniformLocation(location, name);
2200}
2201
Brandon Jones59770802018-04-02 13:18:42 -07002202void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002204 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002205}
2206
Brandon Jones59770802018-04-02 13:18:42 -07002207void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002208{
2209 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2210}
2211
Brandon Jones59770802018-04-02 13:18:42 -07002212void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002213{
2214 GLfloat I[16];
2215 angle::Matrix<GLfloat>::setToIdentity(I);
2216
2217 mGLState.loadPathRenderingMatrix(matrixMode, I);
2218}
2219
2220void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2221{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002222 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002223 if (!pathObj)
2224 return;
2225
2226 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002227 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228
2229 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2230}
2231
2232void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2233{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002234 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002235 if (!pathObj)
2236 return;
2237
2238 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002239 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240
2241 mImplementation->stencilStrokePath(pathObj, reference, mask);
2242}
2243
2244void Context::coverFillPath(GLuint path, GLenum coverMode)
2245{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002246 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002247 if (!pathObj)
2248 return;
2249
2250 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002251 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252
2253 mImplementation->coverFillPath(pathObj, coverMode);
2254}
2255
2256void Context::coverStrokePath(GLuint path, GLenum coverMode)
2257{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002258 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002259 if (!pathObj)
2260 return;
2261
2262 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002263 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002264
2265 mImplementation->coverStrokePath(pathObj, coverMode);
2266}
2267
2268void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2269{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002270 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002271 if (!pathObj)
2272 return;
2273
2274 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002275 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002276
2277 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2278}
2279
2280void Context::stencilThenCoverStrokePath(GLuint path,
2281 GLint reference,
2282 GLuint mask,
2283 GLenum coverMode)
2284{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002285 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002286 if (!pathObj)
2287 return;
2288
2289 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002290 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002291
2292 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2293}
2294
Sami Väisänend59ca052016-06-21 16:10:00 +03002295void Context::coverFillPathInstanced(GLsizei numPaths,
2296 GLenum pathNameType,
2297 const void *paths,
2298 GLuint pathBase,
2299 GLenum coverMode,
2300 GLenum transformType,
2301 const GLfloat *transformValues)
2302{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002303 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002304
2305 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002306 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002307
2308 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2309}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002310
Sami Väisänend59ca052016-06-21 16:10:00 +03002311void Context::coverStrokePathInstanced(GLsizei numPaths,
2312 GLenum pathNameType,
2313 const void *paths,
2314 GLuint pathBase,
2315 GLenum coverMode,
2316 GLenum transformType,
2317 const GLfloat *transformValues)
2318{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002319 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002320
2321 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002322 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002323
2324 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2325 transformValues);
2326}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002327
Sami Väisänend59ca052016-06-21 16:10:00 +03002328void Context::stencilFillPathInstanced(GLsizei numPaths,
2329 GLenum pathNameType,
2330 const void *paths,
2331 GLuint pathBase,
2332 GLenum fillMode,
2333 GLuint mask,
2334 GLenum transformType,
2335 const GLfloat *transformValues)
2336{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002337 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002338
2339 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002340 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002341
2342 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2343 transformValues);
2344}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002345
Sami Väisänend59ca052016-06-21 16:10:00 +03002346void Context::stencilStrokePathInstanced(GLsizei numPaths,
2347 GLenum pathNameType,
2348 const void *paths,
2349 GLuint pathBase,
2350 GLint reference,
2351 GLuint mask,
2352 GLenum transformType,
2353 const GLfloat *transformValues)
2354{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002355 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002356
2357 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002358 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002359
2360 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2361 transformValues);
2362}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002363
Sami Väisänend59ca052016-06-21 16:10:00 +03002364void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2365 GLenum pathNameType,
2366 const void *paths,
2367 GLuint pathBase,
2368 GLenum fillMode,
2369 GLuint mask,
2370 GLenum coverMode,
2371 GLenum transformType,
2372 const GLfloat *transformValues)
2373{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002374 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002375
2376 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002377 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002378
2379 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2380 transformType, transformValues);
2381}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002382
Sami Väisänend59ca052016-06-21 16:10:00 +03002383void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2384 GLenum pathNameType,
2385 const void *paths,
2386 GLuint pathBase,
2387 GLint reference,
2388 GLuint mask,
2389 GLenum coverMode,
2390 GLenum transformType,
2391 const GLfloat *transformValues)
2392{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002393 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002394
2395 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002396 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002397
2398 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2399 transformType, transformValues);
2400}
2401
Sami Väisänen46eaa942016-06-29 10:26:37 +03002402void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2403{
2404 auto *programObject = getProgram(program);
2405
2406 programObject->bindFragmentInputLocation(location, name);
2407}
2408
2409void Context::programPathFragmentInputGen(GLuint program,
2410 GLint location,
2411 GLenum genMode,
2412 GLint components,
2413 const GLfloat *coeffs)
2414{
2415 auto *programObject = getProgram(program);
2416
Jamie Madillbd044ed2017-06-05 12:59:21 -04002417 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002418}
2419
jchen1015015f72017-03-16 13:54:21 +08002420GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2421{
jchen10fd7c3b52017-03-21 15:36:03 +08002422 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002423 return QueryProgramResourceIndex(programObject, programInterface, name);
2424}
2425
jchen10fd7c3b52017-03-21 15:36:03 +08002426void Context::getProgramResourceName(GLuint program,
2427 GLenum programInterface,
2428 GLuint index,
2429 GLsizei bufSize,
2430 GLsizei *length,
2431 GLchar *name)
2432{
2433 const auto *programObject = getProgram(program);
2434 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2435}
2436
jchen10191381f2017-04-11 13:59:04 +08002437GLint Context::getProgramResourceLocation(GLuint program,
2438 GLenum programInterface,
2439 const GLchar *name)
2440{
2441 const auto *programObject = getProgram(program);
2442 return QueryProgramResourceLocation(programObject, programInterface, name);
2443}
2444
jchen10880683b2017-04-12 16:21:55 +08002445void Context::getProgramResourceiv(GLuint program,
2446 GLenum programInterface,
2447 GLuint index,
2448 GLsizei propCount,
2449 const GLenum *props,
2450 GLsizei bufSize,
2451 GLsizei *length,
2452 GLint *params)
2453{
2454 const auto *programObject = getProgram(program);
2455 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2456 length, params);
2457}
2458
jchen10d9cd7b72017-08-30 15:04:25 +08002459void Context::getProgramInterfaceiv(GLuint program,
2460 GLenum programInterface,
2461 GLenum pname,
2462 GLint *params)
2463{
2464 const auto *programObject = getProgram(program);
2465 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2466}
2467
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002468void Context::getProgramInterfaceivRobust(GLuint program,
2469 GLenum programInterface,
2470 GLenum pname,
2471 GLsizei bufSize,
2472 GLsizei *length,
2473 GLint *params)
2474{
2475 UNIMPLEMENTED();
2476}
2477
Jamie Madill427064d2018-04-13 16:20:34 -04002478void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002479{
Geoff Lang7b19a492018-04-20 09:31:52 -04002480 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002481 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002482 GLenum code = error.getCode();
2483 mErrors.insert(code);
2484 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2485 {
2486 markContextLost();
2487 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002488
Geoff Langee6884e2017-11-09 16:51:11 -05002489 ASSERT(!error.getMessage().empty());
2490 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2491 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002492 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002493}
2494
2495// Get one of the recorded errors and clear its flag, if any.
2496// [OpenGL ES 2.0.24] section 2.5 page 13.
2497GLenum Context::getError()
2498{
Geoff Langda5777c2014-07-11 09:52:58 -04002499 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002500 {
Geoff Langda5777c2014-07-11 09:52:58 -04002501 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502 }
Geoff Langda5777c2014-07-11 09:52:58 -04002503 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504 {
Geoff Langda5777c2014-07-11 09:52:58 -04002505 GLenum error = *mErrors.begin();
2506 mErrors.erase(mErrors.begin());
2507 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002508 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509}
2510
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002511// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002512void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002513{
2514 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002515 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002516 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002517 mContextLostForced = true;
2518 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002519 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002520}
2521
Jamie Madill427064d2018-04-13 16:20:34 -04002522bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002523{
2524 return mContextLost;
2525}
2526
Jamie Madillfa920eb2018-01-04 11:45:50 -05002527GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002528{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002529 // Even if the application doesn't want to know about resets, we want to know
2530 // as it will allow us to skip all the calls.
2531 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002532 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002533 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002534 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002536 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002537
2538 // EXT_robustness, section 2.6: If the reset notification behavior is
2539 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2540 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2541 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002542 }
2543
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002544 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2545 // status should be returned at least once, and GL_NO_ERROR should be returned
2546 // once the device has finished resetting.
2547 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002549 ASSERT(mResetStatus == GL_NO_ERROR);
2550 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002551
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002552 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002553 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002554 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002555 }
2556 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002557 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002558 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002559 // If markContextLost was used to mark the context lost then
2560 // assume that is not recoverable, and continue to report the
2561 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002562 mResetStatus = mImplementation->getResetStatus();
2563 }
Jamie Madill893ab082014-05-16 16:56:10 -04002564
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002565 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002566}
2567
2568bool Context::isResetNotificationEnabled()
2569{
2570 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2571}
2572
Corentin Walleze3b10e82015-05-20 11:06:25 -04002573const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002574{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002575 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002576}
2577
2578EGLenum Context::getClientType() const
2579{
2580 return mClientType;
2581}
2582
2583EGLenum Context::getRenderBuffer() const
2584{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002585 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2586 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002587 {
2588 return EGL_NONE;
2589 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002590
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002591 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002592 ASSERT(backAttachment != nullptr);
2593 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002594}
2595
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002596VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002597{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002598 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002599 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2600 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002601 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002602 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2603 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002604
Jamie Madill96a483b2017-06-27 16:49:21 -04002605 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002606 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002607
2608 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002609}
2610
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002611TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002612{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002613 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002614 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2615 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002616 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002617 transformFeedback =
2618 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002619 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002620 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002621 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002622
2623 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002624}
2625
2626bool Context::isVertexArrayGenerated(GLuint vertexArray)
2627{
Jamie Madill96a483b2017-06-27 16:49:21 -04002628 ASSERT(mVertexArrayMap.contains(0));
2629 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002630}
2631
2632bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2633{
Jamie Madill96a483b2017-06-27 16:49:21 -04002634 ASSERT(mTransformFeedbackMap.contains(0));
2635 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002636}
2637
Shannon Woods53a94a82014-06-24 15:20:36 -04002638void Context::detachTexture(GLuint texture)
2639{
2640 // Simple pass-through to State's detachTexture method, as textures do not require
2641 // allocation map management either here or in the resource manager at detach time.
2642 // Zero textures are held by the Context, and we don't attempt to request them from
2643 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002644 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002645}
2646
James Darpinian4d9d4832018-03-13 12:43:28 -07002647void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002648{
Yuly Novikov5807a532015-12-03 13:01:22 -05002649 // Simple pass-through to State's detachBuffer method, since
2650 // only buffer attachments to container objects that are bound to the current context
2651 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002652
Yuly Novikov5807a532015-12-03 13:01:22 -05002653 // [OpenGL ES 3.2] section 5.1.2 page 45:
2654 // Attachments to unbound container objects, such as
2655 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2656 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002657 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002658}
2659
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660void Context::detachFramebuffer(GLuint framebuffer)
2661{
Shannon Woods53a94a82014-06-24 15:20:36 -04002662 // Framebuffer detachment is handled by Context, because 0 is a valid
2663 // Framebuffer object, and a pointer to it must be passed from Context
2664 // to State at binding time.
2665
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002667 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2668 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2669 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002671 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002672 {
2673 bindReadFramebuffer(0);
2674 }
2675
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002676 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002677 {
2678 bindDrawFramebuffer(0);
2679 }
2680}
2681
2682void Context::detachRenderbuffer(GLuint renderbuffer)
2683{
Jamie Madilla02315b2017-02-23 14:14:47 -05002684 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002685}
2686
Jamie Madill57a89722013-07-02 11:57:03 -04002687void Context::detachVertexArray(GLuint vertexArray)
2688{
Jamie Madill77a72f62015-04-14 11:18:32 -04002689 // Vertex array detachment is handled by Context, because 0 is a valid
2690 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002691 // binding time.
2692
Jamie Madill57a89722013-07-02 11:57:03 -04002693 // [OpenGL ES 3.0.2] section 2.10 page 43:
2694 // If a vertex array object that is currently bound is deleted, the binding
2695 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002696 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002697 {
2698 bindVertexArray(0);
2699 }
2700}
2701
Geoff Langc8058452014-02-03 12:04:11 -05002702void Context::detachTransformFeedback(GLuint transformFeedback)
2703{
Corentin Walleza2257da2016-04-19 16:43:12 -04002704 // Transform feedback detachment is handled by Context, because 0 is a valid
2705 // transform feedback, and a pointer to it must be passed from Context to State at
2706 // binding time.
2707
2708 // The OpenGL specification doesn't mention what should happen when the currently bound
2709 // transform feedback object is deleted. Since it is a container object, we treat it like
2710 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002711 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002712 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002713 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002714 }
Geoff Langc8058452014-02-03 12:04:11 -05002715}
2716
Jamie Madilldc356042013-07-19 16:36:57 -04002717void Context::detachSampler(GLuint sampler)
2718{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002719 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002720}
2721
Yunchao Hea336b902017-08-02 16:05:21 +08002722void Context::detachProgramPipeline(GLuint pipeline)
2723{
2724 mGLState.detachProgramPipeline(this, pipeline);
2725}
2726
Jamie Madill3ef140a2017-08-26 23:11:21 -04002727void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002728{
Shaodde78e82017-05-22 14:13:27 +08002729 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730}
2731
Jamie Madille29d1672013-07-19 16:36:57 -04002732void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2733{
Geoff Langc1984ed2016-10-07 12:41:00 -04002734 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002735 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002736 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002737 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002738}
Jamie Madille29d1672013-07-19 16:36:57 -04002739
Geoff Langc1984ed2016-10-07 12:41:00 -04002740void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2741{
2742 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002743 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002744 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002745 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002746}
2747
Brandon Jones59770802018-04-02 13:18:42 -07002748void Context::samplerParameterivRobust(GLuint sampler,
2749 GLenum pname,
2750 GLsizei bufSize,
2751 const GLint *param)
2752{
2753 samplerParameteriv(sampler, pname, param);
2754}
2755
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002756void Context::samplerParameterIivRobust(GLuint sampler,
2757 GLenum pname,
2758 GLsizei bufSize,
2759 const GLint *param)
2760{
2761 UNIMPLEMENTED();
2762}
2763
2764void Context::samplerParameterIuivRobust(GLuint sampler,
2765 GLenum pname,
2766 GLsizei bufSize,
2767 const GLuint *param)
2768{
2769 UNIMPLEMENTED();
2770}
2771
Jamie Madille29d1672013-07-19 16:36:57 -04002772void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2773{
Geoff Langc1984ed2016-10-07 12:41:00 -04002774 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002775 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002776 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002777 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002778}
2779
Geoff Langc1984ed2016-10-07 12:41:00 -04002780void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002781{
Geoff Langc1984ed2016-10-07 12:41:00 -04002782 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002783 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002784 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002785 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002786}
2787
Brandon Jones59770802018-04-02 13:18:42 -07002788void Context::samplerParameterfvRobust(GLuint sampler,
2789 GLenum pname,
2790 GLsizei bufSize,
2791 const GLfloat *param)
2792{
2793 samplerParameterfv(sampler, pname, param);
2794}
2795
Geoff Langc1984ed2016-10-07 12:41:00 -04002796void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002797{
Geoff Langc1984ed2016-10-07 12:41:00 -04002798 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002799 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002800 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002801 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002802}
Jamie Madill9675b802013-07-19 16:36:59 -04002803
Brandon Jones59770802018-04-02 13:18:42 -07002804void Context::getSamplerParameterivRobust(GLuint sampler,
2805 GLenum pname,
2806 GLsizei bufSize,
2807 GLsizei *length,
2808 GLint *params)
2809{
2810 getSamplerParameteriv(sampler, pname, params);
2811}
2812
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002813void Context::getSamplerParameterIivRobust(GLuint sampler,
2814 GLenum pname,
2815 GLsizei bufSize,
2816 GLsizei *length,
2817 GLint *params)
2818{
2819 UNIMPLEMENTED();
2820}
2821
2822void Context::getSamplerParameterIuivRobust(GLuint sampler,
2823 GLenum pname,
2824 GLsizei bufSize,
2825 GLsizei *length,
2826 GLuint *params)
2827{
2828 UNIMPLEMENTED();
2829}
2830
Geoff Langc1984ed2016-10-07 12:41:00 -04002831void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2832{
2833 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002834 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002835 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002836 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002837}
2838
Brandon Jones59770802018-04-02 13:18:42 -07002839void Context::getSamplerParameterfvRobust(GLuint sampler,
2840 GLenum pname,
2841 GLsizei bufSize,
2842 GLsizei *length,
2843 GLfloat *params)
2844{
2845 getSamplerParameterfv(sampler, pname, params);
2846}
2847
Olli Etuahof0fee072016-03-30 15:11:58 +03002848void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2849{
2850 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002851 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002852}
2853
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002854void Context::initRendererString()
2855{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002856 std::ostringstream rendererString;
2857 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002858 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002859 rendererString << ")";
2860
Geoff Langcec35902014-04-16 10:52:36 -04002861 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002862}
2863
Geoff Langc339c4e2016-11-29 10:37:36 -05002864void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002865{
Geoff Langc339c4e2016-11-29 10:37:36 -05002866 const Version &clientVersion = getClientVersion();
2867
2868 std::ostringstream versionString;
2869 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2870 << ANGLE_VERSION_STRING << ")";
2871 mVersionString = MakeStaticString(versionString.str());
2872
2873 std::ostringstream shadingLanguageVersionString;
2874 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2875 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2876 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2877 << ")";
2878 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002879}
2880
Geoff Langcec35902014-04-16 10:52:36 -04002881void Context::initExtensionStrings()
2882{
Geoff Langc339c4e2016-11-29 10:37:36 -05002883 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2884 std::ostringstream combinedStringStream;
2885 std::copy(strings.begin(), strings.end(),
2886 std::ostream_iterator<const char *>(combinedStringStream, " "));
2887 return MakeStaticString(combinedStringStream.str());
2888 };
2889
2890 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002891 for (const auto &extensionString : mExtensions.getStrings())
2892 {
2893 mExtensionStrings.push_back(MakeStaticString(extensionString));
2894 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002895 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002896
Geoff Langc339c4e2016-11-29 10:37:36 -05002897 mRequestableExtensionStrings.clear();
2898 for (const auto &extensionInfo : GetExtensionInfoMap())
2899 {
2900 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002901 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002902 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002903 {
2904 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2905 }
2906 }
2907 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002908}
2909
Geoff Langc339c4e2016-11-29 10:37:36 -05002910const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002911{
Geoff Langc339c4e2016-11-29 10:37:36 -05002912 switch (name)
2913 {
2914 case GL_VENDOR:
2915 return reinterpret_cast<const GLubyte *>("Google Inc.");
2916
2917 case GL_RENDERER:
2918 return reinterpret_cast<const GLubyte *>(mRendererString);
2919
2920 case GL_VERSION:
2921 return reinterpret_cast<const GLubyte *>(mVersionString);
2922
2923 case GL_SHADING_LANGUAGE_VERSION:
2924 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2925
2926 case GL_EXTENSIONS:
2927 return reinterpret_cast<const GLubyte *>(mExtensionString);
2928
2929 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2930 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2931
2932 default:
2933 UNREACHABLE();
2934 return nullptr;
2935 }
Geoff Langcec35902014-04-16 10:52:36 -04002936}
2937
Geoff Langc339c4e2016-11-29 10:37:36 -05002938const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002939{
Geoff Langc339c4e2016-11-29 10:37:36 -05002940 switch (name)
2941 {
2942 case GL_EXTENSIONS:
2943 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2944
2945 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2946 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2947
2948 default:
2949 UNREACHABLE();
2950 return nullptr;
2951 }
Geoff Langcec35902014-04-16 10:52:36 -04002952}
2953
2954size_t Context::getExtensionStringCount() const
2955{
2956 return mExtensionStrings.size();
2957}
2958
Geoff Lang111a99e2017-10-17 10:58:41 -04002959bool Context::isExtensionRequestable(const char *name)
2960{
2961 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2962 auto extension = extensionInfos.find(name);
2963
Geoff Lang111a99e2017-10-17 10:58:41 -04002964 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002965 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002966}
2967
Geoff Langc339c4e2016-11-29 10:37:36 -05002968void Context::requestExtension(const char *name)
2969{
2970 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2971 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2972 const auto &extension = extensionInfos.at(name);
2973 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002974 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002975
2976 if (mExtensions.*(extension.ExtensionsMember))
2977 {
2978 // Extension already enabled
2979 return;
2980 }
2981
2982 mExtensions.*(extension.ExtensionsMember) = true;
2983 updateCaps();
2984 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002985
Jamie Madill2f348d22017-06-05 10:50:59 -04002986 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2987 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002988
Jamie Madill81c2e252017-09-09 23:32:46 -04002989 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2990 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002991 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002992 for (auto &zeroTexture : mZeroTextures)
2993 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002994 if (zeroTexture.get() != nullptr)
2995 {
2996 zeroTexture->signalDirty(this, InitState::Initialized);
2997 }
Geoff Lang9aded172017-04-05 11:07:56 -04002998 }
2999
3000 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003001}
3002
3003size_t Context::getRequestableExtensionStringCount() const
3004{
3005 return mRequestableExtensionStrings.size();
3006}
3007
Jamie Madill493f9572018-05-24 19:52:15 -04003008void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003009{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003010 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003011 ASSERT(transformFeedback != nullptr);
3012 ASSERT(!transformFeedback->isPaused());
3013
Jamie Madill6c1f6712017-02-14 19:08:04 -05003014 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003015}
3016
3017bool Context::hasActiveTransformFeedback(GLuint program) const
3018{
3019 for (auto pair : mTransformFeedbackMap)
3020 {
3021 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3022 {
3023 return true;
3024 }
3025 }
3026 return false;
3027}
3028
Geoff Langb0f917f2017-12-05 13:41:54 -05003029Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003030 const egl::ClientExtensions &clientExtensions,
Geoff Langb0f917f2017-12-05 13:41:54 -05003031 bool robustResourceInit) const
3032{
3033 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3034
3035 if (getClientVersion() < ES_2_0)
3036 {
3037 // Default extensions for GLES1
3038 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003039 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003040 }
3041
3042 if (getClientVersion() < ES_3_0)
3043 {
3044 // Disable ES3+ extensions
3045 supportedExtensions.colorBufferFloat = false;
3046 supportedExtensions.eglImageExternalEssl3 = false;
3047 supportedExtensions.textureNorm16 = false;
3048 supportedExtensions.multiview = false;
3049 supportedExtensions.maxViews = 1u;
3050 }
3051
3052 if (getClientVersion() < ES_3_1)
3053 {
3054 // Disable ES3.1+ extensions
3055 supportedExtensions.geometryShader = false;
3056 }
3057
3058 if (getClientVersion() > ES_2_0)
3059 {
3060 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3061 // supportedExtensions.sRGB = false;
3062 }
3063
3064 // Some extensions are always available because they are implemented in the GL layer.
3065 supportedExtensions.bindUniformLocation = true;
3066 supportedExtensions.vertexArrayObject = true;
3067 supportedExtensions.bindGeneratesResource = true;
3068 supportedExtensions.clientArrays = true;
3069 supportedExtensions.requestExtension = true;
3070
3071 // Enable the no error extension if the context was created with the flag.
3072 supportedExtensions.noError = mSkipValidation;
3073
3074 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3075 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3076
3077 // Explicitly enable GL_KHR_debug
3078 supportedExtensions.debug = true;
3079 supportedExtensions.maxDebugMessageLength = 1024;
3080 supportedExtensions.maxDebugLoggedMessages = 1024;
3081 supportedExtensions.maxDebugGroupStackDepth = 1024;
3082 supportedExtensions.maxLabelLength = 1024;
3083
3084 // Explicitly enable GL_ANGLE_robust_client_memory
3085 supportedExtensions.robustClientMemory = true;
3086
3087 // Determine robust resource init availability from EGL.
3088 supportedExtensions.robustResourceInitialization = robustResourceInit;
3089
3090 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3091 // supports it.
3092 supportedExtensions.robustBufferAccessBehavior =
3093 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3094
3095 // Enable the cache control query unconditionally.
3096 supportedExtensions.programCacheControl = true;
3097
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003098 // Enable EGL_ANGLE_explicit_context subextensions
3099 if (clientExtensions.explicitContext)
3100 {
3101 // GL_ANGLE_explicit_context_gles1
3102 supportedExtensions.explicitContextGles1 = true;
3103 // GL_ANGLE_explicit_context
3104 supportedExtensions.explicitContext = true;
3105 }
3106
Geoff Langb0f917f2017-12-05 13:41:54 -05003107 return supportedExtensions;
3108}
3109
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003110void Context::initCaps(const egl::DisplayExtensions &displayExtensions,
3111 const egl::ClientExtensions &clientExtensions,
3112 bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003113{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003114 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003115
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003116 mSupportedExtensions =
3117 generateSupportedExtensions(displayExtensions, clientExtensions, robustResourceInit);
Jamie Madill493f9572018-05-24 19:52:15 -04003118 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003119
3120 mLimitations = mImplementation->getNativeLimitations();
3121
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003122 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3123 if (getClientVersion() < Version(2, 0))
3124 {
3125 mCaps.maxMultitextureUnits = 4;
3126 mCaps.maxClipPlanes = 6;
3127 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003128 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3129 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3130 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003131 }
3132
Geoff Lang301d1612014-07-09 10:34:37 -04003133 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003134 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003135
Jamie Madill0f80ed82017-09-19 00:24:56 -04003136 if (getClientVersion() < ES_3_1)
3137 {
3138 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3139 }
3140 else
3141 {
3142 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3143 }
Geoff Lang301d1612014-07-09 10:34:37 -04003144
Jiawei Shao54aafe52018-04-27 14:54:57 +08003145 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3146 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003147 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3148 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3149
3150 // Limit textures as well, so we can use fast bitsets with texture bindings.
3151 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003152 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3153 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3154 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3155 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003156
Jiawei Shaodb342272017-09-27 10:21:45 +08003157 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3158
Geoff Langc287ea62016-09-16 14:46:51 -04003159 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003160 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003161 for (const auto &extensionInfo : GetExtensionInfoMap())
3162 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003163 // If the user has requested that extensions start disabled and they are requestable,
3164 // disable them.
3165 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003166 {
3167 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3168 }
3169 }
3170
3171 // Generate texture caps
3172 updateCaps();
3173}
3174
3175void Context::updateCaps()
3176{
Geoff Lang900013c2014-07-07 11:32:19 -04003177 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003178 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003179
Jamie Madill7b62cf92017-11-02 15:20:49 -04003180 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003181 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003182 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003183 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003184
Geoff Lang0d8b7242015-09-09 14:56:53 -04003185 // Update the format caps based on the client version and extensions.
3186 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3187 // ES3.
3188 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003189 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003190 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003191 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003192 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003193 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003194
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003195 // OpenGL ES does not support multisampling with non-rendererable formats
3196 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003197 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003198 (getClientVersion() < ES_3_1 &&
3199 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003200 {
Geoff Langd87878e2014-09-19 15:42:59 -04003201 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003202 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003203 else
3204 {
3205 // We may have limited the max samples for some required renderbuffer formats due to
3206 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3207 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3208
3209 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3210 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3211 // exception of signed and unsigned integer formats."
3212 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3213 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3214 {
3215 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3216 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3217 }
3218
3219 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3220 if (getClientVersion() >= ES_3_1)
3221 {
3222 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3223 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3224 // the exception that the signed and unsigned integer formats are required only to
3225 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3226 // multisamples, which must be at least one."
3227 if (formatInfo.componentType == GL_INT ||
3228 formatInfo.componentType == GL_UNSIGNED_INT)
3229 {
3230 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3231 }
3232
3233 // GLES 3.1 section 19.3.1.
3234 if (formatCaps.texturable)
3235 {
3236 if (formatInfo.depthBits > 0)
3237 {
3238 mCaps.maxDepthTextureSamples =
3239 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3240 }
3241 else if (formatInfo.redBits > 0)
3242 {
3243 mCaps.maxColorTextureSamples =
3244 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3245 }
3246 }
3247 }
3248 }
Geoff Langd87878e2014-09-19 15:42:59 -04003249
3250 if (formatCaps.texturable && formatInfo.compressed)
3251 {
Geoff Langca271392017-04-05 12:30:00 -04003252 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003253 }
3254
Geoff Langca271392017-04-05 12:30:00 -04003255 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003256 }
Jamie Madill32447362017-06-28 14:53:52 -04003257
3258 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003259 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003260 {
3261 mMemoryProgramCache = nullptr;
3262 }
Corentin Walleze4477002017-12-01 14:39:58 -05003263
3264 // Compute which buffer types are allowed
3265 mValidBufferBindings.reset();
3266 mValidBufferBindings.set(BufferBinding::ElementArray);
3267 mValidBufferBindings.set(BufferBinding::Array);
3268
3269 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3270 {
3271 mValidBufferBindings.set(BufferBinding::PixelPack);
3272 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3273 }
3274
3275 if (getClientVersion() >= ES_3_0)
3276 {
3277 mValidBufferBindings.set(BufferBinding::CopyRead);
3278 mValidBufferBindings.set(BufferBinding::CopyWrite);
3279 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3280 mValidBufferBindings.set(BufferBinding::Uniform);
3281 }
3282
3283 if (getClientVersion() >= ES_3_1)
3284 {
3285 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3286 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3287 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3288 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3289 }
Geoff Lang493daf52014-07-03 13:38:44 -04003290}
3291
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003292void Context::initWorkarounds()
3293{
Jamie Madill761b02c2017-06-23 16:27:06 -04003294 // Apply back-end workarounds.
3295 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3296
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003297 // Lose the context upon out of memory error if the application is
3298 // expecting to watch for those events.
3299 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3300}
3301
Jamie Madill05b35b22017-10-03 09:01:44 -04003302Error Context::prepareForDraw()
3303{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003304 if (mGLES1Renderer)
3305 {
3306 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3307 }
3308
Geoff Langa8cb2872018-03-09 16:09:40 -05003309 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003310
3311 if (isRobustResourceInitEnabled())
3312 {
3313 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3314 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3315 }
3316
Geoff Langa8cb2872018-03-09 16:09:40 -05003317 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003318 return NoError();
3319}
3320
3321Error Context::prepareForClear(GLbitfield mask)
3322{
Geoff Langa8cb2872018-03-09 16:09:40 -05003323 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003324 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003325 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003326 return NoError();
3327}
3328
3329Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3330{
Geoff Langa8cb2872018-03-09 16:09:40 -05003331 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003332 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3333 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003334 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003335 return NoError();
3336}
3337
Geoff Langa8cb2872018-03-09 16:09:40 -05003338Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003339{
Geoff Langa8cb2872018-03-09 16:09:40 -05003340 ANGLE_TRY(syncDirtyObjects());
3341 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003342 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003343}
3344
Geoff Langa8cb2872018-03-09 16:09:40 -05003345Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003346{
Geoff Langa8cb2872018-03-09 16:09:40 -05003347 ANGLE_TRY(syncDirtyObjects(objectMask));
3348 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003349 return NoError();
3350}
3351
Geoff Langa8cb2872018-03-09 16:09:40 -05003352Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003353{
3354 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3355 mImplementation->syncState(this, dirtyBits);
3356 mGLState.clearDirtyBits();
3357 return NoError();
3358}
3359
Geoff Langa8cb2872018-03-09 16:09:40 -05003360Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003361{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003362 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003363 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003364 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003365 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003366}
Jamie Madillc29968b2016-01-20 11:17:23 -05003367
Geoff Langa8cb2872018-03-09 16:09:40 -05003368Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003369{
3370 return mGLState.syncDirtyObjects(this);
3371}
3372
Geoff Langa8cb2872018-03-09 16:09:40 -05003373Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003374{
3375 return mGLState.syncDirtyObjects(this, objectMask);
3376}
3377
Jamie Madillc29968b2016-01-20 11:17:23 -05003378void Context::blitFramebuffer(GLint srcX0,
3379 GLint srcY0,
3380 GLint srcX1,
3381 GLint srcY1,
3382 GLint dstX0,
3383 GLint dstY0,
3384 GLint dstX1,
3385 GLint dstY1,
3386 GLbitfield mask,
3387 GLenum filter)
3388{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003389 if (mask == 0)
3390 {
3391 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3392 // buffers are copied.
3393 return;
3394 }
3395
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003396 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003397 ASSERT(drawFramebuffer);
3398
3399 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3400 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3401
Jamie Madillbc918e72018-03-08 09:47:21 -05003402 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003403
Jamie Madillc564c072017-06-01 12:45:42 -04003404 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003405}
Jamie Madillc29968b2016-01-20 11:17:23 -05003406
3407void Context::clear(GLbitfield mask)
3408{
Geoff Langd4fff502017-09-22 11:28:28 -04003409 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3410 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003411}
3412
3413void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3414{
Geoff Langd4fff502017-09-22 11:28:28 -04003415 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3416 ANGLE_CONTEXT_TRY(
3417 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003418}
3419
3420void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3421{
Geoff Langd4fff502017-09-22 11:28:28 -04003422 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3423 ANGLE_CONTEXT_TRY(
3424 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003425}
3426
3427void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3428{
Geoff Langd4fff502017-09-22 11:28:28 -04003429 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3430 ANGLE_CONTEXT_TRY(
3431 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003432}
3433
3434void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003436 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003437 ASSERT(framebufferObject);
3438
3439 // If a buffer is not present, the clear has no effect
3440 if (framebufferObject->getDepthbuffer() == nullptr &&
3441 framebufferObject->getStencilbuffer() == nullptr)
3442 {
3443 return;
3444 }
3445
Geoff Langd4fff502017-09-22 11:28:28 -04003446 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3447 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003448}
3449
3450void Context::readPixels(GLint x,
3451 GLint y,
3452 GLsizei width,
3453 GLsizei height,
3454 GLenum format,
3455 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003456 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003457{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003458 if (width == 0 || height == 0)
3459 {
3460 return;
3461 }
3462
Jamie Madillbc918e72018-03-08 09:47:21 -05003463 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003464
Jamie Madillb6664922017-07-25 12:55:04 -04003465 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3466 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003467
3468 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003469 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003470}
3471
Brandon Jones59770802018-04-02 13:18:42 -07003472void Context::readPixelsRobust(GLint x,
3473 GLint y,
3474 GLsizei width,
3475 GLsizei height,
3476 GLenum format,
3477 GLenum type,
3478 GLsizei bufSize,
3479 GLsizei *length,
3480 GLsizei *columns,
3481 GLsizei *rows,
3482 void *pixels)
3483{
3484 readPixels(x, y, width, height, format, type, pixels);
3485}
3486
3487void Context::readnPixelsRobust(GLint x,
3488 GLint y,
3489 GLsizei width,
3490 GLsizei height,
3491 GLenum format,
3492 GLenum type,
3493 GLsizei bufSize,
3494 GLsizei *length,
3495 GLsizei *columns,
3496 GLsizei *rows,
3497 void *data)
3498{
3499 readPixels(x, y, width, height, format, type, data);
3500}
3501
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003502void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003503 GLint level,
3504 GLenum internalformat,
3505 GLint x,
3506 GLint y,
3507 GLsizei width,
3508 GLsizei height,
3509 GLint border)
3510{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003511 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003512 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003513
Jamie Madillc29968b2016-01-20 11:17:23 -05003514 Rectangle sourceArea(x, y, width, height);
3515
Jamie Madill05b35b22017-10-03 09:01:44 -04003516 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003517 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003518 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003519}
3520
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003521void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003522 GLint level,
3523 GLint xoffset,
3524 GLint yoffset,
3525 GLint x,
3526 GLint y,
3527 GLsizei width,
3528 GLsizei height)
3529{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003530 if (width == 0 || height == 0)
3531 {
3532 return;
3533 }
3534
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003535 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003536 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003537
Jamie Madillc29968b2016-01-20 11:17:23 -05003538 Offset destOffset(xoffset, yoffset, 0);
3539 Rectangle sourceArea(x, y, width, height);
3540
Jamie Madill05b35b22017-10-03 09:01:44 -04003541 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003542 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003543 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003544}
3545
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003546void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003547 GLint level,
3548 GLint xoffset,
3549 GLint yoffset,
3550 GLint zoffset,
3551 GLint x,
3552 GLint y,
3553 GLsizei width,
3554 GLsizei height)
3555{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003556 if (width == 0 || height == 0)
3557 {
3558 return;
3559 }
3560
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003561 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003562 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003563
Jamie Madillc29968b2016-01-20 11:17:23 -05003564 Offset destOffset(xoffset, yoffset, zoffset);
3565 Rectangle sourceArea(x, y, width, height);
3566
Jamie Madill05b35b22017-10-03 09:01:44 -04003567 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3568 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003569 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3570 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003571}
3572
3573void Context::framebufferTexture2D(GLenum target,
3574 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003575 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003576 GLuint texture,
3577 GLint level)
3578{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003579 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003580 ASSERT(framebuffer);
3581
3582 if (texture != 0)
3583 {
3584 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003585 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003586 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003587 }
3588 else
3589 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003590 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003591 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003592
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
3596void Context::framebufferRenderbuffer(GLenum target,
3597 GLenum attachment,
3598 GLenum renderbuffertarget,
3599 GLuint renderbuffer)
3600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003601 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003602 ASSERT(framebuffer);
3603
3604 if (renderbuffer != 0)
3605 {
3606 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003607
Jamie Madillcc129372018-04-12 09:13:18 -04003608 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003609 renderbufferObject);
3610 }
3611 else
3612 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003613 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003614 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003615
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003617}
3618
3619void Context::framebufferTextureLayer(GLenum target,
3620 GLenum attachment,
3621 GLuint texture,
3622 GLint level,
3623 GLint layer)
3624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 ASSERT(framebuffer);
3627
3628 if (texture != 0)
3629 {
3630 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003631 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003632 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 }
3634 else
3635 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003636 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003637 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003638
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003640}
3641
Brandon Jones59770802018-04-02 13:18:42 -07003642void Context::framebufferTextureMultiviewLayered(GLenum target,
3643 GLenum attachment,
3644 GLuint texture,
3645 GLint level,
3646 GLint baseViewIndex,
3647 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003648{
Martin Radev82ef7742017-08-08 17:44:58 +03003649 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3650 ASSERT(framebuffer);
3651
3652 if (texture != 0)
3653 {
3654 Texture *textureObj = getTexture(texture);
3655
Martin Radev18b75ba2017-08-15 15:50:40 +03003656 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003657 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3658 numViews, baseViewIndex);
3659 }
3660 else
3661 {
3662 framebuffer->resetAttachment(this, attachment);
3663 }
3664
3665 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003666}
3667
Brandon Jones59770802018-04-02 13:18:42 -07003668void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3669 GLenum attachment,
3670 GLuint texture,
3671 GLint level,
3672 GLsizei numViews,
3673 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003674{
Martin Radev5dae57b2017-07-14 16:15:55 +03003675 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3676 ASSERT(framebuffer);
3677
3678 if (texture != 0)
3679 {
3680 Texture *textureObj = getTexture(texture);
3681
3682 ImageIndex index = ImageIndex::Make2D(level);
3683 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3684 textureObj, numViews, viewportOffsets);
3685 }
3686 else
3687 {
3688 framebuffer->resetAttachment(this, attachment);
3689 }
3690
3691 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003692}
3693
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003694// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3695void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3696{
3697 UNIMPLEMENTED();
3698}
3699
Jamie Madillc29968b2016-01-20 11:17:23 -05003700void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3701{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003703 ASSERT(framebuffer);
3704 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706}
3707
3708void Context::readBuffer(GLenum mode)
3709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713}
3714
3715void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3716{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003717 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003718 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003719
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003721 ASSERT(framebuffer);
3722
3723 // The specification isn't clear what should be done when the framebuffer isn't complete.
3724 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003725 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003726}
3727
3728void Context::invalidateFramebuffer(GLenum target,
3729 GLsizei numAttachments,
3730 const GLenum *attachments)
3731{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003732 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003733 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003734
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003736 ASSERT(framebuffer);
3737
Jamie Madill427064d2018-04-13 16:20:34 -04003738 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003739 {
Jamie Madill437fa652016-05-03 15:13:24 -04003740 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003741 }
Jamie Madill437fa652016-05-03 15:13:24 -04003742
Jamie Madill4928b7c2017-06-20 12:57:39 -04003743 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003744}
3745
3746void Context::invalidateSubFramebuffer(GLenum target,
3747 GLsizei numAttachments,
3748 const GLenum *attachments,
3749 GLint x,
3750 GLint y,
3751 GLsizei width,
3752 GLsizei height)
3753{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003754 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003755 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003756
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 ASSERT(framebuffer);
3759
Jamie Madill427064d2018-04-13 16:20:34 -04003760 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003761 {
Jamie Madill437fa652016-05-03 15:13:24 -04003762 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003763 }
Jamie Madill437fa652016-05-03 15:13:24 -04003764
3765 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003766 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003767}
3768
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003769void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003770 GLint level,
3771 GLint internalformat,
3772 GLsizei width,
3773 GLsizei height,
3774 GLint border,
3775 GLenum format,
3776 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003777 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003778{
Jamie Madillbc918e72018-03-08 09:47:21 -05003779 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003780
3781 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003782 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003783 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3784 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003785}
3786
Brandon Jones59770802018-04-02 13:18:42 -07003787void Context::texImage2DRobust(TextureTarget target,
3788 GLint level,
3789 GLint internalformat,
3790 GLsizei width,
3791 GLsizei height,
3792 GLint border,
3793 GLenum format,
3794 GLenum type,
3795 GLsizei bufSize,
3796 const void *pixels)
3797{
3798 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3799}
3800
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003801void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003802 GLint level,
3803 GLint internalformat,
3804 GLsizei width,
3805 GLsizei height,
3806 GLsizei depth,
3807 GLint border,
3808 GLenum format,
3809 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003810 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003811{
Jamie Madillbc918e72018-03-08 09:47:21 -05003812 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003813
3814 Extents size(width, height, depth);
3815 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003816 handleError(texture->setImage(this, mGLState.getUnpackState(),
3817 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3818 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003819}
3820
Brandon Jones59770802018-04-02 13:18:42 -07003821void Context::texImage3DRobust(TextureType target,
3822 GLint level,
3823 GLint internalformat,
3824 GLsizei width,
3825 GLsizei height,
3826 GLsizei depth,
3827 GLint border,
3828 GLenum format,
3829 GLenum type,
3830 GLsizei bufSize,
3831 const void *pixels)
3832{
3833 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3834}
3835
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003836void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003837 GLint level,
3838 GLint xoffset,
3839 GLint yoffset,
3840 GLsizei width,
3841 GLsizei height,
3842 GLenum format,
3843 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003844 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003845{
3846 // Zero sized uploads are valid but no-ops
3847 if (width == 0 || height == 0)
3848 {
3849 return;
3850 }
3851
Jamie Madillbc918e72018-03-08 09:47:21 -05003852 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003853
3854 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003855 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003856 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3857 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003858}
3859
Brandon Jones59770802018-04-02 13:18:42 -07003860void Context::texSubImage2DRobust(TextureTarget target,
3861 GLint level,
3862 GLint xoffset,
3863 GLint yoffset,
3864 GLsizei width,
3865 GLsizei height,
3866 GLenum format,
3867 GLenum type,
3868 GLsizei bufSize,
3869 const void *pixels)
3870{
3871 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3872}
3873
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003874void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003875 GLint level,
3876 GLint xoffset,
3877 GLint yoffset,
3878 GLint zoffset,
3879 GLsizei width,
3880 GLsizei height,
3881 GLsizei depth,
3882 GLenum format,
3883 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003884 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003885{
3886 // Zero sized uploads are valid but no-ops
3887 if (width == 0 || height == 0 || depth == 0)
3888 {
3889 return;
3890 }
3891
Jamie Madillbc918e72018-03-08 09:47:21 -05003892 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003893
3894 Box area(xoffset, yoffset, zoffset, width, height, depth);
3895 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003896 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3897 NonCubeTextureTypeToTarget(target), level, area, format, type,
3898 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003899}
3900
Brandon Jones59770802018-04-02 13:18:42 -07003901void Context::texSubImage3DRobust(TextureType target,
3902 GLint level,
3903 GLint xoffset,
3904 GLint yoffset,
3905 GLint zoffset,
3906 GLsizei width,
3907 GLsizei height,
3908 GLsizei depth,
3909 GLenum format,
3910 GLenum type,
3911 GLsizei bufSize,
3912 const void *pixels)
3913{
3914 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3915 pixels);
3916}
3917
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003918void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003919 GLint level,
3920 GLenum internalformat,
3921 GLsizei width,
3922 GLsizei height,
3923 GLint border,
3924 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003925 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003926{
Jamie Madillbc918e72018-03-08 09:47:21 -05003927 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003928
3929 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003930 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003931 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3932 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003933 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003934}
3935
Brandon Jones59770802018-04-02 13:18:42 -07003936void Context::compressedTexImage2DRobust(TextureTarget target,
3937 GLint level,
3938 GLenum internalformat,
3939 GLsizei width,
3940 GLsizei height,
3941 GLint border,
3942 GLsizei imageSize,
3943 GLsizei dataSize,
3944 const GLvoid *data)
3945{
3946 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3947}
3948
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003949void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003950 GLint level,
3951 GLenum internalformat,
3952 GLsizei width,
3953 GLsizei height,
3954 GLsizei depth,
3955 GLint border,
3956 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003957 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003958{
Jamie Madillbc918e72018-03-08 09:47:21 -05003959 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003960
3961 Extents size(width, height, depth);
3962 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003963 handleError(texture->setCompressedImage(
3964 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3965 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003966}
3967
Brandon Jones59770802018-04-02 13:18:42 -07003968void Context::compressedTexImage3DRobust(TextureType target,
3969 GLint level,
3970 GLenum internalformat,
3971 GLsizei width,
3972 GLsizei height,
3973 GLsizei depth,
3974 GLint border,
3975 GLsizei imageSize,
3976 GLsizei dataSize,
3977 const GLvoid *data)
3978{
3979 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3980 data);
3981}
3982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003983void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003984 GLint level,
3985 GLint xoffset,
3986 GLint yoffset,
3987 GLsizei width,
3988 GLsizei height,
3989 GLenum format,
3990 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003991 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003992{
Jamie Madillbc918e72018-03-08 09:47:21 -05003993 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003994
3995 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003996 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003997 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3998 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003999 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004000}
4001
Brandon Jones59770802018-04-02 13:18:42 -07004002void Context::compressedTexSubImage2DRobust(TextureTarget target,
4003 GLint level,
4004 GLint xoffset,
4005 GLint yoffset,
4006 GLsizei width,
4007 GLsizei height,
4008 GLenum format,
4009 GLsizei imageSize,
4010 GLsizei dataSize,
4011 const GLvoid *data)
4012{
4013 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4014 data);
4015}
4016
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004017void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004018 GLint level,
4019 GLint xoffset,
4020 GLint yoffset,
4021 GLint zoffset,
4022 GLsizei width,
4023 GLsizei height,
4024 GLsizei depth,
4025 GLenum format,
4026 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004027 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004028{
4029 // Zero sized uploads are valid but no-ops
4030 if (width == 0 || height == 0)
4031 {
4032 return;
4033 }
4034
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004036
4037 Box area(xoffset, yoffset, zoffset, width, height, depth);
4038 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004039 handleError(texture->setCompressedSubImage(
4040 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4041 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004042}
4043
Brandon Jones59770802018-04-02 13:18:42 -07004044void Context::compressedTexSubImage3DRobust(TextureType target,
4045 GLint level,
4046 GLint xoffset,
4047 GLint yoffset,
4048 GLint zoffset,
4049 GLsizei width,
4050 GLsizei height,
4051 GLsizei depth,
4052 GLenum format,
4053 GLsizei imageSize,
4054 GLsizei dataSize,
4055 const GLvoid *data)
4056{
4057 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4058 imageSize, data);
4059}
4060
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004061void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004062{
4063 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004064 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004065}
4066
Jamie Madill007530e2017-12-28 14:27:04 -05004067void Context::copyTexture(GLuint sourceId,
4068 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004069 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004070 GLuint destId,
4071 GLint destLevel,
4072 GLint internalFormat,
4073 GLenum destType,
4074 GLboolean unpackFlipY,
4075 GLboolean unpackPremultiplyAlpha,
4076 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004077{
Jamie Madillbc918e72018-03-08 09:47:21 -05004078 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004079
4080 gl::Texture *sourceTexture = getTexture(sourceId);
4081 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004082 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4083 sourceLevel, ConvertToBool(unpackFlipY),
4084 ConvertToBool(unpackPremultiplyAlpha),
4085 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004086}
4087
Jamie Madill007530e2017-12-28 14:27:04 -05004088void Context::copySubTexture(GLuint sourceId,
4089 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004090 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004091 GLuint destId,
4092 GLint destLevel,
4093 GLint xoffset,
4094 GLint yoffset,
4095 GLint x,
4096 GLint y,
4097 GLsizei width,
4098 GLsizei height,
4099 GLboolean unpackFlipY,
4100 GLboolean unpackPremultiplyAlpha,
4101 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004102{
4103 // Zero sized copies are valid but no-ops
4104 if (width == 0 || height == 0)
4105 {
4106 return;
4107 }
4108
Jamie Madillbc918e72018-03-08 09:47:21 -05004109 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004110
4111 gl::Texture *sourceTexture = getTexture(sourceId);
4112 gl::Texture *destTexture = getTexture(destId);
4113 Offset offset(xoffset, yoffset, 0);
4114 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004115 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4116 ConvertToBool(unpackFlipY),
4117 ConvertToBool(unpackPremultiplyAlpha),
4118 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004119}
4120
Jamie Madill007530e2017-12-28 14:27:04 -05004121void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004122{
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004124
4125 gl::Texture *sourceTexture = getTexture(sourceId);
4126 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004127 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004128}
4129
Corentin Wallez336129f2017-10-17 15:55:40 -04004130void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004131{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004132 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004133 ASSERT(buffer);
4134
Geoff Lang496c02d2016-10-20 11:38:11 -07004135 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004136}
4137
Brandon Jones59770802018-04-02 13:18:42 -07004138void Context::getBufferPointervRobust(BufferBinding target,
4139 GLenum pname,
4140 GLsizei bufSize,
4141 GLsizei *length,
4142 void **params)
4143{
4144 getBufferPointerv(target, pname, params);
4145}
4146
Corentin Wallez336129f2017-10-17 15:55:40 -04004147void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004149 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004150 ASSERT(buffer);
4151
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004152 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004153 if (error.isError())
4154 {
Jamie Madill437fa652016-05-03 15:13:24 -04004155 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004156 return nullptr;
4157 }
4158
4159 return buffer->getMapPointer();
4160}
4161
Corentin Wallez336129f2017-10-17 15:55:40 -04004162GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004163{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004164 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004165 ASSERT(buffer);
4166
4167 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004168 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004169 if (error.isError())
4170 {
Jamie Madill437fa652016-05-03 15:13:24 -04004171 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004172 return GL_FALSE;
4173 }
4174
4175 return result;
4176}
4177
Corentin Wallez336129f2017-10-17 15:55:40 -04004178void *Context::mapBufferRange(BufferBinding target,
4179 GLintptr offset,
4180 GLsizeiptr length,
4181 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004182{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004183 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004184 ASSERT(buffer);
4185
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004186 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004187 if (error.isError())
4188 {
Jamie Madill437fa652016-05-03 15:13:24 -04004189 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004190 return nullptr;
4191 }
4192
4193 return buffer->getMapPointer();
4194}
4195
Corentin Wallez336129f2017-10-17 15:55:40 -04004196void Context::flushMappedBufferRange(BufferBinding /*target*/,
4197 GLintptr /*offset*/,
4198 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004199{
4200 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4201}
4202
Jamie Madillbc918e72018-03-08 09:47:21 -05004203Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004204{
Geoff Langa8cb2872018-03-09 16:09:40 -05004205 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004206}
4207
Jamie Madillbc918e72018-03-08 09:47:21 -05004208Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004209{
Geoff Langa8cb2872018-03-09 16:09:40 -05004210 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004211}
4212
Jamie Madillbc918e72018-03-08 09:47:21 -05004213Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004214{
Geoff Langa8cb2872018-03-09 16:09:40 -05004215 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004216}
4217
Jiajia Qin5451d532017-11-16 17:16:34 +08004218void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4219{
4220 UNIMPLEMENTED();
4221}
4222
Jamie Madillc20ab272016-06-09 07:20:46 -07004223void Context::activeTexture(GLenum texture)
4224{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004225 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004226}
4227
Jamie Madill876429b2017-04-20 15:46:24 -04004228void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004229{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004230 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004231}
4232
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004233void Context::blendEquation(GLenum mode)
4234{
4235 mGLState.setBlendEquation(mode, mode);
4236}
4237
Jamie Madillc20ab272016-06-09 07:20:46 -07004238void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4239{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004240 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004241}
4242
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004243void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4244{
4245 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4246}
4247
Jamie Madillc20ab272016-06-09 07:20:46 -07004248void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4249{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004250 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004251}
4252
Jamie Madill876429b2017-04-20 15:46:24 -04004253void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004256}
4257
Jamie Madill876429b2017-04-20 15:46:24 -04004258void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004259{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004260 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004261}
4262
4263void Context::clearStencil(GLint s)
4264{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004265 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004266}
4267
4268void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4269{
Geoff Lang92019432017-11-20 13:09:34 -05004270 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4271 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004272}
4273
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004274void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004275{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004276 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004277}
4278
4279void Context::depthFunc(GLenum func)
4280{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004282}
4283
4284void Context::depthMask(GLboolean flag)
4285{
Geoff Lang92019432017-11-20 13:09:34 -05004286 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004287}
4288
Jamie Madill876429b2017-04-20 15:46:24 -04004289void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004290{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004291 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004292}
4293
4294void Context::disable(GLenum cap)
4295{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004297}
4298
4299void Context::disableVertexAttribArray(GLuint index)
4300{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004301 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004302}
4303
4304void Context::enable(GLenum cap)
4305{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004306 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004307}
4308
4309void Context::enableVertexAttribArray(GLuint index)
4310{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004311 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004312}
4313
4314void Context::frontFace(GLenum mode)
4315{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004316 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004317}
4318
4319void Context::hint(GLenum target, GLenum mode)
4320{
4321 switch (target)
4322 {
4323 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004324 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004325 break;
4326
4327 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329 break;
4330
4331 default:
4332 UNREACHABLE();
4333 return;
4334 }
4335}
4336
4337void Context::lineWidth(GLfloat width)
4338{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340}
4341
4342void Context::pixelStorei(GLenum pname, GLint param)
4343{
4344 switch (pname)
4345 {
4346 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004347 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004348 break;
4349
4350 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352 break;
4353
4354 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356 break;
4357
4358 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004359 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004360 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004361 break;
4362
4363 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004364 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004365 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004366 break;
4367
4368 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004369 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004370 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004371 break;
4372
4373 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004374 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376 break;
4377
4378 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004379 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004380 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004381 break;
4382
4383 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004384 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386 break;
4387
4388 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004389 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004390 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004391 break;
4392
4393 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004394 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004395 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004396 break;
4397
4398 default:
4399 UNREACHABLE();
4400 return;
4401 }
4402}
4403
4404void Context::polygonOffset(GLfloat factor, GLfloat units)
4405{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
Jamie Madill876429b2017-04-20 15:46:24 -04004409void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004410{
Geoff Lang92019432017-11-20 13:09:34 -05004411 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
Jiawei Shaodb342272017-09-27 10:21:45 +08004414void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4415{
4416 mGLState.setSampleMaskParams(maskNumber, mask);
4417}
4418
Jamie Madillc20ab272016-06-09 07:20:46 -07004419void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4420{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422}
4423
4424void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4425{
4426 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4427 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429 }
4430
4431 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4432 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434 }
4435}
4436
4437void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4438{
4439 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4440 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442 }
4443
4444 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4445 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447 }
4448}
4449
4450void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4451{
4452 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4453 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004454 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004455 }
4456
4457 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4458 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460 }
4461}
4462
4463void Context::vertexAttrib1f(GLuint index, GLfloat x)
4464{
4465 GLfloat vals[4] = {x, 0, 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::vertexAttrib1fv(GLuint index, const GLfloat *values)
4470{
4471 GLfloat vals[4] = {values[0], 0, 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::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4476{
4477 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004478 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004479}
4480
4481void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4482{
4483 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485}
4486
4487void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4488{
4489 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004490 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004491}
4492
4493void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4494{
4495 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497}
4498
4499void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4500{
4501 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004503}
4504
4505void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
4510void Context::vertexAttribPointer(GLuint index,
4511 GLint size,
4512 GLenum type,
4513 GLboolean normalized,
4514 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004515 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004516{
Corentin Wallez336129f2017-10-17 15:55:40 -04004517 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004518 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519}
4520
Shao80957d92017-02-20 21:25:59 +08004521void Context::vertexAttribFormat(GLuint attribIndex,
4522 GLint size,
4523 GLenum type,
4524 GLboolean normalized,
4525 GLuint relativeOffset)
4526{
Geoff Lang92019432017-11-20 13:09:34 -05004527 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004528 relativeOffset);
4529}
4530
4531void Context::vertexAttribIFormat(GLuint attribIndex,
4532 GLint size,
4533 GLenum type,
4534 GLuint relativeOffset)
4535{
4536 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4537}
4538
4539void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4540{
Shaodde78e82017-05-22 14:13:27 +08004541 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004542}
4543
Jiajia Qin5451d532017-11-16 17:16:34 +08004544void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004545{
4546 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4547}
4548
Jamie Madillc20ab272016-06-09 07:20:46 -07004549void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4550{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004551 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004552}
4553
4554void Context::vertexAttribIPointer(GLuint index,
4555 GLint size,
4556 GLenum type,
4557 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004558 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004559{
Corentin Wallez336129f2017-10-17 15:55:40 -04004560 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4561 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562}
4563
4564void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4565{
4566 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004567 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568}
4569
4570void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4571{
4572 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
4576void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4582{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004583 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004584}
4585
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004586void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4587{
4588 const VertexAttribCurrentValueData &currentValues =
4589 getGLState().getVertexAttribCurrentValue(index);
4590 const VertexArray *vao = getGLState().getVertexArray();
4591 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4592 currentValues, pname, params);
4593}
4594
Brandon Jones59770802018-04-02 13:18:42 -07004595void Context::getVertexAttribivRobust(GLuint index,
4596 GLenum pname,
4597 GLsizei bufSize,
4598 GLsizei *length,
4599 GLint *params)
4600{
4601 getVertexAttribiv(index, pname, params);
4602}
4603
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004604void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4605{
4606 const VertexAttribCurrentValueData &currentValues =
4607 getGLState().getVertexAttribCurrentValue(index);
4608 const VertexArray *vao = getGLState().getVertexArray();
4609 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4610 currentValues, pname, params);
4611}
4612
Brandon Jones59770802018-04-02 13:18:42 -07004613void Context::getVertexAttribfvRobust(GLuint index,
4614 GLenum pname,
4615 GLsizei bufSize,
4616 GLsizei *length,
4617 GLfloat *params)
4618{
4619 getVertexAttribfv(index, pname, params);
4620}
4621
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004622void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4623{
4624 const VertexAttribCurrentValueData &currentValues =
4625 getGLState().getVertexAttribCurrentValue(index);
4626 const VertexArray *vao = getGLState().getVertexArray();
4627 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4628 currentValues, pname, params);
4629}
4630
Brandon Jones59770802018-04-02 13:18:42 -07004631void Context::getVertexAttribIivRobust(GLuint index,
4632 GLenum pname,
4633 GLsizei bufSize,
4634 GLsizei *length,
4635 GLint *params)
4636{
4637 getVertexAttribIiv(index, pname, params);
4638}
4639
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004640void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4641{
4642 const VertexAttribCurrentValueData &currentValues =
4643 getGLState().getVertexAttribCurrentValue(index);
4644 const VertexArray *vao = getGLState().getVertexArray();
4645 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4646 currentValues, pname, params);
4647}
4648
Brandon Jones59770802018-04-02 13:18:42 -07004649void Context::getVertexAttribIuivRobust(GLuint index,
4650 GLenum pname,
4651 GLsizei bufSize,
4652 GLsizei *length,
4653 GLuint *params)
4654{
4655 getVertexAttribIuiv(index, pname, params);
4656}
4657
Jamie Madill876429b2017-04-20 15:46:24 -04004658void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004659{
4660 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4661 QueryVertexAttribPointerv(attrib, pname, pointer);
4662}
4663
Brandon Jones59770802018-04-02 13:18:42 -07004664void Context::getVertexAttribPointervRobust(GLuint index,
4665 GLenum pname,
4666 GLsizei bufSize,
4667 GLsizei *length,
4668 void **pointer)
4669{
4670 getVertexAttribPointerv(index, pname, pointer);
4671}
4672
Jamie Madillc20ab272016-06-09 07:20:46 -07004673void Context::debugMessageControl(GLenum source,
4674 GLenum type,
4675 GLenum severity,
4676 GLsizei count,
4677 const GLuint *ids,
4678 GLboolean enabled)
4679{
4680 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004682 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::debugMessageInsert(GLenum source,
4686 GLenum type,
4687 GLuint id,
4688 GLenum severity,
4689 GLsizei length,
4690 const GLchar *buf)
4691{
4692 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004694}
4695
4696void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
4701GLuint Context::getDebugMessageLog(GLuint count,
4702 GLsizei bufSize,
4703 GLenum *sources,
4704 GLenum *types,
4705 GLuint *ids,
4706 GLenum *severities,
4707 GLsizei *lengths,
4708 GLchar *messageLog)
4709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004710 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4711 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004712}
4713
4714void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4715{
4716 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004717 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004718 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004719}
4720
4721void Context::popDebugGroup()
4722{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004723 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004724 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004725}
4726
Corentin Wallez336129f2017-10-17 15:55:40 -04004727void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004728{
4729 Buffer *buffer = mGLState.getTargetBuffer(target);
4730 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004731 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004732}
4733
Corentin Wallez336129f2017-10-17 15:55:40 -04004734void Context::bufferSubData(BufferBinding target,
4735 GLintptr offset,
4736 GLsizeiptr size,
4737 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004738{
4739 if (data == nullptr)
4740 {
4741 return;
4742 }
4743
4744 Buffer *buffer = mGLState.getTargetBuffer(target);
4745 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004746 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004747}
4748
Jamie Madillef300b12016-10-07 15:12:09 -04004749void Context::attachShader(GLuint program, GLuint shader)
4750{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004751 Program *programObject = mState.mShaderPrograms->getProgram(program);
4752 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004753 ASSERT(programObject && shaderObject);
4754 programObject->attachShader(shaderObject);
4755}
4756
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004757const Workarounds &Context::getWorkarounds() const
4758{
4759 return mWorkarounds;
4760}
4761
Corentin Wallez336129f2017-10-17 15:55:40 -04004762void Context::copyBufferSubData(BufferBinding readTarget,
4763 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004764 GLintptr readOffset,
4765 GLintptr writeOffset,
4766 GLsizeiptr size)
4767{
4768 // if size is zero, the copy is a successful no-op
4769 if (size == 0)
4770 {
4771 return;
4772 }
4773
4774 // TODO(jmadill): cache these.
4775 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4776 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4777
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004778 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004779}
4780
Jamie Madill01a80ee2016-11-07 12:06:18 -05004781void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4782{
4783 Program *programObject = getProgram(program);
4784 // TODO(jmadill): Re-use this from the validation if possible.
4785 ASSERT(programObject);
4786 programObject->bindAttributeLocation(index, name);
4787}
4788
Corentin Wallez336129f2017-10-17 15:55:40 -04004789void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004790{
Corentin Wallez336129f2017-10-17 15:55:40 -04004791 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4792 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004793}
4794
Corentin Wallez336129f2017-10-17 15:55:40 -04004795void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004796{
4797 bindBufferRange(target, index, buffer, 0, 0);
4798}
4799
Corentin Wallez336129f2017-10-17 15:55:40 -04004800void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004801 GLuint index,
4802 GLuint buffer,
4803 GLintptr offset,
4804 GLsizeiptr size)
4805{
Corentin Wallez336129f2017-10-17 15:55:40 -04004806 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4807 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004808}
4809
Jamie Madill01a80ee2016-11-07 12:06:18 -05004810void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4811{
4812 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4813 {
4814 bindReadFramebuffer(framebuffer);
4815 }
4816
4817 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4818 {
4819 bindDrawFramebuffer(framebuffer);
4820 }
4821}
4822
4823void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4824{
4825 ASSERT(target == GL_RENDERBUFFER);
4826 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004827 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004828 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004829}
4830
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004831void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004832 GLsizei samples,
4833 GLenum internalformat,
4834 GLsizei width,
4835 GLsizei height,
4836 GLboolean fixedsamplelocations)
4837{
4838 Extents size(width, height, 1);
4839 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004840 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4841 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004842}
4843
4844void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4845{
JiangYizhou5b03f472017-01-09 10:22:53 +08004846 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4847 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004848 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004849 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004850
4851 switch (pname)
4852 {
4853 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004854 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004855 break;
4856 default:
4857 UNREACHABLE();
4858 }
4859}
4860
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004861void Context::getMultisamplefvRobust(GLenum pname,
4862 GLuint index,
4863 GLsizei bufSize,
4864 GLsizei *length,
4865 GLfloat *val)
4866{
4867 UNIMPLEMENTED();
4868}
4869
Jamie Madille8fb6402017-02-14 17:56:40 -05004870void Context::renderbufferStorage(GLenum target,
4871 GLenum internalformat,
4872 GLsizei width,
4873 GLsizei height)
4874{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004875 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4876 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4877
Jamie Madille8fb6402017-02-14 17:56:40 -05004878 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004879 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004880}
4881
4882void Context::renderbufferStorageMultisample(GLenum target,
4883 GLsizei samples,
4884 GLenum internalformat,
4885 GLsizei width,
4886 GLsizei height)
4887{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004888 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4889 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004890
4891 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004892 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004893 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004894}
4895
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004896void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4897{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004898 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004899 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004900}
4901
JiangYizhoue18e6392017-02-20 10:32:23 +08004902void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4903{
4904 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4905 QueryFramebufferParameteriv(framebuffer, pname, params);
4906}
4907
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004908void Context::getFramebufferParameterivRobust(GLenum target,
4909 GLenum pname,
4910 GLsizei bufSize,
4911 GLsizei *length,
4912 GLint *params)
4913{
4914 UNIMPLEMENTED();
4915}
4916
Jiajia Qin5451d532017-11-16 17:16:34 +08004917void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004918{
4919 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4920 SetFramebufferParameteri(framebuffer, pname, param);
4921}
4922
Jamie Madillb3f26b92017-07-19 15:07:41 -04004923Error Context::getScratchBuffer(size_t requstedSizeBytes,
4924 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004925{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004926 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4927 {
4928 return OutOfMemory() << "Failed to allocate internal buffer.";
4929 }
4930 return NoError();
4931}
4932
4933Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4934 angle::MemoryBuffer **zeroBufferOut) const
4935{
4936 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004937 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004938 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004939 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004940 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004941}
4942
Xinghua Cao10a4d432017-11-28 14:46:26 +08004943Error Context::prepareForDispatch()
4944{
Geoff Langa8cb2872018-03-09 16:09:40 -05004945 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004946
4947 if (isRobustResourceInitEnabled())
4948 {
4949 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4950 }
4951
4952 return NoError();
4953}
4954
Xinghua Cao2b396592017-03-29 15:36:04 +08004955void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4956{
4957 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4958 {
4959 return;
4960 }
4961
Xinghua Cao10a4d432017-11-28 14:46:26 +08004962 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004963 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004964}
4965
Jiajia Qin5451d532017-11-16 17:16:34 +08004966void Context::dispatchComputeIndirect(GLintptr indirect)
4967{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004968 ANGLE_CONTEXT_TRY(prepareForDispatch());
4969 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004970}
4971
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004972void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004973 GLsizei levels,
4974 GLenum internalFormat,
4975 GLsizei width,
4976 GLsizei height)
4977{
4978 Extents size(width, height, 1);
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
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004983void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004984 GLsizei levels,
4985 GLenum internalFormat,
4986 GLsizei width,
4987 GLsizei height,
4988 GLsizei depth)
4989{
4990 Extents size(width, height, depth);
4991 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004992 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004993}
4994
Jiajia Qin5451d532017-11-16 17:16:34 +08004995void Context::memoryBarrier(GLbitfield barriers)
4996{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004997 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004998}
4999
5000void Context::memoryBarrierByRegion(GLbitfield barriers)
5001{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005002 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005003}
5004
Jamie Madillc1d770e2017-04-13 17:31:24 -04005005GLenum Context::checkFramebufferStatus(GLenum target)
5006{
5007 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5008 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005009 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005010}
5011
5012void Context::compileShader(GLuint shader)
5013{
5014 Shader *shaderObject = GetValidShader(this, shader);
5015 if (!shaderObject)
5016 {
5017 return;
5018 }
5019 shaderObject->compile(this);
5020}
5021
5022void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5023{
5024 for (int i = 0; i < n; i++)
5025 {
5026 deleteBuffer(buffers[i]);
5027 }
5028}
5029
5030void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5031{
5032 for (int i = 0; i < n; i++)
5033 {
5034 if (framebuffers[i] != 0)
5035 {
5036 deleteFramebuffer(framebuffers[i]);
5037 }
5038 }
5039}
5040
5041void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5042{
5043 for (int i = 0; i < n; i++)
5044 {
5045 deleteRenderbuffer(renderbuffers[i]);
5046 }
5047}
5048
5049void Context::deleteTextures(GLsizei n, const GLuint *textures)
5050{
5051 for (int i = 0; i < n; i++)
5052 {
5053 if (textures[i] != 0)
5054 {
5055 deleteTexture(textures[i]);
5056 }
5057 }
5058}
5059
5060void Context::detachShader(GLuint program, GLuint shader)
5061{
5062 Program *programObject = getProgram(program);
5063 ASSERT(programObject);
5064
5065 Shader *shaderObject = getShader(shader);
5066 ASSERT(shaderObject);
5067
5068 programObject->detachShader(this, shaderObject);
5069}
5070
5071void Context::genBuffers(GLsizei n, GLuint *buffers)
5072{
5073 for (int i = 0; i < n; i++)
5074 {
5075 buffers[i] = createBuffer();
5076 }
5077}
5078
5079void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5080{
5081 for (int i = 0; i < n; i++)
5082 {
5083 framebuffers[i] = createFramebuffer();
5084 }
5085}
5086
5087void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5088{
5089 for (int i = 0; i < n; i++)
5090 {
5091 renderbuffers[i] = createRenderbuffer();
5092 }
5093}
5094
5095void Context::genTextures(GLsizei n, GLuint *textures)
5096{
5097 for (int i = 0; i < n; i++)
5098 {
5099 textures[i] = createTexture();
5100 }
5101}
5102
5103void Context::getActiveAttrib(GLuint program,
5104 GLuint index,
5105 GLsizei bufsize,
5106 GLsizei *length,
5107 GLint *size,
5108 GLenum *type,
5109 GLchar *name)
5110{
5111 Program *programObject = getProgram(program);
5112 ASSERT(programObject);
5113 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5114}
5115
5116void Context::getActiveUniform(GLuint program,
5117 GLuint index,
5118 GLsizei bufsize,
5119 GLsizei *length,
5120 GLint *size,
5121 GLenum *type,
5122 GLchar *name)
5123{
5124 Program *programObject = getProgram(program);
5125 ASSERT(programObject);
5126 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5127}
5128
5129void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5130{
5131 Program *programObject = getProgram(program);
5132 ASSERT(programObject);
5133 programObject->getAttachedShaders(maxcount, count, shaders);
5134}
5135
5136GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5137{
5138 Program *programObject = getProgram(program);
5139 ASSERT(programObject);
5140 return programObject->getAttributeLocation(name);
5141}
5142
5143void Context::getBooleanv(GLenum pname, GLboolean *params)
5144{
5145 GLenum nativeType;
5146 unsigned int numParams = 0;
5147 getQueryParameterInfo(pname, &nativeType, &numParams);
5148
5149 if (nativeType == GL_BOOL)
5150 {
5151 getBooleanvImpl(pname, params);
5152 }
5153 else
5154 {
5155 CastStateValues(this, nativeType, pname, numParams, params);
5156 }
5157}
5158
Brandon Jones59770802018-04-02 13:18:42 -07005159void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5160{
5161 getBooleanv(pname, params);
5162}
5163
Jamie Madillc1d770e2017-04-13 17:31:24 -04005164void Context::getFloatv(GLenum pname, GLfloat *params)
5165{
5166 GLenum nativeType;
5167 unsigned int numParams = 0;
5168 getQueryParameterInfo(pname, &nativeType, &numParams);
5169
5170 if (nativeType == GL_FLOAT)
5171 {
5172 getFloatvImpl(pname, params);
5173 }
5174 else
5175 {
5176 CastStateValues(this, nativeType, pname, numParams, params);
5177 }
5178}
5179
Brandon Jones59770802018-04-02 13:18:42 -07005180void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5181{
5182 getFloatv(pname, params);
5183}
5184
Jamie Madillc1d770e2017-04-13 17:31:24 -04005185void Context::getIntegerv(GLenum pname, GLint *params)
5186{
5187 GLenum nativeType;
5188 unsigned int numParams = 0;
5189 getQueryParameterInfo(pname, &nativeType, &numParams);
5190
5191 if (nativeType == GL_INT)
5192 {
5193 getIntegervImpl(pname, params);
5194 }
5195 else
5196 {
5197 CastStateValues(this, nativeType, pname, numParams, params);
5198 }
5199}
5200
Brandon Jones59770802018-04-02 13:18:42 -07005201void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5202{
5203 getIntegerv(pname, data);
5204}
5205
Jamie Madillc1d770e2017-04-13 17:31:24 -04005206void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5207{
5208 Program *programObject = getProgram(program);
5209 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005210 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005211}
5212
Brandon Jones59770802018-04-02 13:18:42 -07005213void Context::getProgramivRobust(GLuint program,
5214 GLenum pname,
5215 GLsizei bufSize,
5216 GLsizei *length,
5217 GLint *params)
5218{
5219 getProgramiv(program, pname, params);
5220}
5221
Jiajia Qin5451d532017-11-16 17:16:34 +08005222void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5223{
5224 UNIMPLEMENTED();
5225}
5226
Jamie Madillbe849e42017-05-02 15:49:00 -04005227void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005228{
5229 Program *programObject = getProgram(program);
5230 ASSERT(programObject);
5231 programObject->getInfoLog(bufsize, length, infolog);
5232}
5233
Jiajia Qin5451d532017-11-16 17:16:34 +08005234void Context::getProgramPipelineInfoLog(GLuint pipeline,
5235 GLsizei bufSize,
5236 GLsizei *length,
5237 GLchar *infoLog)
5238{
5239 UNIMPLEMENTED();
5240}
5241
Jamie Madillc1d770e2017-04-13 17:31:24 -04005242void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5243{
5244 Shader *shaderObject = getShader(shader);
5245 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005246 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005247}
5248
Brandon Jones59770802018-04-02 13:18:42 -07005249void Context::getShaderivRobust(GLuint shader,
5250 GLenum pname,
5251 GLsizei bufSize,
5252 GLsizei *length,
5253 GLint *params)
5254{
5255 getShaderiv(shader, pname, params);
5256}
5257
Jamie Madillc1d770e2017-04-13 17:31:24 -04005258void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5259{
5260 Shader *shaderObject = getShader(shader);
5261 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005262 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005263}
5264
5265void Context::getShaderPrecisionFormat(GLenum shadertype,
5266 GLenum precisiontype,
5267 GLint *range,
5268 GLint *precision)
5269{
5270 // TODO(jmadill): Compute shaders.
5271
5272 switch (shadertype)
5273 {
5274 case GL_VERTEX_SHADER:
5275 switch (precisiontype)
5276 {
5277 case GL_LOW_FLOAT:
5278 mCaps.vertexLowpFloat.get(range, precision);
5279 break;
5280 case GL_MEDIUM_FLOAT:
5281 mCaps.vertexMediumpFloat.get(range, precision);
5282 break;
5283 case GL_HIGH_FLOAT:
5284 mCaps.vertexHighpFloat.get(range, precision);
5285 break;
5286
5287 case GL_LOW_INT:
5288 mCaps.vertexLowpInt.get(range, precision);
5289 break;
5290 case GL_MEDIUM_INT:
5291 mCaps.vertexMediumpInt.get(range, precision);
5292 break;
5293 case GL_HIGH_INT:
5294 mCaps.vertexHighpInt.get(range, precision);
5295 break;
5296
5297 default:
5298 UNREACHABLE();
5299 return;
5300 }
5301 break;
5302
5303 case GL_FRAGMENT_SHADER:
5304 switch (precisiontype)
5305 {
5306 case GL_LOW_FLOAT:
5307 mCaps.fragmentLowpFloat.get(range, precision);
5308 break;
5309 case GL_MEDIUM_FLOAT:
5310 mCaps.fragmentMediumpFloat.get(range, precision);
5311 break;
5312 case GL_HIGH_FLOAT:
5313 mCaps.fragmentHighpFloat.get(range, precision);
5314 break;
5315
5316 case GL_LOW_INT:
5317 mCaps.fragmentLowpInt.get(range, precision);
5318 break;
5319 case GL_MEDIUM_INT:
5320 mCaps.fragmentMediumpInt.get(range, precision);
5321 break;
5322 case GL_HIGH_INT:
5323 mCaps.fragmentHighpInt.get(range, precision);
5324 break;
5325
5326 default:
5327 UNREACHABLE();
5328 return;
5329 }
5330 break;
5331
5332 default:
5333 UNREACHABLE();
5334 return;
5335 }
5336}
5337
5338void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5339{
5340 Shader *shaderObject = getShader(shader);
5341 ASSERT(shaderObject);
5342 shaderObject->getSource(bufsize, length, source);
5343}
5344
5345void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5346{
5347 Program *programObject = getProgram(program);
5348 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005349 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005350}
5351
Brandon Jones59770802018-04-02 13:18:42 -07005352void Context::getUniformfvRobust(GLuint program,
5353 GLint location,
5354 GLsizei bufSize,
5355 GLsizei *length,
5356 GLfloat *params)
5357{
5358 getUniformfv(program, location, params);
5359}
5360
Jamie Madillc1d770e2017-04-13 17:31:24 -04005361void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5362{
5363 Program *programObject = getProgram(program);
5364 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005365 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366}
5367
Brandon Jones59770802018-04-02 13:18:42 -07005368void Context::getUniformivRobust(GLuint program,
5369 GLint location,
5370 GLsizei bufSize,
5371 GLsizei *length,
5372 GLint *params)
5373{
5374 getUniformiv(program, location, params);
5375}
5376
Jamie Madillc1d770e2017-04-13 17:31:24 -04005377GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5378{
5379 Program *programObject = getProgram(program);
5380 ASSERT(programObject);
5381 return programObject->getUniformLocation(name);
5382}
5383
5384GLboolean Context::isBuffer(GLuint buffer)
5385{
5386 if (buffer == 0)
5387 {
5388 return GL_FALSE;
5389 }
5390
5391 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5392}
5393
5394GLboolean Context::isEnabled(GLenum cap)
5395{
5396 return mGLState.getEnableFeature(cap);
5397}
5398
5399GLboolean Context::isFramebuffer(GLuint framebuffer)
5400{
5401 if (framebuffer == 0)
5402 {
5403 return GL_FALSE;
5404 }
5405
5406 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5407}
5408
5409GLboolean Context::isProgram(GLuint program)
5410{
5411 if (program == 0)
5412 {
5413 return GL_FALSE;
5414 }
5415
5416 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5417}
5418
5419GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5420{
5421 if (renderbuffer == 0)
5422 {
5423 return GL_FALSE;
5424 }
5425
5426 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5427}
5428
5429GLboolean Context::isShader(GLuint shader)
5430{
5431 if (shader == 0)
5432 {
5433 return GL_FALSE;
5434 }
5435
5436 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5437}
5438
5439GLboolean Context::isTexture(GLuint texture)
5440{
5441 if (texture == 0)
5442 {
5443 return GL_FALSE;
5444 }
5445
5446 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5447}
5448
5449void Context::linkProgram(GLuint program)
5450{
5451 Program *programObject = getProgram(program);
5452 ASSERT(programObject);
5453 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005454 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005455}
5456
5457void Context::releaseShaderCompiler()
5458{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005459 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460}
5461
5462void Context::shaderBinary(GLsizei n,
5463 const GLuint *shaders,
5464 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005465 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466 GLsizei length)
5467{
5468 // No binary shader formats are supported.
5469 UNIMPLEMENTED();
5470}
5471
5472void Context::shaderSource(GLuint shader,
5473 GLsizei count,
5474 const GLchar *const *string,
5475 const GLint *length)
5476{
5477 Shader *shaderObject = getShader(shader);
5478 ASSERT(shaderObject);
5479 shaderObject->setSource(count, string, length);
5480}
5481
5482void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5483{
5484 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5485}
5486
5487void Context::stencilMask(GLuint mask)
5488{
5489 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5490}
5491
5492void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5493{
5494 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5495}
5496
5497void Context::uniform1f(GLint location, GLfloat x)
5498{
5499 Program *program = mGLState.getProgram();
5500 program->setUniform1fv(location, 1, &x);
5501}
5502
5503void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5504{
5505 Program *program = mGLState.getProgram();
5506 program->setUniform1fv(location, count, v);
5507}
5508
5509void Context::uniform1i(GLint location, GLint x)
5510{
5511 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005512 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5513 {
5514 mGLState.setObjectDirty(GL_PROGRAM);
5515 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005516}
5517
5518void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5519{
5520 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005521 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5522 {
5523 mGLState.setObjectDirty(GL_PROGRAM);
5524 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005525}
5526
5527void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5528{
5529 GLfloat xy[2] = {x, y};
5530 Program *program = mGLState.getProgram();
5531 program->setUniform2fv(location, 1, xy);
5532}
5533
5534void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5535{
5536 Program *program = mGLState.getProgram();
5537 program->setUniform2fv(location, count, v);
5538}
5539
5540void Context::uniform2i(GLint location, GLint x, GLint y)
5541{
5542 GLint xy[2] = {x, y};
5543 Program *program = mGLState.getProgram();
5544 program->setUniform2iv(location, 1, xy);
5545}
5546
5547void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5548{
5549 Program *program = mGLState.getProgram();
5550 program->setUniform2iv(location, count, v);
5551}
5552
5553void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5554{
5555 GLfloat xyz[3] = {x, y, z};
5556 Program *program = mGLState.getProgram();
5557 program->setUniform3fv(location, 1, xyz);
5558}
5559
5560void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5561{
5562 Program *program = mGLState.getProgram();
5563 program->setUniform3fv(location, count, v);
5564}
5565
5566void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5567{
5568 GLint xyz[3] = {x, y, z};
5569 Program *program = mGLState.getProgram();
5570 program->setUniform3iv(location, 1, xyz);
5571}
5572
5573void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5574{
5575 Program *program = mGLState.getProgram();
5576 program->setUniform3iv(location, count, v);
5577}
5578
5579void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5580{
5581 GLfloat xyzw[4] = {x, y, z, w};
5582 Program *program = mGLState.getProgram();
5583 program->setUniform4fv(location, 1, xyzw);
5584}
5585
5586void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5587{
5588 Program *program = mGLState.getProgram();
5589 program->setUniform4fv(location, count, v);
5590}
5591
5592void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5593{
5594 GLint xyzw[4] = {x, y, z, w};
5595 Program *program = mGLState.getProgram();
5596 program->setUniform4iv(location, 1, xyzw);
5597}
5598
5599void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5600{
5601 Program *program = mGLState.getProgram();
5602 program->setUniform4iv(location, count, v);
5603}
5604
5605void Context::uniformMatrix2fv(GLint location,
5606 GLsizei count,
5607 GLboolean transpose,
5608 const GLfloat *value)
5609{
5610 Program *program = mGLState.getProgram();
5611 program->setUniformMatrix2fv(location, count, transpose, value);
5612}
5613
5614void Context::uniformMatrix3fv(GLint location,
5615 GLsizei count,
5616 GLboolean transpose,
5617 const GLfloat *value)
5618{
5619 Program *program = mGLState.getProgram();
5620 program->setUniformMatrix3fv(location, count, transpose, value);
5621}
5622
5623void Context::uniformMatrix4fv(GLint location,
5624 GLsizei count,
5625 GLboolean transpose,
5626 const GLfloat *value)
5627{
5628 Program *program = mGLState.getProgram();
5629 program->setUniformMatrix4fv(location, count, transpose, value);
5630}
5631
5632void Context::validateProgram(GLuint program)
5633{
5634 Program *programObject = getProgram(program);
5635 ASSERT(programObject);
5636 programObject->validate(mCaps);
5637}
5638
Jiajia Qin5451d532017-11-16 17:16:34 +08005639void Context::validateProgramPipeline(GLuint pipeline)
5640{
5641 UNIMPLEMENTED();
5642}
5643
Jamie Madilld04908b2017-06-09 14:15:35 -04005644void Context::getProgramBinary(GLuint program,
5645 GLsizei bufSize,
5646 GLsizei *length,
5647 GLenum *binaryFormat,
5648 void *binary)
5649{
5650 Program *programObject = getProgram(program);
5651 ASSERT(programObject != nullptr);
5652
5653 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5654}
5655
5656void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5657{
5658 Program *programObject = getProgram(program);
5659 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005660
Jamie Madilld04908b2017-06-09 14:15:35 -04005661 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5662}
5663
Jamie Madillff325f12017-08-26 15:06:05 -04005664void Context::uniform1ui(GLint location, GLuint v0)
5665{
5666 Program *program = mGLState.getProgram();
5667 program->setUniform1uiv(location, 1, &v0);
5668}
5669
5670void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5671{
5672 Program *program = mGLState.getProgram();
5673 const GLuint xy[] = {v0, v1};
5674 program->setUniform2uiv(location, 1, xy);
5675}
5676
5677void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5678{
5679 Program *program = mGLState.getProgram();
5680 const GLuint xyz[] = {v0, v1, v2};
5681 program->setUniform3uiv(location, 1, xyz);
5682}
5683
5684void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5685{
5686 Program *program = mGLState.getProgram();
5687 const GLuint xyzw[] = {v0, v1, v2, v3};
5688 program->setUniform4uiv(location, 1, xyzw);
5689}
5690
5691void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5692{
5693 Program *program = mGLState.getProgram();
5694 program->setUniform1uiv(location, count, value);
5695}
5696void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5697{
5698 Program *program = mGLState.getProgram();
5699 program->setUniform2uiv(location, count, value);
5700}
5701
5702void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5703{
5704 Program *program = mGLState.getProgram();
5705 program->setUniform3uiv(location, count, value);
5706}
5707
5708void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5709{
5710 Program *program = mGLState.getProgram();
5711 program->setUniform4uiv(location, count, value);
5712}
5713
Jamie Madillf0e04492017-08-26 15:28:42 -04005714void Context::genQueries(GLsizei n, GLuint *ids)
5715{
5716 for (GLsizei i = 0; i < n; i++)
5717 {
5718 GLuint handle = mQueryHandleAllocator.allocate();
5719 mQueryMap.assign(handle, nullptr);
5720 ids[i] = handle;
5721 }
5722}
5723
5724void Context::deleteQueries(GLsizei n, const GLuint *ids)
5725{
5726 for (int i = 0; i < n; i++)
5727 {
5728 GLuint query = ids[i];
5729
5730 Query *queryObject = nullptr;
5731 if (mQueryMap.erase(query, &queryObject))
5732 {
5733 mQueryHandleAllocator.release(query);
5734 if (queryObject)
5735 {
5736 queryObject->release(this);
5737 }
5738 }
5739 }
5740}
5741
5742GLboolean Context::isQuery(GLuint id)
5743{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005744 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005745}
5746
Jamie Madillc8c95812017-08-26 18:40:09 -04005747void Context::uniformMatrix2x3fv(GLint location,
5748 GLsizei count,
5749 GLboolean transpose,
5750 const GLfloat *value)
5751{
5752 Program *program = mGLState.getProgram();
5753 program->setUniformMatrix2x3fv(location, count, transpose, value);
5754}
5755
5756void Context::uniformMatrix3x2fv(GLint location,
5757 GLsizei count,
5758 GLboolean transpose,
5759 const GLfloat *value)
5760{
5761 Program *program = mGLState.getProgram();
5762 program->setUniformMatrix3x2fv(location, count, transpose, value);
5763}
5764
5765void Context::uniformMatrix2x4fv(GLint location,
5766 GLsizei count,
5767 GLboolean transpose,
5768 const GLfloat *value)
5769{
5770 Program *program = mGLState.getProgram();
5771 program->setUniformMatrix2x4fv(location, count, transpose, value);
5772}
5773
5774void Context::uniformMatrix4x2fv(GLint location,
5775 GLsizei count,
5776 GLboolean transpose,
5777 const GLfloat *value)
5778{
5779 Program *program = mGLState.getProgram();
5780 program->setUniformMatrix4x2fv(location, count, transpose, value);
5781}
5782
5783void Context::uniformMatrix3x4fv(GLint location,
5784 GLsizei count,
5785 GLboolean transpose,
5786 const GLfloat *value)
5787{
5788 Program *program = mGLState.getProgram();
5789 program->setUniformMatrix3x4fv(location, count, transpose, value);
5790}
5791
5792void Context::uniformMatrix4x3fv(GLint location,
5793 GLsizei count,
5794 GLboolean transpose,
5795 const GLfloat *value)
5796{
5797 Program *program = mGLState.getProgram();
5798 program->setUniformMatrix4x3fv(location, count, transpose, value);
5799}
5800
Jamie Madilld7576732017-08-26 18:49:50 -04005801void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5802{
5803 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5804 {
5805 GLuint vertexArray = arrays[arrayIndex];
5806
5807 if (arrays[arrayIndex] != 0)
5808 {
5809 VertexArray *vertexArrayObject = nullptr;
5810 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5811 {
5812 if (vertexArrayObject != nullptr)
5813 {
5814 detachVertexArray(vertexArray);
5815 vertexArrayObject->onDestroy(this);
5816 }
5817
5818 mVertexArrayHandleAllocator.release(vertexArray);
5819 }
5820 }
5821 }
5822}
5823
5824void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5825{
5826 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5827 {
5828 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5829 mVertexArrayMap.assign(vertexArray, nullptr);
5830 arrays[arrayIndex] = vertexArray;
5831 }
5832}
5833
5834bool Context::isVertexArray(GLuint array)
5835{
5836 if (array == 0)
5837 {
5838 return GL_FALSE;
5839 }
5840
5841 VertexArray *vao = getVertexArray(array);
5842 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5843}
5844
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005845void Context::endTransformFeedback()
5846{
5847 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5848 transformFeedback->end(this);
5849}
5850
5851void Context::transformFeedbackVaryings(GLuint program,
5852 GLsizei count,
5853 const GLchar *const *varyings,
5854 GLenum bufferMode)
5855{
5856 Program *programObject = getProgram(program);
5857 ASSERT(programObject);
5858 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5859}
5860
5861void Context::getTransformFeedbackVarying(GLuint program,
5862 GLuint index,
5863 GLsizei bufSize,
5864 GLsizei *length,
5865 GLsizei *size,
5866 GLenum *type,
5867 GLchar *name)
5868{
5869 Program *programObject = getProgram(program);
5870 ASSERT(programObject);
5871 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5872}
5873
5874void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5875{
5876 for (int i = 0; i < n; i++)
5877 {
5878 GLuint transformFeedback = ids[i];
5879 if (transformFeedback == 0)
5880 {
5881 continue;
5882 }
5883
5884 TransformFeedback *transformFeedbackObject = nullptr;
5885 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5886 {
5887 if (transformFeedbackObject != nullptr)
5888 {
5889 detachTransformFeedback(transformFeedback);
5890 transformFeedbackObject->release(this);
5891 }
5892
5893 mTransformFeedbackHandleAllocator.release(transformFeedback);
5894 }
5895 }
5896}
5897
5898void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5899{
5900 for (int i = 0; i < n; i++)
5901 {
5902 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5903 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5904 ids[i] = transformFeedback;
5905 }
5906}
5907
5908bool Context::isTransformFeedback(GLuint id)
5909{
5910 if (id == 0)
5911 {
5912 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5913 // returns FALSE
5914 return GL_FALSE;
5915 }
5916
5917 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5918 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5919}
5920
5921void Context::pauseTransformFeedback()
5922{
5923 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5924 transformFeedback->pause();
5925}
5926
5927void Context::resumeTransformFeedback()
5928{
5929 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5930 transformFeedback->resume();
5931}
5932
Jamie Madill12e957f2017-08-26 21:42:26 -04005933void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5934{
5935 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005936 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005937}
5938
Brandon Jones59770802018-04-02 13:18:42 -07005939void Context::getUniformuivRobust(GLuint program,
5940 GLint location,
5941 GLsizei bufSize,
5942 GLsizei *length,
5943 GLuint *params)
5944{
5945 getUniformuiv(program, location, params);
5946}
5947
Jamie Madill12e957f2017-08-26 21:42:26 -04005948GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5949{
5950 const Program *programObject = getProgram(program);
5951 return programObject->getFragDataLocation(name);
5952}
5953
5954void Context::getUniformIndices(GLuint program,
5955 GLsizei uniformCount,
5956 const GLchar *const *uniformNames,
5957 GLuint *uniformIndices)
5958{
5959 const Program *programObject = getProgram(program);
5960 if (!programObject->isLinked())
5961 {
5962 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5963 {
5964 uniformIndices[uniformId] = GL_INVALID_INDEX;
5965 }
5966 }
5967 else
5968 {
5969 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5970 {
5971 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5972 }
5973 }
5974}
5975
5976void Context::getActiveUniformsiv(GLuint program,
5977 GLsizei uniformCount,
5978 const GLuint *uniformIndices,
5979 GLenum pname,
5980 GLint *params)
5981{
5982 const Program *programObject = getProgram(program);
5983 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5984 {
5985 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005986 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005987 }
5988}
5989
5990GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5991{
5992 const Program *programObject = getProgram(program);
5993 return programObject->getUniformBlockIndex(uniformBlockName);
5994}
5995
5996void Context::getActiveUniformBlockiv(GLuint program,
5997 GLuint uniformBlockIndex,
5998 GLenum pname,
5999 GLint *params)
6000{
6001 const Program *programObject = getProgram(program);
6002 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6003}
6004
Brandon Jones59770802018-04-02 13:18:42 -07006005void Context::getActiveUniformBlockivRobust(GLuint program,
6006 GLuint uniformBlockIndex,
6007 GLenum pname,
6008 GLsizei bufSize,
6009 GLsizei *length,
6010 GLint *params)
6011{
6012 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6013}
6014
Jamie Madill12e957f2017-08-26 21:42:26 -04006015void Context::getActiveUniformBlockName(GLuint program,
6016 GLuint uniformBlockIndex,
6017 GLsizei bufSize,
6018 GLsizei *length,
6019 GLchar *uniformBlockName)
6020{
6021 const Program *programObject = getProgram(program);
6022 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6023}
6024
6025void Context::uniformBlockBinding(GLuint program,
6026 GLuint uniformBlockIndex,
6027 GLuint uniformBlockBinding)
6028{
6029 Program *programObject = getProgram(program);
6030 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6031}
6032
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006033GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6034{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006035 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6036 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006037
Jamie Madill70b5bb02017-08-28 13:32:37 -04006038 Sync *syncObject = getSync(syncHandle);
6039 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006040 if (error.isError())
6041 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006042 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006043 handleError(error);
6044 return nullptr;
6045 }
6046
Jamie Madill70b5bb02017-08-28 13:32:37 -04006047 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006048}
6049
6050GLboolean Context::isSync(GLsync sync)
6051{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006052 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006053}
6054
6055GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6056{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006057 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006058
6059 GLenum result = GL_WAIT_FAILED;
6060 handleError(syncObject->clientWait(flags, timeout, &result));
6061 return result;
6062}
6063
6064void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6065{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006066 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006067 handleError(syncObject->serverWait(flags, timeout));
6068}
6069
6070void Context::getInteger64v(GLenum pname, GLint64 *params)
6071{
6072 GLenum nativeType = GL_NONE;
6073 unsigned int numParams = 0;
6074 getQueryParameterInfo(pname, &nativeType, &numParams);
6075
6076 if (nativeType == GL_INT_64_ANGLEX)
6077 {
6078 getInteger64vImpl(pname, params);
6079 }
6080 else
6081 {
6082 CastStateValues(this, nativeType, pname, numParams, params);
6083 }
6084}
6085
Brandon Jones59770802018-04-02 13:18:42 -07006086void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6087{
6088 getInteger64v(pname, data);
6089}
6090
Corentin Wallez336129f2017-10-17 15:55:40 -04006091void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006092{
6093 Buffer *buffer = mGLState.getTargetBuffer(target);
6094 QueryBufferParameteri64v(buffer, pname, params);
6095}
6096
Brandon Jones59770802018-04-02 13:18:42 -07006097void Context::getBufferParameteri64vRobust(BufferBinding target,
6098 GLenum pname,
6099 GLsizei bufSize,
6100 GLsizei *length,
6101 GLint64 *params)
6102{
6103 getBufferParameteri64v(target, pname, params);
6104}
6105
Jamie Madill3ef140a2017-08-26 23:11:21 -04006106void Context::genSamplers(GLsizei count, GLuint *samplers)
6107{
6108 for (int i = 0; i < count; i++)
6109 {
6110 samplers[i] = mState.mSamplers->createSampler();
6111 }
6112}
6113
6114void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6115{
6116 for (int i = 0; i < count; i++)
6117 {
6118 GLuint sampler = samplers[i];
6119
6120 if (mState.mSamplers->getSampler(sampler))
6121 {
6122 detachSampler(sampler);
6123 }
6124
6125 mState.mSamplers->deleteObject(this, sampler);
6126 }
6127}
6128
6129void Context::getInternalformativ(GLenum target,
6130 GLenum internalformat,
6131 GLenum pname,
6132 GLsizei bufSize,
6133 GLint *params)
6134{
6135 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6136 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6137}
6138
Brandon Jones59770802018-04-02 13:18:42 -07006139void Context::getInternalformativRobust(GLenum target,
6140 GLenum internalformat,
6141 GLenum pname,
6142 GLsizei bufSize,
6143 GLsizei *length,
6144 GLint *params)
6145{
6146 getInternalformativ(target, internalformat, pname, bufSize, params);
6147}
6148
Jiajia Qin5451d532017-11-16 17:16:34 +08006149void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6150{
6151 programUniform1iv(program, location, 1, &v0);
6152}
6153
6154void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6155{
6156 GLint xy[2] = {v0, v1};
6157 programUniform2iv(program, location, 1, xy);
6158}
6159
6160void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6161{
6162 GLint xyz[3] = {v0, v1, v2};
6163 programUniform3iv(program, location, 1, xyz);
6164}
6165
6166void Context::programUniform4i(GLuint program,
6167 GLint location,
6168 GLint v0,
6169 GLint v1,
6170 GLint v2,
6171 GLint v3)
6172{
6173 GLint xyzw[4] = {v0, v1, v2, v3};
6174 programUniform4iv(program, location, 1, xyzw);
6175}
6176
6177void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6178{
6179 programUniform1uiv(program, location, 1, &v0);
6180}
6181
6182void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6183{
6184 GLuint xy[2] = {v0, v1};
6185 programUniform2uiv(program, location, 1, xy);
6186}
6187
6188void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6189{
6190 GLuint xyz[3] = {v0, v1, v2};
6191 programUniform3uiv(program, location, 1, xyz);
6192}
6193
6194void Context::programUniform4ui(GLuint program,
6195 GLint location,
6196 GLuint v0,
6197 GLuint v1,
6198 GLuint v2,
6199 GLuint v3)
6200{
6201 GLuint xyzw[4] = {v0, v1, v2, v3};
6202 programUniform4uiv(program, location, 1, xyzw);
6203}
6204
6205void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6206{
6207 programUniform1fv(program, location, 1, &v0);
6208}
6209
6210void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6211{
6212 GLfloat xy[2] = {v0, v1};
6213 programUniform2fv(program, location, 1, xy);
6214}
6215
6216void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6217{
6218 GLfloat xyz[3] = {v0, v1, v2};
6219 programUniform3fv(program, location, 1, xyz);
6220}
6221
6222void Context::programUniform4f(GLuint program,
6223 GLint location,
6224 GLfloat v0,
6225 GLfloat v1,
6226 GLfloat v2,
6227 GLfloat v3)
6228{
6229 GLfloat xyzw[4] = {v0, v1, v2, v3};
6230 programUniform4fv(program, location, 1, xyzw);
6231}
6232
Jamie Madill81c2e252017-09-09 23:32:46 -04006233void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6234{
6235 Program *programObject = getProgram(program);
6236 ASSERT(programObject);
6237 if (programObject->setUniform1iv(location, count, value) ==
6238 Program::SetUniformResult::SamplerChanged)
6239 {
6240 mGLState.setObjectDirty(GL_PROGRAM);
6241 }
6242}
6243
Jiajia Qin5451d532017-11-16 17:16:34 +08006244void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6245{
6246 Program *programObject = getProgram(program);
6247 ASSERT(programObject);
6248 programObject->setUniform2iv(location, count, value);
6249}
6250
6251void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6252{
6253 Program *programObject = getProgram(program);
6254 ASSERT(programObject);
6255 programObject->setUniform3iv(location, count, value);
6256}
6257
6258void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6259{
6260 Program *programObject = getProgram(program);
6261 ASSERT(programObject);
6262 programObject->setUniform4iv(location, count, value);
6263}
6264
6265void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6266{
6267 Program *programObject = getProgram(program);
6268 ASSERT(programObject);
6269 programObject->setUniform1uiv(location, count, value);
6270}
6271
6272void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6273{
6274 Program *programObject = getProgram(program);
6275 ASSERT(programObject);
6276 programObject->setUniform2uiv(location, count, value);
6277}
6278
6279void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6280{
6281 Program *programObject = getProgram(program);
6282 ASSERT(programObject);
6283 programObject->setUniform3uiv(location, count, value);
6284}
6285
6286void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6287{
6288 Program *programObject = getProgram(program);
6289 ASSERT(programObject);
6290 programObject->setUniform4uiv(location, count, value);
6291}
6292
6293void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6294{
6295 Program *programObject = getProgram(program);
6296 ASSERT(programObject);
6297 programObject->setUniform1fv(location, count, value);
6298}
6299
6300void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6301{
6302 Program *programObject = getProgram(program);
6303 ASSERT(programObject);
6304 programObject->setUniform2fv(location, count, value);
6305}
6306
6307void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6308{
6309 Program *programObject = getProgram(program);
6310 ASSERT(programObject);
6311 programObject->setUniform3fv(location, count, value);
6312}
6313
6314void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6315{
6316 Program *programObject = getProgram(program);
6317 ASSERT(programObject);
6318 programObject->setUniform4fv(location, count, value);
6319}
6320
6321void Context::programUniformMatrix2fv(GLuint program,
6322 GLint location,
6323 GLsizei count,
6324 GLboolean transpose,
6325 const GLfloat *value)
6326{
6327 Program *programObject = getProgram(program);
6328 ASSERT(programObject);
6329 programObject->setUniformMatrix2fv(location, count, transpose, value);
6330}
6331
6332void Context::programUniformMatrix3fv(GLuint program,
6333 GLint location,
6334 GLsizei count,
6335 GLboolean transpose,
6336 const GLfloat *value)
6337{
6338 Program *programObject = getProgram(program);
6339 ASSERT(programObject);
6340 programObject->setUniformMatrix3fv(location, count, transpose, value);
6341}
6342
6343void Context::programUniformMatrix4fv(GLuint program,
6344 GLint location,
6345 GLsizei count,
6346 GLboolean transpose,
6347 const GLfloat *value)
6348{
6349 Program *programObject = getProgram(program);
6350 ASSERT(programObject);
6351 programObject->setUniformMatrix4fv(location, count, transpose, value);
6352}
6353
6354void Context::programUniformMatrix2x3fv(GLuint program,
6355 GLint location,
6356 GLsizei count,
6357 GLboolean transpose,
6358 const GLfloat *value)
6359{
6360 Program *programObject = getProgram(program);
6361 ASSERT(programObject);
6362 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6363}
6364
6365void Context::programUniformMatrix3x2fv(GLuint program,
6366 GLint location,
6367 GLsizei count,
6368 GLboolean transpose,
6369 const GLfloat *value)
6370{
6371 Program *programObject = getProgram(program);
6372 ASSERT(programObject);
6373 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6374}
6375
6376void Context::programUniformMatrix2x4fv(GLuint program,
6377 GLint location,
6378 GLsizei count,
6379 GLboolean transpose,
6380 const GLfloat *value)
6381{
6382 Program *programObject = getProgram(program);
6383 ASSERT(programObject);
6384 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6385}
6386
6387void Context::programUniformMatrix4x2fv(GLuint program,
6388 GLint location,
6389 GLsizei count,
6390 GLboolean transpose,
6391 const GLfloat *value)
6392{
6393 Program *programObject = getProgram(program);
6394 ASSERT(programObject);
6395 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6396}
6397
6398void Context::programUniformMatrix3x4fv(GLuint program,
6399 GLint location,
6400 GLsizei count,
6401 GLboolean transpose,
6402 const GLfloat *value)
6403{
6404 Program *programObject = getProgram(program);
6405 ASSERT(programObject);
6406 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6407}
6408
6409void Context::programUniformMatrix4x3fv(GLuint program,
6410 GLint location,
6411 GLsizei count,
6412 GLboolean transpose,
6413 const GLfloat *value)
6414{
6415 Program *programObject = getProgram(program);
6416 ASSERT(programObject);
6417 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6418}
6419
Jamie Madill81c2e252017-09-09 23:32:46 -04006420void Context::onTextureChange(const Texture *texture)
6421{
6422 // Conservatively assume all textures are dirty.
6423 // TODO(jmadill): More fine-grained update.
6424 mGLState.setObjectDirty(GL_TEXTURE);
6425}
6426
James Darpiniane8a93c62018-01-04 18:02:24 -08006427bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6428{
6429 return mGLState.isCurrentTransformFeedback(tf);
6430}
6431bool Context::isCurrentVertexArray(const VertexArray *va) const
6432{
6433 return mGLState.isCurrentVertexArray(va);
6434}
6435
Yunchao Hea336b902017-08-02 16:05:21 +08006436void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6437{
6438 for (int i = 0; i < count; i++)
6439 {
6440 pipelines[i] = createProgramPipeline();
6441 }
6442}
6443
6444void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6445{
6446 for (int i = 0; i < count; i++)
6447 {
6448 if (pipelines[i] != 0)
6449 {
6450 deleteProgramPipeline(pipelines[i]);
6451 }
6452 }
6453}
6454
6455GLboolean Context::isProgramPipeline(GLuint pipeline)
6456{
6457 if (pipeline == 0)
6458 {
6459 return GL_FALSE;
6460 }
6461
6462 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6463}
6464
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006465void Context::finishFenceNV(GLuint fence)
6466{
6467 FenceNV *fenceObject = getFenceNV(fence);
6468
6469 ASSERT(fenceObject && fenceObject->isSet());
6470 handleError(fenceObject->finish());
6471}
6472
6473void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6474{
6475 FenceNV *fenceObject = getFenceNV(fence);
6476
6477 ASSERT(fenceObject && fenceObject->isSet());
6478
6479 switch (pname)
6480 {
6481 case GL_FENCE_STATUS_NV:
6482 {
6483 // GL_NV_fence spec:
6484 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6485 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6486 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6487 GLboolean status = GL_TRUE;
6488 if (fenceObject->getStatus() != GL_TRUE)
6489 {
6490 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6491 }
6492 *params = status;
6493 break;
6494 }
6495
6496 case GL_FENCE_CONDITION_NV:
6497 {
6498 *params = static_cast<GLint>(fenceObject->getCondition());
6499 break;
6500 }
6501
6502 default:
6503 UNREACHABLE();
6504 }
6505}
6506
6507void Context::getTranslatedShaderSource(GLuint shader,
6508 GLsizei bufsize,
6509 GLsizei *length,
6510 GLchar *source)
6511{
6512 Shader *shaderObject = getShader(shader);
6513 ASSERT(shaderObject);
6514 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6515}
6516
6517void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6518{
6519 Program *programObject = getProgram(program);
6520 ASSERT(programObject);
6521
6522 programObject->getUniformfv(this, location, params);
6523}
6524
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006525void Context::getnUniformfvRobust(GLuint program,
6526 GLint location,
6527 GLsizei bufSize,
6528 GLsizei *length,
6529 GLfloat *params)
6530{
6531 UNIMPLEMENTED();
6532}
6533
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006534void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6535{
6536 Program *programObject = getProgram(program);
6537 ASSERT(programObject);
6538
6539 programObject->getUniformiv(this, location, params);
6540}
6541
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006542void Context::getnUniformivRobust(GLuint program,
6543 GLint location,
6544 GLsizei bufSize,
6545 GLsizei *length,
6546 GLint *params)
6547{
6548 UNIMPLEMENTED();
6549}
6550
6551void Context::getnUniformuivRobust(GLuint program,
6552 GLint location,
6553 GLsizei bufSize,
6554 GLsizei *length,
6555 GLuint *params)
6556{
6557 UNIMPLEMENTED();
6558}
6559
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006560GLboolean Context::isFenceNV(GLuint fence)
6561{
6562 FenceNV *fenceObject = getFenceNV(fence);
6563
6564 if (fenceObject == nullptr)
6565 {
6566 return GL_FALSE;
6567 }
6568
6569 // GL_NV_fence spec:
6570 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6571 // existing fence.
6572 return fenceObject->isSet();
6573}
6574
6575void Context::readnPixels(GLint x,
6576 GLint y,
6577 GLsizei width,
6578 GLsizei height,
6579 GLenum format,
6580 GLenum type,
6581 GLsizei bufSize,
6582 void *data)
6583{
6584 return readPixels(x, y, width, height, format, type, data);
6585}
6586
Jamie Madill007530e2017-12-28 14:27:04 -05006587void Context::setFenceNV(GLuint fence, GLenum condition)
6588{
6589 ASSERT(condition == GL_ALL_COMPLETED_NV);
6590
6591 FenceNV *fenceObject = getFenceNV(fence);
6592 ASSERT(fenceObject != nullptr);
6593 handleError(fenceObject->set(condition));
6594}
6595
6596GLboolean Context::testFenceNV(GLuint fence)
6597{
6598 FenceNV *fenceObject = getFenceNV(fence);
6599
6600 ASSERT(fenceObject != nullptr);
6601 ASSERT(fenceObject->isSet() == GL_TRUE);
6602
6603 GLboolean result = GL_TRUE;
6604 Error error = fenceObject->test(&result);
6605 if (error.isError())
6606 {
6607 handleError(error);
6608 return GL_TRUE;
6609 }
6610
6611 return result;
6612}
6613
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006614void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006615{
6616 Texture *texture = getTargetTexture(target);
6617 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006618 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006619}
6620
Jamie Madillfa920eb2018-01-04 11:45:50 -05006621void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006622{
6623 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6624 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6625 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6626}
6627
Jamie Madillfa920eb2018-01-04 11:45:50 -05006628void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6629{
6630 UNIMPLEMENTED();
6631}
6632
Jamie Madill5b772312018-03-08 20:28:32 -05006633bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6634{
6635 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6636 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6637 // to the fact that it is stored internally as a float, and so would require conversion
6638 // if returned from Context::getIntegerv. Since this conversion is already implemented
6639 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6640 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6641 // application.
6642 switch (pname)
6643 {
6644 case GL_COMPRESSED_TEXTURE_FORMATS:
6645 {
6646 *type = GL_INT;
6647 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6648 return true;
6649 }
6650 case GL_SHADER_BINARY_FORMATS:
6651 {
6652 *type = GL_INT;
6653 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6654 return true;
6655 }
6656
6657 case GL_MAX_VERTEX_ATTRIBS:
6658 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6659 case GL_MAX_VARYING_VECTORS:
6660 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6661 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6662 case GL_MAX_TEXTURE_IMAGE_UNITS:
6663 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6664 case GL_MAX_RENDERBUFFER_SIZE:
6665 case GL_NUM_SHADER_BINARY_FORMATS:
6666 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6667 case GL_ARRAY_BUFFER_BINDING:
6668 case GL_FRAMEBUFFER_BINDING:
6669 case GL_RENDERBUFFER_BINDING:
6670 case GL_CURRENT_PROGRAM:
6671 case GL_PACK_ALIGNMENT:
6672 case GL_UNPACK_ALIGNMENT:
6673 case GL_GENERATE_MIPMAP_HINT:
6674 case GL_RED_BITS:
6675 case GL_GREEN_BITS:
6676 case GL_BLUE_BITS:
6677 case GL_ALPHA_BITS:
6678 case GL_DEPTH_BITS:
6679 case GL_STENCIL_BITS:
6680 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6681 case GL_CULL_FACE_MODE:
6682 case GL_FRONT_FACE:
6683 case GL_ACTIVE_TEXTURE:
6684 case GL_STENCIL_FUNC:
6685 case GL_STENCIL_VALUE_MASK:
6686 case GL_STENCIL_REF:
6687 case GL_STENCIL_FAIL:
6688 case GL_STENCIL_PASS_DEPTH_FAIL:
6689 case GL_STENCIL_PASS_DEPTH_PASS:
6690 case GL_STENCIL_BACK_FUNC:
6691 case GL_STENCIL_BACK_VALUE_MASK:
6692 case GL_STENCIL_BACK_REF:
6693 case GL_STENCIL_BACK_FAIL:
6694 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6695 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6696 case GL_DEPTH_FUNC:
6697 case GL_BLEND_SRC_RGB:
6698 case GL_BLEND_SRC_ALPHA:
6699 case GL_BLEND_DST_RGB:
6700 case GL_BLEND_DST_ALPHA:
6701 case GL_BLEND_EQUATION_RGB:
6702 case GL_BLEND_EQUATION_ALPHA:
6703 case GL_STENCIL_WRITEMASK:
6704 case GL_STENCIL_BACK_WRITEMASK:
6705 case GL_STENCIL_CLEAR_VALUE:
6706 case GL_SUBPIXEL_BITS:
6707 case GL_MAX_TEXTURE_SIZE:
6708 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6709 case GL_SAMPLE_BUFFERS:
6710 case GL_SAMPLES:
6711 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6712 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6713 case GL_TEXTURE_BINDING_2D:
6714 case GL_TEXTURE_BINDING_CUBE_MAP:
6715 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6716 {
6717 *type = GL_INT;
6718 *numParams = 1;
6719 return true;
6720 }
6721 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6722 {
6723 if (!getExtensions().packReverseRowOrder)
6724 {
6725 return false;
6726 }
6727 *type = GL_INT;
6728 *numParams = 1;
6729 return true;
6730 }
6731 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6732 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6733 {
6734 if (!getExtensions().textureRectangle)
6735 {
6736 return false;
6737 }
6738 *type = GL_INT;
6739 *numParams = 1;
6740 return true;
6741 }
6742 case GL_MAX_DRAW_BUFFERS_EXT:
6743 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6744 {
6745 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6746 {
6747 return false;
6748 }
6749 *type = GL_INT;
6750 *numParams = 1;
6751 return true;
6752 }
6753 case GL_MAX_VIEWPORT_DIMS:
6754 {
6755 *type = GL_INT;
6756 *numParams = 2;
6757 return true;
6758 }
6759 case GL_VIEWPORT:
6760 case GL_SCISSOR_BOX:
6761 {
6762 *type = GL_INT;
6763 *numParams = 4;
6764 return true;
6765 }
6766 case GL_SHADER_COMPILER:
6767 case GL_SAMPLE_COVERAGE_INVERT:
6768 case GL_DEPTH_WRITEMASK:
6769 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6770 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6771 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6772 // bool-natural
6773 case GL_SAMPLE_COVERAGE:
6774 case GL_SCISSOR_TEST:
6775 case GL_STENCIL_TEST:
6776 case GL_DEPTH_TEST:
6777 case GL_BLEND:
6778 case GL_DITHER:
6779 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6780 {
6781 *type = GL_BOOL;
6782 *numParams = 1;
6783 return true;
6784 }
6785 case GL_COLOR_WRITEMASK:
6786 {
6787 *type = GL_BOOL;
6788 *numParams = 4;
6789 return true;
6790 }
6791 case GL_POLYGON_OFFSET_FACTOR:
6792 case GL_POLYGON_OFFSET_UNITS:
6793 case GL_SAMPLE_COVERAGE_VALUE:
6794 case GL_DEPTH_CLEAR_VALUE:
6795 case GL_LINE_WIDTH:
6796 {
6797 *type = GL_FLOAT;
6798 *numParams = 1;
6799 return true;
6800 }
6801 case GL_ALIASED_LINE_WIDTH_RANGE:
6802 case GL_ALIASED_POINT_SIZE_RANGE:
6803 case GL_DEPTH_RANGE:
6804 {
6805 *type = GL_FLOAT;
6806 *numParams = 2;
6807 return true;
6808 }
6809 case GL_COLOR_CLEAR_VALUE:
6810 case GL_BLEND_COLOR:
6811 {
6812 *type = GL_FLOAT;
6813 *numParams = 4;
6814 return true;
6815 }
6816 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6817 if (!getExtensions().textureFilterAnisotropic)
6818 {
6819 return false;
6820 }
6821 *type = GL_FLOAT;
6822 *numParams = 1;
6823 return true;
6824 case GL_TIMESTAMP_EXT:
6825 if (!getExtensions().disjointTimerQuery)
6826 {
6827 return false;
6828 }
6829 *type = GL_INT_64_ANGLEX;
6830 *numParams = 1;
6831 return true;
6832 case GL_GPU_DISJOINT_EXT:
6833 if (!getExtensions().disjointTimerQuery)
6834 {
6835 return false;
6836 }
6837 *type = GL_INT;
6838 *numParams = 1;
6839 return true;
6840 case GL_COVERAGE_MODULATION_CHROMIUM:
6841 if (!getExtensions().framebufferMixedSamples)
6842 {
6843 return false;
6844 }
6845 *type = GL_INT;
6846 *numParams = 1;
6847 return true;
6848 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6849 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6850 {
6851 return false;
6852 }
6853 *type = GL_INT;
6854 *numParams = 1;
6855 return true;
6856 }
6857
6858 if (getExtensions().debug)
6859 {
6860 switch (pname)
6861 {
6862 case GL_DEBUG_LOGGED_MESSAGES:
6863 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6864 case GL_DEBUG_GROUP_STACK_DEPTH:
6865 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6866 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6867 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6868 case GL_MAX_LABEL_LENGTH:
6869 *type = GL_INT;
6870 *numParams = 1;
6871 return true;
6872
6873 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6874 case GL_DEBUG_OUTPUT:
6875 *type = GL_BOOL;
6876 *numParams = 1;
6877 return true;
6878 }
6879 }
6880
6881 if (getExtensions().multisampleCompatibility)
6882 {
6883 switch (pname)
6884 {
6885 case GL_MULTISAMPLE_EXT:
6886 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6887 *type = GL_BOOL;
6888 *numParams = 1;
6889 return true;
6890 }
6891 }
6892
6893 if (getExtensions().pathRendering)
6894 {
6895 switch (pname)
6896 {
6897 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6898 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6899 *type = GL_FLOAT;
6900 *numParams = 16;
6901 return true;
6902 }
6903 }
6904
6905 if (getExtensions().bindGeneratesResource)
6906 {
6907 switch (pname)
6908 {
6909 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6910 *type = GL_BOOL;
6911 *numParams = 1;
6912 return true;
6913 }
6914 }
6915
6916 if (getExtensions().clientArrays)
6917 {
6918 switch (pname)
6919 {
6920 case GL_CLIENT_ARRAYS_ANGLE:
6921 *type = GL_BOOL;
6922 *numParams = 1;
6923 return true;
6924 }
6925 }
6926
6927 if (getExtensions().sRGBWriteControl)
6928 {
6929 switch (pname)
6930 {
6931 case GL_FRAMEBUFFER_SRGB_EXT:
6932 *type = GL_BOOL;
6933 *numParams = 1;
6934 return true;
6935 }
6936 }
6937
6938 if (getExtensions().robustResourceInitialization &&
6939 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6940 {
6941 *type = GL_BOOL;
6942 *numParams = 1;
6943 return true;
6944 }
6945
6946 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6947 {
6948 *type = GL_BOOL;
6949 *numParams = 1;
6950 return true;
6951 }
6952
6953 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6954 switch (pname)
6955 {
6956 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6957 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6958 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6959 {
6960 return false;
6961 }
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965
6966 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6967 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6968 {
6969 return false;
6970 }
6971 *type = GL_INT;
6972 *numParams = 1;
6973 return true;
6974
6975 case GL_PROGRAM_BINARY_FORMATS_OES:
6976 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6977 {
6978 return false;
6979 }
6980 *type = GL_INT;
6981 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6982 return true;
6983
6984 case GL_PACK_ROW_LENGTH:
6985 case GL_PACK_SKIP_ROWS:
6986 case GL_PACK_SKIP_PIXELS:
6987 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6988 {
6989 return false;
6990 }
6991 *type = GL_INT;
6992 *numParams = 1;
6993 return true;
6994 case GL_UNPACK_ROW_LENGTH:
6995 case GL_UNPACK_SKIP_ROWS:
6996 case GL_UNPACK_SKIP_PIXELS:
6997 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6998 {
6999 return false;
7000 }
7001 *type = GL_INT;
7002 *numParams = 1;
7003 return true;
7004 case GL_VERTEX_ARRAY_BINDING:
7005 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7006 {
7007 return false;
7008 }
7009 *type = GL_INT;
7010 *numParams = 1;
7011 return true;
7012 case GL_PIXEL_PACK_BUFFER_BINDING:
7013 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7014 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7015 {
7016 return false;
7017 }
7018 *type = GL_INT;
7019 *numParams = 1;
7020 return true;
7021 case GL_MAX_SAMPLES:
7022 {
7023 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7024 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7025 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7026 {
7027 return false;
7028 }
7029 *type = GL_INT;
7030 *numParams = 1;
7031 return true;
7032
7033 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7034 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7035 {
7036 return false;
7037 }
7038 *type = GL_INT;
7039 *numParams = 1;
7040 return true;
7041 }
7042 }
7043
7044 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7045 {
7046 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7047 {
7048 return false;
7049 }
7050 *type = GL_INT;
7051 *numParams = 1;
7052 return true;
7053 }
7054
7055 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7056 {
7057 *type = GL_INT;
7058 *numParams = 1;
7059 return true;
7060 }
7061
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007062 if (getClientVersion() < Version(2, 0))
7063 {
7064 switch (pname)
7065 {
7066 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007067 case GL_CLIENT_ACTIVE_TEXTURE:
7068 case GL_MATRIX_MODE:
7069 case GL_MAX_TEXTURE_UNITS:
7070 case GL_MAX_MODELVIEW_STACK_DEPTH:
7071 case GL_MAX_PROJECTION_STACK_DEPTH:
7072 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007073 case GL_MAX_LIGHTS:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007074 case GL_VERTEX_ARRAY_STRIDE:
7075 case GL_NORMAL_ARRAY_STRIDE:
7076 case GL_COLOR_ARRAY_STRIDE:
7077 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7078 case GL_VERTEX_ARRAY_SIZE:
7079 case GL_COLOR_ARRAY_SIZE:
7080 case GL_TEXTURE_COORD_ARRAY_SIZE:
7081 case GL_VERTEX_ARRAY_TYPE:
7082 case GL_NORMAL_ARRAY_TYPE:
7083 case GL_COLOR_ARRAY_TYPE:
7084 case GL_TEXTURE_COORD_ARRAY_TYPE:
7085 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7086 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7087 case GL_COLOR_ARRAY_BUFFER_BINDING:
7088 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7089 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7090 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7091 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007092 *type = GL_INT;
7093 *numParams = 1;
7094 return true;
7095 case GL_ALPHA_TEST_REF:
7096 *type = GL_FLOAT;
7097 *numParams = 1;
7098 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007099 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007100 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007101 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007102 *type = GL_FLOAT;
7103 *numParams = 4;
7104 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007105 case GL_CURRENT_NORMAL:
7106 *type = GL_FLOAT;
7107 *numParams = 3;
7108 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007109 case GL_MODELVIEW_MATRIX:
7110 case GL_PROJECTION_MATRIX:
7111 case GL_TEXTURE_MATRIX:
7112 *type = GL_FLOAT;
7113 *numParams = 16;
7114 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007115 case GL_LIGHT_MODEL_TWO_SIDE:
7116 *type = GL_BOOL;
7117 *numParams = 1;
7118 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007119 }
7120 }
7121
Jamie Madill5b772312018-03-08 20:28:32 -05007122 if (getClientVersion() < Version(3, 0))
7123 {
7124 return false;
7125 }
7126
7127 // Check for ES3.0+ parameter names
7128 switch (pname)
7129 {
7130 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7131 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7132 case GL_UNIFORM_BUFFER_BINDING:
7133 case GL_TRANSFORM_FEEDBACK_BINDING:
7134 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7135 case GL_COPY_READ_BUFFER_BINDING:
7136 case GL_COPY_WRITE_BUFFER_BINDING:
7137 case GL_SAMPLER_BINDING:
7138 case GL_READ_BUFFER:
7139 case GL_TEXTURE_BINDING_3D:
7140 case GL_TEXTURE_BINDING_2D_ARRAY:
7141 case GL_MAX_3D_TEXTURE_SIZE:
7142 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7143 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7144 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7145 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7146 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7147 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7148 case GL_MAX_VARYING_COMPONENTS:
7149 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7150 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7151 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7152 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7153 case GL_NUM_EXTENSIONS:
7154 case GL_MAJOR_VERSION:
7155 case GL_MINOR_VERSION:
7156 case GL_MAX_ELEMENTS_INDICES:
7157 case GL_MAX_ELEMENTS_VERTICES:
7158 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7159 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7160 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7161 case GL_UNPACK_IMAGE_HEIGHT:
7162 case GL_UNPACK_SKIP_IMAGES:
7163 {
7164 *type = GL_INT;
7165 *numParams = 1;
7166 return true;
7167 }
7168
7169 case GL_MAX_ELEMENT_INDEX:
7170 case GL_MAX_UNIFORM_BLOCK_SIZE:
7171 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7172 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7173 case GL_MAX_SERVER_WAIT_TIMEOUT:
7174 {
7175 *type = GL_INT_64_ANGLEX;
7176 *numParams = 1;
7177 return true;
7178 }
7179
7180 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7181 case GL_TRANSFORM_FEEDBACK_PAUSED:
7182 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7183 case GL_RASTERIZER_DISCARD:
7184 {
7185 *type = GL_BOOL;
7186 *numParams = 1;
7187 return true;
7188 }
7189
7190 case GL_MAX_TEXTURE_LOD_BIAS:
7191 {
7192 *type = GL_FLOAT;
7193 *numParams = 1;
7194 return true;
7195 }
7196 }
7197
7198 if (getExtensions().requestExtension)
7199 {
7200 switch (pname)
7201 {
7202 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7203 *type = GL_INT;
7204 *numParams = 1;
7205 return true;
7206 }
7207 }
7208
7209 if (getClientVersion() < Version(3, 1))
7210 {
7211 return false;
7212 }
7213
7214 switch (pname)
7215 {
7216 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7217 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7218 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7219 case GL_MAX_FRAMEBUFFER_WIDTH:
7220 case GL_MAX_FRAMEBUFFER_HEIGHT:
7221 case GL_MAX_FRAMEBUFFER_SAMPLES:
7222 case GL_MAX_SAMPLE_MASK_WORDS:
7223 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7224 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7225 case GL_MAX_INTEGER_SAMPLES:
7226 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7227 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7228 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7229 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7230 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7231 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7232 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7233 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7234 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7235 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7236 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7237 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7238 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7239 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7240 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7241 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7242 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7243 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7244 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7245 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7246 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7247 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7248 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7249 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7250 case GL_MAX_UNIFORM_LOCATIONS:
7251 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7252 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7253 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7254 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7255 case GL_MAX_IMAGE_UNITS:
7256 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7257 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7258 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7259 case GL_SHADER_STORAGE_BUFFER_BINDING:
7260 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7261 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7262 *type = GL_INT;
7263 *numParams = 1;
7264 return true;
7265 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7266 *type = GL_INT_64_ANGLEX;
7267 *numParams = 1;
7268 return true;
7269 case GL_SAMPLE_MASK:
7270 *type = GL_BOOL;
7271 *numParams = 1;
7272 return true;
7273 }
7274
7275 if (getExtensions().geometryShader)
7276 {
7277 switch (pname)
7278 {
7279 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7280 case GL_LAYER_PROVOKING_VERTEX_EXT:
7281 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7282 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7283 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7284 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7285 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7286 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7287 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7288 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7289 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7290 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7291 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7292 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7293 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7294 *type = GL_INT;
7295 *numParams = 1;
7296 return true;
7297 }
7298 }
7299
7300 return false;
7301}
7302
7303bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7304{
7305 if (getClientVersion() < Version(3, 0))
7306 {
7307 return false;
7308 }
7309
7310 switch (target)
7311 {
7312 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7313 case GL_UNIFORM_BUFFER_BINDING:
7314 {
7315 *type = GL_INT;
7316 *numParams = 1;
7317 return true;
7318 }
7319 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7320 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7321 case GL_UNIFORM_BUFFER_START:
7322 case GL_UNIFORM_BUFFER_SIZE:
7323 {
7324 *type = GL_INT_64_ANGLEX;
7325 *numParams = 1;
7326 return true;
7327 }
7328 }
7329
7330 if (getClientVersion() < Version(3, 1))
7331 {
7332 return false;
7333 }
7334
7335 switch (target)
7336 {
7337 case GL_IMAGE_BINDING_LAYERED:
7338 {
7339 *type = GL_BOOL;
7340 *numParams = 1;
7341 return true;
7342 }
7343 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7344 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7345 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7346 case GL_SHADER_STORAGE_BUFFER_BINDING:
7347 case GL_VERTEX_BINDING_BUFFER:
7348 case GL_VERTEX_BINDING_DIVISOR:
7349 case GL_VERTEX_BINDING_OFFSET:
7350 case GL_VERTEX_BINDING_STRIDE:
7351 case GL_SAMPLE_MASK_VALUE:
7352 case GL_IMAGE_BINDING_NAME:
7353 case GL_IMAGE_BINDING_LEVEL:
7354 case GL_IMAGE_BINDING_LAYER:
7355 case GL_IMAGE_BINDING_ACCESS:
7356 case GL_IMAGE_BINDING_FORMAT:
7357 {
7358 *type = GL_INT;
7359 *numParams = 1;
7360 return true;
7361 }
7362 case GL_ATOMIC_COUNTER_BUFFER_START:
7363 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7364 case GL_SHADER_STORAGE_BUFFER_START:
7365 case GL_SHADER_STORAGE_BUFFER_SIZE:
7366 {
7367 *type = GL_INT_64_ANGLEX;
7368 *numParams = 1;
7369 return true;
7370 }
7371 }
7372
7373 return false;
7374}
7375
7376Program *Context::getProgram(GLuint handle) const
7377{
7378 return mState.mShaderPrograms->getProgram(handle);
7379}
7380
7381Shader *Context::getShader(GLuint handle) const
7382{
7383 return mState.mShaderPrograms->getShader(handle);
7384}
7385
7386bool Context::isTextureGenerated(GLuint texture) const
7387{
7388 return mState.mTextures->isHandleGenerated(texture);
7389}
7390
7391bool Context::isBufferGenerated(GLuint buffer) const
7392{
7393 return mState.mBuffers->isHandleGenerated(buffer);
7394}
7395
7396bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7397{
7398 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7399}
7400
7401bool Context::isFramebufferGenerated(GLuint framebuffer) const
7402{
7403 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7404}
7405
7406bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7407{
7408 return mState.mPipelines->isHandleGenerated(pipeline);
7409}
7410
7411bool Context::usingDisplayTextureShareGroup() const
7412{
7413 return mDisplayTextureShareGroup;
7414}
7415
7416GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7417{
7418 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7419 internalformat == GL_DEPTH_STENCIL
7420 ? GL_DEPTH24_STENCIL8
7421 : internalformat;
7422}
7423
Jamie Madillc29968b2016-01-20 11:17:23 -05007424} // namespace gl