blob: c3880b2613f3e84f91583204224c2aba1da3e061 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070027#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030028#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080030#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050032#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050033#include "libANGLE/ResourceManager.h"
34#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050035#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050036#include "libANGLE/Texture.h"
37#include "libANGLE/TransformFeedback.h"
38#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040040#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030041#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040042#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040043#include "libANGLE/renderer/ContextImpl.h"
44#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040045#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040046#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000047
Geoff Langf6db0982015-08-25 13:04:00 -040048namespace
49{
50
Jamie Madillb6664922017-07-25 12:55:04 -040051#define ANGLE_HANDLE_ERR(X) \
52 handleError(X); \
53 return;
54#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
55
Ian Ewell3ffd78b2016-01-22 16:09:42 -050056template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050057std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030058 GLsizei numPaths,
59 const void *paths,
60 GLuint pathBase)
61{
62 std::vector<gl::Path *> ret;
63 ret.reserve(numPaths);
64
65 const auto *nameArray = static_cast<const T *>(paths);
66
67 for (GLsizei i = 0; i < numPaths; ++i)
68 {
69 const GLuint pathName = nameArray[i] + pathBase;
70
71 ret.push_back(resourceManager.getPath(pathName));
72 }
73
74 return ret;
75}
76
Geoff Lang4ddf5af2016-12-01 14:30:44 -050077std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030078 GLsizei numPaths,
79 GLenum pathNameType,
80 const void *paths,
81 GLuint pathBase)
82{
83 switch (pathNameType)
84 {
85 case GL_UNSIGNED_BYTE:
86 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_BYTE:
89 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_UNSIGNED_SHORT:
92 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_SHORT:
95 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_UNSIGNED_INT:
98 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_INT:
101 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
102 }
103
104 UNREACHABLE();
105 return std::vector<gl::Path *>();
106}
107
108template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400109gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110{
Geoff Lang2186c382016-10-14 10:54:54 -0400111 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500112
113 switch (pname)
114 {
115 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400116 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117 case GL_QUERY_RESULT_AVAILABLE_EXT:
118 {
119 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400120 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 if (!error.isError())
122 {
jchen10a99ed552017-09-22 08:10:32 +0800123 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125 return error;
126 }
127 default:
128 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500129 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill09463932018-04-04 05:26:59 -0400133void MarkTransformFeedbackBufferUsage(const gl::Context *context,
134 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Geoff Lang1a683462015-09-29 15:09:59 -0400138 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155gl::Version GetClientVersion(const egl::AttributeMap &attribs)
156{
157 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Geoff Langf6db0982015-08-25 13:04:00 -0400257} // anonymous namespace
258
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000259namespace gl
260{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000261
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400262Context::Context(rx::EGLImplFactory *implFactory,
263 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400264 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500265 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400266 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500267 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700268 const egl::DisplayExtensions &displayExtensions,
269 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500270 : mState(reinterpret_cast<ContextID>(this),
271 shareContext ? &shareContext->mState : nullptr,
272 shareTextures,
273 GetClientVersion(attribs),
274 &mGLState,
275 mCaps,
276 mTextureCaps,
277 mExtensions,
278 mLimitations),
279 mSkipValidation(GetNoError(attribs)),
280 mDisplayTextureShareGroup(shareTextures != nullptr),
281 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700282 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400283 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400284 mGLState(GetDebug(attribs),
285 GetBindGeneratesResource(attribs),
286 GetClientArraysEnabled(attribs),
287 GetRobustResourceInit(attribs),
288 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400289 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mClientType(EGL_OPENGL_ES_API),
291 mHasBeenCurrent(false),
292 mContextLost(false),
293 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700294 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500295 mResetStrategy(GetResetStrategy(attribs)),
296 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400297 mSurfacelessSupported(displayExtensions.surfacelessContext),
298 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400299 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
300 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500301 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400302 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400303 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400304 mScratchBuffer(1000u),
305 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000306{
Jamie Madill5b772312018-03-08 20:28:32 -0500307 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400308 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
309 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400310}
Jamie Madill5b772312018-03-08 20:28:32 -0500311
Geoff Lang33f11fb2018-05-07 13:42:47 -0400312void Context::initialize()
313{
314 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400315
Geoff Lang33f11fb2018-05-07 13:42:47 -0400316 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700317 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400318
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400319 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100320
Shannon Woods53a94a82014-06-24 15:20:36 -0400321 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400322
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000323 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400324 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000325 // and cube map texture state vectors respectively associated with them.
326 // In order that access to these initial textures not be lost, they are treated as texture
327 // objects all of whose names are 0.
328
Corentin Wallez99d492c2018-02-27 15:17:10 -0500329 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800330 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500331
Corentin Wallez99d492c2018-02-27 15:17:10 -0500332 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800333 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400334
Geoff Langeb66a6e2016-10-31 13:06:12 -0400335 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400336 {
337 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500338 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800339 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400340
Corentin Wallez99d492c2018-02-27 15:17:10 -0500341 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800342 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400343 }
Geoff Lang3b573612016-10-31 14:08:10 -0400344 if (getClientVersion() >= Version(3, 1))
345 {
346 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500347 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800348 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800349
Jiajia Qin6eafb042016-12-27 17:04:07 +0800350 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
351 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800352 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800353 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800354
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800355 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
356 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400357 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800358 }
Geoff Lang3b573612016-10-31 14:08:10 -0400359 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000360
Geoff Langb0f917f2017-12-05 13:41:54 -0500361 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400362 {
363 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500364 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800365 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400366 }
367
Geoff Langb0f917f2017-12-05 13:41:54 -0500368 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400369 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500370 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800371 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400372 }
373
Jamie Madill4928b7c2017-06-20 12:57:39 -0400374 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500375
Jamie Madill57a89722013-07-02 11:57:03 -0400376 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000377
Geoff Langeb66a6e2016-10-31 13:06:12 -0400378 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400379 {
380 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
381 // In the initial state, a default transform feedback object is bound and treated as
382 // a transform feedback object with a name of zero. That object is bound any time
383 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400384 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400385 }
Geoff Langc8058452014-02-03 12:04:11 -0500386
Corentin Wallez336129f2017-10-17 15:55:40 -0400387 for (auto type : angle::AllEnums<BufferBinding>())
388 {
389 bindBuffer(type, 0);
390 }
391
392 bindRenderbuffer(GL_RENDERBUFFER, 0);
393
394 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
395 {
396 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
397 }
398
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700399 // Initialize GLES1 renderer if appropriate.
400 if (getClientVersion() < Version(2, 0))
401 {
402 mGLES1Renderer.reset(new GLES1Renderer());
403 }
404
Jamie Madillad9f24e2016-02-12 09:27:24 -0500405 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400406 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500407 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500408 // No dirty objects.
409
410 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400411 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500412 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500413 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
414
415 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
416 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
417 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
418 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
419 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
420 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
422 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
423 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
424 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
425 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
426 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
427
428 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
429 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700430 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500431 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
432 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400433
Xinghua Cao10a4d432017-11-28 14:46:26 +0800434 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
435 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
436 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
437 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
438 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
439 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800440 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800441 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800442
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400443 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444}
445
Jamie Madill4928b7c2017-06-20 12:57:39 -0400446egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700448 if (mGLES1Renderer)
449 {
450 mGLES1Renderer->onDestroy(this, &mGLState);
451 }
452
Jamie Madille7b3fe22018-04-05 09:42:46 -0400453 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400454 ANGLE_TRY(releaseSurface(display));
455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400460 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461
Corentin Wallez80b24112015-08-25 16:41:57 -0400462 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400464 if (query.second != nullptr)
465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400469 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000470
Corentin Wallez80b24112015-08-25 16:41:57 -0400471 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400472 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 if (vertexArray.second)
474 {
475 vertexArray.second->onDestroy(this);
476 }
Jamie Madill57a89722013-07-02 11:57:03 -0400477 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400478 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400479
Corentin Wallez80b24112015-08-25 16:41:57 -0400480 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500481 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500482 if (transformFeedback.second != nullptr)
483 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500484 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500485 }
Geoff Langc8058452014-02-03 12:04:11 -0500486 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400487 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500488
Jamie Madill5b772312018-03-08 20:28:32 -0500489 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400490 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800491 if (zeroTexture.get() != nullptr)
492 {
493 ANGLE_TRY(zeroTexture->onDestroy(this));
494 zeroTexture.set(this, nullptr);
495 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400496 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497
Jamie Madill2f348d22017-06-05 10:50:59 -0400498 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500 mGLState.reset(this);
501
Jamie Madill6c1f6712017-02-14 19:08:04 -0500502 mState.mBuffers->release(this);
503 mState.mShaderPrograms->release(this);
504 mState.mTextures->release(this);
505 mState.mRenderbuffers->release(this);
506 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400507 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500508 mState.mPaths->release(this);
509 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800510 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511
Jamie Madill76e471e2017-10-21 09:56:01 -0400512 mImplementation->onDestroy(this);
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517Context::~Context()
518{
519}
520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522{
Jamie Madill61e16b42017-06-19 11:13:23 -0400523 mCurrentDisplay = display;
524
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 if (!mHasBeenCurrent)
526 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400527 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500529 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400530 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000531
Corentin Wallezc295e512017-01-27 17:47:50 -0500532 int width = 0;
533 int height = 0;
534 if (surface != nullptr)
535 {
536 width = surface->getWidth();
537 height = surface->getHeight();
538 }
539
540 mGLState.setViewportParams(0, 0, width, height);
541 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
543 mHasBeenCurrent = true;
544 }
545
Jamie Madill1b94d432015-08-07 13:23:23 -0400546 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400548 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400549
Jamie Madill4928b7c2017-06-20 12:57:39 -0400550 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500551
552 Framebuffer *newDefault = nullptr;
553 if (surface != nullptr)
554 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500556 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400557 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500558 }
559 else
560 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400561 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500562 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000563
Corentin Wallez37c39792015-08-20 14:19:46 -0400564 // Update default framebuffer, the binding of the previous default
565 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400566 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700567 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700569 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400570 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700571 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700573 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400574 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500575 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400576 }
Ian Ewell292f0052016-02-04 10:37:32 -0500577
578 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400579 mImplementation->onMakeCurrent(this);
580 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000581}
582
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400584{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400585 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400586
Geoff Langbf7b95d2018-05-01 16:48:21 -0400587 // Remove the default framebuffer
588 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 {
590 mGLState.setReadFramebufferBinding(nullptr);
591 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400592
593 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500594 {
595 mGLState.setDrawFramebufferBinding(nullptr);
596 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400597
598 if (defaultFramebuffer)
599 {
600 defaultFramebuffer->onDestroy(this);
601 delete defaultFramebuffer;
602 }
603
Corentin Wallezc295e512017-01-27 17:47:50 -0500604 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
605
606 if (mCurrentSurface)
607 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400608 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500609 mCurrentSurface = nullptr;
610 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400611
612 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400613}
614
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615GLuint Context::createBuffer()
616{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500617 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618}
619
620GLuint Context::createProgram()
621{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500622 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623}
624
Jiawei Shao385b3e02018-03-21 09:43:28 +0800625GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500627 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628}
629
630GLuint Context::createTexture()
631{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500632 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
635GLuint Context::createRenderbuffer()
636{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500637 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Brandon Jones59770802018-04-02 13:18:42 -0700640GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300641{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500642 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300643 if (resultOrError.isError())
644 {
645 handleError(resultOrError.getError());
646 return 0;
647 }
648 return resultOrError.getResult();
649}
650
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651// Returns an unused framebuffer name
652GLuint Context::createFramebuffer()
653{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500654 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655}
656
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500657void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500659 for (int i = 0; i < n; i++)
660 {
661 GLuint handle = mFenceNVHandleAllocator.allocate();
662 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
663 fences[i] = handle;
664 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665}
666
Yunchao Hea336b902017-08-02 16:05:21 +0800667GLuint Context::createProgramPipeline()
668{
669 return mState.mPipelines->createProgramPipeline();
670}
671
Jiawei Shao385b3e02018-03-21 09:43:28 +0800672GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800673{
674 UNIMPLEMENTED();
675 return 0u;
676}
677
James Darpinian4d9d4832018-03-13 12:43:28 -0700678void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679{
James Darpinian4d9d4832018-03-13 12:43:28 -0700680 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
681 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682 {
683 detachBuffer(buffer);
684 }
Jamie Madill893ab082014-05-16 16:56:10 -0400685
James Darpinian4d9d4832018-03-13 12:43:28 -0700686 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
689void Context::deleteShader(GLuint shader)
690{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
694void Context::deleteProgram(GLuint program)
695{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500696 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697}
698
699void Context::deleteTexture(GLuint texture)
700{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500701 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000702 {
703 detachTexture(texture);
704 }
705
Jamie Madill6c1f6712017-02-14 19:08:04 -0500706 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
709void Context::deleteRenderbuffer(GLuint renderbuffer)
710{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500711 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712 {
713 detachRenderbuffer(renderbuffer);
714 }
Jamie Madill893ab082014-05-16 16:56:10 -0400715
Jamie Madill6c1f6712017-02-14 19:08:04 -0500716 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717}
718
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400719void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400720{
721 // The spec specifies the underlying Fence object is not deleted until all current
722 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
723 // and since our API is currently designed for being called from a single thread, we can delete
724 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400725 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400726}
727
Yunchao Hea336b902017-08-02 16:05:21 +0800728void Context::deleteProgramPipeline(GLuint pipeline)
729{
730 if (mState.mPipelines->getProgramPipeline(pipeline))
731 {
732 detachProgramPipeline(pipeline);
733 }
734
735 mState.mPipelines->deleteObject(this, pipeline);
736}
737
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738void Context::deletePaths(GLuint first, GLsizei range)
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741}
742
Brandon Jones59770802018-04-02 13:18:42 -0700743bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746 if (pathObj == nullptr)
747 return false;
748
749 return pathObj->hasPathData();
750}
751
Brandon Jones59770802018-04-02 13:18:42 -0700752bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500754 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755}
756
Brandon Jones59770802018-04-02 13:18:42 -0700757void Context::pathCommands(GLuint path,
758 GLsizei numCommands,
759 const GLubyte *commands,
760 GLsizei numCoords,
761 GLenum coordType,
762 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500764 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300765
766 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
767}
768
Jamie Madill007530e2017-12-28 14:27:04 -0500769void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300770{
Jamie Madill007530e2017-12-28 14:27:04 -0500771 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300772
773 switch (pname)
774 {
775 case GL_PATH_STROKE_WIDTH_CHROMIUM:
776 pathObj->setStrokeWidth(value);
777 break;
778 case GL_PATH_END_CAPS_CHROMIUM:
779 pathObj->setEndCaps(static_cast<GLenum>(value));
780 break;
781 case GL_PATH_JOIN_STYLE_CHROMIUM:
782 pathObj->setJoinStyle(static_cast<GLenum>(value));
783 break;
784 case GL_PATH_MITER_LIMIT_CHROMIUM:
785 pathObj->setMiterLimit(value);
786 break;
787 case GL_PATH_STROKE_BOUND_CHROMIUM:
788 pathObj->setStrokeBound(value);
789 break;
790 default:
791 UNREACHABLE();
792 break;
793 }
794}
795
Jamie Madill007530e2017-12-28 14:27:04 -0500796void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797{
Jamie Madill007530e2017-12-28 14:27:04 -0500798 // TODO(jmadill): Should use proper clamping/casting.
799 pathParameterf(path, pname, static_cast<GLfloat>(value));
800}
801
802void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
803{
804 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300805
806 switch (pname)
807 {
808 case GL_PATH_STROKE_WIDTH_CHROMIUM:
809 *value = pathObj->getStrokeWidth();
810 break;
811 case GL_PATH_END_CAPS_CHROMIUM:
812 *value = static_cast<GLfloat>(pathObj->getEndCaps());
813 break;
814 case GL_PATH_JOIN_STYLE_CHROMIUM:
815 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
816 break;
817 case GL_PATH_MITER_LIMIT_CHROMIUM:
818 *value = pathObj->getMiterLimit();
819 break;
820 case GL_PATH_STROKE_BOUND_CHROMIUM:
821 *value = pathObj->getStrokeBound();
822 break;
823 default:
824 UNREACHABLE();
825 break;
826 }
827}
828
Jamie Madill007530e2017-12-28 14:27:04 -0500829void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
830{
831 GLfloat val = 0.0f;
832 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
833 if (value)
834 *value = static_cast<GLint>(val);
835}
836
Brandon Jones59770802018-04-02 13:18:42 -0700837void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300838{
839 mGLState.setPathStencilFunc(func, ref, mask);
840}
841
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842void Context::deleteFramebuffer(GLuint framebuffer)
843{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500844 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845 {
846 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500848
Jamie Madill6c1f6712017-02-14 19:08:04 -0500849 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850}
851
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500852void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500854 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500856 GLuint fence = fences[i];
857
858 FenceNV *fenceObject = nullptr;
859 if (mFenceNVMap.erase(fence, &fenceObject))
860 {
861 mFenceNVHandleAllocator.release(fence);
862 delete fenceObject;
863 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864 }
865}
866
Geoff Lang70d0f492015-12-10 17:45:46 -0500867Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870}
871
Jamie Madill570f7c82014-07-03 10:38:54 -0400872Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500874 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875}
876
Geoff Lang70d0f492015-12-10 17:45:46 -0500877Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000878{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500879 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000880}
881
Jamie Madill70b5bb02017-08-28 13:32:37 -0400882Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400883{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400884 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400885}
886
Jamie Madill57a89722013-07-02 11:57:03 -0400887VertexArray *Context::getVertexArray(GLuint handle) const
888{
Jamie Madill96a483b2017-06-27 16:49:21 -0400889 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400890}
891
Jamie Madilldc356042013-07-19 16:36:57 -0400892Sampler *Context::getSampler(GLuint handle) const
893{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500894 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400895}
896
Geoff Langc8058452014-02-03 12:04:11 -0500897TransformFeedback *Context::getTransformFeedback(GLuint handle) const
898{
Jamie Madill96a483b2017-06-27 16:49:21 -0400899 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500900}
901
Yunchao Hea336b902017-08-02 16:05:21 +0800902ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
903{
904 return mState.mPipelines->getProgramPipeline(handle);
905}
906
Geoff Lang70d0f492015-12-10 17:45:46 -0500907LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
908{
909 switch (identifier)
910 {
911 case GL_BUFFER:
912 return getBuffer(name);
913 case GL_SHADER:
914 return getShader(name);
915 case GL_PROGRAM:
916 return getProgram(name);
917 case GL_VERTEX_ARRAY:
918 return getVertexArray(name);
919 case GL_QUERY:
920 return getQuery(name);
921 case GL_TRANSFORM_FEEDBACK:
922 return getTransformFeedback(name);
923 case GL_SAMPLER:
924 return getSampler(name);
925 case GL_TEXTURE:
926 return getTexture(name);
927 case GL_RENDERBUFFER:
928 return getRenderbuffer(name);
929 case GL_FRAMEBUFFER:
930 return getFramebuffer(name);
931 default:
932 UNREACHABLE();
933 return nullptr;
934 }
935}
936
937LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
938{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400939 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500940}
941
Martin Radev9d901792016-07-15 15:58:58 +0300942void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
943{
944 LabeledObject *object = getLabeledObject(identifier, name);
945 ASSERT(object != nullptr);
946
947 std::string labelName = GetObjectLabelFromPointer(length, label);
948 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400949
950 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
951 // specified object is active until we do this.
952 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300953}
954
955void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
956{
957 LabeledObject *object = getLabeledObjectFromPtr(ptr);
958 ASSERT(object != nullptr);
959
960 std::string labelName = GetObjectLabelFromPointer(length, label);
961 object->setLabel(labelName);
962}
963
964void Context::getObjectLabel(GLenum identifier,
965 GLuint name,
966 GLsizei bufSize,
967 GLsizei *length,
968 GLchar *label) const
969{
970 LabeledObject *object = getLabeledObject(identifier, name);
971 ASSERT(object != nullptr);
972
973 const std::string &objectLabel = object->getLabel();
974 GetObjectLabelBase(objectLabel, bufSize, length, label);
975}
976
977void Context::getObjectPtrLabel(const void *ptr,
978 GLsizei bufSize,
979 GLsizei *length,
980 GLchar *label) const
981{
982 LabeledObject *object = getLabeledObjectFromPtr(ptr);
983 ASSERT(object != nullptr);
984
985 const std::string &objectLabel = object->getLabel();
986 GetObjectLabelBase(objectLabel, bufSize, length, label);
987}
988
Jamie Madilldc356042013-07-19 16:36:57 -0400989bool Context::isSampler(GLuint samplerName) const
990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500991 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400992}
993
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800994void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500996 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000997
Jamie Madilldedd7b92014-11-05 16:30:36 -0500998 if (handle == 0)
999 {
1000 texture = mZeroTextures[target].get();
1001 }
1002 else
1003 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001004 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001005 }
1006
1007 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001008 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001009}
1010
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001011void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001013 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1014 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001015 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016}
1017
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001018void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001019{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001020 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1021 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001022 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023}
1024
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001025void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001026{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001027 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001028 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001029}
1030
Shao80957d92017-02-20 21:25:59 +08001031void Context::bindVertexBuffer(GLuint bindingIndex,
1032 GLuint bufferHandle,
1033 GLintptr offset,
1034 GLsizei stride)
1035{
1036 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001037 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001038}
1039
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001041{
Geoff Lang76b10c92014-09-05 16:28:14 -04001042 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001043 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001044 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001045 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001046}
1047
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001048void Context::bindImageTexture(GLuint unit,
1049 GLuint texture,
1050 GLint level,
1051 GLboolean layered,
1052 GLint layer,
1053 GLenum access,
1054 GLenum format)
1055{
1056 Texture *tex = mState.mTextures->getTexture(texture);
1057 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1058}
1059
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001060void Context::useProgram(GLuint program)
1061{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001062 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001063}
1064
Jiajia Qin5451d532017-11-16 17:16:34 +08001065void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1066{
1067 UNIMPLEMENTED();
1068}
1069
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001070void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001071{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001072 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001073 TransformFeedback *transformFeedback =
1074 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001075 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001076}
1077
Yunchao Hea336b902017-08-02 16:05:21 +08001078void Context::bindProgramPipeline(GLuint pipelineHandle)
1079{
1080 ProgramPipeline *pipeline =
1081 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1082 mGLState.setProgramPipelineBinding(this, pipeline);
1083}
1084
Corentin Wallezad3ae902018-03-09 13:40:42 -05001085void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001087 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001088 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Geoff Lang5aad9672014-09-08 11:10:42 -04001090 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001091 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001092
1093 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001094 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095}
1096
Corentin Wallezad3ae902018-03-09 13:40:42 -05001097void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001099 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001100 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103
Geoff Lang5aad9672014-09-08 11:10:42 -04001104 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001105 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106}
1107
Corentin Wallezad3ae902018-03-09 13:40:42 -05001108void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001109{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001110 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111
1112 Query *queryObject = getQuery(id, true, target);
1113 ASSERT(queryObject);
1114
Jamie Madillf0e04492017-08-26 15:28:42 -04001115 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116}
1117
Corentin Wallezad3ae902018-03-09 13:40:42 -05001118void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001119{
1120 switch (pname)
1121 {
1122 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001123 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124 break;
1125 case GL_QUERY_COUNTER_BITS_EXT:
1126 switch (target)
1127 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001128 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1130 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001131 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132 params[0] = getExtensions().queryCounterBitsTimestamp;
1133 break;
1134 default:
1135 UNREACHABLE();
1136 params[0] = 0;
1137 break;
1138 }
1139 break;
1140 default:
1141 UNREACHABLE();
1142 return;
1143 }
1144}
1145
Corentin Wallezad3ae902018-03-09 13:40:42 -05001146void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001147 GLenum pname,
1148 GLsizei bufSize,
1149 GLsizei *length,
1150 GLint *params)
1151{
1152 getQueryiv(target, pname, params);
1153}
1154
Geoff Lang2186c382016-10-14 10:54:54 -04001155void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001156{
Geoff Lang2186c382016-10-14 10:54:54 -04001157 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158}
1159
Brandon Jones59770802018-04-02 13:18:42 -07001160void Context::getQueryObjectivRobust(GLuint id,
1161 GLenum pname,
1162 GLsizei bufSize,
1163 GLsizei *length,
1164 GLint *params)
1165{
1166 getQueryObjectiv(id, pname, params);
1167}
1168
Geoff Lang2186c382016-10-14 10:54:54 -04001169void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001170{
Geoff Lang2186c382016-10-14 10:54:54 -04001171 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172}
1173
Brandon Jones59770802018-04-02 13:18:42 -07001174void Context::getQueryObjectuivRobust(GLuint id,
1175 GLenum pname,
1176 GLsizei bufSize,
1177 GLsizei *length,
1178 GLuint *params)
1179{
1180 getQueryObjectuiv(id, pname, params);
1181}
1182
Geoff Lang2186c382016-10-14 10:54:54 -04001183void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001184{
Geoff Lang2186c382016-10-14 10:54:54 -04001185 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186}
1187
Brandon Jones59770802018-04-02 13:18:42 -07001188void Context::getQueryObjecti64vRobust(GLuint id,
1189 GLenum pname,
1190 GLsizei bufSize,
1191 GLsizei *length,
1192 GLint64 *params)
1193{
1194 getQueryObjecti64v(id, pname, params);
1195}
1196
Geoff Lang2186c382016-10-14 10:54:54 -04001197void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198{
Geoff Lang2186c382016-10-14 10:54:54 -04001199 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200}
1201
Brandon Jones59770802018-04-02 13:18:42 -07001202void Context::getQueryObjectui64vRobust(GLuint id,
1203 GLenum pname,
1204 GLsizei bufSize,
1205 GLsizei *length,
1206 GLuint64 *params)
1207{
1208 getQueryObjectui64v(id, pname, params);
1209}
1210
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001211Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001213 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madill2f348d22017-06-05 10:50:59 -04001216FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Jamie Madill96a483b2017-06-27 16:49:21 -04001218 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219}
1220
Corentin Wallezad3ae902018-03-09 13:40:42 -05001221Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222{
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001225 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001227
1228 Query *query = mQueryMap.query(handle);
1229 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001231 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001232 query = new Query(mImplementation->createQuery(type), handle);
1233 query->addRef();
1234 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001235 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237}
1238
Geoff Lang70d0f492015-12-10 17:45:46 -05001239Query *Context::getQuery(GLuint handle) const
1240{
Jamie Madill96a483b2017-06-27 16:49:21 -04001241 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001242}
1243
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001244Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001245{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001246 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1247 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001248}
1249
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001250Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001252 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001253}
1254
Geoff Lang492a7e42014-11-05 13:27:06 -05001255Compiler *Context::getCompiler() const
1256{
Jamie Madill2f348d22017-06-05 10:50:59 -04001257 if (mCompiler.get() == nullptr)
1258 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001259 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001260 }
1261 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001262}
1263
Jamie Madillc1d770e2017-04-13 17:31:24 -04001264void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265{
1266 switch (pname)
1267 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001268 case GL_SHADER_COMPILER:
1269 *params = GL_TRUE;
1270 break;
1271 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1272 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1273 break;
1274 default:
1275 mGLState.getBooleanv(pname, params);
1276 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001277 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278}
1279
Jamie Madillc1d770e2017-04-13 17:31:24 -04001280void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281{
Shannon Woods53a94a82014-06-24 15:20:36 -04001282 // Queries about context capabilities and maximums are answered by Context.
1283 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284 switch (pname)
1285 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001286 case GL_ALIASED_LINE_WIDTH_RANGE:
1287 params[0] = mCaps.minAliasedLineWidth;
1288 params[1] = mCaps.maxAliasedLineWidth;
1289 break;
1290 case GL_ALIASED_POINT_SIZE_RANGE:
1291 params[0] = mCaps.minAliasedPointSize;
1292 params[1] = mCaps.maxAliasedPointSize;
1293 break;
1294 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1295 ASSERT(mExtensions.textureFilterAnisotropic);
1296 *params = mExtensions.maxTextureAnisotropy;
1297 break;
1298 case GL_MAX_TEXTURE_LOD_BIAS:
1299 *params = mCaps.maxLODBias;
1300 break;
1301
1302 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1303 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1304 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001305 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1306 // GLES1 constants for modelview/projection matrix.
1307 if (getClientVersion() < Version(2, 0))
1308 {
1309 mGLState.getFloatv(pname, params);
1310 }
1311 else
1312 {
1313 ASSERT(mExtensions.pathRendering);
1314 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1315 memcpy(params, m, 16 * sizeof(GLfloat));
1316 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001317 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001318 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001319
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 default:
1321 mGLState.getFloatv(pname, params);
1322 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324}
1325
Jamie Madillc1d770e2017-04-13 17:31:24 -04001326void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327{
Shannon Woods53a94a82014-06-24 15:20:36 -04001328 // Queries about context capabilities and maximums are answered by Context.
1329 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001330
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 switch (pname)
1332 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001333 case GL_MAX_VERTEX_ATTRIBS:
1334 *params = mCaps.maxVertexAttributes;
1335 break;
1336 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1337 *params = mCaps.maxVertexUniformVectors;
1338 break;
1339 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001340 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001341 break;
1342 case GL_MAX_VARYING_VECTORS:
1343 *params = mCaps.maxVaryingVectors;
1344 break;
1345 case GL_MAX_VARYING_COMPONENTS:
1346 *params = mCaps.maxVertexOutputComponents;
1347 break;
1348 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1349 *params = mCaps.maxCombinedTextureImageUnits;
1350 break;
1351 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001352 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001353 break;
1354 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001355 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1358 *params = mCaps.maxFragmentUniformVectors;
1359 break;
1360 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001361 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001362 break;
1363 case GL_MAX_RENDERBUFFER_SIZE:
1364 *params = mCaps.maxRenderbufferSize;
1365 break;
1366 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1367 *params = mCaps.maxColorAttachments;
1368 break;
1369 case GL_MAX_DRAW_BUFFERS_EXT:
1370 *params = mCaps.maxDrawBuffers;
1371 break;
1372 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1373 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1374 case GL_SUBPIXEL_BITS:
1375 *params = 4;
1376 break;
1377 case GL_MAX_TEXTURE_SIZE:
1378 *params = mCaps.max2DTextureSize;
1379 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001380 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1381 *params = mCaps.maxRectangleTextureSize;
1382 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001383 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1384 *params = mCaps.maxCubeMapTextureSize;
1385 break;
1386 case GL_MAX_3D_TEXTURE_SIZE:
1387 *params = mCaps.max3DTextureSize;
1388 break;
1389 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1390 *params = mCaps.maxArrayTextureLayers;
1391 break;
1392 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1393 *params = mCaps.uniformBufferOffsetAlignment;
1394 break;
1395 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1396 *params = mCaps.maxUniformBufferBindings;
1397 break;
1398 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001399 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001400 break;
1401 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001402 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001403 break;
1404 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1405 *params = mCaps.maxCombinedTextureImageUnits;
1406 break;
1407 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1408 *params = mCaps.maxVertexOutputComponents;
1409 break;
1410 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1411 *params = mCaps.maxFragmentInputComponents;
1412 break;
1413 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1414 *params = mCaps.minProgramTexelOffset;
1415 break;
1416 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1417 *params = mCaps.maxProgramTexelOffset;
1418 break;
1419 case GL_MAJOR_VERSION:
1420 *params = getClientVersion().major;
1421 break;
1422 case GL_MINOR_VERSION:
1423 *params = getClientVersion().minor;
1424 break;
1425 case GL_MAX_ELEMENTS_INDICES:
1426 *params = mCaps.maxElementsIndices;
1427 break;
1428 case GL_MAX_ELEMENTS_VERTICES:
1429 *params = mCaps.maxElementsVertices;
1430 break;
1431 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1432 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1433 break;
1434 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1435 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1436 break;
1437 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1438 *params = mCaps.maxTransformFeedbackSeparateComponents;
1439 break;
1440 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1441 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1442 break;
1443 case GL_MAX_SAMPLES_ANGLE:
1444 *params = mCaps.maxSamples;
1445 break;
1446 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001447 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001448 params[0] = mCaps.maxViewportWidth;
1449 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001450 }
1451 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 case GL_COMPRESSED_TEXTURE_FORMATS:
1453 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1454 params);
1455 break;
1456 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1457 *params = mResetStrategy;
1458 break;
1459 case GL_NUM_SHADER_BINARY_FORMATS:
1460 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1461 break;
1462 case GL_SHADER_BINARY_FORMATS:
1463 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1464 break;
1465 case GL_NUM_PROGRAM_BINARY_FORMATS:
1466 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1467 break;
1468 case GL_PROGRAM_BINARY_FORMATS:
1469 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1470 break;
1471 case GL_NUM_EXTENSIONS:
1472 *params = static_cast<GLint>(mExtensionStrings.size());
1473 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001474
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 // GL_KHR_debug
1476 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1477 *params = mExtensions.maxDebugMessageLength;
1478 break;
1479 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1480 *params = mExtensions.maxDebugLoggedMessages;
1481 break;
1482 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1483 *params = mExtensions.maxDebugGroupStackDepth;
1484 break;
1485 case GL_MAX_LABEL_LENGTH:
1486 *params = mExtensions.maxLabelLength;
1487 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001488
Martin Radeve5285d22017-07-14 16:23:53 +03001489 // GL_ANGLE_multiview
1490 case GL_MAX_VIEWS_ANGLE:
1491 *params = mExtensions.maxViews;
1492 break;
1493
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 // GL_EXT_disjoint_timer_query
1495 case GL_GPU_DISJOINT_EXT:
1496 *params = mImplementation->getGPUDisjoint();
1497 break;
1498 case GL_MAX_FRAMEBUFFER_WIDTH:
1499 *params = mCaps.maxFramebufferWidth;
1500 break;
1501 case GL_MAX_FRAMEBUFFER_HEIGHT:
1502 *params = mCaps.maxFramebufferHeight;
1503 break;
1504 case GL_MAX_FRAMEBUFFER_SAMPLES:
1505 *params = mCaps.maxFramebufferSamples;
1506 break;
1507 case GL_MAX_SAMPLE_MASK_WORDS:
1508 *params = mCaps.maxSampleMaskWords;
1509 break;
1510 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1511 *params = mCaps.maxColorTextureSamples;
1512 break;
1513 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1514 *params = mCaps.maxDepthTextureSamples;
1515 break;
1516 case GL_MAX_INTEGER_SAMPLES:
1517 *params = mCaps.maxIntegerSamples;
1518 break;
1519 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1520 *params = mCaps.maxVertexAttribRelativeOffset;
1521 break;
1522 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1523 *params = mCaps.maxVertexAttribBindings;
1524 break;
1525 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1526 *params = mCaps.maxVertexAttribStride;
1527 break;
1528 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001529 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001530 break;
1531 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001532 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001533 break;
1534 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001535 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 break;
1537 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001538 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001539 break;
1540 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001541 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001544 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 break;
1546 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001547 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001548 break;
1549 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001550 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001551 break;
1552 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1553 *params = mCaps.minProgramTextureGatherOffset;
1554 break;
1555 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1556 *params = mCaps.maxProgramTextureGatherOffset;
1557 break;
1558 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1559 *params = mCaps.maxComputeWorkGroupInvocations;
1560 break;
1561 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001562 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001563 break;
1564 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001565 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 break;
1567 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1568 *params = mCaps.maxComputeSharedMemorySize;
1569 break;
1570 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001571 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001572 break;
1573 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001574 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001575 break;
1576 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001577 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 break;
1579 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001580 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001583 *params =
1584 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001587 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001588 break;
1589 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1590 *params = mCaps.maxCombinedShaderOutputResources;
1591 break;
1592 case GL_MAX_UNIFORM_LOCATIONS:
1593 *params = mCaps.maxUniformLocations;
1594 break;
1595 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1596 *params = mCaps.maxAtomicCounterBufferBindings;
1597 break;
1598 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1599 *params = mCaps.maxAtomicCounterBufferSize;
1600 break;
1601 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1602 *params = mCaps.maxCombinedAtomicCounterBuffers;
1603 break;
1604 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1605 *params = mCaps.maxCombinedAtomicCounters;
1606 break;
1607 case GL_MAX_IMAGE_UNITS:
1608 *params = mCaps.maxImageUnits;
1609 break;
1610 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1611 *params = mCaps.maxCombinedImageUniforms;
1612 break;
1613 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1614 *params = mCaps.maxShaderStorageBufferBindings;
1615 break;
1616 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1617 *params = mCaps.maxCombinedShaderStorageBlocks;
1618 break;
1619 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1620 *params = mCaps.shaderStorageBufferOffsetAlignment;
1621 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001622
1623 // GL_EXT_geometry_shader
1624 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1625 *params = mCaps.maxFramebufferLayers;
1626 break;
1627 case GL_LAYER_PROVOKING_VERTEX_EXT:
1628 *params = mCaps.layerProvokingVertex;
1629 break;
1630 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001631 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001632 break;
1633 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001634 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001635 break;
1636 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params =
1638 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001639 break;
1640 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1641 *params = mCaps.maxGeometryInputComponents;
1642 break;
1643 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1644 *params = mCaps.maxGeometryOutputComponents;
1645 break;
1646 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1647 *params = mCaps.maxGeometryOutputVertices;
1648 break;
1649 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1650 *params = mCaps.maxGeometryTotalOutputComponents;
1651 break;
1652 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1653 *params = mCaps.maxGeometryShaderInvocations;
1654 break;
1655 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001656 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001657 break;
1658 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001659 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001660 break;
1661 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001663 break;
1664 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001666 break;
1667 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001668 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001669 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001670 // GLES1 emulation: Caps queries
1671 case GL_MAX_TEXTURE_UNITS:
1672 *params = mCaps.maxMultitextureUnits;
1673 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001674 case GL_MAX_MODELVIEW_STACK_DEPTH:
1675 *params = mCaps.maxModelviewMatrixStackDepth;
1676 break;
1677 case GL_MAX_PROJECTION_STACK_DEPTH:
1678 *params = mCaps.maxProjectionMatrixStackDepth;
1679 break;
1680 case GL_MAX_TEXTURE_STACK_DEPTH:
1681 *params = mCaps.maxTextureMatrixStackDepth;
1682 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001683 case GL_MAX_LIGHTS:
1684 *params = mCaps.maxLights;
1685 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001686 case GL_MAX_CLIP_PLANES:
1687 *params = mCaps.maxClipPlanes;
1688 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001689 // GLES1 emulation: Vertex attribute queries
1690 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1691 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1692 case GL_COLOR_ARRAY_BUFFER_BINDING:
1693 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1694 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1695 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1696 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1697 break;
1698 case GL_VERTEX_ARRAY_STRIDE:
1699 case GL_NORMAL_ARRAY_STRIDE:
1700 case GL_COLOR_ARRAY_STRIDE:
1701 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1702 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1703 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1704 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1705 break;
1706 case GL_VERTEX_ARRAY_SIZE:
1707 case GL_COLOR_ARRAY_SIZE:
1708 case GL_TEXTURE_COORD_ARRAY_SIZE:
1709 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1710 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1711 break;
1712 case GL_VERTEX_ARRAY_TYPE:
1713 case GL_COLOR_ARRAY_TYPE:
1714 case GL_NORMAL_ARRAY_TYPE:
1715 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1716 case GL_TEXTURE_COORD_ARRAY_TYPE:
1717 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1718 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1719 break;
1720
Jamie Madill231c7f52017-04-26 13:45:37 -04001721 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001722 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001723 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001724 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001725}
1726
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001727void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001728{
Shannon Woods53a94a82014-06-24 15:20:36 -04001729 // Queries about context capabilities and maximums are answered by Context.
1730 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001731 switch (pname)
1732 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 case GL_MAX_ELEMENT_INDEX:
1734 *params = mCaps.maxElementIndex;
1735 break;
1736 case GL_MAX_UNIFORM_BLOCK_SIZE:
1737 *params = mCaps.maxUniformBlockSize;
1738 break;
1739 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001740 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001741 break;
1742 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001743 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001744 break;
1745 case GL_MAX_SERVER_WAIT_TIMEOUT:
1746 *params = mCaps.maxServerWaitTimeout;
1747 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001748
Jamie Madill231c7f52017-04-26 13:45:37 -04001749 // GL_EXT_disjoint_timer_query
1750 case GL_TIMESTAMP_EXT:
1751 *params = mImplementation->getTimestamp();
1752 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001753
Jamie Madill231c7f52017-04-26 13:45:37 -04001754 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1755 *params = mCaps.maxShaderStorageBlockSize;
1756 break;
1757 default:
1758 UNREACHABLE();
1759 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001760 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001761}
1762
Geoff Lang70d0f492015-12-10 17:45:46 -05001763void Context::getPointerv(GLenum pname, void **params) const
1764{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001765 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001766}
1767
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001768void Context::getPointervRobustANGLERobust(GLenum pname,
1769 GLsizei bufSize,
1770 GLsizei *length,
1771 void **params)
1772{
1773 UNIMPLEMENTED();
1774}
1775
Martin Radev66fb8202016-07-28 11:45:20 +03001776void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001777{
Shannon Woods53a94a82014-06-24 15:20:36 -04001778 // Queries about context capabilities and maximums are answered by Context.
1779 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001780
1781 GLenum nativeType;
1782 unsigned int numParams;
1783 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1784 ASSERT(queryStatus);
1785
1786 if (nativeType == GL_INT)
1787 {
1788 switch (target)
1789 {
1790 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1791 ASSERT(index < 3u);
1792 *data = mCaps.maxComputeWorkGroupCount[index];
1793 break;
1794 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1795 ASSERT(index < 3u);
1796 *data = mCaps.maxComputeWorkGroupSize[index];
1797 break;
1798 default:
1799 mGLState.getIntegeri_v(target, index, data);
1800 }
1801 }
1802 else
1803 {
1804 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1805 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001806}
1807
Brandon Jones59770802018-04-02 13:18:42 -07001808void Context::getIntegeri_vRobust(GLenum target,
1809 GLuint index,
1810 GLsizei bufSize,
1811 GLsizei *length,
1812 GLint *data)
1813{
1814 getIntegeri_v(target, index, data);
1815}
1816
Martin Radev66fb8202016-07-28 11:45:20 +03001817void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001818{
Shannon Woods53a94a82014-06-24 15:20:36 -04001819 // Queries about context capabilities and maximums are answered by Context.
1820 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001821
1822 GLenum nativeType;
1823 unsigned int numParams;
1824 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1825 ASSERT(queryStatus);
1826
1827 if (nativeType == GL_INT_64_ANGLEX)
1828 {
1829 mGLState.getInteger64i_v(target, index, data);
1830 }
1831 else
1832 {
1833 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1834 }
1835}
1836
Brandon Jones59770802018-04-02 13:18:42 -07001837void Context::getInteger64i_vRobust(GLenum target,
1838 GLuint index,
1839 GLsizei bufSize,
1840 GLsizei *length,
1841 GLint64 *data)
1842{
1843 getInteger64i_v(target, index, data);
1844}
1845
Martin Radev66fb8202016-07-28 11:45:20 +03001846void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1847{
1848 // Queries about context capabilities and maximums are answered by Context.
1849 // Queries about current GL state values are answered by State.
1850
1851 GLenum nativeType;
1852 unsigned int numParams;
1853 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1854 ASSERT(queryStatus);
1855
1856 if (nativeType == GL_BOOL)
1857 {
1858 mGLState.getBooleani_v(target, index, data);
1859 }
1860 else
1861 {
1862 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1863 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001864}
1865
Brandon Jones59770802018-04-02 13:18:42 -07001866void Context::getBooleani_vRobust(GLenum target,
1867 GLuint index,
1868 GLsizei bufSize,
1869 GLsizei *length,
1870 GLboolean *data)
1871{
1872 getBooleani_v(target, index, data);
1873}
1874
Corentin Wallez336129f2017-10-17 15:55:40 -04001875void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001876{
1877 Buffer *buffer = mGLState.getTargetBuffer(target);
1878 QueryBufferParameteriv(buffer, pname, params);
1879}
1880
Brandon Jones59770802018-04-02 13:18:42 -07001881void Context::getBufferParameterivRobust(BufferBinding target,
1882 GLenum pname,
1883 GLsizei bufSize,
1884 GLsizei *length,
1885 GLint *params)
1886{
1887 getBufferParameteriv(target, pname, params);
1888}
1889
He Yunchao010e4db2017-03-03 14:22:06 +08001890void Context::getFramebufferAttachmentParameteriv(GLenum target,
1891 GLenum attachment,
1892 GLenum pname,
1893 GLint *params)
1894{
1895 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001896 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001897}
1898
Brandon Jones59770802018-04-02 13:18:42 -07001899void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1900 GLenum attachment,
1901 GLenum pname,
1902 GLsizei bufSize,
1903 GLsizei *length,
1904 GLint *params)
1905{
1906 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1907}
1908
He Yunchao010e4db2017-03-03 14:22:06 +08001909void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1910{
1911 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1912 QueryRenderbufferiv(this, renderbuffer, pname, params);
1913}
1914
Brandon Jones59770802018-04-02 13:18:42 -07001915void Context::getRenderbufferParameterivRobust(GLenum target,
1916 GLenum pname,
1917 GLsizei bufSize,
1918 GLsizei *length,
1919 GLint *params)
1920{
1921 getRenderbufferParameteriv(target, pname, params);
1922}
1923
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001924void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001925{
1926 Texture *texture = getTargetTexture(target);
1927 QueryTexParameterfv(texture, pname, params);
1928}
1929
Brandon Jones59770802018-04-02 13:18:42 -07001930void Context::getTexParameterfvRobust(TextureType target,
1931 GLenum pname,
1932 GLsizei bufSize,
1933 GLsizei *length,
1934 GLfloat *params)
1935{
1936 getTexParameterfv(target, pname, params);
1937}
1938
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001939void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001940{
1941 Texture *texture = getTargetTexture(target);
1942 QueryTexParameteriv(texture, pname, params);
1943}
Jiajia Qin5451d532017-11-16 17:16:34 +08001944
Brandon Jones59770802018-04-02 13:18:42 -07001945void Context::getTexParameterivRobust(TextureType target,
1946 GLenum pname,
1947 GLsizei bufSize,
1948 GLsizei *length,
1949 GLint *params)
1950{
1951 getTexParameteriv(target, pname, params);
1952}
1953
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001954void Context::getTexParameterIivRobust(TextureType target,
1955 GLenum pname,
1956 GLsizei bufSize,
1957 GLsizei *length,
1958 GLint *params)
1959{
1960 UNIMPLEMENTED();
1961}
1962
1963void Context::getTexParameterIuivRobust(TextureType target,
1964 GLenum pname,
1965 GLsizei bufSize,
1966 GLsizei *length,
1967 GLuint *params)
1968{
1969 UNIMPLEMENTED();
1970}
1971
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001972void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001973{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001974 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001975 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001976}
1977
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001978void Context::getTexLevelParameterivRobust(TextureTarget target,
1979 GLint level,
1980 GLenum pname,
1981 GLsizei bufSize,
1982 GLsizei *length,
1983 GLint *params)
1984{
1985 UNIMPLEMENTED();
1986}
1987
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001988void Context::getTexLevelParameterfv(TextureTarget target,
1989 GLint level,
1990 GLenum pname,
1991 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001992{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001993 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001994 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001995}
1996
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001997void Context::getTexLevelParameterfvRobust(TextureTarget target,
1998 GLint level,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 GLsizei *length,
2002 GLfloat *params)
2003{
2004 UNIMPLEMENTED();
2005}
2006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002007void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002008{
2009 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002010 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002011 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002012}
2013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002014void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002015{
2016 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002017 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002018 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::texParameterfvRobust(TextureType target,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 const GLfloat *params)
2025{
2026 texParameterfv(target, pname, params);
2027}
2028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002029void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002030{
2031 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002032 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002033 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002034}
2035
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002036void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002037{
2038 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002039 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002040 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002041}
2042
Brandon Jones59770802018-04-02 13:18:42 -07002043void Context::texParameterivRobust(TextureType target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 const GLint *params)
2047{
2048 texParameteriv(target, pname, params);
2049}
2050
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002051void Context::texParameterIivRobust(TextureType target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 const GLint *params)
2055{
2056 UNIMPLEMENTED();
2057}
2058
2059void Context::texParameterIuivRobust(TextureType target,
2060 GLenum pname,
2061 GLsizei bufSize,
2062 const GLuint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
Jamie Madill493f9572018-05-24 19:52:15 -04002067void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002068{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002069 // No-op if zero count
2070 if (count == 0)
2071 {
2072 return;
2073 }
2074
Jamie Madill05b35b22017-10-03 09:01:44 -04002075 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002076 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002077 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002078}
2079
Jamie Madill493f9572018-05-24 19:52:15 -04002080void Context::drawArraysInstanced(PrimitiveMode mode,
2081 GLint first,
2082 GLsizei count,
2083 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002084{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002085 // No-op if zero count
2086 if (count == 0 || instanceCount == 0)
2087 {
2088 return;
2089 }
2090
Jamie Madill05b35b22017-10-03 09:01:44 -04002091 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002092 ANGLE_CONTEXT_TRY(
2093 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002094 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2095 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002096}
2097
Jamie Madill493f9572018-05-24 19:52:15 -04002098void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002099{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002100 // No-op if zero count
2101 if (count == 0)
2102 {
2103 return;
2104 }
2105
Jamie Madill05b35b22017-10-03 09:01:44 -04002106 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002107 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002108}
2109
Jamie Madill493f9572018-05-24 19:52:15 -04002110void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002111 GLsizei count,
2112 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002113 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002114 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002115{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002116 // No-op if zero count
2117 if (count == 0 || instances == 0)
2118 {
2119 return;
2120 }
2121
Jamie Madill05b35b22017-10-03 09:01:44 -04002122 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002123 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002124 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002125}
2126
Jamie Madill493f9572018-05-24 19:52:15 -04002127void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002128 GLuint start,
2129 GLuint end,
2130 GLsizei count,
2131 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002132 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002133{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002134 // No-op if zero count
2135 if (count == 0)
2136 {
2137 return;
2138 }
2139
Jamie Madill05b35b22017-10-03 09:01:44 -04002140 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002141 ANGLE_CONTEXT_TRY(
2142 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002143}
2144
Jamie Madill493f9572018-05-24 19:52:15 -04002145void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002146{
Jamie Madill05b35b22017-10-03 09:01:44 -04002147 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002148 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002149}
2150
Jamie Madill493f9572018-05-24 19:52:15 -04002151void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002152{
Jamie Madill05b35b22017-10-03 09:01:44 -04002153 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002154 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002155}
2156
Jamie Madill675fe712016-12-19 13:07:54 -05002157void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002158{
Jamie Madillafa02a22017-11-23 12:57:38 -05002159 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002160}
2161
Jamie Madill675fe712016-12-19 13:07:54 -05002162void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002163{
Jamie Madillafa02a22017-11-23 12:57:38 -05002164 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002165}
2166
Austin Kinross6ee1e782015-05-29 17:05:37 -07002167void Context::insertEventMarker(GLsizei length, const char *marker)
2168{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002169 ASSERT(mImplementation);
2170 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002171}
2172
2173void Context::pushGroupMarker(GLsizei length, const char *marker)
2174{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002175 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002176
2177 if (marker == nullptr)
2178 {
2179 // From the EXT_debug_marker spec,
2180 // "If <marker> is null then an empty string is pushed on the stack."
2181 mImplementation->pushGroupMarker(length, "");
2182 }
2183 else
2184 {
2185 mImplementation->pushGroupMarker(length, marker);
2186 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002187}
2188
2189void Context::popGroupMarker()
2190{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002191 ASSERT(mImplementation);
2192 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002193}
2194
Geoff Langd8605522016-04-13 10:19:12 -04002195void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2196{
2197 Program *programObject = getProgram(program);
2198 ASSERT(programObject);
2199
2200 programObject->bindUniformLocation(location, name);
2201}
2202
Brandon Jones59770802018-04-02 13:18:42 -07002203void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002204{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002205 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002206}
2207
Brandon Jones59770802018-04-02 13:18:42 -07002208void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002209{
2210 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2211}
2212
Brandon Jones59770802018-04-02 13:18:42 -07002213void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002214{
2215 GLfloat I[16];
2216 angle::Matrix<GLfloat>::setToIdentity(I);
2217
2218 mGLState.loadPathRenderingMatrix(matrixMode, I);
2219}
2220
2221void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2222{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002223 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002224 if (!pathObj)
2225 return;
2226
2227 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002228 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229
2230 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2231}
2232
2233void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2234{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002235 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002236 if (!pathObj)
2237 return;
2238
2239 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002240 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002241
2242 mImplementation->stencilStrokePath(pathObj, reference, mask);
2243}
2244
2245void Context::coverFillPath(GLuint path, GLenum coverMode)
2246{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002247 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002248 if (!pathObj)
2249 return;
2250
2251 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002252 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002253
2254 mImplementation->coverFillPath(pathObj, coverMode);
2255}
2256
2257void Context::coverStrokePath(GLuint path, GLenum coverMode)
2258{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002259 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002260 if (!pathObj)
2261 return;
2262
2263 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002264 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002265
2266 mImplementation->coverStrokePath(pathObj, coverMode);
2267}
2268
2269void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2270{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002271 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002272 if (!pathObj)
2273 return;
2274
2275 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002276 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002277
2278 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2279}
2280
2281void Context::stencilThenCoverStrokePath(GLuint path,
2282 GLint reference,
2283 GLuint mask,
2284 GLenum coverMode)
2285{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002286 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002287 if (!pathObj)
2288 return;
2289
2290 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002291 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002292
2293 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2294}
2295
Sami Väisänend59ca052016-06-21 16:10:00 +03002296void Context::coverFillPathInstanced(GLsizei numPaths,
2297 GLenum pathNameType,
2298 const void *paths,
2299 GLuint pathBase,
2300 GLenum coverMode,
2301 GLenum transformType,
2302 const GLfloat *transformValues)
2303{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002304 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002305
2306 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002307 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002308
2309 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2310}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002311
Sami Väisänend59ca052016-06-21 16:10:00 +03002312void Context::coverStrokePathInstanced(GLsizei numPaths,
2313 GLenum pathNameType,
2314 const void *paths,
2315 GLuint pathBase,
2316 GLenum coverMode,
2317 GLenum transformType,
2318 const GLfloat *transformValues)
2319{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002320 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002321
2322 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002323 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002324
2325 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2326 transformValues);
2327}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002328
Sami Väisänend59ca052016-06-21 16:10:00 +03002329void Context::stencilFillPathInstanced(GLsizei numPaths,
2330 GLenum pathNameType,
2331 const void *paths,
2332 GLuint pathBase,
2333 GLenum fillMode,
2334 GLuint mask,
2335 GLenum transformType,
2336 const GLfloat *transformValues)
2337{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002338 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002339
2340 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002341 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002342
2343 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2344 transformValues);
2345}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002346
Sami Väisänend59ca052016-06-21 16:10:00 +03002347void Context::stencilStrokePathInstanced(GLsizei numPaths,
2348 GLenum pathNameType,
2349 const void *paths,
2350 GLuint pathBase,
2351 GLint reference,
2352 GLuint mask,
2353 GLenum transformType,
2354 const GLfloat *transformValues)
2355{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002356 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002357
2358 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002359 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002360
2361 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2362 transformValues);
2363}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002364
Sami Väisänend59ca052016-06-21 16:10:00 +03002365void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2366 GLenum pathNameType,
2367 const void *paths,
2368 GLuint pathBase,
2369 GLenum fillMode,
2370 GLuint mask,
2371 GLenum coverMode,
2372 GLenum transformType,
2373 const GLfloat *transformValues)
2374{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002375 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002376
2377 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002378 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002379
2380 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2381 transformType, transformValues);
2382}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002383
Sami Väisänend59ca052016-06-21 16:10:00 +03002384void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2385 GLenum pathNameType,
2386 const void *paths,
2387 GLuint pathBase,
2388 GLint reference,
2389 GLuint mask,
2390 GLenum coverMode,
2391 GLenum transformType,
2392 const GLfloat *transformValues)
2393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002394 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002395
2396 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002397 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002398
2399 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2400 transformType, transformValues);
2401}
2402
Sami Väisänen46eaa942016-06-29 10:26:37 +03002403void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2404{
2405 auto *programObject = getProgram(program);
2406
2407 programObject->bindFragmentInputLocation(location, name);
2408}
2409
2410void Context::programPathFragmentInputGen(GLuint program,
2411 GLint location,
2412 GLenum genMode,
2413 GLint components,
2414 const GLfloat *coeffs)
2415{
2416 auto *programObject = getProgram(program);
2417
Jamie Madillbd044ed2017-06-05 12:59:21 -04002418 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002419}
2420
jchen1015015f72017-03-16 13:54:21 +08002421GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2422{
jchen10fd7c3b52017-03-21 15:36:03 +08002423 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002424 return QueryProgramResourceIndex(programObject, programInterface, name);
2425}
2426
jchen10fd7c3b52017-03-21 15:36:03 +08002427void Context::getProgramResourceName(GLuint program,
2428 GLenum programInterface,
2429 GLuint index,
2430 GLsizei bufSize,
2431 GLsizei *length,
2432 GLchar *name)
2433{
2434 const auto *programObject = getProgram(program);
2435 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2436}
2437
jchen10191381f2017-04-11 13:59:04 +08002438GLint Context::getProgramResourceLocation(GLuint program,
2439 GLenum programInterface,
2440 const GLchar *name)
2441{
2442 const auto *programObject = getProgram(program);
2443 return QueryProgramResourceLocation(programObject, programInterface, name);
2444}
2445
jchen10880683b2017-04-12 16:21:55 +08002446void Context::getProgramResourceiv(GLuint program,
2447 GLenum programInterface,
2448 GLuint index,
2449 GLsizei propCount,
2450 const GLenum *props,
2451 GLsizei bufSize,
2452 GLsizei *length,
2453 GLint *params)
2454{
2455 const auto *programObject = getProgram(program);
2456 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2457 length, params);
2458}
2459
jchen10d9cd7b72017-08-30 15:04:25 +08002460void Context::getProgramInterfaceiv(GLuint program,
2461 GLenum programInterface,
2462 GLenum pname,
2463 GLint *params)
2464{
2465 const auto *programObject = getProgram(program);
2466 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2467}
2468
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002469void Context::getProgramInterfaceivRobust(GLuint program,
2470 GLenum programInterface,
2471 GLenum pname,
2472 GLsizei bufSize,
2473 GLsizei *length,
2474 GLint *params)
2475{
2476 UNIMPLEMENTED();
2477}
2478
Jamie Madill427064d2018-04-13 16:20:34 -04002479void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002480{
Geoff Lang7b19a492018-04-20 09:31:52 -04002481 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002482 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002483 GLenum code = error.getCode();
2484 mErrors.insert(code);
2485 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2486 {
2487 markContextLost();
2488 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002489
Geoff Langee6884e2017-11-09 16:51:11 -05002490 ASSERT(!error.getMessage().empty());
2491 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2492 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002493 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002494}
2495
2496// Get one of the recorded errors and clear its flag, if any.
2497// [OpenGL ES 2.0.24] section 2.5 page 13.
2498GLenum Context::getError()
2499{
Geoff Langda5777c2014-07-11 09:52:58 -04002500 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501 {
Geoff Langda5777c2014-07-11 09:52:58 -04002502 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503 }
Geoff Langda5777c2014-07-11 09:52:58 -04002504 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505 {
Geoff Langda5777c2014-07-11 09:52:58 -04002506 GLenum error = *mErrors.begin();
2507 mErrors.erase(mErrors.begin());
2508 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002510}
2511
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002512// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002513void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514{
2515 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002516 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002517 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002518 mContextLostForced = true;
2519 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002520 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002521}
2522
Jamie Madill427064d2018-04-13 16:20:34 -04002523bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002524{
2525 return mContextLost;
2526}
2527
Jamie Madillfa920eb2018-01-04 11:45:50 -05002528GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530 // Even if the application doesn't want to know about resets, we want to know
2531 // as it will allow us to skip all the calls.
2532 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002533 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002534 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002535 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002536 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002537 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002538
2539 // EXT_robustness, section 2.6: If the reset notification behavior is
2540 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2541 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2542 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002543 }
2544
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2546 // status should be returned at least once, and GL_NO_ERROR should be returned
2547 // once the device has finished resetting.
2548 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002549 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002550 ASSERT(mResetStatus == GL_NO_ERROR);
2551 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002552
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002553 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002554 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002556 }
2557 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002558 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002559 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002560 // If markContextLost was used to mark the context lost then
2561 // assume that is not recoverable, and continue to report the
2562 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002563 mResetStatus = mImplementation->getResetStatus();
2564 }
Jamie Madill893ab082014-05-16 16:56:10 -04002565
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002566 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567}
2568
2569bool Context::isResetNotificationEnabled()
2570{
2571 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2572}
2573
Corentin Walleze3b10e82015-05-20 11:06:25 -04002574const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002575{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002576 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002577}
2578
2579EGLenum Context::getClientType() const
2580{
2581 return mClientType;
2582}
2583
2584EGLenum Context::getRenderBuffer() const
2585{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002586 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2587 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002588 {
2589 return EGL_NONE;
2590 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002591
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002592 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002593 ASSERT(backAttachment != nullptr);
2594 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002595}
2596
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002597VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002598{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002599 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002600 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2601 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002602 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002603 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2604 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002605
Jamie Madill96a483b2017-06-27 16:49:21 -04002606 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002607 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002608
2609 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002610}
2611
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002613{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002614 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002615 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2616 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002617 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002618 transformFeedback =
2619 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002620 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002621 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002622 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002623
2624 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002625}
2626
2627bool Context::isVertexArrayGenerated(GLuint vertexArray)
2628{
Jamie Madill96a483b2017-06-27 16:49:21 -04002629 ASSERT(mVertexArrayMap.contains(0));
2630 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002631}
2632
2633bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2634{
Jamie Madill96a483b2017-06-27 16:49:21 -04002635 ASSERT(mTransformFeedbackMap.contains(0));
2636 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002637}
2638
Shannon Woods53a94a82014-06-24 15:20:36 -04002639void Context::detachTexture(GLuint texture)
2640{
2641 // Simple pass-through to State's detachTexture method, as textures do not require
2642 // allocation map management either here or in the resource manager at detach time.
2643 // Zero textures are held by the Context, and we don't attempt to request them from
2644 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002645 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002646}
2647
James Darpinian4d9d4832018-03-13 12:43:28 -07002648void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649{
Yuly Novikov5807a532015-12-03 13:01:22 -05002650 // Simple pass-through to State's detachBuffer method, since
2651 // only buffer attachments to container objects that are bound to the current context
2652 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002653
Yuly Novikov5807a532015-12-03 13:01:22 -05002654 // [OpenGL ES 3.2] section 5.1.2 page 45:
2655 // Attachments to unbound container objects, such as
2656 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2657 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002658 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659}
2660
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661void Context::detachFramebuffer(GLuint framebuffer)
2662{
Shannon Woods53a94a82014-06-24 15:20:36 -04002663 // Framebuffer detachment is handled by Context, because 0 is a valid
2664 // Framebuffer object, and a pointer to it must be passed from Context
2665 // to State at binding time.
2666
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002668 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2669 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2670 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002672 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 {
2674 bindReadFramebuffer(0);
2675 }
2676
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002677 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678 {
2679 bindDrawFramebuffer(0);
2680 }
2681}
2682
2683void Context::detachRenderbuffer(GLuint renderbuffer)
2684{
Jamie Madilla02315b2017-02-23 14:14:47 -05002685 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686}
2687
Jamie Madill57a89722013-07-02 11:57:03 -04002688void Context::detachVertexArray(GLuint vertexArray)
2689{
Jamie Madill77a72f62015-04-14 11:18:32 -04002690 // Vertex array detachment is handled by Context, because 0 is a valid
2691 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002692 // binding time.
2693
Jamie Madill57a89722013-07-02 11:57:03 -04002694 // [OpenGL ES 3.0.2] section 2.10 page 43:
2695 // If a vertex array object that is currently bound is deleted, the binding
2696 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002697 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002698 {
2699 bindVertexArray(0);
2700 }
2701}
2702
Geoff Langc8058452014-02-03 12:04:11 -05002703void Context::detachTransformFeedback(GLuint transformFeedback)
2704{
Corentin Walleza2257da2016-04-19 16:43:12 -04002705 // Transform feedback detachment is handled by Context, because 0 is a valid
2706 // transform feedback, and a pointer to it must be passed from Context to State at
2707 // binding time.
2708
2709 // The OpenGL specification doesn't mention what should happen when the currently bound
2710 // transform feedback object is deleted. Since it is a container object, we treat it like
2711 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002712 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002713 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002714 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002715 }
Geoff Langc8058452014-02-03 12:04:11 -05002716}
2717
Jamie Madilldc356042013-07-19 16:36:57 -04002718void Context::detachSampler(GLuint sampler)
2719{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002720 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002721}
2722
Yunchao Hea336b902017-08-02 16:05:21 +08002723void Context::detachProgramPipeline(GLuint pipeline)
2724{
2725 mGLState.detachProgramPipeline(this, pipeline);
2726}
2727
Jamie Madill3ef140a2017-08-26 23:11:21 -04002728void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002729{
Shaodde78e82017-05-22 14:13:27 +08002730 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002731}
2732
Jamie Madille29d1672013-07-19 16:36:57 -04002733void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2734{
Geoff Langc1984ed2016-10-07 12:41:00 -04002735 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002736 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002737 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002738 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002739}
Jamie Madille29d1672013-07-19 16:36:57 -04002740
Geoff Langc1984ed2016-10-07 12:41:00 -04002741void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2742{
2743 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002744 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002745 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002746 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002747}
2748
Brandon Jones59770802018-04-02 13:18:42 -07002749void Context::samplerParameterivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 const GLint *param)
2753{
2754 samplerParameteriv(sampler, pname, param);
2755}
2756
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002757void Context::samplerParameterIivRobust(GLuint sampler,
2758 GLenum pname,
2759 GLsizei bufSize,
2760 const GLint *param)
2761{
2762 UNIMPLEMENTED();
2763}
2764
2765void Context::samplerParameterIuivRobust(GLuint sampler,
2766 GLenum pname,
2767 GLsizei bufSize,
2768 const GLuint *param)
2769{
2770 UNIMPLEMENTED();
2771}
2772
Jamie Madille29d1672013-07-19 16:36:57 -04002773void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002779}
2780
Geoff Langc1984ed2016-10-07 12:41:00 -04002781void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002782{
Geoff Langc1984ed2016-10-07 12:41:00 -04002783 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002784 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002785 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002786 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002787}
2788
Brandon Jones59770802018-04-02 13:18:42 -07002789void Context::samplerParameterfvRobust(GLuint sampler,
2790 GLenum pname,
2791 GLsizei bufSize,
2792 const GLfloat *param)
2793{
2794 samplerParameterfv(sampler, pname, param);
2795}
2796
Geoff Langc1984ed2016-10-07 12:41:00 -04002797void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002798{
Geoff Langc1984ed2016-10-07 12:41:00 -04002799 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002800 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002801 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002802 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002803}
Jamie Madill9675b802013-07-19 16:36:59 -04002804
Brandon Jones59770802018-04-02 13:18:42 -07002805void Context::getSamplerParameterivRobust(GLuint sampler,
2806 GLenum pname,
2807 GLsizei bufSize,
2808 GLsizei *length,
2809 GLint *params)
2810{
2811 getSamplerParameteriv(sampler, pname, params);
2812}
2813
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002814void Context::getSamplerParameterIivRobust(GLuint sampler,
2815 GLenum pname,
2816 GLsizei bufSize,
2817 GLsizei *length,
2818 GLint *params)
2819{
2820 UNIMPLEMENTED();
2821}
2822
2823void Context::getSamplerParameterIuivRobust(GLuint sampler,
2824 GLenum pname,
2825 GLsizei bufSize,
2826 GLsizei *length,
2827 GLuint *params)
2828{
2829 UNIMPLEMENTED();
2830}
2831
Geoff Langc1984ed2016-10-07 12:41:00 -04002832void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2833{
2834 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002835 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002837 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002838}
2839
Brandon Jones59770802018-04-02 13:18:42 -07002840void Context::getSamplerParameterfvRobust(GLuint sampler,
2841 GLenum pname,
2842 GLsizei bufSize,
2843 GLsizei *length,
2844 GLfloat *params)
2845{
2846 getSamplerParameterfv(sampler, pname, params);
2847}
2848
Olli Etuahof0fee072016-03-30 15:11:58 +03002849void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2850{
2851 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002852 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002853}
2854
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855void Context::initRendererString()
2856{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002857 std::ostringstream rendererString;
2858 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002859 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002860 rendererString << ")";
2861
Geoff Langcec35902014-04-16 10:52:36 -04002862 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002863}
2864
Geoff Langc339c4e2016-11-29 10:37:36 -05002865void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002866{
Geoff Langc339c4e2016-11-29 10:37:36 -05002867 const Version &clientVersion = getClientVersion();
2868
2869 std::ostringstream versionString;
2870 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2871 << ANGLE_VERSION_STRING << ")";
2872 mVersionString = MakeStaticString(versionString.str());
2873
2874 std::ostringstream shadingLanguageVersionString;
2875 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2876 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2877 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2878 << ")";
2879 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002880}
2881
Geoff Langcec35902014-04-16 10:52:36 -04002882void Context::initExtensionStrings()
2883{
Geoff Langc339c4e2016-11-29 10:37:36 -05002884 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2885 std::ostringstream combinedStringStream;
2886 std::copy(strings.begin(), strings.end(),
2887 std::ostream_iterator<const char *>(combinedStringStream, " "));
2888 return MakeStaticString(combinedStringStream.str());
2889 };
2890
2891 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002892 for (const auto &extensionString : mExtensions.getStrings())
2893 {
2894 mExtensionStrings.push_back(MakeStaticString(extensionString));
2895 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002896 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002897
Geoff Langc339c4e2016-11-29 10:37:36 -05002898 mRequestableExtensionStrings.clear();
2899 for (const auto &extensionInfo : GetExtensionInfoMap())
2900 {
2901 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002902 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002903 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002904 {
2905 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2906 }
2907 }
2908 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002909}
2910
Geoff Langc339c4e2016-11-29 10:37:36 -05002911const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002912{
Geoff Langc339c4e2016-11-29 10:37:36 -05002913 switch (name)
2914 {
2915 case GL_VENDOR:
2916 return reinterpret_cast<const GLubyte *>("Google Inc.");
2917
2918 case GL_RENDERER:
2919 return reinterpret_cast<const GLubyte *>(mRendererString);
2920
2921 case GL_VERSION:
2922 return reinterpret_cast<const GLubyte *>(mVersionString);
2923
2924 case GL_SHADING_LANGUAGE_VERSION:
2925 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2926
2927 case GL_EXTENSIONS:
2928 return reinterpret_cast<const GLubyte *>(mExtensionString);
2929
2930 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2931 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2932
2933 default:
2934 UNREACHABLE();
2935 return nullptr;
2936 }
Geoff Langcec35902014-04-16 10:52:36 -04002937}
2938
Geoff Langc339c4e2016-11-29 10:37:36 -05002939const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002940{
Geoff Langc339c4e2016-11-29 10:37:36 -05002941 switch (name)
2942 {
2943 case GL_EXTENSIONS:
2944 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2945
2946 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2947 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2948
2949 default:
2950 UNREACHABLE();
2951 return nullptr;
2952 }
Geoff Langcec35902014-04-16 10:52:36 -04002953}
2954
2955size_t Context::getExtensionStringCount() const
2956{
2957 return mExtensionStrings.size();
2958}
2959
Geoff Lang111a99e2017-10-17 10:58:41 -04002960bool Context::isExtensionRequestable(const char *name)
2961{
2962 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2963 auto extension = extensionInfos.find(name);
2964
Geoff Lang111a99e2017-10-17 10:58:41 -04002965 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002966 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002967}
2968
Geoff Langc339c4e2016-11-29 10:37:36 -05002969void Context::requestExtension(const char *name)
2970{
2971 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2972 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2973 const auto &extension = extensionInfos.at(name);
2974 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002975 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002976
2977 if (mExtensions.*(extension.ExtensionsMember))
2978 {
2979 // Extension already enabled
2980 return;
2981 }
2982
2983 mExtensions.*(extension.ExtensionsMember) = true;
2984 updateCaps();
2985 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002986
Jamie Madill2f348d22017-06-05 10:50:59 -04002987 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2988 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002989
Jamie Madill81c2e252017-09-09 23:32:46 -04002990 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2991 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002992 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002993 for (auto &zeroTexture : mZeroTextures)
2994 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002995 if (zeroTexture.get() != nullptr)
2996 {
2997 zeroTexture->signalDirty(this, InitState::Initialized);
2998 }
Geoff Lang9aded172017-04-05 11:07:56 -04002999 }
3000
3001 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003002}
3003
3004size_t Context::getRequestableExtensionStringCount() const
3005{
3006 return mRequestableExtensionStrings.size();
3007}
3008
Jamie Madill493f9572018-05-24 19:52:15 -04003009void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003010{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003011 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003012 ASSERT(transformFeedback != nullptr);
3013 ASSERT(!transformFeedback->isPaused());
3014
Jamie Madill6c1f6712017-02-14 19:08:04 -05003015 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003016}
3017
3018bool Context::hasActiveTransformFeedback(GLuint program) const
3019{
3020 for (auto pair : mTransformFeedbackMap)
3021 {
3022 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3023 {
3024 return true;
3025 }
3026 }
3027 return false;
3028}
3029
Geoff Lang33f11fb2018-05-07 13:42:47 -04003030Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003031{
3032 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3033
3034 if (getClientVersion() < ES_2_0)
3035 {
3036 // Default extensions for GLES1
3037 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003038 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003039 }
3040
3041 if (getClientVersion() < ES_3_0)
3042 {
3043 // Disable ES3+ extensions
3044 supportedExtensions.colorBufferFloat = false;
3045 supportedExtensions.eglImageExternalEssl3 = false;
3046 supportedExtensions.textureNorm16 = false;
3047 supportedExtensions.multiview = false;
3048 supportedExtensions.maxViews = 1u;
3049 }
3050
3051 if (getClientVersion() < ES_3_1)
3052 {
3053 // Disable ES3.1+ extensions
3054 supportedExtensions.geometryShader = false;
3055 }
3056
3057 if (getClientVersion() > ES_2_0)
3058 {
3059 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3060 // supportedExtensions.sRGB = false;
3061 }
3062
3063 // Some extensions are always available because they are implemented in the GL layer.
3064 supportedExtensions.bindUniformLocation = true;
3065 supportedExtensions.vertexArrayObject = true;
3066 supportedExtensions.bindGeneratesResource = true;
3067 supportedExtensions.clientArrays = true;
3068 supportedExtensions.requestExtension = true;
3069
3070 // Enable the no error extension if the context was created with the flag.
3071 supportedExtensions.noError = mSkipValidation;
3072
3073 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003074 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003075
3076 // Explicitly enable GL_KHR_debug
3077 supportedExtensions.debug = true;
3078 supportedExtensions.maxDebugMessageLength = 1024;
3079 supportedExtensions.maxDebugLoggedMessages = 1024;
3080 supportedExtensions.maxDebugGroupStackDepth = 1024;
3081 supportedExtensions.maxLabelLength = 1024;
3082
3083 // Explicitly enable GL_ANGLE_robust_client_memory
3084 supportedExtensions.robustClientMemory = true;
3085
3086 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003087 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003088
3089 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3090 // supports it.
3091 supportedExtensions.robustBufferAccessBehavior =
3092 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3093
3094 // Enable the cache control query unconditionally.
3095 supportedExtensions.programCacheControl = true;
3096
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003097 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003098 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003099 {
3100 // GL_ANGLE_explicit_context_gles1
3101 supportedExtensions.explicitContextGles1 = true;
3102 // GL_ANGLE_explicit_context
3103 supportedExtensions.explicitContext = true;
3104 }
3105
Geoff Langb0f917f2017-12-05 13:41:54 -05003106 return supportedExtensions;
3107}
3108
Geoff Lang33f11fb2018-05-07 13:42:47 -04003109void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003110{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003111 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003112
Geoff Lang33f11fb2018-05-07 13:42:47 -04003113 mSupportedExtensions = generateSupportedExtensions();
3114 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003115
3116 mLimitations = mImplementation->getNativeLimitations();
3117
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003118 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3119 if (getClientVersion() < Version(2, 0))
3120 {
3121 mCaps.maxMultitextureUnits = 4;
3122 mCaps.maxClipPlanes = 6;
3123 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003124 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3125 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3126 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003127 }
3128
Geoff Lang301d1612014-07-09 10:34:37 -04003129 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003130 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003131
Jamie Madill0f80ed82017-09-19 00:24:56 -04003132 if (getClientVersion() < ES_3_1)
3133 {
3134 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3135 }
3136 else
3137 {
3138 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3139 }
Geoff Lang301d1612014-07-09 10:34:37 -04003140
Jiawei Shao54aafe52018-04-27 14:54:57 +08003141 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3142 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003143 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3144 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3145
3146 // Limit textures as well, so we can use fast bitsets with texture bindings.
3147 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003148 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3149 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3150 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3151 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003152
Jiawei Shaodb342272017-09-27 10:21:45 +08003153 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3154
Geoff Langc287ea62016-09-16 14:46:51 -04003155 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003156 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003157 for (const auto &extensionInfo : GetExtensionInfoMap())
3158 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003159 // If the user has requested that extensions start disabled and they are requestable,
3160 // disable them.
3161 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003162 {
3163 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3164 }
3165 }
3166
3167 // Generate texture caps
3168 updateCaps();
3169}
3170
3171void Context::updateCaps()
3172{
Geoff Lang900013c2014-07-07 11:32:19 -04003173 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003174 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003175
Jamie Madill7b62cf92017-11-02 15:20:49 -04003176 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003177 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003178 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003179 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003180
Geoff Lang0d8b7242015-09-09 14:56:53 -04003181 // Update the format caps based on the client version and extensions.
3182 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3183 // ES3.
3184 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003185 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003186 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003187 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003188 formatCaps.textureAttachment =
3189 formatCaps.textureAttachment &&
3190 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3191 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3192 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003193
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003194 // OpenGL ES does not support multisampling with non-rendererable formats
3195 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003196 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003197 (getClientVersion() < ES_3_1 &&
3198 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003199 {
Geoff Langd87878e2014-09-19 15:42:59 -04003200 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003201 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003202 else
3203 {
3204 // We may have limited the max samples for some required renderbuffer formats due to
3205 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3206 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3207
3208 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3209 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3210 // exception of signed and unsigned integer formats."
3211 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3212 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3213 {
3214 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3215 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3216 }
3217
3218 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3219 if (getClientVersion() >= ES_3_1)
3220 {
3221 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3222 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3223 // the exception that the signed and unsigned integer formats are required only to
3224 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3225 // multisamples, which must be at least one."
3226 if (formatInfo.componentType == GL_INT ||
3227 formatInfo.componentType == GL_UNSIGNED_INT)
3228 {
3229 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3230 }
3231
3232 // GLES 3.1 section 19.3.1.
3233 if (formatCaps.texturable)
3234 {
3235 if (formatInfo.depthBits > 0)
3236 {
3237 mCaps.maxDepthTextureSamples =
3238 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3239 }
3240 else if (formatInfo.redBits > 0)
3241 {
3242 mCaps.maxColorTextureSamples =
3243 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3244 }
3245 }
3246 }
3247 }
Geoff Langd87878e2014-09-19 15:42:59 -04003248
3249 if (formatCaps.texturable && formatInfo.compressed)
3250 {
Geoff Langca271392017-04-05 12:30:00 -04003251 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003252 }
3253
Geoff Langca271392017-04-05 12:30:00 -04003254 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003255 }
Jamie Madill32447362017-06-28 14:53:52 -04003256
3257 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003258 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003259 {
3260 mMemoryProgramCache = nullptr;
3261 }
Corentin Walleze4477002017-12-01 14:39:58 -05003262
3263 // Compute which buffer types are allowed
3264 mValidBufferBindings.reset();
3265 mValidBufferBindings.set(BufferBinding::ElementArray);
3266 mValidBufferBindings.set(BufferBinding::Array);
3267
3268 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3269 {
3270 mValidBufferBindings.set(BufferBinding::PixelPack);
3271 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3272 }
3273
3274 if (getClientVersion() >= ES_3_0)
3275 {
3276 mValidBufferBindings.set(BufferBinding::CopyRead);
3277 mValidBufferBindings.set(BufferBinding::CopyWrite);
3278 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3279 mValidBufferBindings.set(BufferBinding::Uniform);
3280 }
3281
3282 if (getClientVersion() >= ES_3_1)
3283 {
3284 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3285 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3286 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3287 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3288 }
Geoff Lang493daf52014-07-03 13:38:44 -04003289}
3290
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003291void Context::initWorkarounds()
3292{
Jamie Madill761b02c2017-06-23 16:27:06 -04003293 // Apply back-end workarounds.
3294 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3295
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003296 // Lose the context upon out of memory error if the application is
3297 // expecting to watch for those events.
3298 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3299}
3300
Jamie Madill05b35b22017-10-03 09:01:44 -04003301Error Context::prepareForDraw()
3302{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003303 if (mGLES1Renderer)
3304 {
3305 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3306 }
3307
Geoff Langa8cb2872018-03-09 16:09:40 -05003308 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003309
3310 if (isRobustResourceInitEnabled())
3311 {
3312 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3313 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3314 }
3315
Geoff Langa8cb2872018-03-09 16:09:40 -05003316 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003317 return NoError();
3318}
3319
3320Error Context::prepareForClear(GLbitfield mask)
3321{
Geoff Langa8cb2872018-03-09 16:09:40 -05003322 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003323 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003324 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003325 return NoError();
3326}
3327
3328Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3329{
Geoff Langa8cb2872018-03-09 16:09:40 -05003330 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003331 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3332 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003333 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003334 return NoError();
3335}
3336
Geoff Langa8cb2872018-03-09 16:09:40 -05003337Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003338{
Geoff Langa8cb2872018-03-09 16:09:40 -05003339 ANGLE_TRY(syncDirtyObjects());
3340 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003341 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003342}
3343
Geoff Langa8cb2872018-03-09 16:09:40 -05003344Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003345{
Geoff Langa8cb2872018-03-09 16:09:40 -05003346 ANGLE_TRY(syncDirtyObjects(objectMask));
3347 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003348 return NoError();
3349}
3350
Geoff Langa8cb2872018-03-09 16:09:40 -05003351Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003352{
3353 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3354 mImplementation->syncState(this, dirtyBits);
3355 mGLState.clearDirtyBits();
3356 return NoError();
3357}
3358
Geoff Langa8cb2872018-03-09 16:09:40 -05003359Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003360{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003361 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003362 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003363 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003364 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003365}
Jamie Madillc29968b2016-01-20 11:17:23 -05003366
Geoff Langa8cb2872018-03-09 16:09:40 -05003367Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003368{
3369 return mGLState.syncDirtyObjects(this);
3370}
3371
Geoff Langa8cb2872018-03-09 16:09:40 -05003372Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003373{
3374 return mGLState.syncDirtyObjects(this, objectMask);
3375}
3376
Jamie Madillc29968b2016-01-20 11:17:23 -05003377void Context::blitFramebuffer(GLint srcX0,
3378 GLint srcY0,
3379 GLint srcX1,
3380 GLint srcY1,
3381 GLint dstX0,
3382 GLint dstY0,
3383 GLint dstX1,
3384 GLint dstY1,
3385 GLbitfield mask,
3386 GLenum filter)
3387{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003388 if (mask == 0)
3389 {
3390 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3391 // buffers are copied.
3392 return;
3393 }
3394
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003395 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003396 ASSERT(drawFramebuffer);
3397
3398 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3399 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3400
Jamie Madillbc918e72018-03-08 09:47:21 -05003401 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003402
Jamie Madillc564c072017-06-01 12:45:42 -04003403 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003404}
Jamie Madillc29968b2016-01-20 11:17:23 -05003405
3406void Context::clear(GLbitfield mask)
3407{
Geoff Langd4fff502017-09-22 11:28:28 -04003408 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3409 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003410}
3411
3412void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3413{
Geoff Langd4fff502017-09-22 11:28:28 -04003414 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3415 ANGLE_CONTEXT_TRY(
3416 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003417}
3418
3419void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3420{
Geoff Langd4fff502017-09-22 11:28:28 -04003421 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3422 ANGLE_CONTEXT_TRY(
3423 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003424}
3425
3426void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3427{
Geoff Langd4fff502017-09-22 11:28:28 -04003428 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3429 ANGLE_CONTEXT_TRY(
3430 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003431}
3432
3433void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003435 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003436 ASSERT(framebufferObject);
3437
3438 // If a buffer is not present, the clear has no effect
3439 if (framebufferObject->getDepthbuffer() == nullptr &&
3440 framebufferObject->getStencilbuffer() == nullptr)
3441 {
3442 return;
3443 }
3444
Geoff Langd4fff502017-09-22 11:28:28 -04003445 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3446 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003447}
3448
3449void Context::readPixels(GLint x,
3450 GLint y,
3451 GLsizei width,
3452 GLsizei height,
3453 GLenum format,
3454 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003455 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003456{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003457 if (width == 0 || height == 0)
3458 {
3459 return;
3460 }
3461
Jamie Madillbc918e72018-03-08 09:47:21 -05003462 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003463
Jamie Madillb6664922017-07-25 12:55:04 -04003464 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3465 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003466
3467 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003468 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003469}
3470
Brandon Jones59770802018-04-02 13:18:42 -07003471void Context::readPixelsRobust(GLint x,
3472 GLint y,
3473 GLsizei width,
3474 GLsizei height,
3475 GLenum format,
3476 GLenum type,
3477 GLsizei bufSize,
3478 GLsizei *length,
3479 GLsizei *columns,
3480 GLsizei *rows,
3481 void *pixels)
3482{
3483 readPixels(x, y, width, height, format, type, pixels);
3484}
3485
3486void Context::readnPixelsRobust(GLint x,
3487 GLint y,
3488 GLsizei width,
3489 GLsizei height,
3490 GLenum format,
3491 GLenum type,
3492 GLsizei bufSize,
3493 GLsizei *length,
3494 GLsizei *columns,
3495 GLsizei *rows,
3496 void *data)
3497{
3498 readPixels(x, y, width, height, format, type, data);
3499}
3500
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003501void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 GLint level,
3503 GLenum internalformat,
3504 GLint x,
3505 GLint y,
3506 GLsizei width,
3507 GLsizei height,
3508 GLint border)
3509{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003510 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003511 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003512
Jamie Madillc29968b2016-01-20 11:17:23 -05003513 Rectangle sourceArea(x, y, width, height);
3514
Jamie Madill05b35b22017-10-03 09:01:44 -04003515 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003516 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003517 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003518}
3519
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003520void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003521 GLint level,
3522 GLint xoffset,
3523 GLint yoffset,
3524 GLint x,
3525 GLint y,
3526 GLsizei width,
3527 GLsizei height)
3528{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003529 if (width == 0 || height == 0)
3530 {
3531 return;
3532 }
3533
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003534 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003535 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003536
Jamie Madillc29968b2016-01-20 11:17:23 -05003537 Offset destOffset(xoffset, yoffset, 0);
3538 Rectangle sourceArea(x, y, width, height);
3539
Jamie Madill05b35b22017-10-03 09:01:44 -04003540 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003541 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003542 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003545void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003546 GLint level,
3547 GLint xoffset,
3548 GLint yoffset,
3549 GLint zoffset,
3550 GLint x,
3551 GLint y,
3552 GLsizei width,
3553 GLsizei height)
3554{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003555 if (width == 0 || height == 0)
3556 {
3557 return;
3558 }
3559
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003560 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003561 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003562
Jamie Madillc29968b2016-01-20 11:17:23 -05003563 Offset destOffset(xoffset, yoffset, zoffset);
3564 Rectangle sourceArea(x, y, width, height);
3565
Jamie Madill05b35b22017-10-03 09:01:44 -04003566 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3567 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003568 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3569 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003570}
3571
3572void Context::framebufferTexture2D(GLenum target,
3573 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003574 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003575 GLuint texture,
3576 GLint level)
3577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003578 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 ASSERT(framebuffer);
3580
3581 if (texture != 0)
3582 {
3583 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003584 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003585 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003586 }
3587 else
3588 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003589 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003591
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003592 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003593}
3594
3595void Context::framebufferRenderbuffer(GLenum target,
3596 GLenum attachment,
3597 GLenum renderbuffertarget,
3598 GLuint renderbuffer)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 ASSERT(framebuffer);
3602
3603 if (renderbuffer != 0)
3604 {
3605 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003606
Jamie Madillcc129372018-04-12 09:13:18 -04003607 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 renderbufferObject);
3609 }
3610 else
3611 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003612 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003613 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003614
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003616}
3617
3618void Context::framebufferTextureLayer(GLenum target,
3619 GLenum attachment,
3620 GLuint texture,
3621 GLint level,
3622 GLint layer)
3623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003625 ASSERT(framebuffer);
3626
3627 if (texture != 0)
3628 {
3629 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003630 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003631 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003632 }
3633 else
3634 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003635 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003636 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003637
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003639}
3640
Brandon Jones59770802018-04-02 13:18:42 -07003641void Context::framebufferTextureMultiviewLayered(GLenum target,
3642 GLenum attachment,
3643 GLuint texture,
3644 GLint level,
3645 GLint baseViewIndex,
3646 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003647{
Martin Radev82ef7742017-08-08 17:44:58 +03003648 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3649 ASSERT(framebuffer);
3650
3651 if (texture != 0)
3652 {
3653 Texture *textureObj = getTexture(texture);
3654
Martin Radev18b75ba2017-08-15 15:50:40 +03003655 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003656 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3657 numViews, baseViewIndex);
3658 }
3659 else
3660 {
3661 framebuffer->resetAttachment(this, attachment);
3662 }
3663
3664 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003665}
3666
Brandon Jones59770802018-04-02 13:18:42 -07003667void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3668 GLenum attachment,
3669 GLuint texture,
3670 GLint level,
3671 GLsizei numViews,
3672 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003673{
Martin Radev5dae57b2017-07-14 16:15:55 +03003674 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3675 ASSERT(framebuffer);
3676
3677 if (texture != 0)
3678 {
3679 Texture *textureObj = getTexture(texture);
3680
3681 ImageIndex index = ImageIndex::Make2D(level);
3682 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3683 textureObj, numViews, viewportOffsets);
3684 }
3685 else
3686 {
3687 framebuffer->resetAttachment(this, attachment);
3688 }
3689
3690 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003691}
3692
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003693void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3694{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003695 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3696 ASSERT(framebuffer);
3697
3698 if (texture != 0)
3699 {
3700 Texture *textureObj = getTexture(texture);
3701
3702 ImageIndex index = ImageIndex::MakeFromType(
3703 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3704 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3705 }
3706 else
3707 {
3708 framebuffer->resetAttachment(this, attachment);
3709 }
3710
3711 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003712}
3713
Jamie Madillc29968b2016-01-20 11:17:23 -05003714void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3715{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003716 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003717 ASSERT(framebuffer);
3718 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003720}
3721
3722void Context::readBuffer(GLenum mode)
3723{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003725 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003727}
3728
3729void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3730{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003731 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003732 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003733
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 ASSERT(framebuffer);
3736
3737 // The specification isn't clear what should be done when the framebuffer isn't complete.
3738 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003739 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003740}
3741
3742void Context::invalidateFramebuffer(GLenum target,
3743 GLsizei numAttachments,
3744 const GLenum *attachments)
3745{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003746 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003747 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003748
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 ASSERT(framebuffer);
3751
Jamie Madill427064d2018-04-13 16:20:34 -04003752 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 {
Jamie Madill437fa652016-05-03 15:13:24 -04003754 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
Jamie Madill437fa652016-05-03 15:13:24 -04003756
Jamie Madill4928b7c2017-06-20 12:57:39 -04003757 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003758}
3759
3760void Context::invalidateSubFramebuffer(GLenum target,
3761 GLsizei numAttachments,
3762 const GLenum *attachments,
3763 GLint x,
3764 GLint y,
3765 GLsizei width,
3766 GLsizei height)
3767{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003768 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003769 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003772 ASSERT(framebuffer);
3773
Jamie Madill427064d2018-04-13 16:20:34 -04003774 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003775 {
Jamie Madill437fa652016-05-03 15:13:24 -04003776 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003777 }
Jamie Madill437fa652016-05-03 15:13:24 -04003778
3779 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003780 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003781}
3782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003783void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003784 GLint level,
3785 GLint internalformat,
3786 GLsizei width,
3787 GLsizei height,
3788 GLint border,
3789 GLenum format,
3790 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003791 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003792{
Jamie Madillbc918e72018-03-08 09:47:21 -05003793 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003794
3795 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003796 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003797 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3798 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003799}
3800
Brandon Jones59770802018-04-02 13:18:42 -07003801void Context::texImage2DRobust(TextureTarget target,
3802 GLint level,
3803 GLint internalformat,
3804 GLsizei width,
3805 GLsizei height,
3806 GLint border,
3807 GLenum format,
3808 GLenum type,
3809 GLsizei bufSize,
3810 const void *pixels)
3811{
3812 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3813}
3814
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003815void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003816 GLint level,
3817 GLint internalformat,
3818 GLsizei width,
3819 GLsizei height,
3820 GLsizei depth,
3821 GLint border,
3822 GLenum format,
3823 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003824 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003825{
Jamie Madillbc918e72018-03-08 09:47:21 -05003826 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003827
3828 Extents size(width, height, depth);
3829 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003830 handleError(texture->setImage(this, mGLState.getUnpackState(),
3831 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3832 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003833}
3834
Brandon Jones59770802018-04-02 13:18:42 -07003835void Context::texImage3DRobust(TextureType target,
3836 GLint level,
3837 GLint internalformat,
3838 GLsizei width,
3839 GLsizei height,
3840 GLsizei depth,
3841 GLint border,
3842 GLenum format,
3843 GLenum type,
3844 GLsizei bufSize,
3845 const void *pixels)
3846{
3847 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3848}
3849
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003850void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003851 GLint level,
3852 GLint xoffset,
3853 GLint yoffset,
3854 GLsizei width,
3855 GLsizei height,
3856 GLenum format,
3857 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003858 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003859{
3860 // Zero sized uploads are valid but no-ops
3861 if (width == 0 || height == 0)
3862 {
3863 return;
3864 }
3865
Jamie Madillbc918e72018-03-08 09:47:21 -05003866 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003867
3868 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003869 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003870 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3871 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003872}
3873
Brandon Jones59770802018-04-02 13:18:42 -07003874void Context::texSubImage2DRobust(TextureTarget target,
3875 GLint level,
3876 GLint xoffset,
3877 GLint yoffset,
3878 GLsizei width,
3879 GLsizei height,
3880 GLenum format,
3881 GLenum type,
3882 GLsizei bufSize,
3883 const void *pixels)
3884{
3885 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3886}
3887
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003888void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003889 GLint level,
3890 GLint xoffset,
3891 GLint yoffset,
3892 GLint zoffset,
3893 GLsizei width,
3894 GLsizei height,
3895 GLsizei depth,
3896 GLenum format,
3897 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003898 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003899{
3900 // Zero sized uploads are valid but no-ops
3901 if (width == 0 || height == 0 || depth == 0)
3902 {
3903 return;
3904 }
3905
Jamie Madillbc918e72018-03-08 09:47:21 -05003906 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003907
3908 Box area(xoffset, yoffset, zoffset, width, height, depth);
3909 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003910 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3911 NonCubeTextureTypeToTarget(target), level, area, format, type,
3912 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003913}
3914
Brandon Jones59770802018-04-02 13:18:42 -07003915void Context::texSubImage3DRobust(TextureType target,
3916 GLint level,
3917 GLint xoffset,
3918 GLint yoffset,
3919 GLint zoffset,
3920 GLsizei width,
3921 GLsizei height,
3922 GLsizei depth,
3923 GLenum format,
3924 GLenum type,
3925 GLsizei bufSize,
3926 const void *pixels)
3927{
3928 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3929 pixels);
3930}
3931
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003932void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003933 GLint level,
3934 GLenum internalformat,
3935 GLsizei width,
3936 GLsizei height,
3937 GLint border,
3938 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003939 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003940{
Jamie Madillbc918e72018-03-08 09:47:21 -05003941 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003942
3943 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003944 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003945 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3946 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003947 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003948}
3949
Brandon Jones59770802018-04-02 13:18:42 -07003950void Context::compressedTexImage2DRobust(TextureTarget target,
3951 GLint level,
3952 GLenum internalformat,
3953 GLsizei width,
3954 GLsizei height,
3955 GLint border,
3956 GLsizei imageSize,
3957 GLsizei dataSize,
3958 const GLvoid *data)
3959{
3960 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3961}
3962
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003963void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003964 GLint level,
3965 GLenum internalformat,
3966 GLsizei width,
3967 GLsizei height,
3968 GLsizei depth,
3969 GLint border,
3970 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003971 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003972{
Jamie Madillbc918e72018-03-08 09:47:21 -05003973 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003974
3975 Extents size(width, height, depth);
3976 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003977 handleError(texture->setCompressedImage(
3978 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3979 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003980}
3981
Brandon Jones59770802018-04-02 13:18:42 -07003982void Context::compressedTexImage3DRobust(TextureType target,
3983 GLint level,
3984 GLenum internalformat,
3985 GLsizei width,
3986 GLsizei height,
3987 GLsizei depth,
3988 GLint border,
3989 GLsizei imageSize,
3990 GLsizei dataSize,
3991 const GLvoid *data)
3992{
3993 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3994 data);
3995}
3996
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003997void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003998 GLint level,
3999 GLint xoffset,
4000 GLint yoffset,
4001 GLsizei width,
4002 GLsizei height,
4003 GLenum format,
4004 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004005 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004006{
Jamie Madillbc918e72018-03-08 09:47:21 -05004007 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004008
4009 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004011 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4012 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004013 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004014}
4015
Brandon Jones59770802018-04-02 13:18:42 -07004016void Context::compressedTexSubImage2DRobust(TextureTarget target,
4017 GLint level,
4018 GLint xoffset,
4019 GLint yoffset,
4020 GLsizei width,
4021 GLsizei height,
4022 GLenum format,
4023 GLsizei imageSize,
4024 GLsizei dataSize,
4025 const GLvoid *data)
4026{
4027 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4028 data);
4029}
4030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004031void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004032 GLint level,
4033 GLint xoffset,
4034 GLint yoffset,
4035 GLint zoffset,
4036 GLsizei width,
4037 GLsizei height,
4038 GLsizei depth,
4039 GLenum format,
4040 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004041 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004042{
4043 // Zero sized uploads are valid but no-ops
4044 if (width == 0 || height == 0)
4045 {
4046 return;
4047 }
4048
Jamie Madillbc918e72018-03-08 09:47:21 -05004049 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004050
4051 Box area(xoffset, yoffset, zoffset, width, height, depth);
4052 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004053 handleError(texture->setCompressedSubImage(
4054 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4055 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004056}
4057
Brandon Jones59770802018-04-02 13:18:42 -07004058void Context::compressedTexSubImage3DRobust(TextureType target,
4059 GLint level,
4060 GLint xoffset,
4061 GLint yoffset,
4062 GLint zoffset,
4063 GLsizei width,
4064 GLsizei height,
4065 GLsizei depth,
4066 GLenum format,
4067 GLsizei imageSize,
4068 GLsizei dataSize,
4069 const GLvoid *data)
4070{
4071 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4072 imageSize, data);
4073}
4074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004075void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004076{
4077 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004078 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004079}
4080
Jamie Madill007530e2017-12-28 14:27:04 -05004081void Context::copyTexture(GLuint sourceId,
4082 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004083 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004084 GLuint destId,
4085 GLint destLevel,
4086 GLint internalFormat,
4087 GLenum destType,
4088 GLboolean unpackFlipY,
4089 GLboolean unpackPremultiplyAlpha,
4090 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004091{
Jamie Madillbc918e72018-03-08 09:47:21 -05004092 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004093
4094 gl::Texture *sourceTexture = getTexture(sourceId);
4095 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004096 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4097 sourceLevel, ConvertToBool(unpackFlipY),
4098 ConvertToBool(unpackPremultiplyAlpha),
4099 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004100}
4101
Jamie Madill007530e2017-12-28 14:27:04 -05004102void Context::copySubTexture(GLuint sourceId,
4103 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004104 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004105 GLuint destId,
4106 GLint destLevel,
4107 GLint xoffset,
4108 GLint yoffset,
4109 GLint x,
4110 GLint y,
4111 GLsizei width,
4112 GLsizei height,
4113 GLboolean unpackFlipY,
4114 GLboolean unpackPremultiplyAlpha,
4115 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004116{
4117 // Zero sized copies are valid but no-ops
4118 if (width == 0 || height == 0)
4119 {
4120 return;
4121 }
4122
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004124
4125 gl::Texture *sourceTexture = getTexture(sourceId);
4126 gl::Texture *destTexture = getTexture(destId);
4127 Offset offset(xoffset, yoffset, 0);
4128 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004129 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4130 ConvertToBool(unpackFlipY),
4131 ConvertToBool(unpackPremultiplyAlpha),
4132 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004133}
4134
Jamie Madill007530e2017-12-28 14:27:04 -05004135void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004136{
Jamie Madillbc918e72018-03-08 09:47:21 -05004137 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004138
4139 gl::Texture *sourceTexture = getTexture(sourceId);
4140 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004141 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004142}
4143
Corentin Wallez336129f2017-10-17 15:55:40 -04004144void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004145{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004146 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004147 ASSERT(buffer);
4148
Geoff Lang496c02d2016-10-20 11:38:11 -07004149 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004150}
4151
Brandon Jones59770802018-04-02 13:18:42 -07004152void Context::getBufferPointervRobust(BufferBinding target,
4153 GLenum pname,
4154 GLsizei bufSize,
4155 GLsizei *length,
4156 void **params)
4157{
4158 getBufferPointerv(target, pname, params);
4159}
4160
Corentin Wallez336129f2017-10-17 15:55:40 -04004161void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004162{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004163 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004164 ASSERT(buffer);
4165
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004166 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004167 if (error.isError())
4168 {
Jamie Madill437fa652016-05-03 15:13:24 -04004169 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004170 return nullptr;
4171 }
4172
4173 return buffer->getMapPointer();
4174}
4175
Corentin Wallez336129f2017-10-17 15:55:40 -04004176GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004177{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004178 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004179 ASSERT(buffer);
4180
4181 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004182 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 if (error.isError())
4184 {
Jamie Madill437fa652016-05-03 15:13:24 -04004185 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004186 return GL_FALSE;
4187 }
4188
4189 return result;
4190}
4191
Corentin Wallez336129f2017-10-17 15:55:40 -04004192void *Context::mapBufferRange(BufferBinding target,
4193 GLintptr offset,
4194 GLsizeiptr length,
4195 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004197 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004198 ASSERT(buffer);
4199
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004200 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004201 if (error.isError())
4202 {
Jamie Madill437fa652016-05-03 15:13:24 -04004203 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004204 return nullptr;
4205 }
4206
4207 return buffer->getMapPointer();
4208}
4209
Corentin Wallez336129f2017-10-17 15:55:40 -04004210void Context::flushMappedBufferRange(BufferBinding /*target*/,
4211 GLintptr /*offset*/,
4212 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004213{
4214 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4215}
4216
Jamie Madillbc918e72018-03-08 09:47:21 -05004217Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004218{
Geoff Langa8cb2872018-03-09 16:09:40 -05004219 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004220}
4221
Jamie Madillbc918e72018-03-08 09:47:21 -05004222Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004223{
Geoff Langa8cb2872018-03-09 16:09:40 -05004224 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004225}
4226
Jamie Madillbc918e72018-03-08 09:47:21 -05004227Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004228{
Geoff Langa8cb2872018-03-09 16:09:40 -05004229 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004230}
4231
Jiajia Qin5451d532017-11-16 17:16:34 +08004232void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4233{
4234 UNIMPLEMENTED();
4235}
4236
Jamie Madillc20ab272016-06-09 07:20:46 -07004237void Context::activeTexture(GLenum texture)
4238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
Jamie Madill876429b2017-04-20 15:46:24 -04004242void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004243{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004244 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004245}
4246
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004247void Context::blendEquation(GLenum mode)
4248{
4249 mGLState.setBlendEquation(mode, mode);
4250}
4251
Jamie Madillc20ab272016-06-09 07:20:46 -07004252void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4253{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004254 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004255}
4256
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004257void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4258{
4259 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4260}
4261
Jamie Madillc20ab272016-06-09 07:20:46 -07004262void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
Jamie Madill876429b2017-04-20 15:46:24 -04004267void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004268{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270}
4271
Jamie Madill876429b2017-04-20 15:46:24 -04004272void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004275}
4276
4277void Context::clearStencil(GLint s)
4278{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004279 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004280}
4281
4282void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4283{
Geoff Lang92019432017-11-20 13:09:34 -05004284 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4285 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004286}
4287
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004288void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004289{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004290 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004291}
4292
4293void Context::depthFunc(GLenum func)
4294{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004295 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004296}
4297
4298void Context::depthMask(GLboolean flag)
4299{
Geoff Lang92019432017-11-20 13:09:34 -05004300 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004301}
4302
Jamie Madill876429b2017-04-20 15:46:24 -04004303void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004304{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004305 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004306}
4307
4308void Context::disable(GLenum cap)
4309{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004310 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004311}
4312
4313void Context::disableVertexAttribArray(GLuint index)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
4318void Context::enable(GLenum cap)
4319{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
4323void Context::enableVertexAttribArray(GLuint index)
4324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004326}
4327
4328void Context::frontFace(GLenum mode)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
4333void Context::hint(GLenum target, GLenum mode)
4334{
4335 switch (target)
4336 {
4337 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339 break;
4340
4341 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004342 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004343 break;
4344
4345 default:
4346 UNREACHABLE();
4347 return;
4348 }
4349}
4350
4351void Context::lineWidth(GLfloat width)
4352{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354}
4355
4356void Context::pixelStorei(GLenum pname, GLint param)
4357{
4358 switch (pname)
4359 {
4360 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362 break;
4363
4364 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004365 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004366 break;
4367
4368 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004369 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004370 break;
4371
4372 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004373 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004375 break;
4376
4377 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004378 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380 break;
4381
4382 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004383 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004384 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004385 break;
4386
4387 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004388 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390 break;
4391
4392 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004393 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 break;
4396
4397 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004398 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400 break;
4401
4402 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004403 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405 break;
4406
4407 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004408 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004410 break;
4411
4412 default:
4413 UNREACHABLE();
4414 return;
4415 }
4416}
4417
4418void Context::polygonOffset(GLfloat factor, GLfloat units)
4419{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421}
4422
Jamie Madill876429b2017-04-20 15:46:24 -04004423void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004424{
Geoff Lang92019432017-11-20 13:09:34 -05004425 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
Jiawei Shaodb342272017-09-27 10:21:45 +08004428void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4429{
4430 mGLState.setSampleMaskParams(maskNumber, mask);
4431}
4432
Jamie Madillc20ab272016-06-09 07:20:46 -07004433void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
4438void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4439{
4440 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4441 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 }
4444
4445 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4446 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448 }
4449}
4450
4451void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4452{
4453 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4454 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setStencilWritemask(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.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461 }
4462}
4463
4464void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4465{
4466 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4467 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setStencilOperations(fail, zfail, zpass);
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.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004474 }
4475}
4476
4477void Context::vertexAttrib1f(GLuint index, GLfloat x)
4478{
4479 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
4483void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4484{
4485 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487}
4488
4489void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4490{
4491 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
4495void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4496{
4497 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499}
4500
4501void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4502{
4503 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505}
4506
4507void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4508{
4509 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004510 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4514{
4515 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4520{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
4524void Context::vertexAttribPointer(GLuint index,
4525 GLint size,
4526 GLenum type,
4527 GLboolean normalized,
4528 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004529 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004530{
Corentin Wallez336129f2017-10-17 15:55:40 -04004531 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004532 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533}
4534
Shao80957d92017-02-20 21:25:59 +08004535void Context::vertexAttribFormat(GLuint attribIndex,
4536 GLint size,
4537 GLenum type,
4538 GLboolean normalized,
4539 GLuint relativeOffset)
4540{
Geoff Lang92019432017-11-20 13:09:34 -05004541 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004542 relativeOffset);
4543}
4544
4545void Context::vertexAttribIFormat(GLuint attribIndex,
4546 GLint size,
4547 GLenum type,
4548 GLuint relativeOffset)
4549{
4550 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4551}
4552
4553void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4554{
Shaodde78e82017-05-22 14:13:27 +08004555 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004556}
4557
Jiajia Qin5451d532017-11-16 17:16:34 +08004558void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004559{
4560 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4561}
4562
Jamie Madillc20ab272016-06-09 07:20:46 -07004563void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4564{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004565 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566}
4567
4568void Context::vertexAttribIPointer(GLuint index,
4569 GLint size,
4570 GLenum type,
4571 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004572 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004573{
Corentin Wallez336129f2017-10-17 15:55:40 -04004574 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4575 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576}
4577
4578void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4579{
4580 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582}
4583
4584void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4585{
4586 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588}
4589
4590void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4591{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004600void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4601{
4602 const VertexAttribCurrentValueData &currentValues =
4603 getGLState().getVertexAttribCurrentValue(index);
4604 const VertexArray *vao = getGLState().getVertexArray();
4605 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4606 currentValues, pname, params);
4607}
4608
Brandon Jones59770802018-04-02 13:18:42 -07004609void Context::getVertexAttribivRobust(GLuint index,
4610 GLenum pname,
4611 GLsizei bufSize,
4612 GLsizei *length,
4613 GLint *params)
4614{
4615 getVertexAttribiv(index, pname, params);
4616}
4617
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004618void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4619{
4620 const VertexAttribCurrentValueData &currentValues =
4621 getGLState().getVertexAttribCurrentValue(index);
4622 const VertexArray *vao = getGLState().getVertexArray();
4623 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4624 currentValues, pname, params);
4625}
4626
Brandon Jones59770802018-04-02 13:18:42 -07004627void Context::getVertexAttribfvRobust(GLuint index,
4628 GLenum pname,
4629 GLsizei bufSize,
4630 GLsizei *length,
4631 GLfloat *params)
4632{
4633 getVertexAttribfv(index, pname, params);
4634}
4635
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004636void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4637{
4638 const VertexAttribCurrentValueData &currentValues =
4639 getGLState().getVertexAttribCurrentValue(index);
4640 const VertexArray *vao = getGLState().getVertexArray();
4641 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4642 currentValues, pname, params);
4643}
4644
Brandon Jones59770802018-04-02 13:18:42 -07004645void Context::getVertexAttribIivRobust(GLuint index,
4646 GLenum pname,
4647 GLsizei bufSize,
4648 GLsizei *length,
4649 GLint *params)
4650{
4651 getVertexAttribIiv(index, pname, params);
4652}
4653
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004654void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4655{
4656 const VertexAttribCurrentValueData &currentValues =
4657 getGLState().getVertexAttribCurrentValue(index);
4658 const VertexArray *vao = getGLState().getVertexArray();
4659 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4660 currentValues, pname, params);
4661}
4662
Brandon Jones59770802018-04-02 13:18:42 -07004663void Context::getVertexAttribIuivRobust(GLuint index,
4664 GLenum pname,
4665 GLsizei bufSize,
4666 GLsizei *length,
4667 GLuint *params)
4668{
4669 getVertexAttribIuiv(index, pname, params);
4670}
4671
Jamie Madill876429b2017-04-20 15:46:24 -04004672void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004673{
4674 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4675 QueryVertexAttribPointerv(attrib, pname, pointer);
4676}
4677
Brandon Jones59770802018-04-02 13:18:42 -07004678void Context::getVertexAttribPointervRobust(GLuint index,
4679 GLenum pname,
4680 GLsizei bufSize,
4681 GLsizei *length,
4682 void **pointer)
4683{
4684 getVertexAttribPointerv(index, pname, pointer);
4685}
4686
Jamie Madillc20ab272016-06-09 07:20:46 -07004687void Context::debugMessageControl(GLenum source,
4688 GLenum type,
4689 GLenum severity,
4690 GLsizei count,
4691 const GLuint *ids,
4692 GLboolean enabled)
4693{
4694 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004695 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004696 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::debugMessageInsert(GLenum source,
4700 GLenum type,
4701 GLuint id,
4702 GLenum severity,
4703 GLsizei length,
4704 const GLchar *buf)
4705{
4706 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004708}
4709
4710void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713}
4714
4715GLuint Context::getDebugMessageLog(GLuint count,
4716 GLsizei bufSize,
4717 GLenum *sources,
4718 GLenum *types,
4719 GLuint *ids,
4720 GLenum *severities,
4721 GLsizei *lengths,
4722 GLchar *messageLog)
4723{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004724 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4725 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004726}
4727
4728void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4729{
4730 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004731 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004732 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733}
4734
4735void Context::popDebugGroup()
4736{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004737 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004738 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004739}
4740
Corentin Wallez336129f2017-10-17 15:55:40 -04004741void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004742{
4743 Buffer *buffer = mGLState.getTargetBuffer(target);
4744 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004745 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004746}
4747
Corentin Wallez336129f2017-10-17 15:55:40 -04004748void Context::bufferSubData(BufferBinding target,
4749 GLintptr offset,
4750 GLsizeiptr size,
4751 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004752{
4753 if (data == nullptr)
4754 {
4755 return;
4756 }
4757
4758 Buffer *buffer = mGLState.getTargetBuffer(target);
4759 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004760 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004761}
4762
Jamie Madillef300b12016-10-07 15:12:09 -04004763void Context::attachShader(GLuint program, GLuint shader)
4764{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004765 Program *programObject = mState.mShaderPrograms->getProgram(program);
4766 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004767 ASSERT(programObject && shaderObject);
4768 programObject->attachShader(shaderObject);
4769}
4770
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004771const Workarounds &Context::getWorkarounds() const
4772{
4773 return mWorkarounds;
4774}
4775
Corentin Wallez336129f2017-10-17 15:55:40 -04004776void Context::copyBufferSubData(BufferBinding readTarget,
4777 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004778 GLintptr readOffset,
4779 GLintptr writeOffset,
4780 GLsizeiptr size)
4781{
4782 // if size is zero, the copy is a successful no-op
4783 if (size == 0)
4784 {
4785 return;
4786 }
4787
4788 // TODO(jmadill): cache these.
4789 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4790 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4791
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004792 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004793}
4794
Jamie Madill01a80ee2016-11-07 12:06:18 -05004795void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4796{
4797 Program *programObject = getProgram(program);
4798 // TODO(jmadill): Re-use this from the validation if possible.
4799 ASSERT(programObject);
4800 programObject->bindAttributeLocation(index, name);
4801}
4802
Corentin Wallez336129f2017-10-17 15:55:40 -04004803void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004804{
Corentin Wallez336129f2017-10-17 15:55:40 -04004805 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4806 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004807}
4808
Corentin Wallez336129f2017-10-17 15:55:40 -04004809void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004810{
4811 bindBufferRange(target, index, buffer, 0, 0);
4812}
4813
Corentin Wallez336129f2017-10-17 15:55:40 -04004814void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004815 GLuint index,
4816 GLuint buffer,
4817 GLintptr offset,
4818 GLsizeiptr size)
4819{
Corentin Wallez336129f2017-10-17 15:55:40 -04004820 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4821 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004822}
4823
Jamie Madill01a80ee2016-11-07 12:06:18 -05004824void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4825{
4826 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4827 {
4828 bindReadFramebuffer(framebuffer);
4829 }
4830
4831 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4832 {
4833 bindDrawFramebuffer(framebuffer);
4834 }
4835}
4836
4837void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4838{
4839 ASSERT(target == GL_RENDERBUFFER);
4840 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004841 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004842 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004843}
4844
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004845void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004846 GLsizei samples,
4847 GLenum internalformat,
4848 GLsizei width,
4849 GLsizei height,
4850 GLboolean fixedsamplelocations)
4851{
4852 Extents size(width, height, 1);
4853 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004854 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4855 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004856}
4857
4858void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4859{
JiangYizhou5b03f472017-01-09 10:22:53 +08004860 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4861 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004862 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004863 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004864
4865 switch (pname)
4866 {
4867 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004868 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004869 break;
4870 default:
4871 UNREACHABLE();
4872 }
4873}
4874
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004875void Context::getMultisamplefvRobust(GLenum pname,
4876 GLuint index,
4877 GLsizei bufSize,
4878 GLsizei *length,
4879 GLfloat *val)
4880{
4881 UNIMPLEMENTED();
4882}
4883
Jamie Madille8fb6402017-02-14 17:56:40 -05004884void Context::renderbufferStorage(GLenum target,
4885 GLenum internalformat,
4886 GLsizei width,
4887 GLsizei height)
4888{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004889 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4890 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4891
Jamie Madille8fb6402017-02-14 17:56:40 -05004892 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004893 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004894}
4895
4896void Context::renderbufferStorageMultisample(GLenum target,
4897 GLsizei samples,
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);
Jamie Madille8fb6402017-02-14 17:56:40 -05004904
4905 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004906 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004907 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004908}
4909
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004910void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4911{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004912 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004913 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004914}
4915
JiangYizhoue18e6392017-02-20 10:32:23 +08004916void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4917{
4918 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4919 QueryFramebufferParameteriv(framebuffer, pname, params);
4920}
4921
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004922void Context::getFramebufferParameterivRobust(GLenum target,
4923 GLenum pname,
4924 GLsizei bufSize,
4925 GLsizei *length,
4926 GLint *params)
4927{
4928 UNIMPLEMENTED();
4929}
4930
Jiajia Qin5451d532017-11-16 17:16:34 +08004931void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004932{
4933 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4934 SetFramebufferParameteri(framebuffer, pname, param);
4935}
4936
Jamie Madillb3f26b92017-07-19 15:07:41 -04004937Error Context::getScratchBuffer(size_t requstedSizeBytes,
4938 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004939{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004940 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4941 {
4942 return OutOfMemory() << "Failed to allocate internal buffer.";
4943 }
4944 return NoError();
4945}
4946
4947Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4948 angle::MemoryBuffer **zeroBufferOut) const
4949{
4950 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004951 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004952 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004953 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004954 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004955}
4956
Xinghua Cao10a4d432017-11-28 14:46:26 +08004957Error Context::prepareForDispatch()
4958{
Geoff Langa8cb2872018-03-09 16:09:40 -05004959 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004960
4961 if (isRobustResourceInitEnabled())
4962 {
4963 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4964 }
4965
4966 return NoError();
4967}
4968
Xinghua Cao2b396592017-03-29 15:36:04 +08004969void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4970{
4971 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4972 {
4973 return;
4974 }
4975
Xinghua Cao10a4d432017-11-28 14:46:26 +08004976 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004977 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004978}
4979
Jiajia Qin5451d532017-11-16 17:16:34 +08004980void Context::dispatchComputeIndirect(GLintptr indirect)
4981{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004982 ANGLE_CONTEXT_TRY(prepareForDispatch());
4983 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004984}
4985
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004986void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004987 GLsizei levels,
4988 GLenum internalFormat,
4989 GLsizei width,
4990 GLsizei height)
4991{
4992 Extents size(width, height, 1);
4993 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004994 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004995}
4996
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004997void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004998 GLsizei levels,
4999 GLenum internalFormat,
5000 GLsizei width,
5001 GLsizei height,
5002 GLsizei depth)
5003{
5004 Extents size(width, height, depth);
5005 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005006 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005007}
5008
Jiajia Qin5451d532017-11-16 17:16:34 +08005009void Context::memoryBarrier(GLbitfield barriers)
5010{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005011 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005012}
5013
5014void Context::memoryBarrierByRegion(GLbitfield barriers)
5015{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005016 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005017}
5018
Jamie Madillc1d770e2017-04-13 17:31:24 -04005019GLenum Context::checkFramebufferStatus(GLenum target)
5020{
5021 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5022 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005023 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005024}
5025
5026void Context::compileShader(GLuint shader)
5027{
5028 Shader *shaderObject = GetValidShader(this, shader);
5029 if (!shaderObject)
5030 {
5031 return;
5032 }
5033 shaderObject->compile(this);
5034}
5035
5036void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5037{
5038 for (int i = 0; i < n; i++)
5039 {
5040 deleteBuffer(buffers[i]);
5041 }
5042}
5043
5044void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5045{
5046 for (int i = 0; i < n; i++)
5047 {
5048 if (framebuffers[i] != 0)
5049 {
5050 deleteFramebuffer(framebuffers[i]);
5051 }
5052 }
5053}
5054
5055void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5056{
5057 for (int i = 0; i < n; i++)
5058 {
5059 deleteRenderbuffer(renderbuffers[i]);
5060 }
5061}
5062
5063void Context::deleteTextures(GLsizei n, const GLuint *textures)
5064{
5065 for (int i = 0; i < n; i++)
5066 {
5067 if (textures[i] != 0)
5068 {
5069 deleteTexture(textures[i]);
5070 }
5071 }
5072}
5073
5074void Context::detachShader(GLuint program, GLuint shader)
5075{
5076 Program *programObject = getProgram(program);
5077 ASSERT(programObject);
5078
5079 Shader *shaderObject = getShader(shader);
5080 ASSERT(shaderObject);
5081
5082 programObject->detachShader(this, shaderObject);
5083}
5084
5085void Context::genBuffers(GLsizei n, GLuint *buffers)
5086{
5087 for (int i = 0; i < n; i++)
5088 {
5089 buffers[i] = createBuffer();
5090 }
5091}
5092
5093void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5094{
5095 for (int i = 0; i < n; i++)
5096 {
5097 framebuffers[i] = createFramebuffer();
5098 }
5099}
5100
5101void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5102{
5103 for (int i = 0; i < n; i++)
5104 {
5105 renderbuffers[i] = createRenderbuffer();
5106 }
5107}
5108
5109void Context::genTextures(GLsizei n, GLuint *textures)
5110{
5111 for (int i = 0; i < n; i++)
5112 {
5113 textures[i] = createTexture();
5114 }
5115}
5116
5117void Context::getActiveAttrib(GLuint program,
5118 GLuint index,
5119 GLsizei bufsize,
5120 GLsizei *length,
5121 GLint *size,
5122 GLenum *type,
5123 GLchar *name)
5124{
5125 Program *programObject = getProgram(program);
5126 ASSERT(programObject);
5127 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5128}
5129
5130void Context::getActiveUniform(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->getActiveUniform(index, bufsize, length, size, type, name);
5141}
5142
5143void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5144{
5145 Program *programObject = getProgram(program);
5146 ASSERT(programObject);
5147 programObject->getAttachedShaders(maxcount, count, shaders);
5148}
5149
5150GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5151{
5152 Program *programObject = getProgram(program);
5153 ASSERT(programObject);
5154 return programObject->getAttributeLocation(name);
5155}
5156
5157void Context::getBooleanv(GLenum pname, GLboolean *params)
5158{
5159 GLenum nativeType;
5160 unsigned int numParams = 0;
5161 getQueryParameterInfo(pname, &nativeType, &numParams);
5162
5163 if (nativeType == GL_BOOL)
5164 {
5165 getBooleanvImpl(pname, params);
5166 }
5167 else
5168 {
5169 CastStateValues(this, nativeType, pname, numParams, params);
5170 }
5171}
5172
Brandon Jones59770802018-04-02 13:18:42 -07005173void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5174{
5175 getBooleanv(pname, params);
5176}
5177
Jamie Madillc1d770e2017-04-13 17:31:24 -04005178void Context::getFloatv(GLenum pname, GLfloat *params)
5179{
5180 GLenum nativeType;
5181 unsigned int numParams = 0;
5182 getQueryParameterInfo(pname, &nativeType, &numParams);
5183
5184 if (nativeType == GL_FLOAT)
5185 {
5186 getFloatvImpl(pname, params);
5187 }
5188 else
5189 {
5190 CastStateValues(this, nativeType, pname, numParams, params);
5191 }
5192}
5193
Brandon Jones59770802018-04-02 13:18:42 -07005194void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5195{
5196 getFloatv(pname, params);
5197}
5198
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199void Context::getIntegerv(GLenum pname, GLint *params)
5200{
5201 GLenum nativeType;
5202 unsigned int numParams = 0;
5203 getQueryParameterInfo(pname, &nativeType, &numParams);
5204
5205 if (nativeType == GL_INT)
5206 {
5207 getIntegervImpl(pname, params);
5208 }
5209 else
5210 {
5211 CastStateValues(this, nativeType, pname, numParams, params);
5212 }
5213}
5214
Brandon Jones59770802018-04-02 13:18:42 -07005215void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5216{
5217 getIntegerv(pname, data);
5218}
5219
Jamie Madillc1d770e2017-04-13 17:31:24 -04005220void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5221{
5222 Program *programObject = getProgram(program);
5223 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005224 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005225}
5226
Brandon Jones59770802018-04-02 13:18:42 -07005227void Context::getProgramivRobust(GLuint program,
5228 GLenum pname,
5229 GLsizei bufSize,
5230 GLsizei *length,
5231 GLint *params)
5232{
5233 getProgramiv(program, pname, params);
5234}
5235
Jiajia Qin5451d532017-11-16 17:16:34 +08005236void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5237{
5238 UNIMPLEMENTED();
5239}
5240
Jamie Madillbe849e42017-05-02 15:49:00 -04005241void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005242{
5243 Program *programObject = getProgram(program);
5244 ASSERT(programObject);
5245 programObject->getInfoLog(bufsize, length, infolog);
5246}
5247
Jiajia Qin5451d532017-11-16 17:16:34 +08005248void Context::getProgramPipelineInfoLog(GLuint pipeline,
5249 GLsizei bufSize,
5250 GLsizei *length,
5251 GLchar *infoLog)
5252{
5253 UNIMPLEMENTED();
5254}
5255
Jamie Madillc1d770e2017-04-13 17:31:24 -04005256void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5257{
5258 Shader *shaderObject = getShader(shader);
5259 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005260 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005261}
5262
Brandon Jones59770802018-04-02 13:18:42 -07005263void Context::getShaderivRobust(GLuint shader,
5264 GLenum pname,
5265 GLsizei bufSize,
5266 GLsizei *length,
5267 GLint *params)
5268{
5269 getShaderiv(shader, pname, params);
5270}
5271
Jamie Madillc1d770e2017-04-13 17:31:24 -04005272void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5273{
5274 Shader *shaderObject = getShader(shader);
5275 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005276 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005277}
5278
5279void Context::getShaderPrecisionFormat(GLenum shadertype,
5280 GLenum precisiontype,
5281 GLint *range,
5282 GLint *precision)
5283{
5284 // TODO(jmadill): Compute shaders.
5285
5286 switch (shadertype)
5287 {
5288 case GL_VERTEX_SHADER:
5289 switch (precisiontype)
5290 {
5291 case GL_LOW_FLOAT:
5292 mCaps.vertexLowpFloat.get(range, precision);
5293 break;
5294 case GL_MEDIUM_FLOAT:
5295 mCaps.vertexMediumpFloat.get(range, precision);
5296 break;
5297 case GL_HIGH_FLOAT:
5298 mCaps.vertexHighpFloat.get(range, precision);
5299 break;
5300
5301 case GL_LOW_INT:
5302 mCaps.vertexLowpInt.get(range, precision);
5303 break;
5304 case GL_MEDIUM_INT:
5305 mCaps.vertexMediumpInt.get(range, precision);
5306 break;
5307 case GL_HIGH_INT:
5308 mCaps.vertexHighpInt.get(range, precision);
5309 break;
5310
5311 default:
5312 UNREACHABLE();
5313 return;
5314 }
5315 break;
5316
5317 case GL_FRAGMENT_SHADER:
5318 switch (precisiontype)
5319 {
5320 case GL_LOW_FLOAT:
5321 mCaps.fragmentLowpFloat.get(range, precision);
5322 break;
5323 case GL_MEDIUM_FLOAT:
5324 mCaps.fragmentMediumpFloat.get(range, precision);
5325 break;
5326 case GL_HIGH_FLOAT:
5327 mCaps.fragmentHighpFloat.get(range, precision);
5328 break;
5329
5330 case GL_LOW_INT:
5331 mCaps.fragmentLowpInt.get(range, precision);
5332 break;
5333 case GL_MEDIUM_INT:
5334 mCaps.fragmentMediumpInt.get(range, precision);
5335 break;
5336 case GL_HIGH_INT:
5337 mCaps.fragmentHighpInt.get(range, precision);
5338 break;
5339
5340 default:
5341 UNREACHABLE();
5342 return;
5343 }
5344 break;
5345
5346 default:
5347 UNREACHABLE();
5348 return;
5349 }
5350}
5351
5352void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5353{
5354 Shader *shaderObject = getShader(shader);
5355 ASSERT(shaderObject);
5356 shaderObject->getSource(bufsize, length, source);
5357}
5358
5359void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5360{
5361 Program *programObject = getProgram(program);
5362 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005363 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005364}
5365
Brandon Jones59770802018-04-02 13:18:42 -07005366void Context::getUniformfvRobust(GLuint program,
5367 GLint location,
5368 GLsizei bufSize,
5369 GLsizei *length,
5370 GLfloat *params)
5371{
5372 getUniformfv(program, location, params);
5373}
5374
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5376{
5377 Program *programObject = getProgram(program);
5378 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005379 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005380}
5381
Brandon Jones59770802018-04-02 13:18:42 -07005382void Context::getUniformivRobust(GLuint program,
5383 GLint location,
5384 GLsizei bufSize,
5385 GLsizei *length,
5386 GLint *params)
5387{
5388 getUniformiv(program, location, params);
5389}
5390
Jamie Madillc1d770e2017-04-13 17:31:24 -04005391GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5392{
5393 Program *programObject = getProgram(program);
5394 ASSERT(programObject);
5395 return programObject->getUniformLocation(name);
5396}
5397
5398GLboolean Context::isBuffer(GLuint buffer)
5399{
5400 if (buffer == 0)
5401 {
5402 return GL_FALSE;
5403 }
5404
5405 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5406}
5407
5408GLboolean Context::isEnabled(GLenum cap)
5409{
5410 return mGLState.getEnableFeature(cap);
5411}
5412
5413GLboolean Context::isFramebuffer(GLuint framebuffer)
5414{
5415 if (framebuffer == 0)
5416 {
5417 return GL_FALSE;
5418 }
5419
5420 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5421}
5422
5423GLboolean Context::isProgram(GLuint program)
5424{
5425 if (program == 0)
5426 {
5427 return GL_FALSE;
5428 }
5429
5430 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5431}
5432
5433GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5434{
5435 if (renderbuffer == 0)
5436 {
5437 return GL_FALSE;
5438 }
5439
5440 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5441}
5442
5443GLboolean Context::isShader(GLuint shader)
5444{
5445 if (shader == 0)
5446 {
5447 return GL_FALSE;
5448 }
5449
5450 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5451}
5452
5453GLboolean Context::isTexture(GLuint texture)
5454{
5455 if (texture == 0)
5456 {
5457 return GL_FALSE;
5458 }
5459
5460 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5461}
5462
5463void Context::linkProgram(GLuint program)
5464{
5465 Program *programObject = getProgram(program);
5466 ASSERT(programObject);
5467 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005468 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005469}
5470
5471void Context::releaseShaderCompiler()
5472{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005473 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474}
5475
5476void Context::shaderBinary(GLsizei n,
5477 const GLuint *shaders,
5478 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005479 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005480 GLsizei length)
5481{
5482 // No binary shader formats are supported.
5483 UNIMPLEMENTED();
5484}
5485
5486void Context::shaderSource(GLuint shader,
5487 GLsizei count,
5488 const GLchar *const *string,
5489 const GLint *length)
5490{
5491 Shader *shaderObject = getShader(shader);
5492 ASSERT(shaderObject);
5493 shaderObject->setSource(count, string, length);
5494}
5495
5496void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5497{
5498 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5499}
5500
5501void Context::stencilMask(GLuint mask)
5502{
5503 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5504}
5505
5506void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5507{
5508 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5509}
5510
5511void Context::uniform1f(GLint location, GLfloat x)
5512{
5513 Program *program = mGLState.getProgram();
5514 program->setUniform1fv(location, 1, &x);
5515}
5516
5517void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5518{
5519 Program *program = mGLState.getProgram();
5520 program->setUniform1fv(location, count, v);
5521}
5522
5523void Context::uniform1i(GLint location, GLint x)
5524{
5525 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005526 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5527 {
5528 mGLState.setObjectDirty(GL_PROGRAM);
5529 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005530}
5531
5532void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5533{
5534 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005535 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5536 {
5537 mGLState.setObjectDirty(GL_PROGRAM);
5538 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005539}
5540
5541void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5542{
5543 GLfloat xy[2] = {x, y};
5544 Program *program = mGLState.getProgram();
5545 program->setUniform2fv(location, 1, xy);
5546}
5547
5548void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5549{
5550 Program *program = mGLState.getProgram();
5551 program->setUniform2fv(location, count, v);
5552}
5553
5554void Context::uniform2i(GLint location, GLint x, GLint y)
5555{
5556 GLint xy[2] = {x, y};
5557 Program *program = mGLState.getProgram();
5558 program->setUniform2iv(location, 1, xy);
5559}
5560
5561void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5562{
5563 Program *program = mGLState.getProgram();
5564 program->setUniform2iv(location, count, v);
5565}
5566
5567void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5568{
5569 GLfloat xyz[3] = {x, y, z};
5570 Program *program = mGLState.getProgram();
5571 program->setUniform3fv(location, 1, xyz);
5572}
5573
5574void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5575{
5576 Program *program = mGLState.getProgram();
5577 program->setUniform3fv(location, count, v);
5578}
5579
5580void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5581{
5582 GLint xyz[3] = {x, y, z};
5583 Program *program = mGLState.getProgram();
5584 program->setUniform3iv(location, 1, xyz);
5585}
5586
5587void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5588{
5589 Program *program = mGLState.getProgram();
5590 program->setUniform3iv(location, count, v);
5591}
5592
5593void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5594{
5595 GLfloat xyzw[4] = {x, y, z, w};
5596 Program *program = mGLState.getProgram();
5597 program->setUniform4fv(location, 1, xyzw);
5598}
5599
5600void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5601{
5602 Program *program = mGLState.getProgram();
5603 program->setUniform4fv(location, count, v);
5604}
5605
5606void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5607{
5608 GLint xyzw[4] = {x, y, z, w};
5609 Program *program = mGLState.getProgram();
5610 program->setUniform4iv(location, 1, xyzw);
5611}
5612
5613void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5614{
5615 Program *program = mGLState.getProgram();
5616 program->setUniform4iv(location, count, v);
5617}
5618
5619void Context::uniformMatrix2fv(GLint location,
5620 GLsizei count,
5621 GLboolean transpose,
5622 const GLfloat *value)
5623{
5624 Program *program = mGLState.getProgram();
5625 program->setUniformMatrix2fv(location, count, transpose, value);
5626}
5627
5628void Context::uniformMatrix3fv(GLint location,
5629 GLsizei count,
5630 GLboolean transpose,
5631 const GLfloat *value)
5632{
5633 Program *program = mGLState.getProgram();
5634 program->setUniformMatrix3fv(location, count, transpose, value);
5635}
5636
5637void Context::uniformMatrix4fv(GLint location,
5638 GLsizei count,
5639 GLboolean transpose,
5640 const GLfloat *value)
5641{
5642 Program *program = mGLState.getProgram();
5643 program->setUniformMatrix4fv(location, count, transpose, value);
5644}
5645
5646void Context::validateProgram(GLuint program)
5647{
5648 Program *programObject = getProgram(program);
5649 ASSERT(programObject);
5650 programObject->validate(mCaps);
5651}
5652
Jiajia Qin5451d532017-11-16 17:16:34 +08005653void Context::validateProgramPipeline(GLuint pipeline)
5654{
5655 UNIMPLEMENTED();
5656}
5657
Jamie Madilld04908b2017-06-09 14:15:35 -04005658void Context::getProgramBinary(GLuint program,
5659 GLsizei bufSize,
5660 GLsizei *length,
5661 GLenum *binaryFormat,
5662 void *binary)
5663{
5664 Program *programObject = getProgram(program);
5665 ASSERT(programObject != nullptr);
5666
5667 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5668}
5669
5670void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5671{
5672 Program *programObject = getProgram(program);
5673 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005674
Jamie Madilld04908b2017-06-09 14:15:35 -04005675 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5676}
5677
Jamie Madillff325f12017-08-26 15:06:05 -04005678void Context::uniform1ui(GLint location, GLuint v0)
5679{
5680 Program *program = mGLState.getProgram();
5681 program->setUniform1uiv(location, 1, &v0);
5682}
5683
5684void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5685{
5686 Program *program = mGLState.getProgram();
5687 const GLuint xy[] = {v0, v1};
5688 program->setUniform2uiv(location, 1, xy);
5689}
5690
5691void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5692{
5693 Program *program = mGLState.getProgram();
5694 const GLuint xyz[] = {v0, v1, v2};
5695 program->setUniform3uiv(location, 1, xyz);
5696}
5697
5698void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5699{
5700 Program *program = mGLState.getProgram();
5701 const GLuint xyzw[] = {v0, v1, v2, v3};
5702 program->setUniform4uiv(location, 1, xyzw);
5703}
5704
5705void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5706{
5707 Program *program = mGLState.getProgram();
5708 program->setUniform1uiv(location, count, value);
5709}
5710void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5711{
5712 Program *program = mGLState.getProgram();
5713 program->setUniform2uiv(location, count, value);
5714}
5715
5716void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5717{
5718 Program *program = mGLState.getProgram();
5719 program->setUniform3uiv(location, count, value);
5720}
5721
5722void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5723{
5724 Program *program = mGLState.getProgram();
5725 program->setUniform4uiv(location, count, value);
5726}
5727
Jamie Madillf0e04492017-08-26 15:28:42 -04005728void Context::genQueries(GLsizei n, GLuint *ids)
5729{
5730 for (GLsizei i = 0; i < n; i++)
5731 {
5732 GLuint handle = mQueryHandleAllocator.allocate();
5733 mQueryMap.assign(handle, nullptr);
5734 ids[i] = handle;
5735 }
5736}
5737
5738void Context::deleteQueries(GLsizei n, const GLuint *ids)
5739{
5740 for (int i = 0; i < n; i++)
5741 {
5742 GLuint query = ids[i];
5743
5744 Query *queryObject = nullptr;
5745 if (mQueryMap.erase(query, &queryObject))
5746 {
5747 mQueryHandleAllocator.release(query);
5748 if (queryObject)
5749 {
5750 queryObject->release(this);
5751 }
5752 }
5753 }
5754}
5755
5756GLboolean Context::isQuery(GLuint id)
5757{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005758 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005759}
5760
Jamie Madillc8c95812017-08-26 18:40:09 -04005761void Context::uniformMatrix2x3fv(GLint location,
5762 GLsizei count,
5763 GLboolean transpose,
5764 const GLfloat *value)
5765{
5766 Program *program = mGLState.getProgram();
5767 program->setUniformMatrix2x3fv(location, count, transpose, value);
5768}
5769
5770void Context::uniformMatrix3x2fv(GLint location,
5771 GLsizei count,
5772 GLboolean transpose,
5773 const GLfloat *value)
5774{
5775 Program *program = mGLState.getProgram();
5776 program->setUniformMatrix3x2fv(location, count, transpose, value);
5777}
5778
5779void Context::uniformMatrix2x4fv(GLint location,
5780 GLsizei count,
5781 GLboolean transpose,
5782 const GLfloat *value)
5783{
5784 Program *program = mGLState.getProgram();
5785 program->setUniformMatrix2x4fv(location, count, transpose, value);
5786}
5787
5788void Context::uniformMatrix4x2fv(GLint location,
5789 GLsizei count,
5790 GLboolean transpose,
5791 const GLfloat *value)
5792{
5793 Program *program = mGLState.getProgram();
5794 program->setUniformMatrix4x2fv(location, count, transpose, value);
5795}
5796
5797void Context::uniformMatrix3x4fv(GLint location,
5798 GLsizei count,
5799 GLboolean transpose,
5800 const GLfloat *value)
5801{
5802 Program *program = mGLState.getProgram();
5803 program->setUniformMatrix3x4fv(location, count, transpose, value);
5804}
5805
5806void Context::uniformMatrix4x3fv(GLint location,
5807 GLsizei count,
5808 GLboolean transpose,
5809 const GLfloat *value)
5810{
5811 Program *program = mGLState.getProgram();
5812 program->setUniformMatrix4x3fv(location, count, transpose, value);
5813}
5814
Jamie Madilld7576732017-08-26 18:49:50 -04005815void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5816{
5817 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5818 {
5819 GLuint vertexArray = arrays[arrayIndex];
5820
5821 if (arrays[arrayIndex] != 0)
5822 {
5823 VertexArray *vertexArrayObject = nullptr;
5824 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5825 {
5826 if (vertexArrayObject != nullptr)
5827 {
5828 detachVertexArray(vertexArray);
5829 vertexArrayObject->onDestroy(this);
5830 }
5831
5832 mVertexArrayHandleAllocator.release(vertexArray);
5833 }
5834 }
5835 }
5836}
5837
5838void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5839{
5840 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5841 {
5842 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5843 mVertexArrayMap.assign(vertexArray, nullptr);
5844 arrays[arrayIndex] = vertexArray;
5845 }
5846}
5847
5848bool Context::isVertexArray(GLuint array)
5849{
5850 if (array == 0)
5851 {
5852 return GL_FALSE;
5853 }
5854
5855 VertexArray *vao = getVertexArray(array);
5856 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5857}
5858
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005859void Context::endTransformFeedback()
5860{
5861 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5862 transformFeedback->end(this);
5863}
5864
5865void Context::transformFeedbackVaryings(GLuint program,
5866 GLsizei count,
5867 const GLchar *const *varyings,
5868 GLenum bufferMode)
5869{
5870 Program *programObject = getProgram(program);
5871 ASSERT(programObject);
5872 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5873}
5874
5875void Context::getTransformFeedbackVarying(GLuint program,
5876 GLuint index,
5877 GLsizei bufSize,
5878 GLsizei *length,
5879 GLsizei *size,
5880 GLenum *type,
5881 GLchar *name)
5882{
5883 Program *programObject = getProgram(program);
5884 ASSERT(programObject);
5885 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5886}
5887
5888void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5889{
5890 for (int i = 0; i < n; i++)
5891 {
5892 GLuint transformFeedback = ids[i];
5893 if (transformFeedback == 0)
5894 {
5895 continue;
5896 }
5897
5898 TransformFeedback *transformFeedbackObject = nullptr;
5899 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5900 {
5901 if (transformFeedbackObject != nullptr)
5902 {
5903 detachTransformFeedback(transformFeedback);
5904 transformFeedbackObject->release(this);
5905 }
5906
5907 mTransformFeedbackHandleAllocator.release(transformFeedback);
5908 }
5909 }
5910}
5911
5912void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5913{
5914 for (int i = 0; i < n; i++)
5915 {
5916 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5917 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5918 ids[i] = transformFeedback;
5919 }
5920}
5921
5922bool Context::isTransformFeedback(GLuint id)
5923{
5924 if (id == 0)
5925 {
5926 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5927 // returns FALSE
5928 return GL_FALSE;
5929 }
5930
5931 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5932 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5933}
5934
5935void Context::pauseTransformFeedback()
5936{
5937 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5938 transformFeedback->pause();
5939}
5940
5941void Context::resumeTransformFeedback()
5942{
5943 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5944 transformFeedback->resume();
5945}
5946
Jamie Madill12e957f2017-08-26 21:42:26 -04005947void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5948{
5949 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005950 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005951}
5952
Brandon Jones59770802018-04-02 13:18:42 -07005953void Context::getUniformuivRobust(GLuint program,
5954 GLint location,
5955 GLsizei bufSize,
5956 GLsizei *length,
5957 GLuint *params)
5958{
5959 getUniformuiv(program, location, params);
5960}
5961
Jamie Madill12e957f2017-08-26 21:42:26 -04005962GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5963{
5964 const Program *programObject = getProgram(program);
5965 return programObject->getFragDataLocation(name);
5966}
5967
5968void Context::getUniformIndices(GLuint program,
5969 GLsizei uniformCount,
5970 const GLchar *const *uniformNames,
5971 GLuint *uniformIndices)
5972{
5973 const Program *programObject = getProgram(program);
5974 if (!programObject->isLinked())
5975 {
5976 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5977 {
5978 uniformIndices[uniformId] = GL_INVALID_INDEX;
5979 }
5980 }
5981 else
5982 {
5983 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5984 {
5985 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5986 }
5987 }
5988}
5989
5990void Context::getActiveUniformsiv(GLuint program,
5991 GLsizei uniformCount,
5992 const GLuint *uniformIndices,
5993 GLenum pname,
5994 GLint *params)
5995{
5996 const Program *programObject = getProgram(program);
5997 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5998 {
5999 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006000 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006001 }
6002}
6003
6004GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6005{
6006 const Program *programObject = getProgram(program);
6007 return programObject->getUniformBlockIndex(uniformBlockName);
6008}
6009
6010void Context::getActiveUniformBlockiv(GLuint program,
6011 GLuint uniformBlockIndex,
6012 GLenum pname,
6013 GLint *params)
6014{
6015 const Program *programObject = getProgram(program);
6016 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6017}
6018
Brandon Jones59770802018-04-02 13:18:42 -07006019void Context::getActiveUniformBlockivRobust(GLuint program,
6020 GLuint uniformBlockIndex,
6021 GLenum pname,
6022 GLsizei bufSize,
6023 GLsizei *length,
6024 GLint *params)
6025{
6026 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6027}
6028
Jamie Madill12e957f2017-08-26 21:42:26 -04006029void Context::getActiveUniformBlockName(GLuint program,
6030 GLuint uniformBlockIndex,
6031 GLsizei bufSize,
6032 GLsizei *length,
6033 GLchar *uniformBlockName)
6034{
6035 const Program *programObject = getProgram(program);
6036 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6037}
6038
6039void Context::uniformBlockBinding(GLuint program,
6040 GLuint uniformBlockIndex,
6041 GLuint uniformBlockBinding)
6042{
6043 Program *programObject = getProgram(program);
6044 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6045}
6046
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006047GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6048{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006049 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6050 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006051
Jamie Madill70b5bb02017-08-28 13:32:37 -04006052 Sync *syncObject = getSync(syncHandle);
6053 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006054 if (error.isError())
6055 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006056 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006057 handleError(error);
6058 return nullptr;
6059 }
6060
Jamie Madill70b5bb02017-08-28 13:32:37 -04006061 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006062}
6063
6064GLboolean Context::isSync(GLsync sync)
6065{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006066 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006067}
6068
6069GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6070{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006071 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006072
6073 GLenum result = GL_WAIT_FAILED;
6074 handleError(syncObject->clientWait(flags, timeout, &result));
6075 return result;
6076}
6077
6078void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6079{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006080 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006081 handleError(syncObject->serverWait(flags, timeout));
6082}
6083
6084void Context::getInteger64v(GLenum pname, GLint64 *params)
6085{
6086 GLenum nativeType = GL_NONE;
6087 unsigned int numParams = 0;
6088 getQueryParameterInfo(pname, &nativeType, &numParams);
6089
6090 if (nativeType == GL_INT_64_ANGLEX)
6091 {
6092 getInteger64vImpl(pname, params);
6093 }
6094 else
6095 {
6096 CastStateValues(this, nativeType, pname, numParams, params);
6097 }
6098}
6099
Brandon Jones59770802018-04-02 13:18:42 -07006100void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6101{
6102 getInteger64v(pname, data);
6103}
6104
Corentin Wallez336129f2017-10-17 15:55:40 -04006105void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006106{
6107 Buffer *buffer = mGLState.getTargetBuffer(target);
6108 QueryBufferParameteri64v(buffer, pname, params);
6109}
6110
Brandon Jones59770802018-04-02 13:18:42 -07006111void Context::getBufferParameteri64vRobust(BufferBinding target,
6112 GLenum pname,
6113 GLsizei bufSize,
6114 GLsizei *length,
6115 GLint64 *params)
6116{
6117 getBufferParameteri64v(target, pname, params);
6118}
6119
Jamie Madill3ef140a2017-08-26 23:11:21 -04006120void Context::genSamplers(GLsizei count, GLuint *samplers)
6121{
6122 for (int i = 0; i < count; i++)
6123 {
6124 samplers[i] = mState.mSamplers->createSampler();
6125 }
6126}
6127
6128void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6129{
6130 for (int i = 0; i < count; i++)
6131 {
6132 GLuint sampler = samplers[i];
6133
6134 if (mState.mSamplers->getSampler(sampler))
6135 {
6136 detachSampler(sampler);
6137 }
6138
6139 mState.mSamplers->deleteObject(this, sampler);
6140 }
6141}
6142
6143void Context::getInternalformativ(GLenum target,
6144 GLenum internalformat,
6145 GLenum pname,
6146 GLsizei bufSize,
6147 GLint *params)
6148{
6149 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6150 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6151}
6152
Brandon Jones59770802018-04-02 13:18:42 -07006153void Context::getInternalformativRobust(GLenum target,
6154 GLenum internalformat,
6155 GLenum pname,
6156 GLsizei bufSize,
6157 GLsizei *length,
6158 GLint *params)
6159{
6160 getInternalformativ(target, internalformat, pname, bufSize, params);
6161}
6162
Jiajia Qin5451d532017-11-16 17:16:34 +08006163void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6164{
6165 programUniform1iv(program, location, 1, &v0);
6166}
6167
6168void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6169{
6170 GLint xy[2] = {v0, v1};
6171 programUniform2iv(program, location, 1, xy);
6172}
6173
6174void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6175{
6176 GLint xyz[3] = {v0, v1, v2};
6177 programUniform3iv(program, location, 1, xyz);
6178}
6179
6180void Context::programUniform4i(GLuint program,
6181 GLint location,
6182 GLint v0,
6183 GLint v1,
6184 GLint v2,
6185 GLint v3)
6186{
6187 GLint xyzw[4] = {v0, v1, v2, v3};
6188 programUniform4iv(program, location, 1, xyzw);
6189}
6190
6191void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6192{
6193 programUniform1uiv(program, location, 1, &v0);
6194}
6195
6196void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6197{
6198 GLuint xy[2] = {v0, v1};
6199 programUniform2uiv(program, location, 1, xy);
6200}
6201
6202void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6203{
6204 GLuint xyz[3] = {v0, v1, v2};
6205 programUniform3uiv(program, location, 1, xyz);
6206}
6207
6208void Context::programUniform4ui(GLuint program,
6209 GLint location,
6210 GLuint v0,
6211 GLuint v1,
6212 GLuint v2,
6213 GLuint v3)
6214{
6215 GLuint xyzw[4] = {v0, v1, v2, v3};
6216 programUniform4uiv(program, location, 1, xyzw);
6217}
6218
6219void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6220{
6221 programUniform1fv(program, location, 1, &v0);
6222}
6223
6224void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6225{
6226 GLfloat xy[2] = {v0, v1};
6227 programUniform2fv(program, location, 1, xy);
6228}
6229
6230void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6231{
6232 GLfloat xyz[3] = {v0, v1, v2};
6233 programUniform3fv(program, location, 1, xyz);
6234}
6235
6236void Context::programUniform4f(GLuint program,
6237 GLint location,
6238 GLfloat v0,
6239 GLfloat v1,
6240 GLfloat v2,
6241 GLfloat v3)
6242{
6243 GLfloat xyzw[4] = {v0, v1, v2, v3};
6244 programUniform4fv(program, location, 1, xyzw);
6245}
6246
Jamie Madill81c2e252017-09-09 23:32:46 -04006247void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6248{
6249 Program *programObject = getProgram(program);
6250 ASSERT(programObject);
6251 if (programObject->setUniform1iv(location, count, value) ==
6252 Program::SetUniformResult::SamplerChanged)
6253 {
6254 mGLState.setObjectDirty(GL_PROGRAM);
6255 }
6256}
6257
Jiajia Qin5451d532017-11-16 17:16:34 +08006258void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6259{
6260 Program *programObject = getProgram(program);
6261 ASSERT(programObject);
6262 programObject->setUniform2iv(location, count, value);
6263}
6264
6265void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6266{
6267 Program *programObject = getProgram(program);
6268 ASSERT(programObject);
6269 programObject->setUniform3iv(location, count, value);
6270}
6271
6272void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6273{
6274 Program *programObject = getProgram(program);
6275 ASSERT(programObject);
6276 programObject->setUniform4iv(location, count, value);
6277}
6278
6279void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6280{
6281 Program *programObject = getProgram(program);
6282 ASSERT(programObject);
6283 programObject->setUniform1uiv(location, count, value);
6284}
6285
6286void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6287{
6288 Program *programObject = getProgram(program);
6289 ASSERT(programObject);
6290 programObject->setUniform2uiv(location, count, value);
6291}
6292
6293void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6294{
6295 Program *programObject = getProgram(program);
6296 ASSERT(programObject);
6297 programObject->setUniform3uiv(location, count, value);
6298}
6299
6300void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6301{
6302 Program *programObject = getProgram(program);
6303 ASSERT(programObject);
6304 programObject->setUniform4uiv(location, count, value);
6305}
6306
6307void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6308{
6309 Program *programObject = getProgram(program);
6310 ASSERT(programObject);
6311 programObject->setUniform1fv(location, count, value);
6312}
6313
6314void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6315{
6316 Program *programObject = getProgram(program);
6317 ASSERT(programObject);
6318 programObject->setUniform2fv(location, count, value);
6319}
6320
6321void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6322{
6323 Program *programObject = getProgram(program);
6324 ASSERT(programObject);
6325 programObject->setUniform3fv(location, count, value);
6326}
6327
6328void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6329{
6330 Program *programObject = getProgram(program);
6331 ASSERT(programObject);
6332 programObject->setUniform4fv(location, count, value);
6333}
6334
6335void Context::programUniformMatrix2fv(GLuint program,
6336 GLint location,
6337 GLsizei count,
6338 GLboolean transpose,
6339 const GLfloat *value)
6340{
6341 Program *programObject = getProgram(program);
6342 ASSERT(programObject);
6343 programObject->setUniformMatrix2fv(location, count, transpose, value);
6344}
6345
6346void Context::programUniformMatrix3fv(GLuint program,
6347 GLint location,
6348 GLsizei count,
6349 GLboolean transpose,
6350 const GLfloat *value)
6351{
6352 Program *programObject = getProgram(program);
6353 ASSERT(programObject);
6354 programObject->setUniformMatrix3fv(location, count, transpose, value);
6355}
6356
6357void Context::programUniformMatrix4fv(GLuint program,
6358 GLint location,
6359 GLsizei count,
6360 GLboolean transpose,
6361 const GLfloat *value)
6362{
6363 Program *programObject = getProgram(program);
6364 ASSERT(programObject);
6365 programObject->setUniformMatrix4fv(location, count, transpose, value);
6366}
6367
6368void Context::programUniformMatrix2x3fv(GLuint program,
6369 GLint location,
6370 GLsizei count,
6371 GLboolean transpose,
6372 const GLfloat *value)
6373{
6374 Program *programObject = getProgram(program);
6375 ASSERT(programObject);
6376 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6377}
6378
6379void Context::programUniformMatrix3x2fv(GLuint program,
6380 GLint location,
6381 GLsizei count,
6382 GLboolean transpose,
6383 const GLfloat *value)
6384{
6385 Program *programObject = getProgram(program);
6386 ASSERT(programObject);
6387 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6388}
6389
6390void Context::programUniformMatrix2x4fv(GLuint program,
6391 GLint location,
6392 GLsizei count,
6393 GLboolean transpose,
6394 const GLfloat *value)
6395{
6396 Program *programObject = getProgram(program);
6397 ASSERT(programObject);
6398 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6399}
6400
6401void Context::programUniformMatrix4x2fv(GLuint program,
6402 GLint location,
6403 GLsizei count,
6404 GLboolean transpose,
6405 const GLfloat *value)
6406{
6407 Program *programObject = getProgram(program);
6408 ASSERT(programObject);
6409 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6410}
6411
6412void Context::programUniformMatrix3x4fv(GLuint program,
6413 GLint location,
6414 GLsizei count,
6415 GLboolean transpose,
6416 const GLfloat *value)
6417{
6418 Program *programObject = getProgram(program);
6419 ASSERT(programObject);
6420 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6421}
6422
6423void Context::programUniformMatrix4x3fv(GLuint program,
6424 GLint location,
6425 GLsizei count,
6426 GLboolean transpose,
6427 const GLfloat *value)
6428{
6429 Program *programObject = getProgram(program);
6430 ASSERT(programObject);
6431 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6432}
6433
Jamie Madill81c2e252017-09-09 23:32:46 -04006434void Context::onTextureChange(const Texture *texture)
6435{
6436 // Conservatively assume all textures are dirty.
6437 // TODO(jmadill): More fine-grained update.
6438 mGLState.setObjectDirty(GL_TEXTURE);
6439}
6440
James Darpiniane8a93c62018-01-04 18:02:24 -08006441bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6442{
6443 return mGLState.isCurrentTransformFeedback(tf);
6444}
6445bool Context::isCurrentVertexArray(const VertexArray *va) const
6446{
6447 return mGLState.isCurrentVertexArray(va);
6448}
6449
Yunchao Hea336b902017-08-02 16:05:21 +08006450void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6451{
6452 for (int i = 0; i < count; i++)
6453 {
6454 pipelines[i] = createProgramPipeline();
6455 }
6456}
6457
6458void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6459{
6460 for (int i = 0; i < count; i++)
6461 {
6462 if (pipelines[i] != 0)
6463 {
6464 deleteProgramPipeline(pipelines[i]);
6465 }
6466 }
6467}
6468
6469GLboolean Context::isProgramPipeline(GLuint pipeline)
6470{
6471 if (pipeline == 0)
6472 {
6473 return GL_FALSE;
6474 }
6475
6476 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6477}
6478
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006479void Context::finishFenceNV(GLuint fence)
6480{
6481 FenceNV *fenceObject = getFenceNV(fence);
6482
6483 ASSERT(fenceObject && fenceObject->isSet());
6484 handleError(fenceObject->finish());
6485}
6486
6487void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6488{
6489 FenceNV *fenceObject = getFenceNV(fence);
6490
6491 ASSERT(fenceObject && fenceObject->isSet());
6492
6493 switch (pname)
6494 {
6495 case GL_FENCE_STATUS_NV:
6496 {
6497 // GL_NV_fence spec:
6498 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6499 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6500 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6501 GLboolean status = GL_TRUE;
6502 if (fenceObject->getStatus() != GL_TRUE)
6503 {
6504 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6505 }
6506 *params = status;
6507 break;
6508 }
6509
6510 case GL_FENCE_CONDITION_NV:
6511 {
6512 *params = static_cast<GLint>(fenceObject->getCondition());
6513 break;
6514 }
6515
6516 default:
6517 UNREACHABLE();
6518 }
6519}
6520
6521void Context::getTranslatedShaderSource(GLuint shader,
6522 GLsizei bufsize,
6523 GLsizei *length,
6524 GLchar *source)
6525{
6526 Shader *shaderObject = getShader(shader);
6527 ASSERT(shaderObject);
6528 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6529}
6530
6531void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6532{
6533 Program *programObject = getProgram(program);
6534 ASSERT(programObject);
6535
6536 programObject->getUniformfv(this, location, params);
6537}
6538
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006539void Context::getnUniformfvRobust(GLuint program,
6540 GLint location,
6541 GLsizei bufSize,
6542 GLsizei *length,
6543 GLfloat *params)
6544{
6545 UNIMPLEMENTED();
6546}
6547
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006548void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6549{
6550 Program *programObject = getProgram(program);
6551 ASSERT(programObject);
6552
6553 programObject->getUniformiv(this, location, params);
6554}
6555
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006556void Context::getnUniformivRobust(GLuint program,
6557 GLint location,
6558 GLsizei bufSize,
6559 GLsizei *length,
6560 GLint *params)
6561{
6562 UNIMPLEMENTED();
6563}
6564
6565void Context::getnUniformuivRobust(GLuint program,
6566 GLint location,
6567 GLsizei bufSize,
6568 GLsizei *length,
6569 GLuint *params)
6570{
6571 UNIMPLEMENTED();
6572}
6573
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006574GLboolean Context::isFenceNV(GLuint fence)
6575{
6576 FenceNV *fenceObject = getFenceNV(fence);
6577
6578 if (fenceObject == nullptr)
6579 {
6580 return GL_FALSE;
6581 }
6582
6583 // GL_NV_fence spec:
6584 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6585 // existing fence.
6586 return fenceObject->isSet();
6587}
6588
6589void Context::readnPixels(GLint x,
6590 GLint y,
6591 GLsizei width,
6592 GLsizei height,
6593 GLenum format,
6594 GLenum type,
6595 GLsizei bufSize,
6596 void *data)
6597{
6598 return readPixels(x, y, width, height, format, type, data);
6599}
6600
Jamie Madill007530e2017-12-28 14:27:04 -05006601void Context::setFenceNV(GLuint fence, GLenum condition)
6602{
6603 ASSERT(condition == GL_ALL_COMPLETED_NV);
6604
6605 FenceNV *fenceObject = getFenceNV(fence);
6606 ASSERT(fenceObject != nullptr);
6607 handleError(fenceObject->set(condition));
6608}
6609
6610GLboolean Context::testFenceNV(GLuint fence)
6611{
6612 FenceNV *fenceObject = getFenceNV(fence);
6613
6614 ASSERT(fenceObject != nullptr);
6615 ASSERT(fenceObject->isSet() == GL_TRUE);
6616
6617 GLboolean result = GL_TRUE;
6618 Error error = fenceObject->test(&result);
6619 if (error.isError())
6620 {
6621 handleError(error);
6622 return GL_TRUE;
6623 }
6624
6625 return result;
6626}
6627
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006628void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006629{
6630 Texture *texture = getTargetTexture(target);
6631 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006632 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006633}
6634
Jamie Madillfa920eb2018-01-04 11:45:50 -05006635void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006636{
6637 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6638 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6639 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6640}
6641
Jamie Madillfa920eb2018-01-04 11:45:50 -05006642void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6643{
6644 UNIMPLEMENTED();
6645}
6646
Jamie Madill5b772312018-03-08 20:28:32 -05006647bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6648{
6649 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6650 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6651 // to the fact that it is stored internally as a float, and so would require conversion
6652 // if returned from Context::getIntegerv. Since this conversion is already implemented
6653 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6654 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6655 // application.
6656 switch (pname)
6657 {
6658 case GL_COMPRESSED_TEXTURE_FORMATS:
6659 {
6660 *type = GL_INT;
6661 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6662 return true;
6663 }
6664 case GL_SHADER_BINARY_FORMATS:
6665 {
6666 *type = GL_INT;
6667 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6668 return true;
6669 }
6670
6671 case GL_MAX_VERTEX_ATTRIBS:
6672 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6673 case GL_MAX_VARYING_VECTORS:
6674 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6675 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6676 case GL_MAX_TEXTURE_IMAGE_UNITS:
6677 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6678 case GL_MAX_RENDERBUFFER_SIZE:
6679 case GL_NUM_SHADER_BINARY_FORMATS:
6680 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6681 case GL_ARRAY_BUFFER_BINDING:
6682 case GL_FRAMEBUFFER_BINDING:
6683 case GL_RENDERBUFFER_BINDING:
6684 case GL_CURRENT_PROGRAM:
6685 case GL_PACK_ALIGNMENT:
6686 case GL_UNPACK_ALIGNMENT:
6687 case GL_GENERATE_MIPMAP_HINT:
6688 case GL_RED_BITS:
6689 case GL_GREEN_BITS:
6690 case GL_BLUE_BITS:
6691 case GL_ALPHA_BITS:
6692 case GL_DEPTH_BITS:
6693 case GL_STENCIL_BITS:
6694 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6695 case GL_CULL_FACE_MODE:
6696 case GL_FRONT_FACE:
6697 case GL_ACTIVE_TEXTURE:
6698 case GL_STENCIL_FUNC:
6699 case GL_STENCIL_VALUE_MASK:
6700 case GL_STENCIL_REF:
6701 case GL_STENCIL_FAIL:
6702 case GL_STENCIL_PASS_DEPTH_FAIL:
6703 case GL_STENCIL_PASS_DEPTH_PASS:
6704 case GL_STENCIL_BACK_FUNC:
6705 case GL_STENCIL_BACK_VALUE_MASK:
6706 case GL_STENCIL_BACK_REF:
6707 case GL_STENCIL_BACK_FAIL:
6708 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6709 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6710 case GL_DEPTH_FUNC:
6711 case GL_BLEND_SRC_RGB:
6712 case GL_BLEND_SRC_ALPHA:
6713 case GL_BLEND_DST_RGB:
6714 case GL_BLEND_DST_ALPHA:
6715 case GL_BLEND_EQUATION_RGB:
6716 case GL_BLEND_EQUATION_ALPHA:
6717 case GL_STENCIL_WRITEMASK:
6718 case GL_STENCIL_BACK_WRITEMASK:
6719 case GL_STENCIL_CLEAR_VALUE:
6720 case GL_SUBPIXEL_BITS:
6721 case GL_MAX_TEXTURE_SIZE:
6722 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6723 case GL_SAMPLE_BUFFERS:
6724 case GL_SAMPLES:
6725 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6726 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6727 case GL_TEXTURE_BINDING_2D:
6728 case GL_TEXTURE_BINDING_CUBE_MAP:
6729 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6730 {
6731 *type = GL_INT;
6732 *numParams = 1;
6733 return true;
6734 }
6735 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6736 {
6737 if (!getExtensions().packReverseRowOrder)
6738 {
6739 return false;
6740 }
6741 *type = GL_INT;
6742 *numParams = 1;
6743 return true;
6744 }
6745 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6746 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6747 {
6748 if (!getExtensions().textureRectangle)
6749 {
6750 return false;
6751 }
6752 *type = GL_INT;
6753 *numParams = 1;
6754 return true;
6755 }
6756 case GL_MAX_DRAW_BUFFERS_EXT:
6757 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6758 {
6759 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6760 {
6761 return false;
6762 }
6763 *type = GL_INT;
6764 *numParams = 1;
6765 return true;
6766 }
6767 case GL_MAX_VIEWPORT_DIMS:
6768 {
6769 *type = GL_INT;
6770 *numParams = 2;
6771 return true;
6772 }
6773 case GL_VIEWPORT:
6774 case GL_SCISSOR_BOX:
6775 {
6776 *type = GL_INT;
6777 *numParams = 4;
6778 return true;
6779 }
6780 case GL_SHADER_COMPILER:
6781 case GL_SAMPLE_COVERAGE_INVERT:
6782 case GL_DEPTH_WRITEMASK:
6783 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6784 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6785 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6786 // bool-natural
6787 case GL_SAMPLE_COVERAGE:
6788 case GL_SCISSOR_TEST:
6789 case GL_STENCIL_TEST:
6790 case GL_DEPTH_TEST:
6791 case GL_BLEND:
6792 case GL_DITHER:
6793 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6794 {
6795 *type = GL_BOOL;
6796 *numParams = 1;
6797 return true;
6798 }
6799 case GL_COLOR_WRITEMASK:
6800 {
6801 *type = GL_BOOL;
6802 *numParams = 4;
6803 return true;
6804 }
6805 case GL_POLYGON_OFFSET_FACTOR:
6806 case GL_POLYGON_OFFSET_UNITS:
6807 case GL_SAMPLE_COVERAGE_VALUE:
6808 case GL_DEPTH_CLEAR_VALUE:
6809 case GL_LINE_WIDTH:
6810 {
6811 *type = GL_FLOAT;
6812 *numParams = 1;
6813 return true;
6814 }
6815 case GL_ALIASED_LINE_WIDTH_RANGE:
6816 case GL_ALIASED_POINT_SIZE_RANGE:
6817 case GL_DEPTH_RANGE:
6818 {
6819 *type = GL_FLOAT;
6820 *numParams = 2;
6821 return true;
6822 }
6823 case GL_COLOR_CLEAR_VALUE:
6824 case GL_BLEND_COLOR:
6825 {
6826 *type = GL_FLOAT;
6827 *numParams = 4;
6828 return true;
6829 }
6830 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6831 if (!getExtensions().textureFilterAnisotropic)
6832 {
6833 return false;
6834 }
6835 *type = GL_FLOAT;
6836 *numParams = 1;
6837 return true;
6838 case GL_TIMESTAMP_EXT:
6839 if (!getExtensions().disjointTimerQuery)
6840 {
6841 return false;
6842 }
6843 *type = GL_INT_64_ANGLEX;
6844 *numParams = 1;
6845 return true;
6846 case GL_GPU_DISJOINT_EXT:
6847 if (!getExtensions().disjointTimerQuery)
6848 {
6849 return false;
6850 }
6851 *type = GL_INT;
6852 *numParams = 1;
6853 return true;
6854 case GL_COVERAGE_MODULATION_CHROMIUM:
6855 if (!getExtensions().framebufferMixedSamples)
6856 {
6857 return false;
6858 }
6859 *type = GL_INT;
6860 *numParams = 1;
6861 return true;
6862 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6863 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6864 {
6865 return false;
6866 }
6867 *type = GL_INT;
6868 *numParams = 1;
6869 return true;
6870 }
6871
6872 if (getExtensions().debug)
6873 {
6874 switch (pname)
6875 {
6876 case GL_DEBUG_LOGGED_MESSAGES:
6877 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6878 case GL_DEBUG_GROUP_STACK_DEPTH:
6879 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6880 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6881 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6882 case GL_MAX_LABEL_LENGTH:
6883 *type = GL_INT;
6884 *numParams = 1;
6885 return true;
6886
6887 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6888 case GL_DEBUG_OUTPUT:
6889 *type = GL_BOOL;
6890 *numParams = 1;
6891 return true;
6892 }
6893 }
6894
6895 if (getExtensions().multisampleCompatibility)
6896 {
6897 switch (pname)
6898 {
6899 case GL_MULTISAMPLE_EXT:
6900 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6901 *type = GL_BOOL;
6902 *numParams = 1;
6903 return true;
6904 }
6905 }
6906
6907 if (getExtensions().pathRendering)
6908 {
6909 switch (pname)
6910 {
6911 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6912 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6913 *type = GL_FLOAT;
6914 *numParams = 16;
6915 return true;
6916 }
6917 }
6918
6919 if (getExtensions().bindGeneratesResource)
6920 {
6921 switch (pname)
6922 {
6923 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6924 *type = GL_BOOL;
6925 *numParams = 1;
6926 return true;
6927 }
6928 }
6929
6930 if (getExtensions().clientArrays)
6931 {
6932 switch (pname)
6933 {
6934 case GL_CLIENT_ARRAYS_ANGLE:
6935 *type = GL_BOOL;
6936 *numParams = 1;
6937 return true;
6938 }
6939 }
6940
6941 if (getExtensions().sRGBWriteControl)
6942 {
6943 switch (pname)
6944 {
6945 case GL_FRAMEBUFFER_SRGB_EXT:
6946 *type = GL_BOOL;
6947 *numParams = 1;
6948 return true;
6949 }
6950 }
6951
6952 if (getExtensions().robustResourceInitialization &&
6953 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6954 {
6955 *type = GL_BOOL;
6956 *numParams = 1;
6957 return true;
6958 }
6959
6960 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6961 {
6962 *type = GL_BOOL;
6963 *numParams = 1;
6964 return true;
6965 }
6966
6967 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6968 switch (pname)
6969 {
6970 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6971 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6972 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6973 {
6974 return false;
6975 }
6976 *type = GL_INT;
6977 *numParams = 1;
6978 return true;
6979
6980 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6981 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6982 {
6983 return false;
6984 }
6985 *type = GL_INT;
6986 *numParams = 1;
6987 return true;
6988
6989 case GL_PROGRAM_BINARY_FORMATS_OES:
6990 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6996 return true;
6997
6998 case GL_PACK_ROW_LENGTH:
6999 case GL_PACK_SKIP_ROWS:
7000 case GL_PACK_SKIP_PIXELS:
7001 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008 case GL_UNPACK_ROW_LENGTH:
7009 case GL_UNPACK_SKIP_ROWS:
7010 case GL_UNPACK_SKIP_PIXELS:
7011 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7012 {
7013 return false;
7014 }
7015 *type = GL_INT;
7016 *numParams = 1;
7017 return true;
7018 case GL_VERTEX_ARRAY_BINDING:
7019 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7020 {
7021 return false;
7022 }
7023 *type = GL_INT;
7024 *numParams = 1;
7025 return true;
7026 case GL_PIXEL_PACK_BUFFER_BINDING:
7027 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7028 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7029 {
7030 return false;
7031 }
7032 *type = GL_INT;
7033 *numParams = 1;
7034 return true;
7035 case GL_MAX_SAMPLES:
7036 {
7037 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7038 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7039 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7040 {
7041 return false;
7042 }
7043 *type = GL_INT;
7044 *numParams = 1;
7045 return true;
7046
7047 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7048 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7049 {
7050 return false;
7051 }
7052 *type = GL_INT;
7053 *numParams = 1;
7054 return true;
7055 }
7056 }
7057
7058 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7059 {
7060 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7061 {
7062 return false;
7063 }
7064 *type = GL_INT;
7065 *numParams = 1;
7066 return true;
7067 }
7068
7069 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7070 {
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074 }
7075
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007076 if (getClientVersion() < Version(2, 0))
7077 {
7078 switch (pname)
7079 {
7080 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007081 case GL_CLIENT_ACTIVE_TEXTURE:
7082 case GL_MATRIX_MODE:
7083 case GL_MAX_TEXTURE_UNITS:
7084 case GL_MAX_MODELVIEW_STACK_DEPTH:
7085 case GL_MAX_PROJECTION_STACK_DEPTH:
7086 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007087 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007088 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007089 case GL_VERTEX_ARRAY_STRIDE:
7090 case GL_NORMAL_ARRAY_STRIDE:
7091 case GL_COLOR_ARRAY_STRIDE:
7092 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7093 case GL_VERTEX_ARRAY_SIZE:
7094 case GL_COLOR_ARRAY_SIZE:
7095 case GL_TEXTURE_COORD_ARRAY_SIZE:
7096 case GL_VERTEX_ARRAY_TYPE:
7097 case GL_NORMAL_ARRAY_TYPE:
7098 case GL_COLOR_ARRAY_TYPE:
7099 case GL_TEXTURE_COORD_ARRAY_TYPE:
7100 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7101 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7102 case GL_COLOR_ARRAY_BUFFER_BINDING:
7103 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7104 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7105 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7106 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007107 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007108 *type = GL_INT;
7109 *numParams = 1;
7110 return true;
7111 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007112 case GL_FOG_DENSITY:
7113 case GL_FOG_START:
7114 case GL_FOG_END:
7115 case GL_FOG_MODE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007116 *type = GL_FLOAT;
7117 *numParams = 1;
7118 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007119 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007120 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007121 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007122 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007123 *type = GL_FLOAT;
7124 *numParams = 4;
7125 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007126 case GL_CURRENT_NORMAL:
7127 *type = GL_FLOAT;
7128 *numParams = 3;
7129 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007130 case GL_MODELVIEW_MATRIX:
7131 case GL_PROJECTION_MATRIX:
7132 case GL_TEXTURE_MATRIX:
7133 *type = GL_FLOAT;
7134 *numParams = 16;
7135 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007136 case GL_LIGHT_MODEL_TWO_SIDE:
7137 *type = GL_BOOL;
7138 *numParams = 1;
7139 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007140 }
7141 }
7142
Jamie Madill5b772312018-03-08 20:28:32 -05007143 if (getClientVersion() < Version(3, 0))
7144 {
7145 return false;
7146 }
7147
7148 // Check for ES3.0+ parameter names
7149 switch (pname)
7150 {
7151 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7152 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7153 case GL_UNIFORM_BUFFER_BINDING:
7154 case GL_TRANSFORM_FEEDBACK_BINDING:
7155 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7156 case GL_COPY_READ_BUFFER_BINDING:
7157 case GL_COPY_WRITE_BUFFER_BINDING:
7158 case GL_SAMPLER_BINDING:
7159 case GL_READ_BUFFER:
7160 case GL_TEXTURE_BINDING_3D:
7161 case GL_TEXTURE_BINDING_2D_ARRAY:
7162 case GL_MAX_3D_TEXTURE_SIZE:
7163 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7164 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7165 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7166 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7167 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7168 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7169 case GL_MAX_VARYING_COMPONENTS:
7170 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7171 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7172 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7173 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7174 case GL_NUM_EXTENSIONS:
7175 case GL_MAJOR_VERSION:
7176 case GL_MINOR_VERSION:
7177 case GL_MAX_ELEMENTS_INDICES:
7178 case GL_MAX_ELEMENTS_VERTICES:
7179 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7180 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7181 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7182 case GL_UNPACK_IMAGE_HEIGHT:
7183 case GL_UNPACK_SKIP_IMAGES:
7184 {
7185 *type = GL_INT;
7186 *numParams = 1;
7187 return true;
7188 }
7189
7190 case GL_MAX_ELEMENT_INDEX:
7191 case GL_MAX_UNIFORM_BLOCK_SIZE:
7192 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7193 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7194 case GL_MAX_SERVER_WAIT_TIMEOUT:
7195 {
7196 *type = GL_INT_64_ANGLEX;
7197 *numParams = 1;
7198 return true;
7199 }
7200
7201 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7202 case GL_TRANSFORM_FEEDBACK_PAUSED:
7203 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7204 case GL_RASTERIZER_DISCARD:
7205 {
7206 *type = GL_BOOL;
7207 *numParams = 1;
7208 return true;
7209 }
7210
7211 case GL_MAX_TEXTURE_LOD_BIAS:
7212 {
7213 *type = GL_FLOAT;
7214 *numParams = 1;
7215 return true;
7216 }
7217 }
7218
7219 if (getExtensions().requestExtension)
7220 {
7221 switch (pname)
7222 {
7223 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7224 *type = GL_INT;
7225 *numParams = 1;
7226 return true;
7227 }
7228 }
7229
7230 if (getClientVersion() < Version(3, 1))
7231 {
7232 return false;
7233 }
7234
7235 switch (pname)
7236 {
7237 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7238 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7239 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7240 case GL_MAX_FRAMEBUFFER_WIDTH:
7241 case GL_MAX_FRAMEBUFFER_HEIGHT:
7242 case GL_MAX_FRAMEBUFFER_SAMPLES:
7243 case GL_MAX_SAMPLE_MASK_WORDS:
7244 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7245 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7246 case GL_MAX_INTEGER_SAMPLES:
7247 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7248 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7249 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7250 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7251 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7252 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7253 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7254 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7255 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7256 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7257 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7258 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7259 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7260 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7261 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7262 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7263 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7264 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7265 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7266 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7267 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7268 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7269 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7270 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7271 case GL_MAX_UNIFORM_LOCATIONS:
7272 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7273 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7274 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7275 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7276 case GL_MAX_IMAGE_UNITS:
7277 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7278 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7279 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7280 case GL_SHADER_STORAGE_BUFFER_BINDING:
7281 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7282 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7283 *type = GL_INT;
7284 *numParams = 1;
7285 return true;
7286 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7287 *type = GL_INT_64_ANGLEX;
7288 *numParams = 1;
7289 return true;
7290 case GL_SAMPLE_MASK:
7291 *type = GL_BOOL;
7292 *numParams = 1;
7293 return true;
7294 }
7295
7296 if (getExtensions().geometryShader)
7297 {
7298 switch (pname)
7299 {
7300 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7301 case GL_LAYER_PROVOKING_VERTEX_EXT:
7302 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7303 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7304 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7305 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7306 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7307 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7308 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7309 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7310 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7311 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7312 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7313 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7314 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7315 *type = GL_INT;
7316 *numParams = 1;
7317 return true;
7318 }
7319 }
7320
7321 return false;
7322}
7323
7324bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7325{
7326 if (getClientVersion() < Version(3, 0))
7327 {
7328 return false;
7329 }
7330
7331 switch (target)
7332 {
7333 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7334 case GL_UNIFORM_BUFFER_BINDING:
7335 {
7336 *type = GL_INT;
7337 *numParams = 1;
7338 return true;
7339 }
7340 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7341 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7342 case GL_UNIFORM_BUFFER_START:
7343 case GL_UNIFORM_BUFFER_SIZE:
7344 {
7345 *type = GL_INT_64_ANGLEX;
7346 *numParams = 1;
7347 return true;
7348 }
7349 }
7350
7351 if (getClientVersion() < Version(3, 1))
7352 {
7353 return false;
7354 }
7355
7356 switch (target)
7357 {
7358 case GL_IMAGE_BINDING_LAYERED:
7359 {
7360 *type = GL_BOOL;
7361 *numParams = 1;
7362 return true;
7363 }
7364 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7365 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7366 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7367 case GL_SHADER_STORAGE_BUFFER_BINDING:
7368 case GL_VERTEX_BINDING_BUFFER:
7369 case GL_VERTEX_BINDING_DIVISOR:
7370 case GL_VERTEX_BINDING_OFFSET:
7371 case GL_VERTEX_BINDING_STRIDE:
7372 case GL_SAMPLE_MASK_VALUE:
7373 case GL_IMAGE_BINDING_NAME:
7374 case GL_IMAGE_BINDING_LEVEL:
7375 case GL_IMAGE_BINDING_LAYER:
7376 case GL_IMAGE_BINDING_ACCESS:
7377 case GL_IMAGE_BINDING_FORMAT:
7378 {
7379 *type = GL_INT;
7380 *numParams = 1;
7381 return true;
7382 }
7383 case GL_ATOMIC_COUNTER_BUFFER_START:
7384 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7385 case GL_SHADER_STORAGE_BUFFER_START:
7386 case GL_SHADER_STORAGE_BUFFER_SIZE:
7387 {
7388 *type = GL_INT_64_ANGLEX;
7389 *numParams = 1;
7390 return true;
7391 }
7392 }
7393
7394 return false;
7395}
7396
7397Program *Context::getProgram(GLuint handle) const
7398{
7399 return mState.mShaderPrograms->getProgram(handle);
7400}
7401
7402Shader *Context::getShader(GLuint handle) const
7403{
7404 return mState.mShaderPrograms->getShader(handle);
7405}
7406
7407bool Context::isTextureGenerated(GLuint texture) const
7408{
7409 return mState.mTextures->isHandleGenerated(texture);
7410}
7411
7412bool Context::isBufferGenerated(GLuint buffer) const
7413{
7414 return mState.mBuffers->isHandleGenerated(buffer);
7415}
7416
7417bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7418{
7419 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7420}
7421
7422bool Context::isFramebufferGenerated(GLuint framebuffer) const
7423{
7424 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7425}
7426
7427bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7428{
7429 return mState.mPipelines->isHandleGenerated(pipeline);
7430}
7431
7432bool Context::usingDisplayTextureShareGroup() const
7433{
7434 return mDisplayTextureShareGroup;
7435}
7436
7437GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7438{
7439 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7440 internalformat == GL_DEPTH_STENCIL
7441 ? GL_DEPTH24_STENCIL8
7442 : internalformat;
7443}
7444
Jamie Madillc29968b2016-01-20 11:17:23 -05007445} // namespace gl