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