blob: e5e911281455cefc08aa413a900892bd82dcc1f5 [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 Yangabb09f12018-04-16 10:43:53 -07001686 // GLES1 emulation: Vertex attribute queries
1687 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1688 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1689 case GL_COLOR_ARRAY_BUFFER_BINDING:
1690 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1691 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1692 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1693 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1694 break;
1695 case GL_VERTEX_ARRAY_STRIDE:
1696 case GL_NORMAL_ARRAY_STRIDE:
1697 case GL_COLOR_ARRAY_STRIDE:
1698 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1699 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1700 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1701 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1702 break;
1703 case GL_VERTEX_ARRAY_SIZE:
1704 case GL_COLOR_ARRAY_SIZE:
1705 case GL_TEXTURE_COORD_ARRAY_SIZE:
1706 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1707 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1708 break;
1709 case GL_VERTEX_ARRAY_TYPE:
1710 case GL_COLOR_ARRAY_TYPE:
1711 case GL_NORMAL_ARRAY_TYPE:
1712 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1713 case GL_TEXTURE_COORD_ARRAY_TYPE:
1714 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1715 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1716 break;
1717
Jamie Madill231c7f52017-04-26 13:45:37 -04001718 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001719 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001720 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001721 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001722}
1723
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001724void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001725{
Shannon Woods53a94a82014-06-24 15:20:36 -04001726 // Queries about context capabilities and maximums are answered by Context.
1727 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001728 switch (pname)
1729 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001730 case GL_MAX_ELEMENT_INDEX:
1731 *params = mCaps.maxElementIndex;
1732 break;
1733 case GL_MAX_UNIFORM_BLOCK_SIZE:
1734 *params = mCaps.maxUniformBlockSize;
1735 break;
1736 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001737 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001738 break;
1739 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001740 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001741 break;
1742 case GL_MAX_SERVER_WAIT_TIMEOUT:
1743 *params = mCaps.maxServerWaitTimeout;
1744 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001745
Jamie Madill231c7f52017-04-26 13:45:37 -04001746 // GL_EXT_disjoint_timer_query
1747 case GL_TIMESTAMP_EXT:
1748 *params = mImplementation->getTimestamp();
1749 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001750
Jamie Madill231c7f52017-04-26 13:45:37 -04001751 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1752 *params = mCaps.maxShaderStorageBlockSize;
1753 break;
1754 default:
1755 UNREACHABLE();
1756 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001757 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001758}
1759
Geoff Lang70d0f492015-12-10 17:45:46 -05001760void Context::getPointerv(GLenum pname, void **params) const
1761{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001762 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001763}
1764
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001765void Context::getPointervRobustANGLERobust(GLenum pname,
1766 GLsizei bufSize,
1767 GLsizei *length,
1768 void **params)
1769{
1770 UNIMPLEMENTED();
1771}
1772
Martin Radev66fb8202016-07-28 11:45:20 +03001773void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001774{
Shannon Woods53a94a82014-06-24 15:20:36 -04001775 // Queries about context capabilities and maximums are answered by Context.
1776 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001777
1778 GLenum nativeType;
1779 unsigned int numParams;
1780 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1781 ASSERT(queryStatus);
1782
1783 if (nativeType == GL_INT)
1784 {
1785 switch (target)
1786 {
1787 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1788 ASSERT(index < 3u);
1789 *data = mCaps.maxComputeWorkGroupCount[index];
1790 break;
1791 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1792 ASSERT(index < 3u);
1793 *data = mCaps.maxComputeWorkGroupSize[index];
1794 break;
1795 default:
1796 mGLState.getIntegeri_v(target, index, data);
1797 }
1798 }
1799 else
1800 {
1801 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1802 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001803}
1804
Brandon Jones59770802018-04-02 13:18:42 -07001805void Context::getIntegeri_vRobust(GLenum target,
1806 GLuint index,
1807 GLsizei bufSize,
1808 GLsizei *length,
1809 GLint *data)
1810{
1811 getIntegeri_v(target, index, data);
1812}
1813
Martin Radev66fb8202016-07-28 11:45:20 +03001814void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001815{
Shannon Woods53a94a82014-06-24 15:20:36 -04001816 // Queries about context capabilities and maximums are answered by Context.
1817 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001818
1819 GLenum nativeType;
1820 unsigned int numParams;
1821 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1822 ASSERT(queryStatus);
1823
1824 if (nativeType == GL_INT_64_ANGLEX)
1825 {
1826 mGLState.getInteger64i_v(target, index, data);
1827 }
1828 else
1829 {
1830 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1831 }
1832}
1833
Brandon Jones59770802018-04-02 13:18:42 -07001834void Context::getInteger64i_vRobust(GLenum target,
1835 GLuint index,
1836 GLsizei bufSize,
1837 GLsizei *length,
1838 GLint64 *data)
1839{
1840 getInteger64i_v(target, index, data);
1841}
1842
Martin Radev66fb8202016-07-28 11:45:20 +03001843void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1844{
1845 // Queries about context capabilities and maximums are answered by Context.
1846 // Queries about current GL state values are answered by State.
1847
1848 GLenum nativeType;
1849 unsigned int numParams;
1850 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1851 ASSERT(queryStatus);
1852
1853 if (nativeType == GL_BOOL)
1854 {
1855 mGLState.getBooleani_v(target, index, data);
1856 }
1857 else
1858 {
1859 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1860 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001861}
1862
Brandon Jones59770802018-04-02 13:18:42 -07001863void Context::getBooleani_vRobust(GLenum target,
1864 GLuint index,
1865 GLsizei bufSize,
1866 GLsizei *length,
1867 GLboolean *data)
1868{
1869 getBooleani_v(target, index, data);
1870}
1871
Corentin Wallez336129f2017-10-17 15:55:40 -04001872void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001873{
1874 Buffer *buffer = mGLState.getTargetBuffer(target);
1875 QueryBufferParameteriv(buffer, pname, params);
1876}
1877
Brandon Jones59770802018-04-02 13:18:42 -07001878void Context::getBufferParameterivRobust(BufferBinding target,
1879 GLenum pname,
1880 GLsizei bufSize,
1881 GLsizei *length,
1882 GLint *params)
1883{
1884 getBufferParameteriv(target, pname, params);
1885}
1886
He Yunchao010e4db2017-03-03 14:22:06 +08001887void Context::getFramebufferAttachmentParameteriv(GLenum target,
1888 GLenum attachment,
1889 GLenum pname,
1890 GLint *params)
1891{
1892 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001893 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001894}
1895
Brandon Jones59770802018-04-02 13:18:42 -07001896void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1897 GLenum attachment,
1898 GLenum pname,
1899 GLsizei bufSize,
1900 GLsizei *length,
1901 GLint *params)
1902{
1903 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1904}
1905
He Yunchao010e4db2017-03-03 14:22:06 +08001906void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1907{
1908 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1909 QueryRenderbufferiv(this, renderbuffer, pname, params);
1910}
1911
Brandon Jones59770802018-04-02 13:18:42 -07001912void Context::getRenderbufferParameterivRobust(GLenum target,
1913 GLenum pname,
1914 GLsizei bufSize,
1915 GLsizei *length,
1916 GLint *params)
1917{
1918 getRenderbufferParameteriv(target, pname, params);
1919}
1920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001921void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001922{
1923 Texture *texture = getTargetTexture(target);
1924 QueryTexParameterfv(texture, pname, params);
1925}
1926
Brandon Jones59770802018-04-02 13:18:42 -07001927void Context::getTexParameterfvRobust(TextureType target,
1928 GLenum pname,
1929 GLsizei bufSize,
1930 GLsizei *length,
1931 GLfloat *params)
1932{
1933 getTexParameterfv(target, pname, params);
1934}
1935
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001936void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001937{
1938 Texture *texture = getTargetTexture(target);
1939 QueryTexParameteriv(texture, pname, params);
1940}
Jiajia Qin5451d532017-11-16 17:16:34 +08001941
Brandon Jones59770802018-04-02 13:18:42 -07001942void Context::getTexParameterivRobust(TextureType target,
1943 GLenum pname,
1944 GLsizei bufSize,
1945 GLsizei *length,
1946 GLint *params)
1947{
1948 getTexParameteriv(target, pname, params);
1949}
1950
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001951void Context::getTexParameterIivRobust(TextureType target,
1952 GLenum pname,
1953 GLsizei bufSize,
1954 GLsizei *length,
1955 GLint *params)
1956{
1957 UNIMPLEMENTED();
1958}
1959
1960void Context::getTexParameterIuivRobust(TextureType target,
1961 GLenum pname,
1962 GLsizei bufSize,
1963 GLsizei *length,
1964 GLuint *params)
1965{
1966 UNIMPLEMENTED();
1967}
1968
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001969void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001970{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001971 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001972 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001973}
1974
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001975void Context::getTexLevelParameterivRobust(TextureTarget target,
1976 GLint level,
1977 GLenum pname,
1978 GLsizei bufSize,
1979 GLsizei *length,
1980 GLint *params)
1981{
1982 UNIMPLEMENTED();
1983}
1984
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001985void Context::getTexLevelParameterfv(TextureTarget target,
1986 GLint level,
1987 GLenum pname,
1988 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001989{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001990 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001991 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001992}
1993
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001994void Context::getTexLevelParameterfvRobust(TextureTarget target,
1995 GLint level,
1996 GLenum pname,
1997 GLsizei bufSize,
1998 GLsizei *length,
1999 GLfloat *params)
2000{
2001 UNIMPLEMENTED();
2002}
2003
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002004void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002005{
2006 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002007 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002008 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002009}
2010
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002011void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002012{
2013 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002014 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002015 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002016}
2017
Brandon Jones59770802018-04-02 13:18:42 -07002018void Context::texParameterfvRobust(TextureType target,
2019 GLenum pname,
2020 GLsizei bufSize,
2021 const GLfloat *params)
2022{
2023 texParameterfv(target, pname, params);
2024}
2025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002026void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002027{
2028 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002029 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002030 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002031}
2032
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002033void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002034{
2035 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002036 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002037 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002038}
2039
Brandon Jones59770802018-04-02 13:18:42 -07002040void Context::texParameterivRobust(TextureType target,
2041 GLenum pname,
2042 GLsizei bufSize,
2043 const GLint *params)
2044{
2045 texParameteriv(target, pname, params);
2046}
2047
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002048void Context::texParameterIivRobust(TextureType target,
2049 GLenum pname,
2050 GLsizei bufSize,
2051 const GLint *params)
2052{
2053 UNIMPLEMENTED();
2054}
2055
2056void Context::texParameterIuivRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 const GLuint *params)
2060{
2061 UNIMPLEMENTED();
2062}
2063
Jamie Madill493f9572018-05-24 19:52:15 -04002064void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002065{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002066 // No-op if zero count
2067 if (count == 0)
2068 {
2069 return;
2070 }
2071
Jamie Madill05b35b22017-10-03 09:01:44 -04002072 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002073 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002074 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002075}
2076
Jamie Madill493f9572018-05-24 19:52:15 -04002077void Context::drawArraysInstanced(PrimitiveMode mode,
2078 GLint first,
2079 GLsizei count,
2080 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002081{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002082 // No-op if zero count
2083 if (count == 0 || instanceCount == 0)
2084 {
2085 return;
2086 }
2087
Jamie Madill05b35b22017-10-03 09:01:44 -04002088 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002089 ANGLE_CONTEXT_TRY(
2090 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002091 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2092 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002093}
2094
Jamie Madill493f9572018-05-24 19:52:15 -04002095void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002096{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002097 // No-op if zero count
2098 if (count == 0)
2099 {
2100 return;
2101 }
2102
Jamie Madill05b35b22017-10-03 09:01:44 -04002103 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002104 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002105}
2106
Jamie Madill493f9572018-05-24 19:52:15 -04002107void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002108 GLsizei count,
2109 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002110 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002111 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002112{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002113 // No-op if zero count
2114 if (count == 0 || instances == 0)
2115 {
2116 return;
2117 }
2118
Jamie Madill05b35b22017-10-03 09:01:44 -04002119 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002120 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002121 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002122}
2123
Jamie Madill493f9572018-05-24 19:52:15 -04002124void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002125 GLuint start,
2126 GLuint end,
2127 GLsizei count,
2128 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002129 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002130{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002131 // No-op if zero count
2132 if (count == 0)
2133 {
2134 return;
2135 }
2136
Jamie Madill05b35b22017-10-03 09:01:44 -04002137 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002138 ANGLE_CONTEXT_TRY(
2139 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002140}
2141
Jamie Madill493f9572018-05-24 19:52:15 -04002142void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002143{
Jamie Madill05b35b22017-10-03 09:01:44 -04002144 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002145 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002146}
2147
Jamie Madill493f9572018-05-24 19:52:15 -04002148void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002149{
Jamie Madill05b35b22017-10-03 09:01:44 -04002150 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002151 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002152}
2153
Jamie Madill675fe712016-12-19 13:07:54 -05002154void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002155{
Jamie Madillafa02a22017-11-23 12:57:38 -05002156 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002157}
2158
Jamie Madill675fe712016-12-19 13:07:54 -05002159void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002160{
Jamie Madillafa02a22017-11-23 12:57:38 -05002161 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002162}
2163
Austin Kinross6ee1e782015-05-29 17:05:37 -07002164void Context::insertEventMarker(GLsizei length, const char *marker)
2165{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002166 ASSERT(mImplementation);
2167 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002168}
2169
2170void Context::pushGroupMarker(GLsizei length, const char *marker)
2171{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002172 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002173
2174 if (marker == nullptr)
2175 {
2176 // From the EXT_debug_marker spec,
2177 // "If <marker> is null then an empty string is pushed on the stack."
2178 mImplementation->pushGroupMarker(length, "");
2179 }
2180 else
2181 {
2182 mImplementation->pushGroupMarker(length, marker);
2183 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002184}
2185
2186void Context::popGroupMarker()
2187{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002188 ASSERT(mImplementation);
2189 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002190}
2191
Geoff Langd8605522016-04-13 10:19:12 -04002192void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2193{
2194 Program *programObject = getProgram(program);
2195 ASSERT(programObject);
2196
2197 programObject->bindUniformLocation(location, name);
2198}
2199
Brandon Jones59770802018-04-02 13:18:42 -07002200void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002201{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002202 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002203}
2204
Brandon Jones59770802018-04-02 13:18:42 -07002205void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002206{
2207 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2208}
2209
Brandon Jones59770802018-04-02 13:18:42 -07002210void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002211{
2212 GLfloat I[16];
2213 angle::Matrix<GLfloat>::setToIdentity(I);
2214
2215 mGLState.loadPathRenderingMatrix(matrixMode, I);
2216}
2217
2218void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2219{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002220 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002221 if (!pathObj)
2222 return;
2223
2224 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002225 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002226
2227 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2228}
2229
2230void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2231{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002232 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233 if (!pathObj)
2234 return;
2235
2236 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002237 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002238
2239 mImplementation->stencilStrokePath(pathObj, reference, mask);
2240}
2241
2242void Context::coverFillPath(GLuint path, GLenum coverMode)
2243{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002244 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002245 if (!pathObj)
2246 return;
2247
2248 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002249 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002250
2251 mImplementation->coverFillPath(pathObj, coverMode);
2252}
2253
2254void Context::coverStrokePath(GLuint path, GLenum coverMode)
2255{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002256 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002257 if (!pathObj)
2258 return;
2259
2260 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002261 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002262
2263 mImplementation->coverStrokePath(pathObj, coverMode);
2264}
2265
2266void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2267{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002268 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002269 if (!pathObj)
2270 return;
2271
2272 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002273 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002274
2275 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2276}
2277
2278void Context::stencilThenCoverStrokePath(GLuint path,
2279 GLint reference,
2280 GLuint mask,
2281 GLenum coverMode)
2282{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002283 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002284 if (!pathObj)
2285 return;
2286
2287 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002288 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002289
2290 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2291}
2292
Sami Väisänend59ca052016-06-21 16:10:00 +03002293void Context::coverFillPathInstanced(GLsizei numPaths,
2294 GLenum pathNameType,
2295 const void *paths,
2296 GLuint pathBase,
2297 GLenum coverMode,
2298 GLenum transformType,
2299 const GLfloat *transformValues)
2300{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002301 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002302
2303 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002304 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002305
2306 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2307}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002308
Sami Väisänend59ca052016-06-21 16:10:00 +03002309void Context::coverStrokePathInstanced(GLsizei numPaths,
2310 GLenum pathNameType,
2311 const void *paths,
2312 GLuint pathBase,
2313 GLenum coverMode,
2314 GLenum transformType,
2315 const GLfloat *transformValues)
2316{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002317 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002318
2319 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002320 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002321
2322 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2323 transformValues);
2324}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002325
Sami Väisänend59ca052016-06-21 16:10:00 +03002326void Context::stencilFillPathInstanced(GLsizei numPaths,
2327 GLenum pathNameType,
2328 const void *paths,
2329 GLuint pathBase,
2330 GLenum fillMode,
2331 GLuint mask,
2332 GLenum transformType,
2333 const GLfloat *transformValues)
2334{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002335 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002336
2337 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002338 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002339
2340 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2341 transformValues);
2342}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002343
Sami Väisänend59ca052016-06-21 16:10:00 +03002344void Context::stencilStrokePathInstanced(GLsizei numPaths,
2345 GLenum pathNameType,
2346 const void *paths,
2347 GLuint pathBase,
2348 GLint reference,
2349 GLuint mask,
2350 GLenum transformType,
2351 const GLfloat *transformValues)
2352{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002353 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002354
2355 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002356 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002357
2358 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2359 transformValues);
2360}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002361
Sami Väisänend59ca052016-06-21 16:10:00 +03002362void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2363 GLenum pathNameType,
2364 const void *paths,
2365 GLuint pathBase,
2366 GLenum fillMode,
2367 GLuint mask,
2368 GLenum coverMode,
2369 GLenum transformType,
2370 const GLfloat *transformValues)
2371{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002372 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002373
2374 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002375 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002376
2377 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2378 transformType, transformValues);
2379}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002380
Sami Väisänend59ca052016-06-21 16:10:00 +03002381void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2382 GLenum pathNameType,
2383 const void *paths,
2384 GLuint pathBase,
2385 GLint reference,
2386 GLuint mask,
2387 GLenum coverMode,
2388 GLenum transformType,
2389 const GLfloat *transformValues)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002392
2393 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002394 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002395
2396 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2397 transformType, transformValues);
2398}
2399
Sami Väisänen46eaa942016-06-29 10:26:37 +03002400void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2401{
2402 auto *programObject = getProgram(program);
2403
2404 programObject->bindFragmentInputLocation(location, name);
2405}
2406
2407void Context::programPathFragmentInputGen(GLuint program,
2408 GLint location,
2409 GLenum genMode,
2410 GLint components,
2411 const GLfloat *coeffs)
2412{
2413 auto *programObject = getProgram(program);
2414
Jamie Madillbd044ed2017-06-05 12:59:21 -04002415 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002416}
2417
jchen1015015f72017-03-16 13:54:21 +08002418GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2419{
jchen10fd7c3b52017-03-21 15:36:03 +08002420 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002421 return QueryProgramResourceIndex(programObject, programInterface, name);
2422}
2423
jchen10fd7c3b52017-03-21 15:36:03 +08002424void Context::getProgramResourceName(GLuint program,
2425 GLenum programInterface,
2426 GLuint index,
2427 GLsizei bufSize,
2428 GLsizei *length,
2429 GLchar *name)
2430{
2431 const auto *programObject = getProgram(program);
2432 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2433}
2434
jchen10191381f2017-04-11 13:59:04 +08002435GLint Context::getProgramResourceLocation(GLuint program,
2436 GLenum programInterface,
2437 const GLchar *name)
2438{
2439 const auto *programObject = getProgram(program);
2440 return QueryProgramResourceLocation(programObject, programInterface, name);
2441}
2442
jchen10880683b2017-04-12 16:21:55 +08002443void Context::getProgramResourceiv(GLuint program,
2444 GLenum programInterface,
2445 GLuint index,
2446 GLsizei propCount,
2447 const GLenum *props,
2448 GLsizei bufSize,
2449 GLsizei *length,
2450 GLint *params)
2451{
2452 const auto *programObject = getProgram(program);
2453 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2454 length, params);
2455}
2456
jchen10d9cd7b72017-08-30 15:04:25 +08002457void Context::getProgramInterfaceiv(GLuint program,
2458 GLenum programInterface,
2459 GLenum pname,
2460 GLint *params)
2461{
2462 const auto *programObject = getProgram(program);
2463 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2464}
2465
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002466void Context::getProgramInterfaceivRobust(GLuint program,
2467 GLenum programInterface,
2468 GLenum pname,
2469 GLsizei bufSize,
2470 GLsizei *length,
2471 GLint *params)
2472{
2473 UNIMPLEMENTED();
2474}
2475
Jamie Madill427064d2018-04-13 16:20:34 -04002476void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002477{
Geoff Lang7b19a492018-04-20 09:31:52 -04002478 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002479 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002480 GLenum code = error.getCode();
2481 mErrors.insert(code);
2482 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2483 {
2484 markContextLost();
2485 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002486
Geoff Langee6884e2017-11-09 16:51:11 -05002487 ASSERT(!error.getMessage().empty());
2488 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2489 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002490 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002491}
2492
2493// Get one of the recorded errors and clear its flag, if any.
2494// [OpenGL ES 2.0.24] section 2.5 page 13.
2495GLenum Context::getError()
2496{
Geoff Langda5777c2014-07-11 09:52:58 -04002497 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498 {
Geoff Langda5777c2014-07-11 09:52:58 -04002499 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002500 }
Geoff Langda5777c2014-07-11 09:52:58 -04002501 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002502 {
Geoff Langda5777c2014-07-11 09:52:58 -04002503 GLenum error = *mErrors.begin();
2504 mErrors.erase(mErrors.begin());
2505 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002506 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002507}
2508
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002509// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002510void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002511{
2512 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002513 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002514 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002515 mContextLostForced = true;
2516 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002517 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002518}
2519
Jamie Madill427064d2018-04-13 16:20:34 -04002520bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002521{
2522 return mContextLost;
2523}
2524
Jamie Madillfa920eb2018-01-04 11:45:50 -05002525GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002526{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002527 // Even if the application doesn't want to know about resets, we want to know
2528 // as it will allow us to skip all the calls.
2529 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002532 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002533 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002534 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535
2536 // EXT_robustness, section 2.6: If the reset notification behavior is
2537 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2538 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2539 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002540 }
2541
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2543 // status should be returned at least once, and GL_NO_ERROR should be returned
2544 // once the device has finished resetting.
2545 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002546 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002547 ASSERT(mResetStatus == GL_NO_ERROR);
2548 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002549
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002550 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002551 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002552 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002553 }
2554 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002555 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002556 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002557 // If markContextLost was used to mark the context lost then
2558 // assume that is not recoverable, and continue to report the
2559 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002560 mResetStatus = mImplementation->getResetStatus();
2561 }
Jamie Madill893ab082014-05-16 16:56:10 -04002562
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002563 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002564}
2565
2566bool Context::isResetNotificationEnabled()
2567{
2568 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2569}
2570
Corentin Walleze3b10e82015-05-20 11:06:25 -04002571const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002572{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002573 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002574}
2575
2576EGLenum Context::getClientType() const
2577{
2578 return mClientType;
2579}
2580
2581EGLenum Context::getRenderBuffer() const
2582{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002583 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2584 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002585 {
2586 return EGL_NONE;
2587 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002588
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002589 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002590 ASSERT(backAttachment != nullptr);
2591 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002592}
2593
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002594VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002595{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002596 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002597 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2598 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002599 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002600 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2601 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002602
Jamie Madill96a483b2017-06-27 16:49:21 -04002603 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002604 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002605
2606 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002607}
2608
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002609TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002610{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002611 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2613 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002614 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002615 transformFeedback =
2616 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002617 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002618 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002619 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002620
2621 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002622}
2623
2624bool Context::isVertexArrayGenerated(GLuint vertexArray)
2625{
Jamie Madill96a483b2017-06-27 16:49:21 -04002626 ASSERT(mVertexArrayMap.contains(0));
2627 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002628}
2629
2630bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2631{
Jamie Madill96a483b2017-06-27 16:49:21 -04002632 ASSERT(mTransformFeedbackMap.contains(0));
2633 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002634}
2635
Shannon Woods53a94a82014-06-24 15:20:36 -04002636void Context::detachTexture(GLuint texture)
2637{
2638 // Simple pass-through to State's detachTexture method, as textures do not require
2639 // allocation map management either here or in the resource manager at detach time.
2640 // Zero textures are held by the Context, and we don't attempt to request them from
2641 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002642 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002643}
2644
James Darpinian4d9d4832018-03-13 12:43:28 -07002645void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646{
Yuly Novikov5807a532015-12-03 13:01:22 -05002647 // Simple pass-through to State's detachBuffer method, since
2648 // only buffer attachments to container objects that are bound to the current context
2649 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002650
Yuly Novikov5807a532015-12-03 13:01:22 -05002651 // [OpenGL ES 3.2] section 5.1.2 page 45:
2652 // Attachments to unbound container objects, such as
2653 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2654 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002655 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656}
2657
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002658void Context::detachFramebuffer(GLuint framebuffer)
2659{
Shannon Woods53a94a82014-06-24 15:20:36 -04002660 // Framebuffer detachment is handled by Context, because 0 is a valid
2661 // Framebuffer object, and a pointer to it must be passed from Context
2662 // to State at binding time.
2663
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002665 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2666 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2667 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002669 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670 {
2671 bindReadFramebuffer(0);
2672 }
2673
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002674 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002675 {
2676 bindDrawFramebuffer(0);
2677 }
2678}
2679
2680void Context::detachRenderbuffer(GLuint renderbuffer)
2681{
Jamie Madilla02315b2017-02-23 14:14:47 -05002682 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002683}
2684
Jamie Madill57a89722013-07-02 11:57:03 -04002685void Context::detachVertexArray(GLuint vertexArray)
2686{
Jamie Madill77a72f62015-04-14 11:18:32 -04002687 // Vertex array detachment is handled by Context, because 0 is a valid
2688 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002689 // binding time.
2690
Jamie Madill57a89722013-07-02 11:57:03 -04002691 // [OpenGL ES 3.0.2] section 2.10 page 43:
2692 // If a vertex array object that is currently bound is deleted, the binding
2693 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002694 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002695 {
2696 bindVertexArray(0);
2697 }
2698}
2699
Geoff Langc8058452014-02-03 12:04:11 -05002700void Context::detachTransformFeedback(GLuint transformFeedback)
2701{
Corentin Walleza2257da2016-04-19 16:43:12 -04002702 // Transform feedback detachment is handled by Context, because 0 is a valid
2703 // transform feedback, and a pointer to it must be passed from Context to State at
2704 // binding time.
2705
2706 // The OpenGL specification doesn't mention what should happen when the currently bound
2707 // transform feedback object is deleted. Since it is a container object, we treat it like
2708 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002709 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002710 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002711 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002712 }
Geoff Langc8058452014-02-03 12:04:11 -05002713}
2714
Jamie Madilldc356042013-07-19 16:36:57 -04002715void Context::detachSampler(GLuint sampler)
2716{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002717 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002718}
2719
Yunchao Hea336b902017-08-02 16:05:21 +08002720void Context::detachProgramPipeline(GLuint pipeline)
2721{
2722 mGLState.detachProgramPipeline(this, pipeline);
2723}
2724
Jamie Madill3ef140a2017-08-26 23:11:21 -04002725void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002726{
Shaodde78e82017-05-22 14:13:27 +08002727 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002728}
2729
Jamie Madille29d1672013-07-19 16:36:57 -04002730void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2731{
Geoff Langc1984ed2016-10-07 12:41:00 -04002732 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002733 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002734 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002735 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002736}
Jamie Madille29d1672013-07-19 16:36:57 -04002737
Geoff Langc1984ed2016-10-07 12:41:00 -04002738void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2739{
2740 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002741 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002742 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002743 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002744}
2745
Brandon Jones59770802018-04-02 13:18:42 -07002746void Context::samplerParameterivRobust(GLuint sampler,
2747 GLenum pname,
2748 GLsizei bufSize,
2749 const GLint *param)
2750{
2751 samplerParameteriv(sampler, pname, param);
2752}
2753
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002754void Context::samplerParameterIivRobust(GLuint sampler,
2755 GLenum pname,
2756 GLsizei bufSize,
2757 const GLint *param)
2758{
2759 UNIMPLEMENTED();
2760}
2761
2762void Context::samplerParameterIuivRobust(GLuint sampler,
2763 GLenum pname,
2764 GLsizei bufSize,
2765 const GLuint *param)
2766{
2767 UNIMPLEMENTED();
2768}
2769
Jamie Madille29d1672013-07-19 16:36:57 -04002770void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2771{
Geoff Langc1984ed2016-10-07 12:41:00 -04002772 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002773 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002774 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002775 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002776}
2777
Geoff Langc1984ed2016-10-07 12:41:00 -04002778void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002779{
Geoff Langc1984ed2016-10-07 12:41:00 -04002780 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002781 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002782 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002783 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002784}
2785
Brandon Jones59770802018-04-02 13:18:42 -07002786void Context::samplerParameterfvRobust(GLuint sampler,
2787 GLenum pname,
2788 GLsizei bufSize,
2789 const GLfloat *param)
2790{
2791 samplerParameterfv(sampler, pname, param);
2792}
2793
Geoff Langc1984ed2016-10-07 12:41:00 -04002794void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002795{
Geoff Langc1984ed2016-10-07 12:41:00 -04002796 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002797 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002798 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002799 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002800}
Jamie Madill9675b802013-07-19 16:36:59 -04002801
Brandon Jones59770802018-04-02 13:18:42 -07002802void Context::getSamplerParameterivRobust(GLuint sampler,
2803 GLenum pname,
2804 GLsizei bufSize,
2805 GLsizei *length,
2806 GLint *params)
2807{
2808 getSamplerParameteriv(sampler, pname, params);
2809}
2810
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002811void Context::getSamplerParameterIivRobust(GLuint sampler,
2812 GLenum pname,
2813 GLsizei bufSize,
2814 GLsizei *length,
2815 GLint *params)
2816{
2817 UNIMPLEMENTED();
2818}
2819
2820void Context::getSamplerParameterIuivRobust(GLuint sampler,
2821 GLenum pname,
2822 GLsizei bufSize,
2823 GLsizei *length,
2824 GLuint *params)
2825{
2826 UNIMPLEMENTED();
2827}
2828
Geoff Langc1984ed2016-10-07 12:41:00 -04002829void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2830{
2831 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002832 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002833 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002834 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002835}
2836
Brandon Jones59770802018-04-02 13:18:42 -07002837void Context::getSamplerParameterfvRobust(GLuint sampler,
2838 GLenum pname,
2839 GLsizei bufSize,
2840 GLsizei *length,
2841 GLfloat *params)
2842{
2843 getSamplerParameterfv(sampler, pname, params);
2844}
2845
Olli Etuahof0fee072016-03-30 15:11:58 +03002846void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2847{
2848 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002849 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002850}
2851
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002852void Context::initRendererString()
2853{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002854 std::ostringstream rendererString;
2855 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002856 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002857 rendererString << ")";
2858
Geoff Langcec35902014-04-16 10:52:36 -04002859 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002860}
2861
Geoff Langc339c4e2016-11-29 10:37:36 -05002862void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002863{
Geoff Langc339c4e2016-11-29 10:37:36 -05002864 const Version &clientVersion = getClientVersion();
2865
2866 std::ostringstream versionString;
2867 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2868 << ANGLE_VERSION_STRING << ")";
2869 mVersionString = MakeStaticString(versionString.str());
2870
2871 std::ostringstream shadingLanguageVersionString;
2872 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2873 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2874 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2875 << ")";
2876 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002877}
2878
Geoff Langcec35902014-04-16 10:52:36 -04002879void Context::initExtensionStrings()
2880{
Geoff Langc339c4e2016-11-29 10:37:36 -05002881 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2882 std::ostringstream combinedStringStream;
2883 std::copy(strings.begin(), strings.end(),
2884 std::ostream_iterator<const char *>(combinedStringStream, " "));
2885 return MakeStaticString(combinedStringStream.str());
2886 };
2887
2888 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002889 for (const auto &extensionString : mExtensions.getStrings())
2890 {
2891 mExtensionStrings.push_back(MakeStaticString(extensionString));
2892 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002893 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002894
Geoff Langc339c4e2016-11-29 10:37:36 -05002895 mRequestableExtensionStrings.clear();
2896 for (const auto &extensionInfo : GetExtensionInfoMap())
2897 {
2898 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002899 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002900 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002901 {
2902 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2903 }
2904 }
2905 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002906}
2907
Geoff Langc339c4e2016-11-29 10:37:36 -05002908const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002909{
Geoff Langc339c4e2016-11-29 10:37:36 -05002910 switch (name)
2911 {
2912 case GL_VENDOR:
2913 return reinterpret_cast<const GLubyte *>("Google Inc.");
2914
2915 case GL_RENDERER:
2916 return reinterpret_cast<const GLubyte *>(mRendererString);
2917
2918 case GL_VERSION:
2919 return reinterpret_cast<const GLubyte *>(mVersionString);
2920
2921 case GL_SHADING_LANGUAGE_VERSION:
2922 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2923
2924 case GL_EXTENSIONS:
2925 return reinterpret_cast<const GLubyte *>(mExtensionString);
2926
2927 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2928 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2929
2930 default:
2931 UNREACHABLE();
2932 return nullptr;
2933 }
Geoff Langcec35902014-04-16 10:52:36 -04002934}
2935
Geoff Langc339c4e2016-11-29 10:37:36 -05002936const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002937{
Geoff Langc339c4e2016-11-29 10:37:36 -05002938 switch (name)
2939 {
2940 case GL_EXTENSIONS:
2941 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2942
2943 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2944 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2945
2946 default:
2947 UNREACHABLE();
2948 return nullptr;
2949 }
Geoff Langcec35902014-04-16 10:52:36 -04002950}
2951
2952size_t Context::getExtensionStringCount() const
2953{
2954 return mExtensionStrings.size();
2955}
2956
Geoff Lang111a99e2017-10-17 10:58:41 -04002957bool Context::isExtensionRequestable(const char *name)
2958{
2959 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2960 auto extension = extensionInfos.find(name);
2961
Geoff Lang111a99e2017-10-17 10:58:41 -04002962 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002963 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002964}
2965
Geoff Langc339c4e2016-11-29 10:37:36 -05002966void Context::requestExtension(const char *name)
2967{
2968 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2969 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2970 const auto &extension = extensionInfos.at(name);
2971 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002972 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002973
2974 if (mExtensions.*(extension.ExtensionsMember))
2975 {
2976 // Extension already enabled
2977 return;
2978 }
2979
2980 mExtensions.*(extension.ExtensionsMember) = true;
2981 updateCaps();
2982 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002983
Jamie Madill2f348d22017-06-05 10:50:59 -04002984 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2985 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002986
Jamie Madill81c2e252017-09-09 23:32:46 -04002987 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2988 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002989 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002990 for (auto &zeroTexture : mZeroTextures)
2991 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002992 if (zeroTexture.get() != nullptr)
2993 {
2994 zeroTexture->signalDirty(this, InitState::Initialized);
2995 }
Geoff Lang9aded172017-04-05 11:07:56 -04002996 }
2997
2998 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002999}
3000
3001size_t Context::getRequestableExtensionStringCount() const
3002{
3003 return mRequestableExtensionStrings.size();
3004}
3005
Jamie Madill493f9572018-05-24 19:52:15 -04003006void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003007{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003008 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003009 ASSERT(transformFeedback != nullptr);
3010 ASSERT(!transformFeedback->isPaused());
3011
Jamie Madill6c1f6712017-02-14 19:08:04 -05003012 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003013}
3014
3015bool Context::hasActiveTransformFeedback(GLuint program) const
3016{
3017 for (auto pair : mTransformFeedbackMap)
3018 {
3019 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3020 {
3021 return true;
3022 }
3023 }
3024 return false;
3025}
3026
Geoff Lang33f11fb2018-05-07 13:42:47 -04003027Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003028{
3029 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3030
3031 if (getClientVersion() < ES_2_0)
3032 {
3033 // Default extensions for GLES1
3034 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003035 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003036 }
3037
3038 if (getClientVersion() < ES_3_0)
3039 {
3040 // Disable ES3+ extensions
3041 supportedExtensions.colorBufferFloat = false;
3042 supportedExtensions.eglImageExternalEssl3 = false;
3043 supportedExtensions.textureNorm16 = false;
3044 supportedExtensions.multiview = false;
3045 supportedExtensions.maxViews = 1u;
3046 }
3047
3048 if (getClientVersion() < ES_3_1)
3049 {
3050 // Disable ES3.1+ extensions
3051 supportedExtensions.geometryShader = false;
3052 }
3053
3054 if (getClientVersion() > ES_2_0)
3055 {
3056 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3057 // supportedExtensions.sRGB = false;
3058 }
3059
3060 // Some extensions are always available because they are implemented in the GL layer.
3061 supportedExtensions.bindUniformLocation = true;
3062 supportedExtensions.vertexArrayObject = true;
3063 supportedExtensions.bindGeneratesResource = true;
3064 supportedExtensions.clientArrays = true;
3065 supportedExtensions.requestExtension = true;
3066
3067 // Enable the no error extension if the context was created with the flag.
3068 supportedExtensions.noError = mSkipValidation;
3069
3070 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003071 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003072
3073 // Explicitly enable GL_KHR_debug
3074 supportedExtensions.debug = true;
3075 supportedExtensions.maxDebugMessageLength = 1024;
3076 supportedExtensions.maxDebugLoggedMessages = 1024;
3077 supportedExtensions.maxDebugGroupStackDepth = 1024;
3078 supportedExtensions.maxLabelLength = 1024;
3079
3080 // Explicitly enable GL_ANGLE_robust_client_memory
3081 supportedExtensions.robustClientMemory = true;
3082
3083 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003084 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003085
3086 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3087 // supports it.
3088 supportedExtensions.robustBufferAccessBehavior =
3089 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3090
3091 // Enable the cache control query unconditionally.
3092 supportedExtensions.programCacheControl = true;
3093
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003094 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003095 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003096 {
3097 // GL_ANGLE_explicit_context_gles1
3098 supportedExtensions.explicitContextGles1 = true;
3099 // GL_ANGLE_explicit_context
3100 supportedExtensions.explicitContext = true;
3101 }
3102
Geoff Langb0f917f2017-12-05 13:41:54 -05003103 return supportedExtensions;
3104}
3105
Geoff Lang33f11fb2018-05-07 13:42:47 -04003106void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003107{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003108 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003109
Geoff Lang33f11fb2018-05-07 13:42:47 -04003110 mSupportedExtensions = generateSupportedExtensions();
3111 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003112
3113 mLimitations = mImplementation->getNativeLimitations();
3114
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003115 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3116 if (getClientVersion() < Version(2, 0))
3117 {
3118 mCaps.maxMultitextureUnits = 4;
3119 mCaps.maxClipPlanes = 6;
3120 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003121 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3122 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3123 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003124 }
3125
Geoff Lang301d1612014-07-09 10:34:37 -04003126 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003127 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003128
Jamie Madill0f80ed82017-09-19 00:24:56 -04003129 if (getClientVersion() < ES_3_1)
3130 {
3131 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3132 }
3133 else
3134 {
3135 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3136 }
Geoff Lang301d1612014-07-09 10:34:37 -04003137
Jiawei Shao54aafe52018-04-27 14:54:57 +08003138 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3139 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003140 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3141 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3142
3143 // Limit textures as well, so we can use fast bitsets with texture bindings.
3144 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003145 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3146 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3147 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3148 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003149
Jiawei Shaodb342272017-09-27 10:21:45 +08003150 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3151
Geoff Langc287ea62016-09-16 14:46:51 -04003152 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003153 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003154 for (const auto &extensionInfo : GetExtensionInfoMap())
3155 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003156 // If the user has requested that extensions start disabled and they are requestable,
3157 // disable them.
3158 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003159 {
3160 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3161 }
3162 }
3163
3164 // Generate texture caps
3165 updateCaps();
3166}
3167
3168void Context::updateCaps()
3169{
Geoff Lang900013c2014-07-07 11:32:19 -04003170 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003171 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003172
Jamie Madill7b62cf92017-11-02 15:20:49 -04003173 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003174 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003175 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003176 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003177
Geoff Lang0d8b7242015-09-09 14:56:53 -04003178 // Update the format caps based on the client version and extensions.
3179 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3180 // ES3.
3181 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003182 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003183 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003184 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003185 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003186 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003187
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003188 // OpenGL ES does not support multisampling with non-rendererable formats
3189 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003190 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003191 (getClientVersion() < ES_3_1 &&
3192 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003193 {
Geoff Langd87878e2014-09-19 15:42:59 -04003194 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003195 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003196 else
3197 {
3198 // We may have limited the max samples for some required renderbuffer formats due to
3199 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3200 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3201
3202 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3203 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3204 // exception of signed and unsigned integer formats."
3205 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3206 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3207 {
3208 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3209 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3210 }
3211
3212 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3213 if (getClientVersion() >= ES_3_1)
3214 {
3215 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3216 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3217 // the exception that the signed and unsigned integer formats are required only to
3218 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3219 // multisamples, which must be at least one."
3220 if (formatInfo.componentType == GL_INT ||
3221 formatInfo.componentType == GL_UNSIGNED_INT)
3222 {
3223 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3224 }
3225
3226 // GLES 3.1 section 19.3.1.
3227 if (formatCaps.texturable)
3228 {
3229 if (formatInfo.depthBits > 0)
3230 {
3231 mCaps.maxDepthTextureSamples =
3232 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3233 }
3234 else if (formatInfo.redBits > 0)
3235 {
3236 mCaps.maxColorTextureSamples =
3237 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3238 }
3239 }
3240 }
3241 }
Geoff Langd87878e2014-09-19 15:42:59 -04003242
3243 if (formatCaps.texturable && formatInfo.compressed)
3244 {
Geoff Langca271392017-04-05 12:30:00 -04003245 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003246 }
3247
Geoff Langca271392017-04-05 12:30:00 -04003248 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003249 }
Jamie Madill32447362017-06-28 14:53:52 -04003250
3251 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003252 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003253 {
3254 mMemoryProgramCache = nullptr;
3255 }
Corentin Walleze4477002017-12-01 14:39:58 -05003256
3257 // Compute which buffer types are allowed
3258 mValidBufferBindings.reset();
3259 mValidBufferBindings.set(BufferBinding::ElementArray);
3260 mValidBufferBindings.set(BufferBinding::Array);
3261
3262 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3263 {
3264 mValidBufferBindings.set(BufferBinding::PixelPack);
3265 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3266 }
3267
3268 if (getClientVersion() >= ES_3_0)
3269 {
3270 mValidBufferBindings.set(BufferBinding::CopyRead);
3271 mValidBufferBindings.set(BufferBinding::CopyWrite);
3272 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3273 mValidBufferBindings.set(BufferBinding::Uniform);
3274 }
3275
3276 if (getClientVersion() >= ES_3_1)
3277 {
3278 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3279 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3280 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3281 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3282 }
Geoff Lang493daf52014-07-03 13:38:44 -04003283}
3284
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003285void Context::initWorkarounds()
3286{
Jamie Madill761b02c2017-06-23 16:27:06 -04003287 // Apply back-end workarounds.
3288 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3289
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003290 // Lose the context upon out of memory error if the application is
3291 // expecting to watch for those events.
3292 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3293}
3294
Jamie Madill05b35b22017-10-03 09:01:44 -04003295Error Context::prepareForDraw()
3296{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003297 if (mGLES1Renderer)
3298 {
3299 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3300 }
3301
Geoff Langa8cb2872018-03-09 16:09:40 -05003302 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003303
3304 if (isRobustResourceInitEnabled())
3305 {
3306 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3307 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3308 }
3309
Geoff Langa8cb2872018-03-09 16:09:40 -05003310 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003311 return NoError();
3312}
3313
3314Error Context::prepareForClear(GLbitfield mask)
3315{
Geoff Langa8cb2872018-03-09 16:09:40 -05003316 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003317 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003318 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003319 return NoError();
3320}
3321
3322Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
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()->ensureClearBufferAttachmentsInitialized(this, buffer,
3326 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003327 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003328 return NoError();
3329}
3330
Geoff Langa8cb2872018-03-09 16:09:40 -05003331Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003332{
Geoff Langa8cb2872018-03-09 16:09:40 -05003333 ANGLE_TRY(syncDirtyObjects());
3334 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003335 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003336}
3337
Geoff Langa8cb2872018-03-09 16:09:40 -05003338Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003339{
Geoff Langa8cb2872018-03-09 16:09:40 -05003340 ANGLE_TRY(syncDirtyObjects(objectMask));
3341 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003342 return NoError();
3343}
3344
Geoff Langa8cb2872018-03-09 16:09:40 -05003345Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003346{
3347 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3348 mImplementation->syncState(this, dirtyBits);
3349 mGLState.clearDirtyBits();
3350 return NoError();
3351}
3352
Geoff Langa8cb2872018-03-09 16:09:40 -05003353Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003355 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003356 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003357 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003358 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003359}
Jamie Madillc29968b2016-01-20 11:17:23 -05003360
Geoff Langa8cb2872018-03-09 16:09:40 -05003361Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003362{
3363 return mGLState.syncDirtyObjects(this);
3364}
3365
Geoff Langa8cb2872018-03-09 16:09:40 -05003366Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003367{
3368 return mGLState.syncDirtyObjects(this, objectMask);
3369}
3370
Jamie Madillc29968b2016-01-20 11:17:23 -05003371void Context::blitFramebuffer(GLint srcX0,
3372 GLint srcY0,
3373 GLint srcX1,
3374 GLint srcY1,
3375 GLint dstX0,
3376 GLint dstY0,
3377 GLint dstX1,
3378 GLint dstY1,
3379 GLbitfield mask,
3380 GLenum filter)
3381{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003382 if (mask == 0)
3383 {
3384 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3385 // buffers are copied.
3386 return;
3387 }
3388
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003389 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003390 ASSERT(drawFramebuffer);
3391
3392 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3393 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3394
Jamie Madillbc918e72018-03-08 09:47:21 -05003395 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003396
Jamie Madillc564c072017-06-01 12:45:42 -04003397 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003398}
Jamie Madillc29968b2016-01-20 11:17:23 -05003399
3400void Context::clear(GLbitfield mask)
3401{
Geoff Langd4fff502017-09-22 11:28:28 -04003402 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3403 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003404}
3405
3406void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3407{
Geoff Langd4fff502017-09-22 11:28:28 -04003408 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3409 ANGLE_CONTEXT_TRY(
3410 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003411}
3412
3413void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3414{
Geoff Langd4fff502017-09-22 11:28:28 -04003415 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3416 ANGLE_CONTEXT_TRY(
3417 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003418}
3419
3420void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3421{
Geoff Langd4fff502017-09-22 11:28:28 -04003422 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3423 ANGLE_CONTEXT_TRY(
3424 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003425}
3426
3427void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003429 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003430 ASSERT(framebufferObject);
3431
3432 // If a buffer is not present, the clear has no effect
3433 if (framebufferObject->getDepthbuffer() == nullptr &&
3434 framebufferObject->getStencilbuffer() == nullptr)
3435 {
3436 return;
3437 }
3438
Geoff Langd4fff502017-09-22 11:28:28 -04003439 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3440 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003441}
3442
3443void Context::readPixels(GLint x,
3444 GLint y,
3445 GLsizei width,
3446 GLsizei height,
3447 GLenum format,
3448 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003449 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003450{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003451 if (width == 0 || height == 0)
3452 {
3453 return;
3454 }
3455
Jamie Madillbc918e72018-03-08 09:47:21 -05003456 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003457
Jamie Madillb6664922017-07-25 12:55:04 -04003458 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3459 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003460
3461 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003462 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003463}
3464
Brandon Jones59770802018-04-02 13:18:42 -07003465void Context::readPixelsRobust(GLint x,
3466 GLint y,
3467 GLsizei width,
3468 GLsizei height,
3469 GLenum format,
3470 GLenum type,
3471 GLsizei bufSize,
3472 GLsizei *length,
3473 GLsizei *columns,
3474 GLsizei *rows,
3475 void *pixels)
3476{
3477 readPixels(x, y, width, height, format, type, pixels);
3478}
3479
3480void Context::readnPixelsRobust(GLint x,
3481 GLint y,
3482 GLsizei width,
3483 GLsizei height,
3484 GLenum format,
3485 GLenum type,
3486 GLsizei bufSize,
3487 GLsizei *length,
3488 GLsizei *columns,
3489 GLsizei *rows,
3490 void *data)
3491{
3492 readPixels(x, y, width, height, format, type, data);
3493}
3494
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003495void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003496 GLint level,
3497 GLenum internalformat,
3498 GLint x,
3499 GLint y,
3500 GLsizei width,
3501 GLsizei height,
3502 GLint border)
3503{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003504 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003505 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003506
Jamie Madillc29968b2016-01-20 11:17:23 -05003507 Rectangle sourceArea(x, y, width, height);
3508
Jamie Madill05b35b22017-10-03 09:01:44 -04003509 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003510 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003511 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003512}
3513
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003514void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003515 GLint level,
3516 GLint xoffset,
3517 GLint yoffset,
3518 GLint x,
3519 GLint y,
3520 GLsizei width,
3521 GLsizei height)
3522{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003523 if (width == 0 || height == 0)
3524 {
3525 return;
3526 }
3527
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003528 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003529 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003530
Jamie Madillc29968b2016-01-20 11:17:23 -05003531 Offset destOffset(xoffset, yoffset, 0);
3532 Rectangle sourceArea(x, y, width, height);
3533
Jamie Madill05b35b22017-10-03 09:01:44 -04003534 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003535 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003536 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003537}
3538
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003539void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003540 GLint level,
3541 GLint xoffset,
3542 GLint yoffset,
3543 GLint zoffset,
3544 GLint x,
3545 GLint y,
3546 GLsizei width,
3547 GLsizei height)
3548{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003549 if (width == 0 || height == 0)
3550 {
3551 return;
3552 }
3553
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003554 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003555 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003556
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 Offset destOffset(xoffset, yoffset, zoffset);
3558 Rectangle sourceArea(x, y, width, height);
3559
Jamie Madill05b35b22017-10-03 09:01:44 -04003560 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3561 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003562 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3563 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003564}
3565
3566void Context::framebufferTexture2D(GLenum target,
3567 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003568 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003569 GLuint texture,
3570 GLint level)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003573 ASSERT(framebuffer);
3574
3575 if (texture != 0)
3576 {
3577 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003578 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003579 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003580 }
3581 else
3582 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003583 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003584 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003585
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003587}
3588
3589void Context::framebufferRenderbuffer(GLenum target,
3590 GLenum attachment,
3591 GLenum renderbuffertarget,
3592 GLuint renderbuffer)
3593{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003594 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003595 ASSERT(framebuffer);
3596
3597 if (renderbuffer != 0)
3598 {
3599 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003600
Jamie Madillcc129372018-04-12 09:13:18 -04003601 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003602 renderbufferObject);
3603 }
3604 else
3605 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003606 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003607 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003608
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003609 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610}
3611
3612void Context::framebufferTextureLayer(GLenum target,
3613 GLenum attachment,
3614 GLuint texture,
3615 GLint level,
3616 GLint layer)
3617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003619 ASSERT(framebuffer);
3620
3621 if (texture != 0)
3622 {
3623 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003624 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003625 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 }
3627 else
3628 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003629 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003630 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003631
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003632 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003633}
3634
Brandon Jones59770802018-04-02 13:18:42 -07003635void Context::framebufferTextureMultiviewLayered(GLenum target,
3636 GLenum attachment,
3637 GLuint texture,
3638 GLint level,
3639 GLint baseViewIndex,
3640 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003641{
Martin Radev82ef7742017-08-08 17:44:58 +03003642 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3643 ASSERT(framebuffer);
3644
3645 if (texture != 0)
3646 {
3647 Texture *textureObj = getTexture(texture);
3648
Martin Radev18b75ba2017-08-15 15:50:40 +03003649 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003650 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3651 numViews, baseViewIndex);
3652 }
3653 else
3654 {
3655 framebuffer->resetAttachment(this, attachment);
3656 }
3657
3658 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003659}
3660
Brandon Jones59770802018-04-02 13:18:42 -07003661void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3662 GLenum attachment,
3663 GLuint texture,
3664 GLint level,
3665 GLsizei numViews,
3666 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003667{
Martin Radev5dae57b2017-07-14 16:15:55 +03003668 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3669 ASSERT(framebuffer);
3670
3671 if (texture != 0)
3672 {
3673 Texture *textureObj = getTexture(texture);
3674
3675 ImageIndex index = ImageIndex::Make2D(level);
3676 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3677 textureObj, numViews, viewportOffsets);
3678 }
3679 else
3680 {
3681 framebuffer->resetAttachment(this, attachment);
3682 }
3683
3684 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003685}
3686
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003687// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3688void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3689{
3690 UNIMPLEMENTED();
3691}
3692
Jamie Madillc29968b2016-01-20 11:17:23 -05003693void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3694{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 ASSERT(framebuffer);
3697 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003699}
3700
3701void Context::readBuffer(GLenum mode)
3702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003704 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706}
3707
3708void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3709{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003710 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003711 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003712
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003714 ASSERT(framebuffer);
3715
3716 // The specification isn't clear what should be done when the framebuffer isn't complete.
3717 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003718 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003719}
3720
3721void Context::invalidateFramebuffer(GLenum target,
3722 GLsizei numAttachments,
3723 const GLenum *attachments)
3724{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003726 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003727
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 ASSERT(framebuffer);
3730
Jamie Madill427064d2018-04-13 16:20:34 -04003731 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 {
Jamie Madill437fa652016-05-03 15:13:24 -04003733 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 }
Jamie Madill437fa652016-05-03 15:13:24 -04003735
Jamie Madill4928b7c2017-06-20 12:57:39 -04003736 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003737}
3738
3739void Context::invalidateSubFramebuffer(GLenum target,
3740 GLsizei numAttachments,
3741 const GLenum *attachments,
3742 GLint x,
3743 GLint y,
3744 GLsizei width,
3745 GLsizei height)
3746{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003748 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003749
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 ASSERT(framebuffer);
3752
Jamie Madill427064d2018-04-13 16:20:34 -04003753 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003754 {
Jamie Madill437fa652016-05-03 15:13:24 -04003755 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003756 }
Jamie Madill437fa652016-05-03 15:13:24 -04003757
3758 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003759 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003762void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003763 GLint level,
3764 GLint internalformat,
3765 GLsizei width,
3766 GLsizei height,
3767 GLint border,
3768 GLenum format,
3769 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003770 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003771{
Jamie Madillbc918e72018-03-08 09:47:21 -05003772 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003773
3774 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003775 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003776 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3777 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003778}
3779
Brandon Jones59770802018-04-02 13:18:42 -07003780void Context::texImage2DRobust(TextureTarget target,
3781 GLint level,
3782 GLint internalformat,
3783 GLsizei width,
3784 GLsizei height,
3785 GLint border,
3786 GLenum format,
3787 GLenum type,
3788 GLsizei bufSize,
3789 const void *pixels)
3790{
3791 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3792}
3793
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003794void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003795 GLint level,
3796 GLint internalformat,
3797 GLsizei width,
3798 GLsizei height,
3799 GLsizei depth,
3800 GLint border,
3801 GLenum format,
3802 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003803 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003804{
Jamie Madillbc918e72018-03-08 09:47:21 -05003805 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003806
3807 Extents size(width, height, depth);
3808 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003809 handleError(texture->setImage(this, mGLState.getUnpackState(),
3810 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3811 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003812}
3813
Brandon Jones59770802018-04-02 13:18:42 -07003814void Context::texImage3DRobust(TextureType target,
3815 GLint level,
3816 GLint internalformat,
3817 GLsizei width,
3818 GLsizei height,
3819 GLsizei depth,
3820 GLint border,
3821 GLenum format,
3822 GLenum type,
3823 GLsizei bufSize,
3824 const void *pixels)
3825{
3826 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3827}
3828
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003829void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003830 GLint level,
3831 GLint xoffset,
3832 GLint yoffset,
3833 GLsizei width,
3834 GLsizei height,
3835 GLenum format,
3836 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003837 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003838{
3839 // Zero sized uploads are valid but no-ops
3840 if (width == 0 || height == 0)
3841 {
3842 return;
3843 }
3844
Jamie Madillbc918e72018-03-08 09:47:21 -05003845 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003846
3847 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003848 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003849 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3850 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003851}
3852
Brandon Jones59770802018-04-02 13:18:42 -07003853void Context::texSubImage2DRobust(TextureTarget target,
3854 GLint level,
3855 GLint xoffset,
3856 GLint yoffset,
3857 GLsizei width,
3858 GLsizei height,
3859 GLenum format,
3860 GLenum type,
3861 GLsizei bufSize,
3862 const void *pixels)
3863{
3864 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3865}
3866
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003867void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003868 GLint level,
3869 GLint xoffset,
3870 GLint yoffset,
3871 GLint zoffset,
3872 GLsizei width,
3873 GLsizei height,
3874 GLsizei depth,
3875 GLenum format,
3876 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003877 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003878{
3879 // Zero sized uploads are valid but no-ops
3880 if (width == 0 || height == 0 || depth == 0)
3881 {
3882 return;
3883 }
3884
Jamie Madillbc918e72018-03-08 09:47:21 -05003885 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003886
3887 Box area(xoffset, yoffset, zoffset, width, height, depth);
3888 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003889 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3890 NonCubeTextureTypeToTarget(target), level, area, format, type,
3891 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003892}
3893
Brandon Jones59770802018-04-02 13:18:42 -07003894void Context::texSubImage3DRobust(TextureType target,
3895 GLint level,
3896 GLint xoffset,
3897 GLint yoffset,
3898 GLint zoffset,
3899 GLsizei width,
3900 GLsizei height,
3901 GLsizei depth,
3902 GLenum format,
3903 GLenum type,
3904 GLsizei bufSize,
3905 const void *pixels)
3906{
3907 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3908 pixels);
3909}
3910
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003911void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003912 GLint level,
3913 GLenum internalformat,
3914 GLsizei width,
3915 GLsizei height,
3916 GLint border,
3917 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003918 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003919{
Jamie Madillbc918e72018-03-08 09:47:21 -05003920 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003921
3922 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003923 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003924 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3925 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003926 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003927}
3928
Brandon Jones59770802018-04-02 13:18:42 -07003929void Context::compressedTexImage2DRobust(TextureTarget target,
3930 GLint level,
3931 GLenum internalformat,
3932 GLsizei width,
3933 GLsizei height,
3934 GLint border,
3935 GLsizei imageSize,
3936 GLsizei dataSize,
3937 const GLvoid *data)
3938{
3939 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3940}
3941
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003942void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003943 GLint level,
3944 GLenum internalformat,
3945 GLsizei width,
3946 GLsizei height,
3947 GLsizei depth,
3948 GLint border,
3949 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003950 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003951{
Jamie Madillbc918e72018-03-08 09:47:21 -05003952 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003953
3954 Extents size(width, height, depth);
3955 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003956 handleError(texture->setCompressedImage(
3957 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3958 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003959}
3960
Brandon Jones59770802018-04-02 13:18:42 -07003961void Context::compressedTexImage3DRobust(TextureType target,
3962 GLint level,
3963 GLenum internalformat,
3964 GLsizei width,
3965 GLsizei height,
3966 GLsizei depth,
3967 GLint border,
3968 GLsizei imageSize,
3969 GLsizei dataSize,
3970 const GLvoid *data)
3971{
3972 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3973 data);
3974}
3975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003976void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003977 GLint level,
3978 GLint xoffset,
3979 GLint yoffset,
3980 GLsizei width,
3981 GLsizei height,
3982 GLenum format,
3983 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
Jamie Madillbc918e72018-03-08 09:47:21 -05003986 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003987
3988 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003989 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003990 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3991 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003993}
3994
Brandon Jones59770802018-04-02 13:18:42 -07003995void Context::compressedTexSubImage2DRobust(TextureTarget target,
3996 GLint level,
3997 GLint xoffset,
3998 GLint yoffset,
3999 GLsizei width,
4000 GLsizei height,
4001 GLenum format,
4002 GLsizei imageSize,
4003 GLsizei dataSize,
4004 const GLvoid *data)
4005{
4006 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4007 data);
4008}
4009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004011 GLint level,
4012 GLint xoffset,
4013 GLint yoffset,
4014 GLint zoffset,
4015 GLsizei width,
4016 GLsizei height,
4017 GLsizei depth,
4018 GLenum format,
4019 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004020 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004021{
4022 // Zero sized uploads are valid but no-ops
4023 if (width == 0 || height == 0)
4024 {
4025 return;
4026 }
4027
Jamie Madillbc918e72018-03-08 09:47:21 -05004028 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004029
4030 Box area(xoffset, yoffset, zoffset, width, height, depth);
4031 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004032 handleError(texture->setCompressedSubImage(
4033 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4034 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004035}
4036
Brandon Jones59770802018-04-02 13:18:42 -07004037void Context::compressedTexSubImage3DRobust(TextureType target,
4038 GLint level,
4039 GLint xoffset,
4040 GLint yoffset,
4041 GLint zoffset,
4042 GLsizei width,
4043 GLsizei height,
4044 GLsizei depth,
4045 GLenum format,
4046 GLsizei imageSize,
4047 GLsizei dataSize,
4048 const GLvoid *data)
4049{
4050 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4051 imageSize, data);
4052}
4053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004054void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004055{
4056 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004057 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004058}
4059
Jamie Madill007530e2017-12-28 14:27:04 -05004060void Context::copyTexture(GLuint sourceId,
4061 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004062 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004063 GLuint destId,
4064 GLint destLevel,
4065 GLint internalFormat,
4066 GLenum destType,
4067 GLboolean unpackFlipY,
4068 GLboolean unpackPremultiplyAlpha,
4069 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004070{
Jamie Madillbc918e72018-03-08 09:47:21 -05004071 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004072
4073 gl::Texture *sourceTexture = getTexture(sourceId);
4074 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004075 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4076 sourceLevel, ConvertToBool(unpackFlipY),
4077 ConvertToBool(unpackPremultiplyAlpha),
4078 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004079}
4080
Jamie Madill007530e2017-12-28 14:27:04 -05004081void Context::copySubTexture(GLuint sourceId,
4082 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004083 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004084 GLuint destId,
4085 GLint destLevel,
4086 GLint xoffset,
4087 GLint yoffset,
4088 GLint x,
4089 GLint y,
4090 GLsizei width,
4091 GLsizei height,
4092 GLboolean unpackFlipY,
4093 GLboolean unpackPremultiplyAlpha,
4094 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004095{
4096 // Zero sized copies are valid but no-ops
4097 if (width == 0 || height == 0)
4098 {
4099 return;
4100 }
4101
Jamie Madillbc918e72018-03-08 09:47:21 -05004102 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004103
4104 gl::Texture *sourceTexture = getTexture(sourceId);
4105 gl::Texture *destTexture = getTexture(destId);
4106 Offset offset(xoffset, yoffset, 0);
4107 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004108 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4109 ConvertToBool(unpackFlipY),
4110 ConvertToBool(unpackPremultiplyAlpha),
4111 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004112}
4113
Jamie Madill007530e2017-12-28 14:27:04 -05004114void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004115{
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004117
4118 gl::Texture *sourceTexture = getTexture(sourceId);
4119 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004120 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004121}
4122
Corentin Wallez336129f2017-10-17 15:55:40 -04004123void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004124{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004125 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004126 ASSERT(buffer);
4127
Geoff Lang496c02d2016-10-20 11:38:11 -07004128 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004129}
4130
Brandon Jones59770802018-04-02 13:18:42 -07004131void Context::getBufferPointervRobust(BufferBinding target,
4132 GLenum pname,
4133 GLsizei bufSize,
4134 GLsizei *length,
4135 void **params)
4136{
4137 getBufferPointerv(target, pname, params);
4138}
4139
Corentin Wallez336129f2017-10-17 15:55:40 -04004140void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004141{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004143 ASSERT(buffer);
4144
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004145 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004146 if (error.isError())
4147 {
Jamie Madill437fa652016-05-03 15:13:24 -04004148 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004149 return nullptr;
4150 }
4151
4152 return buffer->getMapPointer();
4153}
4154
Corentin Wallez336129f2017-10-17 15:55:40 -04004155GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004157 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004158 ASSERT(buffer);
4159
4160 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004161 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004162 if (error.isError())
4163 {
Jamie Madill437fa652016-05-03 15:13:24 -04004164 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004165 return GL_FALSE;
4166 }
4167
4168 return result;
4169}
4170
Corentin Wallez336129f2017-10-17 15:55:40 -04004171void *Context::mapBufferRange(BufferBinding target,
4172 GLintptr offset,
4173 GLsizeiptr length,
4174 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004175{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004176 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004177 ASSERT(buffer);
4178
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004179 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 if (error.isError())
4181 {
Jamie Madill437fa652016-05-03 15:13:24 -04004182 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 return nullptr;
4184 }
4185
4186 return buffer->getMapPointer();
4187}
4188
Corentin Wallez336129f2017-10-17 15:55:40 -04004189void Context::flushMappedBufferRange(BufferBinding /*target*/,
4190 GLintptr /*offset*/,
4191 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004192{
4193 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4194}
4195
Jamie Madillbc918e72018-03-08 09:47:21 -05004196Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004197{
Geoff Langa8cb2872018-03-09 16:09:40 -05004198 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004199}
4200
Jamie Madillbc918e72018-03-08 09:47:21 -05004201Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004202{
Geoff Langa8cb2872018-03-09 16:09:40 -05004203 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004204}
4205
Jamie Madillbc918e72018-03-08 09:47:21 -05004206Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004207{
Geoff Langa8cb2872018-03-09 16:09:40 -05004208 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004209}
4210
Jiajia Qin5451d532017-11-16 17:16:34 +08004211void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4212{
4213 UNIMPLEMENTED();
4214}
4215
Jamie Madillc20ab272016-06-09 07:20:46 -07004216void Context::activeTexture(GLenum texture)
4217{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004218 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004219}
4220
Jamie Madill876429b2017-04-20 15:46:24 -04004221void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004223 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004224}
4225
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004226void Context::blendEquation(GLenum mode)
4227{
4228 mGLState.setBlendEquation(mode, mode);
4229}
4230
Jamie Madillc20ab272016-06-09 07:20:46 -07004231void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004234}
4235
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004236void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4237{
4238 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4239}
4240
Jamie Madillc20ab272016-06-09 07:20:46 -07004241void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4242{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004243 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004244}
4245
Jamie Madill876429b2017-04-20 15:46:24 -04004246void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
Jamie Madill876429b2017-04-20 15:46:24 -04004251void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004252{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004253 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004254}
4255
4256void Context::clearStencil(GLint s)
4257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004258 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004259}
4260
4261void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4262{
Geoff Lang92019432017-11-20 13:09:34 -05004263 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4264 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004267void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004268{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270}
4271
4272void Context::depthFunc(GLenum func)
4273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004275}
4276
4277void Context::depthMask(GLboolean flag)
4278{
Geoff Lang92019432017-11-20 13:09:34 -05004279 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004280}
4281
Jamie Madill876429b2017-04-20 15:46:24 -04004282void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285}
4286
4287void Context::disable(GLenum cap)
4288{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004289 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004290}
4291
4292void Context::disableVertexAttribArray(GLuint index)
4293{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004294 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004295}
4296
4297void Context::enable(GLenum cap)
4298{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300}
4301
4302void Context::enableVertexAttribArray(GLuint index)
4303{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305}
4306
4307void Context::frontFace(GLenum mode)
4308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004309 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004310}
4311
4312void Context::hint(GLenum target, GLenum mode)
4313{
4314 switch (target)
4315 {
4316 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004317 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004318 break;
4319
4320 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004321 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004322 break;
4323
4324 default:
4325 UNREACHABLE();
4326 return;
4327 }
4328}
4329
4330void Context::lineWidth(GLfloat width)
4331{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004332 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004333}
4334
4335void Context::pixelStorei(GLenum pname, GLint param)
4336{
4337 switch (pname)
4338 {
4339 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004341 break;
4342
4343 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345 break;
4346
4347 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349 break;
4350
4351 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004352 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354 break;
4355
4356 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004357 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359 break;
4360
4361 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004362 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364 break;
4365
4366 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004367 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369 break;
4370
4371 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004372 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374 break;
4375
4376 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004377 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379 break;
4380
4381 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004382 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004383 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004384 break;
4385
4386 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004387 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004388 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004389 break;
4390
4391 default:
4392 UNREACHABLE();
4393 return;
4394 }
4395}
4396
4397void Context::polygonOffset(GLfloat factor, GLfloat units)
4398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
Jamie Madill876429b2017-04-20 15:46:24 -04004402void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004403{
Geoff Lang92019432017-11-20 13:09:34 -05004404 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jiawei Shaodb342272017-09-27 10:21:45 +08004407void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4408{
4409 mGLState.setSampleMaskParams(maskNumber, mask);
4410}
4411
Jamie Madillc20ab272016-06-09 07:20:46 -07004412void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
4417void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4418{
4419 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4420 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422 }
4423
4424 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4425 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004426 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004427 }
4428}
4429
4430void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4431{
4432 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4433 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004434 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004435 }
4436
4437 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4438 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004439 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004440 }
4441}
4442
4443void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4444{
4445 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4446 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448 }
4449
4450 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4451 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004452 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004453 }
4454}
4455
4456void Context::vertexAttrib1f(GLuint index, GLfloat x)
4457{
4458 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4463{
4464 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4469{
4470 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4475{
4476 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4481{
4482 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004483 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4487{
4488 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
4492void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4493{
4494 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004495 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
4498void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::vertexAttribPointer(GLuint index,
4504 GLint size,
4505 GLenum type,
4506 GLboolean normalized,
4507 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004508 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004509{
Corentin Wallez336129f2017-10-17 15:55:40 -04004510 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004511 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
Shao80957d92017-02-20 21:25:59 +08004514void Context::vertexAttribFormat(GLuint attribIndex,
4515 GLint size,
4516 GLenum type,
4517 GLboolean normalized,
4518 GLuint relativeOffset)
4519{
Geoff Lang92019432017-11-20 13:09:34 -05004520 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004521 relativeOffset);
4522}
4523
4524void Context::vertexAttribIFormat(GLuint attribIndex,
4525 GLint size,
4526 GLenum type,
4527 GLuint relativeOffset)
4528{
4529 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4530}
4531
4532void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4533{
Shaodde78e82017-05-22 14:13:27 +08004534 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004535}
4536
Jiajia Qin5451d532017-11-16 17:16:34 +08004537void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004538{
4539 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4540}
4541
Jamie Madillc20ab272016-06-09 07:20:46 -07004542void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4543{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545}
4546
4547void Context::vertexAttribIPointer(GLuint index,
4548 GLint size,
4549 GLenum type,
4550 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004551 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004552{
Corentin Wallez336129f2017-10-17 15:55:40 -04004553 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4554 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4558{
4559 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4564{
4565 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572}
4573
4574void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577}
4578
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004579void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4580{
4581 const VertexAttribCurrentValueData &currentValues =
4582 getGLState().getVertexAttribCurrentValue(index);
4583 const VertexArray *vao = getGLState().getVertexArray();
4584 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4585 currentValues, pname, params);
4586}
4587
Brandon Jones59770802018-04-02 13:18:42 -07004588void Context::getVertexAttribivRobust(GLuint index,
4589 GLenum pname,
4590 GLsizei bufSize,
4591 GLsizei *length,
4592 GLint *params)
4593{
4594 getVertexAttribiv(index, pname, params);
4595}
4596
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004597void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4598{
4599 const VertexAttribCurrentValueData &currentValues =
4600 getGLState().getVertexAttribCurrentValue(index);
4601 const VertexArray *vao = getGLState().getVertexArray();
4602 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4603 currentValues, pname, params);
4604}
4605
Brandon Jones59770802018-04-02 13:18:42 -07004606void Context::getVertexAttribfvRobust(GLuint index,
4607 GLenum pname,
4608 GLsizei bufSize,
4609 GLsizei *length,
4610 GLfloat *params)
4611{
4612 getVertexAttribfv(index, pname, params);
4613}
4614
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004615void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4616{
4617 const VertexAttribCurrentValueData &currentValues =
4618 getGLState().getVertexAttribCurrentValue(index);
4619 const VertexArray *vao = getGLState().getVertexArray();
4620 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4621 currentValues, pname, params);
4622}
4623
Brandon Jones59770802018-04-02 13:18:42 -07004624void Context::getVertexAttribIivRobust(GLuint index,
4625 GLenum pname,
4626 GLsizei bufSize,
4627 GLsizei *length,
4628 GLint *params)
4629{
4630 getVertexAttribIiv(index, pname, params);
4631}
4632
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004633void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4634{
4635 const VertexAttribCurrentValueData &currentValues =
4636 getGLState().getVertexAttribCurrentValue(index);
4637 const VertexArray *vao = getGLState().getVertexArray();
4638 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4639 currentValues, pname, params);
4640}
4641
Brandon Jones59770802018-04-02 13:18:42 -07004642void Context::getVertexAttribIuivRobust(GLuint index,
4643 GLenum pname,
4644 GLsizei bufSize,
4645 GLsizei *length,
4646 GLuint *params)
4647{
4648 getVertexAttribIuiv(index, pname, params);
4649}
4650
Jamie Madill876429b2017-04-20 15:46:24 -04004651void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004652{
4653 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4654 QueryVertexAttribPointerv(attrib, pname, pointer);
4655}
4656
Brandon Jones59770802018-04-02 13:18:42 -07004657void Context::getVertexAttribPointervRobust(GLuint index,
4658 GLenum pname,
4659 GLsizei bufSize,
4660 GLsizei *length,
4661 void **pointer)
4662{
4663 getVertexAttribPointerv(index, pname, pointer);
4664}
4665
Jamie Madillc20ab272016-06-09 07:20:46 -07004666void Context::debugMessageControl(GLenum source,
4667 GLenum type,
4668 GLenum severity,
4669 GLsizei count,
4670 const GLuint *ids,
4671 GLboolean enabled)
4672{
4673 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004675 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
4678void Context::debugMessageInsert(GLenum source,
4679 GLenum type,
4680 GLuint id,
4681 GLenum severity,
4682 GLsizei length,
4683 const GLchar *buf)
4684{
4685 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004687}
4688
4689void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4690{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004691 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004692}
4693
4694GLuint Context::getDebugMessageLog(GLuint count,
4695 GLsizei bufSize,
4696 GLenum *sources,
4697 GLenum *types,
4698 GLuint *ids,
4699 GLenum *severities,
4700 GLsizei *lengths,
4701 GLchar *messageLog)
4702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004703 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4704 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004705}
4706
4707void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4708{
4709 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004710 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004711 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004712}
4713
4714void Context::popDebugGroup()
4715{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004717 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004718}
4719
Corentin Wallez336129f2017-10-17 15:55:40 -04004720void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004721{
4722 Buffer *buffer = mGLState.getTargetBuffer(target);
4723 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004724 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004725}
4726
Corentin Wallez336129f2017-10-17 15:55:40 -04004727void Context::bufferSubData(BufferBinding target,
4728 GLintptr offset,
4729 GLsizeiptr size,
4730 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004731{
4732 if (data == nullptr)
4733 {
4734 return;
4735 }
4736
4737 Buffer *buffer = mGLState.getTargetBuffer(target);
4738 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004739 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004740}
4741
Jamie Madillef300b12016-10-07 15:12:09 -04004742void Context::attachShader(GLuint program, GLuint shader)
4743{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004744 Program *programObject = mState.mShaderPrograms->getProgram(program);
4745 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004746 ASSERT(programObject && shaderObject);
4747 programObject->attachShader(shaderObject);
4748}
4749
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004750const Workarounds &Context::getWorkarounds() const
4751{
4752 return mWorkarounds;
4753}
4754
Corentin Wallez336129f2017-10-17 15:55:40 -04004755void Context::copyBufferSubData(BufferBinding readTarget,
4756 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004757 GLintptr readOffset,
4758 GLintptr writeOffset,
4759 GLsizeiptr size)
4760{
4761 // if size is zero, the copy is a successful no-op
4762 if (size == 0)
4763 {
4764 return;
4765 }
4766
4767 // TODO(jmadill): cache these.
4768 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4769 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4770
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004771 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004772}
4773
Jamie Madill01a80ee2016-11-07 12:06:18 -05004774void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4775{
4776 Program *programObject = getProgram(program);
4777 // TODO(jmadill): Re-use this from the validation if possible.
4778 ASSERT(programObject);
4779 programObject->bindAttributeLocation(index, name);
4780}
4781
Corentin Wallez336129f2017-10-17 15:55:40 -04004782void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004783{
Corentin Wallez336129f2017-10-17 15:55:40 -04004784 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4785 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004786}
4787
Corentin Wallez336129f2017-10-17 15:55:40 -04004788void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004789{
4790 bindBufferRange(target, index, buffer, 0, 0);
4791}
4792
Corentin Wallez336129f2017-10-17 15:55:40 -04004793void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004794 GLuint index,
4795 GLuint buffer,
4796 GLintptr offset,
4797 GLsizeiptr size)
4798{
Corentin Wallez336129f2017-10-17 15:55:40 -04004799 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4800 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004801}
4802
Jamie Madill01a80ee2016-11-07 12:06:18 -05004803void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4804{
4805 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4806 {
4807 bindReadFramebuffer(framebuffer);
4808 }
4809
4810 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4811 {
4812 bindDrawFramebuffer(framebuffer);
4813 }
4814}
4815
4816void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4817{
4818 ASSERT(target == GL_RENDERBUFFER);
4819 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004820 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004821 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004822}
4823
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004824void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004825 GLsizei samples,
4826 GLenum internalformat,
4827 GLsizei width,
4828 GLsizei height,
4829 GLboolean fixedsamplelocations)
4830{
4831 Extents size(width, height, 1);
4832 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004833 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4834 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004835}
4836
4837void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4838{
JiangYizhou5b03f472017-01-09 10:22:53 +08004839 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4840 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004841 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004842 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004843
4844 switch (pname)
4845 {
4846 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004847 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004848 break;
4849 default:
4850 UNREACHABLE();
4851 }
4852}
4853
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004854void Context::getMultisamplefvRobust(GLenum pname,
4855 GLuint index,
4856 GLsizei bufSize,
4857 GLsizei *length,
4858 GLfloat *val)
4859{
4860 UNIMPLEMENTED();
4861}
4862
Jamie Madille8fb6402017-02-14 17:56:40 -05004863void Context::renderbufferStorage(GLenum target,
4864 GLenum internalformat,
4865 GLsizei width,
4866 GLsizei height)
4867{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004868 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4869 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4870
Jamie Madille8fb6402017-02-14 17:56:40 -05004871 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004872 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004873}
4874
4875void Context::renderbufferStorageMultisample(GLenum target,
4876 GLsizei samples,
4877 GLenum internalformat,
4878 GLsizei width,
4879 GLsizei height)
4880{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004881 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4882 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004883
4884 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004885 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004886 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004887}
4888
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004889void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4890{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004891 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004892 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004893}
4894
JiangYizhoue18e6392017-02-20 10:32:23 +08004895void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4896{
4897 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4898 QueryFramebufferParameteriv(framebuffer, pname, params);
4899}
4900
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004901void Context::getFramebufferParameterivRobust(GLenum target,
4902 GLenum pname,
4903 GLsizei bufSize,
4904 GLsizei *length,
4905 GLint *params)
4906{
4907 UNIMPLEMENTED();
4908}
4909
Jiajia Qin5451d532017-11-16 17:16:34 +08004910void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004911{
4912 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4913 SetFramebufferParameteri(framebuffer, pname, param);
4914}
4915
Jamie Madillb3f26b92017-07-19 15:07:41 -04004916Error Context::getScratchBuffer(size_t requstedSizeBytes,
4917 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004918{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004919 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4920 {
4921 return OutOfMemory() << "Failed to allocate internal buffer.";
4922 }
4923 return NoError();
4924}
4925
4926Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4927 angle::MemoryBuffer **zeroBufferOut) const
4928{
4929 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004930 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004931 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004932 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004933 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004934}
4935
Xinghua Cao10a4d432017-11-28 14:46:26 +08004936Error Context::prepareForDispatch()
4937{
Geoff Langa8cb2872018-03-09 16:09:40 -05004938 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004939
4940 if (isRobustResourceInitEnabled())
4941 {
4942 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4943 }
4944
4945 return NoError();
4946}
4947
Xinghua Cao2b396592017-03-29 15:36:04 +08004948void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4949{
4950 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4951 {
4952 return;
4953 }
4954
Xinghua Cao10a4d432017-11-28 14:46:26 +08004955 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004956 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004957}
4958
Jiajia Qin5451d532017-11-16 17:16:34 +08004959void Context::dispatchComputeIndirect(GLintptr indirect)
4960{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004961 ANGLE_CONTEXT_TRY(prepareForDispatch());
4962 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004963}
4964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004965void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004966 GLsizei levels,
4967 GLenum internalFormat,
4968 GLsizei width,
4969 GLsizei height)
4970{
4971 Extents size(width, height, 1);
4972 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004973 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004974}
4975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004976void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004977 GLsizei levels,
4978 GLenum internalFormat,
4979 GLsizei width,
4980 GLsizei height,
4981 GLsizei depth)
4982{
4983 Extents size(width, height, depth);
4984 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004985 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004986}
4987
Jiajia Qin5451d532017-11-16 17:16:34 +08004988void Context::memoryBarrier(GLbitfield barriers)
4989{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004990 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004991}
4992
4993void Context::memoryBarrierByRegion(GLbitfield barriers)
4994{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004995 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004996}
4997
Jamie Madillc1d770e2017-04-13 17:31:24 -04004998GLenum Context::checkFramebufferStatus(GLenum target)
4999{
5000 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5001 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005002 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005003}
5004
5005void Context::compileShader(GLuint shader)
5006{
5007 Shader *shaderObject = GetValidShader(this, shader);
5008 if (!shaderObject)
5009 {
5010 return;
5011 }
5012 shaderObject->compile(this);
5013}
5014
5015void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5016{
5017 for (int i = 0; i < n; i++)
5018 {
5019 deleteBuffer(buffers[i]);
5020 }
5021}
5022
5023void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5024{
5025 for (int i = 0; i < n; i++)
5026 {
5027 if (framebuffers[i] != 0)
5028 {
5029 deleteFramebuffer(framebuffers[i]);
5030 }
5031 }
5032}
5033
5034void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5035{
5036 for (int i = 0; i < n; i++)
5037 {
5038 deleteRenderbuffer(renderbuffers[i]);
5039 }
5040}
5041
5042void Context::deleteTextures(GLsizei n, const GLuint *textures)
5043{
5044 for (int i = 0; i < n; i++)
5045 {
5046 if (textures[i] != 0)
5047 {
5048 deleteTexture(textures[i]);
5049 }
5050 }
5051}
5052
5053void Context::detachShader(GLuint program, GLuint shader)
5054{
5055 Program *programObject = getProgram(program);
5056 ASSERT(programObject);
5057
5058 Shader *shaderObject = getShader(shader);
5059 ASSERT(shaderObject);
5060
5061 programObject->detachShader(this, shaderObject);
5062}
5063
5064void Context::genBuffers(GLsizei n, GLuint *buffers)
5065{
5066 for (int i = 0; i < n; i++)
5067 {
5068 buffers[i] = createBuffer();
5069 }
5070}
5071
5072void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5073{
5074 for (int i = 0; i < n; i++)
5075 {
5076 framebuffers[i] = createFramebuffer();
5077 }
5078}
5079
5080void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5081{
5082 for (int i = 0; i < n; i++)
5083 {
5084 renderbuffers[i] = createRenderbuffer();
5085 }
5086}
5087
5088void Context::genTextures(GLsizei n, GLuint *textures)
5089{
5090 for (int i = 0; i < n; i++)
5091 {
5092 textures[i] = createTexture();
5093 }
5094}
5095
5096void Context::getActiveAttrib(GLuint program,
5097 GLuint index,
5098 GLsizei bufsize,
5099 GLsizei *length,
5100 GLint *size,
5101 GLenum *type,
5102 GLchar *name)
5103{
5104 Program *programObject = getProgram(program);
5105 ASSERT(programObject);
5106 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5107}
5108
5109void Context::getActiveUniform(GLuint program,
5110 GLuint index,
5111 GLsizei bufsize,
5112 GLsizei *length,
5113 GLint *size,
5114 GLenum *type,
5115 GLchar *name)
5116{
5117 Program *programObject = getProgram(program);
5118 ASSERT(programObject);
5119 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5120}
5121
5122void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5123{
5124 Program *programObject = getProgram(program);
5125 ASSERT(programObject);
5126 programObject->getAttachedShaders(maxcount, count, shaders);
5127}
5128
5129GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5130{
5131 Program *programObject = getProgram(program);
5132 ASSERT(programObject);
5133 return programObject->getAttributeLocation(name);
5134}
5135
5136void Context::getBooleanv(GLenum pname, GLboolean *params)
5137{
5138 GLenum nativeType;
5139 unsigned int numParams = 0;
5140 getQueryParameterInfo(pname, &nativeType, &numParams);
5141
5142 if (nativeType == GL_BOOL)
5143 {
5144 getBooleanvImpl(pname, params);
5145 }
5146 else
5147 {
5148 CastStateValues(this, nativeType, pname, numParams, params);
5149 }
5150}
5151
Brandon Jones59770802018-04-02 13:18:42 -07005152void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5153{
5154 getBooleanv(pname, params);
5155}
5156
Jamie Madillc1d770e2017-04-13 17:31:24 -04005157void Context::getFloatv(GLenum pname, GLfloat *params)
5158{
5159 GLenum nativeType;
5160 unsigned int numParams = 0;
5161 getQueryParameterInfo(pname, &nativeType, &numParams);
5162
5163 if (nativeType == GL_FLOAT)
5164 {
5165 getFloatvImpl(pname, params);
5166 }
5167 else
5168 {
5169 CastStateValues(this, nativeType, pname, numParams, params);
5170 }
5171}
5172
Brandon Jones59770802018-04-02 13:18:42 -07005173void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5174{
5175 getFloatv(pname, params);
5176}
5177
Jamie Madillc1d770e2017-04-13 17:31:24 -04005178void Context::getIntegerv(GLenum pname, GLint *params)
5179{
5180 GLenum nativeType;
5181 unsigned int numParams = 0;
5182 getQueryParameterInfo(pname, &nativeType, &numParams);
5183
5184 if (nativeType == GL_INT)
5185 {
5186 getIntegervImpl(pname, params);
5187 }
5188 else
5189 {
5190 CastStateValues(this, nativeType, pname, numParams, params);
5191 }
5192}
5193
Brandon Jones59770802018-04-02 13:18:42 -07005194void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5195{
5196 getIntegerv(pname, data);
5197}
5198
Jamie Madillc1d770e2017-04-13 17:31:24 -04005199void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5200{
5201 Program *programObject = getProgram(program);
5202 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005203 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005204}
5205
Brandon Jones59770802018-04-02 13:18:42 -07005206void Context::getProgramivRobust(GLuint program,
5207 GLenum pname,
5208 GLsizei bufSize,
5209 GLsizei *length,
5210 GLint *params)
5211{
5212 getProgramiv(program, pname, params);
5213}
5214
Jiajia Qin5451d532017-11-16 17:16:34 +08005215void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5216{
5217 UNIMPLEMENTED();
5218}
5219
Jamie Madillbe849e42017-05-02 15:49:00 -04005220void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221{
5222 Program *programObject = getProgram(program);
5223 ASSERT(programObject);
5224 programObject->getInfoLog(bufsize, length, infolog);
5225}
5226
Jiajia Qin5451d532017-11-16 17:16:34 +08005227void Context::getProgramPipelineInfoLog(GLuint pipeline,
5228 GLsizei bufSize,
5229 GLsizei *length,
5230 GLchar *infoLog)
5231{
5232 UNIMPLEMENTED();
5233}
5234
Jamie Madillc1d770e2017-04-13 17:31:24 -04005235void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5236{
5237 Shader *shaderObject = getShader(shader);
5238 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005239 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005240}
5241
Brandon Jones59770802018-04-02 13:18:42 -07005242void Context::getShaderivRobust(GLuint shader,
5243 GLenum pname,
5244 GLsizei bufSize,
5245 GLsizei *length,
5246 GLint *params)
5247{
5248 getShaderiv(shader, pname, params);
5249}
5250
Jamie Madillc1d770e2017-04-13 17:31:24 -04005251void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5252{
5253 Shader *shaderObject = getShader(shader);
5254 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005255 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005256}
5257
5258void Context::getShaderPrecisionFormat(GLenum shadertype,
5259 GLenum precisiontype,
5260 GLint *range,
5261 GLint *precision)
5262{
5263 // TODO(jmadill): Compute shaders.
5264
5265 switch (shadertype)
5266 {
5267 case GL_VERTEX_SHADER:
5268 switch (precisiontype)
5269 {
5270 case GL_LOW_FLOAT:
5271 mCaps.vertexLowpFloat.get(range, precision);
5272 break;
5273 case GL_MEDIUM_FLOAT:
5274 mCaps.vertexMediumpFloat.get(range, precision);
5275 break;
5276 case GL_HIGH_FLOAT:
5277 mCaps.vertexHighpFloat.get(range, precision);
5278 break;
5279
5280 case GL_LOW_INT:
5281 mCaps.vertexLowpInt.get(range, precision);
5282 break;
5283 case GL_MEDIUM_INT:
5284 mCaps.vertexMediumpInt.get(range, precision);
5285 break;
5286 case GL_HIGH_INT:
5287 mCaps.vertexHighpInt.get(range, precision);
5288 break;
5289
5290 default:
5291 UNREACHABLE();
5292 return;
5293 }
5294 break;
5295
5296 case GL_FRAGMENT_SHADER:
5297 switch (precisiontype)
5298 {
5299 case GL_LOW_FLOAT:
5300 mCaps.fragmentLowpFloat.get(range, precision);
5301 break;
5302 case GL_MEDIUM_FLOAT:
5303 mCaps.fragmentMediumpFloat.get(range, precision);
5304 break;
5305 case GL_HIGH_FLOAT:
5306 mCaps.fragmentHighpFloat.get(range, precision);
5307 break;
5308
5309 case GL_LOW_INT:
5310 mCaps.fragmentLowpInt.get(range, precision);
5311 break;
5312 case GL_MEDIUM_INT:
5313 mCaps.fragmentMediumpInt.get(range, precision);
5314 break;
5315 case GL_HIGH_INT:
5316 mCaps.fragmentHighpInt.get(range, precision);
5317 break;
5318
5319 default:
5320 UNREACHABLE();
5321 return;
5322 }
5323 break;
5324
5325 default:
5326 UNREACHABLE();
5327 return;
5328 }
5329}
5330
5331void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5332{
5333 Shader *shaderObject = getShader(shader);
5334 ASSERT(shaderObject);
5335 shaderObject->getSource(bufsize, length, source);
5336}
5337
5338void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5339{
5340 Program *programObject = getProgram(program);
5341 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005342 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005343}
5344
Brandon Jones59770802018-04-02 13:18:42 -07005345void Context::getUniformfvRobust(GLuint program,
5346 GLint location,
5347 GLsizei bufSize,
5348 GLsizei *length,
5349 GLfloat *params)
5350{
5351 getUniformfv(program, location, params);
5352}
5353
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5355{
5356 Program *programObject = getProgram(program);
5357 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005358 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359}
5360
Brandon Jones59770802018-04-02 13:18:42 -07005361void Context::getUniformivRobust(GLuint program,
5362 GLint location,
5363 GLsizei bufSize,
5364 GLsizei *length,
5365 GLint *params)
5366{
5367 getUniformiv(program, location, params);
5368}
5369
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5371{
5372 Program *programObject = getProgram(program);
5373 ASSERT(programObject);
5374 return programObject->getUniformLocation(name);
5375}
5376
5377GLboolean Context::isBuffer(GLuint buffer)
5378{
5379 if (buffer == 0)
5380 {
5381 return GL_FALSE;
5382 }
5383
5384 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5385}
5386
5387GLboolean Context::isEnabled(GLenum cap)
5388{
5389 return mGLState.getEnableFeature(cap);
5390}
5391
5392GLboolean Context::isFramebuffer(GLuint framebuffer)
5393{
5394 if (framebuffer == 0)
5395 {
5396 return GL_FALSE;
5397 }
5398
5399 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5400}
5401
5402GLboolean Context::isProgram(GLuint program)
5403{
5404 if (program == 0)
5405 {
5406 return GL_FALSE;
5407 }
5408
5409 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5410}
5411
5412GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5413{
5414 if (renderbuffer == 0)
5415 {
5416 return GL_FALSE;
5417 }
5418
5419 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5420}
5421
5422GLboolean Context::isShader(GLuint shader)
5423{
5424 if (shader == 0)
5425 {
5426 return GL_FALSE;
5427 }
5428
5429 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5430}
5431
5432GLboolean Context::isTexture(GLuint texture)
5433{
5434 if (texture == 0)
5435 {
5436 return GL_FALSE;
5437 }
5438
5439 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5440}
5441
5442void Context::linkProgram(GLuint program)
5443{
5444 Program *programObject = getProgram(program);
5445 ASSERT(programObject);
5446 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005447 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448}
5449
5450void Context::releaseShaderCompiler()
5451{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005452 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005453}
5454
5455void Context::shaderBinary(GLsizei n,
5456 const GLuint *shaders,
5457 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005458 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459 GLsizei length)
5460{
5461 // No binary shader formats are supported.
5462 UNIMPLEMENTED();
5463}
5464
5465void Context::shaderSource(GLuint shader,
5466 GLsizei count,
5467 const GLchar *const *string,
5468 const GLint *length)
5469{
5470 Shader *shaderObject = getShader(shader);
5471 ASSERT(shaderObject);
5472 shaderObject->setSource(count, string, length);
5473}
5474
5475void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5476{
5477 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5478}
5479
5480void Context::stencilMask(GLuint mask)
5481{
5482 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5483}
5484
5485void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5486{
5487 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5488}
5489
5490void Context::uniform1f(GLint location, GLfloat x)
5491{
5492 Program *program = mGLState.getProgram();
5493 program->setUniform1fv(location, 1, &x);
5494}
5495
5496void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5497{
5498 Program *program = mGLState.getProgram();
5499 program->setUniform1fv(location, count, v);
5500}
5501
5502void Context::uniform1i(GLint location, GLint x)
5503{
5504 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005505 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5506 {
5507 mGLState.setObjectDirty(GL_PROGRAM);
5508 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005509}
5510
5511void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5512{
5513 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005514 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5515 {
5516 mGLState.setObjectDirty(GL_PROGRAM);
5517 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005518}
5519
5520void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5521{
5522 GLfloat xy[2] = {x, y};
5523 Program *program = mGLState.getProgram();
5524 program->setUniform2fv(location, 1, xy);
5525}
5526
5527void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5528{
5529 Program *program = mGLState.getProgram();
5530 program->setUniform2fv(location, count, v);
5531}
5532
5533void Context::uniform2i(GLint location, GLint x, GLint y)
5534{
5535 GLint xy[2] = {x, y};
5536 Program *program = mGLState.getProgram();
5537 program->setUniform2iv(location, 1, xy);
5538}
5539
5540void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5541{
5542 Program *program = mGLState.getProgram();
5543 program->setUniform2iv(location, count, v);
5544}
5545
5546void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5547{
5548 GLfloat xyz[3] = {x, y, z};
5549 Program *program = mGLState.getProgram();
5550 program->setUniform3fv(location, 1, xyz);
5551}
5552
5553void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5554{
5555 Program *program = mGLState.getProgram();
5556 program->setUniform3fv(location, count, v);
5557}
5558
5559void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5560{
5561 GLint xyz[3] = {x, y, z};
5562 Program *program = mGLState.getProgram();
5563 program->setUniform3iv(location, 1, xyz);
5564}
5565
5566void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5567{
5568 Program *program = mGLState.getProgram();
5569 program->setUniform3iv(location, count, v);
5570}
5571
5572void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5573{
5574 GLfloat xyzw[4] = {x, y, z, w};
5575 Program *program = mGLState.getProgram();
5576 program->setUniform4fv(location, 1, xyzw);
5577}
5578
5579void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5580{
5581 Program *program = mGLState.getProgram();
5582 program->setUniform4fv(location, count, v);
5583}
5584
5585void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5586{
5587 GLint xyzw[4] = {x, y, z, w};
5588 Program *program = mGLState.getProgram();
5589 program->setUniform4iv(location, 1, xyzw);
5590}
5591
5592void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5593{
5594 Program *program = mGLState.getProgram();
5595 program->setUniform4iv(location, count, v);
5596}
5597
5598void Context::uniformMatrix2fv(GLint location,
5599 GLsizei count,
5600 GLboolean transpose,
5601 const GLfloat *value)
5602{
5603 Program *program = mGLState.getProgram();
5604 program->setUniformMatrix2fv(location, count, transpose, value);
5605}
5606
5607void Context::uniformMatrix3fv(GLint location,
5608 GLsizei count,
5609 GLboolean transpose,
5610 const GLfloat *value)
5611{
5612 Program *program = mGLState.getProgram();
5613 program->setUniformMatrix3fv(location, count, transpose, value);
5614}
5615
5616void Context::uniformMatrix4fv(GLint location,
5617 GLsizei count,
5618 GLboolean transpose,
5619 const GLfloat *value)
5620{
5621 Program *program = mGLState.getProgram();
5622 program->setUniformMatrix4fv(location, count, transpose, value);
5623}
5624
5625void Context::validateProgram(GLuint program)
5626{
5627 Program *programObject = getProgram(program);
5628 ASSERT(programObject);
5629 programObject->validate(mCaps);
5630}
5631
Jiajia Qin5451d532017-11-16 17:16:34 +08005632void Context::validateProgramPipeline(GLuint pipeline)
5633{
5634 UNIMPLEMENTED();
5635}
5636
Jamie Madilld04908b2017-06-09 14:15:35 -04005637void Context::getProgramBinary(GLuint program,
5638 GLsizei bufSize,
5639 GLsizei *length,
5640 GLenum *binaryFormat,
5641 void *binary)
5642{
5643 Program *programObject = getProgram(program);
5644 ASSERT(programObject != nullptr);
5645
5646 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5647}
5648
5649void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5650{
5651 Program *programObject = getProgram(program);
5652 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005653
Jamie Madilld04908b2017-06-09 14:15:35 -04005654 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5655}
5656
Jamie Madillff325f12017-08-26 15:06:05 -04005657void Context::uniform1ui(GLint location, GLuint v0)
5658{
5659 Program *program = mGLState.getProgram();
5660 program->setUniform1uiv(location, 1, &v0);
5661}
5662
5663void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5664{
5665 Program *program = mGLState.getProgram();
5666 const GLuint xy[] = {v0, v1};
5667 program->setUniform2uiv(location, 1, xy);
5668}
5669
5670void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5671{
5672 Program *program = mGLState.getProgram();
5673 const GLuint xyz[] = {v0, v1, v2};
5674 program->setUniform3uiv(location, 1, xyz);
5675}
5676
5677void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5678{
5679 Program *program = mGLState.getProgram();
5680 const GLuint xyzw[] = {v0, v1, v2, v3};
5681 program->setUniform4uiv(location, 1, xyzw);
5682}
5683
5684void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5685{
5686 Program *program = mGLState.getProgram();
5687 program->setUniform1uiv(location, count, value);
5688}
5689void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5690{
5691 Program *program = mGLState.getProgram();
5692 program->setUniform2uiv(location, count, value);
5693}
5694
5695void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5696{
5697 Program *program = mGLState.getProgram();
5698 program->setUniform3uiv(location, count, value);
5699}
5700
5701void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5702{
5703 Program *program = mGLState.getProgram();
5704 program->setUniform4uiv(location, count, value);
5705}
5706
Jamie Madillf0e04492017-08-26 15:28:42 -04005707void Context::genQueries(GLsizei n, GLuint *ids)
5708{
5709 for (GLsizei i = 0; i < n; i++)
5710 {
5711 GLuint handle = mQueryHandleAllocator.allocate();
5712 mQueryMap.assign(handle, nullptr);
5713 ids[i] = handle;
5714 }
5715}
5716
5717void Context::deleteQueries(GLsizei n, const GLuint *ids)
5718{
5719 for (int i = 0; i < n; i++)
5720 {
5721 GLuint query = ids[i];
5722
5723 Query *queryObject = nullptr;
5724 if (mQueryMap.erase(query, &queryObject))
5725 {
5726 mQueryHandleAllocator.release(query);
5727 if (queryObject)
5728 {
5729 queryObject->release(this);
5730 }
5731 }
5732 }
5733}
5734
5735GLboolean Context::isQuery(GLuint id)
5736{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005737 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005738}
5739
Jamie Madillc8c95812017-08-26 18:40:09 -04005740void Context::uniformMatrix2x3fv(GLint location,
5741 GLsizei count,
5742 GLboolean transpose,
5743 const GLfloat *value)
5744{
5745 Program *program = mGLState.getProgram();
5746 program->setUniformMatrix2x3fv(location, count, transpose, value);
5747}
5748
5749void Context::uniformMatrix3x2fv(GLint location,
5750 GLsizei count,
5751 GLboolean transpose,
5752 const GLfloat *value)
5753{
5754 Program *program = mGLState.getProgram();
5755 program->setUniformMatrix3x2fv(location, count, transpose, value);
5756}
5757
5758void Context::uniformMatrix2x4fv(GLint location,
5759 GLsizei count,
5760 GLboolean transpose,
5761 const GLfloat *value)
5762{
5763 Program *program = mGLState.getProgram();
5764 program->setUniformMatrix2x4fv(location, count, transpose, value);
5765}
5766
5767void Context::uniformMatrix4x2fv(GLint location,
5768 GLsizei count,
5769 GLboolean transpose,
5770 const GLfloat *value)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniformMatrix4x2fv(location, count, transpose, value);
5774}
5775
5776void Context::uniformMatrix3x4fv(GLint location,
5777 GLsizei count,
5778 GLboolean transpose,
5779 const GLfloat *value)
5780{
5781 Program *program = mGLState.getProgram();
5782 program->setUniformMatrix3x4fv(location, count, transpose, value);
5783}
5784
5785void Context::uniformMatrix4x3fv(GLint location,
5786 GLsizei count,
5787 GLboolean transpose,
5788 const GLfloat *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniformMatrix4x3fv(location, count, transpose, value);
5792}
5793
Jamie Madilld7576732017-08-26 18:49:50 -04005794void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5795{
5796 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5797 {
5798 GLuint vertexArray = arrays[arrayIndex];
5799
5800 if (arrays[arrayIndex] != 0)
5801 {
5802 VertexArray *vertexArrayObject = nullptr;
5803 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5804 {
5805 if (vertexArrayObject != nullptr)
5806 {
5807 detachVertexArray(vertexArray);
5808 vertexArrayObject->onDestroy(this);
5809 }
5810
5811 mVertexArrayHandleAllocator.release(vertexArray);
5812 }
5813 }
5814 }
5815}
5816
5817void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5818{
5819 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5820 {
5821 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5822 mVertexArrayMap.assign(vertexArray, nullptr);
5823 arrays[arrayIndex] = vertexArray;
5824 }
5825}
5826
5827bool Context::isVertexArray(GLuint array)
5828{
5829 if (array == 0)
5830 {
5831 return GL_FALSE;
5832 }
5833
5834 VertexArray *vao = getVertexArray(array);
5835 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5836}
5837
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005838void Context::endTransformFeedback()
5839{
5840 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5841 transformFeedback->end(this);
5842}
5843
5844void Context::transformFeedbackVaryings(GLuint program,
5845 GLsizei count,
5846 const GLchar *const *varyings,
5847 GLenum bufferMode)
5848{
5849 Program *programObject = getProgram(program);
5850 ASSERT(programObject);
5851 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5852}
5853
5854void Context::getTransformFeedbackVarying(GLuint program,
5855 GLuint index,
5856 GLsizei bufSize,
5857 GLsizei *length,
5858 GLsizei *size,
5859 GLenum *type,
5860 GLchar *name)
5861{
5862 Program *programObject = getProgram(program);
5863 ASSERT(programObject);
5864 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5865}
5866
5867void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5868{
5869 for (int i = 0; i < n; i++)
5870 {
5871 GLuint transformFeedback = ids[i];
5872 if (transformFeedback == 0)
5873 {
5874 continue;
5875 }
5876
5877 TransformFeedback *transformFeedbackObject = nullptr;
5878 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5879 {
5880 if (transformFeedbackObject != nullptr)
5881 {
5882 detachTransformFeedback(transformFeedback);
5883 transformFeedbackObject->release(this);
5884 }
5885
5886 mTransformFeedbackHandleAllocator.release(transformFeedback);
5887 }
5888 }
5889}
5890
5891void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5892{
5893 for (int i = 0; i < n; i++)
5894 {
5895 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5896 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5897 ids[i] = transformFeedback;
5898 }
5899}
5900
5901bool Context::isTransformFeedback(GLuint id)
5902{
5903 if (id == 0)
5904 {
5905 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5906 // returns FALSE
5907 return GL_FALSE;
5908 }
5909
5910 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5911 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5912}
5913
5914void Context::pauseTransformFeedback()
5915{
5916 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5917 transformFeedback->pause();
5918}
5919
5920void Context::resumeTransformFeedback()
5921{
5922 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5923 transformFeedback->resume();
5924}
5925
Jamie Madill12e957f2017-08-26 21:42:26 -04005926void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5927{
5928 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005929 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005930}
5931
Brandon Jones59770802018-04-02 13:18:42 -07005932void Context::getUniformuivRobust(GLuint program,
5933 GLint location,
5934 GLsizei bufSize,
5935 GLsizei *length,
5936 GLuint *params)
5937{
5938 getUniformuiv(program, location, params);
5939}
5940
Jamie Madill12e957f2017-08-26 21:42:26 -04005941GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5942{
5943 const Program *programObject = getProgram(program);
5944 return programObject->getFragDataLocation(name);
5945}
5946
5947void Context::getUniformIndices(GLuint program,
5948 GLsizei uniformCount,
5949 const GLchar *const *uniformNames,
5950 GLuint *uniformIndices)
5951{
5952 const Program *programObject = getProgram(program);
5953 if (!programObject->isLinked())
5954 {
5955 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5956 {
5957 uniformIndices[uniformId] = GL_INVALID_INDEX;
5958 }
5959 }
5960 else
5961 {
5962 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5963 {
5964 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5965 }
5966 }
5967}
5968
5969void Context::getActiveUniformsiv(GLuint program,
5970 GLsizei uniformCount,
5971 const GLuint *uniformIndices,
5972 GLenum pname,
5973 GLint *params)
5974{
5975 const Program *programObject = getProgram(program);
5976 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5977 {
5978 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005979 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005980 }
5981}
5982
5983GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5984{
5985 const Program *programObject = getProgram(program);
5986 return programObject->getUniformBlockIndex(uniformBlockName);
5987}
5988
5989void Context::getActiveUniformBlockiv(GLuint program,
5990 GLuint uniformBlockIndex,
5991 GLenum pname,
5992 GLint *params)
5993{
5994 const Program *programObject = getProgram(program);
5995 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5996}
5997
Brandon Jones59770802018-04-02 13:18:42 -07005998void Context::getActiveUniformBlockivRobust(GLuint program,
5999 GLuint uniformBlockIndex,
6000 GLenum pname,
6001 GLsizei bufSize,
6002 GLsizei *length,
6003 GLint *params)
6004{
6005 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6006}
6007
Jamie Madill12e957f2017-08-26 21:42:26 -04006008void Context::getActiveUniformBlockName(GLuint program,
6009 GLuint uniformBlockIndex,
6010 GLsizei bufSize,
6011 GLsizei *length,
6012 GLchar *uniformBlockName)
6013{
6014 const Program *programObject = getProgram(program);
6015 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6016}
6017
6018void Context::uniformBlockBinding(GLuint program,
6019 GLuint uniformBlockIndex,
6020 GLuint uniformBlockBinding)
6021{
6022 Program *programObject = getProgram(program);
6023 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6024}
6025
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006026GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6027{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006028 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6029 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006030
Jamie Madill70b5bb02017-08-28 13:32:37 -04006031 Sync *syncObject = getSync(syncHandle);
6032 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006033 if (error.isError())
6034 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006035 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006036 handleError(error);
6037 return nullptr;
6038 }
6039
Jamie Madill70b5bb02017-08-28 13:32:37 -04006040 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006041}
6042
6043GLboolean Context::isSync(GLsync sync)
6044{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006045 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006046}
6047
6048GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6049{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006050 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006051
6052 GLenum result = GL_WAIT_FAILED;
6053 handleError(syncObject->clientWait(flags, timeout, &result));
6054 return result;
6055}
6056
6057void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6058{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006059 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006060 handleError(syncObject->serverWait(flags, timeout));
6061}
6062
6063void Context::getInteger64v(GLenum pname, GLint64 *params)
6064{
6065 GLenum nativeType = GL_NONE;
6066 unsigned int numParams = 0;
6067 getQueryParameterInfo(pname, &nativeType, &numParams);
6068
6069 if (nativeType == GL_INT_64_ANGLEX)
6070 {
6071 getInteger64vImpl(pname, params);
6072 }
6073 else
6074 {
6075 CastStateValues(this, nativeType, pname, numParams, params);
6076 }
6077}
6078
Brandon Jones59770802018-04-02 13:18:42 -07006079void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6080{
6081 getInteger64v(pname, data);
6082}
6083
Corentin Wallez336129f2017-10-17 15:55:40 -04006084void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006085{
6086 Buffer *buffer = mGLState.getTargetBuffer(target);
6087 QueryBufferParameteri64v(buffer, pname, params);
6088}
6089
Brandon Jones59770802018-04-02 13:18:42 -07006090void Context::getBufferParameteri64vRobust(BufferBinding target,
6091 GLenum pname,
6092 GLsizei bufSize,
6093 GLsizei *length,
6094 GLint64 *params)
6095{
6096 getBufferParameteri64v(target, pname, params);
6097}
6098
Jamie Madill3ef140a2017-08-26 23:11:21 -04006099void Context::genSamplers(GLsizei count, GLuint *samplers)
6100{
6101 for (int i = 0; i < count; i++)
6102 {
6103 samplers[i] = mState.mSamplers->createSampler();
6104 }
6105}
6106
6107void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6108{
6109 for (int i = 0; i < count; i++)
6110 {
6111 GLuint sampler = samplers[i];
6112
6113 if (mState.mSamplers->getSampler(sampler))
6114 {
6115 detachSampler(sampler);
6116 }
6117
6118 mState.mSamplers->deleteObject(this, sampler);
6119 }
6120}
6121
6122void Context::getInternalformativ(GLenum target,
6123 GLenum internalformat,
6124 GLenum pname,
6125 GLsizei bufSize,
6126 GLint *params)
6127{
6128 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6129 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6130}
6131
Brandon Jones59770802018-04-02 13:18:42 -07006132void Context::getInternalformativRobust(GLenum target,
6133 GLenum internalformat,
6134 GLenum pname,
6135 GLsizei bufSize,
6136 GLsizei *length,
6137 GLint *params)
6138{
6139 getInternalformativ(target, internalformat, pname, bufSize, params);
6140}
6141
Jiajia Qin5451d532017-11-16 17:16:34 +08006142void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6143{
6144 programUniform1iv(program, location, 1, &v0);
6145}
6146
6147void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6148{
6149 GLint xy[2] = {v0, v1};
6150 programUniform2iv(program, location, 1, xy);
6151}
6152
6153void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6154{
6155 GLint xyz[3] = {v0, v1, v2};
6156 programUniform3iv(program, location, 1, xyz);
6157}
6158
6159void Context::programUniform4i(GLuint program,
6160 GLint location,
6161 GLint v0,
6162 GLint v1,
6163 GLint v2,
6164 GLint v3)
6165{
6166 GLint xyzw[4] = {v0, v1, v2, v3};
6167 programUniform4iv(program, location, 1, xyzw);
6168}
6169
6170void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6171{
6172 programUniform1uiv(program, location, 1, &v0);
6173}
6174
6175void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6176{
6177 GLuint xy[2] = {v0, v1};
6178 programUniform2uiv(program, location, 1, xy);
6179}
6180
6181void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6182{
6183 GLuint xyz[3] = {v0, v1, v2};
6184 programUniform3uiv(program, location, 1, xyz);
6185}
6186
6187void Context::programUniform4ui(GLuint program,
6188 GLint location,
6189 GLuint v0,
6190 GLuint v1,
6191 GLuint v2,
6192 GLuint v3)
6193{
6194 GLuint xyzw[4] = {v0, v1, v2, v3};
6195 programUniform4uiv(program, location, 1, xyzw);
6196}
6197
6198void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6199{
6200 programUniform1fv(program, location, 1, &v0);
6201}
6202
6203void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6204{
6205 GLfloat xy[2] = {v0, v1};
6206 programUniform2fv(program, location, 1, xy);
6207}
6208
6209void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6210{
6211 GLfloat xyz[3] = {v0, v1, v2};
6212 programUniform3fv(program, location, 1, xyz);
6213}
6214
6215void Context::programUniform4f(GLuint program,
6216 GLint location,
6217 GLfloat v0,
6218 GLfloat v1,
6219 GLfloat v2,
6220 GLfloat v3)
6221{
6222 GLfloat xyzw[4] = {v0, v1, v2, v3};
6223 programUniform4fv(program, location, 1, xyzw);
6224}
6225
Jamie Madill81c2e252017-09-09 23:32:46 -04006226void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6227{
6228 Program *programObject = getProgram(program);
6229 ASSERT(programObject);
6230 if (programObject->setUniform1iv(location, count, value) ==
6231 Program::SetUniformResult::SamplerChanged)
6232 {
6233 mGLState.setObjectDirty(GL_PROGRAM);
6234 }
6235}
6236
Jiajia Qin5451d532017-11-16 17:16:34 +08006237void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6238{
6239 Program *programObject = getProgram(program);
6240 ASSERT(programObject);
6241 programObject->setUniform2iv(location, count, value);
6242}
6243
6244void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6245{
6246 Program *programObject = getProgram(program);
6247 ASSERT(programObject);
6248 programObject->setUniform3iv(location, count, value);
6249}
6250
6251void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6252{
6253 Program *programObject = getProgram(program);
6254 ASSERT(programObject);
6255 programObject->setUniform4iv(location, count, value);
6256}
6257
6258void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6259{
6260 Program *programObject = getProgram(program);
6261 ASSERT(programObject);
6262 programObject->setUniform1uiv(location, count, value);
6263}
6264
6265void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6266{
6267 Program *programObject = getProgram(program);
6268 ASSERT(programObject);
6269 programObject->setUniform2uiv(location, count, value);
6270}
6271
6272void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6273{
6274 Program *programObject = getProgram(program);
6275 ASSERT(programObject);
6276 programObject->setUniform3uiv(location, count, value);
6277}
6278
6279void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6280{
6281 Program *programObject = getProgram(program);
6282 ASSERT(programObject);
6283 programObject->setUniform4uiv(location, count, value);
6284}
6285
6286void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6287{
6288 Program *programObject = getProgram(program);
6289 ASSERT(programObject);
6290 programObject->setUniform1fv(location, count, value);
6291}
6292
6293void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6294{
6295 Program *programObject = getProgram(program);
6296 ASSERT(programObject);
6297 programObject->setUniform2fv(location, count, value);
6298}
6299
6300void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6301{
6302 Program *programObject = getProgram(program);
6303 ASSERT(programObject);
6304 programObject->setUniform3fv(location, count, value);
6305}
6306
6307void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6308{
6309 Program *programObject = getProgram(program);
6310 ASSERT(programObject);
6311 programObject->setUniform4fv(location, count, value);
6312}
6313
6314void Context::programUniformMatrix2fv(GLuint program,
6315 GLint location,
6316 GLsizei count,
6317 GLboolean transpose,
6318 const GLfloat *value)
6319{
6320 Program *programObject = getProgram(program);
6321 ASSERT(programObject);
6322 programObject->setUniformMatrix2fv(location, count, transpose, value);
6323}
6324
6325void Context::programUniformMatrix3fv(GLuint program,
6326 GLint location,
6327 GLsizei count,
6328 GLboolean transpose,
6329 const GLfloat *value)
6330{
6331 Program *programObject = getProgram(program);
6332 ASSERT(programObject);
6333 programObject->setUniformMatrix3fv(location, count, transpose, value);
6334}
6335
6336void Context::programUniformMatrix4fv(GLuint program,
6337 GLint location,
6338 GLsizei count,
6339 GLboolean transpose,
6340 const GLfloat *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniformMatrix4fv(location, count, transpose, value);
6345}
6346
6347void Context::programUniformMatrix2x3fv(GLuint program,
6348 GLint location,
6349 GLsizei count,
6350 GLboolean transpose,
6351 const GLfloat *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6356}
6357
6358void Context::programUniformMatrix3x2fv(GLuint program,
6359 GLint location,
6360 GLsizei count,
6361 GLboolean transpose,
6362 const GLfloat *value)
6363{
6364 Program *programObject = getProgram(program);
6365 ASSERT(programObject);
6366 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6367}
6368
6369void Context::programUniformMatrix2x4fv(GLuint program,
6370 GLint location,
6371 GLsizei count,
6372 GLboolean transpose,
6373 const GLfloat *value)
6374{
6375 Program *programObject = getProgram(program);
6376 ASSERT(programObject);
6377 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6378}
6379
6380void Context::programUniformMatrix4x2fv(GLuint program,
6381 GLint location,
6382 GLsizei count,
6383 GLboolean transpose,
6384 const GLfloat *value)
6385{
6386 Program *programObject = getProgram(program);
6387 ASSERT(programObject);
6388 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6389}
6390
6391void Context::programUniformMatrix3x4fv(GLuint program,
6392 GLint location,
6393 GLsizei count,
6394 GLboolean transpose,
6395 const GLfloat *value)
6396{
6397 Program *programObject = getProgram(program);
6398 ASSERT(programObject);
6399 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6400}
6401
6402void Context::programUniformMatrix4x3fv(GLuint program,
6403 GLint location,
6404 GLsizei count,
6405 GLboolean transpose,
6406 const GLfloat *value)
6407{
6408 Program *programObject = getProgram(program);
6409 ASSERT(programObject);
6410 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6411}
6412
Jamie Madill81c2e252017-09-09 23:32:46 -04006413void Context::onTextureChange(const Texture *texture)
6414{
6415 // Conservatively assume all textures are dirty.
6416 // TODO(jmadill): More fine-grained update.
6417 mGLState.setObjectDirty(GL_TEXTURE);
6418}
6419
James Darpiniane8a93c62018-01-04 18:02:24 -08006420bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6421{
6422 return mGLState.isCurrentTransformFeedback(tf);
6423}
6424bool Context::isCurrentVertexArray(const VertexArray *va) const
6425{
6426 return mGLState.isCurrentVertexArray(va);
6427}
6428
Yunchao Hea336b902017-08-02 16:05:21 +08006429void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6430{
6431 for (int i = 0; i < count; i++)
6432 {
6433 pipelines[i] = createProgramPipeline();
6434 }
6435}
6436
6437void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6438{
6439 for (int i = 0; i < count; i++)
6440 {
6441 if (pipelines[i] != 0)
6442 {
6443 deleteProgramPipeline(pipelines[i]);
6444 }
6445 }
6446}
6447
6448GLboolean Context::isProgramPipeline(GLuint pipeline)
6449{
6450 if (pipeline == 0)
6451 {
6452 return GL_FALSE;
6453 }
6454
6455 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6456}
6457
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006458void Context::finishFenceNV(GLuint fence)
6459{
6460 FenceNV *fenceObject = getFenceNV(fence);
6461
6462 ASSERT(fenceObject && fenceObject->isSet());
6463 handleError(fenceObject->finish());
6464}
6465
6466void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6467{
6468 FenceNV *fenceObject = getFenceNV(fence);
6469
6470 ASSERT(fenceObject && fenceObject->isSet());
6471
6472 switch (pname)
6473 {
6474 case GL_FENCE_STATUS_NV:
6475 {
6476 // GL_NV_fence spec:
6477 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6478 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6479 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6480 GLboolean status = GL_TRUE;
6481 if (fenceObject->getStatus() != GL_TRUE)
6482 {
6483 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6484 }
6485 *params = status;
6486 break;
6487 }
6488
6489 case GL_FENCE_CONDITION_NV:
6490 {
6491 *params = static_cast<GLint>(fenceObject->getCondition());
6492 break;
6493 }
6494
6495 default:
6496 UNREACHABLE();
6497 }
6498}
6499
6500void Context::getTranslatedShaderSource(GLuint shader,
6501 GLsizei bufsize,
6502 GLsizei *length,
6503 GLchar *source)
6504{
6505 Shader *shaderObject = getShader(shader);
6506 ASSERT(shaderObject);
6507 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6508}
6509
6510void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6511{
6512 Program *programObject = getProgram(program);
6513 ASSERT(programObject);
6514
6515 programObject->getUniformfv(this, location, params);
6516}
6517
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006518void Context::getnUniformfvRobust(GLuint program,
6519 GLint location,
6520 GLsizei bufSize,
6521 GLsizei *length,
6522 GLfloat *params)
6523{
6524 UNIMPLEMENTED();
6525}
6526
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006527void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531
6532 programObject->getUniformiv(this, location, params);
6533}
6534
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006535void Context::getnUniformivRobust(GLuint program,
6536 GLint location,
6537 GLsizei bufSize,
6538 GLsizei *length,
6539 GLint *params)
6540{
6541 UNIMPLEMENTED();
6542}
6543
6544void Context::getnUniformuivRobust(GLuint program,
6545 GLint location,
6546 GLsizei bufSize,
6547 GLsizei *length,
6548 GLuint *params)
6549{
6550 UNIMPLEMENTED();
6551}
6552
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006553GLboolean Context::isFenceNV(GLuint fence)
6554{
6555 FenceNV *fenceObject = getFenceNV(fence);
6556
6557 if (fenceObject == nullptr)
6558 {
6559 return GL_FALSE;
6560 }
6561
6562 // GL_NV_fence spec:
6563 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6564 // existing fence.
6565 return fenceObject->isSet();
6566}
6567
6568void Context::readnPixels(GLint x,
6569 GLint y,
6570 GLsizei width,
6571 GLsizei height,
6572 GLenum format,
6573 GLenum type,
6574 GLsizei bufSize,
6575 void *data)
6576{
6577 return readPixels(x, y, width, height, format, type, data);
6578}
6579
Jamie Madill007530e2017-12-28 14:27:04 -05006580void Context::setFenceNV(GLuint fence, GLenum condition)
6581{
6582 ASSERT(condition == GL_ALL_COMPLETED_NV);
6583
6584 FenceNV *fenceObject = getFenceNV(fence);
6585 ASSERT(fenceObject != nullptr);
6586 handleError(fenceObject->set(condition));
6587}
6588
6589GLboolean Context::testFenceNV(GLuint fence)
6590{
6591 FenceNV *fenceObject = getFenceNV(fence);
6592
6593 ASSERT(fenceObject != nullptr);
6594 ASSERT(fenceObject->isSet() == GL_TRUE);
6595
6596 GLboolean result = GL_TRUE;
6597 Error error = fenceObject->test(&result);
6598 if (error.isError())
6599 {
6600 handleError(error);
6601 return GL_TRUE;
6602 }
6603
6604 return result;
6605}
6606
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006607void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006608{
6609 Texture *texture = getTargetTexture(target);
6610 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006611 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006612}
6613
Jamie Madillfa920eb2018-01-04 11:45:50 -05006614void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006615{
6616 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6617 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6618 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6619}
6620
Jamie Madillfa920eb2018-01-04 11:45:50 -05006621void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6622{
6623 UNIMPLEMENTED();
6624}
6625
Jamie Madill5b772312018-03-08 20:28:32 -05006626bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6627{
6628 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6629 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6630 // to the fact that it is stored internally as a float, and so would require conversion
6631 // if returned from Context::getIntegerv. Since this conversion is already implemented
6632 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6633 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6634 // application.
6635 switch (pname)
6636 {
6637 case GL_COMPRESSED_TEXTURE_FORMATS:
6638 {
6639 *type = GL_INT;
6640 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6641 return true;
6642 }
6643 case GL_SHADER_BINARY_FORMATS:
6644 {
6645 *type = GL_INT;
6646 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6647 return true;
6648 }
6649
6650 case GL_MAX_VERTEX_ATTRIBS:
6651 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6652 case GL_MAX_VARYING_VECTORS:
6653 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6654 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6655 case GL_MAX_TEXTURE_IMAGE_UNITS:
6656 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6657 case GL_MAX_RENDERBUFFER_SIZE:
6658 case GL_NUM_SHADER_BINARY_FORMATS:
6659 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6660 case GL_ARRAY_BUFFER_BINDING:
6661 case GL_FRAMEBUFFER_BINDING:
6662 case GL_RENDERBUFFER_BINDING:
6663 case GL_CURRENT_PROGRAM:
6664 case GL_PACK_ALIGNMENT:
6665 case GL_UNPACK_ALIGNMENT:
6666 case GL_GENERATE_MIPMAP_HINT:
6667 case GL_RED_BITS:
6668 case GL_GREEN_BITS:
6669 case GL_BLUE_BITS:
6670 case GL_ALPHA_BITS:
6671 case GL_DEPTH_BITS:
6672 case GL_STENCIL_BITS:
6673 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6674 case GL_CULL_FACE_MODE:
6675 case GL_FRONT_FACE:
6676 case GL_ACTIVE_TEXTURE:
6677 case GL_STENCIL_FUNC:
6678 case GL_STENCIL_VALUE_MASK:
6679 case GL_STENCIL_REF:
6680 case GL_STENCIL_FAIL:
6681 case GL_STENCIL_PASS_DEPTH_FAIL:
6682 case GL_STENCIL_PASS_DEPTH_PASS:
6683 case GL_STENCIL_BACK_FUNC:
6684 case GL_STENCIL_BACK_VALUE_MASK:
6685 case GL_STENCIL_BACK_REF:
6686 case GL_STENCIL_BACK_FAIL:
6687 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6688 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6689 case GL_DEPTH_FUNC:
6690 case GL_BLEND_SRC_RGB:
6691 case GL_BLEND_SRC_ALPHA:
6692 case GL_BLEND_DST_RGB:
6693 case GL_BLEND_DST_ALPHA:
6694 case GL_BLEND_EQUATION_RGB:
6695 case GL_BLEND_EQUATION_ALPHA:
6696 case GL_STENCIL_WRITEMASK:
6697 case GL_STENCIL_BACK_WRITEMASK:
6698 case GL_STENCIL_CLEAR_VALUE:
6699 case GL_SUBPIXEL_BITS:
6700 case GL_MAX_TEXTURE_SIZE:
6701 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6702 case GL_SAMPLE_BUFFERS:
6703 case GL_SAMPLES:
6704 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6705 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6706 case GL_TEXTURE_BINDING_2D:
6707 case GL_TEXTURE_BINDING_CUBE_MAP:
6708 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6709 {
6710 *type = GL_INT;
6711 *numParams = 1;
6712 return true;
6713 }
6714 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6715 {
6716 if (!getExtensions().packReverseRowOrder)
6717 {
6718 return false;
6719 }
6720 *type = GL_INT;
6721 *numParams = 1;
6722 return true;
6723 }
6724 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6725 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6726 {
6727 if (!getExtensions().textureRectangle)
6728 {
6729 return false;
6730 }
6731 *type = GL_INT;
6732 *numParams = 1;
6733 return true;
6734 }
6735 case GL_MAX_DRAW_BUFFERS_EXT:
6736 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6737 {
6738 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6739 {
6740 return false;
6741 }
6742 *type = GL_INT;
6743 *numParams = 1;
6744 return true;
6745 }
6746 case GL_MAX_VIEWPORT_DIMS:
6747 {
6748 *type = GL_INT;
6749 *numParams = 2;
6750 return true;
6751 }
6752 case GL_VIEWPORT:
6753 case GL_SCISSOR_BOX:
6754 {
6755 *type = GL_INT;
6756 *numParams = 4;
6757 return true;
6758 }
6759 case GL_SHADER_COMPILER:
6760 case GL_SAMPLE_COVERAGE_INVERT:
6761 case GL_DEPTH_WRITEMASK:
6762 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6763 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6764 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6765 // bool-natural
6766 case GL_SAMPLE_COVERAGE:
6767 case GL_SCISSOR_TEST:
6768 case GL_STENCIL_TEST:
6769 case GL_DEPTH_TEST:
6770 case GL_BLEND:
6771 case GL_DITHER:
6772 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6773 {
6774 *type = GL_BOOL;
6775 *numParams = 1;
6776 return true;
6777 }
6778 case GL_COLOR_WRITEMASK:
6779 {
6780 *type = GL_BOOL;
6781 *numParams = 4;
6782 return true;
6783 }
6784 case GL_POLYGON_OFFSET_FACTOR:
6785 case GL_POLYGON_OFFSET_UNITS:
6786 case GL_SAMPLE_COVERAGE_VALUE:
6787 case GL_DEPTH_CLEAR_VALUE:
6788 case GL_LINE_WIDTH:
6789 {
6790 *type = GL_FLOAT;
6791 *numParams = 1;
6792 return true;
6793 }
6794 case GL_ALIASED_LINE_WIDTH_RANGE:
6795 case GL_ALIASED_POINT_SIZE_RANGE:
6796 case GL_DEPTH_RANGE:
6797 {
6798 *type = GL_FLOAT;
6799 *numParams = 2;
6800 return true;
6801 }
6802 case GL_COLOR_CLEAR_VALUE:
6803 case GL_BLEND_COLOR:
6804 {
6805 *type = GL_FLOAT;
6806 *numParams = 4;
6807 return true;
6808 }
6809 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6810 if (!getExtensions().textureFilterAnisotropic)
6811 {
6812 return false;
6813 }
6814 *type = GL_FLOAT;
6815 *numParams = 1;
6816 return true;
6817 case GL_TIMESTAMP_EXT:
6818 if (!getExtensions().disjointTimerQuery)
6819 {
6820 return false;
6821 }
6822 *type = GL_INT_64_ANGLEX;
6823 *numParams = 1;
6824 return true;
6825 case GL_GPU_DISJOINT_EXT:
6826 if (!getExtensions().disjointTimerQuery)
6827 {
6828 return false;
6829 }
6830 *type = GL_INT;
6831 *numParams = 1;
6832 return true;
6833 case GL_COVERAGE_MODULATION_CHROMIUM:
6834 if (!getExtensions().framebufferMixedSamples)
6835 {
6836 return false;
6837 }
6838 *type = GL_INT;
6839 *numParams = 1;
6840 return true;
6841 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6842 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6843 {
6844 return false;
6845 }
6846 *type = GL_INT;
6847 *numParams = 1;
6848 return true;
6849 }
6850
6851 if (getExtensions().debug)
6852 {
6853 switch (pname)
6854 {
6855 case GL_DEBUG_LOGGED_MESSAGES:
6856 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6857 case GL_DEBUG_GROUP_STACK_DEPTH:
6858 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6859 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6860 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6861 case GL_MAX_LABEL_LENGTH:
6862 *type = GL_INT;
6863 *numParams = 1;
6864 return true;
6865
6866 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6867 case GL_DEBUG_OUTPUT:
6868 *type = GL_BOOL;
6869 *numParams = 1;
6870 return true;
6871 }
6872 }
6873
6874 if (getExtensions().multisampleCompatibility)
6875 {
6876 switch (pname)
6877 {
6878 case GL_MULTISAMPLE_EXT:
6879 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6880 *type = GL_BOOL;
6881 *numParams = 1;
6882 return true;
6883 }
6884 }
6885
6886 if (getExtensions().pathRendering)
6887 {
6888 switch (pname)
6889 {
6890 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6891 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6892 *type = GL_FLOAT;
6893 *numParams = 16;
6894 return true;
6895 }
6896 }
6897
6898 if (getExtensions().bindGeneratesResource)
6899 {
6900 switch (pname)
6901 {
6902 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6903 *type = GL_BOOL;
6904 *numParams = 1;
6905 return true;
6906 }
6907 }
6908
6909 if (getExtensions().clientArrays)
6910 {
6911 switch (pname)
6912 {
6913 case GL_CLIENT_ARRAYS_ANGLE:
6914 *type = GL_BOOL;
6915 *numParams = 1;
6916 return true;
6917 }
6918 }
6919
6920 if (getExtensions().sRGBWriteControl)
6921 {
6922 switch (pname)
6923 {
6924 case GL_FRAMEBUFFER_SRGB_EXT:
6925 *type = GL_BOOL;
6926 *numParams = 1;
6927 return true;
6928 }
6929 }
6930
6931 if (getExtensions().robustResourceInitialization &&
6932 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6933 {
6934 *type = GL_BOOL;
6935 *numParams = 1;
6936 return true;
6937 }
6938
6939 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6940 {
6941 *type = GL_BOOL;
6942 *numParams = 1;
6943 return true;
6944 }
6945
6946 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6947 switch (pname)
6948 {
6949 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6950 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6951 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6952 {
6953 return false;
6954 }
6955 *type = GL_INT;
6956 *numParams = 1;
6957 return true;
6958
6959 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6960 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6961 {
6962 return false;
6963 }
6964 *type = GL_INT;
6965 *numParams = 1;
6966 return true;
6967
6968 case GL_PROGRAM_BINARY_FORMATS_OES:
6969 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6970 {
6971 return false;
6972 }
6973 *type = GL_INT;
6974 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6975 return true;
6976
6977 case GL_PACK_ROW_LENGTH:
6978 case GL_PACK_SKIP_ROWS:
6979 case GL_PACK_SKIP_PIXELS:
6980 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6981 {
6982 return false;
6983 }
6984 *type = GL_INT;
6985 *numParams = 1;
6986 return true;
6987 case GL_UNPACK_ROW_LENGTH:
6988 case GL_UNPACK_SKIP_ROWS:
6989 case GL_UNPACK_SKIP_PIXELS:
6990 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = 1;
6996 return true;
6997 case GL_VERTEX_ARRAY_BINDING:
6998 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6999 {
7000 return false;
7001 }
7002 *type = GL_INT;
7003 *numParams = 1;
7004 return true;
7005 case GL_PIXEL_PACK_BUFFER_BINDING:
7006 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7007 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7008 {
7009 return false;
7010 }
7011 *type = GL_INT;
7012 *numParams = 1;
7013 return true;
7014 case GL_MAX_SAMPLES:
7015 {
7016 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7017 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7018 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7019 {
7020 return false;
7021 }
7022 *type = GL_INT;
7023 *numParams = 1;
7024 return true;
7025
7026 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7027 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7028 {
7029 return false;
7030 }
7031 *type = GL_INT;
7032 *numParams = 1;
7033 return true;
7034 }
7035 }
7036
7037 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7038 {
7039 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7040 {
7041 return false;
7042 }
7043 *type = GL_INT;
7044 *numParams = 1;
7045 return true;
7046 }
7047
7048 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7049 {
7050 *type = GL_INT;
7051 *numParams = 1;
7052 return true;
7053 }
7054
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007055 if (getClientVersion() < Version(2, 0))
7056 {
7057 switch (pname)
7058 {
7059 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007060 case GL_CLIENT_ACTIVE_TEXTURE:
7061 case GL_MATRIX_MODE:
7062 case GL_MAX_TEXTURE_UNITS:
7063 case GL_MAX_MODELVIEW_STACK_DEPTH:
7064 case GL_MAX_PROJECTION_STACK_DEPTH:
7065 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007066 case GL_MAX_LIGHTS:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007067 case GL_VERTEX_ARRAY_STRIDE:
7068 case GL_NORMAL_ARRAY_STRIDE:
7069 case GL_COLOR_ARRAY_STRIDE:
7070 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7071 case GL_VERTEX_ARRAY_SIZE:
7072 case GL_COLOR_ARRAY_SIZE:
7073 case GL_TEXTURE_COORD_ARRAY_SIZE:
7074 case GL_VERTEX_ARRAY_TYPE:
7075 case GL_NORMAL_ARRAY_TYPE:
7076 case GL_COLOR_ARRAY_TYPE:
7077 case GL_TEXTURE_COORD_ARRAY_TYPE:
7078 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7079 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7080 case GL_COLOR_ARRAY_BUFFER_BINDING:
7081 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7082 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7083 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7084 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007085 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007086 *type = GL_INT;
7087 *numParams = 1;
7088 return true;
7089 case GL_ALPHA_TEST_REF:
7090 *type = GL_FLOAT;
7091 *numParams = 1;
7092 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007093 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007094 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007095 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007096 *type = GL_FLOAT;
7097 *numParams = 4;
7098 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007099 case GL_CURRENT_NORMAL:
7100 *type = GL_FLOAT;
7101 *numParams = 3;
7102 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007103 case GL_MODELVIEW_MATRIX:
7104 case GL_PROJECTION_MATRIX:
7105 case GL_TEXTURE_MATRIX:
7106 *type = GL_FLOAT;
7107 *numParams = 16;
7108 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007109 case GL_LIGHT_MODEL_TWO_SIDE:
7110 *type = GL_BOOL;
7111 *numParams = 1;
7112 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007113 }
7114 }
7115
Jamie Madill5b772312018-03-08 20:28:32 -05007116 if (getClientVersion() < Version(3, 0))
7117 {
7118 return false;
7119 }
7120
7121 // Check for ES3.0+ parameter names
7122 switch (pname)
7123 {
7124 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7125 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7126 case GL_UNIFORM_BUFFER_BINDING:
7127 case GL_TRANSFORM_FEEDBACK_BINDING:
7128 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7129 case GL_COPY_READ_BUFFER_BINDING:
7130 case GL_COPY_WRITE_BUFFER_BINDING:
7131 case GL_SAMPLER_BINDING:
7132 case GL_READ_BUFFER:
7133 case GL_TEXTURE_BINDING_3D:
7134 case GL_TEXTURE_BINDING_2D_ARRAY:
7135 case GL_MAX_3D_TEXTURE_SIZE:
7136 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7137 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7138 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7139 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7140 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7141 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7142 case GL_MAX_VARYING_COMPONENTS:
7143 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7144 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7145 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7146 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7147 case GL_NUM_EXTENSIONS:
7148 case GL_MAJOR_VERSION:
7149 case GL_MINOR_VERSION:
7150 case GL_MAX_ELEMENTS_INDICES:
7151 case GL_MAX_ELEMENTS_VERTICES:
7152 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7153 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7154 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7155 case GL_UNPACK_IMAGE_HEIGHT:
7156 case GL_UNPACK_SKIP_IMAGES:
7157 {
7158 *type = GL_INT;
7159 *numParams = 1;
7160 return true;
7161 }
7162
7163 case GL_MAX_ELEMENT_INDEX:
7164 case GL_MAX_UNIFORM_BLOCK_SIZE:
7165 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7166 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7167 case GL_MAX_SERVER_WAIT_TIMEOUT:
7168 {
7169 *type = GL_INT_64_ANGLEX;
7170 *numParams = 1;
7171 return true;
7172 }
7173
7174 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7175 case GL_TRANSFORM_FEEDBACK_PAUSED:
7176 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7177 case GL_RASTERIZER_DISCARD:
7178 {
7179 *type = GL_BOOL;
7180 *numParams = 1;
7181 return true;
7182 }
7183
7184 case GL_MAX_TEXTURE_LOD_BIAS:
7185 {
7186 *type = GL_FLOAT;
7187 *numParams = 1;
7188 return true;
7189 }
7190 }
7191
7192 if (getExtensions().requestExtension)
7193 {
7194 switch (pname)
7195 {
7196 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7197 *type = GL_INT;
7198 *numParams = 1;
7199 return true;
7200 }
7201 }
7202
7203 if (getClientVersion() < Version(3, 1))
7204 {
7205 return false;
7206 }
7207
7208 switch (pname)
7209 {
7210 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7211 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7212 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7213 case GL_MAX_FRAMEBUFFER_WIDTH:
7214 case GL_MAX_FRAMEBUFFER_HEIGHT:
7215 case GL_MAX_FRAMEBUFFER_SAMPLES:
7216 case GL_MAX_SAMPLE_MASK_WORDS:
7217 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7218 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7219 case GL_MAX_INTEGER_SAMPLES:
7220 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7221 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7222 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7223 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7224 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7225 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7226 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7227 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7228 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7229 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7230 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7231 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7232 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7233 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7234 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7235 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7236 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7237 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7238 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7239 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7240 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7241 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7242 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7243 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7244 case GL_MAX_UNIFORM_LOCATIONS:
7245 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7246 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7247 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7248 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7249 case GL_MAX_IMAGE_UNITS:
7250 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7251 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7252 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7253 case GL_SHADER_STORAGE_BUFFER_BINDING:
7254 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7255 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7256 *type = GL_INT;
7257 *numParams = 1;
7258 return true;
7259 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7260 *type = GL_INT_64_ANGLEX;
7261 *numParams = 1;
7262 return true;
7263 case GL_SAMPLE_MASK:
7264 *type = GL_BOOL;
7265 *numParams = 1;
7266 return true;
7267 }
7268
7269 if (getExtensions().geometryShader)
7270 {
7271 switch (pname)
7272 {
7273 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7274 case GL_LAYER_PROVOKING_VERTEX_EXT:
7275 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7276 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7277 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7278 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7279 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7280 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7281 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7282 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7283 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7284 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7285 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7286 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7287 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7288 *type = GL_INT;
7289 *numParams = 1;
7290 return true;
7291 }
7292 }
7293
7294 return false;
7295}
7296
7297bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7298{
7299 if (getClientVersion() < Version(3, 0))
7300 {
7301 return false;
7302 }
7303
7304 switch (target)
7305 {
7306 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7307 case GL_UNIFORM_BUFFER_BINDING:
7308 {
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7314 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7315 case GL_UNIFORM_BUFFER_START:
7316 case GL_UNIFORM_BUFFER_SIZE:
7317 {
7318 *type = GL_INT_64_ANGLEX;
7319 *numParams = 1;
7320 return true;
7321 }
7322 }
7323
7324 if (getClientVersion() < Version(3, 1))
7325 {
7326 return false;
7327 }
7328
7329 switch (target)
7330 {
7331 case GL_IMAGE_BINDING_LAYERED:
7332 {
7333 *type = GL_BOOL;
7334 *numParams = 1;
7335 return true;
7336 }
7337 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7338 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7339 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7340 case GL_SHADER_STORAGE_BUFFER_BINDING:
7341 case GL_VERTEX_BINDING_BUFFER:
7342 case GL_VERTEX_BINDING_DIVISOR:
7343 case GL_VERTEX_BINDING_OFFSET:
7344 case GL_VERTEX_BINDING_STRIDE:
7345 case GL_SAMPLE_MASK_VALUE:
7346 case GL_IMAGE_BINDING_NAME:
7347 case GL_IMAGE_BINDING_LEVEL:
7348 case GL_IMAGE_BINDING_LAYER:
7349 case GL_IMAGE_BINDING_ACCESS:
7350 case GL_IMAGE_BINDING_FORMAT:
7351 {
7352 *type = GL_INT;
7353 *numParams = 1;
7354 return true;
7355 }
7356 case GL_ATOMIC_COUNTER_BUFFER_START:
7357 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7358 case GL_SHADER_STORAGE_BUFFER_START:
7359 case GL_SHADER_STORAGE_BUFFER_SIZE:
7360 {
7361 *type = GL_INT_64_ANGLEX;
7362 *numParams = 1;
7363 return true;
7364 }
7365 }
7366
7367 return false;
7368}
7369
7370Program *Context::getProgram(GLuint handle) const
7371{
7372 return mState.mShaderPrograms->getProgram(handle);
7373}
7374
7375Shader *Context::getShader(GLuint handle) const
7376{
7377 return mState.mShaderPrograms->getShader(handle);
7378}
7379
7380bool Context::isTextureGenerated(GLuint texture) const
7381{
7382 return mState.mTextures->isHandleGenerated(texture);
7383}
7384
7385bool Context::isBufferGenerated(GLuint buffer) const
7386{
7387 return mState.mBuffers->isHandleGenerated(buffer);
7388}
7389
7390bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7391{
7392 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7393}
7394
7395bool Context::isFramebufferGenerated(GLuint framebuffer) const
7396{
7397 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7398}
7399
7400bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7401{
7402 return mState.mPipelines->isHandleGenerated(pipeline);
7403}
7404
7405bool Context::usingDisplayTextureShareGroup() const
7406{
7407 return mDisplayTextureShareGroup;
7408}
7409
7410GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7411{
7412 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7413 internalformat == GL_DEPTH_STENCIL
7414 ? GL_DEPTH24_STENCIL8
7415 : internalformat;
7416}
7417
Jamie Madillc29968b2016-01-20 11:17:23 -05007418} // namespace gl