blob: e62be2aa974d62802d5a038a7bff506508b79a63 [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)),
Geoff Lang75359662018-04-11 01:42:27 -0400283 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400284 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400285 mGLState(GetDebug(attribs),
286 GetBindGeneratesResource(attribs),
287 GetClientArraysEnabled(attribs),
288 GetRobustResourceInit(attribs),
289 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400290 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500291 mClientType(EGL_OPENGL_ES_API),
292 mHasBeenCurrent(false),
293 mContextLost(false),
294 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700295 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500296 mResetStrategy(GetResetStrategy(attribs)),
297 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400298 mSurfacelessSupported(displayExtensions.surfacelessContext),
299 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400300 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
301 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500302 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400303 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400304 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400305 mScratchBuffer(1000u),
306 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307{
Jamie Madill5b772312018-03-08 20:28:32 -0500308 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400309 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
310 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400311}
Jamie Madill5b772312018-03-08 20:28:32 -0500312
Geoff Lang33f11fb2018-05-07 13:42:47 -0400313void Context::initialize()
314{
315 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400316
Geoff Lang33f11fb2018-05-07 13:42:47 -0400317 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700318 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400319
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400320 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100321
Shannon Woods53a94a82014-06-24 15:20:36 -0400322 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400323
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000324 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400325 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000326 // and cube map texture state vectors respectively associated with them.
327 // In order that access to these initial textures not be lost, they are treated as texture
328 // objects all of whose names are 0.
329
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335
Geoff Langeb66a6e2016-10-31 13:06:12 -0400336 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 {
338 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400341
Corentin Wallez99d492c2018-02-27 15:17:10 -0500342 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 if (getClientVersion() >= Version(3, 1))
346 {
347 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500348 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800349 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800350
Jiajia Qin6eafb042016-12-27 17:04:07 +0800351 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
352 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800353 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800354 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800355
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800356 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
357 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400358 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800359 }
Geoff Lang3b573612016-10-31 14:08:10 -0400360 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400363 {
364 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500365 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800366 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400367 }
368
Geoff Langb0f917f2017-12-05 13:41:54 -0500369 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400370 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500371 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400373 }
374
Jamie Madill4928b7c2017-06-20 12:57:39 -0400375 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500376
Jamie Madill57a89722013-07-02 11:57:03 -0400377 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000378
Geoff Langeb66a6e2016-10-31 13:06:12 -0400379 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400380 {
381 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
382 // In the initial state, a default transform feedback object is bound and treated as
383 // a transform feedback object with a name of zero. That object is bound any time
384 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400385 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400386 }
Geoff Langc8058452014-02-03 12:04:11 -0500387
Corentin Wallez336129f2017-10-17 15:55:40 -0400388 for (auto type : angle::AllEnums<BufferBinding>())
389 {
390 bindBuffer(type, 0);
391 }
392
393 bindRenderbuffer(GL_RENDERBUFFER, 0);
394
395 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
396 {
397 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
398 }
399
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700400 // Initialize GLES1 renderer if appropriate.
401 if (getClientVersion() < Version(2, 0))
402 {
403 mGLES1Renderer.reset(new GLES1Renderer());
404 }
405
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400407 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500408 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 // No dirty objects.
410
411 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400412 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500413 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500414 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
415
416 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
417 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
418 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
419 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
420 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
422 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
423 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
424 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
425 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
426 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
427 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
428
429 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
430 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700431 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500432 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
433 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400434
Xinghua Cao10a4d432017-11-28 14:46:26 +0800435 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
436 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
437 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
438 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
439 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
440 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800441 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800442 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800443
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400444 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445}
446
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000448{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700449 if (mGLES1Renderer)
450 {
451 mGLES1Renderer->onDestroy(this, &mGLState);
452 }
453
Jamie Madille7b3fe22018-04-05 09:42:46 -0400454 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400455 ANGLE_TRY(releaseSurface(display));
456
Corentin Wallez80b24112015-08-25 16:41:57 -0400457 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400459 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000460 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400461 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400465 if (query.second != nullptr)
466 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400467 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400468 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000469 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400470 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000471
Corentin Wallez80b24112015-08-25 16:41:57 -0400472 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400473 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400474 if (vertexArray.second)
475 {
476 vertexArray.second->onDestroy(this);
477 }
Jamie Madill57a89722013-07-02 11:57:03 -0400478 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400479 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400480
Corentin Wallez80b24112015-08-25 16:41:57 -0400481 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500482 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500483 if (transformFeedback.second != nullptr)
484 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500485 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500486 }
Geoff Langc8058452014-02-03 12:04:11 -0500487 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400488 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500489
Jamie Madill5b772312018-03-08 20:28:32 -0500490 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400491 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800492 if (zeroTexture.get() != nullptr)
493 {
494 ANGLE_TRY(zeroTexture->onDestroy(this));
495 zeroTexture.set(this, nullptr);
496 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400497 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498
Jamie Madill2f348d22017-06-05 10:50:59 -0400499 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501 mGLState.reset(this);
502
Jamie Madill6c1f6712017-02-14 19:08:04 -0500503 mState.mBuffers->release(this);
504 mState.mShaderPrograms->release(this);
505 mState.mTextures->release(this);
506 mState.mRenderbuffers->release(this);
507 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400508 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500509 mState.mPaths->release(this);
510 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800511 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512
Jamie Madill76e471e2017-10-21 09:56:01 -0400513 mImplementation->onDestroy(this);
514
Jamie Madill4928b7c2017-06-20 12:57:39 -0400515 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000516}
517
Jamie Madill70ee0f62017-02-06 16:04:20 -0500518Context::~Context()
519{
520}
521
Geoff Lang75359662018-04-11 01:42:27 -0400522void Context::setLabel(EGLLabelKHR label)
523{
524 mLabel = label;
525}
526
527EGLLabelKHR Context::getLabel() const
528{
529 return mLabel;
530}
531
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000533{
Jamie Madill61e16b42017-06-19 11:13:23 -0400534 mCurrentDisplay = display;
535
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536 if (!mHasBeenCurrent)
537 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400538 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000539 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500540 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400541 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
Corentin Wallezc295e512017-01-27 17:47:50 -0500543 int width = 0;
544 int height = 0;
545 if (surface != nullptr)
546 {
547 width = surface->getWidth();
548 height = surface->getHeight();
549 }
550
551 mGLState.setViewportParams(0, 0, width, height);
552 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000553
554 mHasBeenCurrent = true;
555 }
556
Jamie Madill1b94d432015-08-07 13:23:23 -0400557 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400559 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500562
563 Framebuffer *newDefault = nullptr;
564 if (surface != nullptr)
565 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500567 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400568 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500569 }
570 else
571 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400572 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500573 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000574
Corentin Wallez37c39792015-08-20 14:19:46 -0400575 // Update default framebuffer, the binding of the previous default
576 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400577 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700578 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400579 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700580 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400581 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700582 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400583 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700584 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400585 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500586 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400587 }
Ian Ewell292f0052016-02-04 10:37:32 -0500588
589 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400590 mImplementation->onMakeCurrent(this);
591 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592}
593
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400595{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400596 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400597
Geoff Langbf7b95d2018-05-01 16:48:21 -0400598 // Remove the default framebuffer
599 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 {
601 mGLState.setReadFramebufferBinding(nullptr);
602 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400603
604 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500605 {
606 mGLState.setDrawFramebufferBinding(nullptr);
607 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400608
609 if (defaultFramebuffer)
610 {
611 defaultFramebuffer->onDestroy(this);
612 delete defaultFramebuffer;
613 }
614
Corentin Wallezc295e512017-01-27 17:47:50 -0500615 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
616
617 if (mCurrentSurface)
618 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400619 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500620 mCurrentSurface = nullptr;
621 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400622
623 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400624}
625
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626GLuint Context::createBuffer()
627{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500628 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
631GLuint Context::createProgram()
632{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500633 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634}
635
Jiawei Shao385b3e02018-03-21 09:43:28 +0800636GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500638 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639}
640
641GLuint Context::createTexture()
642{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500643 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000644}
645
646GLuint Context::createRenderbuffer()
647{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500648 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649}
650
Brandon Jones59770802018-04-02 13:18:42 -0700651GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300652{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500653 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300654 if (resultOrError.isError())
655 {
656 handleError(resultOrError.getError());
657 return 0;
658 }
659 return resultOrError.getResult();
660}
661
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662// Returns an unused framebuffer name
663GLuint Context::createFramebuffer()
664{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500665 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666}
667
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500668void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500670 for (int i = 0; i < n; i++)
671 {
672 GLuint handle = mFenceNVHandleAllocator.allocate();
673 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
674 fences[i] = handle;
675 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676}
677
Yunchao Hea336b902017-08-02 16:05:21 +0800678GLuint Context::createProgramPipeline()
679{
680 return mState.mPipelines->createProgramPipeline();
681}
682
Jiawei Shao385b3e02018-03-21 09:43:28 +0800683GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800684{
685 UNIMPLEMENTED();
686 return 0u;
687}
688
James Darpinian4d9d4832018-03-13 12:43:28 -0700689void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690{
James Darpinian4d9d4832018-03-13 12:43:28 -0700691 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
692 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693 {
694 detachBuffer(buffer);
695 }
Jamie Madill893ab082014-05-16 16:56:10 -0400696
James Darpinian4d9d4832018-03-13 12:43:28 -0700697 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700void Context::deleteShader(GLuint shader)
701{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500702 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703}
704
705void Context::deleteProgram(GLuint program)
706{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500707 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
710void Context::deleteTexture(GLuint texture)
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713 {
714 detachTexture(texture);
715 }
716
Jamie Madill6c1f6712017-02-14 19:08:04 -0500717 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718}
719
720void Context::deleteRenderbuffer(GLuint renderbuffer)
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723 {
724 detachRenderbuffer(renderbuffer);
725 }
Jamie Madill893ab082014-05-16 16:56:10 -0400726
Jamie Madill6c1f6712017-02-14 19:08:04 -0500727 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728}
729
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400730void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400731{
732 // The spec specifies the underlying Fence object is not deleted until all current
733 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
734 // and since our API is currently designed for being called from a single thread, we can delete
735 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400736 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400737}
738
Yunchao Hea336b902017-08-02 16:05:21 +0800739void Context::deleteProgramPipeline(GLuint pipeline)
740{
741 if (mState.mPipelines->getProgramPipeline(pipeline))
742 {
743 detachProgramPipeline(pipeline);
744 }
745
746 mState.mPipelines->deleteObject(this, pipeline);
747}
748
Sami Väisänene45e53b2016-05-25 10:36:04 +0300749void Context::deletePaths(GLuint first, GLsizei range)
750{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500751 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752}
753
Brandon Jones59770802018-04-02 13:18:42 -0700754bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757 if (pathObj == nullptr)
758 return false;
759
760 return pathObj->hasPathData();
761}
762
Brandon Jones59770802018-04-02 13:18:42 -0700763bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300764{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500765 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300766}
767
Brandon Jones59770802018-04-02 13:18:42 -0700768void Context::pathCommands(GLuint path,
769 GLsizei numCommands,
770 const GLubyte *commands,
771 GLsizei numCoords,
772 GLenum coordType,
773 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500775 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300776
777 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
778}
779
Jamie Madill007530e2017-12-28 14:27:04 -0500780void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300781{
Jamie Madill007530e2017-12-28 14:27:04 -0500782 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300783
784 switch (pname)
785 {
786 case GL_PATH_STROKE_WIDTH_CHROMIUM:
787 pathObj->setStrokeWidth(value);
788 break;
789 case GL_PATH_END_CAPS_CHROMIUM:
790 pathObj->setEndCaps(static_cast<GLenum>(value));
791 break;
792 case GL_PATH_JOIN_STYLE_CHROMIUM:
793 pathObj->setJoinStyle(static_cast<GLenum>(value));
794 break;
795 case GL_PATH_MITER_LIMIT_CHROMIUM:
796 pathObj->setMiterLimit(value);
797 break;
798 case GL_PATH_STROKE_BOUND_CHROMIUM:
799 pathObj->setStrokeBound(value);
800 break;
801 default:
802 UNREACHABLE();
803 break;
804 }
805}
806
Jamie Madill007530e2017-12-28 14:27:04 -0500807void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808{
Jamie Madill007530e2017-12-28 14:27:04 -0500809 // TODO(jmadill): Should use proper clamping/casting.
810 pathParameterf(path, pname, static_cast<GLfloat>(value));
811}
812
813void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
814{
815 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300816
817 switch (pname)
818 {
819 case GL_PATH_STROKE_WIDTH_CHROMIUM:
820 *value = pathObj->getStrokeWidth();
821 break;
822 case GL_PATH_END_CAPS_CHROMIUM:
823 *value = static_cast<GLfloat>(pathObj->getEndCaps());
824 break;
825 case GL_PATH_JOIN_STYLE_CHROMIUM:
826 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
827 break;
828 case GL_PATH_MITER_LIMIT_CHROMIUM:
829 *value = pathObj->getMiterLimit();
830 break;
831 case GL_PATH_STROKE_BOUND_CHROMIUM:
832 *value = pathObj->getStrokeBound();
833 break;
834 default:
835 UNREACHABLE();
836 break;
837 }
838}
839
Jamie Madill007530e2017-12-28 14:27:04 -0500840void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
841{
842 GLfloat val = 0.0f;
843 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
844 if (value)
845 *value = static_cast<GLint>(val);
846}
847
Brandon Jones59770802018-04-02 13:18:42 -0700848void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849{
850 mGLState.setPathStencilFunc(func, ref, mask);
851}
852
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853void Context::deleteFramebuffer(GLuint framebuffer)
854{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500855 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856 {
857 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500859
Jamie Madill6c1f6712017-02-14 19:08:04 -0500860 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861}
862
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500863void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500865 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500867 GLuint fence = fences[i];
868
869 FenceNV *fenceObject = nullptr;
870 if (mFenceNVMap.erase(fence, &fenceObject))
871 {
872 mFenceNVHandleAllocator.release(fence);
873 delete fenceObject;
874 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875 }
876}
877
Geoff Lang70d0f492015-12-10 17:45:46 -0500878Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881}
882
Jamie Madill570f7c82014-07-03 10:38:54 -0400883Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000886}
887
Geoff Lang70d0f492015-12-10 17:45:46 -0500888Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000889{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500890 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000891}
892
Jamie Madill70b5bb02017-08-28 13:32:37 -0400893Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400894{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400895 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400896}
897
Jamie Madill57a89722013-07-02 11:57:03 -0400898VertexArray *Context::getVertexArray(GLuint handle) const
899{
Jamie Madill96a483b2017-06-27 16:49:21 -0400900 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400901}
902
Jamie Madilldc356042013-07-19 16:36:57 -0400903Sampler *Context::getSampler(GLuint handle) const
904{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500905 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400906}
907
Geoff Langc8058452014-02-03 12:04:11 -0500908TransformFeedback *Context::getTransformFeedback(GLuint handle) const
909{
Jamie Madill96a483b2017-06-27 16:49:21 -0400910 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500911}
912
Yunchao Hea336b902017-08-02 16:05:21 +0800913ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
914{
915 return mState.mPipelines->getProgramPipeline(handle);
916}
917
Geoff Lang75359662018-04-11 01:42:27 -0400918gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500919{
920 switch (identifier)
921 {
922 case GL_BUFFER:
923 return getBuffer(name);
924 case GL_SHADER:
925 return getShader(name);
926 case GL_PROGRAM:
927 return getProgram(name);
928 case GL_VERTEX_ARRAY:
929 return getVertexArray(name);
930 case GL_QUERY:
931 return getQuery(name);
932 case GL_TRANSFORM_FEEDBACK:
933 return getTransformFeedback(name);
934 case GL_SAMPLER:
935 return getSampler(name);
936 case GL_TEXTURE:
937 return getTexture(name);
938 case GL_RENDERBUFFER:
939 return getRenderbuffer(name);
940 case GL_FRAMEBUFFER:
941 return getFramebuffer(name);
942 default:
943 UNREACHABLE();
944 return nullptr;
945 }
946}
947
Geoff Lang75359662018-04-11 01:42:27 -0400948gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500949{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400950 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500951}
952
Martin Radev9d901792016-07-15 15:58:58 +0300953void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
954{
Geoff Lang75359662018-04-11 01:42:27 -0400955 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300956 ASSERT(object != nullptr);
957
958 std::string labelName = GetObjectLabelFromPointer(length, label);
959 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400960
961 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
962 // specified object is active until we do this.
963 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300964}
965
966void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
967{
Geoff Lang75359662018-04-11 01:42:27 -0400968 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300969 ASSERT(object != nullptr);
970
971 std::string labelName = GetObjectLabelFromPointer(length, label);
972 object->setLabel(labelName);
973}
974
975void Context::getObjectLabel(GLenum identifier,
976 GLuint name,
977 GLsizei bufSize,
978 GLsizei *length,
979 GLchar *label) const
980{
Geoff Lang75359662018-04-11 01:42:27 -0400981 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300982 ASSERT(object != nullptr);
983
984 const std::string &objectLabel = object->getLabel();
985 GetObjectLabelBase(objectLabel, bufSize, length, label);
986}
987
988void Context::getObjectPtrLabel(const void *ptr,
989 GLsizei bufSize,
990 GLsizei *length,
991 GLchar *label) const
992{
Geoff Lang75359662018-04-11 01:42:27 -0400993 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300994 ASSERT(object != nullptr);
995
996 const std::string &objectLabel = object->getLabel();
997 GetObjectLabelBase(objectLabel, bufSize, length, label);
998}
999
Jamie Madilldc356042013-07-19 16:36:57 -04001000bool Context::isSampler(GLuint samplerName) const
1001{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001002 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001003}
1004
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001005void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001006{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001007 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009 if (handle == 0)
1010 {
1011 texture = mZeroTextures[target].get();
1012 }
1013 else
1014 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001015 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001016 }
1017
1018 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001019 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001020}
1021
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001022void Context::bindReadFramebuffer(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.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027}
1028
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001029void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001030{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001031 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1032 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001033 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034}
1035
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001036void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001037{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001039 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001040}
1041
Shao80957d92017-02-20 21:25:59 +08001042void Context::bindVertexBuffer(GLuint bindingIndex,
1043 GLuint bufferHandle,
1044 GLintptr offset,
1045 GLsizei stride)
1046{
1047 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001048 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001049}
1050
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001051void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001052{
Geoff Lang76b10c92014-09-05 16:28:14 -04001053 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001054 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001055 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001056 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001057}
1058
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001059void Context::bindImageTexture(GLuint unit,
1060 GLuint texture,
1061 GLint level,
1062 GLboolean layered,
1063 GLint layer,
1064 GLenum access,
1065 GLenum format)
1066{
1067 Texture *tex = mState.mTextures->getTexture(texture);
1068 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1069}
1070
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071void Context::useProgram(GLuint program)
1072{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001073 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001074}
1075
Jiajia Qin5451d532017-11-16 17:16:34 +08001076void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1077{
1078 UNIMPLEMENTED();
1079}
1080
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001081void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001082{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001083 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001084 TransformFeedback *transformFeedback =
1085 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001087}
1088
Yunchao Hea336b902017-08-02 16:05:21 +08001089void Context::bindProgramPipeline(GLuint pipelineHandle)
1090{
1091 ProgramPipeline *pipeline =
1092 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1093 mGLState.setProgramPipelineBinding(this, pipeline);
1094}
1095
Corentin Wallezad3ae902018-03-09 13:40:42 -05001096void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001099 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001100
Geoff Lang5aad9672014-09-08 11:10:42 -04001101 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001103
1104 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001105 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106}
1107
Corentin Wallezad3ae902018-03-09 13:40:42 -05001108void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001109{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001110 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001111 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001112
Jamie Madillf0e04492017-08-26 15:28:42 -04001113 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001114
Geoff Lang5aad9672014-09-08 11:10:42 -04001115 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001116 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117}
1118
Corentin Wallezad3ae902018-03-09 13:40:42 -05001119void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001121 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001122
1123 Query *queryObject = getQuery(id, true, target);
1124 ASSERT(queryObject);
1125
Jamie Madillf0e04492017-08-26 15:28:42 -04001126 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127}
1128
Corentin Wallezad3ae902018-03-09 13:40:42 -05001129void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130{
1131 switch (pname)
1132 {
1133 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001134 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135 break;
1136 case GL_QUERY_COUNTER_BITS_EXT:
1137 switch (target)
1138 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001139 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1141 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001142 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001143 params[0] = getExtensions().queryCounterBitsTimestamp;
1144 break;
1145 default:
1146 UNREACHABLE();
1147 params[0] = 0;
1148 break;
1149 }
1150 break;
1151 default:
1152 UNREACHABLE();
1153 return;
1154 }
1155}
1156
Corentin Wallezad3ae902018-03-09 13:40:42 -05001157void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001158 GLenum pname,
1159 GLsizei bufSize,
1160 GLsizei *length,
1161 GLint *params)
1162{
1163 getQueryiv(target, pname, params);
1164}
1165
Geoff Lang2186c382016-10-14 10:54:54 -04001166void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001167{
Geoff Lang2186c382016-10-14 10:54:54 -04001168 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001169}
1170
Brandon Jones59770802018-04-02 13:18:42 -07001171void Context::getQueryObjectivRobust(GLuint id,
1172 GLenum pname,
1173 GLsizei bufSize,
1174 GLsizei *length,
1175 GLint *params)
1176{
1177 getQueryObjectiv(id, pname, params);
1178}
1179
Geoff Lang2186c382016-10-14 10:54:54 -04001180void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181{
Geoff Lang2186c382016-10-14 10:54:54 -04001182 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001183}
1184
Brandon Jones59770802018-04-02 13:18:42 -07001185void Context::getQueryObjectuivRobust(GLuint id,
1186 GLenum pname,
1187 GLsizei bufSize,
1188 GLsizei *length,
1189 GLuint *params)
1190{
1191 getQueryObjectuiv(id, pname, params);
1192}
1193
Geoff Lang2186c382016-10-14 10:54:54 -04001194void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195{
Geoff Lang2186c382016-10-14 10:54:54 -04001196 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197}
1198
Brandon Jones59770802018-04-02 13:18:42 -07001199void Context::getQueryObjecti64vRobust(GLuint id,
1200 GLenum pname,
1201 GLsizei bufSize,
1202 GLsizei *length,
1203 GLint64 *params)
1204{
1205 getQueryObjecti64v(id, pname, params);
1206}
1207
Geoff Lang2186c382016-10-14 10:54:54 -04001208void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001209{
Geoff Lang2186c382016-10-14 10:54:54 -04001210 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001211}
1212
Brandon Jones59770802018-04-02 13:18:42 -07001213void Context::getQueryObjectui64vRobust(GLuint id,
1214 GLenum pname,
1215 GLsizei bufSize,
1216 GLsizei *length,
1217 GLuint64 *params)
1218{
1219 getQueryObjectui64v(id, pname, params);
1220}
1221
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001222Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001224 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225}
1226
Jamie Madill2f348d22017-06-05 10:50:59 -04001227FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228{
Jamie Madill96a483b2017-06-27 16:49:21 -04001229 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230}
1231
Corentin Wallezad3ae902018-03-09 13:40:42 -05001232Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233{
Jamie Madill96a483b2017-06-27 16:49:21 -04001234 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001235 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001236 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001238
1239 Query *query = mQueryMap.query(handle);
1240 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001242 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001243 query = new Query(mImplementation->createQuery(type), handle);
1244 query->addRef();
1245 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001246 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001247 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001248}
1249
Geoff Lang70d0f492015-12-10 17:45:46 -05001250Query *Context::getQuery(GLuint handle) const
1251{
Jamie Madill96a483b2017-06-27 16:49:21 -04001252 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001253}
1254
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001255Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001256{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001257 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1258 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001259}
1260
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001261Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001262{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001263 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264}
1265
Geoff Lang492a7e42014-11-05 13:27:06 -05001266Compiler *Context::getCompiler() const
1267{
Jamie Madill2f348d22017-06-05 10:50:59 -04001268 if (mCompiler.get() == nullptr)
1269 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001270 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001271 }
1272 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001273}
1274
Jamie Madillc1d770e2017-04-13 17:31:24 -04001275void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276{
1277 switch (pname)
1278 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001279 case GL_SHADER_COMPILER:
1280 *params = GL_TRUE;
1281 break;
1282 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1283 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1284 break;
1285 default:
1286 mGLState.getBooleanv(pname, params);
1287 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289}
1290
Jamie Madillc1d770e2017-04-13 17:31:24 -04001291void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292{
Shannon Woods53a94a82014-06-24 15:20:36 -04001293 // Queries about context capabilities and maximums are answered by Context.
1294 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001295 switch (pname)
1296 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001297 case GL_ALIASED_LINE_WIDTH_RANGE:
1298 params[0] = mCaps.minAliasedLineWidth;
1299 params[1] = mCaps.maxAliasedLineWidth;
1300 break;
1301 case GL_ALIASED_POINT_SIZE_RANGE:
1302 params[0] = mCaps.minAliasedPointSize;
1303 params[1] = mCaps.maxAliasedPointSize;
1304 break;
1305 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1306 ASSERT(mExtensions.textureFilterAnisotropic);
1307 *params = mExtensions.maxTextureAnisotropy;
1308 break;
1309 case GL_MAX_TEXTURE_LOD_BIAS:
1310 *params = mCaps.maxLODBias;
1311 break;
1312
1313 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1314 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1315 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001316 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1317 // GLES1 constants for modelview/projection matrix.
1318 if (getClientVersion() < Version(2, 0))
1319 {
1320 mGLState.getFloatv(pname, params);
1321 }
1322 else
1323 {
1324 ASSERT(mExtensions.pathRendering);
1325 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1326 memcpy(params, m, 16 * sizeof(GLfloat));
1327 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001328 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001329 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001330
Jamie Madill231c7f52017-04-26 13:45:37 -04001331 default:
1332 mGLState.getFloatv(pname, params);
1333 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001334 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335}
1336
Jamie Madillc1d770e2017-04-13 17:31:24 -04001337void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338{
Shannon Woods53a94a82014-06-24 15:20:36 -04001339 // Queries about context capabilities and maximums are answered by Context.
1340 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001341
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342 switch (pname)
1343 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001344 case GL_MAX_VERTEX_ATTRIBS:
1345 *params = mCaps.maxVertexAttributes;
1346 break;
1347 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1348 *params = mCaps.maxVertexUniformVectors;
1349 break;
1350 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001351 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001352 break;
1353 case GL_MAX_VARYING_VECTORS:
1354 *params = mCaps.maxVaryingVectors;
1355 break;
1356 case GL_MAX_VARYING_COMPONENTS:
1357 *params = mCaps.maxVertexOutputComponents;
1358 break;
1359 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1360 *params = mCaps.maxCombinedTextureImageUnits;
1361 break;
1362 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001363 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001364 break;
1365 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001366 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001367 break;
1368 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1369 *params = mCaps.maxFragmentUniformVectors;
1370 break;
1371 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001372 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 break;
1374 case GL_MAX_RENDERBUFFER_SIZE:
1375 *params = mCaps.maxRenderbufferSize;
1376 break;
1377 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1378 *params = mCaps.maxColorAttachments;
1379 break;
1380 case GL_MAX_DRAW_BUFFERS_EXT:
1381 *params = mCaps.maxDrawBuffers;
1382 break;
1383 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1384 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1385 case GL_SUBPIXEL_BITS:
1386 *params = 4;
1387 break;
1388 case GL_MAX_TEXTURE_SIZE:
1389 *params = mCaps.max2DTextureSize;
1390 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001391 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1392 *params = mCaps.maxRectangleTextureSize;
1393 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1395 *params = mCaps.maxCubeMapTextureSize;
1396 break;
1397 case GL_MAX_3D_TEXTURE_SIZE:
1398 *params = mCaps.max3DTextureSize;
1399 break;
1400 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1401 *params = mCaps.maxArrayTextureLayers;
1402 break;
1403 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1404 *params = mCaps.uniformBufferOffsetAlignment;
1405 break;
1406 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1407 *params = mCaps.maxUniformBufferBindings;
1408 break;
1409 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001410 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 break;
1412 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001413 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 break;
1415 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1416 *params = mCaps.maxCombinedTextureImageUnits;
1417 break;
1418 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1419 *params = mCaps.maxVertexOutputComponents;
1420 break;
1421 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1422 *params = mCaps.maxFragmentInputComponents;
1423 break;
1424 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1425 *params = mCaps.minProgramTexelOffset;
1426 break;
1427 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1428 *params = mCaps.maxProgramTexelOffset;
1429 break;
1430 case GL_MAJOR_VERSION:
1431 *params = getClientVersion().major;
1432 break;
1433 case GL_MINOR_VERSION:
1434 *params = getClientVersion().minor;
1435 break;
1436 case GL_MAX_ELEMENTS_INDICES:
1437 *params = mCaps.maxElementsIndices;
1438 break;
1439 case GL_MAX_ELEMENTS_VERTICES:
1440 *params = mCaps.maxElementsVertices;
1441 break;
1442 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1443 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1444 break;
1445 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1446 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1447 break;
1448 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1449 *params = mCaps.maxTransformFeedbackSeparateComponents;
1450 break;
1451 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1452 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1453 break;
1454 case GL_MAX_SAMPLES_ANGLE:
1455 *params = mCaps.maxSamples;
1456 break;
1457 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001458 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001459 params[0] = mCaps.maxViewportWidth;
1460 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001461 }
1462 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001463 case GL_COMPRESSED_TEXTURE_FORMATS:
1464 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1465 params);
1466 break;
1467 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1468 *params = mResetStrategy;
1469 break;
1470 case GL_NUM_SHADER_BINARY_FORMATS:
1471 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1472 break;
1473 case GL_SHADER_BINARY_FORMATS:
1474 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1475 break;
1476 case GL_NUM_PROGRAM_BINARY_FORMATS:
1477 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1478 break;
1479 case GL_PROGRAM_BINARY_FORMATS:
1480 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1481 break;
1482 case GL_NUM_EXTENSIONS:
1483 *params = static_cast<GLint>(mExtensionStrings.size());
1484 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001485
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 // GL_KHR_debug
1487 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1488 *params = mExtensions.maxDebugMessageLength;
1489 break;
1490 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1491 *params = mExtensions.maxDebugLoggedMessages;
1492 break;
1493 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1494 *params = mExtensions.maxDebugGroupStackDepth;
1495 break;
1496 case GL_MAX_LABEL_LENGTH:
1497 *params = mExtensions.maxLabelLength;
1498 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001499
Martin Radeve5285d22017-07-14 16:23:53 +03001500 // GL_ANGLE_multiview
1501 case GL_MAX_VIEWS_ANGLE:
1502 *params = mExtensions.maxViews;
1503 break;
1504
Jamie Madill231c7f52017-04-26 13:45:37 -04001505 // GL_EXT_disjoint_timer_query
1506 case GL_GPU_DISJOINT_EXT:
1507 *params = mImplementation->getGPUDisjoint();
1508 break;
1509 case GL_MAX_FRAMEBUFFER_WIDTH:
1510 *params = mCaps.maxFramebufferWidth;
1511 break;
1512 case GL_MAX_FRAMEBUFFER_HEIGHT:
1513 *params = mCaps.maxFramebufferHeight;
1514 break;
1515 case GL_MAX_FRAMEBUFFER_SAMPLES:
1516 *params = mCaps.maxFramebufferSamples;
1517 break;
1518 case GL_MAX_SAMPLE_MASK_WORDS:
1519 *params = mCaps.maxSampleMaskWords;
1520 break;
1521 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1522 *params = mCaps.maxColorTextureSamples;
1523 break;
1524 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1525 *params = mCaps.maxDepthTextureSamples;
1526 break;
1527 case GL_MAX_INTEGER_SAMPLES:
1528 *params = mCaps.maxIntegerSamples;
1529 break;
1530 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1531 *params = mCaps.maxVertexAttribRelativeOffset;
1532 break;
1533 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1534 *params = mCaps.maxVertexAttribBindings;
1535 break;
1536 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1537 *params = mCaps.maxVertexAttribStride;
1538 break;
1539 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001540 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001541 break;
1542 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001543 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001544 break;
1545 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001546 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001547 break;
1548 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001549 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001550 break;
1551 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001552 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001553 break;
1554 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001555 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001556 break;
1557 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001558 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001559 break;
1560 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001561 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001562 break;
1563 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1564 *params = mCaps.minProgramTextureGatherOffset;
1565 break;
1566 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1567 *params = mCaps.maxProgramTextureGatherOffset;
1568 break;
1569 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1570 *params = mCaps.maxComputeWorkGroupInvocations;
1571 break;
1572 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001573 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 break;
1575 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001576 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001577 break;
1578 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1579 *params = mCaps.maxComputeSharedMemorySize;
1580 break;
1581 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001582 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 break;
1584 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001585 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001586 break;
1587 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001588 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 break;
1590 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001591 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 break;
1593 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001594 *params =
1595 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001598 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1601 *params = mCaps.maxCombinedShaderOutputResources;
1602 break;
1603 case GL_MAX_UNIFORM_LOCATIONS:
1604 *params = mCaps.maxUniformLocations;
1605 break;
1606 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1607 *params = mCaps.maxAtomicCounterBufferBindings;
1608 break;
1609 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1610 *params = mCaps.maxAtomicCounterBufferSize;
1611 break;
1612 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1613 *params = mCaps.maxCombinedAtomicCounterBuffers;
1614 break;
1615 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1616 *params = mCaps.maxCombinedAtomicCounters;
1617 break;
1618 case GL_MAX_IMAGE_UNITS:
1619 *params = mCaps.maxImageUnits;
1620 break;
1621 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1622 *params = mCaps.maxCombinedImageUniforms;
1623 break;
1624 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1625 *params = mCaps.maxShaderStorageBufferBindings;
1626 break;
1627 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1628 *params = mCaps.maxCombinedShaderStorageBlocks;
1629 break;
1630 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1631 *params = mCaps.shaderStorageBufferOffsetAlignment;
1632 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001633
1634 // GL_EXT_geometry_shader
1635 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1636 *params = mCaps.maxFramebufferLayers;
1637 break;
1638 case GL_LAYER_PROVOKING_VERTEX_EXT:
1639 *params = mCaps.layerProvokingVertex;
1640 break;
1641 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001642 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001643 break;
1644 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001645 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001646 break;
1647 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params =
1649 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001650 break;
1651 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1652 *params = mCaps.maxGeometryInputComponents;
1653 break;
1654 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1655 *params = mCaps.maxGeometryOutputComponents;
1656 break;
1657 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1658 *params = mCaps.maxGeometryOutputVertices;
1659 break;
1660 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1661 *params = mCaps.maxGeometryTotalOutputComponents;
1662 break;
1663 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1664 *params = mCaps.maxGeometryShaderInvocations;
1665 break;
1666 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001667 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001668 break;
1669 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001670 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001671 break;
1672 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001673 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001674 break;
1675 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001676 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001677 break;
1678 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001679 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001680 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001681 // GLES1 emulation: Caps queries
1682 case GL_MAX_TEXTURE_UNITS:
1683 *params = mCaps.maxMultitextureUnits;
1684 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001685 case GL_MAX_MODELVIEW_STACK_DEPTH:
1686 *params = mCaps.maxModelviewMatrixStackDepth;
1687 break;
1688 case GL_MAX_PROJECTION_STACK_DEPTH:
1689 *params = mCaps.maxProjectionMatrixStackDepth;
1690 break;
1691 case GL_MAX_TEXTURE_STACK_DEPTH:
1692 *params = mCaps.maxTextureMatrixStackDepth;
1693 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001694 case GL_MAX_LIGHTS:
1695 *params = mCaps.maxLights;
1696 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001697 case GL_MAX_CLIP_PLANES:
1698 *params = mCaps.maxClipPlanes;
1699 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001700 // GLES1 emulation: Vertex attribute queries
1701 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1702 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1703 case GL_COLOR_ARRAY_BUFFER_BINDING:
1704 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1705 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1706 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1707 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1708 break;
1709 case GL_VERTEX_ARRAY_STRIDE:
1710 case GL_NORMAL_ARRAY_STRIDE:
1711 case GL_COLOR_ARRAY_STRIDE:
1712 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1713 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1714 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1715 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1716 break;
1717 case GL_VERTEX_ARRAY_SIZE:
1718 case GL_COLOR_ARRAY_SIZE:
1719 case GL_TEXTURE_COORD_ARRAY_SIZE:
1720 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1721 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1722 break;
1723 case GL_VERTEX_ARRAY_TYPE:
1724 case GL_COLOR_ARRAY_TYPE:
1725 case GL_NORMAL_ARRAY_TYPE:
1726 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1727 case GL_TEXTURE_COORD_ARRAY_TYPE:
1728 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1729 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1730 break;
1731
Jamie Madill231c7f52017-04-26 13:45:37 -04001732 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001733 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001734 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001735 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001736}
1737
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001738void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001739{
Shannon Woods53a94a82014-06-24 15:20:36 -04001740 // Queries about context capabilities and maximums are answered by Context.
1741 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001742 switch (pname)
1743 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001744 case GL_MAX_ELEMENT_INDEX:
1745 *params = mCaps.maxElementIndex;
1746 break;
1747 case GL_MAX_UNIFORM_BLOCK_SIZE:
1748 *params = mCaps.maxUniformBlockSize;
1749 break;
1750 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001751 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001752 break;
1753 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001754 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001755 break;
1756 case GL_MAX_SERVER_WAIT_TIMEOUT:
1757 *params = mCaps.maxServerWaitTimeout;
1758 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001759
Jamie Madill231c7f52017-04-26 13:45:37 -04001760 // GL_EXT_disjoint_timer_query
1761 case GL_TIMESTAMP_EXT:
1762 *params = mImplementation->getTimestamp();
1763 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001764
Jamie Madill231c7f52017-04-26 13:45:37 -04001765 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1766 *params = mCaps.maxShaderStorageBlockSize;
1767 break;
1768 default:
1769 UNREACHABLE();
1770 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001771 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001772}
1773
Geoff Lang70d0f492015-12-10 17:45:46 -05001774void Context::getPointerv(GLenum pname, void **params) const
1775{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001776 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001777}
1778
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001779void Context::getPointervRobustANGLERobust(GLenum pname,
1780 GLsizei bufSize,
1781 GLsizei *length,
1782 void **params)
1783{
1784 UNIMPLEMENTED();
1785}
1786
Martin Radev66fb8202016-07-28 11:45:20 +03001787void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001788{
Shannon Woods53a94a82014-06-24 15:20:36 -04001789 // Queries about context capabilities and maximums are answered by Context.
1790 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001791
1792 GLenum nativeType;
1793 unsigned int numParams;
1794 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1795 ASSERT(queryStatus);
1796
1797 if (nativeType == GL_INT)
1798 {
1799 switch (target)
1800 {
1801 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1802 ASSERT(index < 3u);
1803 *data = mCaps.maxComputeWorkGroupCount[index];
1804 break;
1805 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1806 ASSERT(index < 3u);
1807 *data = mCaps.maxComputeWorkGroupSize[index];
1808 break;
1809 default:
1810 mGLState.getIntegeri_v(target, index, data);
1811 }
1812 }
1813 else
1814 {
1815 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1816 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001817}
1818
Brandon Jones59770802018-04-02 13:18:42 -07001819void Context::getIntegeri_vRobust(GLenum target,
1820 GLuint index,
1821 GLsizei bufSize,
1822 GLsizei *length,
1823 GLint *data)
1824{
1825 getIntegeri_v(target, index, data);
1826}
1827
Martin Radev66fb8202016-07-28 11:45:20 +03001828void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001829{
Shannon Woods53a94a82014-06-24 15:20:36 -04001830 // Queries about context capabilities and maximums are answered by Context.
1831 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001832
1833 GLenum nativeType;
1834 unsigned int numParams;
1835 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1836 ASSERT(queryStatus);
1837
1838 if (nativeType == GL_INT_64_ANGLEX)
1839 {
1840 mGLState.getInteger64i_v(target, index, data);
1841 }
1842 else
1843 {
1844 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1845 }
1846}
1847
Brandon Jones59770802018-04-02 13:18:42 -07001848void Context::getInteger64i_vRobust(GLenum target,
1849 GLuint index,
1850 GLsizei bufSize,
1851 GLsizei *length,
1852 GLint64 *data)
1853{
1854 getInteger64i_v(target, index, data);
1855}
1856
Martin Radev66fb8202016-07-28 11:45:20 +03001857void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1858{
1859 // Queries about context capabilities and maximums are answered by Context.
1860 // Queries about current GL state values are answered by State.
1861
1862 GLenum nativeType;
1863 unsigned int numParams;
1864 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1865 ASSERT(queryStatus);
1866
1867 if (nativeType == GL_BOOL)
1868 {
1869 mGLState.getBooleani_v(target, index, data);
1870 }
1871 else
1872 {
1873 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1874 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001875}
1876
Brandon Jones59770802018-04-02 13:18:42 -07001877void Context::getBooleani_vRobust(GLenum target,
1878 GLuint index,
1879 GLsizei bufSize,
1880 GLsizei *length,
1881 GLboolean *data)
1882{
1883 getBooleani_v(target, index, data);
1884}
1885
Corentin Wallez336129f2017-10-17 15:55:40 -04001886void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001887{
1888 Buffer *buffer = mGLState.getTargetBuffer(target);
1889 QueryBufferParameteriv(buffer, pname, params);
1890}
1891
Brandon Jones59770802018-04-02 13:18:42 -07001892void Context::getBufferParameterivRobust(BufferBinding target,
1893 GLenum pname,
1894 GLsizei bufSize,
1895 GLsizei *length,
1896 GLint *params)
1897{
1898 getBufferParameteriv(target, pname, params);
1899}
1900
He Yunchao010e4db2017-03-03 14:22:06 +08001901void Context::getFramebufferAttachmentParameteriv(GLenum target,
1902 GLenum attachment,
1903 GLenum pname,
1904 GLint *params)
1905{
1906 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001907 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001908}
1909
Brandon Jones59770802018-04-02 13:18:42 -07001910void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1911 GLenum attachment,
1912 GLenum pname,
1913 GLsizei bufSize,
1914 GLsizei *length,
1915 GLint *params)
1916{
1917 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1918}
1919
He Yunchao010e4db2017-03-03 14:22:06 +08001920void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1921{
1922 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1923 QueryRenderbufferiv(this, renderbuffer, pname, params);
1924}
1925
Brandon Jones59770802018-04-02 13:18:42 -07001926void Context::getRenderbufferParameterivRobust(GLenum target,
1927 GLenum pname,
1928 GLsizei bufSize,
1929 GLsizei *length,
1930 GLint *params)
1931{
1932 getRenderbufferParameteriv(target, pname, params);
1933}
1934
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001935void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001936{
1937 Texture *texture = getTargetTexture(target);
1938 QueryTexParameterfv(texture, pname, params);
1939}
1940
Brandon Jones59770802018-04-02 13:18:42 -07001941void Context::getTexParameterfvRobust(TextureType target,
1942 GLenum pname,
1943 GLsizei bufSize,
1944 GLsizei *length,
1945 GLfloat *params)
1946{
1947 getTexParameterfv(target, pname, params);
1948}
1949
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001950void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001951{
1952 Texture *texture = getTargetTexture(target);
1953 QueryTexParameteriv(texture, pname, params);
1954}
Jiajia Qin5451d532017-11-16 17:16:34 +08001955
Brandon Jones59770802018-04-02 13:18:42 -07001956void Context::getTexParameterivRobust(TextureType target,
1957 GLenum pname,
1958 GLsizei bufSize,
1959 GLsizei *length,
1960 GLint *params)
1961{
1962 getTexParameteriv(target, pname, params);
1963}
1964
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001965void Context::getTexParameterIivRobust(TextureType target,
1966 GLenum pname,
1967 GLsizei bufSize,
1968 GLsizei *length,
1969 GLint *params)
1970{
1971 UNIMPLEMENTED();
1972}
1973
1974void Context::getTexParameterIuivRobust(TextureType target,
1975 GLenum pname,
1976 GLsizei bufSize,
1977 GLsizei *length,
1978 GLuint *params)
1979{
1980 UNIMPLEMENTED();
1981}
1982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001983void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001984{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001985 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001986 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001987}
1988
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001989void Context::getTexLevelParameterivRobust(TextureTarget target,
1990 GLint level,
1991 GLenum pname,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLint *params)
1995{
1996 UNIMPLEMENTED();
1997}
1998
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001999void Context::getTexLevelParameterfv(TextureTarget target,
2000 GLint level,
2001 GLenum pname,
2002 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002003{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002004 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002005 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002006}
2007
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002008void Context::getTexLevelParameterfvRobust(TextureTarget target,
2009 GLint level,
2010 GLenum pname,
2011 GLsizei bufSize,
2012 GLsizei *length,
2013 GLfloat *params)
2014{
2015 UNIMPLEMENTED();
2016}
2017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002018void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002019{
2020 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002021 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002022 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002023}
2024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002025void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002026{
2027 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002028 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002029 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002030}
2031
Brandon Jones59770802018-04-02 13:18:42 -07002032void Context::texParameterfvRobust(TextureType target,
2033 GLenum pname,
2034 GLsizei bufSize,
2035 const GLfloat *params)
2036{
2037 texParameterfv(target, pname, params);
2038}
2039
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002040void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002041{
2042 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002043 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002044 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002045}
2046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002047void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002048{
2049 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002050 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002051 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002052}
2053
Brandon Jones59770802018-04-02 13:18:42 -07002054void Context::texParameterivRobust(TextureType target,
2055 GLenum pname,
2056 GLsizei bufSize,
2057 const GLint *params)
2058{
2059 texParameteriv(target, pname, params);
2060}
2061
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002062void Context::texParameterIivRobust(TextureType target,
2063 GLenum pname,
2064 GLsizei bufSize,
2065 const GLint *params)
2066{
2067 UNIMPLEMENTED();
2068}
2069
2070void Context::texParameterIuivRobust(TextureType target,
2071 GLenum pname,
2072 GLsizei bufSize,
2073 const GLuint *params)
2074{
2075 UNIMPLEMENTED();
2076}
2077
Jamie Madill493f9572018-05-24 19:52:15 -04002078void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002079{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002080 // No-op if zero count
2081 if (count == 0)
2082 {
2083 return;
2084 }
2085
Jamie Madill05b35b22017-10-03 09:01:44 -04002086 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002087 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002088 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002089}
2090
Jamie Madill493f9572018-05-24 19:52:15 -04002091void Context::drawArraysInstanced(PrimitiveMode mode,
2092 GLint first,
2093 GLsizei count,
2094 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002095{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002096 // No-op if zero count
2097 if (count == 0 || instanceCount == 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(
2104 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002105 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2106 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002107}
2108
Jamie Madill493f9572018-05-24 19:52:15 -04002109void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002110{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002111 // No-op if zero count
2112 if (count == 0)
2113 {
2114 return;
2115 }
2116
Jamie Madill05b35b22017-10-03 09:01:44 -04002117 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002118 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002119}
2120
Jamie Madill493f9572018-05-24 19:52:15 -04002121void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002122 GLsizei count,
2123 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002124 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002125 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002126{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002127 // No-op if zero count
2128 if (count == 0 || instances == 0)
2129 {
2130 return;
2131 }
2132
Jamie Madill05b35b22017-10-03 09:01:44 -04002133 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002134 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002135 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002136}
2137
Jamie Madill493f9572018-05-24 19:52:15 -04002138void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002139 GLuint start,
2140 GLuint end,
2141 GLsizei count,
2142 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002143 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002144{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002145 // No-op if zero count
2146 if (count == 0)
2147 {
2148 return;
2149 }
2150
Jamie Madill05b35b22017-10-03 09:01:44 -04002151 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002152 ANGLE_CONTEXT_TRY(
2153 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002154}
2155
Jamie Madill493f9572018-05-24 19:52:15 -04002156void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002157{
Jamie Madill05b35b22017-10-03 09:01:44 -04002158 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002159 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002160}
2161
Jamie Madill493f9572018-05-24 19:52:15 -04002162void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002163{
Jamie Madill05b35b22017-10-03 09:01:44 -04002164 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002165 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002166}
2167
Jamie Madill675fe712016-12-19 13:07:54 -05002168void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002169{
Jamie Madillafa02a22017-11-23 12:57:38 -05002170 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002171}
2172
Jamie Madill675fe712016-12-19 13:07:54 -05002173void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002174{
Jamie Madillafa02a22017-11-23 12:57:38 -05002175 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176}
2177
Austin Kinross6ee1e782015-05-29 17:05:37 -07002178void Context::insertEventMarker(GLsizei length, const char *marker)
2179{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002180 ASSERT(mImplementation);
2181 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002182}
2183
2184void Context::pushGroupMarker(GLsizei length, const char *marker)
2185{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002186 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002187
2188 if (marker == nullptr)
2189 {
2190 // From the EXT_debug_marker spec,
2191 // "If <marker> is null then an empty string is pushed on the stack."
2192 mImplementation->pushGroupMarker(length, "");
2193 }
2194 else
2195 {
2196 mImplementation->pushGroupMarker(length, marker);
2197 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002198}
2199
2200void Context::popGroupMarker()
2201{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002202 ASSERT(mImplementation);
2203 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002204}
2205
Geoff Langd8605522016-04-13 10:19:12 -04002206void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2207{
2208 Program *programObject = getProgram(program);
2209 ASSERT(programObject);
2210
2211 programObject->bindUniformLocation(location, name);
2212}
2213
Brandon Jones59770802018-04-02 13:18:42 -07002214void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002215{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002216 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002217}
2218
Brandon Jones59770802018-04-02 13:18:42 -07002219void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002220{
2221 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2222}
2223
Brandon Jones59770802018-04-02 13:18:42 -07002224void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002225{
2226 GLfloat I[16];
2227 angle::Matrix<GLfloat>::setToIdentity(I);
2228
2229 mGLState.loadPathRenderingMatrix(matrixMode, I);
2230}
2231
2232void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2233{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002234 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002235 if (!pathObj)
2236 return;
2237
2238 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002239 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002240
2241 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2242}
2243
2244void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2245{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002246 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002247 if (!pathObj)
2248 return;
2249
2250 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002251 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002252
2253 mImplementation->stencilStrokePath(pathObj, reference, mask);
2254}
2255
2256void Context::coverFillPath(GLuint path, GLenum coverMode)
2257{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002258 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002259 if (!pathObj)
2260 return;
2261
2262 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002263 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002264
2265 mImplementation->coverFillPath(pathObj, coverMode);
2266}
2267
2268void Context::coverStrokePath(GLuint path, GLenum coverMode)
2269{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002270 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002271 if (!pathObj)
2272 return;
2273
2274 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002275 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002276
2277 mImplementation->coverStrokePath(pathObj, coverMode);
2278}
2279
2280void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, 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->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2290}
2291
2292void Context::stencilThenCoverStrokePath(GLuint path,
2293 GLint reference,
2294 GLuint mask,
2295 GLenum coverMode)
2296{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002297 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002298 if (!pathObj)
2299 return;
2300
2301 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002302 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002303
2304 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2305}
2306
Sami Väisänend59ca052016-06-21 16:10:00 +03002307void Context::coverFillPathInstanced(GLsizei numPaths,
2308 GLenum pathNameType,
2309 const void *paths,
2310 GLuint pathBase,
2311 GLenum coverMode,
2312 GLenum transformType,
2313 const GLfloat *transformValues)
2314{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002315 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002316
2317 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002318 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002319
2320 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2321}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002322
Sami Väisänend59ca052016-06-21 16:10:00 +03002323void Context::coverStrokePathInstanced(GLsizei numPaths,
2324 GLenum pathNameType,
2325 const void *paths,
2326 GLuint pathBase,
2327 GLenum coverMode,
2328 GLenum transformType,
2329 const GLfloat *transformValues)
2330{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002331 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002332
2333 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002334 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002335
2336 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2337 transformValues);
2338}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002339
Sami Väisänend59ca052016-06-21 16:10:00 +03002340void Context::stencilFillPathInstanced(GLsizei numPaths,
2341 GLenum pathNameType,
2342 const void *paths,
2343 GLuint pathBase,
2344 GLenum fillMode,
2345 GLuint mask,
2346 GLenum transformType,
2347 const GLfloat *transformValues)
2348{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002349 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002350
2351 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002352 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002353
2354 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2355 transformValues);
2356}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002357
Sami Väisänend59ca052016-06-21 16:10:00 +03002358void Context::stencilStrokePathInstanced(GLsizei numPaths,
2359 GLenum pathNameType,
2360 const void *paths,
2361 GLuint pathBase,
2362 GLint reference,
2363 GLuint mask,
2364 GLenum transformType,
2365 const GLfloat *transformValues)
2366{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002367 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002368
2369 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002370 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2373 transformValues);
2374}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002375
Sami Väisänend59ca052016-06-21 16:10:00 +03002376void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2377 GLenum pathNameType,
2378 const void *paths,
2379 GLuint pathBase,
2380 GLenum fillMode,
2381 GLuint mask,
2382 GLenum coverMode,
2383 GLenum transformType,
2384 const GLfloat *transformValues)
2385{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002386 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002389 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002390
2391 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2392 transformType, transformValues);
2393}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002394
Sami Väisänend59ca052016-06-21 16:10:00 +03002395void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2396 GLenum pathNameType,
2397 const void *paths,
2398 GLuint pathBase,
2399 GLint reference,
2400 GLuint mask,
2401 GLenum coverMode,
2402 GLenum transformType,
2403 const GLfloat *transformValues)
2404{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002406
2407 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002408 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002409
2410 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2411 transformType, transformValues);
2412}
2413
Sami Väisänen46eaa942016-06-29 10:26:37 +03002414void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2415{
2416 auto *programObject = getProgram(program);
2417
2418 programObject->bindFragmentInputLocation(location, name);
2419}
2420
2421void Context::programPathFragmentInputGen(GLuint program,
2422 GLint location,
2423 GLenum genMode,
2424 GLint components,
2425 const GLfloat *coeffs)
2426{
2427 auto *programObject = getProgram(program);
2428
Jamie Madillbd044ed2017-06-05 12:59:21 -04002429 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002430}
2431
jchen1015015f72017-03-16 13:54:21 +08002432GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2433{
jchen10fd7c3b52017-03-21 15:36:03 +08002434 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002435 return QueryProgramResourceIndex(programObject, programInterface, name);
2436}
2437
jchen10fd7c3b52017-03-21 15:36:03 +08002438void Context::getProgramResourceName(GLuint program,
2439 GLenum programInterface,
2440 GLuint index,
2441 GLsizei bufSize,
2442 GLsizei *length,
2443 GLchar *name)
2444{
2445 const auto *programObject = getProgram(program);
2446 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2447}
2448
jchen10191381f2017-04-11 13:59:04 +08002449GLint Context::getProgramResourceLocation(GLuint program,
2450 GLenum programInterface,
2451 const GLchar *name)
2452{
2453 const auto *programObject = getProgram(program);
2454 return QueryProgramResourceLocation(programObject, programInterface, name);
2455}
2456
jchen10880683b2017-04-12 16:21:55 +08002457void Context::getProgramResourceiv(GLuint program,
2458 GLenum programInterface,
2459 GLuint index,
2460 GLsizei propCount,
2461 const GLenum *props,
2462 GLsizei bufSize,
2463 GLsizei *length,
2464 GLint *params)
2465{
2466 const auto *programObject = getProgram(program);
2467 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2468 length, params);
2469}
2470
jchen10d9cd7b72017-08-30 15:04:25 +08002471void Context::getProgramInterfaceiv(GLuint program,
2472 GLenum programInterface,
2473 GLenum pname,
2474 GLint *params)
2475{
2476 const auto *programObject = getProgram(program);
2477 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2478}
2479
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002480void Context::getProgramInterfaceivRobust(GLuint program,
2481 GLenum programInterface,
2482 GLenum pname,
2483 GLsizei bufSize,
2484 GLsizei *length,
2485 GLint *params)
2486{
2487 UNIMPLEMENTED();
2488}
2489
Jamie Madill427064d2018-04-13 16:20:34 -04002490void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002491{
Geoff Lang7b19a492018-04-20 09:31:52 -04002492 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002493 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002494 GLenum code = error.getCode();
2495 mErrors.insert(code);
2496 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2497 {
2498 markContextLost();
2499 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002500
Geoff Langee6884e2017-11-09 16:51:11 -05002501 ASSERT(!error.getMessage().empty());
2502 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2503 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002504 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505}
2506
2507// Get one of the recorded errors and clear its flag, if any.
2508// [OpenGL ES 2.0.24] section 2.5 page 13.
2509GLenum Context::getError()
2510{
Geoff Langda5777c2014-07-11 09:52:58 -04002511 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002512 {
Geoff Langda5777c2014-07-11 09:52:58 -04002513 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002514 }
Geoff Langda5777c2014-07-11 09:52:58 -04002515 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002516 {
Geoff Langda5777c2014-07-11 09:52:58 -04002517 GLenum error = *mErrors.begin();
2518 mErrors.erase(mErrors.begin());
2519 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002520 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521}
2522
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002523// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002524void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002525{
2526 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002527 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002528 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002529 mContextLostForced = true;
2530 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002531 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002532}
2533
Jamie Madill427064d2018-04-13 16:20:34 -04002534bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535{
2536 return mContextLost;
2537}
2538
Jamie Madillfa920eb2018-01-04 11:45:50 -05002539GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002540{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002541 // Even if the application doesn't want to know about resets, we want to know
2542 // as it will allow us to skip all the calls.
2543 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002544 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002546 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002547 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002548 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002549
2550 // EXT_robustness, section 2.6: If the reset notification behavior is
2551 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2552 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2553 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002554 }
2555
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002556 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2557 // status should be returned at least once, and GL_NO_ERROR should be returned
2558 // once the device has finished resetting.
2559 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002560 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002561 ASSERT(mResetStatus == GL_NO_ERROR);
2562 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002563
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002564 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002565 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002566 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567 }
2568 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002569 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002570 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002571 // If markContextLost was used to mark the context lost then
2572 // assume that is not recoverable, and continue to report the
2573 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002574 mResetStatus = mImplementation->getResetStatus();
2575 }
Jamie Madill893ab082014-05-16 16:56:10 -04002576
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002577 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002578}
2579
2580bool Context::isResetNotificationEnabled()
2581{
2582 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2583}
2584
Corentin Walleze3b10e82015-05-20 11:06:25 -04002585const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002586{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002587 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002588}
2589
2590EGLenum Context::getClientType() const
2591{
2592 return mClientType;
2593}
2594
2595EGLenum Context::getRenderBuffer() const
2596{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002597 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2598 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002599 {
2600 return EGL_NONE;
2601 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002602
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002603 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002604 ASSERT(backAttachment != nullptr);
2605 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002606}
2607
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002608VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
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 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2612 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002613 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002614 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2615 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002616
Jamie Madill96a483b2017-06-27 16:49:21 -04002617 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002618 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002619
2620 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002621}
2622
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002623TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002624{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002625 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002626 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2627 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002628 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002629 transformFeedback =
2630 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002631 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002632 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002633 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002634
2635 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002636}
2637
2638bool Context::isVertexArrayGenerated(GLuint vertexArray)
2639{
Jamie Madill96a483b2017-06-27 16:49:21 -04002640 ASSERT(mVertexArrayMap.contains(0));
2641 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002642}
2643
2644bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2645{
Jamie Madill96a483b2017-06-27 16:49:21 -04002646 ASSERT(mTransformFeedbackMap.contains(0));
2647 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002648}
2649
Shannon Woods53a94a82014-06-24 15:20:36 -04002650void Context::detachTexture(GLuint texture)
2651{
2652 // Simple pass-through to State's detachTexture method, as textures do not require
2653 // allocation map management either here or in the resource manager at detach time.
2654 // Zero textures are held by the Context, and we don't attempt to request them from
2655 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002656 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002657}
2658
James Darpinian4d9d4832018-03-13 12:43:28 -07002659void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660{
Yuly Novikov5807a532015-12-03 13:01:22 -05002661 // Simple pass-through to State's detachBuffer method, since
2662 // only buffer attachments to container objects that are bound to the current context
2663 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002664
Yuly Novikov5807a532015-12-03 13:01:22 -05002665 // [OpenGL ES 3.2] section 5.1.2 page 45:
2666 // Attachments to unbound container objects, such as
2667 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2668 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002669 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670}
2671
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002672void Context::detachFramebuffer(GLuint framebuffer)
2673{
Shannon Woods53a94a82014-06-24 15:20:36 -04002674 // Framebuffer detachment is handled by Context, because 0 is a valid
2675 // Framebuffer object, and a pointer to it must be passed from Context
2676 // to State at binding time.
2677
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002679 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2680 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2681 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002682
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002683 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684 {
2685 bindReadFramebuffer(0);
2686 }
2687
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002688 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002689 {
2690 bindDrawFramebuffer(0);
2691 }
2692}
2693
2694void Context::detachRenderbuffer(GLuint renderbuffer)
2695{
Jamie Madilla02315b2017-02-23 14:14:47 -05002696 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002697}
2698
Jamie Madill57a89722013-07-02 11:57:03 -04002699void Context::detachVertexArray(GLuint vertexArray)
2700{
Jamie Madill77a72f62015-04-14 11:18:32 -04002701 // Vertex array detachment is handled by Context, because 0 is a valid
2702 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002703 // binding time.
2704
Jamie Madill57a89722013-07-02 11:57:03 -04002705 // [OpenGL ES 3.0.2] section 2.10 page 43:
2706 // If a vertex array object that is currently bound is deleted, the binding
2707 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002708 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002709 {
2710 bindVertexArray(0);
2711 }
2712}
2713
Geoff Langc8058452014-02-03 12:04:11 -05002714void Context::detachTransformFeedback(GLuint transformFeedback)
2715{
Corentin Walleza2257da2016-04-19 16:43:12 -04002716 // Transform feedback detachment is handled by Context, because 0 is a valid
2717 // transform feedback, and a pointer to it must be passed from Context to State at
2718 // binding time.
2719
2720 // The OpenGL specification doesn't mention what should happen when the currently bound
2721 // transform feedback object is deleted. Since it is a container object, we treat it like
2722 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002723 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002724 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002725 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002726 }
Geoff Langc8058452014-02-03 12:04:11 -05002727}
2728
Jamie Madilldc356042013-07-19 16:36:57 -04002729void Context::detachSampler(GLuint sampler)
2730{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002731 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002732}
2733
Yunchao Hea336b902017-08-02 16:05:21 +08002734void Context::detachProgramPipeline(GLuint pipeline)
2735{
2736 mGLState.detachProgramPipeline(this, pipeline);
2737}
2738
Jamie Madill3ef140a2017-08-26 23:11:21 -04002739void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002740{
Shaodde78e82017-05-22 14:13:27 +08002741 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002742}
2743
Jamie Madille29d1672013-07-19 16:36:57 -04002744void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2745{
Geoff Langc1984ed2016-10-07 12:41:00 -04002746 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002747 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002748 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002749 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002750}
Jamie Madille29d1672013-07-19 16:36:57 -04002751
Geoff Langc1984ed2016-10-07 12:41:00 -04002752void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2753{
2754 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002755 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002756 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002757 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002758}
2759
Brandon Jones59770802018-04-02 13:18:42 -07002760void Context::samplerParameterivRobust(GLuint sampler,
2761 GLenum pname,
2762 GLsizei bufSize,
2763 const GLint *param)
2764{
2765 samplerParameteriv(sampler, pname, param);
2766}
2767
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002768void Context::samplerParameterIivRobust(GLuint sampler,
2769 GLenum pname,
2770 GLsizei bufSize,
2771 const GLint *param)
2772{
2773 UNIMPLEMENTED();
2774}
2775
2776void Context::samplerParameterIuivRobust(GLuint sampler,
2777 GLenum pname,
2778 GLsizei bufSize,
2779 const GLuint *param)
2780{
2781 UNIMPLEMENTED();
2782}
2783
Jamie Madille29d1672013-07-19 16:36:57 -04002784void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2785{
Geoff Langc1984ed2016-10-07 12:41:00 -04002786 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002787 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002788 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002789 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002790}
2791
Geoff Langc1984ed2016-10-07 12:41:00 -04002792void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002793{
Geoff Langc1984ed2016-10-07 12:41:00 -04002794 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002795 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002796 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002797 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002798}
2799
Brandon Jones59770802018-04-02 13:18:42 -07002800void Context::samplerParameterfvRobust(GLuint sampler,
2801 GLenum pname,
2802 GLsizei bufSize,
2803 const GLfloat *param)
2804{
2805 samplerParameterfv(sampler, pname, param);
2806}
2807
Geoff Langc1984ed2016-10-07 12:41:00 -04002808void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002809{
Geoff Langc1984ed2016-10-07 12:41:00 -04002810 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002811 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002813 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002814}
Jamie Madill9675b802013-07-19 16:36:59 -04002815
Brandon Jones59770802018-04-02 13:18:42 -07002816void Context::getSamplerParameterivRobust(GLuint sampler,
2817 GLenum pname,
2818 GLsizei bufSize,
2819 GLsizei *length,
2820 GLint *params)
2821{
2822 getSamplerParameteriv(sampler, pname, params);
2823}
2824
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002825void Context::getSamplerParameterIivRobust(GLuint sampler,
2826 GLenum pname,
2827 GLsizei bufSize,
2828 GLsizei *length,
2829 GLint *params)
2830{
2831 UNIMPLEMENTED();
2832}
2833
2834void Context::getSamplerParameterIuivRobust(GLuint sampler,
2835 GLenum pname,
2836 GLsizei bufSize,
2837 GLsizei *length,
2838 GLuint *params)
2839{
2840 UNIMPLEMENTED();
2841}
2842
Geoff Langc1984ed2016-10-07 12:41:00 -04002843void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2844{
2845 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002846 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002847 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002848 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002849}
2850
Brandon Jones59770802018-04-02 13:18:42 -07002851void Context::getSamplerParameterfvRobust(GLuint sampler,
2852 GLenum pname,
2853 GLsizei bufSize,
2854 GLsizei *length,
2855 GLfloat *params)
2856{
2857 getSamplerParameterfv(sampler, pname, params);
2858}
2859
Olli Etuahof0fee072016-03-30 15:11:58 +03002860void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2861{
2862 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002863 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002864}
2865
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002866void Context::initRendererString()
2867{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002868 std::ostringstream rendererString;
2869 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002870 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002871 rendererString << ")";
2872
Geoff Langcec35902014-04-16 10:52:36 -04002873 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002874}
2875
Geoff Langc339c4e2016-11-29 10:37:36 -05002876void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002877{
Geoff Langc339c4e2016-11-29 10:37:36 -05002878 const Version &clientVersion = getClientVersion();
2879
2880 std::ostringstream versionString;
2881 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2882 << ANGLE_VERSION_STRING << ")";
2883 mVersionString = MakeStaticString(versionString.str());
2884
2885 std::ostringstream shadingLanguageVersionString;
2886 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2887 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2888 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2889 << ")";
2890 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002891}
2892
Geoff Langcec35902014-04-16 10:52:36 -04002893void Context::initExtensionStrings()
2894{
Geoff Langc339c4e2016-11-29 10:37:36 -05002895 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2896 std::ostringstream combinedStringStream;
2897 std::copy(strings.begin(), strings.end(),
2898 std::ostream_iterator<const char *>(combinedStringStream, " "));
2899 return MakeStaticString(combinedStringStream.str());
2900 };
2901
2902 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002903 for (const auto &extensionString : mExtensions.getStrings())
2904 {
2905 mExtensionStrings.push_back(MakeStaticString(extensionString));
2906 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002907 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002908
Geoff Langc339c4e2016-11-29 10:37:36 -05002909 mRequestableExtensionStrings.clear();
2910 for (const auto &extensionInfo : GetExtensionInfoMap())
2911 {
2912 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002913 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002914 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002915 {
2916 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2917 }
2918 }
2919 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002920}
2921
Geoff Langc339c4e2016-11-29 10:37:36 -05002922const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002923{
Geoff Langc339c4e2016-11-29 10:37:36 -05002924 switch (name)
2925 {
2926 case GL_VENDOR:
2927 return reinterpret_cast<const GLubyte *>("Google Inc.");
2928
2929 case GL_RENDERER:
2930 return reinterpret_cast<const GLubyte *>(mRendererString);
2931
2932 case GL_VERSION:
2933 return reinterpret_cast<const GLubyte *>(mVersionString);
2934
2935 case GL_SHADING_LANGUAGE_VERSION:
2936 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2937
2938 case GL_EXTENSIONS:
2939 return reinterpret_cast<const GLubyte *>(mExtensionString);
2940
2941 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2942 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2943
2944 default:
2945 UNREACHABLE();
2946 return nullptr;
2947 }
Geoff Langcec35902014-04-16 10:52:36 -04002948}
2949
Geoff Langc339c4e2016-11-29 10:37:36 -05002950const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002951{
Geoff Langc339c4e2016-11-29 10:37:36 -05002952 switch (name)
2953 {
2954 case GL_EXTENSIONS:
2955 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2956
2957 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2958 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2959
2960 default:
2961 UNREACHABLE();
2962 return nullptr;
2963 }
Geoff Langcec35902014-04-16 10:52:36 -04002964}
2965
2966size_t Context::getExtensionStringCount() const
2967{
2968 return mExtensionStrings.size();
2969}
2970
Geoff Lang111a99e2017-10-17 10:58:41 -04002971bool Context::isExtensionRequestable(const char *name)
2972{
2973 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2974 auto extension = extensionInfos.find(name);
2975
Geoff Lang111a99e2017-10-17 10:58:41 -04002976 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002977 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002978}
2979
Geoff Langc339c4e2016-11-29 10:37:36 -05002980void Context::requestExtension(const char *name)
2981{
2982 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2983 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2984 const auto &extension = extensionInfos.at(name);
2985 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002986 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002987
2988 if (mExtensions.*(extension.ExtensionsMember))
2989 {
2990 // Extension already enabled
2991 return;
2992 }
2993
2994 mExtensions.*(extension.ExtensionsMember) = true;
2995 updateCaps();
2996 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002997
Jamie Madill2f348d22017-06-05 10:50:59 -04002998 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2999 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003000
Jamie Madill81c2e252017-09-09 23:32:46 -04003001 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3002 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003003 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003004 for (auto &zeroTexture : mZeroTextures)
3005 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003006 if (zeroTexture.get() != nullptr)
3007 {
3008 zeroTexture->signalDirty(this, InitState::Initialized);
3009 }
Geoff Lang9aded172017-04-05 11:07:56 -04003010 }
3011
3012 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003013}
3014
3015size_t Context::getRequestableExtensionStringCount() const
3016{
3017 return mRequestableExtensionStrings.size();
3018}
3019
Jamie Madill493f9572018-05-24 19:52:15 -04003020void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003021{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003022 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003023 ASSERT(transformFeedback != nullptr);
3024 ASSERT(!transformFeedback->isPaused());
3025
Jamie Madill6c1f6712017-02-14 19:08:04 -05003026 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003027}
3028
3029bool Context::hasActiveTransformFeedback(GLuint program) const
3030{
3031 for (auto pair : mTransformFeedbackMap)
3032 {
3033 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3034 {
3035 return true;
3036 }
3037 }
3038 return false;
3039}
3040
Geoff Lang33f11fb2018-05-07 13:42:47 -04003041Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003042{
3043 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3044
3045 if (getClientVersion() < ES_2_0)
3046 {
3047 // Default extensions for GLES1
3048 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003049 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003050 }
3051
3052 if (getClientVersion() < ES_3_0)
3053 {
3054 // Disable ES3+ extensions
3055 supportedExtensions.colorBufferFloat = false;
3056 supportedExtensions.eglImageExternalEssl3 = false;
3057 supportedExtensions.textureNorm16 = false;
3058 supportedExtensions.multiview = false;
3059 supportedExtensions.maxViews = 1u;
3060 }
3061
3062 if (getClientVersion() < ES_3_1)
3063 {
3064 // Disable ES3.1+ extensions
3065 supportedExtensions.geometryShader = false;
3066 }
3067
3068 if (getClientVersion() > ES_2_0)
3069 {
3070 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3071 // supportedExtensions.sRGB = false;
3072 }
3073
3074 // Some extensions are always available because they are implemented in the GL layer.
3075 supportedExtensions.bindUniformLocation = true;
3076 supportedExtensions.vertexArrayObject = true;
3077 supportedExtensions.bindGeneratesResource = true;
3078 supportedExtensions.clientArrays = true;
3079 supportedExtensions.requestExtension = true;
3080
3081 // Enable the no error extension if the context was created with the flag.
3082 supportedExtensions.noError = mSkipValidation;
3083
3084 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003085 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003086
3087 // Explicitly enable GL_KHR_debug
3088 supportedExtensions.debug = true;
3089 supportedExtensions.maxDebugMessageLength = 1024;
3090 supportedExtensions.maxDebugLoggedMessages = 1024;
3091 supportedExtensions.maxDebugGroupStackDepth = 1024;
3092 supportedExtensions.maxLabelLength = 1024;
3093
3094 // Explicitly enable GL_ANGLE_robust_client_memory
3095 supportedExtensions.robustClientMemory = true;
3096
3097 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003098 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003099
3100 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3101 // supports it.
3102 supportedExtensions.robustBufferAccessBehavior =
3103 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3104
3105 // Enable the cache control query unconditionally.
3106 supportedExtensions.programCacheControl = true;
3107
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003108 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003109 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003110 {
3111 // GL_ANGLE_explicit_context_gles1
3112 supportedExtensions.explicitContextGles1 = true;
3113 // GL_ANGLE_explicit_context
3114 supportedExtensions.explicitContext = true;
3115 }
3116
Geoff Langb0f917f2017-12-05 13:41:54 -05003117 return supportedExtensions;
3118}
3119
Geoff Lang33f11fb2018-05-07 13:42:47 -04003120void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003121{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003122 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003123
Geoff Lang33f11fb2018-05-07 13:42:47 -04003124 mSupportedExtensions = generateSupportedExtensions();
3125 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003126
3127 mLimitations = mImplementation->getNativeLimitations();
3128
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003129 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3130 if (getClientVersion() < Version(2, 0))
3131 {
3132 mCaps.maxMultitextureUnits = 4;
3133 mCaps.maxClipPlanes = 6;
3134 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003135 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3136 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3137 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003138 }
3139
Luc Ferronad2ae932018-06-11 15:31:17 -04003140 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003141 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003142
Luc Ferronad2ae932018-06-11 15:31:17 -04003143 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3144
Jamie Madill0f80ed82017-09-19 00:24:56 -04003145 if (getClientVersion() < ES_3_1)
3146 {
3147 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3148 }
3149 else
3150 {
3151 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3152 }
Geoff Lang301d1612014-07-09 10:34:37 -04003153
Jiawei Shao54aafe52018-04-27 14:54:57 +08003154 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3155 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003156 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3157 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3158
3159 // Limit textures as well, so we can use fast bitsets with texture bindings.
3160 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003161 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3162 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3163 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3164 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003165
Jiawei Shaodb342272017-09-27 10:21:45 +08003166 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3167
Geoff Langc287ea62016-09-16 14:46:51 -04003168 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003169 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003170 for (const auto &extensionInfo : GetExtensionInfoMap())
3171 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003172 // If the user has requested that extensions start disabled and they are requestable,
3173 // disable them.
3174 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003175 {
3176 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3177 }
3178 }
3179
3180 // Generate texture caps
3181 updateCaps();
3182}
3183
3184void Context::updateCaps()
3185{
Geoff Lang900013c2014-07-07 11:32:19 -04003186 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003187 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003188
Jamie Madill7b62cf92017-11-02 15:20:49 -04003189 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003190 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003191 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003192 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003193
Geoff Lang0d8b7242015-09-09 14:56:53 -04003194 // Update the format caps based on the client version and extensions.
3195 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3196 // ES3.
3197 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003198 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003199 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003200 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003201 formatCaps.textureAttachment =
3202 formatCaps.textureAttachment &&
3203 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3204 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3205 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003206
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003207 // OpenGL ES does not support multisampling with non-rendererable formats
3208 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003209 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003210 (getClientVersion() < ES_3_1 &&
3211 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003212 {
Geoff Langd87878e2014-09-19 15:42:59 -04003213 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003214 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003215 else
3216 {
3217 // We may have limited the max samples for some required renderbuffer formats due to
3218 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3219 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3220
3221 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3222 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3223 // exception of signed and unsigned integer formats."
3224 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3225 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3226 {
3227 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3228 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3229 }
3230
3231 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3232 if (getClientVersion() >= ES_3_1)
3233 {
3234 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3235 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3236 // the exception that the signed and unsigned integer formats are required only to
3237 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3238 // multisamples, which must be at least one."
3239 if (formatInfo.componentType == GL_INT ||
3240 formatInfo.componentType == GL_UNSIGNED_INT)
3241 {
3242 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3243 }
3244
3245 // GLES 3.1 section 19.3.1.
3246 if (formatCaps.texturable)
3247 {
3248 if (formatInfo.depthBits > 0)
3249 {
3250 mCaps.maxDepthTextureSamples =
3251 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3252 }
3253 else if (formatInfo.redBits > 0)
3254 {
3255 mCaps.maxColorTextureSamples =
3256 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3257 }
3258 }
3259 }
3260 }
Geoff Langd87878e2014-09-19 15:42:59 -04003261
3262 if (formatCaps.texturable && formatInfo.compressed)
3263 {
Geoff Langca271392017-04-05 12:30:00 -04003264 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003265 }
3266
Geoff Langca271392017-04-05 12:30:00 -04003267 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003268 }
Jamie Madill32447362017-06-28 14:53:52 -04003269
3270 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003271 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003272 {
3273 mMemoryProgramCache = nullptr;
3274 }
Corentin Walleze4477002017-12-01 14:39:58 -05003275
3276 // Compute which buffer types are allowed
3277 mValidBufferBindings.reset();
3278 mValidBufferBindings.set(BufferBinding::ElementArray);
3279 mValidBufferBindings.set(BufferBinding::Array);
3280
3281 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3282 {
3283 mValidBufferBindings.set(BufferBinding::PixelPack);
3284 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3285 }
3286
3287 if (getClientVersion() >= ES_3_0)
3288 {
3289 mValidBufferBindings.set(BufferBinding::CopyRead);
3290 mValidBufferBindings.set(BufferBinding::CopyWrite);
3291 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3292 mValidBufferBindings.set(BufferBinding::Uniform);
3293 }
3294
3295 if (getClientVersion() >= ES_3_1)
3296 {
3297 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3298 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3299 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3300 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3301 }
Geoff Lang493daf52014-07-03 13:38:44 -04003302}
3303
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003304void Context::initWorkarounds()
3305{
Jamie Madill761b02c2017-06-23 16:27:06 -04003306 // Apply back-end workarounds.
3307 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3308
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003309 // Lose the context upon out of memory error if the application is
3310 // expecting to watch for those events.
3311 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3312}
3313
Jamie Madill05b35b22017-10-03 09:01:44 -04003314Error Context::prepareForDraw()
3315{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003316 if (mGLES1Renderer)
3317 {
3318 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3319 }
3320
Geoff Langa8cb2872018-03-09 16:09:40 -05003321 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003322
3323 if (isRobustResourceInitEnabled())
3324 {
3325 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3326 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3327 }
3328
Geoff Langa8cb2872018-03-09 16:09:40 -05003329 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003330 return NoError();
3331}
3332
3333Error Context::prepareForClear(GLbitfield mask)
3334{
Geoff Langa8cb2872018-03-09 16:09:40 -05003335 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003336 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003337 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003338 return NoError();
3339}
3340
3341Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3342{
Geoff Langa8cb2872018-03-09 16:09:40 -05003343 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003344 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3345 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003346 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003347 return NoError();
3348}
3349
Geoff Langa8cb2872018-03-09 16:09:40 -05003350Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003351{
Geoff Langa8cb2872018-03-09 16:09:40 -05003352 ANGLE_TRY(syncDirtyObjects());
3353 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003354 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003355}
3356
Geoff Langa8cb2872018-03-09 16:09:40 -05003357Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003358{
Geoff Langa8cb2872018-03-09 16:09:40 -05003359 ANGLE_TRY(syncDirtyObjects(objectMask));
3360 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003361 return NoError();
3362}
3363
Geoff Langa8cb2872018-03-09 16:09:40 -05003364Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003365{
3366 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3367 mImplementation->syncState(this, dirtyBits);
3368 mGLState.clearDirtyBits();
3369 return NoError();
3370}
3371
Geoff Langa8cb2872018-03-09 16:09:40 -05003372Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003373{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003374 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003375 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003376 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003377 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003378}
Jamie Madillc29968b2016-01-20 11:17:23 -05003379
Geoff Langa8cb2872018-03-09 16:09:40 -05003380Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003381{
3382 return mGLState.syncDirtyObjects(this);
3383}
3384
Geoff Langa8cb2872018-03-09 16:09:40 -05003385Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003386{
3387 return mGLState.syncDirtyObjects(this, objectMask);
3388}
3389
Jamie Madillc29968b2016-01-20 11:17:23 -05003390void Context::blitFramebuffer(GLint srcX0,
3391 GLint srcY0,
3392 GLint srcX1,
3393 GLint srcY1,
3394 GLint dstX0,
3395 GLint dstY0,
3396 GLint dstX1,
3397 GLint dstY1,
3398 GLbitfield mask,
3399 GLenum filter)
3400{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003401 if (mask == 0)
3402 {
3403 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3404 // buffers are copied.
3405 return;
3406 }
3407
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003408 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003409 ASSERT(drawFramebuffer);
3410
3411 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3412 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3413
Jamie Madillbc918e72018-03-08 09:47:21 -05003414 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003415
Jamie Madillc564c072017-06-01 12:45:42 -04003416 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003417}
Jamie Madillc29968b2016-01-20 11:17:23 -05003418
3419void Context::clear(GLbitfield mask)
3420{
Geoff Langd4fff502017-09-22 11:28:28 -04003421 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3422 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003423}
3424
3425void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3426{
Geoff Langd4fff502017-09-22 11:28:28 -04003427 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3428 ANGLE_CONTEXT_TRY(
3429 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003430}
3431
3432void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3433{
Geoff Langd4fff502017-09-22 11:28:28 -04003434 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3435 ANGLE_CONTEXT_TRY(
3436 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003437}
3438
3439void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3440{
Geoff Langd4fff502017-09-22 11:28:28 -04003441 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3442 ANGLE_CONTEXT_TRY(
3443 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003444}
3445
3446void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003448 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003449 ASSERT(framebufferObject);
3450
3451 // If a buffer is not present, the clear has no effect
3452 if (framebufferObject->getDepthbuffer() == nullptr &&
3453 framebufferObject->getStencilbuffer() == nullptr)
3454 {
3455 return;
3456 }
3457
Geoff Langd4fff502017-09-22 11:28:28 -04003458 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3459 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003460}
3461
3462void Context::readPixels(GLint x,
3463 GLint y,
3464 GLsizei width,
3465 GLsizei height,
3466 GLenum format,
3467 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003468 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003469{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003470 if (width == 0 || height == 0)
3471 {
3472 return;
3473 }
3474
Jamie Madillbc918e72018-03-08 09:47:21 -05003475 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003476
Jamie Madillb6664922017-07-25 12:55:04 -04003477 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3478 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003479
3480 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003481 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003482}
3483
Brandon Jones59770802018-04-02 13:18:42 -07003484void Context::readPixelsRobust(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 *pixels)
3495{
3496 readPixels(x, y, width, height, format, type, pixels);
3497}
3498
3499void Context::readnPixelsRobust(GLint x,
3500 GLint y,
3501 GLsizei width,
3502 GLsizei height,
3503 GLenum format,
3504 GLenum type,
3505 GLsizei bufSize,
3506 GLsizei *length,
3507 GLsizei *columns,
3508 GLsizei *rows,
3509 void *data)
3510{
3511 readPixels(x, y, width, height, format, type, data);
3512}
3513
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003514void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003515 GLint level,
3516 GLenum internalformat,
3517 GLint x,
3518 GLint y,
3519 GLsizei width,
3520 GLsizei height,
3521 GLint border)
3522{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003523 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003524 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003525
Jamie Madillc29968b2016-01-20 11:17:23 -05003526 Rectangle sourceArea(x, y, width, height);
3527
Jamie Madill05b35b22017-10-03 09:01:44 -04003528 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003529 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003530 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003531}
3532
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003533void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003534 GLint level,
3535 GLint xoffset,
3536 GLint yoffset,
3537 GLint x,
3538 GLint y,
3539 GLsizei width,
3540 GLsizei height)
3541{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003542 if (width == 0 || height == 0)
3543 {
3544 return;
3545 }
3546
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003547 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003548 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003549
Jamie Madillc29968b2016-01-20 11:17:23 -05003550 Offset destOffset(xoffset, yoffset, 0);
3551 Rectangle sourceArea(x, y, width, height);
3552
Jamie Madill05b35b22017-10-03 09:01:44 -04003553 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003554 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003555 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003556}
3557
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003558void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003559 GLint level,
3560 GLint xoffset,
3561 GLint yoffset,
3562 GLint zoffset,
3563 GLint x,
3564 GLint y,
3565 GLsizei width,
3566 GLsizei height)
3567{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003568 if (width == 0 || height == 0)
3569 {
3570 return;
3571 }
3572
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003573 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003574 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003575
Jamie Madillc29968b2016-01-20 11:17:23 -05003576 Offset destOffset(xoffset, yoffset, zoffset);
3577 Rectangle sourceArea(x, y, width, height);
3578
Jamie Madill05b35b22017-10-03 09:01:44 -04003579 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3580 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003581 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3582 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003583}
3584
3585void Context::framebufferTexture2D(GLenum target,
3586 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003587 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003588 GLuint texture,
3589 GLint level)
3590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 ASSERT(framebuffer);
3593
3594 if (texture != 0)
3595 {
3596 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003597 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003598 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 }
3600 else
3601 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003602 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003603 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003604
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003606}
3607
3608void Context::framebufferRenderbuffer(GLenum target,
3609 GLenum attachment,
3610 GLenum renderbuffertarget,
3611 GLuint renderbuffer)
3612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003614 ASSERT(framebuffer);
3615
3616 if (renderbuffer != 0)
3617 {
3618 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003619
Jamie Madillcc129372018-04-12 09:13:18 -04003620 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003621 renderbufferObject);
3622 }
3623 else
3624 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003625 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003627
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003629}
3630
3631void Context::framebufferTextureLayer(GLenum target,
3632 GLenum attachment,
3633 GLuint texture,
3634 GLint level,
3635 GLint layer)
3636{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003637 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003638 ASSERT(framebuffer);
3639
3640 if (texture != 0)
3641 {
3642 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003643 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003644 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003645 }
3646 else
3647 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003648 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003649 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003650
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003652}
3653
Brandon Jones59770802018-04-02 13:18:42 -07003654void Context::framebufferTextureMultiviewLayered(GLenum target,
3655 GLenum attachment,
3656 GLuint texture,
3657 GLint level,
3658 GLint baseViewIndex,
3659 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003660{
Martin Radev82ef7742017-08-08 17:44:58 +03003661 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3662 ASSERT(framebuffer);
3663
3664 if (texture != 0)
3665 {
3666 Texture *textureObj = getTexture(texture);
3667
Martin Radev18b75ba2017-08-15 15:50:40 +03003668 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003669 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3670 numViews, baseViewIndex);
3671 }
3672 else
3673 {
3674 framebuffer->resetAttachment(this, attachment);
3675 }
3676
3677 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003678}
3679
Brandon Jones59770802018-04-02 13:18:42 -07003680void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3681 GLenum attachment,
3682 GLuint texture,
3683 GLint level,
3684 GLsizei numViews,
3685 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003686{
Martin Radev5dae57b2017-07-14 16:15:55 +03003687 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3688 ASSERT(framebuffer);
3689
3690 if (texture != 0)
3691 {
3692 Texture *textureObj = getTexture(texture);
3693
3694 ImageIndex index = ImageIndex::Make2D(level);
3695 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3696 textureObj, numViews, viewportOffsets);
3697 }
3698 else
3699 {
3700 framebuffer->resetAttachment(this, attachment);
3701 }
3702
3703 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003704}
3705
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003706void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3707{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003708 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3709 ASSERT(framebuffer);
3710
3711 if (texture != 0)
3712 {
3713 Texture *textureObj = getTexture(texture);
3714
3715 ImageIndex index = ImageIndex::MakeFromType(
3716 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3717 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3718 }
3719 else
3720 {
3721 framebuffer->resetAttachment(this, attachment);
3722 }
3723
3724 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003725}
3726
Jamie Madillc29968b2016-01-20 11:17:23 -05003727void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3728{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003730 ASSERT(framebuffer);
3731 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003733}
3734
3735void Context::readBuffer(GLenum mode)
3736{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003740}
3741
3742void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3743{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003744 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003745 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003746
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003748 ASSERT(framebuffer);
3749
3750 // The specification isn't clear what should be done when the framebuffer isn't complete.
3751 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003752 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003753}
3754
3755void Context::invalidateFramebuffer(GLenum target,
3756 GLsizei numAttachments,
3757 const GLenum *attachments)
3758{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003759 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003760 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003761
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003762 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003763 ASSERT(framebuffer);
3764
Jamie Madill427064d2018-04-13 16:20:34 -04003765 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 {
Jamie Madill437fa652016-05-03 15:13:24 -04003767 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003768 }
Jamie Madill437fa652016-05-03 15:13:24 -04003769
Jamie Madill4928b7c2017-06-20 12:57:39 -04003770 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003771}
3772
3773void Context::invalidateSubFramebuffer(GLenum target,
3774 GLsizei numAttachments,
3775 const GLenum *attachments,
3776 GLint x,
3777 GLint y,
3778 GLsizei width,
3779 GLsizei height)
3780{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003781 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003782 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003783
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003784 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003785 ASSERT(framebuffer);
3786
Jamie Madill427064d2018-04-13 16:20:34 -04003787 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 {
Jamie Madill437fa652016-05-03 15:13:24 -04003789 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 }
Jamie Madill437fa652016-05-03 15:13:24 -04003791
3792 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003793 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003794}
3795
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003796void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003797 GLint level,
3798 GLint internalformat,
3799 GLsizei width,
3800 GLsizei height,
3801 GLint border,
3802 GLenum format,
3803 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003804 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003805{
Jamie Madillbc918e72018-03-08 09:47:21 -05003806 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003807
3808 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003809 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003810 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3811 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003812}
3813
Brandon Jones59770802018-04-02 13:18:42 -07003814void Context::texImage2DRobust(TextureTarget target,
3815 GLint level,
3816 GLint internalformat,
3817 GLsizei width,
3818 GLsizei height,
3819 GLint border,
3820 GLenum format,
3821 GLenum type,
3822 GLsizei bufSize,
3823 const void *pixels)
3824{
3825 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3826}
3827
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003828void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003829 GLint level,
3830 GLint internalformat,
3831 GLsizei width,
3832 GLsizei height,
3833 GLsizei depth,
3834 GLint border,
3835 GLenum format,
3836 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003837 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003838{
Jamie Madillbc918e72018-03-08 09:47:21 -05003839 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003840
3841 Extents size(width, height, depth);
3842 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003843 handleError(texture->setImage(this, mGLState.getUnpackState(),
3844 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3845 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003846}
3847
Brandon Jones59770802018-04-02 13:18:42 -07003848void Context::texImage3DRobust(TextureType target,
3849 GLint level,
3850 GLint internalformat,
3851 GLsizei width,
3852 GLsizei height,
3853 GLsizei depth,
3854 GLint border,
3855 GLenum format,
3856 GLenum type,
3857 GLsizei bufSize,
3858 const void *pixels)
3859{
3860 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3861}
3862
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003863void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003864 GLint level,
3865 GLint xoffset,
3866 GLint yoffset,
3867 GLsizei width,
3868 GLsizei height,
3869 GLenum format,
3870 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003871 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003872{
3873 // Zero sized uploads are valid but no-ops
3874 if (width == 0 || height == 0)
3875 {
3876 return;
3877 }
3878
Jamie Madillbc918e72018-03-08 09:47:21 -05003879 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003880
3881 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003882 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003883 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3884 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003885}
3886
Brandon Jones59770802018-04-02 13:18:42 -07003887void Context::texSubImage2DRobust(TextureTarget target,
3888 GLint level,
3889 GLint xoffset,
3890 GLint yoffset,
3891 GLsizei width,
3892 GLsizei height,
3893 GLenum format,
3894 GLenum type,
3895 GLsizei bufSize,
3896 const void *pixels)
3897{
3898 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3899}
3900
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003901void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003902 GLint level,
3903 GLint xoffset,
3904 GLint yoffset,
3905 GLint zoffset,
3906 GLsizei width,
3907 GLsizei height,
3908 GLsizei depth,
3909 GLenum format,
3910 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003911 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003912{
3913 // Zero sized uploads are valid but no-ops
3914 if (width == 0 || height == 0 || depth == 0)
3915 {
3916 return;
3917 }
3918
Jamie Madillbc918e72018-03-08 09:47:21 -05003919 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003920
3921 Box area(xoffset, yoffset, zoffset, width, height, depth);
3922 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003923 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3924 NonCubeTextureTypeToTarget(target), level, area, format, type,
3925 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003926}
3927
Brandon Jones59770802018-04-02 13:18:42 -07003928void Context::texSubImage3DRobust(TextureType target,
3929 GLint level,
3930 GLint xoffset,
3931 GLint yoffset,
3932 GLint zoffset,
3933 GLsizei width,
3934 GLsizei height,
3935 GLsizei depth,
3936 GLenum format,
3937 GLenum type,
3938 GLsizei bufSize,
3939 const void *pixels)
3940{
3941 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3942 pixels);
3943}
3944
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003945void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003946 GLint level,
3947 GLenum internalformat,
3948 GLsizei width,
3949 GLsizei height,
3950 GLint border,
3951 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003952 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003953{
Jamie Madillbc918e72018-03-08 09:47:21 -05003954 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003955
3956 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003957 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003958 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3959 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003960 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003961}
3962
Brandon Jones59770802018-04-02 13:18:42 -07003963void Context::compressedTexImage2DRobust(TextureTarget target,
3964 GLint level,
3965 GLenum internalformat,
3966 GLsizei width,
3967 GLsizei height,
3968 GLint border,
3969 GLsizei imageSize,
3970 GLsizei dataSize,
3971 const GLvoid *data)
3972{
3973 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3974}
3975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003976void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003977 GLint level,
3978 GLenum internalformat,
3979 GLsizei width,
3980 GLsizei height,
3981 GLsizei depth,
3982 GLint border,
3983 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
Jamie Madillbc918e72018-03-08 09:47:21 -05003986 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003987
3988 Extents size(width, height, depth);
3989 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003990 handleError(texture->setCompressedImage(
3991 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3992 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003993}
3994
Brandon Jones59770802018-04-02 13:18:42 -07003995void Context::compressedTexImage3DRobust(TextureType target,
3996 GLint level,
3997 GLenum internalformat,
3998 GLsizei width,
3999 GLsizei height,
4000 GLsizei depth,
4001 GLint border,
4002 GLsizei imageSize,
4003 GLsizei dataSize,
4004 const GLvoid *data)
4005{
4006 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4007 data);
4008}
4009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004011 GLint level,
4012 GLint xoffset,
4013 GLint yoffset,
4014 GLsizei width,
4015 GLsizei height,
4016 GLenum format,
4017 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004018 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004019{
Jamie Madillbc918e72018-03-08 09:47:21 -05004020 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004021
4022 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004023 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004024 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4025 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004026 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004027}
4028
Brandon Jones59770802018-04-02 13:18:42 -07004029void Context::compressedTexSubImage2DRobust(TextureTarget target,
4030 GLint level,
4031 GLint xoffset,
4032 GLint yoffset,
4033 GLsizei width,
4034 GLsizei height,
4035 GLenum format,
4036 GLsizei imageSize,
4037 GLsizei dataSize,
4038 const GLvoid *data)
4039{
4040 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4041 data);
4042}
4043
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004044void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004045 GLint level,
4046 GLint xoffset,
4047 GLint yoffset,
4048 GLint zoffset,
4049 GLsizei width,
4050 GLsizei height,
4051 GLsizei depth,
4052 GLenum format,
4053 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004054 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004055{
4056 // Zero sized uploads are valid but no-ops
4057 if (width == 0 || height == 0)
4058 {
4059 return;
4060 }
4061
Jamie Madillbc918e72018-03-08 09:47:21 -05004062 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004063
4064 Box area(xoffset, yoffset, zoffset, width, height, depth);
4065 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004066 handleError(texture->setCompressedSubImage(
4067 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4068 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004069}
4070
Brandon Jones59770802018-04-02 13:18:42 -07004071void Context::compressedTexSubImage3DRobust(TextureType target,
4072 GLint level,
4073 GLint xoffset,
4074 GLint yoffset,
4075 GLint zoffset,
4076 GLsizei width,
4077 GLsizei height,
4078 GLsizei depth,
4079 GLenum format,
4080 GLsizei imageSize,
4081 GLsizei dataSize,
4082 const GLvoid *data)
4083{
4084 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4085 imageSize, data);
4086}
4087
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004088void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004089{
4090 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004091 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004092}
4093
Jamie Madill007530e2017-12-28 14:27:04 -05004094void Context::copyTexture(GLuint sourceId,
4095 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004096 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004097 GLuint destId,
4098 GLint destLevel,
4099 GLint internalFormat,
4100 GLenum destType,
4101 GLboolean unpackFlipY,
4102 GLboolean unpackPremultiplyAlpha,
4103 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004104{
Jamie Madillbc918e72018-03-08 09:47:21 -05004105 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004106
4107 gl::Texture *sourceTexture = getTexture(sourceId);
4108 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004109 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4110 sourceLevel, ConvertToBool(unpackFlipY),
4111 ConvertToBool(unpackPremultiplyAlpha),
4112 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004113}
4114
Jamie Madill007530e2017-12-28 14:27:04 -05004115void Context::copySubTexture(GLuint sourceId,
4116 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004117 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004118 GLuint destId,
4119 GLint destLevel,
4120 GLint xoffset,
4121 GLint yoffset,
4122 GLint x,
4123 GLint y,
4124 GLsizei width,
4125 GLsizei height,
4126 GLboolean unpackFlipY,
4127 GLboolean unpackPremultiplyAlpha,
4128 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004129{
4130 // Zero sized copies are valid but no-ops
4131 if (width == 0 || height == 0)
4132 {
4133 return;
4134 }
4135
Jamie Madillbc918e72018-03-08 09:47:21 -05004136 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004137
4138 gl::Texture *sourceTexture = getTexture(sourceId);
4139 gl::Texture *destTexture = getTexture(destId);
4140 Offset offset(xoffset, yoffset, 0);
4141 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004142 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4143 ConvertToBool(unpackFlipY),
4144 ConvertToBool(unpackPremultiplyAlpha),
4145 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004146}
4147
Jamie Madill007530e2017-12-28 14:27:04 -05004148void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004149{
Jamie Madillbc918e72018-03-08 09:47:21 -05004150 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004151
4152 gl::Texture *sourceTexture = getTexture(sourceId);
4153 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004154 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004155}
4156
Corentin Wallez336129f2017-10-17 15:55:40 -04004157void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004158{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004159 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004160 ASSERT(buffer);
4161
Geoff Lang496c02d2016-10-20 11:38:11 -07004162 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004163}
4164
Brandon Jones59770802018-04-02 13:18:42 -07004165void Context::getBufferPointervRobust(BufferBinding target,
4166 GLenum pname,
4167 GLsizei bufSize,
4168 GLsizei *length,
4169 void **params)
4170{
4171 getBufferPointerv(target, pname, params);
4172}
4173
Corentin Wallez336129f2017-10-17 15:55:40 -04004174void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004175{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004176 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004177 ASSERT(buffer);
4178
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004179 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 if (error.isError())
4181 {
Jamie Madill437fa652016-05-03 15:13:24 -04004182 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 return nullptr;
4184 }
4185
4186 return buffer->getMapPointer();
4187}
4188
Corentin Wallez336129f2017-10-17 15:55:40 -04004189GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004190{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004191 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004192 ASSERT(buffer);
4193
4194 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004195 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004196 if (error.isError())
4197 {
Jamie Madill437fa652016-05-03 15:13:24 -04004198 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004199 return GL_FALSE;
4200 }
4201
4202 return result;
4203}
4204
Corentin Wallez336129f2017-10-17 15:55:40 -04004205void *Context::mapBufferRange(BufferBinding target,
4206 GLintptr offset,
4207 GLsizeiptr length,
4208 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004209{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004210 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004211 ASSERT(buffer);
4212
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004213 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004214 if (error.isError())
4215 {
Jamie Madill437fa652016-05-03 15:13:24 -04004216 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004217 return nullptr;
4218 }
4219
4220 return buffer->getMapPointer();
4221}
4222
Corentin Wallez336129f2017-10-17 15:55:40 -04004223void Context::flushMappedBufferRange(BufferBinding /*target*/,
4224 GLintptr /*offset*/,
4225 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004226{
4227 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4228}
4229
Jamie Madillbc918e72018-03-08 09:47:21 -05004230Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004231{
Geoff Langa8cb2872018-03-09 16:09:40 -05004232 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004233}
4234
Jamie Madillbc918e72018-03-08 09:47:21 -05004235Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004236{
Geoff Langa8cb2872018-03-09 16:09:40 -05004237 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004238}
4239
Jamie Madillbc918e72018-03-08 09:47:21 -05004240Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004241{
Geoff Langa8cb2872018-03-09 16:09:40 -05004242 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004243}
4244
Jiajia Qin5451d532017-11-16 17:16:34 +08004245void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4246{
4247 UNIMPLEMENTED();
4248}
4249
Jamie Madillc20ab272016-06-09 07:20:46 -07004250void Context::activeTexture(GLenum texture)
4251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004252 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004253}
4254
Jamie Madill876429b2017-04-20 15:46:24 -04004255void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004256{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004257 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004258}
4259
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004260void Context::blendEquation(GLenum mode)
4261{
4262 mGLState.setBlendEquation(mode, mode);
4263}
4264
Jamie Madillc20ab272016-06-09 07:20:46 -07004265void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004267 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004268}
4269
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004270void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4271{
4272 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4273}
4274
Jamie Madillc20ab272016-06-09 07:20:46 -07004275void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4276{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004278}
4279
Jamie Madill876429b2017-04-20 15:46:24 -04004280void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004281{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004282 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004283}
4284
Jamie Madill876429b2017-04-20 15:46:24 -04004285void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004286{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004287 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004288}
4289
4290void Context::clearStencil(GLint s)
4291{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004292 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004293}
4294
4295void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4296{
Geoff Lang92019432017-11-20 13:09:34 -05004297 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4298 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004299}
4300
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004301void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004302{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004303 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004304}
4305
4306void Context::depthFunc(GLenum func)
4307{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309}
4310
4311void Context::depthMask(GLboolean flag)
4312{
Geoff Lang92019432017-11-20 13:09:34 -05004313 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004314}
4315
Jamie Madill876429b2017-04-20 15:46:24 -04004316void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004317{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004319}
4320
4321void Context::disable(GLenum cap)
4322{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324}
4325
4326void Context::disableVertexAttribArray(GLuint index)
4327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329}
4330
4331void Context::enable(GLenum cap)
4332{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004333 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004334}
4335
4336void Context::enableVertexAttribArray(GLuint index)
4337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339}
4340
4341void Context::frontFace(GLenum mode)
4342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344}
4345
4346void Context::hint(GLenum target, GLenum mode)
4347{
4348 switch (target)
4349 {
4350 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352 break;
4353
4354 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356 break;
4357
4358 default:
4359 UNREACHABLE();
4360 return;
4361 }
4362}
4363
4364void Context::lineWidth(GLfloat width)
4365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367}
4368
4369void Context::pixelStorei(GLenum pname, GLint param)
4370{
4371 switch (pname)
4372 {
4373 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004375 break;
4376
4377 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379 break;
4380
4381 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383 break;
4384
4385 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004386 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004388 break;
4389
4390 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004391 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393 break;
4394
4395 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004396 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398 break;
4399
4400 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004401 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403 break;
4404
4405 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004406 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408 break;
4409
4410 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004411 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413 break;
4414
4415 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004416 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418 break;
4419
4420 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004421 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004422 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004423 break;
4424
4425 default:
4426 UNREACHABLE();
4427 return;
4428 }
4429}
4430
4431void Context::polygonOffset(GLfloat factor, GLfloat units)
4432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
Jamie Madill876429b2017-04-20 15:46:24 -04004436void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004437{
Geoff Lang92019432017-11-20 13:09:34 -05004438 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004439}
4440
Jiawei Shaodb342272017-09-27 10:21:45 +08004441void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4442{
4443 mGLState.setSampleMaskParams(maskNumber, mask);
4444}
4445
Jamie Madillc20ab272016-06-09 07:20:46 -07004446void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449}
4450
4451void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4452{
4453 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4454 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456 }
4457
4458 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4459 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461 }
4462}
4463
4464void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4465{
4466 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4467 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004469 }
4470
4471 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4472 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004473 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004474 }
4475}
4476
4477void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4478{
4479 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4480 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482 }
4483
4484 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4485 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 }
4488}
4489
4490void Context::vertexAttrib1f(GLuint index, GLfloat x)
4491{
4492 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494}
4495
4496void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4497{
4498 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004499 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004500}
4501
4502void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4503{
4504 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004505 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
4508void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4509{
4510 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4515{
4516 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
4520void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4521{
4522 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524}
4525
4526void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4527{
4528 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530}
4531
4532void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4533{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535}
4536
4537void Context::vertexAttribPointer(GLuint index,
4538 GLint size,
4539 GLenum type,
4540 GLboolean normalized,
4541 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004542 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004543{
Corentin Wallez336129f2017-10-17 15:55:40 -04004544 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004545 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546}
4547
Shao80957d92017-02-20 21:25:59 +08004548void Context::vertexAttribFormat(GLuint attribIndex,
4549 GLint size,
4550 GLenum type,
4551 GLboolean normalized,
4552 GLuint relativeOffset)
4553{
Geoff Lang92019432017-11-20 13:09:34 -05004554 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004555 relativeOffset);
4556}
4557
4558void Context::vertexAttribIFormat(GLuint attribIndex,
4559 GLint size,
4560 GLenum type,
4561 GLuint relativeOffset)
4562{
4563 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4564}
4565
4566void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4567{
Shaodde78e82017-05-22 14:13:27 +08004568 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004569}
4570
Jiajia Qin5451d532017-11-16 17:16:34 +08004571void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004572{
4573 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4574}
4575
Jamie Madillc20ab272016-06-09 07:20:46 -07004576void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::vertexAttribIPointer(GLuint index,
4582 GLint size,
4583 GLenum type,
4584 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004585 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004586{
Corentin Wallez336129f2017-10-17 15:55:40 -04004587 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4588 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004589}
4590
4591void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4592{
4593 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004594 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004595}
4596
4597void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4598{
4599 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004600 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
4603void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004606}
4607
4608void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004613void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4614{
4615 const VertexAttribCurrentValueData &currentValues =
4616 getGLState().getVertexAttribCurrentValue(index);
4617 const VertexArray *vao = getGLState().getVertexArray();
4618 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4619 currentValues, pname, params);
4620}
4621
Brandon Jones59770802018-04-02 13:18:42 -07004622void Context::getVertexAttribivRobust(GLuint index,
4623 GLenum pname,
4624 GLsizei bufSize,
4625 GLsizei *length,
4626 GLint *params)
4627{
4628 getVertexAttribiv(index, pname, params);
4629}
4630
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004631void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4632{
4633 const VertexAttribCurrentValueData &currentValues =
4634 getGLState().getVertexAttribCurrentValue(index);
4635 const VertexArray *vao = getGLState().getVertexArray();
4636 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4637 currentValues, pname, params);
4638}
4639
Brandon Jones59770802018-04-02 13:18:42 -07004640void Context::getVertexAttribfvRobust(GLuint index,
4641 GLenum pname,
4642 GLsizei bufSize,
4643 GLsizei *length,
4644 GLfloat *params)
4645{
4646 getVertexAttribfv(index, pname, params);
4647}
4648
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004649void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4650{
4651 const VertexAttribCurrentValueData &currentValues =
4652 getGLState().getVertexAttribCurrentValue(index);
4653 const VertexArray *vao = getGLState().getVertexArray();
4654 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4655 currentValues, pname, params);
4656}
4657
Brandon Jones59770802018-04-02 13:18:42 -07004658void Context::getVertexAttribIivRobust(GLuint index,
4659 GLenum pname,
4660 GLsizei bufSize,
4661 GLsizei *length,
4662 GLint *params)
4663{
4664 getVertexAttribIiv(index, pname, params);
4665}
4666
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004667void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4668{
4669 const VertexAttribCurrentValueData &currentValues =
4670 getGLState().getVertexAttribCurrentValue(index);
4671 const VertexArray *vao = getGLState().getVertexArray();
4672 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4673 currentValues, pname, params);
4674}
4675
Brandon Jones59770802018-04-02 13:18:42 -07004676void Context::getVertexAttribIuivRobust(GLuint index,
4677 GLenum pname,
4678 GLsizei bufSize,
4679 GLsizei *length,
4680 GLuint *params)
4681{
4682 getVertexAttribIuiv(index, pname, params);
4683}
4684
Jamie Madill876429b2017-04-20 15:46:24 -04004685void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004686{
4687 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4688 QueryVertexAttribPointerv(attrib, pname, pointer);
4689}
4690
Brandon Jones59770802018-04-02 13:18:42 -07004691void Context::getVertexAttribPointervRobust(GLuint index,
4692 GLenum pname,
4693 GLsizei bufSize,
4694 GLsizei *length,
4695 void **pointer)
4696{
4697 getVertexAttribPointerv(index, pname, pointer);
4698}
4699
Jamie Madillc20ab272016-06-09 07:20:46 -07004700void Context::debugMessageControl(GLenum source,
4701 GLenum type,
4702 GLenum severity,
4703 GLsizei count,
4704 const GLuint *ids,
4705 GLboolean enabled)
4706{
4707 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004708 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004709 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004710}
4711
4712void Context::debugMessageInsert(GLenum source,
4713 GLenum type,
4714 GLuint id,
4715 GLenum severity,
4716 GLsizei length,
4717 const GLchar *buf)
4718{
4719 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004720 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004721}
4722
4723void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004725 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004726}
4727
4728GLuint Context::getDebugMessageLog(GLuint count,
4729 GLsizei bufSize,
4730 GLenum *sources,
4731 GLenum *types,
4732 GLuint *ids,
4733 GLenum *severities,
4734 GLsizei *lengths,
4735 GLchar *messageLog)
4736{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004737 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4738 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004739}
4740
4741void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4742{
4743 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004744 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004745 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748void Context::popDebugGroup()
4749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004750 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004751 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004752}
4753
Corentin Wallez336129f2017-10-17 15:55:40 -04004754void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004755{
4756 Buffer *buffer = mGLState.getTargetBuffer(target);
4757 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004758 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004759}
4760
Corentin Wallez336129f2017-10-17 15:55:40 -04004761void Context::bufferSubData(BufferBinding target,
4762 GLintptr offset,
4763 GLsizeiptr size,
4764 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004765{
4766 if (data == nullptr)
4767 {
4768 return;
4769 }
4770
4771 Buffer *buffer = mGLState.getTargetBuffer(target);
4772 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004773 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004774}
4775
Jamie Madillef300b12016-10-07 15:12:09 -04004776void Context::attachShader(GLuint program, GLuint shader)
4777{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004778 Program *programObject = mState.mShaderPrograms->getProgram(program);
4779 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004780 ASSERT(programObject && shaderObject);
4781 programObject->attachShader(shaderObject);
4782}
4783
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004784const Workarounds &Context::getWorkarounds() const
4785{
4786 return mWorkarounds;
4787}
4788
Corentin Wallez336129f2017-10-17 15:55:40 -04004789void Context::copyBufferSubData(BufferBinding readTarget,
4790 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004791 GLintptr readOffset,
4792 GLintptr writeOffset,
4793 GLsizeiptr size)
4794{
4795 // if size is zero, the copy is a successful no-op
4796 if (size == 0)
4797 {
4798 return;
4799 }
4800
4801 // TODO(jmadill): cache these.
4802 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4803 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4804
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004805 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004806}
4807
Jamie Madill01a80ee2016-11-07 12:06:18 -05004808void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4809{
4810 Program *programObject = getProgram(program);
4811 // TODO(jmadill): Re-use this from the validation if possible.
4812 ASSERT(programObject);
4813 programObject->bindAttributeLocation(index, name);
4814}
4815
Corentin Wallez336129f2017-10-17 15:55:40 -04004816void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004817{
Corentin Wallez336129f2017-10-17 15:55:40 -04004818 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4819 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004820}
4821
Corentin Wallez336129f2017-10-17 15:55:40 -04004822void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004823{
4824 bindBufferRange(target, index, buffer, 0, 0);
4825}
4826
Corentin Wallez336129f2017-10-17 15:55:40 -04004827void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004828 GLuint index,
4829 GLuint buffer,
4830 GLintptr offset,
4831 GLsizeiptr size)
4832{
Corentin Wallez336129f2017-10-17 15:55:40 -04004833 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4834 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004835}
4836
Jamie Madill01a80ee2016-11-07 12:06:18 -05004837void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4838{
4839 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4840 {
4841 bindReadFramebuffer(framebuffer);
4842 }
4843
4844 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4845 {
4846 bindDrawFramebuffer(framebuffer);
4847 }
4848}
4849
4850void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4851{
4852 ASSERT(target == GL_RENDERBUFFER);
4853 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004854 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004855 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004856}
4857
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004858void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004859 GLsizei samples,
4860 GLenum internalformat,
4861 GLsizei width,
4862 GLsizei height,
4863 GLboolean fixedsamplelocations)
4864{
4865 Extents size(width, height, 1);
4866 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004867 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4868 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004869}
4870
4871void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4872{
JiangYizhou5b03f472017-01-09 10:22:53 +08004873 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4874 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004875 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004876 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004877
4878 switch (pname)
4879 {
4880 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004881 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004882 break;
4883 default:
4884 UNREACHABLE();
4885 }
4886}
4887
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004888void Context::getMultisamplefvRobust(GLenum pname,
4889 GLuint index,
4890 GLsizei bufSize,
4891 GLsizei *length,
4892 GLfloat *val)
4893{
4894 UNIMPLEMENTED();
4895}
4896
Jamie Madille8fb6402017-02-14 17:56:40 -05004897void Context::renderbufferStorage(GLenum target,
4898 GLenum internalformat,
4899 GLsizei width,
4900 GLsizei height)
4901{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004902 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4903 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4904
Jamie Madille8fb6402017-02-14 17:56:40 -05004905 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004906 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004907}
4908
4909void Context::renderbufferStorageMultisample(GLenum target,
4910 GLsizei samples,
4911 GLenum internalformat,
4912 GLsizei width,
4913 GLsizei height)
4914{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004915 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4916 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004917
4918 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004919 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004920 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004921}
4922
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004923void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4924{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004925 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004926 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004927}
4928
JiangYizhoue18e6392017-02-20 10:32:23 +08004929void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4930{
4931 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4932 QueryFramebufferParameteriv(framebuffer, pname, params);
4933}
4934
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004935void Context::getFramebufferParameterivRobust(GLenum target,
4936 GLenum pname,
4937 GLsizei bufSize,
4938 GLsizei *length,
4939 GLint *params)
4940{
4941 UNIMPLEMENTED();
4942}
4943
Jiajia Qin5451d532017-11-16 17:16:34 +08004944void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004945{
4946 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4947 SetFramebufferParameteri(framebuffer, pname, param);
4948}
4949
Jamie Madillb3f26b92017-07-19 15:07:41 -04004950Error Context::getScratchBuffer(size_t requstedSizeBytes,
4951 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004952{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004953 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4954 {
4955 return OutOfMemory() << "Failed to allocate internal buffer.";
4956 }
4957 return NoError();
4958}
4959
4960Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4961 angle::MemoryBuffer **zeroBufferOut) const
4962{
4963 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004964 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004965 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004966 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004967 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004968}
4969
Xinghua Cao10a4d432017-11-28 14:46:26 +08004970Error Context::prepareForDispatch()
4971{
Geoff Langa8cb2872018-03-09 16:09:40 -05004972 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004973
4974 if (isRobustResourceInitEnabled())
4975 {
4976 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4977 }
4978
4979 return NoError();
4980}
4981
Xinghua Cao2b396592017-03-29 15:36:04 +08004982void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4983{
4984 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4985 {
4986 return;
4987 }
4988
Xinghua Cao10a4d432017-11-28 14:46:26 +08004989 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004990 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004991}
4992
Jiajia Qin5451d532017-11-16 17:16:34 +08004993void Context::dispatchComputeIndirect(GLintptr indirect)
4994{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004995 ANGLE_CONTEXT_TRY(prepareForDispatch());
4996 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004997}
4998
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004999void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005000 GLsizei levels,
5001 GLenum internalFormat,
5002 GLsizei width,
5003 GLsizei height)
5004{
5005 Extents size(width, height, 1);
5006 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005007 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005008}
5009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005010void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005011 GLsizei levels,
5012 GLenum internalFormat,
5013 GLsizei width,
5014 GLsizei height,
5015 GLsizei depth)
5016{
5017 Extents size(width, height, depth);
5018 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005019 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005020}
5021
Jiajia Qin5451d532017-11-16 17:16:34 +08005022void Context::memoryBarrier(GLbitfield barriers)
5023{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005024 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005025}
5026
5027void Context::memoryBarrierByRegion(GLbitfield barriers)
5028{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005029 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005030}
5031
Jamie Madillc1d770e2017-04-13 17:31:24 -04005032GLenum Context::checkFramebufferStatus(GLenum target)
5033{
5034 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5035 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005036 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005037}
5038
5039void Context::compileShader(GLuint shader)
5040{
5041 Shader *shaderObject = GetValidShader(this, shader);
5042 if (!shaderObject)
5043 {
5044 return;
5045 }
5046 shaderObject->compile(this);
5047}
5048
5049void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5050{
5051 for (int i = 0; i < n; i++)
5052 {
5053 deleteBuffer(buffers[i]);
5054 }
5055}
5056
5057void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5058{
5059 for (int i = 0; i < n; i++)
5060 {
5061 if (framebuffers[i] != 0)
5062 {
5063 deleteFramebuffer(framebuffers[i]);
5064 }
5065 }
5066}
5067
5068void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5069{
5070 for (int i = 0; i < n; i++)
5071 {
5072 deleteRenderbuffer(renderbuffers[i]);
5073 }
5074}
5075
5076void Context::deleteTextures(GLsizei n, const GLuint *textures)
5077{
5078 for (int i = 0; i < n; i++)
5079 {
5080 if (textures[i] != 0)
5081 {
5082 deleteTexture(textures[i]);
5083 }
5084 }
5085}
5086
5087void Context::detachShader(GLuint program, GLuint shader)
5088{
5089 Program *programObject = getProgram(program);
5090 ASSERT(programObject);
5091
5092 Shader *shaderObject = getShader(shader);
5093 ASSERT(shaderObject);
5094
5095 programObject->detachShader(this, shaderObject);
5096}
5097
5098void Context::genBuffers(GLsizei n, GLuint *buffers)
5099{
5100 for (int i = 0; i < n; i++)
5101 {
5102 buffers[i] = createBuffer();
5103 }
5104}
5105
5106void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5107{
5108 for (int i = 0; i < n; i++)
5109 {
5110 framebuffers[i] = createFramebuffer();
5111 }
5112}
5113
5114void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5115{
5116 for (int i = 0; i < n; i++)
5117 {
5118 renderbuffers[i] = createRenderbuffer();
5119 }
5120}
5121
5122void Context::genTextures(GLsizei n, GLuint *textures)
5123{
5124 for (int i = 0; i < n; i++)
5125 {
5126 textures[i] = createTexture();
5127 }
5128}
5129
5130void Context::getActiveAttrib(GLuint program,
5131 GLuint index,
5132 GLsizei bufsize,
5133 GLsizei *length,
5134 GLint *size,
5135 GLenum *type,
5136 GLchar *name)
5137{
5138 Program *programObject = getProgram(program);
5139 ASSERT(programObject);
5140 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5141}
5142
5143void Context::getActiveUniform(GLuint program,
5144 GLuint index,
5145 GLsizei bufsize,
5146 GLsizei *length,
5147 GLint *size,
5148 GLenum *type,
5149 GLchar *name)
5150{
5151 Program *programObject = getProgram(program);
5152 ASSERT(programObject);
5153 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5154}
5155
5156void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5157{
5158 Program *programObject = getProgram(program);
5159 ASSERT(programObject);
5160 programObject->getAttachedShaders(maxcount, count, shaders);
5161}
5162
5163GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5164{
5165 Program *programObject = getProgram(program);
5166 ASSERT(programObject);
5167 return programObject->getAttributeLocation(name);
5168}
5169
5170void Context::getBooleanv(GLenum pname, GLboolean *params)
5171{
5172 GLenum nativeType;
5173 unsigned int numParams = 0;
5174 getQueryParameterInfo(pname, &nativeType, &numParams);
5175
5176 if (nativeType == GL_BOOL)
5177 {
5178 getBooleanvImpl(pname, params);
5179 }
5180 else
5181 {
5182 CastStateValues(this, nativeType, pname, numParams, params);
5183 }
5184}
5185
Brandon Jones59770802018-04-02 13:18:42 -07005186void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5187{
5188 getBooleanv(pname, params);
5189}
5190
Jamie Madillc1d770e2017-04-13 17:31:24 -04005191void Context::getFloatv(GLenum pname, GLfloat *params)
5192{
5193 GLenum nativeType;
5194 unsigned int numParams = 0;
5195 getQueryParameterInfo(pname, &nativeType, &numParams);
5196
5197 if (nativeType == GL_FLOAT)
5198 {
5199 getFloatvImpl(pname, params);
5200 }
5201 else
5202 {
5203 CastStateValues(this, nativeType, pname, numParams, params);
5204 }
5205}
5206
Brandon Jones59770802018-04-02 13:18:42 -07005207void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5208{
5209 getFloatv(pname, params);
5210}
5211
Jamie Madillc1d770e2017-04-13 17:31:24 -04005212void Context::getIntegerv(GLenum pname, GLint *params)
5213{
5214 GLenum nativeType;
5215 unsigned int numParams = 0;
5216 getQueryParameterInfo(pname, &nativeType, &numParams);
5217
5218 if (nativeType == GL_INT)
5219 {
5220 getIntegervImpl(pname, params);
5221 }
5222 else
5223 {
5224 CastStateValues(this, nativeType, pname, numParams, params);
5225 }
5226}
5227
Brandon Jones59770802018-04-02 13:18:42 -07005228void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5229{
5230 getIntegerv(pname, data);
5231}
5232
Jamie Madillc1d770e2017-04-13 17:31:24 -04005233void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5234{
5235 Program *programObject = getProgram(program);
5236 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005237 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238}
5239
Brandon Jones59770802018-04-02 13:18:42 -07005240void Context::getProgramivRobust(GLuint program,
5241 GLenum pname,
5242 GLsizei bufSize,
5243 GLsizei *length,
5244 GLint *params)
5245{
5246 getProgramiv(program, pname, params);
5247}
5248
Jiajia Qin5451d532017-11-16 17:16:34 +08005249void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5250{
5251 UNIMPLEMENTED();
5252}
5253
Jamie Madillbe849e42017-05-02 15:49:00 -04005254void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005255{
5256 Program *programObject = getProgram(program);
5257 ASSERT(programObject);
5258 programObject->getInfoLog(bufsize, length, infolog);
5259}
5260
Jiajia Qin5451d532017-11-16 17:16:34 +08005261void Context::getProgramPipelineInfoLog(GLuint pipeline,
5262 GLsizei bufSize,
5263 GLsizei *length,
5264 GLchar *infoLog)
5265{
5266 UNIMPLEMENTED();
5267}
5268
Jamie Madillc1d770e2017-04-13 17:31:24 -04005269void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5270{
5271 Shader *shaderObject = getShader(shader);
5272 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005273 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005274}
5275
Brandon Jones59770802018-04-02 13:18:42 -07005276void Context::getShaderivRobust(GLuint shader,
5277 GLenum pname,
5278 GLsizei bufSize,
5279 GLsizei *length,
5280 GLint *params)
5281{
5282 getShaderiv(shader, pname, params);
5283}
5284
Jamie Madillc1d770e2017-04-13 17:31:24 -04005285void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5286{
5287 Shader *shaderObject = getShader(shader);
5288 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005289 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005290}
5291
5292void Context::getShaderPrecisionFormat(GLenum shadertype,
5293 GLenum precisiontype,
5294 GLint *range,
5295 GLint *precision)
5296{
5297 // TODO(jmadill): Compute shaders.
5298
5299 switch (shadertype)
5300 {
5301 case GL_VERTEX_SHADER:
5302 switch (precisiontype)
5303 {
5304 case GL_LOW_FLOAT:
5305 mCaps.vertexLowpFloat.get(range, precision);
5306 break;
5307 case GL_MEDIUM_FLOAT:
5308 mCaps.vertexMediumpFloat.get(range, precision);
5309 break;
5310 case GL_HIGH_FLOAT:
5311 mCaps.vertexHighpFloat.get(range, precision);
5312 break;
5313
5314 case GL_LOW_INT:
5315 mCaps.vertexLowpInt.get(range, precision);
5316 break;
5317 case GL_MEDIUM_INT:
5318 mCaps.vertexMediumpInt.get(range, precision);
5319 break;
5320 case GL_HIGH_INT:
5321 mCaps.vertexHighpInt.get(range, precision);
5322 break;
5323
5324 default:
5325 UNREACHABLE();
5326 return;
5327 }
5328 break;
5329
5330 case GL_FRAGMENT_SHADER:
5331 switch (precisiontype)
5332 {
5333 case GL_LOW_FLOAT:
5334 mCaps.fragmentLowpFloat.get(range, precision);
5335 break;
5336 case GL_MEDIUM_FLOAT:
5337 mCaps.fragmentMediumpFloat.get(range, precision);
5338 break;
5339 case GL_HIGH_FLOAT:
5340 mCaps.fragmentHighpFloat.get(range, precision);
5341 break;
5342
5343 case GL_LOW_INT:
5344 mCaps.fragmentLowpInt.get(range, precision);
5345 break;
5346 case GL_MEDIUM_INT:
5347 mCaps.fragmentMediumpInt.get(range, precision);
5348 break;
5349 case GL_HIGH_INT:
5350 mCaps.fragmentHighpInt.get(range, precision);
5351 break;
5352
5353 default:
5354 UNREACHABLE();
5355 return;
5356 }
5357 break;
5358
5359 default:
5360 UNREACHABLE();
5361 return;
5362 }
5363}
5364
5365void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5366{
5367 Shader *shaderObject = getShader(shader);
5368 ASSERT(shaderObject);
5369 shaderObject->getSource(bufsize, length, source);
5370}
5371
5372void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5373{
5374 Program *programObject = getProgram(program);
5375 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005376 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005377}
5378
Brandon Jones59770802018-04-02 13:18:42 -07005379void Context::getUniformfvRobust(GLuint program,
5380 GLint location,
5381 GLsizei bufSize,
5382 GLsizei *length,
5383 GLfloat *params)
5384{
5385 getUniformfv(program, location, params);
5386}
5387
Jamie Madillc1d770e2017-04-13 17:31:24 -04005388void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5389{
5390 Program *programObject = getProgram(program);
5391 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005392 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005393}
5394
Brandon Jones59770802018-04-02 13:18:42 -07005395void Context::getUniformivRobust(GLuint program,
5396 GLint location,
5397 GLsizei bufSize,
5398 GLsizei *length,
5399 GLint *params)
5400{
5401 getUniformiv(program, location, params);
5402}
5403
Jamie Madillc1d770e2017-04-13 17:31:24 -04005404GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5405{
5406 Program *programObject = getProgram(program);
5407 ASSERT(programObject);
5408 return programObject->getUniformLocation(name);
5409}
5410
5411GLboolean Context::isBuffer(GLuint buffer)
5412{
5413 if (buffer == 0)
5414 {
5415 return GL_FALSE;
5416 }
5417
5418 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5419}
5420
5421GLboolean Context::isEnabled(GLenum cap)
5422{
5423 return mGLState.getEnableFeature(cap);
5424}
5425
5426GLboolean Context::isFramebuffer(GLuint framebuffer)
5427{
5428 if (framebuffer == 0)
5429 {
5430 return GL_FALSE;
5431 }
5432
5433 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5434}
5435
5436GLboolean Context::isProgram(GLuint program)
5437{
5438 if (program == 0)
5439 {
5440 return GL_FALSE;
5441 }
5442
5443 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5444}
5445
5446GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5447{
5448 if (renderbuffer == 0)
5449 {
5450 return GL_FALSE;
5451 }
5452
5453 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5454}
5455
5456GLboolean Context::isShader(GLuint shader)
5457{
5458 if (shader == 0)
5459 {
5460 return GL_FALSE;
5461 }
5462
5463 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5464}
5465
5466GLboolean Context::isTexture(GLuint texture)
5467{
5468 if (texture == 0)
5469 {
5470 return GL_FALSE;
5471 }
5472
5473 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5474}
5475
5476void Context::linkProgram(GLuint program)
5477{
5478 Program *programObject = getProgram(program);
5479 ASSERT(programObject);
5480 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005481 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005482}
5483
5484void Context::releaseShaderCompiler()
5485{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005486 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005487}
5488
5489void Context::shaderBinary(GLsizei n,
5490 const GLuint *shaders,
5491 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005492 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005493 GLsizei length)
5494{
5495 // No binary shader formats are supported.
5496 UNIMPLEMENTED();
5497}
5498
5499void Context::shaderSource(GLuint shader,
5500 GLsizei count,
5501 const GLchar *const *string,
5502 const GLint *length)
5503{
5504 Shader *shaderObject = getShader(shader);
5505 ASSERT(shaderObject);
5506 shaderObject->setSource(count, string, length);
5507}
5508
5509void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5510{
5511 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5512}
5513
5514void Context::stencilMask(GLuint mask)
5515{
5516 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5517}
5518
5519void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5520{
5521 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5522}
5523
5524void Context::uniform1f(GLint location, GLfloat x)
5525{
5526 Program *program = mGLState.getProgram();
5527 program->setUniform1fv(location, 1, &x);
5528}
5529
5530void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5531{
5532 Program *program = mGLState.getProgram();
5533 program->setUniform1fv(location, count, v);
5534}
5535
5536void Context::uniform1i(GLint location, GLint x)
5537{
5538 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005539 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5540 {
5541 mGLState.setObjectDirty(GL_PROGRAM);
5542 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005543}
5544
5545void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5546{
5547 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005548 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5549 {
5550 mGLState.setObjectDirty(GL_PROGRAM);
5551 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552}
5553
5554void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5555{
5556 GLfloat xy[2] = {x, y};
5557 Program *program = mGLState.getProgram();
5558 program->setUniform2fv(location, 1, xy);
5559}
5560
5561void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5562{
5563 Program *program = mGLState.getProgram();
5564 program->setUniform2fv(location, count, v);
5565}
5566
5567void Context::uniform2i(GLint location, GLint x, GLint y)
5568{
5569 GLint xy[2] = {x, y};
5570 Program *program = mGLState.getProgram();
5571 program->setUniform2iv(location, 1, xy);
5572}
5573
5574void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5575{
5576 Program *program = mGLState.getProgram();
5577 program->setUniform2iv(location, count, v);
5578}
5579
5580void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5581{
5582 GLfloat xyz[3] = {x, y, z};
5583 Program *program = mGLState.getProgram();
5584 program->setUniform3fv(location, 1, xyz);
5585}
5586
5587void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5588{
5589 Program *program = mGLState.getProgram();
5590 program->setUniform3fv(location, count, v);
5591}
5592
5593void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5594{
5595 GLint xyz[3] = {x, y, z};
5596 Program *program = mGLState.getProgram();
5597 program->setUniform3iv(location, 1, xyz);
5598}
5599
5600void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5601{
5602 Program *program = mGLState.getProgram();
5603 program->setUniform3iv(location, count, v);
5604}
5605
5606void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5607{
5608 GLfloat xyzw[4] = {x, y, z, w};
5609 Program *program = mGLState.getProgram();
5610 program->setUniform4fv(location, 1, xyzw);
5611}
5612
5613void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5614{
5615 Program *program = mGLState.getProgram();
5616 program->setUniform4fv(location, count, v);
5617}
5618
5619void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5620{
5621 GLint xyzw[4] = {x, y, z, w};
5622 Program *program = mGLState.getProgram();
5623 program->setUniform4iv(location, 1, xyzw);
5624}
5625
5626void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5627{
5628 Program *program = mGLState.getProgram();
5629 program->setUniform4iv(location, count, v);
5630}
5631
5632void Context::uniformMatrix2fv(GLint location,
5633 GLsizei count,
5634 GLboolean transpose,
5635 const GLfloat *value)
5636{
5637 Program *program = mGLState.getProgram();
5638 program->setUniformMatrix2fv(location, count, transpose, value);
5639}
5640
5641void Context::uniformMatrix3fv(GLint location,
5642 GLsizei count,
5643 GLboolean transpose,
5644 const GLfloat *value)
5645{
5646 Program *program = mGLState.getProgram();
5647 program->setUniformMatrix3fv(location, count, transpose, value);
5648}
5649
5650void Context::uniformMatrix4fv(GLint location,
5651 GLsizei count,
5652 GLboolean transpose,
5653 const GLfloat *value)
5654{
5655 Program *program = mGLState.getProgram();
5656 program->setUniformMatrix4fv(location, count, transpose, value);
5657}
5658
5659void Context::validateProgram(GLuint program)
5660{
5661 Program *programObject = getProgram(program);
5662 ASSERT(programObject);
5663 programObject->validate(mCaps);
5664}
5665
Jiajia Qin5451d532017-11-16 17:16:34 +08005666void Context::validateProgramPipeline(GLuint pipeline)
5667{
5668 UNIMPLEMENTED();
5669}
5670
Jamie Madilld04908b2017-06-09 14:15:35 -04005671void Context::getProgramBinary(GLuint program,
5672 GLsizei bufSize,
5673 GLsizei *length,
5674 GLenum *binaryFormat,
5675 void *binary)
5676{
5677 Program *programObject = getProgram(program);
5678 ASSERT(programObject != nullptr);
5679
5680 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5681}
5682
5683void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5684{
5685 Program *programObject = getProgram(program);
5686 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005687
Jamie Madilld04908b2017-06-09 14:15:35 -04005688 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5689}
5690
Jamie Madillff325f12017-08-26 15:06:05 -04005691void Context::uniform1ui(GLint location, GLuint v0)
5692{
5693 Program *program = mGLState.getProgram();
5694 program->setUniform1uiv(location, 1, &v0);
5695}
5696
5697void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5698{
5699 Program *program = mGLState.getProgram();
5700 const GLuint xy[] = {v0, v1};
5701 program->setUniform2uiv(location, 1, xy);
5702}
5703
5704void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5705{
5706 Program *program = mGLState.getProgram();
5707 const GLuint xyz[] = {v0, v1, v2};
5708 program->setUniform3uiv(location, 1, xyz);
5709}
5710
5711void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5712{
5713 Program *program = mGLState.getProgram();
5714 const GLuint xyzw[] = {v0, v1, v2, v3};
5715 program->setUniform4uiv(location, 1, xyzw);
5716}
5717
5718void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5719{
5720 Program *program = mGLState.getProgram();
5721 program->setUniform1uiv(location, count, value);
5722}
5723void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5724{
5725 Program *program = mGLState.getProgram();
5726 program->setUniform2uiv(location, count, value);
5727}
5728
5729void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5730{
5731 Program *program = mGLState.getProgram();
5732 program->setUniform3uiv(location, count, value);
5733}
5734
5735void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5736{
5737 Program *program = mGLState.getProgram();
5738 program->setUniform4uiv(location, count, value);
5739}
5740
Jamie Madillf0e04492017-08-26 15:28:42 -04005741void Context::genQueries(GLsizei n, GLuint *ids)
5742{
5743 for (GLsizei i = 0; i < n; i++)
5744 {
5745 GLuint handle = mQueryHandleAllocator.allocate();
5746 mQueryMap.assign(handle, nullptr);
5747 ids[i] = handle;
5748 }
5749}
5750
5751void Context::deleteQueries(GLsizei n, const GLuint *ids)
5752{
5753 for (int i = 0; i < n; i++)
5754 {
5755 GLuint query = ids[i];
5756
5757 Query *queryObject = nullptr;
5758 if (mQueryMap.erase(query, &queryObject))
5759 {
5760 mQueryHandleAllocator.release(query);
5761 if (queryObject)
5762 {
5763 queryObject->release(this);
5764 }
5765 }
5766 }
5767}
5768
5769GLboolean Context::isQuery(GLuint id)
5770{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005771 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005772}
5773
Jamie Madillc8c95812017-08-26 18:40:09 -04005774void Context::uniformMatrix2x3fv(GLint location,
5775 GLsizei count,
5776 GLboolean transpose,
5777 const GLfloat *value)
5778{
5779 Program *program = mGLState.getProgram();
5780 program->setUniformMatrix2x3fv(location, count, transpose, value);
5781}
5782
5783void Context::uniformMatrix3x2fv(GLint location,
5784 GLsizei count,
5785 GLboolean transpose,
5786 const GLfloat *value)
5787{
5788 Program *program = mGLState.getProgram();
5789 program->setUniformMatrix3x2fv(location, count, transpose, value);
5790}
5791
5792void Context::uniformMatrix2x4fv(GLint location,
5793 GLsizei count,
5794 GLboolean transpose,
5795 const GLfloat *value)
5796{
5797 Program *program = mGLState.getProgram();
5798 program->setUniformMatrix2x4fv(location, count, transpose, value);
5799}
5800
5801void Context::uniformMatrix4x2fv(GLint location,
5802 GLsizei count,
5803 GLboolean transpose,
5804 const GLfloat *value)
5805{
5806 Program *program = mGLState.getProgram();
5807 program->setUniformMatrix4x2fv(location, count, transpose, value);
5808}
5809
5810void Context::uniformMatrix3x4fv(GLint location,
5811 GLsizei count,
5812 GLboolean transpose,
5813 const GLfloat *value)
5814{
5815 Program *program = mGLState.getProgram();
5816 program->setUniformMatrix3x4fv(location, count, transpose, value);
5817}
5818
5819void Context::uniformMatrix4x3fv(GLint location,
5820 GLsizei count,
5821 GLboolean transpose,
5822 const GLfloat *value)
5823{
5824 Program *program = mGLState.getProgram();
5825 program->setUniformMatrix4x3fv(location, count, transpose, value);
5826}
5827
Jamie Madilld7576732017-08-26 18:49:50 -04005828void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5829{
5830 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5831 {
5832 GLuint vertexArray = arrays[arrayIndex];
5833
5834 if (arrays[arrayIndex] != 0)
5835 {
5836 VertexArray *vertexArrayObject = nullptr;
5837 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5838 {
5839 if (vertexArrayObject != nullptr)
5840 {
5841 detachVertexArray(vertexArray);
5842 vertexArrayObject->onDestroy(this);
5843 }
5844
5845 mVertexArrayHandleAllocator.release(vertexArray);
5846 }
5847 }
5848 }
5849}
5850
5851void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5852{
5853 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5854 {
5855 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5856 mVertexArrayMap.assign(vertexArray, nullptr);
5857 arrays[arrayIndex] = vertexArray;
5858 }
5859}
5860
5861bool Context::isVertexArray(GLuint array)
5862{
5863 if (array == 0)
5864 {
5865 return GL_FALSE;
5866 }
5867
5868 VertexArray *vao = getVertexArray(array);
5869 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5870}
5871
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005872void Context::endTransformFeedback()
5873{
5874 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5875 transformFeedback->end(this);
5876}
5877
5878void Context::transformFeedbackVaryings(GLuint program,
5879 GLsizei count,
5880 const GLchar *const *varyings,
5881 GLenum bufferMode)
5882{
5883 Program *programObject = getProgram(program);
5884 ASSERT(programObject);
5885 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5886}
5887
5888void Context::getTransformFeedbackVarying(GLuint program,
5889 GLuint index,
5890 GLsizei bufSize,
5891 GLsizei *length,
5892 GLsizei *size,
5893 GLenum *type,
5894 GLchar *name)
5895{
5896 Program *programObject = getProgram(program);
5897 ASSERT(programObject);
5898 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5899}
5900
5901void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5902{
5903 for (int i = 0; i < n; i++)
5904 {
5905 GLuint transformFeedback = ids[i];
5906 if (transformFeedback == 0)
5907 {
5908 continue;
5909 }
5910
5911 TransformFeedback *transformFeedbackObject = nullptr;
5912 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5913 {
5914 if (transformFeedbackObject != nullptr)
5915 {
5916 detachTransformFeedback(transformFeedback);
5917 transformFeedbackObject->release(this);
5918 }
5919
5920 mTransformFeedbackHandleAllocator.release(transformFeedback);
5921 }
5922 }
5923}
5924
5925void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5926{
5927 for (int i = 0; i < n; i++)
5928 {
5929 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5930 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5931 ids[i] = transformFeedback;
5932 }
5933}
5934
5935bool Context::isTransformFeedback(GLuint id)
5936{
5937 if (id == 0)
5938 {
5939 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5940 // returns FALSE
5941 return GL_FALSE;
5942 }
5943
5944 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5945 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5946}
5947
5948void Context::pauseTransformFeedback()
5949{
5950 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5951 transformFeedback->pause();
5952}
5953
5954void Context::resumeTransformFeedback()
5955{
5956 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5957 transformFeedback->resume();
5958}
5959
Jamie Madill12e957f2017-08-26 21:42:26 -04005960void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5961{
5962 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005963 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005964}
5965
Brandon Jones59770802018-04-02 13:18:42 -07005966void Context::getUniformuivRobust(GLuint program,
5967 GLint location,
5968 GLsizei bufSize,
5969 GLsizei *length,
5970 GLuint *params)
5971{
5972 getUniformuiv(program, location, params);
5973}
5974
Jamie Madill12e957f2017-08-26 21:42:26 -04005975GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5976{
5977 const Program *programObject = getProgram(program);
5978 return programObject->getFragDataLocation(name);
5979}
5980
5981void Context::getUniformIndices(GLuint program,
5982 GLsizei uniformCount,
5983 const GLchar *const *uniformNames,
5984 GLuint *uniformIndices)
5985{
5986 const Program *programObject = getProgram(program);
5987 if (!programObject->isLinked())
5988 {
5989 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5990 {
5991 uniformIndices[uniformId] = GL_INVALID_INDEX;
5992 }
5993 }
5994 else
5995 {
5996 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5997 {
5998 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5999 }
6000 }
6001}
6002
6003void Context::getActiveUniformsiv(GLuint program,
6004 GLsizei uniformCount,
6005 const GLuint *uniformIndices,
6006 GLenum pname,
6007 GLint *params)
6008{
6009 const Program *programObject = getProgram(program);
6010 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6011 {
6012 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006013 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006014 }
6015}
6016
6017GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6018{
6019 const Program *programObject = getProgram(program);
6020 return programObject->getUniformBlockIndex(uniformBlockName);
6021}
6022
6023void Context::getActiveUniformBlockiv(GLuint program,
6024 GLuint uniformBlockIndex,
6025 GLenum pname,
6026 GLint *params)
6027{
6028 const Program *programObject = getProgram(program);
6029 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6030}
6031
Brandon Jones59770802018-04-02 13:18:42 -07006032void Context::getActiveUniformBlockivRobust(GLuint program,
6033 GLuint uniformBlockIndex,
6034 GLenum pname,
6035 GLsizei bufSize,
6036 GLsizei *length,
6037 GLint *params)
6038{
6039 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6040}
6041
Jamie Madill12e957f2017-08-26 21:42:26 -04006042void Context::getActiveUniformBlockName(GLuint program,
6043 GLuint uniformBlockIndex,
6044 GLsizei bufSize,
6045 GLsizei *length,
6046 GLchar *uniformBlockName)
6047{
6048 const Program *programObject = getProgram(program);
6049 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6050}
6051
6052void Context::uniformBlockBinding(GLuint program,
6053 GLuint uniformBlockIndex,
6054 GLuint uniformBlockBinding)
6055{
6056 Program *programObject = getProgram(program);
6057 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6058}
6059
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006060GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6061{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006062 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6063 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006064
Jamie Madill70b5bb02017-08-28 13:32:37 -04006065 Sync *syncObject = getSync(syncHandle);
6066 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006067 if (error.isError())
6068 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006069 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006070 handleError(error);
6071 return nullptr;
6072 }
6073
Jamie Madill70b5bb02017-08-28 13:32:37 -04006074 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006075}
6076
6077GLboolean Context::isSync(GLsync sync)
6078{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006079 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006080}
6081
6082GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6083{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006084 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006085
6086 GLenum result = GL_WAIT_FAILED;
6087 handleError(syncObject->clientWait(flags, timeout, &result));
6088 return result;
6089}
6090
6091void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6092{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006093 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006094 handleError(syncObject->serverWait(flags, timeout));
6095}
6096
6097void Context::getInteger64v(GLenum pname, GLint64 *params)
6098{
6099 GLenum nativeType = GL_NONE;
6100 unsigned int numParams = 0;
6101 getQueryParameterInfo(pname, &nativeType, &numParams);
6102
6103 if (nativeType == GL_INT_64_ANGLEX)
6104 {
6105 getInteger64vImpl(pname, params);
6106 }
6107 else
6108 {
6109 CastStateValues(this, nativeType, pname, numParams, params);
6110 }
6111}
6112
Brandon Jones59770802018-04-02 13:18:42 -07006113void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6114{
6115 getInteger64v(pname, data);
6116}
6117
Corentin Wallez336129f2017-10-17 15:55:40 -04006118void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006119{
6120 Buffer *buffer = mGLState.getTargetBuffer(target);
6121 QueryBufferParameteri64v(buffer, pname, params);
6122}
6123
Brandon Jones59770802018-04-02 13:18:42 -07006124void Context::getBufferParameteri64vRobust(BufferBinding target,
6125 GLenum pname,
6126 GLsizei bufSize,
6127 GLsizei *length,
6128 GLint64 *params)
6129{
6130 getBufferParameteri64v(target, pname, params);
6131}
6132
Jamie Madill3ef140a2017-08-26 23:11:21 -04006133void Context::genSamplers(GLsizei count, GLuint *samplers)
6134{
6135 for (int i = 0; i < count; i++)
6136 {
6137 samplers[i] = mState.mSamplers->createSampler();
6138 }
6139}
6140
6141void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6142{
6143 for (int i = 0; i < count; i++)
6144 {
6145 GLuint sampler = samplers[i];
6146
6147 if (mState.mSamplers->getSampler(sampler))
6148 {
6149 detachSampler(sampler);
6150 }
6151
6152 mState.mSamplers->deleteObject(this, sampler);
6153 }
6154}
6155
6156void Context::getInternalformativ(GLenum target,
6157 GLenum internalformat,
6158 GLenum pname,
6159 GLsizei bufSize,
6160 GLint *params)
6161{
6162 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6163 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6164}
6165
Brandon Jones59770802018-04-02 13:18:42 -07006166void Context::getInternalformativRobust(GLenum target,
6167 GLenum internalformat,
6168 GLenum pname,
6169 GLsizei bufSize,
6170 GLsizei *length,
6171 GLint *params)
6172{
6173 getInternalformativ(target, internalformat, pname, bufSize, params);
6174}
6175
Jiajia Qin5451d532017-11-16 17:16:34 +08006176void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6177{
6178 programUniform1iv(program, location, 1, &v0);
6179}
6180
6181void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6182{
6183 GLint xy[2] = {v0, v1};
6184 programUniform2iv(program, location, 1, xy);
6185}
6186
6187void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6188{
6189 GLint xyz[3] = {v0, v1, v2};
6190 programUniform3iv(program, location, 1, xyz);
6191}
6192
6193void Context::programUniform4i(GLuint program,
6194 GLint location,
6195 GLint v0,
6196 GLint v1,
6197 GLint v2,
6198 GLint v3)
6199{
6200 GLint xyzw[4] = {v0, v1, v2, v3};
6201 programUniform4iv(program, location, 1, xyzw);
6202}
6203
6204void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6205{
6206 programUniform1uiv(program, location, 1, &v0);
6207}
6208
6209void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6210{
6211 GLuint xy[2] = {v0, v1};
6212 programUniform2uiv(program, location, 1, xy);
6213}
6214
6215void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6216{
6217 GLuint xyz[3] = {v0, v1, v2};
6218 programUniform3uiv(program, location, 1, xyz);
6219}
6220
6221void Context::programUniform4ui(GLuint program,
6222 GLint location,
6223 GLuint v0,
6224 GLuint v1,
6225 GLuint v2,
6226 GLuint v3)
6227{
6228 GLuint xyzw[4] = {v0, v1, v2, v3};
6229 programUniform4uiv(program, location, 1, xyzw);
6230}
6231
6232void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6233{
6234 programUniform1fv(program, location, 1, &v0);
6235}
6236
6237void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6238{
6239 GLfloat xy[2] = {v0, v1};
6240 programUniform2fv(program, location, 1, xy);
6241}
6242
6243void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6244{
6245 GLfloat xyz[3] = {v0, v1, v2};
6246 programUniform3fv(program, location, 1, xyz);
6247}
6248
6249void Context::programUniform4f(GLuint program,
6250 GLint location,
6251 GLfloat v0,
6252 GLfloat v1,
6253 GLfloat v2,
6254 GLfloat v3)
6255{
6256 GLfloat xyzw[4] = {v0, v1, v2, v3};
6257 programUniform4fv(program, location, 1, xyzw);
6258}
6259
Jamie Madill81c2e252017-09-09 23:32:46 -04006260void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6261{
6262 Program *programObject = getProgram(program);
6263 ASSERT(programObject);
6264 if (programObject->setUniform1iv(location, count, value) ==
6265 Program::SetUniformResult::SamplerChanged)
6266 {
6267 mGLState.setObjectDirty(GL_PROGRAM);
6268 }
6269}
6270
Jiajia Qin5451d532017-11-16 17:16:34 +08006271void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6272{
6273 Program *programObject = getProgram(program);
6274 ASSERT(programObject);
6275 programObject->setUniform2iv(location, count, value);
6276}
6277
6278void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6279{
6280 Program *programObject = getProgram(program);
6281 ASSERT(programObject);
6282 programObject->setUniform3iv(location, count, value);
6283}
6284
6285void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6286{
6287 Program *programObject = getProgram(program);
6288 ASSERT(programObject);
6289 programObject->setUniform4iv(location, count, value);
6290}
6291
6292void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6293{
6294 Program *programObject = getProgram(program);
6295 ASSERT(programObject);
6296 programObject->setUniform1uiv(location, count, value);
6297}
6298
6299void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6300{
6301 Program *programObject = getProgram(program);
6302 ASSERT(programObject);
6303 programObject->setUniform2uiv(location, count, value);
6304}
6305
6306void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6307{
6308 Program *programObject = getProgram(program);
6309 ASSERT(programObject);
6310 programObject->setUniform3uiv(location, count, value);
6311}
6312
6313void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6314{
6315 Program *programObject = getProgram(program);
6316 ASSERT(programObject);
6317 programObject->setUniform4uiv(location, count, value);
6318}
6319
6320void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6321{
6322 Program *programObject = getProgram(program);
6323 ASSERT(programObject);
6324 programObject->setUniform1fv(location, count, value);
6325}
6326
6327void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6328{
6329 Program *programObject = getProgram(program);
6330 ASSERT(programObject);
6331 programObject->setUniform2fv(location, count, value);
6332}
6333
6334void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6335{
6336 Program *programObject = getProgram(program);
6337 ASSERT(programObject);
6338 programObject->setUniform3fv(location, count, value);
6339}
6340
6341void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6342{
6343 Program *programObject = getProgram(program);
6344 ASSERT(programObject);
6345 programObject->setUniform4fv(location, count, value);
6346}
6347
6348void Context::programUniformMatrix2fv(GLuint program,
6349 GLint location,
6350 GLsizei count,
6351 GLboolean transpose,
6352 const GLfloat *value)
6353{
6354 Program *programObject = getProgram(program);
6355 ASSERT(programObject);
6356 programObject->setUniformMatrix2fv(location, count, transpose, value);
6357}
6358
6359void Context::programUniformMatrix3fv(GLuint program,
6360 GLint location,
6361 GLsizei count,
6362 GLboolean transpose,
6363 const GLfloat *value)
6364{
6365 Program *programObject = getProgram(program);
6366 ASSERT(programObject);
6367 programObject->setUniformMatrix3fv(location, count, transpose, value);
6368}
6369
6370void Context::programUniformMatrix4fv(GLuint program,
6371 GLint location,
6372 GLsizei count,
6373 GLboolean transpose,
6374 const GLfloat *value)
6375{
6376 Program *programObject = getProgram(program);
6377 ASSERT(programObject);
6378 programObject->setUniformMatrix4fv(location, count, transpose, value);
6379}
6380
6381void Context::programUniformMatrix2x3fv(GLuint program,
6382 GLint location,
6383 GLsizei count,
6384 GLboolean transpose,
6385 const GLfloat *value)
6386{
6387 Program *programObject = getProgram(program);
6388 ASSERT(programObject);
6389 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6390}
6391
6392void Context::programUniformMatrix3x2fv(GLuint program,
6393 GLint location,
6394 GLsizei count,
6395 GLboolean transpose,
6396 const GLfloat *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6401}
6402
6403void Context::programUniformMatrix2x4fv(GLuint program,
6404 GLint location,
6405 GLsizei count,
6406 GLboolean transpose,
6407 const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6412}
6413
6414void Context::programUniformMatrix4x2fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix3x4fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix4x3fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6445}
6446
Jamie Madill81c2e252017-09-09 23:32:46 -04006447void Context::onTextureChange(const Texture *texture)
6448{
6449 // Conservatively assume all textures are dirty.
6450 // TODO(jmadill): More fine-grained update.
6451 mGLState.setObjectDirty(GL_TEXTURE);
6452}
6453
James Darpiniane8a93c62018-01-04 18:02:24 -08006454bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6455{
6456 return mGLState.isCurrentTransformFeedback(tf);
6457}
6458bool Context::isCurrentVertexArray(const VertexArray *va) const
6459{
6460 return mGLState.isCurrentVertexArray(va);
6461}
6462
Yunchao Hea336b902017-08-02 16:05:21 +08006463void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6464{
6465 for (int i = 0; i < count; i++)
6466 {
6467 pipelines[i] = createProgramPipeline();
6468 }
6469}
6470
6471void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6472{
6473 for (int i = 0; i < count; i++)
6474 {
6475 if (pipelines[i] != 0)
6476 {
6477 deleteProgramPipeline(pipelines[i]);
6478 }
6479 }
6480}
6481
6482GLboolean Context::isProgramPipeline(GLuint pipeline)
6483{
6484 if (pipeline == 0)
6485 {
6486 return GL_FALSE;
6487 }
6488
6489 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6490}
6491
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006492void Context::finishFenceNV(GLuint fence)
6493{
6494 FenceNV *fenceObject = getFenceNV(fence);
6495
6496 ASSERT(fenceObject && fenceObject->isSet());
6497 handleError(fenceObject->finish());
6498}
6499
6500void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6501{
6502 FenceNV *fenceObject = getFenceNV(fence);
6503
6504 ASSERT(fenceObject && fenceObject->isSet());
6505
6506 switch (pname)
6507 {
6508 case GL_FENCE_STATUS_NV:
6509 {
6510 // GL_NV_fence spec:
6511 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6512 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6513 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6514 GLboolean status = GL_TRUE;
6515 if (fenceObject->getStatus() != GL_TRUE)
6516 {
6517 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6518 }
6519 *params = status;
6520 break;
6521 }
6522
6523 case GL_FENCE_CONDITION_NV:
6524 {
6525 *params = static_cast<GLint>(fenceObject->getCondition());
6526 break;
6527 }
6528
6529 default:
6530 UNREACHABLE();
6531 }
6532}
6533
6534void Context::getTranslatedShaderSource(GLuint shader,
6535 GLsizei bufsize,
6536 GLsizei *length,
6537 GLchar *source)
6538{
6539 Shader *shaderObject = getShader(shader);
6540 ASSERT(shaderObject);
6541 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6542}
6543
6544void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6545{
6546 Program *programObject = getProgram(program);
6547 ASSERT(programObject);
6548
6549 programObject->getUniformfv(this, location, params);
6550}
6551
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006552void Context::getnUniformfvRobust(GLuint program,
6553 GLint location,
6554 GLsizei bufSize,
6555 GLsizei *length,
6556 GLfloat *params)
6557{
6558 UNIMPLEMENTED();
6559}
6560
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006561void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6562{
6563 Program *programObject = getProgram(program);
6564 ASSERT(programObject);
6565
6566 programObject->getUniformiv(this, location, params);
6567}
6568
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006569void Context::getnUniformivRobust(GLuint program,
6570 GLint location,
6571 GLsizei bufSize,
6572 GLsizei *length,
6573 GLint *params)
6574{
6575 UNIMPLEMENTED();
6576}
6577
6578void Context::getnUniformuivRobust(GLuint program,
6579 GLint location,
6580 GLsizei bufSize,
6581 GLsizei *length,
6582 GLuint *params)
6583{
6584 UNIMPLEMENTED();
6585}
6586
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006587GLboolean Context::isFenceNV(GLuint fence)
6588{
6589 FenceNV *fenceObject = getFenceNV(fence);
6590
6591 if (fenceObject == nullptr)
6592 {
6593 return GL_FALSE;
6594 }
6595
6596 // GL_NV_fence spec:
6597 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6598 // existing fence.
6599 return fenceObject->isSet();
6600}
6601
6602void Context::readnPixels(GLint x,
6603 GLint y,
6604 GLsizei width,
6605 GLsizei height,
6606 GLenum format,
6607 GLenum type,
6608 GLsizei bufSize,
6609 void *data)
6610{
6611 return readPixels(x, y, width, height, format, type, data);
6612}
6613
Jamie Madill007530e2017-12-28 14:27:04 -05006614void Context::setFenceNV(GLuint fence, GLenum condition)
6615{
6616 ASSERT(condition == GL_ALL_COMPLETED_NV);
6617
6618 FenceNV *fenceObject = getFenceNV(fence);
6619 ASSERT(fenceObject != nullptr);
6620 handleError(fenceObject->set(condition));
6621}
6622
6623GLboolean Context::testFenceNV(GLuint fence)
6624{
6625 FenceNV *fenceObject = getFenceNV(fence);
6626
6627 ASSERT(fenceObject != nullptr);
6628 ASSERT(fenceObject->isSet() == GL_TRUE);
6629
6630 GLboolean result = GL_TRUE;
6631 Error error = fenceObject->test(&result);
6632 if (error.isError())
6633 {
6634 handleError(error);
6635 return GL_TRUE;
6636 }
6637
6638 return result;
6639}
6640
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006641void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006642{
6643 Texture *texture = getTargetTexture(target);
6644 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006645 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006646}
6647
Jamie Madillfa920eb2018-01-04 11:45:50 -05006648void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006649{
6650 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6651 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6652 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6653}
6654
Jamie Madillfa920eb2018-01-04 11:45:50 -05006655void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6656{
6657 UNIMPLEMENTED();
6658}
6659
Jamie Madill5b772312018-03-08 20:28:32 -05006660bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6661{
6662 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6663 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6664 // to the fact that it is stored internally as a float, and so would require conversion
6665 // if returned from Context::getIntegerv. Since this conversion is already implemented
6666 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6667 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6668 // application.
6669 switch (pname)
6670 {
6671 case GL_COMPRESSED_TEXTURE_FORMATS:
6672 {
6673 *type = GL_INT;
6674 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6675 return true;
6676 }
6677 case GL_SHADER_BINARY_FORMATS:
6678 {
6679 *type = GL_INT;
6680 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6681 return true;
6682 }
6683
6684 case GL_MAX_VERTEX_ATTRIBS:
6685 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6686 case GL_MAX_VARYING_VECTORS:
6687 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6688 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6689 case GL_MAX_TEXTURE_IMAGE_UNITS:
6690 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6691 case GL_MAX_RENDERBUFFER_SIZE:
6692 case GL_NUM_SHADER_BINARY_FORMATS:
6693 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6694 case GL_ARRAY_BUFFER_BINDING:
6695 case GL_FRAMEBUFFER_BINDING:
6696 case GL_RENDERBUFFER_BINDING:
6697 case GL_CURRENT_PROGRAM:
6698 case GL_PACK_ALIGNMENT:
6699 case GL_UNPACK_ALIGNMENT:
6700 case GL_GENERATE_MIPMAP_HINT:
6701 case GL_RED_BITS:
6702 case GL_GREEN_BITS:
6703 case GL_BLUE_BITS:
6704 case GL_ALPHA_BITS:
6705 case GL_DEPTH_BITS:
6706 case GL_STENCIL_BITS:
6707 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6708 case GL_CULL_FACE_MODE:
6709 case GL_FRONT_FACE:
6710 case GL_ACTIVE_TEXTURE:
6711 case GL_STENCIL_FUNC:
6712 case GL_STENCIL_VALUE_MASK:
6713 case GL_STENCIL_REF:
6714 case GL_STENCIL_FAIL:
6715 case GL_STENCIL_PASS_DEPTH_FAIL:
6716 case GL_STENCIL_PASS_DEPTH_PASS:
6717 case GL_STENCIL_BACK_FUNC:
6718 case GL_STENCIL_BACK_VALUE_MASK:
6719 case GL_STENCIL_BACK_REF:
6720 case GL_STENCIL_BACK_FAIL:
6721 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6722 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6723 case GL_DEPTH_FUNC:
6724 case GL_BLEND_SRC_RGB:
6725 case GL_BLEND_SRC_ALPHA:
6726 case GL_BLEND_DST_RGB:
6727 case GL_BLEND_DST_ALPHA:
6728 case GL_BLEND_EQUATION_RGB:
6729 case GL_BLEND_EQUATION_ALPHA:
6730 case GL_STENCIL_WRITEMASK:
6731 case GL_STENCIL_BACK_WRITEMASK:
6732 case GL_STENCIL_CLEAR_VALUE:
6733 case GL_SUBPIXEL_BITS:
6734 case GL_MAX_TEXTURE_SIZE:
6735 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6736 case GL_SAMPLE_BUFFERS:
6737 case GL_SAMPLES:
6738 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6739 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6740 case GL_TEXTURE_BINDING_2D:
6741 case GL_TEXTURE_BINDING_CUBE_MAP:
6742 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6743 {
6744 *type = GL_INT;
6745 *numParams = 1;
6746 return true;
6747 }
6748 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6749 {
6750 if (!getExtensions().packReverseRowOrder)
6751 {
6752 return false;
6753 }
6754 *type = GL_INT;
6755 *numParams = 1;
6756 return true;
6757 }
6758 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6759 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6760 {
6761 if (!getExtensions().textureRectangle)
6762 {
6763 return false;
6764 }
6765 *type = GL_INT;
6766 *numParams = 1;
6767 return true;
6768 }
6769 case GL_MAX_DRAW_BUFFERS_EXT:
6770 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6771 {
6772 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6773 {
6774 return false;
6775 }
6776 *type = GL_INT;
6777 *numParams = 1;
6778 return true;
6779 }
6780 case GL_MAX_VIEWPORT_DIMS:
6781 {
6782 *type = GL_INT;
6783 *numParams = 2;
6784 return true;
6785 }
6786 case GL_VIEWPORT:
6787 case GL_SCISSOR_BOX:
6788 {
6789 *type = GL_INT;
6790 *numParams = 4;
6791 return true;
6792 }
6793 case GL_SHADER_COMPILER:
6794 case GL_SAMPLE_COVERAGE_INVERT:
6795 case GL_DEPTH_WRITEMASK:
6796 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6797 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6798 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6799 // bool-natural
6800 case GL_SAMPLE_COVERAGE:
6801 case GL_SCISSOR_TEST:
6802 case GL_STENCIL_TEST:
6803 case GL_DEPTH_TEST:
6804 case GL_BLEND:
6805 case GL_DITHER:
6806 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6807 {
6808 *type = GL_BOOL;
6809 *numParams = 1;
6810 return true;
6811 }
6812 case GL_COLOR_WRITEMASK:
6813 {
6814 *type = GL_BOOL;
6815 *numParams = 4;
6816 return true;
6817 }
6818 case GL_POLYGON_OFFSET_FACTOR:
6819 case GL_POLYGON_OFFSET_UNITS:
6820 case GL_SAMPLE_COVERAGE_VALUE:
6821 case GL_DEPTH_CLEAR_VALUE:
6822 case GL_LINE_WIDTH:
6823 {
6824 *type = GL_FLOAT;
6825 *numParams = 1;
6826 return true;
6827 }
6828 case GL_ALIASED_LINE_WIDTH_RANGE:
6829 case GL_ALIASED_POINT_SIZE_RANGE:
6830 case GL_DEPTH_RANGE:
6831 {
6832 *type = GL_FLOAT;
6833 *numParams = 2;
6834 return true;
6835 }
6836 case GL_COLOR_CLEAR_VALUE:
6837 case GL_BLEND_COLOR:
6838 {
6839 *type = GL_FLOAT;
6840 *numParams = 4;
6841 return true;
6842 }
6843 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6844 if (!getExtensions().textureFilterAnisotropic)
6845 {
6846 return false;
6847 }
6848 *type = GL_FLOAT;
6849 *numParams = 1;
6850 return true;
6851 case GL_TIMESTAMP_EXT:
6852 if (!getExtensions().disjointTimerQuery)
6853 {
6854 return false;
6855 }
6856 *type = GL_INT_64_ANGLEX;
6857 *numParams = 1;
6858 return true;
6859 case GL_GPU_DISJOINT_EXT:
6860 if (!getExtensions().disjointTimerQuery)
6861 {
6862 return false;
6863 }
6864 *type = GL_INT;
6865 *numParams = 1;
6866 return true;
6867 case GL_COVERAGE_MODULATION_CHROMIUM:
6868 if (!getExtensions().framebufferMixedSamples)
6869 {
6870 return false;
6871 }
6872 *type = GL_INT;
6873 *numParams = 1;
6874 return true;
6875 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6876 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6877 {
6878 return false;
6879 }
6880 *type = GL_INT;
6881 *numParams = 1;
6882 return true;
6883 }
6884
6885 if (getExtensions().debug)
6886 {
6887 switch (pname)
6888 {
6889 case GL_DEBUG_LOGGED_MESSAGES:
6890 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6891 case GL_DEBUG_GROUP_STACK_DEPTH:
6892 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6893 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6894 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6895 case GL_MAX_LABEL_LENGTH:
6896 *type = GL_INT;
6897 *numParams = 1;
6898 return true;
6899
6900 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6901 case GL_DEBUG_OUTPUT:
6902 *type = GL_BOOL;
6903 *numParams = 1;
6904 return true;
6905 }
6906 }
6907
6908 if (getExtensions().multisampleCompatibility)
6909 {
6910 switch (pname)
6911 {
6912 case GL_MULTISAMPLE_EXT:
6913 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6914 *type = GL_BOOL;
6915 *numParams = 1;
6916 return true;
6917 }
6918 }
6919
6920 if (getExtensions().pathRendering)
6921 {
6922 switch (pname)
6923 {
6924 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6925 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6926 *type = GL_FLOAT;
6927 *numParams = 16;
6928 return true;
6929 }
6930 }
6931
6932 if (getExtensions().bindGeneratesResource)
6933 {
6934 switch (pname)
6935 {
6936 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6937 *type = GL_BOOL;
6938 *numParams = 1;
6939 return true;
6940 }
6941 }
6942
6943 if (getExtensions().clientArrays)
6944 {
6945 switch (pname)
6946 {
6947 case GL_CLIENT_ARRAYS_ANGLE:
6948 *type = GL_BOOL;
6949 *numParams = 1;
6950 return true;
6951 }
6952 }
6953
6954 if (getExtensions().sRGBWriteControl)
6955 {
6956 switch (pname)
6957 {
6958 case GL_FRAMEBUFFER_SRGB_EXT:
6959 *type = GL_BOOL;
6960 *numParams = 1;
6961 return true;
6962 }
6963 }
6964
6965 if (getExtensions().robustResourceInitialization &&
6966 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6967 {
6968 *type = GL_BOOL;
6969 *numParams = 1;
6970 return true;
6971 }
6972
6973 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6974 {
6975 *type = GL_BOOL;
6976 *numParams = 1;
6977 return true;
6978 }
6979
6980 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6981 switch (pname)
6982 {
6983 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6984 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6985 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6986 {
6987 return false;
6988 }
6989 *type = GL_INT;
6990 *numParams = 1;
6991 return true;
6992
6993 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6994 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6995 {
6996 return false;
6997 }
6998 *type = GL_INT;
6999 *numParams = 1;
7000 return true;
7001
7002 case GL_PROGRAM_BINARY_FORMATS_OES:
7003 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7004 {
7005 return false;
7006 }
7007 *type = GL_INT;
7008 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7009 return true;
7010
7011 case GL_PACK_ROW_LENGTH:
7012 case GL_PACK_SKIP_ROWS:
7013 case GL_PACK_SKIP_PIXELS:
7014 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7015 {
7016 return false;
7017 }
7018 *type = GL_INT;
7019 *numParams = 1;
7020 return true;
7021 case GL_UNPACK_ROW_LENGTH:
7022 case GL_UNPACK_SKIP_ROWS:
7023 case GL_UNPACK_SKIP_PIXELS:
7024 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7025 {
7026 return false;
7027 }
7028 *type = GL_INT;
7029 *numParams = 1;
7030 return true;
7031 case GL_VERTEX_ARRAY_BINDING:
7032 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7033 {
7034 return false;
7035 }
7036 *type = GL_INT;
7037 *numParams = 1;
7038 return true;
7039 case GL_PIXEL_PACK_BUFFER_BINDING:
7040 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7041 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7042 {
7043 return false;
7044 }
7045 *type = GL_INT;
7046 *numParams = 1;
7047 return true;
7048 case GL_MAX_SAMPLES:
7049 {
7050 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7051 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7052 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7053 {
7054 return false;
7055 }
7056 *type = GL_INT;
7057 *numParams = 1;
7058 return true;
7059
7060 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7061 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7062 {
7063 return false;
7064 }
7065 *type = GL_INT;
7066 *numParams = 1;
7067 return true;
7068 }
7069 }
7070
7071 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7072 {
7073 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7074 {
7075 return false;
7076 }
7077 *type = GL_INT;
7078 *numParams = 1;
7079 return true;
7080 }
7081
7082 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7083 {
7084 *type = GL_INT;
7085 *numParams = 1;
7086 return true;
7087 }
7088
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007089 if (getClientVersion() < Version(2, 0))
7090 {
7091 switch (pname)
7092 {
7093 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007094 case GL_CLIENT_ACTIVE_TEXTURE:
7095 case GL_MATRIX_MODE:
7096 case GL_MAX_TEXTURE_UNITS:
7097 case GL_MAX_MODELVIEW_STACK_DEPTH:
7098 case GL_MAX_PROJECTION_STACK_DEPTH:
7099 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007100 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007101 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007102 case GL_VERTEX_ARRAY_STRIDE:
7103 case GL_NORMAL_ARRAY_STRIDE:
7104 case GL_COLOR_ARRAY_STRIDE:
7105 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7106 case GL_VERTEX_ARRAY_SIZE:
7107 case GL_COLOR_ARRAY_SIZE:
7108 case GL_TEXTURE_COORD_ARRAY_SIZE:
7109 case GL_VERTEX_ARRAY_TYPE:
7110 case GL_NORMAL_ARRAY_TYPE:
7111 case GL_COLOR_ARRAY_TYPE:
7112 case GL_TEXTURE_COORD_ARRAY_TYPE:
7113 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7114 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7115 case GL_COLOR_ARRAY_BUFFER_BINDING:
7116 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7117 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7118 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7119 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007120 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007121 *type = GL_INT;
7122 *numParams = 1;
7123 return true;
7124 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007125 case GL_FOG_DENSITY:
7126 case GL_FOG_START:
7127 case GL_FOG_END:
7128 case GL_FOG_MODE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007129 *type = GL_FLOAT;
7130 *numParams = 1;
7131 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007132 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007133 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007134 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007135 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007136 *type = GL_FLOAT;
7137 *numParams = 4;
7138 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007139 case GL_CURRENT_NORMAL:
7140 *type = GL_FLOAT;
7141 *numParams = 3;
7142 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007143 case GL_MODELVIEW_MATRIX:
7144 case GL_PROJECTION_MATRIX:
7145 case GL_TEXTURE_MATRIX:
7146 *type = GL_FLOAT;
7147 *numParams = 16;
7148 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007149 case GL_LIGHT_MODEL_TWO_SIDE:
7150 *type = GL_BOOL;
7151 *numParams = 1;
7152 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007153 }
7154 }
7155
Jamie Madill5b772312018-03-08 20:28:32 -05007156 if (getClientVersion() < Version(3, 0))
7157 {
7158 return false;
7159 }
7160
7161 // Check for ES3.0+ parameter names
7162 switch (pname)
7163 {
7164 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7165 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7166 case GL_UNIFORM_BUFFER_BINDING:
7167 case GL_TRANSFORM_FEEDBACK_BINDING:
7168 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7169 case GL_COPY_READ_BUFFER_BINDING:
7170 case GL_COPY_WRITE_BUFFER_BINDING:
7171 case GL_SAMPLER_BINDING:
7172 case GL_READ_BUFFER:
7173 case GL_TEXTURE_BINDING_3D:
7174 case GL_TEXTURE_BINDING_2D_ARRAY:
7175 case GL_MAX_3D_TEXTURE_SIZE:
7176 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7177 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7178 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7179 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7180 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7181 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7182 case GL_MAX_VARYING_COMPONENTS:
7183 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7184 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7185 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7186 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7187 case GL_NUM_EXTENSIONS:
7188 case GL_MAJOR_VERSION:
7189 case GL_MINOR_VERSION:
7190 case GL_MAX_ELEMENTS_INDICES:
7191 case GL_MAX_ELEMENTS_VERTICES:
7192 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7193 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7194 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7195 case GL_UNPACK_IMAGE_HEIGHT:
7196 case GL_UNPACK_SKIP_IMAGES:
7197 {
7198 *type = GL_INT;
7199 *numParams = 1;
7200 return true;
7201 }
7202
7203 case GL_MAX_ELEMENT_INDEX:
7204 case GL_MAX_UNIFORM_BLOCK_SIZE:
7205 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7206 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7207 case GL_MAX_SERVER_WAIT_TIMEOUT:
7208 {
7209 *type = GL_INT_64_ANGLEX;
7210 *numParams = 1;
7211 return true;
7212 }
7213
7214 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7215 case GL_TRANSFORM_FEEDBACK_PAUSED:
7216 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7217 case GL_RASTERIZER_DISCARD:
7218 {
7219 *type = GL_BOOL;
7220 *numParams = 1;
7221 return true;
7222 }
7223
7224 case GL_MAX_TEXTURE_LOD_BIAS:
7225 {
7226 *type = GL_FLOAT;
7227 *numParams = 1;
7228 return true;
7229 }
7230 }
7231
7232 if (getExtensions().requestExtension)
7233 {
7234 switch (pname)
7235 {
7236 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7237 *type = GL_INT;
7238 *numParams = 1;
7239 return true;
7240 }
7241 }
7242
7243 if (getClientVersion() < Version(3, 1))
7244 {
7245 return false;
7246 }
7247
7248 switch (pname)
7249 {
7250 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7251 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7252 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7253 case GL_MAX_FRAMEBUFFER_WIDTH:
7254 case GL_MAX_FRAMEBUFFER_HEIGHT:
7255 case GL_MAX_FRAMEBUFFER_SAMPLES:
7256 case GL_MAX_SAMPLE_MASK_WORDS:
7257 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7258 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7259 case GL_MAX_INTEGER_SAMPLES:
7260 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7261 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7262 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7263 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7264 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7265 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7266 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7267 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7268 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7269 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7270 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7271 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7272 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7273 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7274 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7275 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7276 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7277 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7278 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7279 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7280 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7281 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7282 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7283 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7284 case GL_MAX_UNIFORM_LOCATIONS:
7285 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7286 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7287 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7288 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7289 case GL_MAX_IMAGE_UNITS:
7290 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7291 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7292 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7293 case GL_SHADER_STORAGE_BUFFER_BINDING:
7294 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7295 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7296 *type = GL_INT;
7297 *numParams = 1;
7298 return true;
7299 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7300 *type = GL_INT_64_ANGLEX;
7301 *numParams = 1;
7302 return true;
7303 case GL_SAMPLE_MASK:
7304 *type = GL_BOOL;
7305 *numParams = 1;
7306 return true;
7307 }
7308
7309 if (getExtensions().geometryShader)
7310 {
7311 switch (pname)
7312 {
7313 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7314 case GL_LAYER_PROVOKING_VERTEX_EXT:
7315 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7316 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7317 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7318 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7319 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7320 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7321 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7322 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7323 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7324 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7325 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7326 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7327 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7328 *type = GL_INT;
7329 *numParams = 1;
7330 return true;
7331 }
7332 }
7333
7334 return false;
7335}
7336
7337bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7338{
7339 if (getClientVersion() < Version(3, 0))
7340 {
7341 return false;
7342 }
7343
7344 switch (target)
7345 {
7346 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7347 case GL_UNIFORM_BUFFER_BINDING:
7348 {
7349 *type = GL_INT;
7350 *numParams = 1;
7351 return true;
7352 }
7353 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7354 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7355 case GL_UNIFORM_BUFFER_START:
7356 case GL_UNIFORM_BUFFER_SIZE:
7357 {
7358 *type = GL_INT_64_ANGLEX;
7359 *numParams = 1;
7360 return true;
7361 }
7362 }
7363
7364 if (getClientVersion() < Version(3, 1))
7365 {
7366 return false;
7367 }
7368
7369 switch (target)
7370 {
7371 case GL_IMAGE_BINDING_LAYERED:
7372 {
7373 *type = GL_BOOL;
7374 *numParams = 1;
7375 return true;
7376 }
7377 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7378 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7379 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7380 case GL_SHADER_STORAGE_BUFFER_BINDING:
7381 case GL_VERTEX_BINDING_BUFFER:
7382 case GL_VERTEX_BINDING_DIVISOR:
7383 case GL_VERTEX_BINDING_OFFSET:
7384 case GL_VERTEX_BINDING_STRIDE:
7385 case GL_SAMPLE_MASK_VALUE:
7386 case GL_IMAGE_BINDING_NAME:
7387 case GL_IMAGE_BINDING_LEVEL:
7388 case GL_IMAGE_BINDING_LAYER:
7389 case GL_IMAGE_BINDING_ACCESS:
7390 case GL_IMAGE_BINDING_FORMAT:
7391 {
7392 *type = GL_INT;
7393 *numParams = 1;
7394 return true;
7395 }
7396 case GL_ATOMIC_COUNTER_BUFFER_START:
7397 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7398 case GL_SHADER_STORAGE_BUFFER_START:
7399 case GL_SHADER_STORAGE_BUFFER_SIZE:
7400 {
7401 *type = GL_INT_64_ANGLEX;
7402 *numParams = 1;
7403 return true;
7404 }
7405 }
7406
7407 return false;
7408}
7409
7410Program *Context::getProgram(GLuint handle) const
7411{
7412 return mState.mShaderPrograms->getProgram(handle);
7413}
7414
7415Shader *Context::getShader(GLuint handle) const
7416{
7417 return mState.mShaderPrograms->getShader(handle);
7418}
7419
7420bool Context::isTextureGenerated(GLuint texture) const
7421{
7422 return mState.mTextures->isHandleGenerated(texture);
7423}
7424
7425bool Context::isBufferGenerated(GLuint buffer) const
7426{
7427 return mState.mBuffers->isHandleGenerated(buffer);
7428}
7429
7430bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7431{
7432 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7433}
7434
7435bool Context::isFramebufferGenerated(GLuint framebuffer) const
7436{
7437 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7438}
7439
7440bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7441{
7442 return mState.mPipelines->isHandleGenerated(pipeline);
7443}
7444
7445bool Context::usingDisplayTextureShareGroup() const
7446{
7447 return mDisplayTextureShareGroup;
7448}
7449
7450GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7451{
7452 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7453 internalformat == GL_DEPTH_STENCIL
7454 ? GL_DEPTH24_STENCIL8
7455 : internalformat;
7456}
7457
Jamie Madillc29968b2016-01-20 11:17:23 -05007458} // namespace gl