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