blob: c3bc863b5ddb32aef52045be4e08d967fc983044 [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),
Geoff Lang3cacf692018-06-20 16:49:57 -0400282 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400283 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400284 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400285 mGLState(GetDebug(attribs),
286 GetBindGeneratesResource(attribs),
287 GetClientArraysEnabled(attribs),
288 GetRobustResourceInit(attribs),
289 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400290 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500291 mClientType(EGL_OPENGL_ES_API),
292 mHasBeenCurrent(false),
293 mContextLost(false),
294 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700295 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500296 mResetStrategy(GetResetStrategy(attribs)),
297 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400298 mSurfacelessSupported(displayExtensions.surfacelessContext),
299 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400300 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
301 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500302 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400303 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400304 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400305 mScratchBuffer(1000u),
306 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307{
Jamie Madill5b772312018-03-08 20:28:32 -0500308 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400309 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
310 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400311}
Jamie Madill5b772312018-03-08 20:28:32 -0500312
Geoff Lang33f11fb2018-05-07 13:42:47 -0400313void Context::initialize()
314{
315 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400316
Geoff Lang33f11fb2018-05-07 13:42:47 -0400317 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700318 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400319
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400320 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100321
Shannon Woods53a94a82014-06-24 15:20:36 -0400322 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400323
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000324 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400325 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000326 // and cube map texture state vectors respectively associated with them.
327 // In order that access to these initial textures not be lost, they are treated as texture
328 // objects all of whose names are 0.
329
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335
Geoff Langeb66a6e2016-10-31 13:06:12 -0400336 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 {
338 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400341
Corentin Wallez99d492c2018-02-27 15:17:10 -0500342 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 if (getClientVersion() >= Version(3, 1))
346 {
347 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500348 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800349 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800350
Jiajia Qin6eafb042016-12-27 17:04:07 +0800351 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
352 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800353 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800354 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800355
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800356 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
357 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400358 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800359 }
Geoff Lang3b573612016-10-31 14:08:10 -0400360 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400363 {
364 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500365 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800366 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400367 }
368
Geoff Langb0f917f2017-12-05 13:41:54 -0500369 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400370 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500371 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400373 }
374
Jamie Madill4928b7c2017-06-20 12:57:39 -0400375 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500376
Jamie Madill57a89722013-07-02 11:57:03 -0400377 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000378
Geoff Langeb66a6e2016-10-31 13:06:12 -0400379 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400380 {
381 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
382 // In the initial state, a default transform feedback object is bound and treated as
383 // a transform feedback object with a name of zero. That object is bound any time
384 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400385 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400386 }
Geoff Langc8058452014-02-03 12:04:11 -0500387
Corentin Wallez336129f2017-10-17 15:55:40 -0400388 for (auto type : angle::AllEnums<BufferBinding>())
389 {
390 bindBuffer(type, 0);
391 }
392
393 bindRenderbuffer(GL_RENDERBUFFER, 0);
394
395 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
396 {
397 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
398 }
399
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700400 // Initialize GLES1 renderer if appropriate.
401 if (getClientVersion() < Version(2, 0))
402 {
403 mGLES1Renderer.reset(new GLES1Renderer());
404 }
405
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400407 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500408 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 // No dirty objects.
410
411 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400412 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500413 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400414 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500415 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
416
417 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
418 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
419 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
420 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
422 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
423 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
424 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
425 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
426 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
427 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400428 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500429 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
430
431 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
432 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700433 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400434 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
435 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500436 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
437 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400438
Xinghua Cao10a4d432017-11-28 14:46:26 +0800439 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
440 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
441 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
442 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
443 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
444 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800445 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800446 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800447
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400448 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000449}
450
Jamie Madill4928b7c2017-06-20 12:57:39 -0400451egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700453 if (mGLES1Renderer)
454 {
455 mGLES1Renderer->onDestroy(this, &mGLState);
456 }
457
Jamie Madille7b3fe22018-04-05 09:42:46 -0400458 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400459 ANGLE_TRY(releaseSurface(display));
460
Corentin Wallez80b24112015-08-25 16:41:57 -0400461 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400465 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallez80b24112015-08-25 16:41:57 -0400467 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400469 if (query.second != nullptr)
470 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400471 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400472 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400474 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000475
Corentin Wallez80b24112015-08-25 16:41:57 -0400476 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400477 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478 if (vertexArray.second)
479 {
480 vertexArray.second->onDestroy(this);
481 }
Jamie Madill57a89722013-07-02 11:57:03 -0400482 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400483 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400484
Corentin Wallez80b24112015-08-25 16:41:57 -0400485 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500486 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500487 if (transformFeedback.second != nullptr)
488 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500489 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500490 }
Geoff Langc8058452014-02-03 12:04:11 -0500491 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400492 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500493
Jamie Madill5b772312018-03-08 20:28:32 -0500494 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400495 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800496 if (zeroTexture.get() != nullptr)
497 {
498 ANGLE_TRY(zeroTexture->onDestroy(this));
499 zeroTexture.set(this, nullptr);
500 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400501 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502
Jamie Madill2f348d22017-06-05 10:50:59 -0400503 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500504
Jamie Madill4928b7c2017-06-20 12:57:39 -0400505 mGLState.reset(this);
506
Jamie Madill6c1f6712017-02-14 19:08:04 -0500507 mState.mBuffers->release(this);
508 mState.mShaderPrograms->release(this);
509 mState.mTextures->release(this);
510 mState.mRenderbuffers->release(this);
511 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400512 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500513 mState.mPaths->release(this);
514 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800515 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400516
Jamie Madill76e471e2017-10-21 09:56:01 -0400517 mImplementation->onDestroy(this);
518
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520}
521
Jamie Madill70ee0f62017-02-06 16:04:20 -0500522Context::~Context()
523{
524}
525
Geoff Lang75359662018-04-11 01:42:27 -0400526void Context::setLabel(EGLLabelKHR label)
527{
528 mLabel = label;
529}
530
531EGLLabelKHR Context::getLabel() const
532{
533 return mLabel;
534}
535
Jamie Madill4928b7c2017-06-20 12:57:39 -0400536egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537{
Jamie Madill61e16b42017-06-19 11:13:23 -0400538 mCurrentDisplay = display;
539
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000540 if (!mHasBeenCurrent)
541 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400542 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500544 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400545 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546
Corentin Wallezc295e512017-01-27 17:47:50 -0500547 int width = 0;
548 int height = 0;
549 if (surface != nullptr)
550 {
551 width = surface->getWidth();
552 height = surface->getHeight();
553 }
554
555 mGLState.setViewportParams(0, 0, width, height);
556 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557
558 mHasBeenCurrent = true;
559 }
560
Jamie Madill1b94d432015-08-07 13:23:23 -0400561 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700562 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400563 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400564
Jamie Madill4928b7c2017-06-20 12:57:39 -0400565 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500566
567 Framebuffer *newDefault = nullptr;
568 if (surface != nullptr)
569 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500571 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400572 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500573 }
574 else
575 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400576 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500577 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000578
Corentin Wallez37c39792015-08-20 14:19:46 -0400579 // Update default framebuffer, the binding of the previous default
580 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400581 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700582 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400583 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700584 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400585 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700586 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400587 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700588 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400589 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500590 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400591 }
Ian Ewell292f0052016-02-04 10:37:32 -0500592
593 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594 mImplementation->onMakeCurrent(this);
595 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596}
597
Jamie Madill4928b7c2017-06-20 12:57:39 -0400598egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400599{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400600 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400601
Geoff Langbf7b95d2018-05-01 16:48:21 -0400602 // Remove the default framebuffer
603 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500604 {
605 mGLState.setReadFramebufferBinding(nullptr);
606 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400607
608 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500609 {
610 mGLState.setDrawFramebufferBinding(nullptr);
611 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400612
613 if (defaultFramebuffer)
614 {
615 defaultFramebuffer->onDestroy(this);
616 delete defaultFramebuffer;
617 }
618
Corentin Wallezc295e512017-01-27 17:47:50 -0500619 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
620
621 if (mCurrentSurface)
622 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400623 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500624 mCurrentSurface = nullptr;
625 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400626
627 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400628}
629
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630GLuint Context::createBuffer()
631{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500632 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
635GLuint Context::createProgram()
636{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500637 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jiawei Shao385b3e02018-03-21 09:43:28 +0800640GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500642 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
645GLuint Context::createTexture()
646{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500647 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000648}
649
650GLuint Context::createRenderbuffer()
651{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500652 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
Brandon Jones59770802018-04-02 13:18:42 -0700655GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300656{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500657 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300658 if (resultOrError.isError())
659 {
660 handleError(resultOrError.getError());
661 return 0;
662 }
663 return resultOrError.getResult();
664}
665
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666// Returns an unused framebuffer name
667GLuint Context::createFramebuffer()
668{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500669 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670}
671
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500672void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500674 for (int i = 0; i < n; i++)
675 {
676 GLuint handle = mFenceNVHandleAllocator.allocate();
677 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
678 fences[i] = handle;
679 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
Yunchao Hea336b902017-08-02 16:05:21 +0800682GLuint Context::createProgramPipeline()
683{
684 return mState.mPipelines->createProgramPipeline();
685}
686
Jiawei Shao385b3e02018-03-21 09:43:28 +0800687GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800688{
689 UNIMPLEMENTED();
690 return 0u;
691}
692
James Darpinian4d9d4832018-03-13 12:43:28 -0700693void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694{
James Darpinian4d9d4832018-03-13 12:43:28 -0700695 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
696 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697 {
698 detachBuffer(buffer);
699 }
Jamie Madill893ab082014-05-16 16:56:10 -0400700
James Darpinian4d9d4832018-03-13 12:43:28 -0700701 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000702}
703
704void Context::deleteShader(GLuint shader)
705{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500706 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
709void Context::deleteProgram(GLuint program)
710{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500711 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
714void Context::deleteTexture(GLuint texture)
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717 {
718 detachTexture(texture);
719 }
720
Jamie Madill6c1f6712017-02-14 19:08:04 -0500721 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722}
723
724void Context::deleteRenderbuffer(GLuint renderbuffer)
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000727 {
728 detachRenderbuffer(renderbuffer);
729 }
Jamie Madill893ab082014-05-16 16:56:10 -0400730
Jamie Madill6c1f6712017-02-14 19:08:04 -0500731 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000732}
733
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400734void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400735{
736 // The spec specifies the underlying Fence object is not deleted until all current
737 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
738 // and since our API is currently designed for being called from a single thread, we can delete
739 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400740 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400741}
742
Yunchao Hea336b902017-08-02 16:05:21 +0800743void Context::deleteProgramPipeline(GLuint pipeline)
744{
745 if (mState.mPipelines->getProgramPipeline(pipeline))
746 {
747 detachProgramPipeline(pipeline);
748 }
749
750 mState.mPipelines->deleteObject(this, pipeline);
751}
752
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753void Context::deletePaths(GLuint first, GLsizei range)
754{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500755 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300756}
757
Brandon Jones59770802018-04-02 13:18:42 -0700758bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500760 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300761 if (pathObj == nullptr)
762 return false;
763
764 return pathObj->hasPathData();
765}
766
Brandon Jones59770802018-04-02 13:18:42 -0700767bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300768{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500769 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300770}
771
Brandon Jones59770802018-04-02 13:18:42 -0700772void Context::pathCommands(GLuint path,
773 GLsizei numCommands,
774 const GLubyte *commands,
775 GLsizei numCoords,
776 GLenum coordType,
777 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300778{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500779 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300780
781 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
782}
783
Jamie Madill007530e2017-12-28 14:27:04 -0500784void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300785{
Jamie Madill007530e2017-12-28 14:27:04 -0500786 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300787
788 switch (pname)
789 {
790 case GL_PATH_STROKE_WIDTH_CHROMIUM:
791 pathObj->setStrokeWidth(value);
792 break;
793 case GL_PATH_END_CAPS_CHROMIUM:
794 pathObj->setEndCaps(static_cast<GLenum>(value));
795 break;
796 case GL_PATH_JOIN_STYLE_CHROMIUM:
797 pathObj->setJoinStyle(static_cast<GLenum>(value));
798 break;
799 case GL_PATH_MITER_LIMIT_CHROMIUM:
800 pathObj->setMiterLimit(value);
801 break;
802 case GL_PATH_STROKE_BOUND_CHROMIUM:
803 pathObj->setStrokeBound(value);
804 break;
805 default:
806 UNREACHABLE();
807 break;
808 }
809}
810
Jamie Madill007530e2017-12-28 14:27:04 -0500811void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812{
Jamie Madill007530e2017-12-28 14:27:04 -0500813 // TODO(jmadill): Should use proper clamping/casting.
814 pathParameterf(path, pname, static_cast<GLfloat>(value));
815}
816
817void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
818{
819 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300820
821 switch (pname)
822 {
823 case GL_PATH_STROKE_WIDTH_CHROMIUM:
824 *value = pathObj->getStrokeWidth();
825 break;
826 case GL_PATH_END_CAPS_CHROMIUM:
827 *value = static_cast<GLfloat>(pathObj->getEndCaps());
828 break;
829 case GL_PATH_JOIN_STYLE_CHROMIUM:
830 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
831 break;
832 case GL_PATH_MITER_LIMIT_CHROMIUM:
833 *value = pathObj->getMiterLimit();
834 break;
835 case GL_PATH_STROKE_BOUND_CHROMIUM:
836 *value = pathObj->getStrokeBound();
837 break;
838 default:
839 UNREACHABLE();
840 break;
841 }
842}
843
Jamie Madill007530e2017-12-28 14:27:04 -0500844void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
845{
846 GLfloat val = 0.0f;
847 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
848 if (value)
849 *value = static_cast<GLint>(val);
850}
851
Brandon Jones59770802018-04-02 13:18:42 -0700852void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853{
854 mGLState.setPathStencilFunc(func, ref, mask);
855}
856
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857void Context::deleteFramebuffer(GLuint framebuffer)
858{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500859 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860 {
861 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500863
Jamie Madill6c1f6712017-02-14 19:08:04 -0500864 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865}
866
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500867void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500869 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500871 GLuint fence = fences[i];
872
873 FenceNV *fenceObject = nullptr;
874 if (mFenceNVMap.erase(fence, &fenceObject))
875 {
876 mFenceNVHandleAllocator.release(fence);
877 delete fenceObject;
878 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879 }
880}
881
Geoff Lang70d0f492015-12-10 17:45:46 -0500882Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000883{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500884 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000885}
886
Jamie Madill570f7c82014-07-03 10:38:54 -0400887Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000888{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500889 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000890}
891
Geoff Lang70d0f492015-12-10 17:45:46 -0500892Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000893{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500894 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000895}
896
Jamie Madill70b5bb02017-08-28 13:32:37 -0400897Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400898{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400899 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400900}
901
Jamie Madill57a89722013-07-02 11:57:03 -0400902VertexArray *Context::getVertexArray(GLuint handle) const
903{
Jamie Madill96a483b2017-06-27 16:49:21 -0400904 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400905}
906
Jamie Madilldc356042013-07-19 16:36:57 -0400907Sampler *Context::getSampler(GLuint handle) const
908{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500909 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400910}
911
Geoff Langc8058452014-02-03 12:04:11 -0500912TransformFeedback *Context::getTransformFeedback(GLuint handle) const
913{
Jamie Madill96a483b2017-06-27 16:49:21 -0400914 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500915}
916
Yunchao Hea336b902017-08-02 16:05:21 +0800917ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
918{
919 return mState.mPipelines->getProgramPipeline(handle);
920}
921
Geoff Lang75359662018-04-11 01:42:27 -0400922gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500923{
924 switch (identifier)
925 {
926 case GL_BUFFER:
927 return getBuffer(name);
928 case GL_SHADER:
929 return getShader(name);
930 case GL_PROGRAM:
931 return getProgram(name);
932 case GL_VERTEX_ARRAY:
933 return getVertexArray(name);
934 case GL_QUERY:
935 return getQuery(name);
936 case GL_TRANSFORM_FEEDBACK:
937 return getTransformFeedback(name);
938 case GL_SAMPLER:
939 return getSampler(name);
940 case GL_TEXTURE:
941 return getTexture(name);
942 case GL_RENDERBUFFER:
943 return getRenderbuffer(name);
944 case GL_FRAMEBUFFER:
945 return getFramebuffer(name);
946 default:
947 UNREACHABLE();
948 return nullptr;
949 }
950}
951
Geoff Lang75359662018-04-11 01:42:27 -0400952gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500953{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400954 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500955}
956
Martin Radev9d901792016-07-15 15:58:58 +0300957void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
958{
Geoff Lang75359662018-04-11 01:42:27 -0400959 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300960 ASSERT(object != nullptr);
961
962 std::string labelName = GetObjectLabelFromPointer(length, label);
963 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400964
965 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
966 // specified object is active until we do this.
967 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300968}
969
970void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
971{
Geoff Lang75359662018-04-11 01:42:27 -0400972 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300973 ASSERT(object != nullptr);
974
975 std::string labelName = GetObjectLabelFromPointer(length, label);
976 object->setLabel(labelName);
977}
978
979void Context::getObjectLabel(GLenum identifier,
980 GLuint name,
981 GLsizei bufSize,
982 GLsizei *length,
983 GLchar *label) const
984{
Geoff Lang75359662018-04-11 01:42:27 -0400985 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300986 ASSERT(object != nullptr);
987
988 const std::string &objectLabel = object->getLabel();
989 GetObjectLabelBase(objectLabel, bufSize, length, label);
990}
991
992void Context::getObjectPtrLabel(const void *ptr,
993 GLsizei bufSize,
994 GLsizei *length,
995 GLchar *label) const
996{
Geoff Lang75359662018-04-11 01:42:27 -0400997 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300998 ASSERT(object != nullptr);
999
1000 const std::string &objectLabel = object->getLabel();
1001 GetObjectLabelBase(objectLabel, bufSize, length, label);
1002}
1003
Jamie Madilldc356042013-07-19 16:36:57 -04001004bool Context::isSampler(GLuint samplerName) const
1005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001006 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001007}
1008
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001009void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001011 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012
Jamie Madilldedd7b92014-11-05 16:30:36 -05001013 if (handle == 0)
1014 {
1015 texture = mZeroTextures[target].get();
1016 }
1017 else
1018 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001019 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001020 }
1021
1022 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001023 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001024}
1025
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001026void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001028 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1029 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001030 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001031}
1032
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001033void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001035 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1036 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001037 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001038}
1039
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001041{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001042 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001043 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001044}
1045
Shao80957d92017-02-20 21:25:59 +08001046void Context::bindVertexBuffer(GLuint bindingIndex,
1047 GLuint bufferHandle,
1048 GLintptr offset,
1049 GLsizei stride)
1050{
1051 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001052 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001053}
1054
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001056{
Geoff Lang76b10c92014-09-05 16:28:14 -04001057 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001058 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001059 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001060 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001061}
1062
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001063void Context::bindImageTexture(GLuint unit,
1064 GLuint texture,
1065 GLint level,
1066 GLboolean layered,
1067 GLint layer,
1068 GLenum access,
1069 GLenum format)
1070{
1071 Texture *tex = mState.mTextures->getTexture(texture);
1072 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1073}
1074
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075void Context::useProgram(GLuint program)
1076{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001077 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001078}
1079
Jiajia Qin5451d532017-11-16 17:16:34 +08001080void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1081{
1082 UNIMPLEMENTED();
1083}
1084
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001085void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001086{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001087 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001088 TransformFeedback *transformFeedback =
1089 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001090 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001091}
1092
Yunchao Hea336b902017-08-02 16:05:21 +08001093void Context::bindProgramPipeline(GLuint pipelineHandle)
1094{
1095 ProgramPipeline *pipeline =
1096 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1097 mGLState.setProgramPipelineBinding(this, pipeline);
1098}
1099
Corentin Wallezad3ae902018-03-09 13:40:42 -05001100void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001103 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001104
Geoff Lang5aad9672014-09-08 11:10:42 -04001105 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001107
1108 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Corentin Wallezad3ae902018-03-09 13:40:42 -05001112void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001114 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001115 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116
Jamie Madillf0e04492017-08-26 15:28:42 -04001117 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001118
Geoff Lang5aad9672014-09-08 11:10:42 -04001119 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001120 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121}
1122
Corentin Wallezad3ae902018-03-09 13:40:42 -05001123void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001125 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001126
1127 Query *queryObject = getQuery(id, true, target);
1128 ASSERT(queryObject);
1129
Jamie Madillf0e04492017-08-26 15:28:42 -04001130 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001131}
1132
Corentin Wallezad3ae902018-03-09 13:40:42 -05001133void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134{
1135 switch (pname)
1136 {
1137 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001138 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139 break;
1140 case GL_QUERY_COUNTER_BITS_EXT:
1141 switch (target)
1142 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001143 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1145 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001146 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001147 params[0] = getExtensions().queryCounterBitsTimestamp;
1148 break;
1149 default:
1150 UNREACHABLE();
1151 params[0] = 0;
1152 break;
1153 }
1154 break;
1155 default:
1156 UNREACHABLE();
1157 return;
1158 }
1159}
1160
Corentin Wallezad3ae902018-03-09 13:40:42 -05001161void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001162 GLenum pname,
1163 GLsizei bufSize,
1164 GLsizei *length,
1165 GLint *params)
1166{
1167 getQueryiv(target, pname, params);
1168}
1169
Geoff Lang2186c382016-10-14 10:54:54 -04001170void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001171{
Geoff Lang2186c382016-10-14 10:54:54 -04001172 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173}
1174
Brandon Jones59770802018-04-02 13:18:42 -07001175void Context::getQueryObjectivRobust(GLuint id,
1176 GLenum pname,
1177 GLsizei bufSize,
1178 GLsizei *length,
1179 GLint *params)
1180{
1181 getQueryObjectiv(id, pname, params);
1182}
1183
Geoff Lang2186c382016-10-14 10:54:54 -04001184void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185{
Geoff Lang2186c382016-10-14 10:54:54 -04001186 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187}
1188
Brandon Jones59770802018-04-02 13:18:42 -07001189void Context::getQueryObjectuivRobust(GLuint id,
1190 GLenum pname,
1191 GLsizei bufSize,
1192 GLsizei *length,
1193 GLuint *params)
1194{
1195 getQueryObjectuiv(id, pname, params);
1196}
1197
Geoff Lang2186c382016-10-14 10:54:54 -04001198void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199{
Geoff Lang2186c382016-10-14 10:54:54 -04001200 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201}
1202
Brandon Jones59770802018-04-02 13:18:42 -07001203void Context::getQueryObjecti64vRobust(GLuint id,
1204 GLenum pname,
1205 GLsizei bufSize,
1206 GLsizei *length,
1207 GLint64 *params)
1208{
1209 getQueryObjecti64v(id, pname, params);
1210}
1211
Geoff Lang2186c382016-10-14 10:54:54 -04001212void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001213{
Geoff Lang2186c382016-10-14 10:54:54 -04001214 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215}
1216
Brandon Jones59770802018-04-02 13:18:42 -07001217void Context::getQueryObjectui64vRobust(GLuint id,
1218 GLenum pname,
1219 GLsizei bufSize,
1220 GLsizei *length,
1221 GLuint64 *params)
1222{
1223 getQueryObjectui64v(id, pname, params);
1224}
1225
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001226Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001228 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229}
1230
Jamie Madill2f348d22017-06-05 10:50:59 -04001231FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001232{
Jamie Madill96a483b2017-06-27 16:49:21 -04001233 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001234}
1235
Corentin Wallezad3ae902018-03-09 13:40:42 -05001236Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237{
Jamie Madill96a483b2017-06-27 16:49:21 -04001238 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001240 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001242
1243 Query *query = mQueryMap.query(handle);
1244 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001246 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001247 query = new Query(mImplementation->createQuery(type), handle);
1248 query->addRef();
1249 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001250 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001251 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252}
1253
Geoff Lang70d0f492015-12-10 17:45:46 -05001254Query *Context::getQuery(GLuint handle) const
1255{
Jamie Madill96a483b2017-06-27 16:49:21 -04001256 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001257}
1258
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001259Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001260{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001261 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1262 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001263}
1264
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001265Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001267 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268}
1269
Geoff Lang492a7e42014-11-05 13:27:06 -05001270Compiler *Context::getCompiler() const
1271{
Jamie Madill2f348d22017-06-05 10:50:59 -04001272 if (mCompiler.get() == nullptr)
1273 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001274 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001275 }
1276 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001277}
1278
Jamie Madillc1d770e2017-04-13 17:31:24 -04001279void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280{
1281 switch (pname)
1282 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001283 case GL_SHADER_COMPILER:
1284 *params = GL_TRUE;
1285 break;
1286 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1287 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1288 break;
1289 default:
1290 mGLState.getBooleanv(pname, params);
1291 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293}
1294
Jamie Madillc1d770e2017-04-13 17:31:24 -04001295void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296{
Shannon Woods53a94a82014-06-24 15:20:36 -04001297 // Queries about context capabilities and maximums are answered by Context.
1298 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299 switch (pname)
1300 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001301 case GL_ALIASED_LINE_WIDTH_RANGE:
1302 params[0] = mCaps.minAliasedLineWidth;
1303 params[1] = mCaps.maxAliasedLineWidth;
1304 break;
1305 case GL_ALIASED_POINT_SIZE_RANGE:
1306 params[0] = mCaps.minAliasedPointSize;
1307 params[1] = mCaps.maxAliasedPointSize;
1308 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001309 case GL_SMOOTH_POINT_SIZE_RANGE:
1310 params[0] = mCaps.minSmoothPointSize;
1311 params[1] = mCaps.maxSmoothPointSize;
1312 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001313 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1314 ASSERT(mExtensions.textureFilterAnisotropic);
1315 *params = mExtensions.maxTextureAnisotropy;
1316 break;
1317 case GL_MAX_TEXTURE_LOD_BIAS:
1318 *params = mCaps.maxLODBias;
1319 break;
1320
1321 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1322 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1323 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001324 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1325 // GLES1 constants for modelview/projection matrix.
1326 if (getClientVersion() < Version(2, 0))
1327 {
1328 mGLState.getFloatv(pname, params);
1329 }
1330 else
1331 {
1332 ASSERT(mExtensions.pathRendering);
1333 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1334 memcpy(params, m, 16 * sizeof(GLfloat));
1335 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001336 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001337 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001338
Jamie Madill231c7f52017-04-26 13:45:37 -04001339 default:
1340 mGLState.getFloatv(pname, params);
1341 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343}
1344
Jamie Madillc1d770e2017-04-13 17:31:24 -04001345void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346{
Shannon Woods53a94a82014-06-24 15:20:36 -04001347 // Queries about context capabilities and maximums are answered by Context.
1348 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001349
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001350 switch (pname)
1351 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001352 case GL_MAX_VERTEX_ATTRIBS:
1353 *params = mCaps.maxVertexAttributes;
1354 break;
1355 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1356 *params = mCaps.maxVertexUniformVectors;
1357 break;
1358 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001359 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
1361 case GL_MAX_VARYING_VECTORS:
1362 *params = mCaps.maxVaryingVectors;
1363 break;
1364 case GL_MAX_VARYING_COMPONENTS:
1365 *params = mCaps.maxVertexOutputComponents;
1366 break;
1367 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1368 *params = mCaps.maxCombinedTextureImageUnits;
1369 break;
1370 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001371 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 break;
1373 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001374 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 break;
1376 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1377 *params = mCaps.maxFragmentUniformVectors;
1378 break;
1379 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001380 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001381 break;
1382 case GL_MAX_RENDERBUFFER_SIZE:
1383 *params = mCaps.maxRenderbufferSize;
1384 break;
1385 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1386 *params = mCaps.maxColorAttachments;
1387 break;
1388 case GL_MAX_DRAW_BUFFERS_EXT:
1389 *params = mCaps.maxDrawBuffers;
1390 break;
1391 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1392 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1393 case GL_SUBPIXEL_BITS:
1394 *params = 4;
1395 break;
1396 case GL_MAX_TEXTURE_SIZE:
1397 *params = mCaps.max2DTextureSize;
1398 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001399 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1400 *params = mCaps.maxRectangleTextureSize;
1401 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001402 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1403 *params = mCaps.maxCubeMapTextureSize;
1404 break;
1405 case GL_MAX_3D_TEXTURE_SIZE:
1406 *params = mCaps.max3DTextureSize;
1407 break;
1408 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1409 *params = mCaps.maxArrayTextureLayers;
1410 break;
1411 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1412 *params = mCaps.uniformBufferOffsetAlignment;
1413 break;
1414 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1415 *params = mCaps.maxUniformBufferBindings;
1416 break;
1417 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001418 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001421 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1424 *params = mCaps.maxCombinedTextureImageUnits;
1425 break;
1426 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1427 *params = mCaps.maxVertexOutputComponents;
1428 break;
1429 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1430 *params = mCaps.maxFragmentInputComponents;
1431 break;
1432 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1433 *params = mCaps.minProgramTexelOffset;
1434 break;
1435 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1436 *params = mCaps.maxProgramTexelOffset;
1437 break;
1438 case GL_MAJOR_VERSION:
1439 *params = getClientVersion().major;
1440 break;
1441 case GL_MINOR_VERSION:
1442 *params = getClientVersion().minor;
1443 break;
1444 case GL_MAX_ELEMENTS_INDICES:
1445 *params = mCaps.maxElementsIndices;
1446 break;
1447 case GL_MAX_ELEMENTS_VERTICES:
1448 *params = mCaps.maxElementsVertices;
1449 break;
1450 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1451 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1452 break;
1453 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1454 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1455 break;
1456 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1457 *params = mCaps.maxTransformFeedbackSeparateComponents;
1458 break;
1459 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1460 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1461 break;
1462 case GL_MAX_SAMPLES_ANGLE:
1463 *params = mCaps.maxSamples;
1464 break;
1465 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001466 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001467 params[0] = mCaps.maxViewportWidth;
1468 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001469 }
1470 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 case GL_COMPRESSED_TEXTURE_FORMATS:
1472 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1473 params);
1474 break;
1475 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1476 *params = mResetStrategy;
1477 break;
1478 case GL_NUM_SHADER_BINARY_FORMATS:
1479 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1480 break;
1481 case GL_SHADER_BINARY_FORMATS:
1482 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1483 break;
1484 case GL_NUM_PROGRAM_BINARY_FORMATS:
1485 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1486 break;
1487 case GL_PROGRAM_BINARY_FORMATS:
1488 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1489 break;
1490 case GL_NUM_EXTENSIONS:
1491 *params = static_cast<GLint>(mExtensionStrings.size());
1492 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001493
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 // GL_KHR_debug
1495 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1496 *params = mExtensions.maxDebugMessageLength;
1497 break;
1498 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1499 *params = mExtensions.maxDebugLoggedMessages;
1500 break;
1501 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1502 *params = mExtensions.maxDebugGroupStackDepth;
1503 break;
1504 case GL_MAX_LABEL_LENGTH:
1505 *params = mExtensions.maxLabelLength;
1506 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001507
Martin Radeve5285d22017-07-14 16:23:53 +03001508 // GL_ANGLE_multiview
1509 case GL_MAX_VIEWS_ANGLE:
1510 *params = mExtensions.maxViews;
1511 break;
1512
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 // GL_EXT_disjoint_timer_query
1514 case GL_GPU_DISJOINT_EXT:
1515 *params = mImplementation->getGPUDisjoint();
1516 break;
1517 case GL_MAX_FRAMEBUFFER_WIDTH:
1518 *params = mCaps.maxFramebufferWidth;
1519 break;
1520 case GL_MAX_FRAMEBUFFER_HEIGHT:
1521 *params = mCaps.maxFramebufferHeight;
1522 break;
1523 case GL_MAX_FRAMEBUFFER_SAMPLES:
1524 *params = mCaps.maxFramebufferSamples;
1525 break;
1526 case GL_MAX_SAMPLE_MASK_WORDS:
1527 *params = mCaps.maxSampleMaskWords;
1528 break;
1529 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1530 *params = mCaps.maxColorTextureSamples;
1531 break;
1532 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1533 *params = mCaps.maxDepthTextureSamples;
1534 break;
1535 case GL_MAX_INTEGER_SAMPLES:
1536 *params = mCaps.maxIntegerSamples;
1537 break;
1538 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1539 *params = mCaps.maxVertexAttribRelativeOffset;
1540 break;
1541 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1542 *params = mCaps.maxVertexAttribBindings;
1543 break;
1544 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1545 *params = mCaps.maxVertexAttribStride;
1546 break;
1547 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001548 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001549 break;
1550 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001551 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001552 break;
1553 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001554 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001557 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001560 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001561 break;
1562 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001563 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 break;
1565 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001566 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001569 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1572 *params = mCaps.minProgramTextureGatherOffset;
1573 break;
1574 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1575 *params = mCaps.maxProgramTextureGatherOffset;
1576 break;
1577 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1578 *params = mCaps.maxComputeWorkGroupInvocations;
1579 break;
1580 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001581 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001582 break;
1583 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001584 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1587 *params = mCaps.maxComputeSharedMemorySize;
1588 break;
1589 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001590 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001593 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 break;
1595 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001596 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 break;
1598 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001599 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 break;
1601 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001602 *params =
1603 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 break;
1605 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001606 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1609 *params = mCaps.maxCombinedShaderOutputResources;
1610 break;
1611 case GL_MAX_UNIFORM_LOCATIONS:
1612 *params = mCaps.maxUniformLocations;
1613 break;
1614 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1615 *params = mCaps.maxAtomicCounterBufferBindings;
1616 break;
1617 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1618 *params = mCaps.maxAtomicCounterBufferSize;
1619 break;
1620 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1621 *params = mCaps.maxCombinedAtomicCounterBuffers;
1622 break;
1623 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1624 *params = mCaps.maxCombinedAtomicCounters;
1625 break;
1626 case GL_MAX_IMAGE_UNITS:
1627 *params = mCaps.maxImageUnits;
1628 break;
1629 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1630 *params = mCaps.maxCombinedImageUniforms;
1631 break;
1632 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1633 *params = mCaps.maxShaderStorageBufferBindings;
1634 break;
1635 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1636 *params = mCaps.maxCombinedShaderStorageBlocks;
1637 break;
1638 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1639 *params = mCaps.shaderStorageBufferOffsetAlignment;
1640 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001641
1642 // GL_EXT_geometry_shader
1643 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1644 *params = mCaps.maxFramebufferLayers;
1645 break;
1646 case GL_LAYER_PROVOKING_VERTEX_EXT:
1647 *params = mCaps.layerProvokingVertex;
1648 break;
1649 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001651 break;
1652 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001653 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001654 break;
1655 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001656 *params =
1657 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
1659 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1660 *params = mCaps.maxGeometryInputComponents;
1661 break;
1662 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1663 *params = mCaps.maxGeometryOutputComponents;
1664 break;
1665 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1666 *params = mCaps.maxGeometryOutputVertices;
1667 break;
1668 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1669 *params = mCaps.maxGeometryTotalOutputComponents;
1670 break;
1671 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1672 *params = mCaps.maxGeometryShaderInvocations;
1673 break;
1674 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001675 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001676 break;
1677 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001678 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001679 break;
1680 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001681 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001682 break;
1683 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001684 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001685 break;
1686 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001687 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001688 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001689 // GLES1 emulation: Caps queries
1690 case GL_MAX_TEXTURE_UNITS:
1691 *params = mCaps.maxMultitextureUnits;
1692 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001693 case GL_MAX_MODELVIEW_STACK_DEPTH:
1694 *params = mCaps.maxModelviewMatrixStackDepth;
1695 break;
1696 case GL_MAX_PROJECTION_STACK_DEPTH:
1697 *params = mCaps.maxProjectionMatrixStackDepth;
1698 break;
1699 case GL_MAX_TEXTURE_STACK_DEPTH:
1700 *params = mCaps.maxTextureMatrixStackDepth;
1701 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001702 case GL_MAX_LIGHTS:
1703 *params = mCaps.maxLights;
1704 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001705 case GL_MAX_CLIP_PLANES:
1706 *params = mCaps.maxClipPlanes;
1707 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001708 // GLES1 emulation: Vertex attribute queries
1709 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1710 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1711 case GL_COLOR_ARRAY_BUFFER_BINDING:
1712 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1713 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1714 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1715 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1716 break;
1717 case GL_VERTEX_ARRAY_STRIDE:
1718 case GL_NORMAL_ARRAY_STRIDE:
1719 case GL_COLOR_ARRAY_STRIDE:
1720 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1721 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1722 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1723 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1724 break;
1725 case GL_VERTEX_ARRAY_SIZE:
1726 case GL_COLOR_ARRAY_SIZE:
1727 case GL_TEXTURE_COORD_ARRAY_SIZE:
1728 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1729 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1730 break;
1731 case GL_VERTEX_ARRAY_TYPE:
1732 case GL_COLOR_ARRAY_TYPE:
1733 case GL_NORMAL_ARRAY_TYPE:
1734 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1735 case GL_TEXTURE_COORD_ARRAY_TYPE:
1736 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1737 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1738 break;
1739
jchen1082af6202018-06-22 10:59:52 +08001740 // GL_KHR_parallel_shader_compile
1741 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1742 *params = mGLState.getMaxShaderCompilerThreads();
1743 break;
1744
Jamie Madill231c7f52017-04-26 13:45:37 -04001745 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001746 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001747 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001748 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001749}
1750
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001751void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001752{
Shannon Woods53a94a82014-06-24 15:20:36 -04001753 // Queries about context capabilities and maximums are answered by Context.
1754 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001755 switch (pname)
1756 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001757 case GL_MAX_ELEMENT_INDEX:
1758 *params = mCaps.maxElementIndex;
1759 break;
1760 case GL_MAX_UNIFORM_BLOCK_SIZE:
1761 *params = mCaps.maxUniformBlockSize;
1762 break;
1763 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001764 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001765 break;
1766 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001767 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001768 break;
1769 case GL_MAX_SERVER_WAIT_TIMEOUT:
1770 *params = mCaps.maxServerWaitTimeout;
1771 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001772
Jamie Madill231c7f52017-04-26 13:45:37 -04001773 // GL_EXT_disjoint_timer_query
1774 case GL_TIMESTAMP_EXT:
1775 *params = mImplementation->getTimestamp();
1776 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001777
Jamie Madill231c7f52017-04-26 13:45:37 -04001778 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1779 *params = mCaps.maxShaderStorageBlockSize;
1780 break;
1781 default:
1782 UNREACHABLE();
1783 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001784 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001785}
1786
Geoff Lang70d0f492015-12-10 17:45:46 -05001787void Context::getPointerv(GLenum pname, void **params) const
1788{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001789 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001790}
1791
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001792void Context::getPointervRobustANGLERobust(GLenum pname,
1793 GLsizei bufSize,
1794 GLsizei *length,
1795 void **params)
1796{
1797 UNIMPLEMENTED();
1798}
1799
Martin Radev66fb8202016-07-28 11:45:20 +03001800void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001801{
Shannon Woods53a94a82014-06-24 15:20:36 -04001802 // Queries about context capabilities and maximums are answered by Context.
1803 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001804
1805 GLenum nativeType;
1806 unsigned int numParams;
1807 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1808 ASSERT(queryStatus);
1809
1810 if (nativeType == GL_INT)
1811 {
1812 switch (target)
1813 {
1814 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1815 ASSERT(index < 3u);
1816 *data = mCaps.maxComputeWorkGroupCount[index];
1817 break;
1818 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1819 ASSERT(index < 3u);
1820 *data = mCaps.maxComputeWorkGroupSize[index];
1821 break;
1822 default:
1823 mGLState.getIntegeri_v(target, index, data);
1824 }
1825 }
1826 else
1827 {
1828 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1829 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001830}
1831
Brandon Jones59770802018-04-02 13:18:42 -07001832void Context::getIntegeri_vRobust(GLenum target,
1833 GLuint index,
1834 GLsizei bufSize,
1835 GLsizei *length,
1836 GLint *data)
1837{
1838 getIntegeri_v(target, index, data);
1839}
1840
Martin Radev66fb8202016-07-28 11:45:20 +03001841void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001842{
Shannon Woods53a94a82014-06-24 15:20:36 -04001843 // Queries about context capabilities and maximums are answered by Context.
1844 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001845
1846 GLenum nativeType;
1847 unsigned int numParams;
1848 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1849 ASSERT(queryStatus);
1850
1851 if (nativeType == GL_INT_64_ANGLEX)
1852 {
1853 mGLState.getInteger64i_v(target, index, data);
1854 }
1855 else
1856 {
1857 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1858 }
1859}
1860
Brandon Jones59770802018-04-02 13:18:42 -07001861void Context::getInteger64i_vRobust(GLenum target,
1862 GLuint index,
1863 GLsizei bufSize,
1864 GLsizei *length,
1865 GLint64 *data)
1866{
1867 getInteger64i_v(target, index, data);
1868}
1869
Martin Radev66fb8202016-07-28 11:45:20 +03001870void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1871{
1872 // Queries about context capabilities and maximums are answered by Context.
1873 // Queries about current GL state values are answered by State.
1874
1875 GLenum nativeType;
1876 unsigned int numParams;
1877 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1878 ASSERT(queryStatus);
1879
1880 if (nativeType == GL_BOOL)
1881 {
1882 mGLState.getBooleani_v(target, index, data);
1883 }
1884 else
1885 {
1886 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1887 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001888}
1889
Brandon Jones59770802018-04-02 13:18:42 -07001890void Context::getBooleani_vRobust(GLenum target,
1891 GLuint index,
1892 GLsizei bufSize,
1893 GLsizei *length,
1894 GLboolean *data)
1895{
1896 getBooleani_v(target, index, data);
1897}
1898
Corentin Wallez336129f2017-10-17 15:55:40 -04001899void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001900{
1901 Buffer *buffer = mGLState.getTargetBuffer(target);
1902 QueryBufferParameteriv(buffer, pname, params);
1903}
1904
Brandon Jones59770802018-04-02 13:18:42 -07001905void Context::getBufferParameterivRobust(BufferBinding target,
1906 GLenum pname,
1907 GLsizei bufSize,
1908 GLsizei *length,
1909 GLint *params)
1910{
1911 getBufferParameteriv(target, pname, params);
1912}
1913
He Yunchao010e4db2017-03-03 14:22:06 +08001914void Context::getFramebufferAttachmentParameteriv(GLenum target,
1915 GLenum attachment,
1916 GLenum pname,
1917 GLint *params)
1918{
1919 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001920 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001921}
1922
Brandon Jones59770802018-04-02 13:18:42 -07001923void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1924 GLenum attachment,
1925 GLenum pname,
1926 GLsizei bufSize,
1927 GLsizei *length,
1928 GLint *params)
1929{
1930 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1931}
1932
He Yunchao010e4db2017-03-03 14:22:06 +08001933void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1934{
1935 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1936 QueryRenderbufferiv(this, renderbuffer, pname, params);
1937}
1938
Brandon Jones59770802018-04-02 13:18:42 -07001939void Context::getRenderbufferParameterivRobust(GLenum target,
1940 GLenum pname,
1941 GLsizei bufSize,
1942 GLsizei *length,
1943 GLint *params)
1944{
1945 getRenderbufferParameteriv(target, pname, params);
1946}
1947
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001948void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001949{
1950 Texture *texture = getTargetTexture(target);
1951 QueryTexParameterfv(texture, pname, params);
1952}
1953
Brandon Jones59770802018-04-02 13:18:42 -07001954void Context::getTexParameterfvRobust(TextureType target,
1955 GLenum pname,
1956 GLsizei bufSize,
1957 GLsizei *length,
1958 GLfloat *params)
1959{
1960 getTexParameterfv(target, pname, params);
1961}
1962
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001963void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001964{
1965 Texture *texture = getTargetTexture(target);
1966 QueryTexParameteriv(texture, pname, params);
1967}
Jiajia Qin5451d532017-11-16 17:16:34 +08001968
Brandon Jones59770802018-04-02 13:18:42 -07001969void Context::getTexParameterivRobust(TextureType target,
1970 GLenum pname,
1971 GLsizei bufSize,
1972 GLsizei *length,
1973 GLint *params)
1974{
1975 getTexParameteriv(target, pname, params);
1976}
1977
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001978void Context::getTexParameterIivRobust(TextureType target,
1979 GLenum pname,
1980 GLsizei bufSize,
1981 GLsizei *length,
1982 GLint *params)
1983{
1984 UNIMPLEMENTED();
1985}
1986
1987void Context::getTexParameterIuivRobust(TextureType target,
1988 GLenum pname,
1989 GLsizei bufSize,
1990 GLsizei *length,
1991 GLuint *params)
1992{
1993 UNIMPLEMENTED();
1994}
1995
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001996void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001997{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001998 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001999 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002000}
2001
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002002void Context::getTexLevelParameterivRobust(TextureTarget target,
2003 GLint level,
2004 GLenum pname,
2005 GLsizei bufSize,
2006 GLsizei *length,
2007 GLint *params)
2008{
2009 UNIMPLEMENTED();
2010}
2011
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002012void Context::getTexLevelParameterfv(TextureTarget target,
2013 GLint level,
2014 GLenum pname,
2015 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002016{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002017 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002018 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002019}
2020
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002021void Context::getTexLevelParameterfvRobust(TextureTarget target,
2022 GLint level,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLfloat *params)
2027{
2028 UNIMPLEMENTED();
2029}
2030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002031void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002032{
2033 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002034 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002035 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002036}
2037
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002038void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002039{
2040 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002041 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002042 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002043}
2044
Brandon Jones59770802018-04-02 13:18:42 -07002045void Context::texParameterfvRobust(TextureType target,
2046 GLenum pname,
2047 GLsizei bufSize,
2048 const GLfloat *params)
2049{
2050 texParameterfv(target, pname, params);
2051}
2052
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002053void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002054{
2055 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002056 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002057 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002058}
2059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002060void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002061{
2062 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002063 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002064 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002065}
2066
Brandon Jones59770802018-04-02 13:18:42 -07002067void Context::texParameterivRobust(TextureType target,
2068 GLenum pname,
2069 GLsizei bufSize,
2070 const GLint *params)
2071{
2072 texParameteriv(target, pname, params);
2073}
2074
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002075void Context::texParameterIivRobust(TextureType target,
2076 GLenum pname,
2077 GLsizei bufSize,
2078 const GLint *params)
2079{
2080 UNIMPLEMENTED();
2081}
2082
2083void Context::texParameterIuivRobust(TextureType target,
2084 GLenum pname,
2085 GLsizei bufSize,
2086 const GLuint *params)
2087{
2088 UNIMPLEMENTED();
2089}
2090
Jamie Madill493f9572018-05-24 19:52:15 -04002091void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002092{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002093 // No-op if zero count
2094 if (count == 0)
2095 {
2096 return;
2097 }
2098
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002099 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002100 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002101 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002102}
2103
Jamie Madill493f9572018-05-24 19:52:15 -04002104void Context::drawArraysInstanced(PrimitiveMode mode,
2105 GLint first,
2106 GLsizei count,
2107 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002108{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002109 // No-op if zero count
2110 if (count == 0 || instanceCount == 0)
2111 {
2112 return;
2113 }
2114
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002115 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002116 ANGLE_CONTEXT_TRY(
2117 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002118 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2119 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002120}
2121
Jamie Madill493f9572018-05-24 19:52:15 -04002122void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002123{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002124 // No-op if zero count
2125 if (count == 0)
2126 {
2127 return;
2128 }
2129
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002130 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002131 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002132}
2133
Jamie Madill493f9572018-05-24 19:52:15 -04002134void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002135 GLsizei count,
2136 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002137 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002138 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002139{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002140 // No-op if zero count
2141 if (count == 0 || instances == 0)
2142 {
2143 return;
2144 }
2145
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002146 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002147 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002148 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002149}
2150
Jamie Madill493f9572018-05-24 19:52:15 -04002151void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002152 GLuint start,
2153 GLuint end,
2154 GLsizei count,
2155 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002156 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002157{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002158 // No-op if zero count
2159 if (count == 0)
2160 {
2161 return;
2162 }
2163
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002164 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002165 ANGLE_CONTEXT_TRY(
2166 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002167}
2168
Jamie Madill493f9572018-05-24 19:52:15 -04002169void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002170{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002171 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002172 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002173}
2174
Jamie Madill493f9572018-05-24 19:52:15 -04002175void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002176{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002177 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002178 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002179}
2180
Jamie Madill675fe712016-12-19 13:07:54 -05002181void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182{
Jamie Madillafa02a22017-11-23 12:57:38 -05002183 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002184}
2185
Jamie Madill675fe712016-12-19 13:07:54 -05002186void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002187{
Jamie Madillafa02a22017-11-23 12:57:38 -05002188 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002189}
2190
Austin Kinross6ee1e782015-05-29 17:05:37 -07002191void Context::insertEventMarker(GLsizei length, const char *marker)
2192{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002193 ASSERT(mImplementation);
2194 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002195}
2196
2197void Context::pushGroupMarker(GLsizei length, const char *marker)
2198{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002199 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002200
2201 if (marker == nullptr)
2202 {
2203 // From the EXT_debug_marker spec,
2204 // "If <marker> is null then an empty string is pushed on the stack."
2205 mImplementation->pushGroupMarker(length, "");
2206 }
2207 else
2208 {
2209 mImplementation->pushGroupMarker(length, marker);
2210 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002211}
2212
2213void Context::popGroupMarker()
2214{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002215 ASSERT(mImplementation);
2216 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002217}
2218
Geoff Langd8605522016-04-13 10:19:12 -04002219void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2220{
2221 Program *programObject = getProgram(program);
2222 ASSERT(programObject);
2223
2224 programObject->bindUniformLocation(location, name);
2225}
2226
Brandon Jones59770802018-04-02 13:18:42 -07002227void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002229 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002230}
2231
Brandon Jones59770802018-04-02 13:18:42 -07002232void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233{
2234 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2235}
2236
Brandon Jones59770802018-04-02 13:18:42 -07002237void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002238{
2239 GLfloat I[16];
2240 angle::Matrix<GLfloat>::setToIdentity(I);
2241
2242 mGLState.loadPathRenderingMatrix(matrixMode, I);
2243}
2244
2245void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
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->stencilFillPath(pathObj, fillMode, mask);
2255}
2256
2257void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
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->stencilStrokePath(pathObj, reference, mask);
2267}
2268
2269void Context::coverFillPath(GLuint path, 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->coverFillPath(pathObj, coverMode);
2279}
2280
2281void Context::coverStrokePath(GLuint path, GLenum coverMode)
2282{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002283 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002284 if (!pathObj)
2285 return;
2286
2287 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002288 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002289
2290 mImplementation->coverStrokePath(pathObj, coverMode);
2291}
2292
2293void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2294{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002295 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002296 if (!pathObj)
2297 return;
2298
2299 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002300 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002301
2302 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2303}
2304
2305void Context::stencilThenCoverStrokePath(GLuint path,
2306 GLint reference,
2307 GLuint mask,
2308 GLenum coverMode)
2309{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002310 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002311 if (!pathObj)
2312 return;
2313
2314 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002315 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002316
2317 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2318}
2319
Sami Väisänend59ca052016-06-21 16:10:00 +03002320void Context::coverFillPathInstanced(GLsizei numPaths,
2321 GLenum pathNameType,
2322 const void *paths,
2323 GLuint pathBase,
2324 GLenum coverMode,
2325 GLenum transformType,
2326 const GLfloat *transformValues)
2327{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002328 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002329
2330 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002331 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002332
2333 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2334}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002335
Sami Väisänend59ca052016-06-21 16:10:00 +03002336void Context::coverStrokePathInstanced(GLsizei numPaths,
2337 GLenum pathNameType,
2338 const void *paths,
2339 GLuint pathBase,
2340 GLenum coverMode,
2341 GLenum transformType,
2342 const GLfloat *transformValues)
2343{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002344 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002345
2346 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002347 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002348
2349 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2350 transformValues);
2351}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002352
Sami Väisänend59ca052016-06-21 16:10:00 +03002353void Context::stencilFillPathInstanced(GLsizei numPaths,
2354 GLenum pathNameType,
2355 const void *paths,
2356 GLuint pathBase,
2357 GLenum fillMode,
2358 GLuint mask,
2359 GLenum transformType,
2360 const GLfloat *transformValues)
2361{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002362 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002363
2364 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002365 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002366
2367 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2368 transformValues);
2369}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002370
Sami Väisänend59ca052016-06-21 16:10:00 +03002371void Context::stencilStrokePathInstanced(GLsizei numPaths,
2372 GLenum pathNameType,
2373 const void *paths,
2374 GLuint pathBase,
2375 GLint reference,
2376 GLuint mask,
2377 GLenum transformType,
2378 const GLfloat *transformValues)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002381
2382 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002383 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002384
2385 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2386 transformValues);
2387}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002388
Sami Väisänend59ca052016-06-21 16:10:00 +03002389void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2390 GLenum pathNameType,
2391 const void *paths,
2392 GLuint pathBase,
2393 GLenum fillMode,
2394 GLuint mask,
2395 GLenum coverMode,
2396 GLenum transformType,
2397 const GLfloat *transformValues)
2398{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002399 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002400
2401 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002402 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002403
2404 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2405 transformType, transformValues);
2406}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002407
Sami Väisänend59ca052016-06-21 16:10:00 +03002408void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2409 GLenum pathNameType,
2410 const void *paths,
2411 GLuint pathBase,
2412 GLint reference,
2413 GLuint mask,
2414 GLenum coverMode,
2415 GLenum transformType,
2416 const GLfloat *transformValues)
2417{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002418 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002419
2420 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002421 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002422
2423 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2424 transformType, transformValues);
2425}
2426
Sami Väisänen46eaa942016-06-29 10:26:37 +03002427void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2428{
2429 auto *programObject = getProgram(program);
2430
2431 programObject->bindFragmentInputLocation(location, name);
2432}
2433
2434void Context::programPathFragmentInputGen(GLuint program,
2435 GLint location,
2436 GLenum genMode,
2437 GLint components,
2438 const GLfloat *coeffs)
2439{
2440 auto *programObject = getProgram(program);
2441
Jamie Madillbd044ed2017-06-05 12:59:21 -04002442 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002443}
2444
jchen1015015f72017-03-16 13:54:21 +08002445GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2446{
jchen10fd7c3b52017-03-21 15:36:03 +08002447 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002448 return QueryProgramResourceIndex(programObject, programInterface, name);
2449}
2450
jchen10fd7c3b52017-03-21 15:36:03 +08002451void Context::getProgramResourceName(GLuint program,
2452 GLenum programInterface,
2453 GLuint index,
2454 GLsizei bufSize,
2455 GLsizei *length,
2456 GLchar *name)
2457{
2458 const auto *programObject = getProgram(program);
2459 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2460}
2461
jchen10191381f2017-04-11 13:59:04 +08002462GLint Context::getProgramResourceLocation(GLuint program,
2463 GLenum programInterface,
2464 const GLchar *name)
2465{
2466 const auto *programObject = getProgram(program);
2467 return QueryProgramResourceLocation(programObject, programInterface, name);
2468}
2469
jchen10880683b2017-04-12 16:21:55 +08002470void Context::getProgramResourceiv(GLuint program,
2471 GLenum programInterface,
2472 GLuint index,
2473 GLsizei propCount,
2474 const GLenum *props,
2475 GLsizei bufSize,
2476 GLsizei *length,
2477 GLint *params)
2478{
2479 const auto *programObject = getProgram(program);
2480 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2481 length, params);
2482}
2483
jchen10d9cd7b72017-08-30 15:04:25 +08002484void Context::getProgramInterfaceiv(GLuint program,
2485 GLenum programInterface,
2486 GLenum pname,
2487 GLint *params)
2488{
2489 const auto *programObject = getProgram(program);
2490 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2491}
2492
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002493void Context::getProgramInterfaceivRobust(GLuint program,
2494 GLenum programInterface,
2495 GLenum pname,
2496 GLsizei bufSize,
2497 GLsizei *length,
2498 GLint *params)
2499{
2500 UNIMPLEMENTED();
2501}
2502
Jamie Madill427064d2018-04-13 16:20:34 -04002503void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504{
Geoff Lang7b19a492018-04-20 09:31:52 -04002505 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002506 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002507 GLenum code = error.getCode();
2508 mErrors.insert(code);
2509 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2510 {
2511 markContextLost();
2512 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002513
Geoff Langee6884e2017-11-09 16:51:11 -05002514 ASSERT(!error.getMessage().empty());
2515 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2516 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002517 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002518}
2519
2520// Get one of the recorded errors and clear its flag, if any.
2521// [OpenGL ES 2.0.24] section 2.5 page 13.
2522GLenum Context::getError()
2523{
Geoff Langda5777c2014-07-11 09:52:58 -04002524 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525 {
Geoff Langda5777c2014-07-11 09:52:58 -04002526 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002527 }
Geoff Langda5777c2014-07-11 09:52:58 -04002528 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529 {
Geoff Langda5777c2014-07-11 09:52:58 -04002530 GLenum error = *mErrors.begin();
2531 mErrors.erase(mErrors.begin());
2532 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002533 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002534}
2535
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002536// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002537void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002538{
2539 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002540 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002541 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002542 mContextLostForced = true;
2543 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002544 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545}
2546
Jamie Madill427064d2018-04-13 16:20:34 -04002547bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002548{
2549 return mContextLost;
2550}
2551
Jamie Madillfa920eb2018-01-04 11:45:50 -05002552GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002553{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002554 // Even if the application doesn't want to know about resets, we want to know
2555 // as it will allow us to skip all the calls.
2556 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002557 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002558 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002559 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002560 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002561 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002562
2563 // EXT_robustness, section 2.6: If the reset notification behavior is
2564 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2565 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2566 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567 }
2568
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002569 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2570 // status should be returned at least once, and GL_NO_ERROR should be returned
2571 // once the device has finished resetting.
2572 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002573 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002574 ASSERT(mResetStatus == GL_NO_ERROR);
2575 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002576
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002577 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002578 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002579 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580 }
2581 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002582 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002583 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002584 // If markContextLost was used to mark the context lost then
2585 // assume that is not recoverable, and continue to report the
2586 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002587 mResetStatus = mImplementation->getResetStatus();
2588 }
Jamie Madill893ab082014-05-16 16:56:10 -04002589
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002591}
2592
2593bool Context::isResetNotificationEnabled()
2594{
2595 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2596}
2597
Corentin Walleze3b10e82015-05-20 11:06:25 -04002598const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002599{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002600 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002601}
2602
2603EGLenum Context::getClientType() const
2604{
2605 return mClientType;
2606}
2607
2608EGLenum Context::getRenderBuffer() const
2609{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002610 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2611 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002612 {
2613 return EGL_NONE;
2614 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002615
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002616 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002617 ASSERT(backAttachment != nullptr);
2618 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002619}
2620
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002621VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002622{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002623 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002624 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2625 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002626 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002627 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2628 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002629
Jamie Madill96a483b2017-06-27 16:49:21 -04002630 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002631 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002632
2633 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002634}
2635
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002636TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002637{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002638 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002639 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2640 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002641 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002642 transformFeedback =
2643 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002644 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002645 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002646 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002647
2648 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002649}
2650
2651bool Context::isVertexArrayGenerated(GLuint vertexArray)
2652{
Jamie Madill96a483b2017-06-27 16:49:21 -04002653 ASSERT(mVertexArrayMap.contains(0));
2654 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002655}
2656
2657bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2658{
Jamie Madill96a483b2017-06-27 16:49:21 -04002659 ASSERT(mTransformFeedbackMap.contains(0));
2660 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002661}
2662
Shannon Woods53a94a82014-06-24 15:20:36 -04002663void Context::detachTexture(GLuint texture)
2664{
2665 // Simple pass-through to State's detachTexture method, as textures do not require
2666 // allocation map management either here or in the resource manager at detach time.
2667 // Zero textures are held by the Context, and we don't attempt to request them from
2668 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002669 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002670}
2671
James Darpinian4d9d4832018-03-13 12:43:28 -07002672void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673{
Yuly Novikov5807a532015-12-03 13:01:22 -05002674 // Simple pass-through to State's detachBuffer method, since
2675 // only buffer attachments to container objects that are bound to the current context
2676 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002677
Yuly Novikov5807a532015-12-03 13:01:22 -05002678 // [OpenGL ES 3.2] section 5.1.2 page 45:
2679 // Attachments to unbound container objects, such as
2680 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2681 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002682 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002683}
2684
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002685void Context::detachFramebuffer(GLuint framebuffer)
2686{
Shannon Woods53a94a82014-06-24 15:20:36 -04002687 // Framebuffer detachment is handled by Context, because 0 is a valid
2688 // Framebuffer object, and a pointer to it must be passed from Context
2689 // to State at binding time.
2690
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002691 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002692 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2693 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2694 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002695
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002696 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002697 {
2698 bindReadFramebuffer(0);
2699 }
2700
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002701 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002702 {
2703 bindDrawFramebuffer(0);
2704 }
2705}
2706
2707void Context::detachRenderbuffer(GLuint renderbuffer)
2708{
Jamie Madilla02315b2017-02-23 14:14:47 -05002709 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002710}
2711
Jamie Madill57a89722013-07-02 11:57:03 -04002712void Context::detachVertexArray(GLuint vertexArray)
2713{
Jamie Madill77a72f62015-04-14 11:18:32 -04002714 // Vertex array detachment is handled by Context, because 0 is a valid
2715 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002716 // binding time.
2717
Jamie Madill57a89722013-07-02 11:57:03 -04002718 // [OpenGL ES 3.0.2] section 2.10 page 43:
2719 // If a vertex array object that is currently bound is deleted, the binding
2720 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002721 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002722 {
2723 bindVertexArray(0);
2724 }
2725}
2726
Geoff Langc8058452014-02-03 12:04:11 -05002727void Context::detachTransformFeedback(GLuint transformFeedback)
2728{
Corentin Walleza2257da2016-04-19 16:43:12 -04002729 // Transform feedback detachment is handled by Context, because 0 is a valid
2730 // transform feedback, and a pointer to it must be passed from Context to State at
2731 // binding time.
2732
2733 // The OpenGL specification doesn't mention what should happen when the currently bound
2734 // transform feedback object is deleted. Since it is a container object, we treat it like
2735 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002736 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002737 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002738 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002739 }
Geoff Langc8058452014-02-03 12:04:11 -05002740}
2741
Jamie Madilldc356042013-07-19 16:36:57 -04002742void Context::detachSampler(GLuint sampler)
2743{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002744 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002745}
2746
Yunchao Hea336b902017-08-02 16:05:21 +08002747void Context::detachProgramPipeline(GLuint pipeline)
2748{
2749 mGLState.detachProgramPipeline(this, pipeline);
2750}
2751
Jamie Madill3ef140a2017-08-26 23:11:21 -04002752void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002753{
Shaodde78e82017-05-22 14:13:27 +08002754 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002755}
2756
Jamie Madille29d1672013-07-19 16:36:57 -04002757void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2758{
Geoff Langc1984ed2016-10-07 12:41:00 -04002759 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002760 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002761 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002762 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002763}
Jamie Madille29d1672013-07-19 16:36:57 -04002764
Geoff Langc1984ed2016-10-07 12:41:00 -04002765void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2766{
2767 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002768 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002769 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002770 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002771}
2772
Brandon Jones59770802018-04-02 13:18:42 -07002773void Context::samplerParameterivRobust(GLuint sampler,
2774 GLenum pname,
2775 GLsizei bufSize,
2776 const GLint *param)
2777{
2778 samplerParameteriv(sampler, pname, param);
2779}
2780
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002781void Context::samplerParameterIivRobust(GLuint sampler,
2782 GLenum pname,
2783 GLsizei bufSize,
2784 const GLint *param)
2785{
2786 UNIMPLEMENTED();
2787}
2788
2789void Context::samplerParameterIuivRobust(GLuint sampler,
2790 GLenum pname,
2791 GLsizei bufSize,
2792 const GLuint *param)
2793{
2794 UNIMPLEMENTED();
2795}
2796
Jamie Madille29d1672013-07-19 16:36:57 -04002797void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2798{
Geoff Langc1984ed2016-10-07 12:41:00 -04002799 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002800 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002801 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002802 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002803}
2804
Geoff Langc1984ed2016-10-07 12:41:00 -04002805void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002806{
Geoff Langc1984ed2016-10-07 12:41:00 -04002807 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002808 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002809 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002810 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002811}
2812
Brandon Jones59770802018-04-02 13:18:42 -07002813void Context::samplerParameterfvRobust(GLuint sampler,
2814 GLenum pname,
2815 GLsizei bufSize,
2816 const GLfloat *param)
2817{
2818 samplerParameterfv(sampler, pname, param);
2819}
2820
Geoff Langc1984ed2016-10-07 12:41:00 -04002821void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002822{
Geoff Langc1984ed2016-10-07 12:41:00 -04002823 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002824 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002825 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002826 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002827}
Jamie Madill9675b802013-07-19 16:36:59 -04002828
Brandon Jones59770802018-04-02 13:18:42 -07002829void Context::getSamplerParameterivRobust(GLuint sampler,
2830 GLenum pname,
2831 GLsizei bufSize,
2832 GLsizei *length,
2833 GLint *params)
2834{
2835 getSamplerParameteriv(sampler, pname, params);
2836}
2837
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002838void Context::getSamplerParameterIivRobust(GLuint sampler,
2839 GLenum pname,
2840 GLsizei bufSize,
2841 GLsizei *length,
2842 GLint *params)
2843{
2844 UNIMPLEMENTED();
2845}
2846
2847void Context::getSamplerParameterIuivRobust(GLuint sampler,
2848 GLenum pname,
2849 GLsizei bufSize,
2850 GLsizei *length,
2851 GLuint *params)
2852{
2853 UNIMPLEMENTED();
2854}
2855
Geoff Langc1984ed2016-10-07 12:41:00 -04002856void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2857{
2858 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002859 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002860 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002861 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002862}
2863
Brandon Jones59770802018-04-02 13:18:42 -07002864void Context::getSamplerParameterfvRobust(GLuint sampler,
2865 GLenum pname,
2866 GLsizei bufSize,
2867 GLsizei *length,
2868 GLfloat *params)
2869{
2870 getSamplerParameterfv(sampler, pname, params);
2871}
2872
Olli Etuahof0fee072016-03-30 15:11:58 +03002873void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2874{
2875 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002876 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002877}
2878
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002879void Context::initRendererString()
2880{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002881 std::ostringstream rendererString;
2882 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002883 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002884 rendererString << ")";
2885
Geoff Langcec35902014-04-16 10:52:36 -04002886 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002887}
2888
Geoff Langc339c4e2016-11-29 10:37:36 -05002889void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002890{
Geoff Langc339c4e2016-11-29 10:37:36 -05002891 const Version &clientVersion = getClientVersion();
2892
2893 std::ostringstream versionString;
2894 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2895 << ANGLE_VERSION_STRING << ")";
2896 mVersionString = MakeStaticString(versionString.str());
2897
2898 std::ostringstream shadingLanguageVersionString;
2899 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2900 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2901 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2902 << ")";
2903 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002904}
2905
Geoff Langcec35902014-04-16 10:52:36 -04002906void Context::initExtensionStrings()
2907{
Geoff Langc339c4e2016-11-29 10:37:36 -05002908 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2909 std::ostringstream combinedStringStream;
2910 std::copy(strings.begin(), strings.end(),
2911 std::ostream_iterator<const char *>(combinedStringStream, " "));
2912 return MakeStaticString(combinedStringStream.str());
2913 };
2914
2915 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002916 for (const auto &extensionString : mExtensions.getStrings())
2917 {
2918 mExtensionStrings.push_back(MakeStaticString(extensionString));
2919 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002920 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002921
Geoff Langc339c4e2016-11-29 10:37:36 -05002922 mRequestableExtensionStrings.clear();
2923 for (const auto &extensionInfo : GetExtensionInfoMap())
2924 {
2925 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002926 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002927 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002928 {
2929 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2930 }
2931 }
2932 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002933}
2934
Geoff Langc339c4e2016-11-29 10:37:36 -05002935const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002936{
Geoff Langc339c4e2016-11-29 10:37:36 -05002937 switch (name)
2938 {
2939 case GL_VENDOR:
2940 return reinterpret_cast<const GLubyte *>("Google Inc.");
2941
2942 case GL_RENDERER:
2943 return reinterpret_cast<const GLubyte *>(mRendererString);
2944
2945 case GL_VERSION:
2946 return reinterpret_cast<const GLubyte *>(mVersionString);
2947
2948 case GL_SHADING_LANGUAGE_VERSION:
2949 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2950
2951 case GL_EXTENSIONS:
2952 return reinterpret_cast<const GLubyte *>(mExtensionString);
2953
2954 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2955 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2956
2957 default:
2958 UNREACHABLE();
2959 return nullptr;
2960 }
Geoff Langcec35902014-04-16 10:52:36 -04002961}
2962
Geoff Langc339c4e2016-11-29 10:37:36 -05002963const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002964{
Geoff Langc339c4e2016-11-29 10:37:36 -05002965 switch (name)
2966 {
2967 case GL_EXTENSIONS:
2968 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2969
2970 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2971 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2972
2973 default:
2974 UNREACHABLE();
2975 return nullptr;
2976 }
Geoff Langcec35902014-04-16 10:52:36 -04002977}
2978
2979size_t Context::getExtensionStringCount() const
2980{
2981 return mExtensionStrings.size();
2982}
2983
Geoff Lang111a99e2017-10-17 10:58:41 -04002984bool Context::isExtensionRequestable(const char *name)
2985{
2986 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2987 auto extension = extensionInfos.find(name);
2988
Geoff Lang111a99e2017-10-17 10:58:41 -04002989 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002990 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002991}
2992
Geoff Langc339c4e2016-11-29 10:37:36 -05002993void Context::requestExtension(const char *name)
2994{
2995 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2996 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2997 const auto &extension = extensionInfos.at(name);
2998 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002999 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003000
3001 if (mExtensions.*(extension.ExtensionsMember))
3002 {
3003 // Extension already enabled
3004 return;
3005 }
3006
3007 mExtensions.*(extension.ExtensionsMember) = true;
3008 updateCaps();
3009 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003010
Jamie Madill2f348d22017-06-05 10:50:59 -04003011 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3012 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003013
Jamie Madill81c2e252017-09-09 23:32:46 -04003014 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3015 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003016 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003017 for (auto &zeroTexture : mZeroTextures)
3018 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003019 if (zeroTexture.get() != nullptr)
3020 {
3021 zeroTexture->signalDirty(this, InitState::Initialized);
3022 }
Geoff Lang9aded172017-04-05 11:07:56 -04003023 }
3024
3025 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003026}
3027
3028size_t Context::getRequestableExtensionStringCount() const
3029{
3030 return mRequestableExtensionStrings.size();
3031}
3032
Jamie Madill493f9572018-05-24 19:52:15 -04003033void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003034{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003035 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003036 ASSERT(transformFeedback != nullptr);
3037 ASSERT(!transformFeedback->isPaused());
3038
Jamie Madill6c1f6712017-02-14 19:08:04 -05003039 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003040}
3041
3042bool Context::hasActiveTransformFeedback(GLuint program) const
3043{
3044 for (auto pair : mTransformFeedbackMap)
3045 {
3046 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3047 {
3048 return true;
3049 }
3050 }
3051 return false;
3052}
3053
Geoff Lang33f11fb2018-05-07 13:42:47 -04003054Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003055{
3056 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3057
jchen1082af6202018-06-22 10:59:52 +08003058 // Explicitly enable GL_KHR_parallel_shader_compile
3059 supportedExtensions.parallelShaderCompile = true;
3060
Geoff Langb0f917f2017-12-05 13:41:54 -05003061 if (getClientVersion() < ES_2_0)
3062 {
3063 // Default extensions for GLES1
3064 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003065 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003066 supportedExtensions.pointSprite = true;
jchen1082af6202018-06-22 10:59:52 +08003067 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003068 }
3069
3070 if (getClientVersion() < ES_3_0)
3071 {
3072 // Disable ES3+ extensions
3073 supportedExtensions.colorBufferFloat = false;
3074 supportedExtensions.eglImageExternalEssl3 = false;
3075 supportedExtensions.textureNorm16 = false;
3076 supportedExtensions.multiview = false;
3077 supportedExtensions.maxViews = 1u;
3078 }
3079
3080 if (getClientVersion() < ES_3_1)
3081 {
3082 // Disable ES3.1+ extensions
3083 supportedExtensions.geometryShader = false;
3084 }
3085
3086 if (getClientVersion() > ES_2_0)
3087 {
3088 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3089 // supportedExtensions.sRGB = false;
3090 }
3091
3092 // Some extensions are always available because they are implemented in the GL layer.
3093 supportedExtensions.bindUniformLocation = true;
3094 supportedExtensions.vertexArrayObject = true;
3095 supportedExtensions.bindGeneratesResource = true;
3096 supportedExtensions.clientArrays = true;
3097 supportedExtensions.requestExtension = true;
3098
3099 // Enable the no error extension if the context was created with the flag.
3100 supportedExtensions.noError = mSkipValidation;
3101
3102 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003103 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003104
3105 // Explicitly enable GL_KHR_debug
3106 supportedExtensions.debug = true;
3107 supportedExtensions.maxDebugMessageLength = 1024;
3108 supportedExtensions.maxDebugLoggedMessages = 1024;
3109 supportedExtensions.maxDebugGroupStackDepth = 1024;
3110 supportedExtensions.maxLabelLength = 1024;
3111
3112 // Explicitly enable GL_ANGLE_robust_client_memory
3113 supportedExtensions.robustClientMemory = true;
3114
3115 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003116 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003117
3118 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3119 // supports it.
3120 supportedExtensions.robustBufferAccessBehavior =
3121 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3122
3123 // Enable the cache control query unconditionally.
3124 supportedExtensions.programCacheControl = true;
3125
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003126 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003127 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003128 {
3129 // GL_ANGLE_explicit_context_gles1
3130 supportedExtensions.explicitContextGles1 = true;
3131 // GL_ANGLE_explicit_context
3132 supportedExtensions.explicitContext = true;
3133 }
3134
Geoff Langb0f917f2017-12-05 13:41:54 -05003135 return supportedExtensions;
3136}
3137
Geoff Lang33f11fb2018-05-07 13:42:47 -04003138void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003139{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003140 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003141
Geoff Lang33f11fb2018-05-07 13:42:47 -04003142 mSupportedExtensions = generateSupportedExtensions();
3143 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003144
3145 mLimitations = mImplementation->getNativeLimitations();
3146
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003147 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3148 if (getClientVersion() < Version(2, 0))
3149 {
3150 mCaps.maxMultitextureUnits = 4;
3151 mCaps.maxClipPlanes = 6;
3152 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003153 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3154 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3155 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003156 mCaps.minSmoothPointSize = 1.0f;
3157 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003158 }
3159
Luc Ferronad2ae932018-06-11 15:31:17 -04003160 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003161 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003162
Luc Ferronad2ae932018-06-11 15:31:17 -04003163 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3164
Jamie Madill0f80ed82017-09-19 00:24:56 -04003165 if (getClientVersion() < ES_3_1)
3166 {
3167 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3168 }
3169 else
3170 {
3171 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3172 }
Geoff Lang301d1612014-07-09 10:34:37 -04003173
Jiawei Shao54aafe52018-04-27 14:54:57 +08003174 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3175 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003176 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3177 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3178
3179 // Limit textures as well, so we can use fast bitsets with texture bindings.
3180 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003181 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3182 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3183 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3184 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003185
Jiawei Shaodb342272017-09-27 10:21:45 +08003186 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3187
Geoff Langc287ea62016-09-16 14:46:51 -04003188 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003189 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003190 for (const auto &extensionInfo : GetExtensionInfoMap())
3191 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003192 // If the user has requested that extensions start disabled and they are requestable,
3193 // disable them.
3194 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003195 {
3196 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3197 }
3198 }
3199
3200 // Generate texture caps
3201 updateCaps();
3202}
3203
3204void Context::updateCaps()
3205{
Geoff Lang900013c2014-07-07 11:32:19 -04003206 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003207 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003208
Jamie Madill7b62cf92017-11-02 15:20:49 -04003209 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003210 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003211 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003212 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003213
Geoff Lang0d8b7242015-09-09 14:56:53 -04003214 // Update the format caps based on the client version and extensions.
3215 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3216 // ES3.
3217 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003218 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003219 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003220 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003221 formatCaps.textureAttachment =
3222 formatCaps.textureAttachment &&
3223 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3224 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3225 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003226
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003227 // OpenGL ES does not support multisampling with non-rendererable formats
3228 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003229 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003230 (getClientVersion() < ES_3_1 &&
3231 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003232 {
Geoff Langd87878e2014-09-19 15:42:59 -04003233 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003234 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003235 else
3236 {
3237 // We may have limited the max samples for some required renderbuffer formats due to
3238 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3239 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3240
3241 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3242 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3243 // exception of signed and unsigned integer formats."
3244 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3245 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3246 {
3247 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3248 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3249 }
3250
3251 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3252 if (getClientVersion() >= ES_3_1)
3253 {
3254 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3255 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3256 // the exception that the signed and unsigned integer formats are required only to
3257 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3258 // multisamples, which must be at least one."
3259 if (formatInfo.componentType == GL_INT ||
3260 formatInfo.componentType == GL_UNSIGNED_INT)
3261 {
3262 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3263 }
3264
3265 // GLES 3.1 section 19.3.1.
3266 if (formatCaps.texturable)
3267 {
3268 if (formatInfo.depthBits > 0)
3269 {
3270 mCaps.maxDepthTextureSamples =
3271 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3272 }
3273 else if (formatInfo.redBits > 0)
3274 {
3275 mCaps.maxColorTextureSamples =
3276 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3277 }
3278 }
3279 }
3280 }
Geoff Langd87878e2014-09-19 15:42:59 -04003281
3282 if (formatCaps.texturable && formatInfo.compressed)
3283 {
Geoff Langca271392017-04-05 12:30:00 -04003284 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003285 }
3286
Geoff Langca271392017-04-05 12:30:00 -04003287 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003288 }
Jamie Madill32447362017-06-28 14:53:52 -04003289
3290 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003291 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003292 {
3293 mMemoryProgramCache = nullptr;
3294 }
Corentin Walleze4477002017-12-01 14:39:58 -05003295
3296 // Compute which buffer types are allowed
3297 mValidBufferBindings.reset();
3298 mValidBufferBindings.set(BufferBinding::ElementArray);
3299 mValidBufferBindings.set(BufferBinding::Array);
3300
3301 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3302 {
3303 mValidBufferBindings.set(BufferBinding::PixelPack);
3304 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3305 }
3306
3307 if (getClientVersion() >= ES_3_0)
3308 {
3309 mValidBufferBindings.set(BufferBinding::CopyRead);
3310 mValidBufferBindings.set(BufferBinding::CopyWrite);
3311 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3312 mValidBufferBindings.set(BufferBinding::Uniform);
3313 }
3314
3315 if (getClientVersion() >= ES_3_1)
3316 {
3317 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3318 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3319 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3320 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3321 }
Geoff Lang493daf52014-07-03 13:38:44 -04003322}
3323
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003324void Context::initWorkarounds()
3325{
Jamie Madill761b02c2017-06-23 16:27:06 -04003326 // Apply back-end workarounds.
3327 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3328
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003329 // Lose the context upon out of memory error if the application is
3330 // expecting to watch for those events.
3331 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3332}
3333
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003334Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003335{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003336 if (mGLES1Renderer)
3337 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003338 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003339 }
3340
Geoff Langa8cb2872018-03-09 16:09:40 -05003341 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003342
3343 if (isRobustResourceInitEnabled())
3344 {
3345 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3346 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3347 }
3348
Geoff Langa8cb2872018-03-09 16:09:40 -05003349 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003350 return NoError();
3351}
3352
3353Error Context::prepareForClear(GLbitfield mask)
3354{
Geoff Langa8cb2872018-03-09 16:09:40 -05003355 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003356 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003357 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003358 return NoError();
3359}
3360
3361Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3362{
Geoff Langa8cb2872018-03-09 16:09:40 -05003363 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003364 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3365 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003366 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003367 return NoError();
3368}
3369
Geoff Langa8cb2872018-03-09 16:09:40 -05003370Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003371{
Geoff Langa8cb2872018-03-09 16:09:40 -05003372 ANGLE_TRY(syncDirtyObjects());
3373 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003374 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003375}
3376
Geoff Langa8cb2872018-03-09 16:09:40 -05003377Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003378{
Geoff Langa8cb2872018-03-09 16:09:40 -05003379 ANGLE_TRY(syncDirtyObjects(objectMask));
3380 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003381 return NoError();
3382}
3383
Geoff Langa8cb2872018-03-09 16:09:40 -05003384Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003385{
3386 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3387 mImplementation->syncState(this, dirtyBits);
3388 mGLState.clearDirtyBits();
3389 return NoError();
3390}
3391
Geoff Langa8cb2872018-03-09 16:09:40 -05003392Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003394 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003395 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003396 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003397 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003398}
Jamie Madillc29968b2016-01-20 11:17:23 -05003399
Geoff Langa8cb2872018-03-09 16:09:40 -05003400Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003401{
3402 return mGLState.syncDirtyObjects(this);
3403}
3404
Geoff Langa8cb2872018-03-09 16:09:40 -05003405Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003406{
3407 return mGLState.syncDirtyObjects(this, objectMask);
3408}
3409
Jamie Madillc29968b2016-01-20 11:17:23 -05003410void Context::blitFramebuffer(GLint srcX0,
3411 GLint srcY0,
3412 GLint srcX1,
3413 GLint srcY1,
3414 GLint dstX0,
3415 GLint dstY0,
3416 GLint dstX1,
3417 GLint dstY1,
3418 GLbitfield mask,
3419 GLenum filter)
3420{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003421 if (mask == 0)
3422 {
3423 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3424 // buffers are copied.
3425 return;
3426 }
3427
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003428 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003429 ASSERT(drawFramebuffer);
3430
3431 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3432 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3433
Jamie Madillbc918e72018-03-08 09:47:21 -05003434 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003435
Jamie Madillc564c072017-06-01 12:45:42 -04003436 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003437}
Jamie Madillc29968b2016-01-20 11:17:23 -05003438
3439void Context::clear(GLbitfield mask)
3440{
Geoff Langd4fff502017-09-22 11:28:28 -04003441 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3442 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003443}
3444
3445void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3446{
Geoff Langd4fff502017-09-22 11:28:28 -04003447 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3448 ANGLE_CONTEXT_TRY(
3449 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003450}
3451
3452void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3453{
Geoff Langd4fff502017-09-22 11:28:28 -04003454 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3455 ANGLE_CONTEXT_TRY(
3456 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003457}
3458
3459void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3460{
Geoff Langd4fff502017-09-22 11:28:28 -04003461 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3462 ANGLE_CONTEXT_TRY(
3463 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003464}
3465
3466void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3467{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003468 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003469 ASSERT(framebufferObject);
3470
3471 // If a buffer is not present, the clear has no effect
3472 if (framebufferObject->getDepthbuffer() == nullptr &&
3473 framebufferObject->getStencilbuffer() == nullptr)
3474 {
3475 return;
3476 }
3477
Geoff Langd4fff502017-09-22 11:28:28 -04003478 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3479 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003480}
3481
3482void Context::readPixels(GLint x,
3483 GLint y,
3484 GLsizei width,
3485 GLsizei height,
3486 GLenum format,
3487 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003488 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003489{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003490 if (width == 0 || height == 0)
3491 {
3492 return;
3493 }
3494
Jamie Madillbc918e72018-03-08 09:47:21 -05003495 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003496
Jamie Madillb6664922017-07-25 12:55:04 -04003497 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3498 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003499
3500 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003501 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003502}
3503
Brandon Jones59770802018-04-02 13:18:42 -07003504void Context::readPixelsRobust(GLint x,
3505 GLint y,
3506 GLsizei width,
3507 GLsizei height,
3508 GLenum format,
3509 GLenum type,
3510 GLsizei bufSize,
3511 GLsizei *length,
3512 GLsizei *columns,
3513 GLsizei *rows,
3514 void *pixels)
3515{
3516 readPixels(x, y, width, height, format, type, pixels);
3517}
3518
3519void Context::readnPixelsRobust(GLint x,
3520 GLint y,
3521 GLsizei width,
3522 GLsizei height,
3523 GLenum format,
3524 GLenum type,
3525 GLsizei bufSize,
3526 GLsizei *length,
3527 GLsizei *columns,
3528 GLsizei *rows,
3529 void *data)
3530{
3531 readPixels(x, y, width, height, format, type, data);
3532}
3533
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003534void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 GLint level,
3536 GLenum internalformat,
3537 GLint x,
3538 GLint y,
3539 GLsizei width,
3540 GLsizei height,
3541 GLint border)
3542{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003543 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003544 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003545
Jamie Madillc29968b2016-01-20 11:17:23 -05003546 Rectangle sourceArea(x, y, width, height);
3547
Jamie Madill05b35b22017-10-03 09:01:44 -04003548 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003549 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003550 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003551}
3552
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003553void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003554 GLint level,
3555 GLint xoffset,
3556 GLint yoffset,
3557 GLint x,
3558 GLint y,
3559 GLsizei width,
3560 GLsizei height)
3561{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003562 if (width == 0 || height == 0)
3563 {
3564 return;
3565 }
3566
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003567 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003568 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003569
Jamie Madillc29968b2016-01-20 11:17:23 -05003570 Offset destOffset(xoffset, yoffset, 0);
3571 Rectangle sourceArea(x, y, width, height);
3572
Jamie Madill05b35b22017-10-03 09:01:44 -04003573 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003574 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003575 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003576}
3577
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003578void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 GLint level,
3580 GLint xoffset,
3581 GLint yoffset,
3582 GLint zoffset,
3583 GLint x,
3584 GLint y,
3585 GLsizei width,
3586 GLsizei height)
3587{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003588 if (width == 0 || height == 0)
3589 {
3590 return;
3591 }
3592
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003593 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003594 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003595
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 Offset destOffset(xoffset, yoffset, zoffset);
3597 Rectangle sourceArea(x, y, width, height);
3598
Jamie Madill05b35b22017-10-03 09:01:44 -04003599 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3600 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003601 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3602 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003603}
3604
3605void Context::framebufferTexture2D(GLenum target,
3606 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003607 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 GLuint texture,
3609 GLint level)
3610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003611 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003612 ASSERT(framebuffer);
3613
3614 if (texture != 0)
3615 {
3616 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003617 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003618 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003619 }
3620 else
3621 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003622 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003623 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003624
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626}
3627
3628void Context::framebufferRenderbuffer(GLenum target,
3629 GLenum attachment,
3630 GLenum renderbuffertarget,
3631 GLuint renderbuffer)
3632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003634 ASSERT(framebuffer);
3635
3636 if (renderbuffer != 0)
3637 {
3638 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003639
Jamie Madillcc129372018-04-12 09:13:18 -04003640 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003641 renderbufferObject);
3642 }
3643 else
3644 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003645 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003646 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003647
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003649}
3650
3651void Context::framebufferTextureLayer(GLenum target,
3652 GLenum attachment,
3653 GLuint texture,
3654 GLint level,
3655 GLint layer)
3656{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003657 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003658 ASSERT(framebuffer);
3659
3660 if (texture != 0)
3661 {
3662 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003663 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003664 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003665 }
3666 else
3667 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003668 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003670
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003672}
3673
Brandon Jones59770802018-04-02 13:18:42 -07003674void Context::framebufferTextureMultiviewLayered(GLenum target,
3675 GLenum attachment,
3676 GLuint texture,
3677 GLint level,
3678 GLint baseViewIndex,
3679 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003680{
Martin Radev82ef7742017-08-08 17:44:58 +03003681 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3682 ASSERT(framebuffer);
3683
3684 if (texture != 0)
3685 {
3686 Texture *textureObj = getTexture(texture);
3687
Martin Radev18b75ba2017-08-15 15:50:40 +03003688 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003689 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3690 numViews, baseViewIndex);
3691 }
3692 else
3693 {
3694 framebuffer->resetAttachment(this, attachment);
3695 }
3696
3697 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003698}
3699
Brandon Jones59770802018-04-02 13:18:42 -07003700void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3701 GLenum attachment,
3702 GLuint texture,
3703 GLint level,
3704 GLsizei numViews,
3705 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003706{
Martin Radev5dae57b2017-07-14 16:15:55 +03003707 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3708 ASSERT(framebuffer);
3709
3710 if (texture != 0)
3711 {
3712 Texture *textureObj = getTexture(texture);
3713
3714 ImageIndex index = ImageIndex::Make2D(level);
3715 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3716 textureObj, numViews, viewportOffsets);
3717 }
3718 else
3719 {
3720 framebuffer->resetAttachment(this, attachment);
3721 }
3722
3723 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003724}
3725
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003726void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3727{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003728 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3729 ASSERT(framebuffer);
3730
3731 if (texture != 0)
3732 {
3733 Texture *textureObj = getTexture(texture);
3734
3735 ImageIndex index = ImageIndex::MakeFromType(
3736 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3737 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3738 }
3739 else
3740 {
3741 framebuffer->resetAttachment(this, attachment);
3742 }
3743
3744 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003745}
3746
Jamie Madillc29968b2016-01-20 11:17:23 -05003747void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 ASSERT(framebuffer);
3751 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003753}
3754
3755void Context::readBuffer(GLenum mode)
3756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003759 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
3762void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3763{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003764 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003765 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003766
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003767 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003768 ASSERT(framebuffer);
3769
3770 // The specification isn't clear what should be done when the framebuffer isn't complete.
3771 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003772 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003773}
3774
3775void Context::invalidateFramebuffer(GLenum target,
3776 GLsizei numAttachments,
3777 const GLenum *attachments)
3778{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003779 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003780 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003781
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003782 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003783 ASSERT(framebuffer);
3784
Jamie Madill427064d2018-04-13 16:20:34 -04003785 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003786 {
Jamie Madill437fa652016-05-03 15:13:24 -04003787 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003788 }
Jamie Madill437fa652016-05-03 15:13:24 -04003789
Jamie Madill4928b7c2017-06-20 12:57:39 -04003790 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003791}
3792
3793void Context::invalidateSubFramebuffer(GLenum target,
3794 GLsizei numAttachments,
3795 const GLenum *attachments,
3796 GLint x,
3797 GLint y,
3798 GLsizei width,
3799 GLsizei height)
3800{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003801 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003802 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003803
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003805 ASSERT(framebuffer);
3806
Jamie Madill427064d2018-04-13 16:20:34 -04003807 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003808 {
Jamie Madill437fa652016-05-03 15:13:24 -04003809 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003810 }
Jamie Madill437fa652016-05-03 15:13:24 -04003811
3812 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003813 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003814}
3815
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003816void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003817 GLint level,
3818 GLint internalformat,
3819 GLsizei width,
3820 GLsizei height,
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, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003829 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003830 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003831 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003832}
3833
Brandon Jones59770802018-04-02 13:18:42 -07003834void Context::texImage2DRobust(TextureTarget target,
3835 GLint level,
3836 GLint internalformat,
3837 GLsizei width,
3838 GLsizei height,
3839 GLint border,
3840 GLenum format,
3841 GLenum type,
3842 GLsizei bufSize,
3843 const void *pixels)
3844{
3845 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3846}
3847
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003848void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003849 GLint level,
3850 GLint internalformat,
3851 GLsizei width,
3852 GLsizei height,
3853 GLsizei depth,
3854 GLint border,
3855 GLenum format,
3856 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003857 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003858{
Jamie Madillbc918e72018-03-08 09:47:21 -05003859 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003860
3861 Extents size(width, height, depth);
3862 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003863 handleError(texture->setImage(this, mGLState.getUnpackState(),
3864 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003865 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003866}
3867
Brandon Jones59770802018-04-02 13:18:42 -07003868void Context::texImage3DRobust(TextureType target,
3869 GLint level,
3870 GLint internalformat,
3871 GLsizei width,
3872 GLsizei height,
3873 GLsizei depth,
3874 GLint border,
3875 GLenum format,
3876 GLenum type,
3877 GLsizei bufSize,
3878 const void *pixels)
3879{
3880 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3881}
3882
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003883void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003884 GLint level,
3885 GLint xoffset,
3886 GLint yoffset,
3887 GLsizei width,
3888 GLsizei height,
3889 GLenum format,
3890 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003891 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003892{
3893 // Zero sized uploads are valid but no-ops
3894 if (width == 0 || height == 0)
3895 {
3896 return;
3897 }
3898
Jamie Madillbc918e72018-03-08 09:47:21 -05003899 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003900
3901 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003902 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003903 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003904 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003905}
3906
Brandon Jones59770802018-04-02 13:18:42 -07003907void Context::texSubImage2DRobust(TextureTarget target,
3908 GLint level,
3909 GLint xoffset,
3910 GLint yoffset,
3911 GLsizei width,
3912 GLsizei height,
3913 GLenum format,
3914 GLenum type,
3915 GLsizei bufSize,
3916 const void *pixels)
3917{
3918 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3919}
3920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003921void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003922 GLint level,
3923 GLint xoffset,
3924 GLint yoffset,
3925 GLint zoffset,
3926 GLsizei width,
3927 GLsizei height,
3928 GLsizei depth,
3929 GLenum format,
3930 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003931 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003932{
3933 // Zero sized uploads are valid but no-ops
3934 if (width == 0 || height == 0 || depth == 0)
3935 {
3936 return;
3937 }
3938
Jamie Madillbc918e72018-03-08 09:47:21 -05003939 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003940
3941 Box area(xoffset, yoffset, zoffset, width, height, depth);
3942 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003943 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3944 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003945 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003946}
3947
Brandon Jones59770802018-04-02 13:18:42 -07003948void Context::texSubImage3DRobust(TextureType target,
3949 GLint level,
3950 GLint xoffset,
3951 GLint yoffset,
3952 GLint zoffset,
3953 GLsizei width,
3954 GLsizei height,
3955 GLsizei depth,
3956 GLenum format,
3957 GLenum type,
3958 GLsizei bufSize,
3959 const void *pixels)
3960{
3961 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3962 pixels);
3963}
3964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003966 GLint level,
3967 GLenum internalformat,
3968 GLsizei width,
3969 GLsizei height,
3970 GLint border,
3971 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003972 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003973{
Jamie Madillbc918e72018-03-08 09:47:21 -05003974 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003975
3976 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003977 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003978 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3979 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003980 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003981}
3982
Brandon Jones59770802018-04-02 13:18:42 -07003983void Context::compressedTexImage2DRobust(TextureTarget target,
3984 GLint level,
3985 GLenum internalformat,
3986 GLsizei width,
3987 GLsizei height,
3988 GLint border,
3989 GLsizei imageSize,
3990 GLsizei dataSize,
3991 const GLvoid *data)
3992{
3993 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3994}
3995
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003996void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003997 GLint level,
3998 GLenum internalformat,
3999 GLsizei width,
4000 GLsizei height,
4001 GLsizei depth,
4002 GLint border,
4003 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004004 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004005{
Jamie Madillbc918e72018-03-08 09:47:21 -05004006 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004007
4008 Extents size(width, height, depth);
4009 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004010 handleError(texture->setCompressedImage(
4011 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004012 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004013}
4014
Brandon Jones59770802018-04-02 13:18:42 -07004015void Context::compressedTexImage3DRobust(TextureType target,
4016 GLint level,
4017 GLenum internalformat,
4018 GLsizei width,
4019 GLsizei height,
4020 GLsizei depth,
4021 GLint border,
4022 GLsizei imageSize,
4023 GLsizei dataSize,
4024 const GLvoid *data)
4025{
4026 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4027 data);
4028}
4029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004030void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004031 GLint level,
4032 GLint xoffset,
4033 GLint yoffset,
4034 GLsizei width,
4035 GLsizei height,
4036 GLenum format,
4037 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004038 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004039{
Jamie Madillbc918e72018-03-08 09:47:21 -05004040 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004041
4042 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004043 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004044 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4045 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004046 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004047}
4048
Brandon Jones59770802018-04-02 13:18:42 -07004049void Context::compressedTexSubImage2DRobust(TextureTarget target,
4050 GLint level,
4051 GLint xoffset,
4052 GLint yoffset,
4053 GLsizei width,
4054 GLsizei height,
4055 GLenum format,
4056 GLsizei imageSize,
4057 GLsizei dataSize,
4058 const GLvoid *data)
4059{
4060 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4061 data);
4062}
4063
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004064void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004065 GLint level,
4066 GLint xoffset,
4067 GLint yoffset,
4068 GLint zoffset,
4069 GLsizei width,
4070 GLsizei height,
4071 GLsizei depth,
4072 GLenum format,
4073 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004074 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004075{
4076 // Zero sized uploads are valid but no-ops
4077 if (width == 0 || height == 0)
4078 {
4079 return;
4080 }
4081
Jamie Madillbc918e72018-03-08 09:47:21 -05004082 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004083
4084 Box area(xoffset, yoffset, zoffset, width, height, depth);
4085 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004086 handleError(texture->setCompressedSubImage(
4087 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004088 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004089}
4090
Brandon Jones59770802018-04-02 13:18:42 -07004091void Context::compressedTexSubImage3DRobust(TextureType target,
4092 GLint level,
4093 GLint xoffset,
4094 GLint yoffset,
4095 GLint zoffset,
4096 GLsizei width,
4097 GLsizei height,
4098 GLsizei depth,
4099 GLenum format,
4100 GLsizei imageSize,
4101 GLsizei dataSize,
4102 const GLvoid *data)
4103{
4104 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4105 imageSize, data);
4106}
4107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004108void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004109{
4110 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004111 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004112}
4113
Jamie Madill007530e2017-12-28 14:27:04 -05004114void Context::copyTexture(GLuint sourceId,
4115 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004116 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004117 GLuint destId,
4118 GLint destLevel,
4119 GLint internalFormat,
4120 GLenum destType,
4121 GLboolean unpackFlipY,
4122 GLboolean unpackPremultiplyAlpha,
4123 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004124{
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004126
4127 gl::Texture *sourceTexture = getTexture(sourceId);
4128 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004129 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4130 sourceLevel, 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::copySubTexture(GLuint sourceId,
4136 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004137 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004138 GLuint destId,
4139 GLint destLevel,
4140 GLint xoffset,
4141 GLint yoffset,
4142 GLint x,
4143 GLint y,
4144 GLsizei width,
4145 GLsizei height,
4146 GLboolean unpackFlipY,
4147 GLboolean unpackPremultiplyAlpha,
4148 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004149{
4150 // Zero sized copies are valid but no-ops
4151 if (width == 0 || height == 0)
4152 {
4153 return;
4154 }
4155
Jamie Madillbc918e72018-03-08 09:47:21 -05004156 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004157
4158 gl::Texture *sourceTexture = getTexture(sourceId);
4159 gl::Texture *destTexture = getTexture(destId);
4160 Offset offset(xoffset, yoffset, 0);
4161 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004162 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4163 ConvertToBool(unpackFlipY),
4164 ConvertToBool(unpackPremultiplyAlpha),
4165 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004166}
4167
Jamie Madill007530e2017-12-28 14:27:04 -05004168void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004169{
Jamie Madillbc918e72018-03-08 09:47:21 -05004170 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004171
4172 gl::Texture *sourceTexture = getTexture(sourceId);
4173 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004174 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004175}
4176
Corentin Wallez336129f2017-10-17 15:55:40 -04004177void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004178{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004179 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 ASSERT(buffer);
4181
Geoff Lang496c02d2016-10-20 11:38:11 -07004182 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183}
4184
Brandon Jones59770802018-04-02 13:18:42 -07004185void Context::getBufferPointervRobust(BufferBinding target,
4186 GLenum pname,
4187 GLsizei bufSize,
4188 GLsizei *length,
4189 void **params)
4190{
4191 getBufferPointerv(target, pname, params);
4192}
4193
Corentin Wallez336129f2017-10-17 15:55:40 -04004194void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004195{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004196 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004197 ASSERT(buffer);
4198
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004199 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004200 if (error.isError())
4201 {
Jamie Madill437fa652016-05-03 15:13:24 -04004202 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004203 return nullptr;
4204 }
4205
4206 return buffer->getMapPointer();
4207}
4208
Corentin Wallez336129f2017-10-17 15:55:40 -04004209GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004210{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004211 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004212 ASSERT(buffer);
4213
4214 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004215 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004216 if (error.isError())
4217 {
Jamie Madill437fa652016-05-03 15:13:24 -04004218 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004219 return GL_FALSE;
4220 }
4221
4222 return result;
4223}
4224
Corentin Wallez336129f2017-10-17 15:55:40 -04004225void *Context::mapBufferRange(BufferBinding target,
4226 GLintptr offset,
4227 GLsizeiptr length,
4228 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004229{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004230 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004231 ASSERT(buffer);
4232
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004233 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004234 if (error.isError())
4235 {
Jamie Madill437fa652016-05-03 15:13:24 -04004236 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004237 return nullptr;
4238 }
4239
4240 return buffer->getMapPointer();
4241}
4242
Corentin Wallez336129f2017-10-17 15:55:40 -04004243void Context::flushMappedBufferRange(BufferBinding /*target*/,
4244 GLintptr /*offset*/,
4245 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004246{
4247 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4248}
4249
Jamie Madillbc918e72018-03-08 09:47:21 -05004250Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004251{
Geoff Langa8cb2872018-03-09 16:09:40 -05004252 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004253}
4254
Jamie Madillbc918e72018-03-08 09:47:21 -05004255Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004256{
Geoff Langa8cb2872018-03-09 16:09:40 -05004257 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004258}
4259
Jamie Madillbc918e72018-03-08 09:47:21 -05004260Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004261{
Geoff Langa8cb2872018-03-09 16:09:40 -05004262 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004263}
4264
Jiajia Qin5451d532017-11-16 17:16:34 +08004265void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4266{
4267 UNIMPLEMENTED();
4268}
4269
Jamie Madillc20ab272016-06-09 07:20:46 -07004270void Context::activeTexture(GLenum texture)
4271{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004273}
4274
Jamie Madill876429b2017-04-20 15:46:24 -04004275void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004276{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004278}
4279
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004280void Context::blendEquation(GLenum mode)
4281{
4282 mGLState.setBlendEquation(mode, mode);
4283}
4284
Jamie Madillc20ab272016-06-09 07:20:46 -07004285void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4286{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004287 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004288}
4289
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004290void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4291{
4292 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4293}
4294
Jamie Madillc20ab272016-06-09 07:20:46 -07004295void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4296{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004297 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004298}
4299
Jamie Madill876429b2017-04-20 15:46:24 -04004300void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004301{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004303}
4304
Jamie Madill876429b2017-04-20 15:46:24 -04004305void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004307 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004308}
4309
4310void Context::clearStencil(GLint s)
4311{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004312 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004313}
4314
4315void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4316{
Geoff Lang92019432017-11-20 13:09:34 -05004317 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4318 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004319}
4320
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004321void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004322{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324}
4325
4326void Context::depthFunc(GLenum func)
4327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329}
4330
4331void Context::depthMask(GLboolean flag)
4332{
Geoff Lang92019432017-11-20 13:09:34 -05004333 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004334}
4335
Jamie Madill876429b2017-04-20 15:46:24 -04004336void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339}
4340
4341void Context::disable(GLenum cap)
4342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344}
4345
4346void Context::disableVertexAttribArray(GLuint index)
4347{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349}
4350
4351void Context::enable(GLenum cap)
4352{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354}
4355
4356void Context::enableVertexAttribArray(GLuint index)
4357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359}
4360
4361void Context::frontFace(GLenum mode)
4362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364}
4365
4366void Context::hint(GLenum target, GLenum mode)
4367{
4368 switch (target)
4369 {
4370 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004371 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004372 break;
4373
4374 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376 break;
4377
4378 default:
4379 UNREACHABLE();
4380 return;
4381 }
4382}
4383
4384void Context::lineWidth(GLfloat width)
4385{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387}
4388
4389void Context::pixelStorei(GLenum pname, GLint param)
4390{
4391 switch (pname)
4392 {
4393 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 break;
4396
4397 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004398 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004399 break;
4400
4401 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403 break;
4404
4405 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004406 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408 break;
4409
4410 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004411 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413 break;
4414
4415 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004416 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418 break;
4419
4420 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004421 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004422 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004423 break;
4424
4425 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004426 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004427 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428 break;
4429
4430 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004431 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004432 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004433 break;
4434
4435 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004436 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438 break;
4439
4440 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004441 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 break;
4444
4445 default:
4446 UNREACHABLE();
4447 return;
4448 }
4449}
4450
4451void Context::polygonOffset(GLfloat factor, GLfloat units)
4452{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454}
4455
Jamie Madill876429b2017-04-20 15:46:24 -04004456void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004457{
Geoff Lang92019432017-11-20 13:09:34 -05004458 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004459}
4460
Jiawei Shaodb342272017-09-27 10:21:45 +08004461void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4462{
4463 mGLState.setSampleMaskParams(maskNumber, mask);
4464}
4465
Jamie Madillc20ab272016-06-09 07:20:46 -07004466void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4467{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004469}
4470
4471void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4472{
4473 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4474 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476 }
4477
4478 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4479 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481 }
4482}
4483
4484void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4485{
4486 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4487 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489 }
4490
4491 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4492 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494 }
4495}
4496
4497void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4498{
4499 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4500 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004501 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502 }
4503
4504 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4505 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507 }
4508}
4509
4510void Context::vertexAttrib1f(GLuint index, GLfloat x)
4511{
4512 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514}
4515
4516void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4517{
4518 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004519 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004520}
4521
4522void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4523{
4524 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004525 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004526}
4527
4528void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4529{
4530 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532}
4533
4534void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4535{
4536 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538}
4539
4540void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4541{
4542 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004543 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004544}
4545
4546void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4547{
4548 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550}
4551
4552void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4553{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::vertexAttribPointer(GLuint index,
4558 GLint size,
4559 GLenum type,
4560 GLboolean normalized,
4561 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004562 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004563{
Corentin Wallez336129f2017-10-17 15:55:40 -04004564 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004565 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566}
4567
Shao80957d92017-02-20 21:25:59 +08004568void Context::vertexAttribFormat(GLuint attribIndex,
4569 GLint size,
4570 GLenum type,
4571 GLboolean normalized,
4572 GLuint relativeOffset)
4573{
Geoff Lang92019432017-11-20 13:09:34 -05004574 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004575 relativeOffset);
4576}
4577
4578void Context::vertexAttribIFormat(GLuint attribIndex,
4579 GLint size,
4580 GLenum type,
4581 GLuint relativeOffset)
4582{
4583 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4584}
4585
4586void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4587{
Shaodde78e82017-05-22 14:13:27 +08004588 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004589}
4590
Jiajia Qin5451d532017-11-16 17:16:34 +08004591void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004592{
4593 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4594}
4595
Jamie Madillc20ab272016-06-09 07:20:46 -07004596void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004598 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
4601void Context::vertexAttribIPointer(GLuint index,
4602 GLint size,
4603 GLenum type,
4604 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004605 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004606{
Corentin Wallez336129f2017-10-17 15:55:40 -04004607 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4608 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4612{
4613 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004614 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615}
4616
4617void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4618{
4619 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004620 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
4623void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626}
4627
4628void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631}
4632
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004633void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4634{
4635 const VertexAttribCurrentValueData &currentValues =
4636 getGLState().getVertexAttribCurrentValue(index);
4637 const VertexArray *vao = getGLState().getVertexArray();
4638 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4639 currentValues, pname, params);
4640}
4641
Brandon Jones59770802018-04-02 13:18:42 -07004642void Context::getVertexAttribivRobust(GLuint index,
4643 GLenum pname,
4644 GLsizei bufSize,
4645 GLsizei *length,
4646 GLint *params)
4647{
4648 getVertexAttribiv(index, pname, params);
4649}
4650
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004651void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4652{
4653 const VertexAttribCurrentValueData &currentValues =
4654 getGLState().getVertexAttribCurrentValue(index);
4655 const VertexArray *vao = getGLState().getVertexArray();
4656 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4657 currentValues, pname, params);
4658}
4659
Brandon Jones59770802018-04-02 13:18:42 -07004660void Context::getVertexAttribfvRobust(GLuint index,
4661 GLenum pname,
4662 GLsizei bufSize,
4663 GLsizei *length,
4664 GLfloat *params)
4665{
4666 getVertexAttribfv(index, pname, params);
4667}
4668
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004669void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4670{
4671 const VertexAttribCurrentValueData &currentValues =
4672 getGLState().getVertexAttribCurrentValue(index);
4673 const VertexArray *vao = getGLState().getVertexArray();
4674 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4675 currentValues, pname, params);
4676}
4677
Brandon Jones59770802018-04-02 13:18:42 -07004678void Context::getVertexAttribIivRobust(GLuint index,
4679 GLenum pname,
4680 GLsizei bufSize,
4681 GLsizei *length,
4682 GLint *params)
4683{
4684 getVertexAttribIiv(index, pname, params);
4685}
4686
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004687void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4688{
4689 const VertexAttribCurrentValueData &currentValues =
4690 getGLState().getVertexAttribCurrentValue(index);
4691 const VertexArray *vao = getGLState().getVertexArray();
4692 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4693 currentValues, pname, params);
4694}
4695
Brandon Jones59770802018-04-02 13:18:42 -07004696void Context::getVertexAttribIuivRobust(GLuint index,
4697 GLenum pname,
4698 GLsizei bufSize,
4699 GLsizei *length,
4700 GLuint *params)
4701{
4702 getVertexAttribIuiv(index, pname, params);
4703}
4704
Jamie Madill876429b2017-04-20 15:46:24 -04004705void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004706{
4707 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4708 QueryVertexAttribPointerv(attrib, pname, pointer);
4709}
4710
Brandon Jones59770802018-04-02 13:18:42 -07004711void Context::getVertexAttribPointervRobust(GLuint index,
4712 GLenum pname,
4713 GLsizei bufSize,
4714 GLsizei *length,
4715 void **pointer)
4716{
4717 getVertexAttribPointerv(index, pname, pointer);
4718}
4719
Jamie Madillc20ab272016-06-09 07:20:46 -07004720void Context::debugMessageControl(GLenum source,
4721 GLenum type,
4722 GLenum severity,
4723 GLsizei count,
4724 const GLuint *ids,
4725 GLboolean enabled)
4726{
4727 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004728 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004729 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004730}
4731
4732void Context::debugMessageInsert(GLenum source,
4733 GLenum type,
4734 GLuint id,
4735 GLenum severity,
4736 GLsizei length,
4737 const GLchar *buf)
4738{
4739 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004740 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004741}
4742
4743void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004745 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748GLuint Context::getDebugMessageLog(GLuint count,
4749 GLsizei bufSize,
4750 GLenum *sources,
4751 GLenum *types,
4752 GLuint *ids,
4753 GLenum *severities,
4754 GLsizei *lengths,
4755 GLchar *messageLog)
4756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004757 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4758 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004759}
4760
4761void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4762{
4763 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004764 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004765 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004766}
4767
4768void Context::popDebugGroup()
4769{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004770 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004771 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004772}
4773
Corentin Wallez336129f2017-10-17 15:55:40 -04004774void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004775{
4776 Buffer *buffer = mGLState.getTargetBuffer(target);
4777 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004778 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004779}
4780
Corentin Wallez336129f2017-10-17 15:55:40 -04004781void Context::bufferSubData(BufferBinding target,
4782 GLintptr offset,
4783 GLsizeiptr size,
4784 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004785{
4786 if (data == nullptr)
4787 {
4788 return;
4789 }
4790
4791 Buffer *buffer = mGLState.getTargetBuffer(target);
4792 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004793 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004794}
4795
Jamie Madillef300b12016-10-07 15:12:09 -04004796void Context::attachShader(GLuint program, GLuint shader)
4797{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004798 Program *programObject = mState.mShaderPrograms->getProgram(program);
4799 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004800 ASSERT(programObject && shaderObject);
4801 programObject->attachShader(shaderObject);
4802}
4803
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004804const Workarounds &Context::getWorkarounds() const
4805{
4806 return mWorkarounds;
4807}
4808
Corentin Wallez336129f2017-10-17 15:55:40 -04004809void Context::copyBufferSubData(BufferBinding readTarget,
4810 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004811 GLintptr readOffset,
4812 GLintptr writeOffset,
4813 GLsizeiptr size)
4814{
4815 // if size is zero, the copy is a successful no-op
4816 if (size == 0)
4817 {
4818 return;
4819 }
4820
4821 // TODO(jmadill): cache these.
4822 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4823 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4824
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004825 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004826}
4827
Jamie Madill01a80ee2016-11-07 12:06:18 -05004828void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4829{
4830 Program *programObject = getProgram(program);
4831 // TODO(jmadill): Re-use this from the validation if possible.
4832 ASSERT(programObject);
4833 programObject->bindAttributeLocation(index, name);
4834}
4835
Corentin Wallez336129f2017-10-17 15:55:40 -04004836void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004837{
Corentin Wallez336129f2017-10-17 15:55:40 -04004838 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4839 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004840}
4841
Corentin Wallez336129f2017-10-17 15:55:40 -04004842void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004843{
4844 bindBufferRange(target, index, buffer, 0, 0);
4845}
4846
Corentin Wallez336129f2017-10-17 15:55:40 -04004847void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004848 GLuint index,
4849 GLuint buffer,
4850 GLintptr offset,
4851 GLsizeiptr size)
4852{
Corentin Wallez336129f2017-10-17 15:55:40 -04004853 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4854 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004855}
4856
Jamie Madill01a80ee2016-11-07 12:06:18 -05004857void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4858{
4859 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4860 {
4861 bindReadFramebuffer(framebuffer);
4862 }
4863
4864 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4865 {
4866 bindDrawFramebuffer(framebuffer);
4867 }
4868}
4869
4870void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4871{
4872 ASSERT(target == GL_RENDERBUFFER);
4873 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004874 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004875 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004876}
4877
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004878void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004879 GLsizei samples,
4880 GLenum internalformat,
4881 GLsizei width,
4882 GLsizei height,
4883 GLboolean fixedsamplelocations)
4884{
4885 Extents size(width, height, 1);
4886 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004887 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4888 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004889}
4890
4891void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4892{
JiangYizhou5b03f472017-01-09 10:22:53 +08004893 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4894 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004895 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004896 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004897
4898 switch (pname)
4899 {
4900 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004901 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004902 break;
4903 default:
4904 UNREACHABLE();
4905 }
4906}
4907
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004908void Context::getMultisamplefvRobust(GLenum pname,
4909 GLuint index,
4910 GLsizei bufSize,
4911 GLsizei *length,
4912 GLfloat *val)
4913{
4914 UNIMPLEMENTED();
4915}
4916
Jamie Madille8fb6402017-02-14 17:56:40 -05004917void Context::renderbufferStorage(GLenum target,
4918 GLenum internalformat,
4919 GLsizei width,
4920 GLsizei height)
4921{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004922 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4923 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4924
Jamie Madille8fb6402017-02-14 17:56:40 -05004925 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004926 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004927}
4928
4929void Context::renderbufferStorageMultisample(GLenum target,
4930 GLsizei samples,
4931 GLenum internalformat,
4932 GLsizei width,
4933 GLsizei height)
4934{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004935 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4936 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004937
4938 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004939 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004940 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004941}
4942
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004943void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4944{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004945 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004946 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004947}
4948
JiangYizhoue18e6392017-02-20 10:32:23 +08004949void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4950{
4951 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4952 QueryFramebufferParameteriv(framebuffer, pname, params);
4953}
4954
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004955void Context::getFramebufferParameterivRobust(GLenum target,
4956 GLenum pname,
4957 GLsizei bufSize,
4958 GLsizei *length,
4959 GLint *params)
4960{
4961 UNIMPLEMENTED();
4962}
4963
Jiajia Qin5451d532017-11-16 17:16:34 +08004964void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004965{
4966 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4967 SetFramebufferParameteri(framebuffer, pname, param);
4968}
4969
Jamie Madillb3f26b92017-07-19 15:07:41 -04004970Error Context::getScratchBuffer(size_t requstedSizeBytes,
4971 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004972{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004973 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4974 {
4975 return OutOfMemory() << "Failed to allocate internal buffer.";
4976 }
4977 return NoError();
4978}
4979
4980Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4981 angle::MemoryBuffer **zeroBufferOut) const
4982{
4983 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004984 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004985 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004986 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004987 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004988}
4989
Xinghua Cao10a4d432017-11-28 14:46:26 +08004990Error Context::prepareForDispatch()
4991{
Geoff Langa8cb2872018-03-09 16:09:40 -05004992 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004993
4994 if (isRobustResourceInitEnabled())
4995 {
4996 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4997 }
4998
4999 return NoError();
5000}
5001
Xinghua Cao2b396592017-03-29 15:36:04 +08005002void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5003{
5004 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5005 {
5006 return;
5007 }
5008
Xinghua Cao10a4d432017-11-28 14:46:26 +08005009 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005010 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005011}
5012
Jiajia Qin5451d532017-11-16 17:16:34 +08005013void Context::dispatchComputeIndirect(GLintptr indirect)
5014{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005015 ANGLE_CONTEXT_TRY(prepareForDispatch());
5016 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005017}
5018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005019void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005020 GLsizei levels,
5021 GLenum internalFormat,
5022 GLsizei width,
5023 GLsizei height)
5024{
5025 Extents size(width, height, 1);
5026 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005027 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005028}
5029
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005030void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005031 GLsizei levels,
5032 GLenum internalFormat,
5033 GLsizei width,
5034 GLsizei height,
5035 GLsizei depth)
5036{
5037 Extents size(width, height, depth);
5038 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005039 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005040}
5041
Jiajia Qin5451d532017-11-16 17:16:34 +08005042void Context::memoryBarrier(GLbitfield barriers)
5043{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005044 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005045}
5046
5047void Context::memoryBarrierByRegion(GLbitfield barriers)
5048{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005049 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005050}
5051
Jamie Madillc1d770e2017-04-13 17:31:24 -04005052GLenum Context::checkFramebufferStatus(GLenum target)
5053{
5054 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5055 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005056 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005057}
5058
5059void Context::compileShader(GLuint shader)
5060{
5061 Shader *shaderObject = GetValidShader(this, shader);
5062 if (!shaderObject)
5063 {
5064 return;
5065 }
5066 shaderObject->compile(this);
5067}
5068
5069void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5070{
5071 for (int i = 0; i < n; i++)
5072 {
5073 deleteBuffer(buffers[i]);
5074 }
5075}
5076
5077void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5078{
5079 for (int i = 0; i < n; i++)
5080 {
5081 if (framebuffers[i] != 0)
5082 {
5083 deleteFramebuffer(framebuffers[i]);
5084 }
5085 }
5086}
5087
5088void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5089{
5090 for (int i = 0; i < n; i++)
5091 {
5092 deleteRenderbuffer(renderbuffers[i]);
5093 }
5094}
5095
5096void Context::deleteTextures(GLsizei n, const GLuint *textures)
5097{
5098 for (int i = 0; i < n; i++)
5099 {
5100 if (textures[i] != 0)
5101 {
5102 deleteTexture(textures[i]);
5103 }
5104 }
5105}
5106
5107void Context::detachShader(GLuint program, GLuint shader)
5108{
5109 Program *programObject = getProgram(program);
5110 ASSERT(programObject);
5111
5112 Shader *shaderObject = getShader(shader);
5113 ASSERT(shaderObject);
5114
5115 programObject->detachShader(this, shaderObject);
5116}
5117
5118void Context::genBuffers(GLsizei n, GLuint *buffers)
5119{
5120 for (int i = 0; i < n; i++)
5121 {
5122 buffers[i] = createBuffer();
5123 }
5124}
5125
5126void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5127{
5128 for (int i = 0; i < n; i++)
5129 {
5130 framebuffers[i] = createFramebuffer();
5131 }
5132}
5133
5134void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5135{
5136 for (int i = 0; i < n; i++)
5137 {
5138 renderbuffers[i] = createRenderbuffer();
5139 }
5140}
5141
5142void Context::genTextures(GLsizei n, GLuint *textures)
5143{
5144 for (int i = 0; i < n; i++)
5145 {
5146 textures[i] = createTexture();
5147 }
5148}
5149
5150void Context::getActiveAttrib(GLuint program,
5151 GLuint index,
5152 GLsizei bufsize,
5153 GLsizei *length,
5154 GLint *size,
5155 GLenum *type,
5156 GLchar *name)
5157{
5158 Program *programObject = getProgram(program);
5159 ASSERT(programObject);
5160 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5161}
5162
5163void Context::getActiveUniform(GLuint program,
5164 GLuint index,
5165 GLsizei bufsize,
5166 GLsizei *length,
5167 GLint *size,
5168 GLenum *type,
5169 GLchar *name)
5170{
5171 Program *programObject = getProgram(program);
5172 ASSERT(programObject);
5173 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5174}
5175
5176void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5177{
5178 Program *programObject = getProgram(program);
5179 ASSERT(programObject);
5180 programObject->getAttachedShaders(maxcount, count, shaders);
5181}
5182
5183GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5184{
5185 Program *programObject = getProgram(program);
5186 ASSERT(programObject);
5187 return programObject->getAttributeLocation(name);
5188}
5189
5190void Context::getBooleanv(GLenum pname, GLboolean *params)
5191{
5192 GLenum nativeType;
5193 unsigned int numParams = 0;
5194 getQueryParameterInfo(pname, &nativeType, &numParams);
5195
5196 if (nativeType == GL_BOOL)
5197 {
5198 getBooleanvImpl(pname, params);
5199 }
5200 else
5201 {
5202 CastStateValues(this, nativeType, pname, numParams, params);
5203 }
5204}
5205
Brandon Jones59770802018-04-02 13:18:42 -07005206void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5207{
5208 getBooleanv(pname, params);
5209}
5210
Jamie Madillc1d770e2017-04-13 17:31:24 -04005211void Context::getFloatv(GLenum pname, GLfloat *params)
5212{
5213 GLenum nativeType;
5214 unsigned int numParams = 0;
5215 getQueryParameterInfo(pname, &nativeType, &numParams);
5216
5217 if (nativeType == GL_FLOAT)
5218 {
5219 getFloatvImpl(pname, params);
5220 }
5221 else
5222 {
5223 CastStateValues(this, nativeType, pname, numParams, params);
5224 }
5225}
5226
Brandon Jones59770802018-04-02 13:18:42 -07005227void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5228{
5229 getFloatv(pname, params);
5230}
5231
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232void Context::getIntegerv(GLenum pname, GLint *params)
5233{
5234 GLenum nativeType;
5235 unsigned int numParams = 0;
5236 getQueryParameterInfo(pname, &nativeType, &numParams);
5237
5238 if (nativeType == GL_INT)
5239 {
5240 getIntegervImpl(pname, params);
5241 }
5242 else
5243 {
5244 CastStateValues(this, nativeType, pname, numParams, params);
5245 }
5246}
5247
Brandon Jones59770802018-04-02 13:18:42 -07005248void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5249{
5250 getIntegerv(pname, data);
5251}
5252
Jamie Madillc1d770e2017-04-13 17:31:24 -04005253void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5254{
5255 Program *programObject = getProgram(program);
5256 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005257 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005258}
5259
Brandon Jones59770802018-04-02 13:18:42 -07005260void Context::getProgramivRobust(GLuint program,
5261 GLenum pname,
5262 GLsizei bufSize,
5263 GLsizei *length,
5264 GLint *params)
5265{
5266 getProgramiv(program, pname, params);
5267}
5268
Jiajia Qin5451d532017-11-16 17:16:34 +08005269void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5270{
5271 UNIMPLEMENTED();
5272}
5273
Jamie Madillbe849e42017-05-02 15:49:00 -04005274void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005275{
5276 Program *programObject = getProgram(program);
5277 ASSERT(programObject);
5278 programObject->getInfoLog(bufsize, length, infolog);
5279}
5280
Jiajia Qin5451d532017-11-16 17:16:34 +08005281void Context::getProgramPipelineInfoLog(GLuint pipeline,
5282 GLsizei bufSize,
5283 GLsizei *length,
5284 GLchar *infoLog)
5285{
5286 UNIMPLEMENTED();
5287}
5288
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5290{
5291 Shader *shaderObject = getShader(shader);
5292 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005293 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005294}
5295
Brandon Jones59770802018-04-02 13:18:42 -07005296void Context::getShaderivRobust(GLuint shader,
5297 GLenum pname,
5298 GLsizei bufSize,
5299 GLsizei *length,
5300 GLint *params)
5301{
5302 getShaderiv(shader, pname, params);
5303}
5304
Jamie Madillc1d770e2017-04-13 17:31:24 -04005305void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5306{
5307 Shader *shaderObject = getShader(shader);
5308 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005309 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005310}
5311
5312void Context::getShaderPrecisionFormat(GLenum shadertype,
5313 GLenum precisiontype,
5314 GLint *range,
5315 GLint *precision)
5316{
5317 // TODO(jmadill): Compute shaders.
5318
5319 switch (shadertype)
5320 {
5321 case GL_VERTEX_SHADER:
5322 switch (precisiontype)
5323 {
5324 case GL_LOW_FLOAT:
5325 mCaps.vertexLowpFloat.get(range, precision);
5326 break;
5327 case GL_MEDIUM_FLOAT:
5328 mCaps.vertexMediumpFloat.get(range, precision);
5329 break;
5330 case GL_HIGH_FLOAT:
5331 mCaps.vertexHighpFloat.get(range, precision);
5332 break;
5333
5334 case GL_LOW_INT:
5335 mCaps.vertexLowpInt.get(range, precision);
5336 break;
5337 case GL_MEDIUM_INT:
5338 mCaps.vertexMediumpInt.get(range, precision);
5339 break;
5340 case GL_HIGH_INT:
5341 mCaps.vertexHighpInt.get(range, precision);
5342 break;
5343
5344 default:
5345 UNREACHABLE();
5346 return;
5347 }
5348 break;
5349
5350 case GL_FRAGMENT_SHADER:
5351 switch (precisiontype)
5352 {
5353 case GL_LOW_FLOAT:
5354 mCaps.fragmentLowpFloat.get(range, precision);
5355 break;
5356 case GL_MEDIUM_FLOAT:
5357 mCaps.fragmentMediumpFloat.get(range, precision);
5358 break;
5359 case GL_HIGH_FLOAT:
5360 mCaps.fragmentHighpFloat.get(range, precision);
5361 break;
5362
5363 case GL_LOW_INT:
5364 mCaps.fragmentLowpInt.get(range, precision);
5365 break;
5366 case GL_MEDIUM_INT:
5367 mCaps.fragmentMediumpInt.get(range, precision);
5368 break;
5369 case GL_HIGH_INT:
5370 mCaps.fragmentHighpInt.get(range, precision);
5371 break;
5372
5373 default:
5374 UNREACHABLE();
5375 return;
5376 }
5377 break;
5378
5379 default:
5380 UNREACHABLE();
5381 return;
5382 }
5383}
5384
5385void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5386{
5387 Shader *shaderObject = getShader(shader);
5388 ASSERT(shaderObject);
5389 shaderObject->getSource(bufsize, length, source);
5390}
5391
5392void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5393{
5394 Program *programObject = getProgram(program);
5395 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005396 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005397}
5398
Brandon Jones59770802018-04-02 13:18:42 -07005399void Context::getUniformfvRobust(GLuint program,
5400 GLint location,
5401 GLsizei bufSize,
5402 GLsizei *length,
5403 GLfloat *params)
5404{
5405 getUniformfv(program, location, params);
5406}
5407
Jamie Madillc1d770e2017-04-13 17:31:24 -04005408void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5409{
5410 Program *programObject = getProgram(program);
5411 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005412 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005413}
5414
Brandon Jones59770802018-04-02 13:18:42 -07005415void Context::getUniformivRobust(GLuint program,
5416 GLint location,
5417 GLsizei bufSize,
5418 GLsizei *length,
5419 GLint *params)
5420{
5421 getUniformiv(program, location, params);
5422}
5423
Jamie Madillc1d770e2017-04-13 17:31:24 -04005424GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5425{
5426 Program *programObject = getProgram(program);
5427 ASSERT(programObject);
5428 return programObject->getUniformLocation(name);
5429}
5430
5431GLboolean Context::isBuffer(GLuint buffer)
5432{
5433 if (buffer == 0)
5434 {
5435 return GL_FALSE;
5436 }
5437
5438 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5439}
5440
5441GLboolean Context::isEnabled(GLenum cap)
5442{
5443 return mGLState.getEnableFeature(cap);
5444}
5445
5446GLboolean Context::isFramebuffer(GLuint framebuffer)
5447{
5448 if (framebuffer == 0)
5449 {
5450 return GL_FALSE;
5451 }
5452
5453 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5454}
5455
5456GLboolean Context::isProgram(GLuint program)
5457{
5458 if (program == 0)
5459 {
5460 return GL_FALSE;
5461 }
5462
5463 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5464}
5465
5466GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5467{
5468 if (renderbuffer == 0)
5469 {
5470 return GL_FALSE;
5471 }
5472
5473 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5474}
5475
5476GLboolean Context::isShader(GLuint shader)
5477{
5478 if (shader == 0)
5479 {
5480 return GL_FALSE;
5481 }
5482
5483 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5484}
5485
5486GLboolean Context::isTexture(GLuint texture)
5487{
5488 if (texture == 0)
5489 {
5490 return GL_FALSE;
5491 }
5492
5493 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5494}
5495
5496void Context::linkProgram(GLuint program)
5497{
5498 Program *programObject = getProgram(program);
5499 ASSERT(programObject);
5500 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005501 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005502}
5503
5504void Context::releaseShaderCompiler()
5505{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005506 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005507}
5508
5509void Context::shaderBinary(GLsizei n,
5510 const GLuint *shaders,
5511 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005512 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005513 GLsizei length)
5514{
5515 // No binary shader formats are supported.
5516 UNIMPLEMENTED();
5517}
5518
5519void Context::shaderSource(GLuint shader,
5520 GLsizei count,
5521 const GLchar *const *string,
5522 const GLint *length)
5523{
5524 Shader *shaderObject = getShader(shader);
5525 ASSERT(shaderObject);
5526 shaderObject->setSource(count, string, length);
5527}
5528
5529void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5530{
5531 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5532}
5533
5534void Context::stencilMask(GLuint mask)
5535{
5536 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5537}
5538
5539void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5540{
5541 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5542}
5543
5544void Context::uniform1f(GLint location, GLfloat x)
5545{
5546 Program *program = mGLState.getProgram();
5547 program->setUniform1fv(location, 1, &x);
5548}
5549
5550void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5551{
5552 Program *program = mGLState.getProgram();
5553 program->setUniform1fv(location, count, v);
5554}
5555
5556void Context::uniform1i(GLint location, GLint x)
5557{
5558 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005559 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5560 {
5561 mGLState.setObjectDirty(GL_PROGRAM);
5562 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005563}
5564
5565void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5566{
5567 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005568 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5569 {
5570 mGLState.setObjectDirty(GL_PROGRAM);
5571 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572}
5573
5574void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5575{
5576 GLfloat xy[2] = {x, y};
5577 Program *program = mGLState.getProgram();
5578 program->setUniform2fv(location, 1, xy);
5579}
5580
5581void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5582{
5583 Program *program = mGLState.getProgram();
5584 program->setUniform2fv(location, count, v);
5585}
5586
5587void Context::uniform2i(GLint location, GLint x, GLint y)
5588{
5589 GLint xy[2] = {x, y};
5590 Program *program = mGLState.getProgram();
5591 program->setUniform2iv(location, 1, xy);
5592}
5593
5594void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5595{
5596 Program *program = mGLState.getProgram();
5597 program->setUniform2iv(location, count, v);
5598}
5599
5600void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5601{
5602 GLfloat xyz[3] = {x, y, z};
5603 Program *program = mGLState.getProgram();
5604 program->setUniform3fv(location, 1, xyz);
5605}
5606
5607void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5608{
5609 Program *program = mGLState.getProgram();
5610 program->setUniform3fv(location, count, v);
5611}
5612
5613void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5614{
5615 GLint xyz[3] = {x, y, z};
5616 Program *program = mGLState.getProgram();
5617 program->setUniform3iv(location, 1, xyz);
5618}
5619
5620void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5621{
5622 Program *program = mGLState.getProgram();
5623 program->setUniform3iv(location, count, v);
5624}
5625
5626void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5627{
5628 GLfloat xyzw[4] = {x, y, z, w};
5629 Program *program = mGLState.getProgram();
5630 program->setUniform4fv(location, 1, xyzw);
5631}
5632
5633void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5634{
5635 Program *program = mGLState.getProgram();
5636 program->setUniform4fv(location, count, v);
5637}
5638
5639void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5640{
5641 GLint xyzw[4] = {x, y, z, w};
5642 Program *program = mGLState.getProgram();
5643 program->setUniform4iv(location, 1, xyzw);
5644}
5645
5646void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5647{
5648 Program *program = mGLState.getProgram();
5649 program->setUniform4iv(location, count, v);
5650}
5651
5652void Context::uniformMatrix2fv(GLint location,
5653 GLsizei count,
5654 GLboolean transpose,
5655 const GLfloat *value)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniformMatrix2fv(location, count, transpose, value);
5659}
5660
5661void Context::uniformMatrix3fv(GLint location,
5662 GLsizei count,
5663 GLboolean transpose,
5664 const GLfloat *value)
5665{
5666 Program *program = mGLState.getProgram();
5667 program->setUniformMatrix3fv(location, count, transpose, value);
5668}
5669
5670void Context::uniformMatrix4fv(GLint location,
5671 GLsizei count,
5672 GLboolean transpose,
5673 const GLfloat *value)
5674{
5675 Program *program = mGLState.getProgram();
5676 program->setUniformMatrix4fv(location, count, transpose, value);
5677}
5678
5679void Context::validateProgram(GLuint program)
5680{
5681 Program *programObject = getProgram(program);
5682 ASSERT(programObject);
5683 programObject->validate(mCaps);
5684}
5685
Jiajia Qin5451d532017-11-16 17:16:34 +08005686void Context::validateProgramPipeline(GLuint pipeline)
5687{
5688 UNIMPLEMENTED();
5689}
5690
Jamie Madilld04908b2017-06-09 14:15:35 -04005691void Context::getProgramBinary(GLuint program,
5692 GLsizei bufSize,
5693 GLsizei *length,
5694 GLenum *binaryFormat,
5695 void *binary)
5696{
5697 Program *programObject = getProgram(program);
5698 ASSERT(programObject != nullptr);
5699
5700 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5701}
5702
5703void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5704{
5705 Program *programObject = getProgram(program);
5706 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005707
Jamie Madilld04908b2017-06-09 14:15:35 -04005708 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5709}
5710
Jamie Madillff325f12017-08-26 15:06:05 -04005711void Context::uniform1ui(GLint location, GLuint v0)
5712{
5713 Program *program = mGLState.getProgram();
5714 program->setUniform1uiv(location, 1, &v0);
5715}
5716
5717void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5718{
5719 Program *program = mGLState.getProgram();
5720 const GLuint xy[] = {v0, v1};
5721 program->setUniform2uiv(location, 1, xy);
5722}
5723
5724void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5725{
5726 Program *program = mGLState.getProgram();
5727 const GLuint xyz[] = {v0, v1, v2};
5728 program->setUniform3uiv(location, 1, xyz);
5729}
5730
5731void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5732{
5733 Program *program = mGLState.getProgram();
5734 const GLuint xyzw[] = {v0, v1, v2, v3};
5735 program->setUniform4uiv(location, 1, xyzw);
5736}
5737
5738void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5739{
5740 Program *program = mGLState.getProgram();
5741 program->setUniform1uiv(location, count, value);
5742}
5743void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5744{
5745 Program *program = mGLState.getProgram();
5746 program->setUniform2uiv(location, count, value);
5747}
5748
5749void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5750{
5751 Program *program = mGLState.getProgram();
5752 program->setUniform3uiv(location, count, value);
5753}
5754
5755void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5756{
5757 Program *program = mGLState.getProgram();
5758 program->setUniform4uiv(location, count, value);
5759}
5760
Jamie Madillf0e04492017-08-26 15:28:42 -04005761void Context::genQueries(GLsizei n, GLuint *ids)
5762{
5763 for (GLsizei i = 0; i < n; i++)
5764 {
5765 GLuint handle = mQueryHandleAllocator.allocate();
5766 mQueryMap.assign(handle, nullptr);
5767 ids[i] = handle;
5768 }
5769}
5770
5771void Context::deleteQueries(GLsizei n, const GLuint *ids)
5772{
5773 for (int i = 0; i < n; i++)
5774 {
5775 GLuint query = ids[i];
5776
5777 Query *queryObject = nullptr;
5778 if (mQueryMap.erase(query, &queryObject))
5779 {
5780 mQueryHandleAllocator.release(query);
5781 if (queryObject)
5782 {
5783 queryObject->release(this);
5784 }
5785 }
5786 }
5787}
5788
5789GLboolean Context::isQuery(GLuint id)
5790{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005791 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005792}
5793
Jamie Madillc8c95812017-08-26 18:40:09 -04005794void Context::uniformMatrix2x3fv(GLint location,
5795 GLsizei count,
5796 GLboolean transpose,
5797 const GLfloat *value)
5798{
5799 Program *program = mGLState.getProgram();
5800 program->setUniformMatrix2x3fv(location, count, transpose, value);
5801}
5802
5803void Context::uniformMatrix3x2fv(GLint location,
5804 GLsizei count,
5805 GLboolean transpose,
5806 const GLfloat *value)
5807{
5808 Program *program = mGLState.getProgram();
5809 program->setUniformMatrix3x2fv(location, count, transpose, value);
5810}
5811
5812void Context::uniformMatrix2x4fv(GLint location,
5813 GLsizei count,
5814 GLboolean transpose,
5815 const GLfloat *value)
5816{
5817 Program *program = mGLState.getProgram();
5818 program->setUniformMatrix2x4fv(location, count, transpose, value);
5819}
5820
5821void Context::uniformMatrix4x2fv(GLint location,
5822 GLsizei count,
5823 GLboolean transpose,
5824 const GLfloat *value)
5825{
5826 Program *program = mGLState.getProgram();
5827 program->setUniformMatrix4x2fv(location, count, transpose, value);
5828}
5829
5830void Context::uniformMatrix3x4fv(GLint location,
5831 GLsizei count,
5832 GLboolean transpose,
5833 const GLfloat *value)
5834{
5835 Program *program = mGLState.getProgram();
5836 program->setUniformMatrix3x4fv(location, count, transpose, value);
5837}
5838
5839void Context::uniformMatrix4x3fv(GLint location,
5840 GLsizei count,
5841 GLboolean transpose,
5842 const GLfloat *value)
5843{
5844 Program *program = mGLState.getProgram();
5845 program->setUniformMatrix4x3fv(location, count, transpose, value);
5846}
5847
Jamie Madilld7576732017-08-26 18:49:50 -04005848void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5849{
5850 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5851 {
5852 GLuint vertexArray = arrays[arrayIndex];
5853
5854 if (arrays[arrayIndex] != 0)
5855 {
5856 VertexArray *vertexArrayObject = nullptr;
5857 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5858 {
5859 if (vertexArrayObject != nullptr)
5860 {
5861 detachVertexArray(vertexArray);
5862 vertexArrayObject->onDestroy(this);
5863 }
5864
5865 mVertexArrayHandleAllocator.release(vertexArray);
5866 }
5867 }
5868 }
5869}
5870
5871void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5872{
5873 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5874 {
5875 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5876 mVertexArrayMap.assign(vertexArray, nullptr);
5877 arrays[arrayIndex] = vertexArray;
5878 }
5879}
5880
5881bool Context::isVertexArray(GLuint array)
5882{
5883 if (array == 0)
5884 {
5885 return GL_FALSE;
5886 }
5887
5888 VertexArray *vao = getVertexArray(array);
5889 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5890}
5891
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005892void Context::endTransformFeedback()
5893{
5894 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5895 transformFeedback->end(this);
5896}
5897
5898void Context::transformFeedbackVaryings(GLuint program,
5899 GLsizei count,
5900 const GLchar *const *varyings,
5901 GLenum bufferMode)
5902{
5903 Program *programObject = getProgram(program);
5904 ASSERT(programObject);
5905 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5906}
5907
5908void Context::getTransformFeedbackVarying(GLuint program,
5909 GLuint index,
5910 GLsizei bufSize,
5911 GLsizei *length,
5912 GLsizei *size,
5913 GLenum *type,
5914 GLchar *name)
5915{
5916 Program *programObject = getProgram(program);
5917 ASSERT(programObject);
5918 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5919}
5920
5921void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5922{
5923 for (int i = 0; i < n; i++)
5924 {
5925 GLuint transformFeedback = ids[i];
5926 if (transformFeedback == 0)
5927 {
5928 continue;
5929 }
5930
5931 TransformFeedback *transformFeedbackObject = nullptr;
5932 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5933 {
5934 if (transformFeedbackObject != nullptr)
5935 {
5936 detachTransformFeedback(transformFeedback);
5937 transformFeedbackObject->release(this);
5938 }
5939
5940 mTransformFeedbackHandleAllocator.release(transformFeedback);
5941 }
5942 }
5943}
5944
5945void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5946{
5947 for (int i = 0; i < n; i++)
5948 {
5949 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5950 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5951 ids[i] = transformFeedback;
5952 }
5953}
5954
5955bool Context::isTransformFeedback(GLuint id)
5956{
5957 if (id == 0)
5958 {
5959 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5960 // returns FALSE
5961 return GL_FALSE;
5962 }
5963
5964 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5965 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5966}
5967
5968void Context::pauseTransformFeedback()
5969{
5970 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5971 transformFeedback->pause();
5972}
5973
5974void Context::resumeTransformFeedback()
5975{
5976 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5977 transformFeedback->resume();
5978}
5979
Jamie Madill12e957f2017-08-26 21:42:26 -04005980void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5981{
5982 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005983 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005984}
5985
Brandon Jones59770802018-04-02 13:18:42 -07005986void Context::getUniformuivRobust(GLuint program,
5987 GLint location,
5988 GLsizei bufSize,
5989 GLsizei *length,
5990 GLuint *params)
5991{
5992 getUniformuiv(program, location, params);
5993}
5994
Jamie Madill12e957f2017-08-26 21:42:26 -04005995GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5996{
5997 const Program *programObject = getProgram(program);
5998 return programObject->getFragDataLocation(name);
5999}
6000
6001void Context::getUniformIndices(GLuint program,
6002 GLsizei uniformCount,
6003 const GLchar *const *uniformNames,
6004 GLuint *uniformIndices)
6005{
6006 const Program *programObject = getProgram(program);
6007 if (!programObject->isLinked())
6008 {
6009 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6010 {
6011 uniformIndices[uniformId] = GL_INVALID_INDEX;
6012 }
6013 }
6014 else
6015 {
6016 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6017 {
6018 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6019 }
6020 }
6021}
6022
6023void Context::getActiveUniformsiv(GLuint program,
6024 GLsizei uniformCount,
6025 const GLuint *uniformIndices,
6026 GLenum pname,
6027 GLint *params)
6028{
6029 const Program *programObject = getProgram(program);
6030 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6031 {
6032 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006033 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006034 }
6035}
6036
6037GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6038{
6039 const Program *programObject = getProgram(program);
6040 return programObject->getUniformBlockIndex(uniformBlockName);
6041}
6042
6043void Context::getActiveUniformBlockiv(GLuint program,
6044 GLuint uniformBlockIndex,
6045 GLenum pname,
6046 GLint *params)
6047{
6048 const Program *programObject = getProgram(program);
6049 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6050}
6051
Brandon Jones59770802018-04-02 13:18:42 -07006052void Context::getActiveUniformBlockivRobust(GLuint program,
6053 GLuint uniformBlockIndex,
6054 GLenum pname,
6055 GLsizei bufSize,
6056 GLsizei *length,
6057 GLint *params)
6058{
6059 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6060}
6061
Jamie Madill12e957f2017-08-26 21:42:26 -04006062void Context::getActiveUniformBlockName(GLuint program,
6063 GLuint uniformBlockIndex,
6064 GLsizei bufSize,
6065 GLsizei *length,
6066 GLchar *uniformBlockName)
6067{
6068 const Program *programObject = getProgram(program);
6069 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6070}
6071
6072void Context::uniformBlockBinding(GLuint program,
6073 GLuint uniformBlockIndex,
6074 GLuint uniformBlockBinding)
6075{
6076 Program *programObject = getProgram(program);
6077 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6078}
6079
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006080GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6081{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006082 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6083 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006084
Jamie Madill70b5bb02017-08-28 13:32:37 -04006085 Sync *syncObject = getSync(syncHandle);
6086 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006087 if (error.isError())
6088 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006089 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006090 handleError(error);
6091 return nullptr;
6092 }
6093
Jamie Madill70b5bb02017-08-28 13:32:37 -04006094 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006095}
6096
6097GLboolean Context::isSync(GLsync sync)
6098{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006099 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006100}
6101
6102GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6103{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006104 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006105
6106 GLenum result = GL_WAIT_FAILED;
6107 handleError(syncObject->clientWait(flags, timeout, &result));
6108 return result;
6109}
6110
6111void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6112{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006113 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006114 handleError(syncObject->serverWait(flags, timeout));
6115}
6116
6117void Context::getInteger64v(GLenum pname, GLint64 *params)
6118{
6119 GLenum nativeType = GL_NONE;
6120 unsigned int numParams = 0;
6121 getQueryParameterInfo(pname, &nativeType, &numParams);
6122
6123 if (nativeType == GL_INT_64_ANGLEX)
6124 {
6125 getInteger64vImpl(pname, params);
6126 }
6127 else
6128 {
6129 CastStateValues(this, nativeType, pname, numParams, params);
6130 }
6131}
6132
Brandon Jones59770802018-04-02 13:18:42 -07006133void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6134{
6135 getInteger64v(pname, data);
6136}
6137
Corentin Wallez336129f2017-10-17 15:55:40 -04006138void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006139{
6140 Buffer *buffer = mGLState.getTargetBuffer(target);
6141 QueryBufferParameteri64v(buffer, pname, params);
6142}
6143
Brandon Jones59770802018-04-02 13:18:42 -07006144void Context::getBufferParameteri64vRobust(BufferBinding target,
6145 GLenum pname,
6146 GLsizei bufSize,
6147 GLsizei *length,
6148 GLint64 *params)
6149{
6150 getBufferParameteri64v(target, pname, params);
6151}
6152
Jamie Madill3ef140a2017-08-26 23:11:21 -04006153void Context::genSamplers(GLsizei count, GLuint *samplers)
6154{
6155 for (int i = 0; i < count; i++)
6156 {
6157 samplers[i] = mState.mSamplers->createSampler();
6158 }
6159}
6160
6161void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6162{
6163 for (int i = 0; i < count; i++)
6164 {
6165 GLuint sampler = samplers[i];
6166
6167 if (mState.mSamplers->getSampler(sampler))
6168 {
6169 detachSampler(sampler);
6170 }
6171
6172 mState.mSamplers->deleteObject(this, sampler);
6173 }
6174}
6175
6176void Context::getInternalformativ(GLenum target,
6177 GLenum internalformat,
6178 GLenum pname,
6179 GLsizei bufSize,
6180 GLint *params)
6181{
6182 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6183 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6184}
6185
Brandon Jones59770802018-04-02 13:18:42 -07006186void Context::getInternalformativRobust(GLenum target,
6187 GLenum internalformat,
6188 GLenum pname,
6189 GLsizei bufSize,
6190 GLsizei *length,
6191 GLint *params)
6192{
6193 getInternalformativ(target, internalformat, pname, bufSize, params);
6194}
6195
Jiajia Qin5451d532017-11-16 17:16:34 +08006196void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6197{
6198 programUniform1iv(program, location, 1, &v0);
6199}
6200
6201void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6202{
6203 GLint xy[2] = {v0, v1};
6204 programUniform2iv(program, location, 1, xy);
6205}
6206
6207void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6208{
6209 GLint xyz[3] = {v0, v1, v2};
6210 programUniform3iv(program, location, 1, xyz);
6211}
6212
6213void Context::programUniform4i(GLuint program,
6214 GLint location,
6215 GLint v0,
6216 GLint v1,
6217 GLint v2,
6218 GLint v3)
6219{
6220 GLint xyzw[4] = {v0, v1, v2, v3};
6221 programUniform4iv(program, location, 1, xyzw);
6222}
6223
6224void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6225{
6226 programUniform1uiv(program, location, 1, &v0);
6227}
6228
6229void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6230{
6231 GLuint xy[2] = {v0, v1};
6232 programUniform2uiv(program, location, 1, xy);
6233}
6234
6235void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6236{
6237 GLuint xyz[3] = {v0, v1, v2};
6238 programUniform3uiv(program, location, 1, xyz);
6239}
6240
6241void Context::programUniform4ui(GLuint program,
6242 GLint location,
6243 GLuint v0,
6244 GLuint v1,
6245 GLuint v2,
6246 GLuint v3)
6247{
6248 GLuint xyzw[4] = {v0, v1, v2, v3};
6249 programUniform4uiv(program, location, 1, xyzw);
6250}
6251
6252void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6253{
6254 programUniform1fv(program, location, 1, &v0);
6255}
6256
6257void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6258{
6259 GLfloat xy[2] = {v0, v1};
6260 programUniform2fv(program, location, 1, xy);
6261}
6262
6263void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6264{
6265 GLfloat xyz[3] = {v0, v1, v2};
6266 programUniform3fv(program, location, 1, xyz);
6267}
6268
6269void Context::programUniform4f(GLuint program,
6270 GLint location,
6271 GLfloat v0,
6272 GLfloat v1,
6273 GLfloat v2,
6274 GLfloat v3)
6275{
6276 GLfloat xyzw[4] = {v0, v1, v2, v3};
6277 programUniform4fv(program, location, 1, xyzw);
6278}
6279
Jamie Madill81c2e252017-09-09 23:32:46 -04006280void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6281{
6282 Program *programObject = getProgram(program);
6283 ASSERT(programObject);
6284 if (programObject->setUniform1iv(location, count, value) ==
6285 Program::SetUniformResult::SamplerChanged)
6286 {
6287 mGLState.setObjectDirty(GL_PROGRAM);
6288 }
6289}
6290
Jiajia Qin5451d532017-11-16 17:16:34 +08006291void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6292{
6293 Program *programObject = getProgram(program);
6294 ASSERT(programObject);
6295 programObject->setUniform2iv(location, count, value);
6296}
6297
6298void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6299{
6300 Program *programObject = getProgram(program);
6301 ASSERT(programObject);
6302 programObject->setUniform3iv(location, count, value);
6303}
6304
6305void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6306{
6307 Program *programObject = getProgram(program);
6308 ASSERT(programObject);
6309 programObject->setUniform4iv(location, count, value);
6310}
6311
6312void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6313{
6314 Program *programObject = getProgram(program);
6315 ASSERT(programObject);
6316 programObject->setUniform1uiv(location, count, value);
6317}
6318
6319void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6320{
6321 Program *programObject = getProgram(program);
6322 ASSERT(programObject);
6323 programObject->setUniform2uiv(location, count, value);
6324}
6325
6326void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 programObject->setUniform3uiv(location, count, value);
6331}
6332
6333void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6334{
6335 Program *programObject = getProgram(program);
6336 ASSERT(programObject);
6337 programObject->setUniform4uiv(location, count, value);
6338}
6339
6340void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniform1fv(location, count, value);
6345}
6346
6347void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6348{
6349 Program *programObject = getProgram(program);
6350 ASSERT(programObject);
6351 programObject->setUniform2fv(location, count, value);
6352}
6353
6354void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniform3fv(location, count, value);
6359}
6360
6361void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6362{
6363 Program *programObject = getProgram(program);
6364 ASSERT(programObject);
6365 programObject->setUniform4fv(location, count, value);
6366}
6367
6368void Context::programUniformMatrix2fv(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->setUniformMatrix2fv(location, count, transpose, value);
6377}
6378
6379void Context::programUniformMatrix3fv(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->setUniformMatrix3fv(location, count, transpose, value);
6388}
6389
6390void Context::programUniformMatrix4fv(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->setUniformMatrix4fv(location, count, transpose, value);
6399}
6400
6401void Context::programUniformMatrix2x3fv(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->setUniformMatrix2x3fv(location, count, transpose, value);
6410}
6411
6412void Context::programUniformMatrix3x2fv(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->setUniformMatrix3x2fv(location, count, transpose, value);
6421}
6422
6423void Context::programUniformMatrix2x4fv(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->setUniformMatrix2x4fv(location, count, transpose, value);
6432}
6433
6434void Context::programUniformMatrix4x2fv(GLuint program,
6435 GLint location,
6436 GLsizei count,
6437 GLboolean transpose,
6438 const GLfloat *value)
6439{
6440 Program *programObject = getProgram(program);
6441 ASSERT(programObject);
6442 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6443}
6444
6445void Context::programUniformMatrix3x4fv(GLuint program,
6446 GLint location,
6447 GLsizei count,
6448 GLboolean transpose,
6449 const GLfloat *value)
6450{
6451 Program *programObject = getProgram(program);
6452 ASSERT(programObject);
6453 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6454}
6455
6456void Context::programUniformMatrix4x3fv(GLuint program,
6457 GLint location,
6458 GLsizei count,
6459 GLboolean transpose,
6460 const GLfloat *value)
6461{
6462 Program *programObject = getProgram(program);
6463 ASSERT(programObject);
6464 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6465}
6466
Jamie Madill81c2e252017-09-09 23:32:46 -04006467void Context::onTextureChange(const Texture *texture)
6468{
6469 // Conservatively assume all textures are dirty.
6470 // TODO(jmadill): More fine-grained update.
6471 mGLState.setObjectDirty(GL_TEXTURE);
6472}
6473
James Darpiniane8a93c62018-01-04 18:02:24 -08006474bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6475{
6476 return mGLState.isCurrentTransformFeedback(tf);
6477}
6478bool Context::isCurrentVertexArray(const VertexArray *va) const
6479{
6480 return mGLState.isCurrentVertexArray(va);
6481}
6482
Yunchao Hea336b902017-08-02 16:05:21 +08006483void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6484{
6485 for (int i = 0; i < count; i++)
6486 {
6487 pipelines[i] = createProgramPipeline();
6488 }
6489}
6490
6491void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6492{
6493 for (int i = 0; i < count; i++)
6494 {
6495 if (pipelines[i] != 0)
6496 {
6497 deleteProgramPipeline(pipelines[i]);
6498 }
6499 }
6500}
6501
6502GLboolean Context::isProgramPipeline(GLuint pipeline)
6503{
6504 if (pipeline == 0)
6505 {
6506 return GL_FALSE;
6507 }
6508
6509 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6510}
6511
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006512void Context::finishFenceNV(GLuint fence)
6513{
6514 FenceNV *fenceObject = getFenceNV(fence);
6515
6516 ASSERT(fenceObject && fenceObject->isSet());
6517 handleError(fenceObject->finish());
6518}
6519
6520void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6521{
6522 FenceNV *fenceObject = getFenceNV(fence);
6523
6524 ASSERT(fenceObject && fenceObject->isSet());
6525
6526 switch (pname)
6527 {
6528 case GL_FENCE_STATUS_NV:
6529 {
6530 // GL_NV_fence spec:
6531 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6532 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6533 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6534 GLboolean status = GL_TRUE;
6535 if (fenceObject->getStatus() != GL_TRUE)
6536 {
6537 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6538 }
6539 *params = status;
6540 break;
6541 }
6542
6543 case GL_FENCE_CONDITION_NV:
6544 {
6545 *params = static_cast<GLint>(fenceObject->getCondition());
6546 break;
6547 }
6548
6549 default:
6550 UNREACHABLE();
6551 }
6552}
6553
6554void Context::getTranslatedShaderSource(GLuint shader,
6555 GLsizei bufsize,
6556 GLsizei *length,
6557 GLchar *source)
6558{
6559 Shader *shaderObject = getShader(shader);
6560 ASSERT(shaderObject);
6561 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6562}
6563
6564void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6565{
6566 Program *programObject = getProgram(program);
6567 ASSERT(programObject);
6568
6569 programObject->getUniformfv(this, location, params);
6570}
6571
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006572void Context::getnUniformfvRobust(GLuint program,
6573 GLint location,
6574 GLsizei bufSize,
6575 GLsizei *length,
6576 GLfloat *params)
6577{
6578 UNIMPLEMENTED();
6579}
6580
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006581void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6582{
6583 Program *programObject = getProgram(program);
6584 ASSERT(programObject);
6585
6586 programObject->getUniformiv(this, location, params);
6587}
6588
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006589void Context::getnUniformivRobust(GLuint program,
6590 GLint location,
6591 GLsizei bufSize,
6592 GLsizei *length,
6593 GLint *params)
6594{
6595 UNIMPLEMENTED();
6596}
6597
6598void Context::getnUniformuivRobust(GLuint program,
6599 GLint location,
6600 GLsizei bufSize,
6601 GLsizei *length,
6602 GLuint *params)
6603{
6604 UNIMPLEMENTED();
6605}
6606
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006607GLboolean Context::isFenceNV(GLuint fence)
6608{
6609 FenceNV *fenceObject = getFenceNV(fence);
6610
6611 if (fenceObject == nullptr)
6612 {
6613 return GL_FALSE;
6614 }
6615
6616 // GL_NV_fence spec:
6617 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6618 // existing fence.
6619 return fenceObject->isSet();
6620}
6621
6622void Context::readnPixels(GLint x,
6623 GLint y,
6624 GLsizei width,
6625 GLsizei height,
6626 GLenum format,
6627 GLenum type,
6628 GLsizei bufSize,
6629 void *data)
6630{
6631 return readPixels(x, y, width, height, format, type, data);
6632}
6633
Jamie Madill007530e2017-12-28 14:27:04 -05006634void Context::setFenceNV(GLuint fence, GLenum condition)
6635{
6636 ASSERT(condition == GL_ALL_COMPLETED_NV);
6637
6638 FenceNV *fenceObject = getFenceNV(fence);
6639 ASSERT(fenceObject != nullptr);
6640 handleError(fenceObject->set(condition));
6641}
6642
6643GLboolean Context::testFenceNV(GLuint fence)
6644{
6645 FenceNV *fenceObject = getFenceNV(fence);
6646
6647 ASSERT(fenceObject != nullptr);
6648 ASSERT(fenceObject->isSet() == GL_TRUE);
6649
6650 GLboolean result = GL_TRUE;
6651 Error error = fenceObject->test(&result);
6652 if (error.isError())
6653 {
6654 handleError(error);
6655 return GL_TRUE;
6656 }
6657
6658 return result;
6659}
6660
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006661void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006662{
6663 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006664 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006665 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006666}
6667
Jamie Madillfa920eb2018-01-04 11:45:50 -05006668void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006669{
6670 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006671 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006672 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6673}
6674
Jamie Madillfa920eb2018-01-04 11:45:50 -05006675void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6676{
6677 UNIMPLEMENTED();
6678}
6679
Jamie Madill5b772312018-03-08 20:28:32 -05006680bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6681{
6682 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6683 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6684 // to the fact that it is stored internally as a float, and so would require conversion
6685 // if returned from Context::getIntegerv. Since this conversion is already implemented
6686 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6687 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6688 // application.
6689 switch (pname)
6690 {
6691 case GL_COMPRESSED_TEXTURE_FORMATS:
6692 {
6693 *type = GL_INT;
6694 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6695 return true;
6696 }
6697 case GL_SHADER_BINARY_FORMATS:
6698 {
6699 *type = GL_INT;
6700 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6701 return true;
6702 }
6703
6704 case GL_MAX_VERTEX_ATTRIBS:
6705 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6706 case GL_MAX_VARYING_VECTORS:
6707 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6708 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6709 case GL_MAX_TEXTURE_IMAGE_UNITS:
6710 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6711 case GL_MAX_RENDERBUFFER_SIZE:
6712 case GL_NUM_SHADER_BINARY_FORMATS:
6713 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6714 case GL_ARRAY_BUFFER_BINDING:
6715 case GL_FRAMEBUFFER_BINDING:
6716 case GL_RENDERBUFFER_BINDING:
6717 case GL_CURRENT_PROGRAM:
6718 case GL_PACK_ALIGNMENT:
6719 case GL_UNPACK_ALIGNMENT:
6720 case GL_GENERATE_MIPMAP_HINT:
6721 case GL_RED_BITS:
6722 case GL_GREEN_BITS:
6723 case GL_BLUE_BITS:
6724 case GL_ALPHA_BITS:
6725 case GL_DEPTH_BITS:
6726 case GL_STENCIL_BITS:
6727 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6728 case GL_CULL_FACE_MODE:
6729 case GL_FRONT_FACE:
6730 case GL_ACTIVE_TEXTURE:
6731 case GL_STENCIL_FUNC:
6732 case GL_STENCIL_VALUE_MASK:
6733 case GL_STENCIL_REF:
6734 case GL_STENCIL_FAIL:
6735 case GL_STENCIL_PASS_DEPTH_FAIL:
6736 case GL_STENCIL_PASS_DEPTH_PASS:
6737 case GL_STENCIL_BACK_FUNC:
6738 case GL_STENCIL_BACK_VALUE_MASK:
6739 case GL_STENCIL_BACK_REF:
6740 case GL_STENCIL_BACK_FAIL:
6741 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6742 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6743 case GL_DEPTH_FUNC:
6744 case GL_BLEND_SRC_RGB:
6745 case GL_BLEND_SRC_ALPHA:
6746 case GL_BLEND_DST_RGB:
6747 case GL_BLEND_DST_ALPHA:
6748 case GL_BLEND_EQUATION_RGB:
6749 case GL_BLEND_EQUATION_ALPHA:
6750 case GL_STENCIL_WRITEMASK:
6751 case GL_STENCIL_BACK_WRITEMASK:
6752 case GL_STENCIL_CLEAR_VALUE:
6753 case GL_SUBPIXEL_BITS:
6754 case GL_MAX_TEXTURE_SIZE:
6755 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6756 case GL_SAMPLE_BUFFERS:
6757 case GL_SAMPLES:
6758 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6759 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6760 case GL_TEXTURE_BINDING_2D:
6761 case GL_TEXTURE_BINDING_CUBE_MAP:
6762 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6763 {
6764 *type = GL_INT;
6765 *numParams = 1;
6766 return true;
6767 }
6768 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6769 {
6770 if (!getExtensions().packReverseRowOrder)
6771 {
6772 return false;
6773 }
6774 *type = GL_INT;
6775 *numParams = 1;
6776 return true;
6777 }
6778 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6779 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6780 {
6781 if (!getExtensions().textureRectangle)
6782 {
6783 return false;
6784 }
6785 *type = GL_INT;
6786 *numParams = 1;
6787 return true;
6788 }
6789 case GL_MAX_DRAW_BUFFERS_EXT:
6790 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6791 {
6792 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6793 {
6794 return false;
6795 }
6796 *type = GL_INT;
6797 *numParams = 1;
6798 return true;
6799 }
6800 case GL_MAX_VIEWPORT_DIMS:
6801 {
6802 *type = GL_INT;
6803 *numParams = 2;
6804 return true;
6805 }
6806 case GL_VIEWPORT:
6807 case GL_SCISSOR_BOX:
6808 {
6809 *type = GL_INT;
6810 *numParams = 4;
6811 return true;
6812 }
6813 case GL_SHADER_COMPILER:
6814 case GL_SAMPLE_COVERAGE_INVERT:
6815 case GL_DEPTH_WRITEMASK:
6816 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6817 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6818 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6819 // bool-natural
6820 case GL_SAMPLE_COVERAGE:
6821 case GL_SCISSOR_TEST:
6822 case GL_STENCIL_TEST:
6823 case GL_DEPTH_TEST:
6824 case GL_BLEND:
6825 case GL_DITHER:
6826 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6827 {
6828 *type = GL_BOOL;
6829 *numParams = 1;
6830 return true;
6831 }
6832 case GL_COLOR_WRITEMASK:
6833 {
6834 *type = GL_BOOL;
6835 *numParams = 4;
6836 return true;
6837 }
6838 case GL_POLYGON_OFFSET_FACTOR:
6839 case GL_POLYGON_OFFSET_UNITS:
6840 case GL_SAMPLE_COVERAGE_VALUE:
6841 case GL_DEPTH_CLEAR_VALUE:
6842 case GL_LINE_WIDTH:
6843 {
6844 *type = GL_FLOAT;
6845 *numParams = 1;
6846 return true;
6847 }
6848 case GL_ALIASED_LINE_WIDTH_RANGE:
6849 case GL_ALIASED_POINT_SIZE_RANGE:
6850 case GL_DEPTH_RANGE:
6851 {
6852 *type = GL_FLOAT;
6853 *numParams = 2;
6854 return true;
6855 }
6856 case GL_COLOR_CLEAR_VALUE:
6857 case GL_BLEND_COLOR:
6858 {
6859 *type = GL_FLOAT;
6860 *numParams = 4;
6861 return true;
6862 }
6863 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6864 if (!getExtensions().textureFilterAnisotropic)
6865 {
6866 return false;
6867 }
6868 *type = GL_FLOAT;
6869 *numParams = 1;
6870 return true;
6871 case GL_TIMESTAMP_EXT:
6872 if (!getExtensions().disjointTimerQuery)
6873 {
6874 return false;
6875 }
6876 *type = GL_INT_64_ANGLEX;
6877 *numParams = 1;
6878 return true;
6879 case GL_GPU_DISJOINT_EXT:
6880 if (!getExtensions().disjointTimerQuery)
6881 {
6882 return false;
6883 }
6884 *type = GL_INT;
6885 *numParams = 1;
6886 return true;
6887 case GL_COVERAGE_MODULATION_CHROMIUM:
6888 if (!getExtensions().framebufferMixedSamples)
6889 {
6890 return false;
6891 }
6892 *type = GL_INT;
6893 *numParams = 1;
6894 return true;
6895 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6896 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6897 {
6898 return false;
6899 }
6900 *type = GL_INT;
6901 *numParams = 1;
6902 return true;
6903 }
6904
6905 if (getExtensions().debug)
6906 {
6907 switch (pname)
6908 {
6909 case GL_DEBUG_LOGGED_MESSAGES:
6910 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6911 case GL_DEBUG_GROUP_STACK_DEPTH:
6912 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6913 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6914 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6915 case GL_MAX_LABEL_LENGTH:
6916 *type = GL_INT;
6917 *numParams = 1;
6918 return true;
6919
6920 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6921 case GL_DEBUG_OUTPUT:
6922 *type = GL_BOOL;
6923 *numParams = 1;
6924 return true;
6925 }
6926 }
6927
6928 if (getExtensions().multisampleCompatibility)
6929 {
6930 switch (pname)
6931 {
6932 case GL_MULTISAMPLE_EXT:
6933 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6934 *type = GL_BOOL;
6935 *numParams = 1;
6936 return true;
6937 }
6938 }
6939
6940 if (getExtensions().pathRendering)
6941 {
6942 switch (pname)
6943 {
6944 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6945 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6946 *type = GL_FLOAT;
6947 *numParams = 16;
6948 return true;
6949 }
6950 }
6951
6952 if (getExtensions().bindGeneratesResource)
6953 {
6954 switch (pname)
6955 {
6956 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6957 *type = GL_BOOL;
6958 *numParams = 1;
6959 return true;
6960 }
6961 }
6962
6963 if (getExtensions().clientArrays)
6964 {
6965 switch (pname)
6966 {
6967 case GL_CLIENT_ARRAYS_ANGLE:
6968 *type = GL_BOOL;
6969 *numParams = 1;
6970 return true;
6971 }
6972 }
6973
6974 if (getExtensions().sRGBWriteControl)
6975 {
6976 switch (pname)
6977 {
6978 case GL_FRAMEBUFFER_SRGB_EXT:
6979 *type = GL_BOOL;
6980 *numParams = 1;
6981 return true;
6982 }
6983 }
6984
6985 if (getExtensions().robustResourceInitialization &&
6986 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6987 {
6988 *type = GL_BOOL;
6989 *numParams = 1;
6990 return true;
6991 }
6992
6993 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6994 {
6995 *type = GL_BOOL;
6996 *numParams = 1;
6997 return true;
6998 }
6999
jchen1082af6202018-06-22 10:59:52 +08007000 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7001 {
7002 *type = GL_INT;
7003 *numParams = 1;
7004 return true;
7005 }
7006
Jamie Madill5b772312018-03-08 20:28:32 -05007007 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7008 switch (pname)
7009 {
7010 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7011 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7012 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7013 {
7014 return false;
7015 }
7016 *type = GL_INT;
7017 *numParams = 1;
7018 return true;
7019
7020 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7021 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7022 {
7023 return false;
7024 }
7025 *type = GL_INT;
7026 *numParams = 1;
7027 return true;
7028
7029 case GL_PROGRAM_BINARY_FORMATS_OES:
7030 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7031 {
7032 return false;
7033 }
7034 *type = GL_INT;
7035 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7036 return true;
7037
7038 case GL_PACK_ROW_LENGTH:
7039 case GL_PACK_SKIP_ROWS:
7040 case GL_PACK_SKIP_PIXELS:
7041 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7042 {
7043 return false;
7044 }
7045 *type = GL_INT;
7046 *numParams = 1;
7047 return true;
7048 case GL_UNPACK_ROW_LENGTH:
7049 case GL_UNPACK_SKIP_ROWS:
7050 case GL_UNPACK_SKIP_PIXELS:
7051 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7052 {
7053 return false;
7054 }
7055 *type = GL_INT;
7056 *numParams = 1;
7057 return true;
7058 case GL_VERTEX_ARRAY_BINDING:
7059 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7060 {
7061 return false;
7062 }
7063 *type = GL_INT;
7064 *numParams = 1;
7065 return true;
7066 case GL_PIXEL_PACK_BUFFER_BINDING:
7067 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7068 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7069 {
7070 return false;
7071 }
7072 *type = GL_INT;
7073 *numParams = 1;
7074 return true;
7075 case GL_MAX_SAMPLES:
7076 {
7077 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7078 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7079 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7080 {
7081 return false;
7082 }
7083 *type = GL_INT;
7084 *numParams = 1;
7085 return true;
7086
7087 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7088 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7089 {
7090 return false;
7091 }
7092 *type = GL_INT;
7093 *numParams = 1;
7094 return true;
7095 }
7096 }
7097
7098 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7099 {
7100 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7101 {
7102 return false;
7103 }
7104 *type = GL_INT;
7105 *numParams = 1;
7106 return true;
7107 }
7108
7109 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7110 {
7111 *type = GL_INT;
7112 *numParams = 1;
7113 return true;
7114 }
7115
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007116 if (getClientVersion() < Version(2, 0))
7117 {
7118 switch (pname)
7119 {
7120 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007121 case GL_CLIENT_ACTIVE_TEXTURE:
7122 case GL_MATRIX_MODE:
7123 case GL_MAX_TEXTURE_UNITS:
7124 case GL_MAX_MODELVIEW_STACK_DEPTH:
7125 case GL_MAX_PROJECTION_STACK_DEPTH:
7126 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007127 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007128 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007129 case GL_VERTEX_ARRAY_STRIDE:
7130 case GL_NORMAL_ARRAY_STRIDE:
7131 case GL_COLOR_ARRAY_STRIDE:
7132 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7133 case GL_VERTEX_ARRAY_SIZE:
7134 case GL_COLOR_ARRAY_SIZE:
7135 case GL_TEXTURE_COORD_ARRAY_SIZE:
7136 case GL_VERTEX_ARRAY_TYPE:
7137 case GL_NORMAL_ARRAY_TYPE:
7138 case GL_COLOR_ARRAY_TYPE:
7139 case GL_TEXTURE_COORD_ARRAY_TYPE:
7140 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7141 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7142 case GL_COLOR_ARRAY_BUFFER_BINDING:
7143 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7144 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7145 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7146 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007147 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007148 *type = GL_INT;
7149 *numParams = 1;
7150 return true;
7151 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007152 case GL_FOG_DENSITY:
7153 case GL_FOG_START:
7154 case GL_FOG_END:
7155 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007156 case GL_POINT_SIZE:
7157 case GL_POINT_SIZE_MIN:
7158 case GL_POINT_SIZE_MAX:
7159 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007160 *type = GL_FLOAT;
7161 *numParams = 1;
7162 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007163 case GL_SMOOTH_POINT_SIZE_RANGE:
7164 *type = GL_FLOAT;
7165 *numParams = 2;
7166 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007167 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007168 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007169 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007170 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007171 *type = GL_FLOAT;
7172 *numParams = 4;
7173 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007174 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007175 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007176 *type = GL_FLOAT;
7177 *numParams = 3;
7178 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007179 case GL_MODELVIEW_MATRIX:
7180 case GL_PROJECTION_MATRIX:
7181 case GL_TEXTURE_MATRIX:
7182 *type = GL_FLOAT;
7183 *numParams = 16;
7184 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007185 case GL_LIGHT_MODEL_TWO_SIDE:
7186 *type = GL_BOOL;
7187 *numParams = 1;
7188 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007189 }
7190 }
7191
Jamie Madill5b772312018-03-08 20:28:32 -05007192 if (getClientVersion() < Version(3, 0))
7193 {
7194 return false;
7195 }
7196
7197 // Check for ES3.0+ parameter names
7198 switch (pname)
7199 {
7200 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7201 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7202 case GL_UNIFORM_BUFFER_BINDING:
7203 case GL_TRANSFORM_FEEDBACK_BINDING:
7204 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7205 case GL_COPY_READ_BUFFER_BINDING:
7206 case GL_COPY_WRITE_BUFFER_BINDING:
7207 case GL_SAMPLER_BINDING:
7208 case GL_READ_BUFFER:
7209 case GL_TEXTURE_BINDING_3D:
7210 case GL_TEXTURE_BINDING_2D_ARRAY:
7211 case GL_MAX_3D_TEXTURE_SIZE:
7212 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7213 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7214 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7215 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7216 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7217 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7218 case GL_MAX_VARYING_COMPONENTS:
7219 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7220 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7221 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7222 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7223 case GL_NUM_EXTENSIONS:
7224 case GL_MAJOR_VERSION:
7225 case GL_MINOR_VERSION:
7226 case GL_MAX_ELEMENTS_INDICES:
7227 case GL_MAX_ELEMENTS_VERTICES:
7228 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7229 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7230 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7231 case GL_UNPACK_IMAGE_HEIGHT:
7232 case GL_UNPACK_SKIP_IMAGES:
7233 {
7234 *type = GL_INT;
7235 *numParams = 1;
7236 return true;
7237 }
7238
7239 case GL_MAX_ELEMENT_INDEX:
7240 case GL_MAX_UNIFORM_BLOCK_SIZE:
7241 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7242 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7243 case GL_MAX_SERVER_WAIT_TIMEOUT:
7244 {
7245 *type = GL_INT_64_ANGLEX;
7246 *numParams = 1;
7247 return true;
7248 }
7249
7250 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7251 case GL_TRANSFORM_FEEDBACK_PAUSED:
7252 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7253 case GL_RASTERIZER_DISCARD:
7254 {
7255 *type = GL_BOOL;
7256 *numParams = 1;
7257 return true;
7258 }
7259
7260 case GL_MAX_TEXTURE_LOD_BIAS:
7261 {
7262 *type = GL_FLOAT;
7263 *numParams = 1;
7264 return true;
7265 }
7266 }
7267
7268 if (getExtensions().requestExtension)
7269 {
7270 switch (pname)
7271 {
7272 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7273 *type = GL_INT;
7274 *numParams = 1;
7275 return true;
7276 }
7277 }
7278
7279 if (getClientVersion() < Version(3, 1))
7280 {
7281 return false;
7282 }
7283
7284 switch (pname)
7285 {
7286 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7287 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7288 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7289 case GL_MAX_FRAMEBUFFER_WIDTH:
7290 case GL_MAX_FRAMEBUFFER_HEIGHT:
7291 case GL_MAX_FRAMEBUFFER_SAMPLES:
7292 case GL_MAX_SAMPLE_MASK_WORDS:
7293 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7294 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7295 case GL_MAX_INTEGER_SAMPLES:
7296 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7297 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7298 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7299 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7300 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7301 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7302 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7303 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7304 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7305 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7306 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7307 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7308 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7309 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7310 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7311 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7312 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7313 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7314 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7315 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7316 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7317 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7318 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7319 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7320 case GL_MAX_UNIFORM_LOCATIONS:
7321 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7322 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7323 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7324 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7325 case GL_MAX_IMAGE_UNITS:
7326 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7327 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7328 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7329 case GL_SHADER_STORAGE_BUFFER_BINDING:
7330 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7331 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7332 *type = GL_INT;
7333 *numParams = 1;
7334 return true;
7335 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7336 *type = GL_INT_64_ANGLEX;
7337 *numParams = 1;
7338 return true;
7339 case GL_SAMPLE_MASK:
7340 *type = GL_BOOL;
7341 *numParams = 1;
7342 return true;
7343 }
7344
7345 if (getExtensions().geometryShader)
7346 {
7347 switch (pname)
7348 {
7349 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7350 case GL_LAYER_PROVOKING_VERTEX_EXT:
7351 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7352 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7353 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7354 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7355 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7356 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7357 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7358 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7359 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7360 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7361 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7362 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7363 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7364 *type = GL_INT;
7365 *numParams = 1;
7366 return true;
7367 }
7368 }
7369
7370 return false;
7371}
7372
7373bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7374{
7375 if (getClientVersion() < Version(3, 0))
7376 {
7377 return false;
7378 }
7379
7380 switch (target)
7381 {
7382 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7383 case GL_UNIFORM_BUFFER_BINDING:
7384 {
7385 *type = GL_INT;
7386 *numParams = 1;
7387 return true;
7388 }
7389 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7390 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7391 case GL_UNIFORM_BUFFER_START:
7392 case GL_UNIFORM_BUFFER_SIZE:
7393 {
7394 *type = GL_INT_64_ANGLEX;
7395 *numParams = 1;
7396 return true;
7397 }
7398 }
7399
7400 if (getClientVersion() < Version(3, 1))
7401 {
7402 return false;
7403 }
7404
7405 switch (target)
7406 {
7407 case GL_IMAGE_BINDING_LAYERED:
7408 {
7409 *type = GL_BOOL;
7410 *numParams = 1;
7411 return true;
7412 }
7413 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7414 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7415 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7416 case GL_SHADER_STORAGE_BUFFER_BINDING:
7417 case GL_VERTEX_BINDING_BUFFER:
7418 case GL_VERTEX_BINDING_DIVISOR:
7419 case GL_VERTEX_BINDING_OFFSET:
7420 case GL_VERTEX_BINDING_STRIDE:
7421 case GL_SAMPLE_MASK_VALUE:
7422 case GL_IMAGE_BINDING_NAME:
7423 case GL_IMAGE_BINDING_LEVEL:
7424 case GL_IMAGE_BINDING_LAYER:
7425 case GL_IMAGE_BINDING_ACCESS:
7426 case GL_IMAGE_BINDING_FORMAT:
7427 {
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 }
7432 case GL_ATOMIC_COUNTER_BUFFER_START:
7433 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7434 case GL_SHADER_STORAGE_BUFFER_START:
7435 case GL_SHADER_STORAGE_BUFFER_SIZE:
7436 {
7437 *type = GL_INT_64_ANGLEX;
7438 *numParams = 1;
7439 return true;
7440 }
7441 }
7442
7443 return false;
7444}
7445
7446Program *Context::getProgram(GLuint handle) const
7447{
7448 return mState.mShaderPrograms->getProgram(handle);
7449}
7450
7451Shader *Context::getShader(GLuint handle) const
7452{
7453 return mState.mShaderPrograms->getShader(handle);
7454}
7455
7456bool Context::isTextureGenerated(GLuint texture) const
7457{
7458 return mState.mTextures->isHandleGenerated(texture);
7459}
7460
7461bool Context::isBufferGenerated(GLuint buffer) const
7462{
7463 return mState.mBuffers->isHandleGenerated(buffer);
7464}
7465
7466bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7467{
7468 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7469}
7470
7471bool Context::isFramebufferGenerated(GLuint framebuffer) const
7472{
7473 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7474}
7475
7476bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7477{
7478 return mState.mPipelines->isHandleGenerated(pipeline);
7479}
7480
7481bool Context::usingDisplayTextureShareGroup() const
7482{
7483 return mDisplayTextureShareGroup;
7484}
7485
7486GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7487{
7488 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7489 internalformat == GL_DEPTH_STENCIL
7490 ? GL_DEPTH24_STENCIL8
7491 : internalformat;
7492}
7493
jchen1082af6202018-06-22 10:59:52 +08007494void Context::maxShaderCompilerThreads(GLuint count)
7495{
7496 mGLState.setMaxShaderCompilerThreads(count);
7497}
7498
Jamie Madillc29968b2016-01-20 11:17:23 -05007499} // namespace gl