blob: 15a2a794d00c118afe7ae0573572d4249e93222d [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"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Geoff Langf6db0982015-08-25 13:04:00 -0400262} // anonymous namespace
263
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000264namespace gl
265{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000266
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400267Context::Context(rx::EGLImplFactory *implFactory,
268 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400269 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500270 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400271 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500272 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400273 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500274 : mState(reinterpret_cast<ContextID>(this),
275 shareContext ? &shareContext->mState : nullptr,
276 shareTextures,
277 GetClientVersion(attribs),
278 &mGLState,
279 mCaps,
280 mTextureCaps,
281 mExtensions,
282 mLimitations),
283 mSkipValidation(GetNoError(attribs)),
284 mDisplayTextureShareGroup(shareTextures != nullptr),
285 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700286 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400287 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400288 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500289 mClientType(EGL_OPENGL_ES_API),
290 mHasBeenCurrent(false),
291 mContextLost(false),
292 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700293 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500294 mResetStrategy(GetResetStrategy(attribs)),
295 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400296 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
297 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500298 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500299 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400300 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400301 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400302 mScratchBuffer(1000u),
303 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000304{
Jamie Madill5b772312018-03-08 20:28:32 -0500305 // Needed to solve a Clang warning of unused variables.
306 UNUSED_VARIABLE(mSavedArgsType);
307 UNUSED_VARIABLE(mParamsBuffer);
308
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400309 mImplementation->setMemoryProgramCache(memoryProgramCache);
310
Geoff Langb433e872017-10-05 14:01:47 -0400311 bool robustResourceInit = GetRobustResourceInit(attribs);
312 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700313 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400314
Jamie Madill4928b7c2017-06-20 12:57:39 -0400315 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400316 GetClientArraysEnabled(attribs), robustResourceInit,
317 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100318
Shannon Woods53a94a82014-06-24 15:20:36 -0400319 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400320
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000321 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400322 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000323 // and cube map texture state vectors respectively associated with them.
324 // In order that access to these initial textures not be lost, they are treated as texture
325 // objects all of whose names are 0.
326
Corentin Wallez99d492c2018-02-27 15:17:10 -0500327 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800328 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500329
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400332
Geoff Langeb66a6e2016-10-31 13:06:12 -0400333 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400334 {
335 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500336 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800337 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400338
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400341 }
Geoff Lang3b573612016-10-31 14:08:10 -0400342 if (getClientVersion() >= Version(3, 1))
343 {
344 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500345 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800346 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800347
Jiajia Qin6eafb042016-12-27 17:04:07 +0800348 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
349 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800350 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800351 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800352
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800353 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
354 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400355 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800356 }
Geoff Lang3b573612016-10-31 14:08:10 -0400357 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000358
Geoff Lang4751aab2017-10-30 15:14:52 -0400359 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
360 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400361 {
362 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400365 }
366
Geoff Lang4751aab2017-10-30 15:14:52 -0400367 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400368 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500369 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800370 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400371 }
372
Jamie Madill4928b7c2017-06-20 12:57:39 -0400373 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500374
Jamie Madill57a89722013-07-02 11:57:03 -0400375 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000376
Geoff Langeb66a6e2016-10-31 13:06:12 -0400377 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400378 {
379 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
380 // In the initial state, a default transform feedback object is bound and treated as
381 // a transform feedback object with a name of zero. That object is bound any time
382 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400383 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400384 }
Geoff Langc8058452014-02-03 12:04:11 -0500385
Corentin Wallez336129f2017-10-17 15:55:40 -0400386 for (auto type : angle::AllEnums<BufferBinding>())
387 {
388 bindBuffer(type, 0);
389 }
390
391 bindRenderbuffer(GL_RENDERBUFFER, 0);
392
393 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
394 {
395 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
396 }
397
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400399 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500400 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500401 // No dirty objects.
402
403 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
407
408 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
409 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
411 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
412 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
415 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
416 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
419 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
420
421 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700423 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500424 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400426
Xinghua Cao10a4d432017-11-28 14:46:26 +0800427 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
428 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
429 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
430 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
431 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
432 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800433 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800434
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400435 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000436}
437
Jamie Madill4928b7c2017-06-20 12:57:39 -0400438egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439{
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400444 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445
Corentin Wallez80b24112015-08-25 16:41:57 -0400446 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400448 if (query.second != nullptr)
449 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400450 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400451 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400453 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400456 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400457 if (vertexArray.second)
458 {
459 vertexArray.second->onDestroy(this);
460 }
Jamie Madill57a89722013-07-02 11:57:03 -0400461 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400462 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400463
Corentin Wallez80b24112015-08-25 16:41:57 -0400464 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500465 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500466 if (transformFeedback.second != nullptr)
467 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500468 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500469 }
Geoff Langc8058452014-02-03 12:04:11 -0500470 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400471 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500472
Jamie Madill5b772312018-03-08 20:28:32 -0500473 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400474 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800475 if (zeroTexture.get() != nullptr)
476 {
477 ANGLE_TRY(zeroTexture->onDestroy(this));
478 zeroTexture.set(this, nullptr);
479 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400480 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481
Corentin Wallezccab69d2017-01-27 16:57:15 -0500482 SafeDelete(mSurfacelessFramebuffer);
483
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400485 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487 mGLState.reset(this);
488
Jamie Madill6c1f6712017-02-14 19:08:04 -0500489 mState.mBuffers->release(this);
490 mState.mShaderPrograms->release(this);
491 mState.mTextures->release(this);
492 mState.mRenderbuffers->release(this);
493 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400494 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500495 mState.mPaths->release(this);
496 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800497 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498
Jamie Madill76e471e2017-10-21 09:56:01 -0400499 mImplementation->onDestroy(this);
500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502}
503
Jamie Madill70ee0f62017-02-06 16:04:20 -0500504Context::~Context()
505{
506}
507
Jamie Madill4928b7c2017-06-20 12:57:39 -0400508egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509{
Jamie Madill61e16b42017-06-19 11:13:23 -0400510 mCurrentDisplay = display;
511
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000512 if (!mHasBeenCurrent)
513 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500515 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400516 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517
Corentin Wallezc295e512017-01-27 17:47:50 -0500518 int width = 0;
519 int height = 0;
520 if (surface != nullptr)
521 {
522 width = surface->getWidth();
523 height = surface->getHeight();
524 }
525
526 mGLState.setViewportParams(0, 0, width, height);
527 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528
529 mHasBeenCurrent = true;
530 }
531
Jamie Madill1b94d432015-08-07 13:23:23 -0400532 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700533 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400534 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400535
Jamie Madill4928b7c2017-06-20 12:57:39 -0400536 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500537
538 Framebuffer *newDefault = nullptr;
539 if (surface != nullptr)
540 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400541 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500542 mCurrentSurface = surface;
543 newDefault = surface->getDefaultFramebuffer();
544 }
545 else
546 {
547 if (mSurfacelessFramebuffer == nullptr)
548 {
549 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
550 }
551
552 newDefault = mSurfacelessFramebuffer;
553 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000554
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 // Update default framebuffer, the binding of the previous default
556 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400557 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700560 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700562 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400563 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700564 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400565 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500566 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400567 }
Ian Ewell292f0052016-02-04 10:37:32 -0500568
569 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570 mImplementation->onMakeCurrent(this);
571 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000572}
573
Jamie Madill4928b7c2017-06-20 12:57:39 -0400574egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400575{
Corentin Wallez37c39792015-08-20 14:19:46 -0400576 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 Framebuffer *currentDefault = nullptr;
578 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400579 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500580 currentDefault = mCurrentSurface->getDefaultFramebuffer();
581 }
582 else if (mSurfacelessFramebuffer != nullptr)
583 {
584 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400585 }
586
Corentin Wallezc295e512017-01-27 17:47:50 -0500587 if (mGLState.getReadFramebuffer() == currentDefault)
588 {
589 mGLState.setReadFramebufferBinding(nullptr);
590 }
591 if (mGLState.getDrawFramebuffer() == currentDefault)
592 {
593 mGLState.setDrawFramebufferBinding(nullptr);
594 }
595 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
596
597 if (mCurrentSurface)
598 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 mCurrentSurface = nullptr;
601 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602
603 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400604}
605
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606GLuint Context::createBuffer()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609}
610
611GLuint Context::createProgram()
612{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500613 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614}
615
616GLuint Context::createShader(GLenum type)
617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619}
620
621GLuint Context::createTexture()
622{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500623 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000624}
625
626GLuint Context::createRenderbuffer()
627{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500628 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
Sami Väisänene45e53b2016-05-25 10:36:04 +0300631GLuint Context::createPaths(GLsizei range)
632{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500633 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300634 if (resultOrError.isError())
635 {
636 handleError(resultOrError.getError());
637 return 0;
638 }
639 return resultOrError.getResult();
640}
641
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642// Returns an unused framebuffer name
643GLuint Context::createFramebuffer()
644{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500645 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646}
647
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500648void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500650 for (int i = 0; i < n; i++)
651 {
652 GLuint handle = mFenceNVHandleAllocator.allocate();
653 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
654 fences[i] = handle;
655 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656}
657
Yunchao Hea336b902017-08-02 16:05:21 +0800658GLuint Context::createProgramPipeline()
659{
660 return mState.mPipelines->createProgramPipeline();
661}
662
Jiajia Qin5451d532017-11-16 17:16:34 +0800663GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
664{
665 UNIMPLEMENTED();
666 return 0u;
667}
668
James Darpinian4d9d4832018-03-13 12:43:28 -0700669void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670{
James Darpinian4d9d4832018-03-13 12:43:28 -0700671 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
672 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673 {
674 detachBuffer(buffer);
675 }
Jamie Madill893ab082014-05-16 16:56:10 -0400676
James Darpinian4d9d4832018-03-13 12:43:28 -0700677 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
680void Context::deleteShader(GLuint shader)
681{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500682 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683}
684
685void Context::deleteProgram(GLuint program)
686{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500687 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
690void Context::deleteTexture(GLuint texture)
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693 {
694 detachTexture(texture);
695 }
696
Jamie Madill6c1f6712017-02-14 19:08:04 -0500697 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700void Context::deleteRenderbuffer(GLuint renderbuffer)
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703 {
704 detachRenderbuffer(renderbuffer);
705 }
Jamie Madill893ab082014-05-16 16:56:10 -0400706
Jamie Madill6c1f6712017-02-14 19:08:04 -0500707 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400710void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400711{
712 // The spec specifies the underlying Fence object is not deleted until all current
713 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
714 // and since our API is currently designed for being called from a single thread, we can delete
715 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400716 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400717}
718
Yunchao Hea336b902017-08-02 16:05:21 +0800719void Context::deleteProgramPipeline(GLuint pipeline)
720{
721 if (mState.mPipelines->getProgramPipeline(pipeline))
722 {
723 detachProgramPipeline(pipeline);
724 }
725
726 mState.mPipelines->deleteObject(this, pipeline);
727}
728
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729void Context::deletePaths(GLuint first, GLsizei range)
730{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500731 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732}
733
734bool Context::hasPathData(GLuint path) const
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737 if (pathObj == nullptr)
738 return false;
739
740 return pathObj->hasPathData();
741}
742
743bool Context::hasPath(GLuint path) const
744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746}
747
748void Context::setPathCommands(GLuint path,
749 GLsizei numCommands,
750 const GLubyte *commands,
751 GLsizei numCoords,
752 GLenum coordType,
753 const void *coords)
754{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500755 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300756
757 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
758}
759
Jamie Madill007530e2017-12-28 14:27:04 -0500760void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300761{
Jamie Madill007530e2017-12-28 14:27:04 -0500762 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763
764 switch (pname)
765 {
766 case GL_PATH_STROKE_WIDTH_CHROMIUM:
767 pathObj->setStrokeWidth(value);
768 break;
769 case GL_PATH_END_CAPS_CHROMIUM:
770 pathObj->setEndCaps(static_cast<GLenum>(value));
771 break;
772 case GL_PATH_JOIN_STYLE_CHROMIUM:
773 pathObj->setJoinStyle(static_cast<GLenum>(value));
774 break;
775 case GL_PATH_MITER_LIMIT_CHROMIUM:
776 pathObj->setMiterLimit(value);
777 break;
778 case GL_PATH_STROKE_BOUND_CHROMIUM:
779 pathObj->setStrokeBound(value);
780 break;
781 default:
782 UNREACHABLE();
783 break;
784 }
785}
786
Jamie Madill007530e2017-12-28 14:27:04 -0500787void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300788{
Jamie Madill007530e2017-12-28 14:27:04 -0500789 // TODO(jmadill): Should use proper clamping/casting.
790 pathParameterf(path, pname, static_cast<GLfloat>(value));
791}
792
793void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
794{
795 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300796
797 switch (pname)
798 {
799 case GL_PATH_STROKE_WIDTH_CHROMIUM:
800 *value = pathObj->getStrokeWidth();
801 break;
802 case GL_PATH_END_CAPS_CHROMIUM:
803 *value = static_cast<GLfloat>(pathObj->getEndCaps());
804 break;
805 case GL_PATH_JOIN_STYLE_CHROMIUM:
806 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
807 break;
808 case GL_PATH_MITER_LIMIT_CHROMIUM:
809 *value = pathObj->getMiterLimit();
810 break;
811 case GL_PATH_STROKE_BOUND_CHROMIUM:
812 *value = pathObj->getStrokeBound();
813 break;
814 default:
815 UNREACHABLE();
816 break;
817 }
818}
819
Jamie Madill007530e2017-12-28 14:27:04 -0500820void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
821{
822 GLfloat val = 0.0f;
823 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
824 if (value)
825 *value = static_cast<GLint>(val);
826}
827
Sami Väisänene45e53b2016-05-25 10:36:04 +0300828void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
829{
830 mGLState.setPathStencilFunc(func, ref, mask);
831}
832
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833void Context::deleteFramebuffer(GLuint framebuffer)
834{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500835 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000836 {
837 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500839
Jamie Madill6c1f6712017-02-14 19:08:04 -0500840 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841}
842
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500843void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500845 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500847 GLuint fence = fences[i];
848
849 FenceNV *fenceObject = nullptr;
850 if (mFenceNVMap.erase(fence, &fenceObject))
851 {
852 mFenceNVHandleAllocator.release(fence);
853 delete fenceObject;
854 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855 }
856}
857
Geoff Lang70d0f492015-12-10 17:45:46 -0500858Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500860 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861}
862
Jamie Madill570f7c82014-07-03 10:38:54 -0400863Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500865 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866}
867
Geoff Lang70d0f492015-12-10 17:45:46 -0500868Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000871}
872
Jamie Madill70b5bb02017-08-28 13:32:37 -0400873Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400874{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400875 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400876}
877
Jamie Madill57a89722013-07-02 11:57:03 -0400878VertexArray *Context::getVertexArray(GLuint handle) const
879{
Jamie Madill96a483b2017-06-27 16:49:21 -0400880 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400881}
882
Jamie Madilldc356042013-07-19 16:36:57 -0400883Sampler *Context::getSampler(GLuint handle) const
884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400886}
887
Geoff Langc8058452014-02-03 12:04:11 -0500888TransformFeedback *Context::getTransformFeedback(GLuint handle) const
889{
Jamie Madill96a483b2017-06-27 16:49:21 -0400890 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500891}
892
Yunchao Hea336b902017-08-02 16:05:21 +0800893ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
894{
895 return mState.mPipelines->getProgramPipeline(handle);
896}
897
Geoff Lang70d0f492015-12-10 17:45:46 -0500898LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
899{
900 switch (identifier)
901 {
902 case GL_BUFFER:
903 return getBuffer(name);
904 case GL_SHADER:
905 return getShader(name);
906 case GL_PROGRAM:
907 return getProgram(name);
908 case GL_VERTEX_ARRAY:
909 return getVertexArray(name);
910 case GL_QUERY:
911 return getQuery(name);
912 case GL_TRANSFORM_FEEDBACK:
913 return getTransformFeedback(name);
914 case GL_SAMPLER:
915 return getSampler(name);
916 case GL_TEXTURE:
917 return getTexture(name);
918 case GL_RENDERBUFFER:
919 return getRenderbuffer(name);
920 case GL_FRAMEBUFFER:
921 return getFramebuffer(name);
922 default:
923 UNREACHABLE();
924 return nullptr;
925 }
926}
927
928LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
929{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400930 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500931}
932
Martin Radev9d901792016-07-15 15:58:58 +0300933void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
934{
935 LabeledObject *object = getLabeledObject(identifier, name);
936 ASSERT(object != nullptr);
937
938 std::string labelName = GetObjectLabelFromPointer(length, label);
939 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400940
941 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
942 // specified object is active until we do this.
943 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300944}
945
946void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
947{
948 LabeledObject *object = getLabeledObjectFromPtr(ptr);
949 ASSERT(object != nullptr);
950
951 std::string labelName = GetObjectLabelFromPointer(length, label);
952 object->setLabel(labelName);
953}
954
955void Context::getObjectLabel(GLenum identifier,
956 GLuint name,
957 GLsizei bufSize,
958 GLsizei *length,
959 GLchar *label) const
960{
961 LabeledObject *object = getLabeledObject(identifier, name);
962 ASSERT(object != nullptr);
963
964 const std::string &objectLabel = object->getLabel();
965 GetObjectLabelBase(objectLabel, bufSize, length, label);
966}
967
968void Context::getObjectPtrLabel(const void *ptr,
969 GLsizei bufSize,
970 GLsizei *length,
971 GLchar *label) const
972{
973 LabeledObject *object = getLabeledObjectFromPtr(ptr);
974 ASSERT(object != nullptr);
975
976 const std::string &objectLabel = object->getLabel();
977 GetObjectLabelBase(objectLabel, bufSize, length, label);
978}
979
Jamie Madilldc356042013-07-19 16:36:57 -0400980bool Context::isSampler(GLuint samplerName) const
981{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500982 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400983}
984
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800985void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000986{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500987 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988
Jamie Madilldedd7b92014-11-05 16:30:36 -0500989 if (handle == 0)
990 {
991 texture = mZeroTextures[target].get();
992 }
993 else
994 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500995 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500996 }
997
998 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400999 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001000}
1001
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001002void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001003{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001004 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1005 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001006 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007}
1008
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001009void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001011 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1012 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001013 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001014}
1015
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001016void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001017{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001018 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001019 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001020}
1021
Shao80957d92017-02-20 21:25:59 +08001022void Context::bindVertexBuffer(GLuint bindingIndex,
1023 GLuint bufferHandle,
1024 GLintptr offset,
1025 GLsizei stride)
1026{
1027 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001028 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001029}
1030
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001032{
Geoff Lang76b10c92014-09-05 16:28:14 -04001033 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001034 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001035 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001036 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001037}
1038
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001039void Context::bindImageTexture(GLuint unit,
1040 GLuint texture,
1041 GLint level,
1042 GLboolean layered,
1043 GLint layer,
1044 GLenum access,
1045 GLenum format)
1046{
1047 Texture *tex = mState.mTextures->getTexture(texture);
1048 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1049}
1050
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051void Context::useProgram(GLuint program)
1052{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001053 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001054}
1055
Jiajia Qin5451d532017-11-16 17:16:34 +08001056void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1057{
1058 UNIMPLEMENTED();
1059}
1060
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001061void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001062{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001063 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001064 TransformFeedback *transformFeedback =
1065 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001066 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001067}
1068
Yunchao Hea336b902017-08-02 16:05:21 +08001069void Context::bindProgramPipeline(GLuint pipelineHandle)
1070{
1071 ProgramPipeline *pipeline =
1072 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1073 mGLState.setProgramPipelineBinding(this, pipeline);
1074}
1075
Jamie Madillf0e04492017-08-26 15:28:42 -04001076void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001079 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080
Geoff Lang5aad9672014-09-08 11:10:42 -04001081 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001082 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001083
1084 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001085 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086}
1087
Jamie Madillf0e04492017-08-26 15:28:42 -04001088void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001090 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001091 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001092
Jamie Madillf0e04492017-08-26 15:28:42 -04001093 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001094
Geoff Lang5aad9672014-09-08 11:10:42 -04001095 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001096 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097}
1098
Jamie Madillf0e04492017-08-26 15:28:42 -04001099void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001100{
1101 ASSERT(target == GL_TIMESTAMP_EXT);
1102
1103 Query *queryObject = getQuery(id, true, target);
1104 ASSERT(queryObject);
1105
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001107}
1108
1109void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1110{
1111 switch (pname)
1112 {
1113 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001114 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115 break;
1116 case GL_QUERY_COUNTER_BITS_EXT:
1117 switch (target)
1118 {
1119 case GL_TIME_ELAPSED_EXT:
1120 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1121 break;
1122 case GL_TIMESTAMP_EXT:
1123 params[0] = getExtensions().queryCounterBitsTimestamp;
1124 break;
1125 default:
1126 UNREACHABLE();
1127 params[0] = 0;
1128 break;
1129 }
1130 break;
1131 default:
1132 UNREACHABLE();
1133 return;
1134 }
1135}
1136
Geoff Lang2186c382016-10-14 10:54:54 -04001137void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001138{
Geoff Lang2186c382016-10-14 10:54:54 -04001139 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140}
1141
Geoff Lang2186c382016-10-14 10:54:54 -04001142void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001143{
Geoff Lang2186c382016-10-14 10:54:54 -04001144 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001145}
1146
Geoff Lang2186c382016-10-14 10:54:54 -04001147void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001148{
Geoff Lang2186c382016-10-14 10:54:54 -04001149 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001150}
1151
Geoff Lang2186c382016-10-14 10:54:54 -04001152void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001153{
Geoff Lang2186c382016-10-14 10:54:54 -04001154 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001155}
1156
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001157Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001159 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160}
1161
Jamie Madill2f348d22017-06-05 10:50:59 -04001162FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163{
Jamie Madill96a483b2017-06-27 16:49:21 -04001164 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165}
1166
Jamie Madill2f348d22017-06-05 10:50:59 -04001167Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168{
Jamie Madill96a483b2017-06-27 16:49:21 -04001169 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001170 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001171 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001173
1174 Query *query = mQueryMap.query(handle);
1175 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001177 query = new Query(mImplementation->createQuery(type), handle);
1178 query->addRef();
1179 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001180 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001181 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001182}
1183
Geoff Lang70d0f492015-12-10 17:45:46 -05001184Query *Context::getQuery(GLuint handle) const
1185{
Jamie Madill96a483b2017-06-27 16:49:21 -04001186 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001187}
1188
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001189Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001190{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001191 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1192 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001193}
1194
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001195Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001197 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198}
1199
Geoff Lang492a7e42014-11-05 13:27:06 -05001200Compiler *Context::getCompiler() const
1201{
Jamie Madill2f348d22017-06-05 10:50:59 -04001202 if (mCompiler.get() == nullptr)
1203 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001204 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001205 }
1206 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001207}
1208
Jamie Madillc1d770e2017-04-13 17:31:24 -04001209void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
1211 switch (pname)
1212 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001213 case GL_SHADER_COMPILER:
1214 *params = GL_TRUE;
1215 break;
1216 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1217 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1218 break;
1219 default:
1220 mGLState.getBooleanv(pname, params);
1221 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223}
1224
Jamie Madillc1d770e2017-04-13 17:31:24 -04001225void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226{
Shannon Woods53a94a82014-06-24 15:20:36 -04001227 // Queries about context capabilities and maximums are answered by Context.
1228 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 switch (pname)
1230 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001231 case GL_ALIASED_LINE_WIDTH_RANGE:
1232 params[0] = mCaps.minAliasedLineWidth;
1233 params[1] = mCaps.maxAliasedLineWidth;
1234 break;
1235 case GL_ALIASED_POINT_SIZE_RANGE:
1236 params[0] = mCaps.minAliasedPointSize;
1237 params[1] = mCaps.maxAliasedPointSize;
1238 break;
1239 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1240 ASSERT(mExtensions.textureFilterAnisotropic);
1241 *params = mExtensions.maxTextureAnisotropy;
1242 break;
1243 case GL_MAX_TEXTURE_LOD_BIAS:
1244 *params = mCaps.maxLODBias;
1245 break;
1246
1247 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1248 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1249 {
1250 ASSERT(mExtensions.pathRendering);
1251 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1252 memcpy(params, m, 16 * sizeof(GLfloat));
1253 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001254 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001255
Jamie Madill231c7f52017-04-26 13:45:37 -04001256 default:
1257 mGLState.getFloatv(pname, params);
1258 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001259 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001260}
1261
Jamie Madillc1d770e2017-04-13 17:31:24 -04001262void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001263{
Shannon Woods53a94a82014-06-24 15:20:36 -04001264 // Queries about context capabilities and maximums are answered by Context.
1265 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001266
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001267 switch (pname)
1268 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001269 case GL_MAX_VERTEX_ATTRIBS:
1270 *params = mCaps.maxVertexAttributes;
1271 break;
1272 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1273 *params = mCaps.maxVertexUniformVectors;
1274 break;
1275 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1276 *params = mCaps.maxVertexUniformComponents;
1277 break;
1278 case GL_MAX_VARYING_VECTORS:
1279 *params = mCaps.maxVaryingVectors;
1280 break;
1281 case GL_MAX_VARYING_COMPONENTS:
1282 *params = mCaps.maxVertexOutputComponents;
1283 break;
1284 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1285 *params = mCaps.maxCombinedTextureImageUnits;
1286 break;
1287 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1288 *params = mCaps.maxVertexTextureImageUnits;
1289 break;
1290 case GL_MAX_TEXTURE_IMAGE_UNITS:
1291 *params = mCaps.maxTextureImageUnits;
1292 break;
1293 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1294 *params = mCaps.maxFragmentUniformVectors;
1295 break;
1296 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1297 *params = mCaps.maxFragmentUniformComponents;
1298 break;
1299 case GL_MAX_RENDERBUFFER_SIZE:
1300 *params = mCaps.maxRenderbufferSize;
1301 break;
1302 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1303 *params = mCaps.maxColorAttachments;
1304 break;
1305 case GL_MAX_DRAW_BUFFERS_EXT:
1306 *params = mCaps.maxDrawBuffers;
1307 break;
1308 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1309 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1310 case GL_SUBPIXEL_BITS:
1311 *params = 4;
1312 break;
1313 case GL_MAX_TEXTURE_SIZE:
1314 *params = mCaps.max2DTextureSize;
1315 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001316 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1317 *params = mCaps.maxRectangleTextureSize;
1318 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001319 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1320 *params = mCaps.maxCubeMapTextureSize;
1321 break;
1322 case GL_MAX_3D_TEXTURE_SIZE:
1323 *params = mCaps.max3DTextureSize;
1324 break;
1325 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1326 *params = mCaps.maxArrayTextureLayers;
1327 break;
1328 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1329 *params = mCaps.uniformBufferOffsetAlignment;
1330 break;
1331 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1332 *params = mCaps.maxUniformBufferBindings;
1333 break;
1334 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1335 *params = mCaps.maxVertexUniformBlocks;
1336 break;
1337 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1338 *params = mCaps.maxFragmentUniformBlocks;
1339 break;
1340 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1341 *params = mCaps.maxCombinedTextureImageUnits;
1342 break;
1343 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1344 *params = mCaps.maxVertexOutputComponents;
1345 break;
1346 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1347 *params = mCaps.maxFragmentInputComponents;
1348 break;
1349 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1350 *params = mCaps.minProgramTexelOffset;
1351 break;
1352 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1353 *params = mCaps.maxProgramTexelOffset;
1354 break;
1355 case GL_MAJOR_VERSION:
1356 *params = getClientVersion().major;
1357 break;
1358 case GL_MINOR_VERSION:
1359 *params = getClientVersion().minor;
1360 break;
1361 case GL_MAX_ELEMENTS_INDICES:
1362 *params = mCaps.maxElementsIndices;
1363 break;
1364 case GL_MAX_ELEMENTS_VERTICES:
1365 *params = mCaps.maxElementsVertices;
1366 break;
1367 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1368 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1369 break;
1370 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1371 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1372 break;
1373 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1374 *params = mCaps.maxTransformFeedbackSeparateComponents;
1375 break;
1376 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1377 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1378 break;
1379 case GL_MAX_SAMPLES_ANGLE:
1380 *params = mCaps.maxSamples;
1381 break;
1382 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001383 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001384 params[0] = mCaps.maxViewportWidth;
1385 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001386 }
1387 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001388 case GL_COMPRESSED_TEXTURE_FORMATS:
1389 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1390 params);
1391 break;
1392 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1393 *params = mResetStrategy;
1394 break;
1395 case GL_NUM_SHADER_BINARY_FORMATS:
1396 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1397 break;
1398 case GL_SHADER_BINARY_FORMATS:
1399 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1400 break;
1401 case GL_NUM_PROGRAM_BINARY_FORMATS:
1402 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1403 break;
1404 case GL_PROGRAM_BINARY_FORMATS:
1405 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1406 break;
1407 case GL_NUM_EXTENSIONS:
1408 *params = static_cast<GLint>(mExtensionStrings.size());
1409 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001410
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 // GL_KHR_debug
1412 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1413 *params = mExtensions.maxDebugMessageLength;
1414 break;
1415 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1416 *params = mExtensions.maxDebugLoggedMessages;
1417 break;
1418 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1419 *params = mExtensions.maxDebugGroupStackDepth;
1420 break;
1421 case GL_MAX_LABEL_LENGTH:
1422 *params = mExtensions.maxLabelLength;
1423 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001424
Martin Radeve5285d22017-07-14 16:23:53 +03001425 // GL_ANGLE_multiview
1426 case GL_MAX_VIEWS_ANGLE:
1427 *params = mExtensions.maxViews;
1428 break;
1429
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 // GL_EXT_disjoint_timer_query
1431 case GL_GPU_DISJOINT_EXT:
1432 *params = mImplementation->getGPUDisjoint();
1433 break;
1434 case GL_MAX_FRAMEBUFFER_WIDTH:
1435 *params = mCaps.maxFramebufferWidth;
1436 break;
1437 case GL_MAX_FRAMEBUFFER_HEIGHT:
1438 *params = mCaps.maxFramebufferHeight;
1439 break;
1440 case GL_MAX_FRAMEBUFFER_SAMPLES:
1441 *params = mCaps.maxFramebufferSamples;
1442 break;
1443 case GL_MAX_SAMPLE_MASK_WORDS:
1444 *params = mCaps.maxSampleMaskWords;
1445 break;
1446 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1447 *params = mCaps.maxColorTextureSamples;
1448 break;
1449 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1450 *params = mCaps.maxDepthTextureSamples;
1451 break;
1452 case GL_MAX_INTEGER_SAMPLES:
1453 *params = mCaps.maxIntegerSamples;
1454 break;
1455 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1456 *params = mCaps.maxVertexAttribRelativeOffset;
1457 break;
1458 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1459 *params = mCaps.maxVertexAttribBindings;
1460 break;
1461 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1462 *params = mCaps.maxVertexAttribStride;
1463 break;
1464 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1465 *params = mCaps.maxVertexAtomicCounterBuffers;
1466 break;
1467 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1468 *params = mCaps.maxVertexAtomicCounters;
1469 break;
1470 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1471 *params = mCaps.maxVertexImageUniforms;
1472 break;
1473 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1474 *params = mCaps.maxVertexShaderStorageBlocks;
1475 break;
1476 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1477 *params = mCaps.maxFragmentAtomicCounterBuffers;
1478 break;
1479 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1480 *params = mCaps.maxFragmentAtomicCounters;
1481 break;
1482 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1483 *params = mCaps.maxFragmentImageUniforms;
1484 break;
1485 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1486 *params = mCaps.maxFragmentShaderStorageBlocks;
1487 break;
1488 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1489 *params = mCaps.minProgramTextureGatherOffset;
1490 break;
1491 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1492 *params = mCaps.maxProgramTextureGatherOffset;
1493 break;
1494 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1495 *params = mCaps.maxComputeWorkGroupInvocations;
1496 break;
1497 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1498 *params = mCaps.maxComputeUniformBlocks;
1499 break;
1500 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1501 *params = mCaps.maxComputeTextureImageUnits;
1502 break;
1503 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1504 *params = mCaps.maxComputeSharedMemorySize;
1505 break;
1506 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1507 *params = mCaps.maxComputeUniformComponents;
1508 break;
1509 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1510 *params = mCaps.maxComputeAtomicCounterBuffers;
1511 break;
1512 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1513 *params = mCaps.maxComputeAtomicCounters;
1514 break;
1515 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1516 *params = mCaps.maxComputeImageUniforms;
1517 break;
1518 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1519 *params = mCaps.maxCombinedComputeUniformComponents;
1520 break;
1521 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1522 *params = mCaps.maxComputeShaderStorageBlocks;
1523 break;
1524 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1525 *params = mCaps.maxCombinedShaderOutputResources;
1526 break;
1527 case GL_MAX_UNIFORM_LOCATIONS:
1528 *params = mCaps.maxUniformLocations;
1529 break;
1530 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1531 *params = mCaps.maxAtomicCounterBufferBindings;
1532 break;
1533 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1534 *params = mCaps.maxAtomicCounterBufferSize;
1535 break;
1536 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1537 *params = mCaps.maxCombinedAtomicCounterBuffers;
1538 break;
1539 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1540 *params = mCaps.maxCombinedAtomicCounters;
1541 break;
1542 case GL_MAX_IMAGE_UNITS:
1543 *params = mCaps.maxImageUnits;
1544 break;
1545 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1546 *params = mCaps.maxCombinedImageUniforms;
1547 break;
1548 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1549 *params = mCaps.maxShaderStorageBufferBindings;
1550 break;
1551 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1552 *params = mCaps.maxCombinedShaderStorageBlocks;
1553 break;
1554 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1555 *params = mCaps.shaderStorageBufferOffsetAlignment;
1556 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001557
1558 // GL_EXT_geometry_shader
1559 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1560 *params = mCaps.maxFramebufferLayers;
1561 break;
1562 case GL_LAYER_PROVOKING_VERTEX_EXT:
1563 *params = mCaps.layerProvokingVertex;
1564 break;
1565 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1566 *params = mCaps.maxGeometryUniformComponents;
1567 break;
1568 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1569 *params = mCaps.maxGeometryUniformBlocks;
1570 break;
1571 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1572 *params = mCaps.maxCombinedGeometryUniformComponents;
1573 break;
1574 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1575 *params = mCaps.maxGeometryInputComponents;
1576 break;
1577 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1578 *params = mCaps.maxGeometryOutputComponents;
1579 break;
1580 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1581 *params = mCaps.maxGeometryOutputVertices;
1582 break;
1583 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1584 *params = mCaps.maxGeometryTotalOutputComponents;
1585 break;
1586 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1587 *params = mCaps.maxGeometryShaderInvocations;
1588 break;
1589 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1590 *params = mCaps.maxGeometryTextureImageUnits;
1591 break;
1592 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1593 *params = mCaps.maxGeometryAtomicCounterBuffers;
1594 break;
1595 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1596 *params = mCaps.maxGeometryAtomicCounters;
1597 break;
1598 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1599 *params = mCaps.maxGeometryImageUniforms;
1600 break;
1601 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1602 *params = mCaps.maxGeometryShaderStorageBlocks;
1603 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001605 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001606 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001607 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001608}
1609
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001610void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001611{
Shannon Woods53a94a82014-06-24 15:20:36 -04001612 // Queries about context capabilities and maximums are answered by Context.
1613 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001614 switch (pname)
1615 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 case GL_MAX_ELEMENT_INDEX:
1617 *params = mCaps.maxElementIndex;
1618 break;
1619 case GL_MAX_UNIFORM_BLOCK_SIZE:
1620 *params = mCaps.maxUniformBlockSize;
1621 break;
1622 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1623 *params = mCaps.maxCombinedVertexUniformComponents;
1624 break;
1625 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1626 *params = mCaps.maxCombinedFragmentUniformComponents;
1627 break;
1628 case GL_MAX_SERVER_WAIT_TIMEOUT:
1629 *params = mCaps.maxServerWaitTimeout;
1630 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001631
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 // GL_EXT_disjoint_timer_query
1633 case GL_TIMESTAMP_EXT:
1634 *params = mImplementation->getTimestamp();
1635 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001636
Jamie Madill231c7f52017-04-26 13:45:37 -04001637 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1638 *params = mCaps.maxShaderStorageBlockSize;
1639 break;
1640 default:
1641 UNREACHABLE();
1642 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001643 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001644}
1645
Geoff Lang70d0f492015-12-10 17:45:46 -05001646void Context::getPointerv(GLenum pname, void **params) const
1647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001648 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001649}
1650
Martin Radev66fb8202016-07-28 11:45:20 +03001651void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001652{
Shannon Woods53a94a82014-06-24 15:20:36 -04001653 // Queries about context capabilities and maximums are answered by Context.
1654 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001655
1656 GLenum nativeType;
1657 unsigned int numParams;
1658 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1659 ASSERT(queryStatus);
1660
1661 if (nativeType == GL_INT)
1662 {
1663 switch (target)
1664 {
1665 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1666 ASSERT(index < 3u);
1667 *data = mCaps.maxComputeWorkGroupCount[index];
1668 break;
1669 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1670 ASSERT(index < 3u);
1671 *data = mCaps.maxComputeWorkGroupSize[index];
1672 break;
1673 default:
1674 mGLState.getIntegeri_v(target, index, data);
1675 }
1676 }
1677 else
1678 {
1679 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1680 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001681}
1682
Martin Radev66fb8202016-07-28 11:45:20 +03001683void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001684{
Shannon Woods53a94a82014-06-24 15:20:36 -04001685 // Queries about context capabilities and maximums are answered by Context.
1686 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001687
1688 GLenum nativeType;
1689 unsigned int numParams;
1690 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1691 ASSERT(queryStatus);
1692
1693 if (nativeType == GL_INT_64_ANGLEX)
1694 {
1695 mGLState.getInteger64i_v(target, index, data);
1696 }
1697 else
1698 {
1699 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1700 }
1701}
1702
1703void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1704{
1705 // Queries about context capabilities and maximums are answered by Context.
1706 // Queries about current GL state values are answered by State.
1707
1708 GLenum nativeType;
1709 unsigned int numParams;
1710 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1711 ASSERT(queryStatus);
1712
1713 if (nativeType == GL_BOOL)
1714 {
1715 mGLState.getBooleani_v(target, index, data);
1716 }
1717 else
1718 {
1719 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1720 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001721}
1722
Corentin Wallez336129f2017-10-17 15:55:40 -04001723void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001724{
1725 Buffer *buffer = mGLState.getTargetBuffer(target);
1726 QueryBufferParameteriv(buffer, pname, params);
1727}
1728
1729void Context::getFramebufferAttachmentParameteriv(GLenum target,
1730 GLenum attachment,
1731 GLenum pname,
1732 GLint *params)
1733{
1734 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001735 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001736}
1737
1738void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1739{
1740 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1741 QueryRenderbufferiv(this, renderbuffer, pname, params);
1742}
1743
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001744void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001745{
1746 Texture *texture = getTargetTexture(target);
1747 QueryTexParameterfv(texture, pname, params);
1748}
1749
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001750void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001751{
1752 Texture *texture = getTargetTexture(target);
1753 QueryTexParameteriv(texture, pname, params);
1754}
Jiajia Qin5451d532017-11-16 17:16:34 +08001755
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001756void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001757{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001758 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001759 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001760}
1761
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001762void Context::getTexLevelParameterfv(TextureTarget target,
1763 GLint level,
1764 GLenum pname,
1765 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001766{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001767 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001768 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001769}
1770
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001771void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001772{
1773 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001774 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001775 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001776}
1777
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001778void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001779{
1780 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001781 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001782 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001783}
1784
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001785void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001786{
1787 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001788 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001789 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001790}
1791
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001792void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001793{
1794 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001795 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001796 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001797}
1798
Jamie Madill675fe712016-12-19 13:07:54 -05001799void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001800{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001801 // No-op if zero count
1802 if (count == 0)
1803 {
1804 return;
1805 }
1806
Jamie Madill05b35b22017-10-03 09:01:44 -04001807 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001808 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1809 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001810}
1811
Jamie Madill675fe712016-12-19 13:07:54 -05001812void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001813{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001814 // No-op if zero count
1815 if (count == 0 || instanceCount == 0)
1816 {
1817 return;
1818 }
1819
Jamie Madill05b35b22017-10-03 09:01:44 -04001820 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001821 ANGLE_CONTEXT_TRY(
1822 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1823 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001824}
1825
Jamie Madill876429b2017-04-20 15:46:24 -04001826void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001827{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001828 // No-op if zero count
1829 if (count == 0)
1830 {
1831 return;
1832 }
1833
Jamie Madill05b35b22017-10-03 09:01:44 -04001834 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001835 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::drawElementsInstanced(GLenum mode,
1839 GLsizei count,
1840 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001841 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001842 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001843{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001844 // No-op if zero count
1845 if (count == 0 || instances == 0)
1846 {
1847 return;
1848 }
1849
Jamie Madill05b35b22017-10-03 09:01:44 -04001850 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001851 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001852 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001853}
1854
Jamie Madill675fe712016-12-19 13:07:54 -05001855void Context::drawRangeElements(GLenum mode,
1856 GLuint start,
1857 GLuint end,
1858 GLsizei count,
1859 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001860 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001861{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001862 // No-op if zero count
1863 if (count == 0)
1864 {
1865 return;
1866 }
1867
Jamie Madill05b35b22017-10-03 09:01:44 -04001868 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001869 ANGLE_CONTEXT_TRY(
1870 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001871}
1872
Jamie Madill876429b2017-04-20 15:46:24 -04001873void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001874{
Jamie Madill05b35b22017-10-03 09:01:44 -04001875 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001876 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001877}
1878
Jamie Madill876429b2017-04-20 15:46:24 -04001879void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001880{
Jamie Madill05b35b22017-10-03 09:01:44 -04001881 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001882 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001883}
1884
Jamie Madill675fe712016-12-19 13:07:54 -05001885void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001886{
Jamie Madillafa02a22017-11-23 12:57:38 -05001887 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001888}
1889
Jamie Madill675fe712016-12-19 13:07:54 -05001890void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001891{
Jamie Madillafa02a22017-11-23 12:57:38 -05001892 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001893}
1894
Austin Kinross6ee1e782015-05-29 17:05:37 -07001895void Context::insertEventMarker(GLsizei length, const char *marker)
1896{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001897 ASSERT(mImplementation);
1898 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001899}
1900
1901void Context::pushGroupMarker(GLsizei length, const char *marker)
1902{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001903 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001904
1905 if (marker == nullptr)
1906 {
1907 // From the EXT_debug_marker spec,
1908 // "If <marker> is null then an empty string is pushed on the stack."
1909 mImplementation->pushGroupMarker(length, "");
1910 }
1911 else
1912 {
1913 mImplementation->pushGroupMarker(length, marker);
1914 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001915}
1916
1917void Context::popGroupMarker()
1918{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001919 ASSERT(mImplementation);
1920 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001921}
1922
Geoff Langd8605522016-04-13 10:19:12 -04001923void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1924{
1925 Program *programObject = getProgram(program);
1926 ASSERT(programObject);
1927
1928 programObject->bindUniformLocation(location, name);
1929}
1930
Sami Väisänena797e062016-05-12 15:23:40 +03001931void Context::setCoverageModulation(GLenum components)
1932{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001933 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001934}
1935
Sami Väisänene45e53b2016-05-25 10:36:04 +03001936void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1937{
1938 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1939}
1940
1941void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1942{
1943 GLfloat I[16];
1944 angle::Matrix<GLfloat>::setToIdentity(I);
1945
1946 mGLState.loadPathRenderingMatrix(matrixMode, I);
1947}
1948
1949void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001951 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001952 if (!pathObj)
1953 return;
1954
1955 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001956 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001957
1958 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1959}
1960
1961void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1962{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001963 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001964 if (!pathObj)
1965 return;
1966
1967 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001968 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001969
1970 mImplementation->stencilStrokePath(pathObj, reference, mask);
1971}
1972
1973void Context::coverFillPath(GLuint path, GLenum coverMode)
1974{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001975 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001976 if (!pathObj)
1977 return;
1978
1979 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001980 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001981
1982 mImplementation->coverFillPath(pathObj, coverMode);
1983}
1984
1985void Context::coverStrokePath(GLuint path, GLenum coverMode)
1986{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001987 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001988 if (!pathObj)
1989 return;
1990
1991 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001992 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001993
1994 mImplementation->coverStrokePath(pathObj, coverMode);
1995}
1996
1997void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001999 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002000 if (!pathObj)
2001 return;
2002
2003 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002004 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002005
2006 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2007}
2008
2009void Context::stencilThenCoverStrokePath(GLuint path,
2010 GLint reference,
2011 GLuint mask,
2012 GLenum coverMode)
2013{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002014 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002015 if (!pathObj)
2016 return;
2017
2018 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002019 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002020
2021 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2022}
2023
Sami Väisänend59ca052016-06-21 16:10:00 +03002024void Context::coverFillPathInstanced(GLsizei numPaths,
2025 GLenum pathNameType,
2026 const void *paths,
2027 GLuint pathBase,
2028 GLenum coverMode,
2029 GLenum transformType,
2030 const GLfloat *transformValues)
2031{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002032 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002033
2034 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002035 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002036
2037 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2038}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002039
Sami Väisänend59ca052016-06-21 16:10:00 +03002040void Context::coverStrokePathInstanced(GLsizei numPaths,
2041 GLenum pathNameType,
2042 const void *paths,
2043 GLuint pathBase,
2044 GLenum coverMode,
2045 GLenum transformType,
2046 const GLfloat *transformValues)
2047{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002048 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002049
2050 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002051 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002052
2053 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2054 transformValues);
2055}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002056
Sami Väisänend59ca052016-06-21 16:10:00 +03002057void Context::stencilFillPathInstanced(GLsizei numPaths,
2058 GLenum pathNameType,
2059 const void *paths,
2060 GLuint pathBase,
2061 GLenum fillMode,
2062 GLuint mask,
2063 GLenum transformType,
2064 const GLfloat *transformValues)
2065{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002066 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002067
2068 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002069 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002070
2071 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2072 transformValues);
2073}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002074
Sami Väisänend59ca052016-06-21 16:10:00 +03002075void Context::stencilStrokePathInstanced(GLsizei numPaths,
2076 GLenum pathNameType,
2077 const void *paths,
2078 GLuint pathBase,
2079 GLint reference,
2080 GLuint mask,
2081 GLenum transformType,
2082 const GLfloat *transformValues)
2083{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002084 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002085
2086 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002087 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002088
2089 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2090 transformValues);
2091}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002092
Sami Väisänend59ca052016-06-21 16:10:00 +03002093void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2094 GLenum pathNameType,
2095 const void *paths,
2096 GLuint pathBase,
2097 GLenum fillMode,
2098 GLuint mask,
2099 GLenum coverMode,
2100 GLenum transformType,
2101 const GLfloat *transformValues)
2102{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002103 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002104
2105 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002106 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002107
2108 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2109 transformType, transformValues);
2110}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002111
Sami Väisänend59ca052016-06-21 16:10:00 +03002112void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2113 GLenum pathNameType,
2114 const void *paths,
2115 GLuint pathBase,
2116 GLint reference,
2117 GLuint mask,
2118 GLenum coverMode,
2119 GLenum transformType,
2120 const GLfloat *transformValues)
2121{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002122 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002123
2124 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002125 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002126
2127 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2128 transformType, transformValues);
2129}
2130
Sami Väisänen46eaa942016-06-29 10:26:37 +03002131void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2132{
2133 auto *programObject = getProgram(program);
2134
2135 programObject->bindFragmentInputLocation(location, name);
2136}
2137
2138void Context::programPathFragmentInputGen(GLuint program,
2139 GLint location,
2140 GLenum genMode,
2141 GLint components,
2142 const GLfloat *coeffs)
2143{
2144 auto *programObject = getProgram(program);
2145
Jamie Madillbd044ed2017-06-05 12:59:21 -04002146 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002147}
2148
jchen1015015f72017-03-16 13:54:21 +08002149GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2150{
jchen10fd7c3b52017-03-21 15:36:03 +08002151 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002152 return QueryProgramResourceIndex(programObject, programInterface, name);
2153}
2154
jchen10fd7c3b52017-03-21 15:36:03 +08002155void Context::getProgramResourceName(GLuint program,
2156 GLenum programInterface,
2157 GLuint index,
2158 GLsizei bufSize,
2159 GLsizei *length,
2160 GLchar *name)
2161{
2162 const auto *programObject = getProgram(program);
2163 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2164}
2165
jchen10191381f2017-04-11 13:59:04 +08002166GLint Context::getProgramResourceLocation(GLuint program,
2167 GLenum programInterface,
2168 const GLchar *name)
2169{
2170 const auto *programObject = getProgram(program);
2171 return QueryProgramResourceLocation(programObject, programInterface, name);
2172}
2173
jchen10880683b2017-04-12 16:21:55 +08002174void Context::getProgramResourceiv(GLuint program,
2175 GLenum programInterface,
2176 GLuint index,
2177 GLsizei propCount,
2178 const GLenum *props,
2179 GLsizei bufSize,
2180 GLsizei *length,
2181 GLint *params)
2182{
2183 const auto *programObject = getProgram(program);
2184 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2185 length, params);
2186}
2187
jchen10d9cd7b72017-08-30 15:04:25 +08002188void Context::getProgramInterfaceiv(GLuint program,
2189 GLenum programInterface,
2190 GLenum pname,
2191 GLint *params)
2192{
2193 const auto *programObject = getProgram(program);
2194 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2195}
2196
Jamie Madill71c88b32017-09-14 22:20:29 -04002197void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002198{
Geoff Langda5777c2014-07-11 09:52:58 -04002199 if (error.isError())
2200 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002201 GLenum code = error.getCode();
2202 mErrors.insert(code);
2203 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2204 {
2205 markContextLost();
2206 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002207
Geoff Langee6884e2017-11-09 16:51:11 -05002208 ASSERT(!error.getMessage().empty());
2209 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2210 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002211 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212}
2213
2214// Get one of the recorded errors and clear its flag, if any.
2215// [OpenGL ES 2.0.24] section 2.5 page 13.
2216GLenum Context::getError()
2217{
Geoff Langda5777c2014-07-11 09:52:58 -04002218 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219 {
Geoff Langda5777c2014-07-11 09:52:58 -04002220 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002221 }
Geoff Langda5777c2014-07-11 09:52:58 -04002222 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223 {
Geoff Langda5777c2014-07-11 09:52:58 -04002224 GLenum error = *mErrors.begin();
2225 mErrors.erase(mErrors.begin());
2226 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228}
2229
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230// NOTE: this function should not assume that this context is current!
2231void Context::markContextLost()
2232{
2233 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002234 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002235 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002236 mContextLostForced = true;
2237 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002238 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239}
2240
2241bool Context::isContextLost()
2242{
2243 return mContextLost;
2244}
2245
Jamie Madillfa920eb2018-01-04 11:45:50 -05002246GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002247{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248 // Even if the application doesn't want to know about resets, we want to know
2249 // as it will allow us to skip all the calls.
2250 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002251 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002252 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002253 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002255 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256
2257 // EXT_robustness, section 2.6: If the reset notification behavior is
2258 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2259 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2260 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002261 }
2262
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002263 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2264 // status should be returned at least once, and GL_NO_ERROR should be returned
2265 // once the device has finished resetting.
2266 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002267 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 ASSERT(mResetStatus == GL_NO_ERROR);
2269 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002270
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002271 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002272 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002273 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002274 }
2275 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002276 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002277 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002278 // If markContextLost was used to mark the context lost then
2279 // assume that is not recoverable, and continue to report the
2280 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002281 mResetStatus = mImplementation->getResetStatus();
2282 }
Jamie Madill893ab082014-05-16 16:56:10 -04002283
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002284 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002285}
2286
2287bool Context::isResetNotificationEnabled()
2288{
2289 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2290}
2291
Corentin Walleze3b10e82015-05-20 11:06:25 -04002292const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002293{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002294 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002295}
2296
2297EGLenum Context::getClientType() const
2298{
2299 return mClientType;
2300}
2301
2302EGLenum Context::getRenderBuffer() const
2303{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002304 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2305 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002306 {
2307 return EGL_NONE;
2308 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002309
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002310 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002311 ASSERT(backAttachment != nullptr);
2312 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002313}
2314
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002315VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002316{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002317 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002318 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2319 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002320 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002321 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2322 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002323
Jamie Madill96a483b2017-06-27 16:49:21 -04002324 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002325 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002326
2327 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002328}
2329
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002330TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002331{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002332 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002333 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2334 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002335 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002336 transformFeedback =
2337 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002338 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002339 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002341
2342 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002343}
2344
2345bool Context::isVertexArrayGenerated(GLuint vertexArray)
2346{
Jamie Madill96a483b2017-06-27 16:49:21 -04002347 ASSERT(mVertexArrayMap.contains(0));
2348 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002349}
2350
2351bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2352{
Jamie Madill96a483b2017-06-27 16:49:21 -04002353 ASSERT(mTransformFeedbackMap.contains(0));
2354 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002355}
2356
Shannon Woods53a94a82014-06-24 15:20:36 -04002357void Context::detachTexture(GLuint texture)
2358{
2359 // Simple pass-through to State's detachTexture method, as textures do not require
2360 // allocation map management either here or in the resource manager at detach time.
2361 // Zero textures are held by the Context, and we don't attempt to request them from
2362 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002363 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002364}
2365
James Darpinian4d9d4832018-03-13 12:43:28 -07002366void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002367{
Yuly Novikov5807a532015-12-03 13:01:22 -05002368 // Simple pass-through to State's detachBuffer method, since
2369 // only buffer attachments to container objects that are bound to the current context
2370 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002371
Yuly Novikov5807a532015-12-03 13:01:22 -05002372 // [OpenGL ES 3.2] section 5.1.2 page 45:
2373 // Attachments to unbound container objects, such as
2374 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2375 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002376 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002377}
2378
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002379void Context::detachFramebuffer(GLuint framebuffer)
2380{
Shannon Woods53a94a82014-06-24 15:20:36 -04002381 // Framebuffer detachment is handled by Context, because 0 is a valid
2382 // Framebuffer object, and a pointer to it must be passed from Context
2383 // to State at binding time.
2384
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002385 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002386 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2387 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2388 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002389
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002390 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002391 {
2392 bindReadFramebuffer(0);
2393 }
2394
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002395 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396 {
2397 bindDrawFramebuffer(0);
2398 }
2399}
2400
2401void Context::detachRenderbuffer(GLuint renderbuffer)
2402{
Jamie Madilla02315b2017-02-23 14:14:47 -05002403 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002404}
2405
Jamie Madill57a89722013-07-02 11:57:03 -04002406void Context::detachVertexArray(GLuint vertexArray)
2407{
Jamie Madill77a72f62015-04-14 11:18:32 -04002408 // Vertex array detachment is handled by Context, because 0 is a valid
2409 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002410 // binding time.
2411
Jamie Madill57a89722013-07-02 11:57:03 -04002412 // [OpenGL ES 3.0.2] section 2.10 page 43:
2413 // If a vertex array object that is currently bound is deleted, the binding
2414 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002415 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002416 {
2417 bindVertexArray(0);
2418 }
2419}
2420
Geoff Langc8058452014-02-03 12:04:11 -05002421void Context::detachTransformFeedback(GLuint transformFeedback)
2422{
Corentin Walleza2257da2016-04-19 16:43:12 -04002423 // Transform feedback detachment is handled by Context, because 0 is a valid
2424 // transform feedback, and a pointer to it must be passed from Context to State at
2425 // binding time.
2426
2427 // The OpenGL specification doesn't mention what should happen when the currently bound
2428 // transform feedback object is deleted. Since it is a container object, we treat it like
2429 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002430 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002431 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002432 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002433 }
Geoff Langc8058452014-02-03 12:04:11 -05002434}
2435
Jamie Madilldc356042013-07-19 16:36:57 -04002436void Context::detachSampler(GLuint sampler)
2437{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002438 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002439}
2440
Yunchao Hea336b902017-08-02 16:05:21 +08002441void Context::detachProgramPipeline(GLuint pipeline)
2442{
2443 mGLState.detachProgramPipeline(this, pipeline);
2444}
2445
Jamie Madill3ef140a2017-08-26 23:11:21 -04002446void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002447{
Shaodde78e82017-05-22 14:13:27 +08002448 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002449}
2450
Jamie Madille29d1672013-07-19 16:36:57 -04002451void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2452{
Geoff Langc1984ed2016-10-07 12:41:00 -04002453 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002456 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002457}
Jamie Madille29d1672013-07-19 16:36:57 -04002458
Geoff Langc1984ed2016-10-07 12:41:00 -04002459void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2460{
2461 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002462 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002463 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002464 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002465}
2466
2467void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2468{
Geoff Langc1984ed2016-10-07 12:41:00 -04002469 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002470 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002471 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002472 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002473}
2474
Geoff Langc1984ed2016-10-07 12:41:00 -04002475void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002476{
Geoff Langc1984ed2016-10-07 12:41:00 -04002477 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002478 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002479 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002480 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002481}
2482
Geoff Langc1984ed2016-10-07 12:41:00 -04002483void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002484{
Geoff Langc1984ed2016-10-07 12:41:00 -04002485 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002486 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002487 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002488 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002489}
Jamie Madill9675b802013-07-19 16:36:59 -04002490
Geoff Langc1984ed2016-10-07 12:41:00 -04002491void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2492{
2493 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002494 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002495 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002496 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002497}
2498
Olli Etuahof0fee072016-03-30 15:11:58 +03002499void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2500{
2501 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002502 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002503}
2504
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505void Context::initRendererString()
2506{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002507 std::ostringstream rendererString;
2508 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002509 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002510 rendererString << ")";
2511
Geoff Langcec35902014-04-16 10:52:36 -04002512 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513}
2514
Geoff Langc339c4e2016-11-29 10:37:36 -05002515void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002516{
Geoff Langc339c4e2016-11-29 10:37:36 -05002517 const Version &clientVersion = getClientVersion();
2518
2519 std::ostringstream versionString;
2520 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2521 << ANGLE_VERSION_STRING << ")";
2522 mVersionString = MakeStaticString(versionString.str());
2523
2524 std::ostringstream shadingLanguageVersionString;
2525 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2526 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2527 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2528 << ")";
2529 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530}
2531
Geoff Langcec35902014-04-16 10:52:36 -04002532void Context::initExtensionStrings()
2533{
Geoff Langc339c4e2016-11-29 10:37:36 -05002534 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2535 std::ostringstream combinedStringStream;
2536 std::copy(strings.begin(), strings.end(),
2537 std::ostream_iterator<const char *>(combinedStringStream, " "));
2538 return MakeStaticString(combinedStringStream.str());
2539 };
2540
2541 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002542 for (const auto &extensionString : mExtensions.getStrings())
2543 {
2544 mExtensionStrings.push_back(MakeStaticString(extensionString));
2545 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002546 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002547
Bryan Bernhart58806562017-01-05 13:09:31 -08002548 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2549
Geoff Langc339c4e2016-11-29 10:37:36 -05002550 mRequestableExtensionStrings.clear();
2551 for (const auto &extensionInfo : GetExtensionInfoMap())
2552 {
2553 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002554 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2555 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002556 {
2557 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2558 }
2559 }
2560 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002561}
2562
Geoff Langc339c4e2016-11-29 10:37:36 -05002563const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002564{
Geoff Langc339c4e2016-11-29 10:37:36 -05002565 switch (name)
2566 {
2567 case GL_VENDOR:
2568 return reinterpret_cast<const GLubyte *>("Google Inc.");
2569
2570 case GL_RENDERER:
2571 return reinterpret_cast<const GLubyte *>(mRendererString);
2572
2573 case GL_VERSION:
2574 return reinterpret_cast<const GLubyte *>(mVersionString);
2575
2576 case GL_SHADING_LANGUAGE_VERSION:
2577 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2578
2579 case GL_EXTENSIONS:
2580 return reinterpret_cast<const GLubyte *>(mExtensionString);
2581
2582 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2583 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2584
2585 default:
2586 UNREACHABLE();
2587 return nullptr;
2588 }
Geoff Langcec35902014-04-16 10:52:36 -04002589}
2590
Geoff Langc339c4e2016-11-29 10:37:36 -05002591const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002592{
Geoff Langc339c4e2016-11-29 10:37:36 -05002593 switch (name)
2594 {
2595 case GL_EXTENSIONS:
2596 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2597
2598 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2599 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2600
2601 default:
2602 UNREACHABLE();
2603 return nullptr;
2604 }
Geoff Langcec35902014-04-16 10:52:36 -04002605}
2606
2607size_t Context::getExtensionStringCount() const
2608{
2609 return mExtensionStrings.size();
2610}
2611
Geoff Lang111a99e2017-10-17 10:58:41 -04002612bool Context::isExtensionRequestable(const char *name)
2613{
2614 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2615 auto extension = extensionInfos.find(name);
2616
2617 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2618 return extension != extensionInfos.end() && extension->second.Requestable &&
2619 nativeExtensions.*(extension->second.ExtensionsMember);
2620}
2621
Geoff Langc339c4e2016-11-29 10:37:36 -05002622void Context::requestExtension(const char *name)
2623{
2624 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2625 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2626 const auto &extension = extensionInfos.at(name);
2627 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002628 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002629
2630 if (mExtensions.*(extension.ExtensionsMember))
2631 {
2632 // Extension already enabled
2633 return;
2634 }
2635
2636 mExtensions.*(extension.ExtensionsMember) = true;
2637 updateCaps();
2638 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002639
Jamie Madill2f348d22017-06-05 10:50:59 -04002640 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2641 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002642
Jamie Madill81c2e252017-09-09 23:32:46 -04002643 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2644 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002645 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002646 for (auto &zeroTexture : mZeroTextures)
2647 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002648 if (zeroTexture.get() != nullptr)
2649 {
2650 zeroTexture->signalDirty(this, InitState::Initialized);
2651 }
Geoff Lang9aded172017-04-05 11:07:56 -04002652 }
2653
2654 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002655}
2656
2657size_t Context::getRequestableExtensionStringCount() const
2658{
2659 return mRequestableExtensionStrings.size();
2660}
2661
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002662void Context::beginTransformFeedback(GLenum primitiveMode)
2663{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002664 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002665 ASSERT(transformFeedback != nullptr);
2666 ASSERT(!transformFeedback->isPaused());
2667
Jamie Madill6c1f6712017-02-14 19:08:04 -05002668 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002669}
2670
2671bool Context::hasActiveTransformFeedback(GLuint program) const
2672{
2673 for (auto pair : mTransformFeedbackMap)
2674 {
2675 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2676 {
2677 return true;
2678 }
2679 }
2680 return false;
2681}
2682
Geoff Langb433e872017-10-05 14:01:47 -04002683void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002684{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002685 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002686
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002687 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2688 if (getClientVersion() < Version(2, 0))
2689 {
2690 mCaps.maxMultitextureUnits = 4;
2691 mCaps.maxClipPlanes = 6;
2692 mCaps.maxLights = 8;
2693 mCaps.maxModelviewMatrixStackDepth = 16;
2694 mCaps.maxProjectionMatrixStackDepth = 16;
2695 mCaps.maxTextureMatrixStackDepth = 16;
2696 }
2697
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002698 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002699
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002700 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002701
Geoff Langeb66a6e2016-10-31 13:06:12 -04002702 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002703 {
2704 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002705 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002706 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002707 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002708 mExtensions.multiview = false;
2709 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002710 }
2711
Jiawei Shao89be29a2017-11-06 14:36:45 +08002712 if (getClientVersion() < ES_3_1)
2713 {
2714 // Disable ES3.1+ extensions
2715 mExtensions.geometryShader = false;
2716 }
2717
Geoff Langeb66a6e2016-10-31 13:06:12 -04002718 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002719 {
2720 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002721 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002722 }
2723
Jamie Madill00ed7a12016-05-19 13:13:38 -04002724 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002725 mExtensions.bindUniformLocation = true;
2726 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002727 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002728 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002729 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002730
2731 // Enable the no error extension if the context was created with the flag.
2732 mExtensions.noError = mSkipValidation;
2733
Corentin Wallezccab69d2017-01-27 16:57:15 -05002734 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002735 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002736
Geoff Lang70d0f492015-12-10 17:45:46 -05002737 // Explicitly enable GL_KHR_debug
2738 mExtensions.debug = true;
2739 mExtensions.maxDebugMessageLength = 1024;
2740 mExtensions.maxDebugLoggedMessages = 1024;
2741 mExtensions.maxDebugGroupStackDepth = 1024;
2742 mExtensions.maxLabelLength = 1024;
2743
Geoff Langff5b2d52016-09-07 11:32:23 -04002744 // Explicitly enable GL_ANGLE_robust_client_memory
2745 mExtensions.robustClientMemory = true;
2746
Jamie Madille08a1d32017-03-07 17:24:06 -05002747 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002748 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002749
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002750 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2751 // supports it.
2752 mExtensions.robustBufferAccessBehavior =
2753 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2754
Jamie Madillc43be722017-07-13 16:22:14 -04002755 // Enable the cache control query unconditionally.
2756 mExtensions.programCacheControl = true;
2757
Geoff Lang301d1612014-07-09 10:34:37 -04002758 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002759 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002760
Jamie Madill0f80ed82017-09-19 00:24:56 -04002761 if (getClientVersion() < ES_3_1)
2762 {
2763 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2764 }
2765 else
2766 {
2767 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2768 }
Geoff Lang301d1612014-07-09 10:34:37 -04002769
Jamie Madill0f80ed82017-09-19 00:24:56 -04002770 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2771 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2772 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2773
2774 // Limit textures as well, so we can use fast bitsets with texture bindings.
2775 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2776 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2777 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002778
Jiawei Shaodb342272017-09-27 10:21:45 +08002779 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2780
Geoff Langc287ea62016-09-16 14:46:51 -04002781 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002782 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002783 for (const auto &extensionInfo : GetExtensionInfoMap())
2784 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04002785 // If the user has requested that extensions start disabled and they are requestable,
2786 // disable them.
2787 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002788 {
2789 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2790 }
2791 }
2792
2793 // Generate texture caps
2794 updateCaps();
2795}
2796
2797void Context::updateCaps()
2798{
Geoff Lang900013c2014-07-07 11:32:19 -04002799 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002800 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002801
Jamie Madill7b62cf92017-11-02 15:20:49 -04002802 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002803 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002804 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002805 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002806
Geoff Lang0d8b7242015-09-09 14:56:53 -04002807 // Update the format caps based on the client version and extensions.
2808 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2809 // ES3.
2810 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002811 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002812 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002813 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002814 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002815 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002816
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002817 // OpenGL ES does not support multisampling with non-rendererable formats
2818 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002819 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002820 (getClientVersion() < ES_3_1 &&
2821 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002822 {
Geoff Langd87878e2014-09-19 15:42:59 -04002823 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002824 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002825 else
2826 {
2827 // We may have limited the max samples for some required renderbuffer formats due to
2828 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2829 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2830
2831 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2832 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2833 // exception of signed and unsigned integer formats."
2834 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2835 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2836 {
2837 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2838 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2839 }
2840
2841 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2842 if (getClientVersion() >= ES_3_1)
2843 {
2844 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2845 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2846 // the exception that the signed and unsigned integer formats are required only to
2847 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2848 // multisamples, which must be at least one."
2849 if (formatInfo.componentType == GL_INT ||
2850 formatInfo.componentType == GL_UNSIGNED_INT)
2851 {
2852 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2853 }
2854
2855 // GLES 3.1 section 19.3.1.
2856 if (formatCaps.texturable)
2857 {
2858 if (formatInfo.depthBits > 0)
2859 {
2860 mCaps.maxDepthTextureSamples =
2861 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2862 }
2863 else if (formatInfo.redBits > 0)
2864 {
2865 mCaps.maxColorTextureSamples =
2866 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2867 }
2868 }
2869 }
2870 }
Geoff Langd87878e2014-09-19 15:42:59 -04002871
2872 if (formatCaps.texturable && formatInfo.compressed)
2873 {
Geoff Langca271392017-04-05 12:30:00 -04002874 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002875 }
2876
Geoff Langca271392017-04-05 12:30:00 -04002877 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002878 }
Jamie Madill32447362017-06-28 14:53:52 -04002879
2880 // If program binary is disabled, blank out the memory cache pointer.
2881 if (!mImplementation->getNativeExtensions().getProgramBinary)
2882 {
2883 mMemoryProgramCache = nullptr;
2884 }
Corentin Walleze4477002017-12-01 14:39:58 -05002885
2886 // Compute which buffer types are allowed
2887 mValidBufferBindings.reset();
2888 mValidBufferBindings.set(BufferBinding::ElementArray);
2889 mValidBufferBindings.set(BufferBinding::Array);
2890
2891 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2892 {
2893 mValidBufferBindings.set(BufferBinding::PixelPack);
2894 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2895 }
2896
2897 if (getClientVersion() >= ES_3_0)
2898 {
2899 mValidBufferBindings.set(BufferBinding::CopyRead);
2900 mValidBufferBindings.set(BufferBinding::CopyWrite);
2901 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2902 mValidBufferBindings.set(BufferBinding::Uniform);
2903 }
2904
2905 if (getClientVersion() >= ES_3_1)
2906 {
2907 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2908 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2909 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2910 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2911 }
Geoff Lang493daf52014-07-03 13:38:44 -04002912}
2913
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002914void Context::initWorkarounds()
2915{
Jamie Madill761b02c2017-06-23 16:27:06 -04002916 // Apply back-end workarounds.
2917 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2918
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002919 // Lose the context upon out of memory error if the application is
2920 // expecting to watch for those events.
2921 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2922}
2923
Jamie Madill05b35b22017-10-03 09:01:44 -04002924Error Context::prepareForDraw()
2925{
Geoff Langa8cb2872018-03-09 16:09:40 -05002926 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002927
2928 if (isRobustResourceInitEnabled())
2929 {
2930 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2931 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2932 }
2933
Geoff Langa8cb2872018-03-09 16:09:40 -05002934 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04002935 return NoError();
2936}
2937
2938Error Context::prepareForClear(GLbitfield mask)
2939{
Geoff Langa8cb2872018-03-09 16:09:40 -05002940 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002941 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05002942 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04002943 return NoError();
2944}
2945
2946Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2947{
Geoff Langa8cb2872018-03-09 16:09:40 -05002948 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002949 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2950 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05002951 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002952 return NoError();
2953}
2954
Geoff Langa8cb2872018-03-09 16:09:40 -05002955Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002956{
Geoff Langa8cb2872018-03-09 16:09:40 -05002957 ANGLE_TRY(syncDirtyObjects());
2958 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002959 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002960}
2961
Geoff Langa8cb2872018-03-09 16:09:40 -05002962Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002963{
Geoff Langa8cb2872018-03-09 16:09:40 -05002964 ANGLE_TRY(syncDirtyObjects(objectMask));
2965 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04002966 return NoError();
2967}
2968
Geoff Langa8cb2872018-03-09 16:09:40 -05002969Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04002970{
2971 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2972 mImplementation->syncState(this, dirtyBits);
2973 mGLState.clearDirtyBits();
2974 return NoError();
2975}
2976
Geoff Langa8cb2872018-03-09 16:09:40 -05002977Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002978{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002979 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002980 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002981 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002982 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002983}
Jamie Madillc29968b2016-01-20 11:17:23 -05002984
Geoff Langa8cb2872018-03-09 16:09:40 -05002985Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04002986{
2987 return mGLState.syncDirtyObjects(this);
2988}
2989
Geoff Langa8cb2872018-03-09 16:09:40 -05002990Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002991{
2992 return mGLState.syncDirtyObjects(this, objectMask);
2993}
2994
Jamie Madillc29968b2016-01-20 11:17:23 -05002995void Context::blitFramebuffer(GLint srcX0,
2996 GLint srcY0,
2997 GLint srcX1,
2998 GLint srcY1,
2999 GLint dstX0,
3000 GLint dstY0,
3001 GLint dstX1,
3002 GLint dstY1,
3003 GLbitfield mask,
3004 GLenum filter)
3005{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003006 if (mask == 0)
3007 {
3008 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3009 // buffers are copied.
3010 return;
3011 }
3012
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003013 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003014 ASSERT(drawFramebuffer);
3015
3016 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3017 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3018
Jamie Madillbc918e72018-03-08 09:47:21 -05003019 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003020
Jamie Madillc564c072017-06-01 12:45:42 -04003021 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003022}
Jamie Madillc29968b2016-01-20 11:17:23 -05003023
3024void Context::clear(GLbitfield mask)
3025{
Geoff Langd4fff502017-09-22 11:28:28 -04003026 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3027 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003028}
3029
3030void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3031{
Geoff Langd4fff502017-09-22 11:28:28 -04003032 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3033 ANGLE_CONTEXT_TRY(
3034 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003035}
3036
3037void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3038{
Geoff Langd4fff502017-09-22 11:28:28 -04003039 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3040 ANGLE_CONTEXT_TRY(
3041 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003042}
3043
3044void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3045{
Geoff Langd4fff502017-09-22 11:28:28 -04003046 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3047 ANGLE_CONTEXT_TRY(
3048 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003049}
3050
3051void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3052{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003053 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003054 ASSERT(framebufferObject);
3055
3056 // If a buffer is not present, the clear has no effect
3057 if (framebufferObject->getDepthbuffer() == nullptr &&
3058 framebufferObject->getStencilbuffer() == nullptr)
3059 {
3060 return;
3061 }
3062
Geoff Langd4fff502017-09-22 11:28:28 -04003063 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3064 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003065}
3066
3067void Context::readPixels(GLint x,
3068 GLint y,
3069 GLsizei width,
3070 GLsizei height,
3071 GLenum format,
3072 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003073 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003074{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003075 if (width == 0 || height == 0)
3076 {
3077 return;
3078 }
3079
Jamie Madillbc918e72018-03-08 09:47:21 -05003080 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003081
Jamie Madillb6664922017-07-25 12:55:04 -04003082 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3083 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003084
3085 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003086 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003087}
3088
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003089void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003090 GLint level,
3091 GLenum internalformat,
3092 GLint x,
3093 GLint y,
3094 GLsizei width,
3095 GLsizei height,
3096 GLint border)
3097{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003098 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003099 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003100
Jamie Madillc29968b2016-01-20 11:17:23 -05003101 Rectangle sourceArea(x, y, width, height);
3102
Jamie Madill05b35b22017-10-03 09:01:44 -04003103 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003104 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003105 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003106}
3107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003108void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003109 GLint level,
3110 GLint xoffset,
3111 GLint yoffset,
3112 GLint x,
3113 GLint y,
3114 GLsizei width,
3115 GLsizei height)
3116{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003117 if (width == 0 || height == 0)
3118 {
3119 return;
3120 }
3121
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003122 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003123 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003124
Jamie Madillc29968b2016-01-20 11:17:23 -05003125 Offset destOffset(xoffset, yoffset, 0);
3126 Rectangle sourceArea(x, y, width, height);
3127
Jamie Madill05b35b22017-10-03 09:01:44 -04003128 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003129 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003130 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003131}
3132
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003133void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003134 GLint level,
3135 GLint xoffset,
3136 GLint yoffset,
3137 GLint zoffset,
3138 GLint x,
3139 GLint y,
3140 GLsizei width,
3141 GLsizei height)
3142{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003143 if (width == 0 || height == 0)
3144 {
3145 return;
3146 }
3147
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003148 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003149 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003150
Jamie Madillc29968b2016-01-20 11:17:23 -05003151 Offset destOffset(xoffset, yoffset, zoffset);
3152 Rectangle sourceArea(x, y, width, height);
3153
Jamie Madill05b35b22017-10-03 09:01:44 -04003154 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3155 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003156 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3157 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003158}
3159
3160void Context::framebufferTexture2D(GLenum target,
3161 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003162 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003163 GLuint texture,
3164 GLint level)
3165{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003166 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003167 ASSERT(framebuffer);
3168
3169 if (texture != 0)
3170 {
3171 Texture *textureObj = getTexture(texture);
3172
3173 ImageIndex index = ImageIndex::MakeInvalid();
3174
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003175 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003176 {
3177 index = ImageIndex::Make2D(level);
3178 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003179 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003180 {
3181 index = ImageIndex::MakeRectangle(level);
3182 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003183 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003184 {
3185 ASSERT(level == 0);
3186 index = ImageIndex::Make2DMultisample();
3187 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003188 else
3189 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003190 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003191 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003192 }
3193
Jamie Madilla02315b2017-02-23 14:14:47 -05003194 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003195 }
3196 else
3197 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003198 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003199 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003200
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003201 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003202}
3203
3204void Context::framebufferRenderbuffer(GLenum target,
3205 GLenum attachment,
3206 GLenum renderbuffertarget,
3207 GLuint renderbuffer)
3208{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003209 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003210 ASSERT(framebuffer);
3211
3212 if (renderbuffer != 0)
3213 {
3214 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003215
3216 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003217 renderbufferObject);
3218 }
3219 else
3220 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003221 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003222 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003223
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003224 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003225}
3226
3227void Context::framebufferTextureLayer(GLenum target,
3228 GLenum attachment,
3229 GLuint texture,
3230 GLint level,
3231 GLint layer)
3232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003233 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003234 ASSERT(framebuffer);
3235
3236 if (texture != 0)
3237 {
3238 Texture *textureObject = getTexture(texture);
3239
3240 ImageIndex index = ImageIndex::MakeInvalid();
3241
Corentin Wallez99d492c2018-02-27 15:17:10 -05003242 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003243 {
3244 index = ImageIndex::Make3D(level, layer);
3245 }
3246 else
3247 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003248 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003249 index = ImageIndex::Make2DArray(level, layer);
3250 }
3251
Jamie Madilla02315b2017-02-23 14:14:47 -05003252 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003253 }
3254 else
3255 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003256 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003257 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003258
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003259 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003260}
3261
Martin Radev137032d2017-07-13 10:11:12 +03003262void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3263 GLenum attachment,
3264 GLuint texture,
3265 GLint level,
3266 GLint baseViewIndex,
3267 GLsizei numViews)
3268{
Martin Radev82ef7742017-08-08 17:44:58 +03003269 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3270 ASSERT(framebuffer);
3271
3272 if (texture != 0)
3273 {
3274 Texture *textureObj = getTexture(texture);
3275
Martin Radev18b75ba2017-08-15 15:50:40 +03003276 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003277 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3278 numViews, baseViewIndex);
3279 }
3280 else
3281 {
3282 framebuffer->resetAttachment(this, attachment);
3283 }
3284
3285 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003286}
3287
3288void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3289 GLenum attachment,
3290 GLuint texture,
3291 GLint level,
3292 GLsizei numViews,
3293 const GLint *viewportOffsets)
3294{
Martin Radev5dae57b2017-07-14 16:15:55 +03003295 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3296 ASSERT(framebuffer);
3297
3298 if (texture != 0)
3299 {
3300 Texture *textureObj = getTexture(texture);
3301
3302 ImageIndex index = ImageIndex::Make2D(level);
3303 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3304 textureObj, numViews, viewportOffsets);
3305 }
3306 else
3307 {
3308 framebuffer->resetAttachment(this, attachment);
3309 }
3310
3311 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003312}
3313
Jamie Madillc29968b2016-01-20 11:17:23 -05003314void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3315{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003316 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003317 ASSERT(framebuffer);
3318 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003319 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003320}
3321
3322void Context::readBuffer(GLenum mode)
3323{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003324 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003325 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003326 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003327}
3328
3329void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3330{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003331 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003332 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003333
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003334 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003335 ASSERT(framebuffer);
3336
3337 // The specification isn't clear what should be done when the framebuffer isn't complete.
3338 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003339 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003340}
3341
3342void Context::invalidateFramebuffer(GLenum target,
3343 GLsizei numAttachments,
3344 const GLenum *attachments)
3345{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003346 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003347 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003348
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003349 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003350 ASSERT(framebuffer);
3351
Jamie Madille98b1b52018-03-08 09:47:23 -05003352 bool complete = false;
3353 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3354 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003355 {
Jamie Madill437fa652016-05-03 15:13:24 -04003356 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003357 }
Jamie Madill437fa652016-05-03 15:13:24 -04003358
Jamie Madill4928b7c2017-06-20 12:57:39 -04003359 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003360}
3361
3362void Context::invalidateSubFramebuffer(GLenum target,
3363 GLsizei numAttachments,
3364 const GLenum *attachments,
3365 GLint x,
3366 GLint y,
3367 GLsizei width,
3368 GLsizei height)
3369{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003370 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003371 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003372
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003373 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003374 ASSERT(framebuffer);
3375
Jamie Madille98b1b52018-03-08 09:47:23 -05003376 bool complete = false;
3377 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3378 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003379 {
Jamie Madill437fa652016-05-03 15:13:24 -04003380 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003381 }
Jamie Madill437fa652016-05-03 15:13:24 -04003382
3383 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003384 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003385}
3386
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003387void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003388 GLint level,
3389 GLint internalformat,
3390 GLsizei width,
3391 GLsizei height,
3392 GLint border,
3393 GLenum format,
3394 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003395 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003396{
Jamie Madillbc918e72018-03-08 09:47:21 -05003397 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003398
3399 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003400 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003401 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3402 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003403}
3404
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003405void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003406 GLint level,
3407 GLint internalformat,
3408 GLsizei width,
3409 GLsizei height,
3410 GLsizei depth,
3411 GLint border,
3412 GLenum format,
3413 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003414 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003415{
Jamie Madillbc918e72018-03-08 09:47:21 -05003416 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003417
3418 Extents size(width, height, depth);
3419 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003420 handleError(texture->setImage(this, mGLState.getUnpackState(),
3421 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3422 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003423}
3424
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003425void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003426 GLint level,
3427 GLint xoffset,
3428 GLint yoffset,
3429 GLsizei width,
3430 GLsizei height,
3431 GLenum format,
3432 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003433 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003434{
3435 // Zero sized uploads are valid but no-ops
3436 if (width == 0 || height == 0)
3437 {
3438 return;
3439 }
3440
Jamie Madillbc918e72018-03-08 09:47:21 -05003441 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003442
3443 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003444 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003445 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3446 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003447}
3448
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003449void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003450 GLint level,
3451 GLint xoffset,
3452 GLint yoffset,
3453 GLint zoffset,
3454 GLsizei width,
3455 GLsizei height,
3456 GLsizei depth,
3457 GLenum format,
3458 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003459 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003460{
3461 // Zero sized uploads are valid but no-ops
3462 if (width == 0 || height == 0 || depth == 0)
3463 {
3464 return;
3465 }
3466
Jamie Madillbc918e72018-03-08 09:47:21 -05003467 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003468
3469 Box area(xoffset, yoffset, zoffset, width, height, depth);
3470 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003471 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3472 NonCubeTextureTypeToTarget(target), level, area, format, type,
3473 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003474}
3475
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003476void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003477 GLint level,
3478 GLenum internalformat,
3479 GLsizei width,
3480 GLsizei height,
3481 GLint border,
3482 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003483 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003484{
Jamie Madillbc918e72018-03-08 09:47:21 -05003485 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003486
3487 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003488 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003489 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3490 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003491 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003492}
3493
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003494void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003495 GLint level,
3496 GLenum internalformat,
3497 GLsizei width,
3498 GLsizei height,
3499 GLsizei depth,
3500 GLint border,
3501 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003502 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003503{
Jamie Madillbc918e72018-03-08 09:47:21 -05003504 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003505
3506 Extents size(width, height, depth);
3507 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003508 handleError(texture->setCompressedImage(
3509 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3510 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003511}
3512
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003513void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003514 GLint level,
3515 GLint xoffset,
3516 GLint yoffset,
3517 GLsizei width,
3518 GLsizei height,
3519 GLenum format,
3520 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003521 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003522{
Jamie Madillbc918e72018-03-08 09:47:21 -05003523 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003524
3525 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003526 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003527 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3528 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003529 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003530}
3531
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003532void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003533 GLint level,
3534 GLint xoffset,
3535 GLint yoffset,
3536 GLint zoffset,
3537 GLsizei width,
3538 GLsizei height,
3539 GLsizei depth,
3540 GLenum format,
3541 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003542 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003543{
3544 // Zero sized uploads are valid but no-ops
3545 if (width == 0 || height == 0)
3546 {
3547 return;
3548 }
3549
Jamie Madillbc918e72018-03-08 09:47:21 -05003550 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003551
3552 Box area(xoffset, yoffset, zoffset, width, height, depth);
3553 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003554 handleError(texture->setCompressedSubImage(
3555 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3556 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003557}
3558
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003559void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003560{
3561 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003562 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003563}
3564
Jamie Madill007530e2017-12-28 14:27:04 -05003565void Context::copyTexture(GLuint sourceId,
3566 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003567 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003568 GLuint destId,
3569 GLint destLevel,
3570 GLint internalFormat,
3571 GLenum destType,
3572 GLboolean unpackFlipY,
3573 GLboolean unpackPremultiplyAlpha,
3574 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003575{
Jamie Madillbc918e72018-03-08 09:47:21 -05003576 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003577
3578 gl::Texture *sourceTexture = getTexture(sourceId);
3579 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003580 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3581 sourceLevel, ConvertToBool(unpackFlipY),
3582 ConvertToBool(unpackPremultiplyAlpha),
3583 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003584}
3585
Jamie Madill007530e2017-12-28 14:27:04 -05003586void Context::copySubTexture(GLuint sourceId,
3587 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003588 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003589 GLuint destId,
3590 GLint destLevel,
3591 GLint xoffset,
3592 GLint yoffset,
3593 GLint x,
3594 GLint y,
3595 GLsizei width,
3596 GLsizei height,
3597 GLboolean unpackFlipY,
3598 GLboolean unpackPremultiplyAlpha,
3599 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003600{
3601 // Zero sized copies are valid but no-ops
3602 if (width == 0 || height == 0)
3603 {
3604 return;
3605 }
3606
Jamie Madillbc918e72018-03-08 09:47:21 -05003607 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003608
3609 gl::Texture *sourceTexture = getTexture(sourceId);
3610 gl::Texture *destTexture = getTexture(destId);
3611 Offset offset(xoffset, yoffset, 0);
3612 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003613 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3614 ConvertToBool(unpackFlipY),
3615 ConvertToBool(unpackPremultiplyAlpha),
3616 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003617}
3618
Jamie Madill007530e2017-12-28 14:27:04 -05003619void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003620{
Jamie Madillbc918e72018-03-08 09:47:21 -05003621 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003622
3623 gl::Texture *sourceTexture = getTexture(sourceId);
3624 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003625 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003626}
3627
Corentin Wallez336129f2017-10-17 15:55:40 -04003628void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003630 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003631 ASSERT(buffer);
3632
Geoff Lang496c02d2016-10-20 11:38:11 -07003633 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003634}
3635
Corentin Wallez336129f2017-10-17 15:55:40 -04003636void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003639 ASSERT(buffer);
3640
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003641 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003642 if (error.isError())
3643 {
Jamie Madill437fa652016-05-03 15:13:24 -04003644 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003645 return nullptr;
3646 }
3647
3648 return buffer->getMapPointer();
3649}
3650
Corentin Wallez336129f2017-10-17 15:55:40 -04003651GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003654 ASSERT(buffer);
3655
3656 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003657 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003658 if (error.isError())
3659 {
Jamie Madill437fa652016-05-03 15:13:24 -04003660 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003661 return GL_FALSE;
3662 }
3663
3664 return result;
3665}
3666
Corentin Wallez336129f2017-10-17 15:55:40 -04003667void *Context::mapBufferRange(BufferBinding target,
3668 GLintptr offset,
3669 GLsizeiptr length,
3670 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003673 ASSERT(buffer);
3674
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003675 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003676 if (error.isError())
3677 {
Jamie Madill437fa652016-05-03 15:13:24 -04003678 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003679 return nullptr;
3680 }
3681
3682 return buffer->getMapPointer();
3683}
3684
Corentin Wallez336129f2017-10-17 15:55:40 -04003685void Context::flushMappedBufferRange(BufferBinding /*target*/,
3686 GLintptr /*offset*/,
3687 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003688{
3689 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3690}
3691
Jamie Madillbc918e72018-03-08 09:47:21 -05003692Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003693{
Geoff Langa8cb2872018-03-09 16:09:40 -05003694 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003695}
3696
Jamie Madillbc918e72018-03-08 09:47:21 -05003697Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003698{
Geoff Langa8cb2872018-03-09 16:09:40 -05003699 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003700}
3701
Jamie Madillbc918e72018-03-08 09:47:21 -05003702Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003703{
Geoff Langa8cb2872018-03-09 16:09:40 -05003704 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003705}
3706
Jiajia Qin5451d532017-11-16 17:16:34 +08003707void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3708{
3709 UNIMPLEMENTED();
3710}
3711
Jamie Madillc20ab272016-06-09 07:20:46 -07003712void Context::activeTexture(GLenum texture)
3713{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003715}
3716
Jamie Madill876429b2017-04-20 15:46:24 -04003717void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003722void Context::blendEquation(GLenum mode)
3723{
3724 mGLState.setBlendEquation(mode, mode);
3725}
3726
Jamie Madillc20ab272016-06-09 07:20:46 -07003727void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3728{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003730}
3731
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003732void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3733{
3734 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3735}
3736
Jamie Madillc20ab272016-06-09 07:20:46 -07003737void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3738{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003740}
3741
Jamie Madill876429b2017-04-20 15:46:24 -04003742void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003745}
3746
Jamie Madill876429b2017-04-20 15:46:24 -04003747void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003750}
3751
3752void Context::clearStencil(GLint s)
3753{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003755}
3756
3757void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3758{
Geoff Lang92019432017-11-20 13:09:34 -05003759 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3760 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003761}
3762
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003763void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766}
3767
3768void Context::depthFunc(GLenum func)
3769{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771}
3772
3773void Context::depthMask(GLboolean flag)
3774{
Geoff Lang92019432017-11-20 13:09:34 -05003775 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003776}
3777
Jamie Madill876429b2017-04-20 15:46:24 -04003778void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003779{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003781}
3782
3783void Context::disable(GLenum cap)
3784{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786}
3787
3788void Context::disableVertexAttribArray(GLuint index)
3789{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791}
3792
3793void Context::enable(GLenum cap)
3794{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796}
3797
3798void Context::enableVertexAttribArray(GLuint index)
3799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003801}
3802
3803void Context::frontFace(GLenum mode)
3804{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003805 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003806}
3807
3808void Context::hint(GLenum target, GLenum mode)
3809{
3810 switch (target)
3811 {
3812 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814 break;
3815
3816 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003817 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003818 break;
3819
3820 default:
3821 UNREACHABLE();
3822 return;
3823 }
3824}
3825
3826void Context::lineWidth(GLfloat width)
3827{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003828 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003829}
3830
3831void Context::pixelStorei(GLenum pname, GLint param)
3832{
3833 switch (pname)
3834 {
3835 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003836 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003837 break;
3838
3839 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841 break;
3842
3843 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845 break;
3846
3847 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003848 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850 break;
3851
3852 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003853 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003854 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003855 break;
3856
3857 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003858 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003860 break;
3861
3862 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003863 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865 break;
3866
3867 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003868 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870 break;
3871
3872 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003873 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875 break;
3876
3877 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003878 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003880 break;
3881
3882 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003883 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003885 break;
3886
3887 default:
3888 UNREACHABLE();
3889 return;
3890 }
3891}
3892
3893void Context::polygonOffset(GLfloat factor, GLfloat units)
3894{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003895 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003896}
3897
Jamie Madill876429b2017-04-20 15:46:24 -04003898void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003899{
Geoff Lang92019432017-11-20 13:09:34 -05003900 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003901}
3902
Jiawei Shaodb342272017-09-27 10:21:45 +08003903void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3904{
3905 mGLState.setSampleMaskParams(maskNumber, mask);
3906}
3907
Jamie Madillc20ab272016-06-09 07:20:46 -07003908void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003911}
3912
3913void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3914{
3915 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3916 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003917 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003918 }
3919
3920 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3921 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003922 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003923 }
3924}
3925
3926void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3927{
3928 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3929 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003930 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003931 }
3932
3933 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3934 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003935 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003936 }
3937}
3938
3939void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3940{
3941 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3942 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003943 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003944 }
3945
3946 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3947 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003949 }
3950}
3951
3952void Context::vertexAttrib1f(GLuint index, GLfloat x)
3953{
3954 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003955 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003956}
3957
3958void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3959{
3960 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003961 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003962}
3963
3964void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3965{
3966 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003967 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003968}
3969
3970void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3971{
3972 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003974}
3975
3976void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3977{
3978 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003979 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003980}
3981
3982void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3983{
3984 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003986}
3987
3988void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3989{
3990 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003991 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003992}
3993
3994void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3995{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003996 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999void Context::vertexAttribPointer(GLuint index,
4000 GLint size,
4001 GLenum type,
4002 GLboolean normalized,
4003 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004004 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004005{
Corentin Wallez336129f2017-10-17 15:55:40 -04004006 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004007 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004008}
4009
Shao80957d92017-02-20 21:25:59 +08004010void Context::vertexAttribFormat(GLuint attribIndex,
4011 GLint size,
4012 GLenum type,
4013 GLboolean normalized,
4014 GLuint relativeOffset)
4015{
Geoff Lang92019432017-11-20 13:09:34 -05004016 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004017 relativeOffset);
4018}
4019
4020void Context::vertexAttribIFormat(GLuint attribIndex,
4021 GLint size,
4022 GLenum type,
4023 GLuint relativeOffset)
4024{
4025 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4026}
4027
4028void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4029{
Shaodde78e82017-05-22 14:13:27 +08004030 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004031}
4032
Jiajia Qin5451d532017-11-16 17:16:34 +08004033void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004034{
4035 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4036}
4037
Jamie Madillc20ab272016-06-09 07:20:46 -07004038void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4039{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004040 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004041}
4042
4043void Context::vertexAttribIPointer(GLuint index,
4044 GLint size,
4045 GLenum type,
4046 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004047 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004048{
Corentin Wallez336129f2017-10-17 15:55:40 -04004049 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4050 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004051}
4052
4053void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4054{
4055 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004056 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004057}
4058
4059void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4060{
4061 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004062 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004063}
4064
4065void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4066{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004067 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004068}
4069
4070void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4071{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004072 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004073}
4074
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004075void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4076{
4077 const VertexAttribCurrentValueData &currentValues =
4078 getGLState().getVertexAttribCurrentValue(index);
4079 const VertexArray *vao = getGLState().getVertexArray();
4080 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4081 currentValues, pname, params);
4082}
4083
4084void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4085{
4086 const VertexAttribCurrentValueData &currentValues =
4087 getGLState().getVertexAttribCurrentValue(index);
4088 const VertexArray *vao = getGLState().getVertexArray();
4089 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4090 currentValues, pname, params);
4091}
4092
4093void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4094{
4095 const VertexAttribCurrentValueData &currentValues =
4096 getGLState().getVertexAttribCurrentValue(index);
4097 const VertexArray *vao = getGLState().getVertexArray();
4098 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4099 currentValues, pname, params);
4100}
4101
4102void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4103{
4104 const VertexAttribCurrentValueData &currentValues =
4105 getGLState().getVertexAttribCurrentValue(index);
4106 const VertexArray *vao = getGLState().getVertexArray();
4107 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4108 currentValues, pname, params);
4109}
4110
Jamie Madill876429b2017-04-20 15:46:24 -04004111void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004112{
4113 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4114 QueryVertexAttribPointerv(attrib, pname, pointer);
4115}
4116
Jamie Madillc20ab272016-06-09 07:20:46 -07004117void Context::debugMessageControl(GLenum source,
4118 GLenum type,
4119 GLenum severity,
4120 GLsizei count,
4121 const GLuint *ids,
4122 GLboolean enabled)
4123{
4124 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004125 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004126 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004127}
4128
4129void Context::debugMessageInsert(GLenum source,
4130 GLenum type,
4131 GLuint id,
4132 GLenum severity,
4133 GLsizei length,
4134 const GLchar *buf)
4135{
4136 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004137 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004138}
4139
4140void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4141{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004143}
4144
4145GLuint Context::getDebugMessageLog(GLuint count,
4146 GLsizei bufSize,
4147 GLenum *sources,
4148 GLenum *types,
4149 GLuint *ids,
4150 GLenum *severities,
4151 GLsizei *lengths,
4152 GLchar *messageLog)
4153{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004154 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4155 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004156}
4157
4158void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4159{
4160 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004161 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004162 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004163}
4164
4165void Context::popDebugGroup()
4166{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004167 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004168 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004169}
4170
Corentin Wallez336129f2017-10-17 15:55:40 -04004171void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004172{
4173 Buffer *buffer = mGLState.getTargetBuffer(target);
4174 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004175 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004176}
4177
Corentin Wallez336129f2017-10-17 15:55:40 -04004178void Context::bufferSubData(BufferBinding target,
4179 GLintptr offset,
4180 GLsizeiptr size,
4181 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004182{
4183 if (data == nullptr)
4184 {
4185 return;
4186 }
4187
4188 Buffer *buffer = mGLState.getTargetBuffer(target);
4189 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004190 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004191}
4192
Jamie Madillef300b12016-10-07 15:12:09 -04004193void Context::attachShader(GLuint program, GLuint shader)
4194{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004195 Program *programObject = mState.mShaderPrograms->getProgram(program);
4196 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004197 ASSERT(programObject && shaderObject);
4198 programObject->attachShader(shaderObject);
4199}
4200
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004201const Workarounds &Context::getWorkarounds() const
4202{
4203 return mWorkarounds;
4204}
4205
Corentin Wallez336129f2017-10-17 15:55:40 -04004206void Context::copyBufferSubData(BufferBinding readTarget,
4207 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004208 GLintptr readOffset,
4209 GLintptr writeOffset,
4210 GLsizeiptr size)
4211{
4212 // if size is zero, the copy is a successful no-op
4213 if (size == 0)
4214 {
4215 return;
4216 }
4217
4218 // TODO(jmadill): cache these.
4219 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4220 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4221
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004222 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004223}
4224
Jamie Madill01a80ee2016-11-07 12:06:18 -05004225void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4226{
4227 Program *programObject = getProgram(program);
4228 // TODO(jmadill): Re-use this from the validation if possible.
4229 ASSERT(programObject);
4230 programObject->bindAttributeLocation(index, name);
4231}
4232
Corentin Wallez336129f2017-10-17 15:55:40 -04004233void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004234{
Corentin Wallez336129f2017-10-17 15:55:40 -04004235 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4236 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004237}
4238
Corentin Wallez336129f2017-10-17 15:55:40 -04004239void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004240{
4241 bindBufferRange(target, index, buffer, 0, 0);
4242}
4243
Corentin Wallez336129f2017-10-17 15:55:40 -04004244void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004245 GLuint index,
4246 GLuint buffer,
4247 GLintptr offset,
4248 GLsizeiptr size)
4249{
Corentin Wallez336129f2017-10-17 15:55:40 -04004250 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4251 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004252}
4253
Jamie Madill01a80ee2016-11-07 12:06:18 -05004254void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4255{
4256 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4257 {
4258 bindReadFramebuffer(framebuffer);
4259 }
4260
4261 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4262 {
4263 bindDrawFramebuffer(framebuffer);
4264 }
4265}
4266
4267void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4268{
4269 ASSERT(target == GL_RENDERBUFFER);
4270 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004271 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004272 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004273}
4274
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004275void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004276 GLsizei samples,
4277 GLenum internalformat,
4278 GLsizei width,
4279 GLsizei height,
4280 GLboolean fixedsamplelocations)
4281{
4282 Extents size(width, height, 1);
4283 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004284 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4285 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004286}
4287
4288void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4289{
JiangYizhou5b03f472017-01-09 10:22:53 +08004290 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4291 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004292 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004293 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004294
4295 switch (pname)
4296 {
4297 case GL_SAMPLE_POSITION:
4298 handleError(framebuffer->getSamplePosition(index, val));
4299 break;
4300 default:
4301 UNREACHABLE();
4302 }
4303}
4304
Jamie Madille8fb6402017-02-14 17:56:40 -05004305void Context::renderbufferStorage(GLenum target,
4306 GLenum internalformat,
4307 GLsizei width,
4308 GLsizei height)
4309{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004310 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4311 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4312
Jamie Madille8fb6402017-02-14 17:56:40 -05004313 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004314 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004315}
4316
4317void Context::renderbufferStorageMultisample(GLenum target,
4318 GLsizei samples,
4319 GLenum internalformat,
4320 GLsizei width,
4321 GLsizei height)
4322{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004323 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4324 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004325
4326 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004327 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004328 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004329}
4330
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004331void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4332{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004333 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004334 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004335}
4336
JiangYizhoue18e6392017-02-20 10:32:23 +08004337void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4338{
4339 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4340 QueryFramebufferParameteriv(framebuffer, pname, params);
4341}
4342
Jiajia Qin5451d532017-11-16 17:16:34 +08004343void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004344{
4345 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4346 SetFramebufferParameteri(framebuffer, pname, param);
4347}
4348
Jamie Madillb3f26b92017-07-19 15:07:41 -04004349Error Context::getScratchBuffer(size_t requstedSizeBytes,
4350 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004351{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004352 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4353 {
4354 return OutOfMemory() << "Failed to allocate internal buffer.";
4355 }
4356 return NoError();
4357}
4358
4359Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4360 angle::MemoryBuffer **zeroBufferOut) const
4361{
4362 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004363 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004364 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004365 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004366 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004367}
4368
Xinghua Cao10a4d432017-11-28 14:46:26 +08004369Error Context::prepareForDispatch()
4370{
Geoff Langa8cb2872018-03-09 16:09:40 -05004371 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004372
4373 if (isRobustResourceInitEnabled())
4374 {
4375 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4376 }
4377
4378 return NoError();
4379}
4380
Xinghua Cao2b396592017-03-29 15:36:04 +08004381void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4382{
4383 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4384 {
4385 return;
4386 }
4387
Xinghua Cao10a4d432017-11-28 14:46:26 +08004388 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004389 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004390}
4391
Jiajia Qin5451d532017-11-16 17:16:34 +08004392void Context::dispatchComputeIndirect(GLintptr indirect)
4393{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004394 ANGLE_CONTEXT_TRY(prepareForDispatch());
4395 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004396}
4397
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004398void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004399 GLsizei levels,
4400 GLenum internalFormat,
4401 GLsizei width,
4402 GLsizei height)
4403{
4404 Extents size(width, height, 1);
4405 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004406 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004407}
4408
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004409void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004410 GLsizei levels,
4411 GLenum internalFormat,
4412 GLsizei width,
4413 GLsizei height,
4414 GLsizei depth)
4415{
4416 Extents size(width, height, depth);
4417 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004418 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004419}
4420
Jiajia Qin5451d532017-11-16 17:16:34 +08004421void Context::memoryBarrier(GLbitfield barriers)
4422{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004423 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004424}
4425
4426void Context::memoryBarrierByRegion(GLbitfield barriers)
4427{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004428 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004429}
4430
Jamie Madillc1d770e2017-04-13 17:31:24 -04004431GLenum Context::checkFramebufferStatus(GLenum target)
4432{
4433 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4434 ASSERT(framebuffer);
4435
Jamie Madille98b1b52018-03-08 09:47:23 -05004436 GLenum status = GL_NONE;
4437 Error err = framebuffer->checkStatus(this, &status);
4438 if (err.isError())
4439 {
4440 handleError(err);
4441 return 0;
4442 }
4443 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004444}
4445
4446void Context::compileShader(GLuint shader)
4447{
4448 Shader *shaderObject = GetValidShader(this, shader);
4449 if (!shaderObject)
4450 {
4451 return;
4452 }
4453 shaderObject->compile(this);
4454}
4455
4456void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4457{
4458 for (int i = 0; i < n; i++)
4459 {
4460 deleteBuffer(buffers[i]);
4461 }
4462}
4463
4464void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4465{
4466 for (int i = 0; i < n; i++)
4467 {
4468 if (framebuffers[i] != 0)
4469 {
4470 deleteFramebuffer(framebuffers[i]);
4471 }
4472 }
4473}
4474
4475void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4476{
4477 for (int i = 0; i < n; i++)
4478 {
4479 deleteRenderbuffer(renderbuffers[i]);
4480 }
4481}
4482
4483void Context::deleteTextures(GLsizei n, const GLuint *textures)
4484{
4485 for (int i = 0; i < n; i++)
4486 {
4487 if (textures[i] != 0)
4488 {
4489 deleteTexture(textures[i]);
4490 }
4491 }
4492}
4493
4494void Context::detachShader(GLuint program, GLuint shader)
4495{
4496 Program *programObject = getProgram(program);
4497 ASSERT(programObject);
4498
4499 Shader *shaderObject = getShader(shader);
4500 ASSERT(shaderObject);
4501
4502 programObject->detachShader(this, shaderObject);
4503}
4504
4505void Context::genBuffers(GLsizei n, GLuint *buffers)
4506{
4507 for (int i = 0; i < n; i++)
4508 {
4509 buffers[i] = createBuffer();
4510 }
4511}
4512
4513void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4514{
4515 for (int i = 0; i < n; i++)
4516 {
4517 framebuffers[i] = createFramebuffer();
4518 }
4519}
4520
4521void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4522{
4523 for (int i = 0; i < n; i++)
4524 {
4525 renderbuffers[i] = createRenderbuffer();
4526 }
4527}
4528
4529void Context::genTextures(GLsizei n, GLuint *textures)
4530{
4531 for (int i = 0; i < n; i++)
4532 {
4533 textures[i] = createTexture();
4534 }
4535}
4536
4537void Context::getActiveAttrib(GLuint program,
4538 GLuint index,
4539 GLsizei bufsize,
4540 GLsizei *length,
4541 GLint *size,
4542 GLenum *type,
4543 GLchar *name)
4544{
4545 Program *programObject = getProgram(program);
4546 ASSERT(programObject);
4547 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4548}
4549
4550void Context::getActiveUniform(GLuint program,
4551 GLuint index,
4552 GLsizei bufsize,
4553 GLsizei *length,
4554 GLint *size,
4555 GLenum *type,
4556 GLchar *name)
4557{
4558 Program *programObject = getProgram(program);
4559 ASSERT(programObject);
4560 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4561}
4562
4563void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4564{
4565 Program *programObject = getProgram(program);
4566 ASSERT(programObject);
4567 programObject->getAttachedShaders(maxcount, count, shaders);
4568}
4569
4570GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4571{
4572 Program *programObject = getProgram(program);
4573 ASSERT(programObject);
4574 return programObject->getAttributeLocation(name);
4575}
4576
4577void Context::getBooleanv(GLenum pname, GLboolean *params)
4578{
4579 GLenum nativeType;
4580 unsigned int numParams = 0;
4581 getQueryParameterInfo(pname, &nativeType, &numParams);
4582
4583 if (nativeType == GL_BOOL)
4584 {
4585 getBooleanvImpl(pname, params);
4586 }
4587 else
4588 {
4589 CastStateValues(this, nativeType, pname, numParams, params);
4590 }
4591}
4592
4593void Context::getFloatv(GLenum pname, GLfloat *params)
4594{
4595 GLenum nativeType;
4596 unsigned int numParams = 0;
4597 getQueryParameterInfo(pname, &nativeType, &numParams);
4598
4599 if (nativeType == GL_FLOAT)
4600 {
4601 getFloatvImpl(pname, params);
4602 }
4603 else
4604 {
4605 CastStateValues(this, nativeType, pname, numParams, params);
4606 }
4607}
4608
4609void Context::getIntegerv(GLenum pname, GLint *params)
4610{
4611 GLenum nativeType;
4612 unsigned int numParams = 0;
4613 getQueryParameterInfo(pname, &nativeType, &numParams);
4614
4615 if (nativeType == GL_INT)
4616 {
4617 getIntegervImpl(pname, params);
4618 }
4619 else
4620 {
4621 CastStateValues(this, nativeType, pname, numParams, params);
4622 }
4623}
4624
4625void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4626{
4627 Program *programObject = getProgram(program);
4628 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004629 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004630}
4631
Jiajia Qin5451d532017-11-16 17:16:34 +08004632void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4633{
4634 UNIMPLEMENTED();
4635}
4636
Jamie Madillbe849e42017-05-02 15:49:00 -04004637void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004638{
4639 Program *programObject = getProgram(program);
4640 ASSERT(programObject);
4641 programObject->getInfoLog(bufsize, length, infolog);
4642}
4643
Jiajia Qin5451d532017-11-16 17:16:34 +08004644void Context::getProgramPipelineInfoLog(GLuint pipeline,
4645 GLsizei bufSize,
4646 GLsizei *length,
4647 GLchar *infoLog)
4648{
4649 UNIMPLEMENTED();
4650}
4651
Jamie Madillc1d770e2017-04-13 17:31:24 -04004652void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4653{
4654 Shader *shaderObject = getShader(shader);
4655 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004656 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004657}
4658
4659void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4660{
4661 Shader *shaderObject = getShader(shader);
4662 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004663 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004664}
4665
4666void Context::getShaderPrecisionFormat(GLenum shadertype,
4667 GLenum precisiontype,
4668 GLint *range,
4669 GLint *precision)
4670{
4671 // TODO(jmadill): Compute shaders.
4672
4673 switch (shadertype)
4674 {
4675 case GL_VERTEX_SHADER:
4676 switch (precisiontype)
4677 {
4678 case GL_LOW_FLOAT:
4679 mCaps.vertexLowpFloat.get(range, precision);
4680 break;
4681 case GL_MEDIUM_FLOAT:
4682 mCaps.vertexMediumpFloat.get(range, precision);
4683 break;
4684 case GL_HIGH_FLOAT:
4685 mCaps.vertexHighpFloat.get(range, precision);
4686 break;
4687
4688 case GL_LOW_INT:
4689 mCaps.vertexLowpInt.get(range, precision);
4690 break;
4691 case GL_MEDIUM_INT:
4692 mCaps.vertexMediumpInt.get(range, precision);
4693 break;
4694 case GL_HIGH_INT:
4695 mCaps.vertexHighpInt.get(range, precision);
4696 break;
4697
4698 default:
4699 UNREACHABLE();
4700 return;
4701 }
4702 break;
4703
4704 case GL_FRAGMENT_SHADER:
4705 switch (precisiontype)
4706 {
4707 case GL_LOW_FLOAT:
4708 mCaps.fragmentLowpFloat.get(range, precision);
4709 break;
4710 case GL_MEDIUM_FLOAT:
4711 mCaps.fragmentMediumpFloat.get(range, precision);
4712 break;
4713 case GL_HIGH_FLOAT:
4714 mCaps.fragmentHighpFloat.get(range, precision);
4715 break;
4716
4717 case GL_LOW_INT:
4718 mCaps.fragmentLowpInt.get(range, precision);
4719 break;
4720 case GL_MEDIUM_INT:
4721 mCaps.fragmentMediumpInt.get(range, precision);
4722 break;
4723 case GL_HIGH_INT:
4724 mCaps.fragmentHighpInt.get(range, precision);
4725 break;
4726
4727 default:
4728 UNREACHABLE();
4729 return;
4730 }
4731 break;
4732
4733 default:
4734 UNREACHABLE();
4735 return;
4736 }
4737}
4738
4739void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4740{
4741 Shader *shaderObject = getShader(shader);
4742 ASSERT(shaderObject);
4743 shaderObject->getSource(bufsize, length, source);
4744}
4745
4746void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4747{
4748 Program *programObject = getProgram(program);
4749 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004750 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004751}
4752
4753void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4754{
4755 Program *programObject = getProgram(program);
4756 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004757 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004758}
4759
4760GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4761{
4762 Program *programObject = getProgram(program);
4763 ASSERT(programObject);
4764 return programObject->getUniformLocation(name);
4765}
4766
4767GLboolean Context::isBuffer(GLuint buffer)
4768{
4769 if (buffer == 0)
4770 {
4771 return GL_FALSE;
4772 }
4773
4774 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4775}
4776
4777GLboolean Context::isEnabled(GLenum cap)
4778{
4779 return mGLState.getEnableFeature(cap);
4780}
4781
4782GLboolean Context::isFramebuffer(GLuint framebuffer)
4783{
4784 if (framebuffer == 0)
4785 {
4786 return GL_FALSE;
4787 }
4788
4789 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4790}
4791
4792GLboolean Context::isProgram(GLuint program)
4793{
4794 if (program == 0)
4795 {
4796 return GL_FALSE;
4797 }
4798
4799 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4800}
4801
4802GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4803{
4804 if (renderbuffer == 0)
4805 {
4806 return GL_FALSE;
4807 }
4808
4809 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4810}
4811
4812GLboolean Context::isShader(GLuint shader)
4813{
4814 if (shader == 0)
4815 {
4816 return GL_FALSE;
4817 }
4818
4819 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4820}
4821
4822GLboolean Context::isTexture(GLuint texture)
4823{
4824 if (texture == 0)
4825 {
4826 return GL_FALSE;
4827 }
4828
4829 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4830}
4831
4832void Context::linkProgram(GLuint program)
4833{
4834 Program *programObject = getProgram(program);
4835 ASSERT(programObject);
4836 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004837 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004838}
4839
4840void Context::releaseShaderCompiler()
4841{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004842 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004843}
4844
4845void Context::shaderBinary(GLsizei n,
4846 const GLuint *shaders,
4847 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004848 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004849 GLsizei length)
4850{
4851 // No binary shader formats are supported.
4852 UNIMPLEMENTED();
4853}
4854
4855void Context::shaderSource(GLuint shader,
4856 GLsizei count,
4857 const GLchar *const *string,
4858 const GLint *length)
4859{
4860 Shader *shaderObject = getShader(shader);
4861 ASSERT(shaderObject);
4862 shaderObject->setSource(count, string, length);
4863}
4864
4865void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4866{
4867 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4868}
4869
4870void Context::stencilMask(GLuint mask)
4871{
4872 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4873}
4874
4875void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4876{
4877 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4878}
4879
4880void Context::uniform1f(GLint location, GLfloat x)
4881{
4882 Program *program = mGLState.getProgram();
4883 program->setUniform1fv(location, 1, &x);
4884}
4885
4886void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4887{
4888 Program *program = mGLState.getProgram();
4889 program->setUniform1fv(location, count, v);
4890}
4891
4892void Context::uniform1i(GLint location, GLint x)
4893{
4894 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004895 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4896 {
4897 mGLState.setObjectDirty(GL_PROGRAM);
4898 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004899}
4900
4901void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4902{
4903 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004904 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4905 {
4906 mGLState.setObjectDirty(GL_PROGRAM);
4907 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004908}
4909
4910void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4911{
4912 GLfloat xy[2] = {x, y};
4913 Program *program = mGLState.getProgram();
4914 program->setUniform2fv(location, 1, xy);
4915}
4916
4917void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4918{
4919 Program *program = mGLState.getProgram();
4920 program->setUniform2fv(location, count, v);
4921}
4922
4923void Context::uniform2i(GLint location, GLint x, GLint y)
4924{
4925 GLint xy[2] = {x, y};
4926 Program *program = mGLState.getProgram();
4927 program->setUniform2iv(location, 1, xy);
4928}
4929
4930void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4931{
4932 Program *program = mGLState.getProgram();
4933 program->setUniform2iv(location, count, v);
4934}
4935
4936void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4937{
4938 GLfloat xyz[3] = {x, y, z};
4939 Program *program = mGLState.getProgram();
4940 program->setUniform3fv(location, 1, xyz);
4941}
4942
4943void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4944{
4945 Program *program = mGLState.getProgram();
4946 program->setUniform3fv(location, count, v);
4947}
4948
4949void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4950{
4951 GLint xyz[3] = {x, y, z};
4952 Program *program = mGLState.getProgram();
4953 program->setUniform3iv(location, 1, xyz);
4954}
4955
4956void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4957{
4958 Program *program = mGLState.getProgram();
4959 program->setUniform3iv(location, count, v);
4960}
4961
4962void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4963{
4964 GLfloat xyzw[4] = {x, y, z, w};
4965 Program *program = mGLState.getProgram();
4966 program->setUniform4fv(location, 1, xyzw);
4967}
4968
4969void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4970{
4971 Program *program = mGLState.getProgram();
4972 program->setUniform4fv(location, count, v);
4973}
4974
4975void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4976{
4977 GLint xyzw[4] = {x, y, z, w};
4978 Program *program = mGLState.getProgram();
4979 program->setUniform4iv(location, 1, xyzw);
4980}
4981
4982void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4983{
4984 Program *program = mGLState.getProgram();
4985 program->setUniform4iv(location, count, v);
4986}
4987
4988void Context::uniformMatrix2fv(GLint location,
4989 GLsizei count,
4990 GLboolean transpose,
4991 const GLfloat *value)
4992{
4993 Program *program = mGLState.getProgram();
4994 program->setUniformMatrix2fv(location, count, transpose, value);
4995}
4996
4997void Context::uniformMatrix3fv(GLint location,
4998 GLsizei count,
4999 GLboolean transpose,
5000 const GLfloat *value)
5001{
5002 Program *program = mGLState.getProgram();
5003 program->setUniformMatrix3fv(location, count, transpose, value);
5004}
5005
5006void Context::uniformMatrix4fv(GLint location,
5007 GLsizei count,
5008 GLboolean transpose,
5009 const GLfloat *value)
5010{
5011 Program *program = mGLState.getProgram();
5012 program->setUniformMatrix4fv(location, count, transpose, value);
5013}
5014
5015void Context::validateProgram(GLuint program)
5016{
5017 Program *programObject = getProgram(program);
5018 ASSERT(programObject);
5019 programObject->validate(mCaps);
5020}
5021
Jiajia Qin5451d532017-11-16 17:16:34 +08005022void Context::validateProgramPipeline(GLuint pipeline)
5023{
5024 UNIMPLEMENTED();
5025}
5026
Jamie Madilld04908b2017-06-09 14:15:35 -04005027void Context::getProgramBinary(GLuint program,
5028 GLsizei bufSize,
5029 GLsizei *length,
5030 GLenum *binaryFormat,
5031 void *binary)
5032{
5033 Program *programObject = getProgram(program);
5034 ASSERT(programObject != nullptr);
5035
5036 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5037}
5038
5039void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5040{
5041 Program *programObject = getProgram(program);
5042 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005043
Jamie Madilld04908b2017-06-09 14:15:35 -04005044 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5045}
5046
Jamie Madillff325f12017-08-26 15:06:05 -04005047void Context::uniform1ui(GLint location, GLuint v0)
5048{
5049 Program *program = mGLState.getProgram();
5050 program->setUniform1uiv(location, 1, &v0);
5051}
5052
5053void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5054{
5055 Program *program = mGLState.getProgram();
5056 const GLuint xy[] = {v0, v1};
5057 program->setUniform2uiv(location, 1, xy);
5058}
5059
5060void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5061{
5062 Program *program = mGLState.getProgram();
5063 const GLuint xyz[] = {v0, v1, v2};
5064 program->setUniform3uiv(location, 1, xyz);
5065}
5066
5067void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5068{
5069 Program *program = mGLState.getProgram();
5070 const GLuint xyzw[] = {v0, v1, v2, v3};
5071 program->setUniform4uiv(location, 1, xyzw);
5072}
5073
5074void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5075{
5076 Program *program = mGLState.getProgram();
5077 program->setUniform1uiv(location, count, value);
5078}
5079void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5080{
5081 Program *program = mGLState.getProgram();
5082 program->setUniform2uiv(location, count, value);
5083}
5084
5085void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5086{
5087 Program *program = mGLState.getProgram();
5088 program->setUniform3uiv(location, count, value);
5089}
5090
5091void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5092{
5093 Program *program = mGLState.getProgram();
5094 program->setUniform4uiv(location, count, value);
5095}
5096
Jamie Madillf0e04492017-08-26 15:28:42 -04005097void Context::genQueries(GLsizei n, GLuint *ids)
5098{
5099 for (GLsizei i = 0; i < n; i++)
5100 {
5101 GLuint handle = mQueryHandleAllocator.allocate();
5102 mQueryMap.assign(handle, nullptr);
5103 ids[i] = handle;
5104 }
5105}
5106
5107void Context::deleteQueries(GLsizei n, const GLuint *ids)
5108{
5109 for (int i = 0; i < n; i++)
5110 {
5111 GLuint query = ids[i];
5112
5113 Query *queryObject = nullptr;
5114 if (mQueryMap.erase(query, &queryObject))
5115 {
5116 mQueryHandleAllocator.release(query);
5117 if (queryObject)
5118 {
5119 queryObject->release(this);
5120 }
5121 }
5122 }
5123}
5124
5125GLboolean Context::isQuery(GLuint id)
5126{
5127 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5128}
5129
Jamie Madillc8c95812017-08-26 18:40:09 -04005130void Context::uniformMatrix2x3fv(GLint location,
5131 GLsizei count,
5132 GLboolean transpose,
5133 const GLfloat *value)
5134{
5135 Program *program = mGLState.getProgram();
5136 program->setUniformMatrix2x3fv(location, count, transpose, value);
5137}
5138
5139void Context::uniformMatrix3x2fv(GLint location,
5140 GLsizei count,
5141 GLboolean transpose,
5142 const GLfloat *value)
5143{
5144 Program *program = mGLState.getProgram();
5145 program->setUniformMatrix3x2fv(location, count, transpose, value);
5146}
5147
5148void Context::uniformMatrix2x4fv(GLint location,
5149 GLsizei count,
5150 GLboolean transpose,
5151 const GLfloat *value)
5152{
5153 Program *program = mGLState.getProgram();
5154 program->setUniformMatrix2x4fv(location, count, transpose, value);
5155}
5156
5157void Context::uniformMatrix4x2fv(GLint location,
5158 GLsizei count,
5159 GLboolean transpose,
5160 const GLfloat *value)
5161{
5162 Program *program = mGLState.getProgram();
5163 program->setUniformMatrix4x2fv(location, count, transpose, value);
5164}
5165
5166void Context::uniformMatrix3x4fv(GLint location,
5167 GLsizei count,
5168 GLboolean transpose,
5169 const GLfloat *value)
5170{
5171 Program *program = mGLState.getProgram();
5172 program->setUniformMatrix3x4fv(location, count, transpose, value);
5173}
5174
5175void Context::uniformMatrix4x3fv(GLint location,
5176 GLsizei count,
5177 GLboolean transpose,
5178 const GLfloat *value)
5179{
5180 Program *program = mGLState.getProgram();
5181 program->setUniformMatrix4x3fv(location, count, transpose, value);
5182}
5183
Jamie Madilld7576732017-08-26 18:49:50 -04005184void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5185{
5186 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5187 {
5188 GLuint vertexArray = arrays[arrayIndex];
5189
5190 if (arrays[arrayIndex] != 0)
5191 {
5192 VertexArray *vertexArrayObject = nullptr;
5193 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5194 {
5195 if (vertexArrayObject != nullptr)
5196 {
5197 detachVertexArray(vertexArray);
5198 vertexArrayObject->onDestroy(this);
5199 }
5200
5201 mVertexArrayHandleAllocator.release(vertexArray);
5202 }
5203 }
5204 }
5205}
5206
5207void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5208{
5209 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5210 {
5211 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5212 mVertexArrayMap.assign(vertexArray, nullptr);
5213 arrays[arrayIndex] = vertexArray;
5214 }
5215}
5216
5217bool Context::isVertexArray(GLuint array)
5218{
5219 if (array == 0)
5220 {
5221 return GL_FALSE;
5222 }
5223
5224 VertexArray *vao = getVertexArray(array);
5225 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5226}
5227
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005228void Context::endTransformFeedback()
5229{
5230 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5231 transformFeedback->end(this);
5232}
5233
5234void Context::transformFeedbackVaryings(GLuint program,
5235 GLsizei count,
5236 const GLchar *const *varyings,
5237 GLenum bufferMode)
5238{
5239 Program *programObject = getProgram(program);
5240 ASSERT(programObject);
5241 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5242}
5243
5244void Context::getTransformFeedbackVarying(GLuint program,
5245 GLuint index,
5246 GLsizei bufSize,
5247 GLsizei *length,
5248 GLsizei *size,
5249 GLenum *type,
5250 GLchar *name)
5251{
5252 Program *programObject = getProgram(program);
5253 ASSERT(programObject);
5254 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5255}
5256
5257void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5258{
5259 for (int i = 0; i < n; i++)
5260 {
5261 GLuint transformFeedback = ids[i];
5262 if (transformFeedback == 0)
5263 {
5264 continue;
5265 }
5266
5267 TransformFeedback *transformFeedbackObject = nullptr;
5268 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5269 {
5270 if (transformFeedbackObject != nullptr)
5271 {
5272 detachTransformFeedback(transformFeedback);
5273 transformFeedbackObject->release(this);
5274 }
5275
5276 mTransformFeedbackHandleAllocator.release(transformFeedback);
5277 }
5278 }
5279}
5280
5281void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5282{
5283 for (int i = 0; i < n; i++)
5284 {
5285 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5286 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5287 ids[i] = transformFeedback;
5288 }
5289}
5290
5291bool Context::isTransformFeedback(GLuint id)
5292{
5293 if (id == 0)
5294 {
5295 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5296 // returns FALSE
5297 return GL_FALSE;
5298 }
5299
5300 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5301 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5302}
5303
5304void Context::pauseTransformFeedback()
5305{
5306 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5307 transformFeedback->pause();
5308}
5309
5310void Context::resumeTransformFeedback()
5311{
5312 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5313 transformFeedback->resume();
5314}
5315
Jamie Madill12e957f2017-08-26 21:42:26 -04005316void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5317{
5318 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005319 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005320}
5321
5322GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5323{
5324 const Program *programObject = getProgram(program);
5325 return programObject->getFragDataLocation(name);
5326}
5327
5328void Context::getUniformIndices(GLuint program,
5329 GLsizei uniformCount,
5330 const GLchar *const *uniformNames,
5331 GLuint *uniformIndices)
5332{
5333 const Program *programObject = getProgram(program);
5334 if (!programObject->isLinked())
5335 {
5336 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5337 {
5338 uniformIndices[uniformId] = GL_INVALID_INDEX;
5339 }
5340 }
5341 else
5342 {
5343 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5344 {
5345 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5346 }
5347 }
5348}
5349
5350void Context::getActiveUniformsiv(GLuint program,
5351 GLsizei uniformCount,
5352 const GLuint *uniformIndices,
5353 GLenum pname,
5354 GLint *params)
5355{
5356 const Program *programObject = getProgram(program);
5357 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5358 {
5359 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005360 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005361 }
5362}
5363
5364GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5365{
5366 const Program *programObject = getProgram(program);
5367 return programObject->getUniformBlockIndex(uniformBlockName);
5368}
5369
5370void Context::getActiveUniformBlockiv(GLuint program,
5371 GLuint uniformBlockIndex,
5372 GLenum pname,
5373 GLint *params)
5374{
5375 const Program *programObject = getProgram(program);
5376 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5377}
5378
5379void Context::getActiveUniformBlockName(GLuint program,
5380 GLuint uniformBlockIndex,
5381 GLsizei bufSize,
5382 GLsizei *length,
5383 GLchar *uniformBlockName)
5384{
5385 const Program *programObject = getProgram(program);
5386 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5387}
5388
5389void Context::uniformBlockBinding(GLuint program,
5390 GLuint uniformBlockIndex,
5391 GLuint uniformBlockBinding)
5392{
5393 Program *programObject = getProgram(program);
5394 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5395}
5396
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005397GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5398{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005399 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5400 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005401
Jamie Madill70b5bb02017-08-28 13:32:37 -04005402 Sync *syncObject = getSync(syncHandle);
5403 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005404 if (error.isError())
5405 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005406 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005407 handleError(error);
5408 return nullptr;
5409 }
5410
Jamie Madill70b5bb02017-08-28 13:32:37 -04005411 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005412}
5413
5414GLboolean Context::isSync(GLsync sync)
5415{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005416 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005417}
5418
5419GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5420{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005421 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005422
5423 GLenum result = GL_WAIT_FAILED;
5424 handleError(syncObject->clientWait(flags, timeout, &result));
5425 return result;
5426}
5427
5428void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5429{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005430 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005431 handleError(syncObject->serverWait(flags, timeout));
5432}
5433
5434void Context::getInteger64v(GLenum pname, GLint64 *params)
5435{
5436 GLenum nativeType = GL_NONE;
5437 unsigned int numParams = 0;
5438 getQueryParameterInfo(pname, &nativeType, &numParams);
5439
5440 if (nativeType == GL_INT_64_ANGLEX)
5441 {
5442 getInteger64vImpl(pname, params);
5443 }
5444 else
5445 {
5446 CastStateValues(this, nativeType, pname, numParams, params);
5447 }
5448}
5449
Corentin Wallez336129f2017-10-17 15:55:40 -04005450void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005451{
5452 Buffer *buffer = mGLState.getTargetBuffer(target);
5453 QueryBufferParameteri64v(buffer, pname, params);
5454}
5455
5456void Context::genSamplers(GLsizei count, GLuint *samplers)
5457{
5458 for (int i = 0; i < count; i++)
5459 {
5460 samplers[i] = mState.mSamplers->createSampler();
5461 }
5462}
5463
5464void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5465{
5466 for (int i = 0; i < count; i++)
5467 {
5468 GLuint sampler = samplers[i];
5469
5470 if (mState.mSamplers->getSampler(sampler))
5471 {
5472 detachSampler(sampler);
5473 }
5474
5475 mState.mSamplers->deleteObject(this, sampler);
5476 }
5477}
5478
5479void Context::getInternalformativ(GLenum target,
5480 GLenum internalformat,
5481 GLenum pname,
5482 GLsizei bufSize,
5483 GLint *params)
5484{
5485 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5486 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5487}
5488
Jiajia Qin5451d532017-11-16 17:16:34 +08005489void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5490{
5491 programUniform1iv(program, location, 1, &v0);
5492}
5493
5494void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5495{
5496 GLint xy[2] = {v0, v1};
5497 programUniform2iv(program, location, 1, xy);
5498}
5499
5500void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5501{
5502 GLint xyz[3] = {v0, v1, v2};
5503 programUniform3iv(program, location, 1, xyz);
5504}
5505
5506void Context::programUniform4i(GLuint program,
5507 GLint location,
5508 GLint v0,
5509 GLint v1,
5510 GLint v2,
5511 GLint v3)
5512{
5513 GLint xyzw[4] = {v0, v1, v2, v3};
5514 programUniform4iv(program, location, 1, xyzw);
5515}
5516
5517void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5518{
5519 programUniform1uiv(program, location, 1, &v0);
5520}
5521
5522void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5523{
5524 GLuint xy[2] = {v0, v1};
5525 programUniform2uiv(program, location, 1, xy);
5526}
5527
5528void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5529{
5530 GLuint xyz[3] = {v0, v1, v2};
5531 programUniform3uiv(program, location, 1, xyz);
5532}
5533
5534void Context::programUniform4ui(GLuint program,
5535 GLint location,
5536 GLuint v0,
5537 GLuint v1,
5538 GLuint v2,
5539 GLuint v3)
5540{
5541 GLuint xyzw[4] = {v0, v1, v2, v3};
5542 programUniform4uiv(program, location, 1, xyzw);
5543}
5544
5545void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5546{
5547 programUniform1fv(program, location, 1, &v0);
5548}
5549
5550void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5551{
5552 GLfloat xy[2] = {v0, v1};
5553 programUniform2fv(program, location, 1, xy);
5554}
5555
5556void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5557{
5558 GLfloat xyz[3] = {v0, v1, v2};
5559 programUniform3fv(program, location, 1, xyz);
5560}
5561
5562void Context::programUniform4f(GLuint program,
5563 GLint location,
5564 GLfloat v0,
5565 GLfloat v1,
5566 GLfloat v2,
5567 GLfloat v3)
5568{
5569 GLfloat xyzw[4] = {v0, v1, v2, v3};
5570 programUniform4fv(program, location, 1, xyzw);
5571}
5572
Jamie Madill81c2e252017-09-09 23:32:46 -04005573void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject);
5577 if (programObject->setUniform1iv(location, count, value) ==
5578 Program::SetUniformResult::SamplerChanged)
5579 {
5580 mGLState.setObjectDirty(GL_PROGRAM);
5581 }
5582}
5583
Jiajia Qin5451d532017-11-16 17:16:34 +08005584void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5585{
5586 Program *programObject = getProgram(program);
5587 ASSERT(programObject);
5588 programObject->setUniform2iv(location, count, value);
5589}
5590
5591void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5592{
5593 Program *programObject = getProgram(program);
5594 ASSERT(programObject);
5595 programObject->setUniform3iv(location, count, value);
5596}
5597
5598void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5599{
5600 Program *programObject = getProgram(program);
5601 ASSERT(programObject);
5602 programObject->setUniform4iv(location, count, value);
5603}
5604
5605void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject);
5609 programObject->setUniform1uiv(location, count, value);
5610}
5611
5612void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5613{
5614 Program *programObject = getProgram(program);
5615 ASSERT(programObject);
5616 programObject->setUniform2uiv(location, count, value);
5617}
5618
5619void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5620{
5621 Program *programObject = getProgram(program);
5622 ASSERT(programObject);
5623 programObject->setUniform3uiv(location, count, value);
5624}
5625
5626void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5627{
5628 Program *programObject = getProgram(program);
5629 ASSERT(programObject);
5630 programObject->setUniform4uiv(location, count, value);
5631}
5632
5633void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5634{
5635 Program *programObject = getProgram(program);
5636 ASSERT(programObject);
5637 programObject->setUniform1fv(location, count, value);
5638}
5639
5640void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5641{
5642 Program *programObject = getProgram(program);
5643 ASSERT(programObject);
5644 programObject->setUniform2fv(location, count, value);
5645}
5646
5647void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5648{
5649 Program *programObject = getProgram(program);
5650 ASSERT(programObject);
5651 programObject->setUniform3fv(location, count, value);
5652}
5653
5654void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5655{
5656 Program *programObject = getProgram(program);
5657 ASSERT(programObject);
5658 programObject->setUniform4fv(location, count, value);
5659}
5660
5661void Context::programUniformMatrix2fv(GLuint program,
5662 GLint location,
5663 GLsizei count,
5664 GLboolean transpose,
5665 const GLfloat *value)
5666{
5667 Program *programObject = getProgram(program);
5668 ASSERT(programObject);
5669 programObject->setUniformMatrix2fv(location, count, transpose, value);
5670}
5671
5672void Context::programUniformMatrix3fv(GLuint program,
5673 GLint location,
5674 GLsizei count,
5675 GLboolean transpose,
5676 const GLfloat *value)
5677{
5678 Program *programObject = getProgram(program);
5679 ASSERT(programObject);
5680 programObject->setUniformMatrix3fv(location, count, transpose, value);
5681}
5682
5683void Context::programUniformMatrix4fv(GLuint program,
5684 GLint location,
5685 GLsizei count,
5686 GLboolean transpose,
5687 const GLfloat *value)
5688{
5689 Program *programObject = getProgram(program);
5690 ASSERT(programObject);
5691 programObject->setUniformMatrix4fv(location, count, transpose, value);
5692}
5693
5694void Context::programUniformMatrix2x3fv(GLuint program,
5695 GLint location,
5696 GLsizei count,
5697 GLboolean transpose,
5698 const GLfloat *value)
5699{
5700 Program *programObject = getProgram(program);
5701 ASSERT(programObject);
5702 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5703}
5704
5705void Context::programUniformMatrix3x2fv(GLuint program,
5706 GLint location,
5707 GLsizei count,
5708 GLboolean transpose,
5709 const GLfloat *value)
5710{
5711 Program *programObject = getProgram(program);
5712 ASSERT(programObject);
5713 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5714}
5715
5716void Context::programUniformMatrix2x4fv(GLuint program,
5717 GLint location,
5718 GLsizei count,
5719 GLboolean transpose,
5720 const GLfloat *value)
5721{
5722 Program *programObject = getProgram(program);
5723 ASSERT(programObject);
5724 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5725}
5726
5727void Context::programUniformMatrix4x2fv(GLuint program,
5728 GLint location,
5729 GLsizei count,
5730 GLboolean transpose,
5731 const GLfloat *value)
5732{
5733 Program *programObject = getProgram(program);
5734 ASSERT(programObject);
5735 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5736}
5737
5738void Context::programUniformMatrix3x4fv(GLuint program,
5739 GLint location,
5740 GLsizei count,
5741 GLboolean transpose,
5742 const GLfloat *value)
5743{
5744 Program *programObject = getProgram(program);
5745 ASSERT(programObject);
5746 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5747}
5748
5749void Context::programUniformMatrix4x3fv(GLuint program,
5750 GLint location,
5751 GLsizei count,
5752 GLboolean transpose,
5753 const GLfloat *value)
5754{
5755 Program *programObject = getProgram(program);
5756 ASSERT(programObject);
5757 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5758}
5759
Jamie Madill81c2e252017-09-09 23:32:46 -04005760void Context::onTextureChange(const Texture *texture)
5761{
5762 // Conservatively assume all textures are dirty.
5763 // TODO(jmadill): More fine-grained update.
5764 mGLState.setObjectDirty(GL_TEXTURE);
5765}
5766
James Darpiniane8a93c62018-01-04 18:02:24 -08005767bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5768{
5769 return mGLState.isCurrentTransformFeedback(tf);
5770}
5771bool Context::isCurrentVertexArray(const VertexArray *va) const
5772{
5773 return mGLState.isCurrentVertexArray(va);
5774}
5775
Yunchao Hea336b902017-08-02 16:05:21 +08005776void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5777{
5778 for (int i = 0; i < count; i++)
5779 {
5780 pipelines[i] = createProgramPipeline();
5781 }
5782}
5783
5784void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5785{
5786 for (int i = 0; i < count; i++)
5787 {
5788 if (pipelines[i] != 0)
5789 {
5790 deleteProgramPipeline(pipelines[i]);
5791 }
5792 }
5793}
5794
5795GLboolean Context::isProgramPipeline(GLuint pipeline)
5796{
5797 if (pipeline == 0)
5798 {
5799 return GL_FALSE;
5800 }
5801
5802 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5803}
5804
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005805void Context::finishFenceNV(GLuint fence)
5806{
5807 FenceNV *fenceObject = getFenceNV(fence);
5808
5809 ASSERT(fenceObject && fenceObject->isSet());
5810 handleError(fenceObject->finish());
5811}
5812
5813void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5814{
5815 FenceNV *fenceObject = getFenceNV(fence);
5816
5817 ASSERT(fenceObject && fenceObject->isSet());
5818
5819 switch (pname)
5820 {
5821 case GL_FENCE_STATUS_NV:
5822 {
5823 // GL_NV_fence spec:
5824 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5825 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5826 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5827 GLboolean status = GL_TRUE;
5828 if (fenceObject->getStatus() != GL_TRUE)
5829 {
5830 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5831 }
5832 *params = status;
5833 break;
5834 }
5835
5836 case GL_FENCE_CONDITION_NV:
5837 {
5838 *params = static_cast<GLint>(fenceObject->getCondition());
5839 break;
5840 }
5841
5842 default:
5843 UNREACHABLE();
5844 }
5845}
5846
5847void Context::getTranslatedShaderSource(GLuint shader,
5848 GLsizei bufsize,
5849 GLsizei *length,
5850 GLchar *source)
5851{
5852 Shader *shaderObject = getShader(shader);
5853 ASSERT(shaderObject);
5854 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5855}
5856
5857void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5858{
5859 Program *programObject = getProgram(program);
5860 ASSERT(programObject);
5861
5862 programObject->getUniformfv(this, location, params);
5863}
5864
5865void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5866{
5867 Program *programObject = getProgram(program);
5868 ASSERT(programObject);
5869
5870 programObject->getUniformiv(this, location, params);
5871}
5872
5873GLboolean Context::isFenceNV(GLuint fence)
5874{
5875 FenceNV *fenceObject = getFenceNV(fence);
5876
5877 if (fenceObject == nullptr)
5878 {
5879 return GL_FALSE;
5880 }
5881
5882 // GL_NV_fence spec:
5883 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5884 // existing fence.
5885 return fenceObject->isSet();
5886}
5887
5888void Context::readnPixels(GLint x,
5889 GLint y,
5890 GLsizei width,
5891 GLsizei height,
5892 GLenum format,
5893 GLenum type,
5894 GLsizei bufSize,
5895 void *data)
5896{
5897 return readPixels(x, y, width, height, format, type, data);
5898}
5899
Jamie Madill007530e2017-12-28 14:27:04 -05005900void Context::setFenceNV(GLuint fence, GLenum condition)
5901{
5902 ASSERT(condition == GL_ALL_COMPLETED_NV);
5903
5904 FenceNV *fenceObject = getFenceNV(fence);
5905 ASSERT(fenceObject != nullptr);
5906 handleError(fenceObject->set(condition));
5907}
5908
5909GLboolean Context::testFenceNV(GLuint fence)
5910{
5911 FenceNV *fenceObject = getFenceNV(fence);
5912
5913 ASSERT(fenceObject != nullptr);
5914 ASSERT(fenceObject->isSet() == GL_TRUE);
5915
5916 GLboolean result = GL_TRUE;
5917 Error error = fenceObject->test(&result);
5918 if (error.isError())
5919 {
5920 handleError(error);
5921 return GL_TRUE;
5922 }
5923
5924 return result;
5925}
5926
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005927void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005928{
5929 Texture *texture = getTargetTexture(target);
5930 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005931 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005932}
5933
Jamie Madillfa920eb2018-01-04 11:45:50 -05005934void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005935{
5936 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5937 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5938 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5939}
5940
Jamie Madillfa920eb2018-01-04 11:45:50 -05005941void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5942{
5943 UNIMPLEMENTED();
5944}
5945
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005946void Context::alphaFunc(GLenum func, GLfloat ref)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::alphaFuncx(GLenum func, GLfixed ref)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::clearDepthx(GLfixed depth)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::clientActiveTexture(GLenum texture)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::cullFace(GLenum mode)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::depthRangex(GLfixed n, GLfixed f)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::disableClientState(GLenum array)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::enableClientState(GLenum array)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::fogf(GLenum pname, GLfloat param)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::fogfv(GLenum pname, const GLfloat *params)
6027{
6028 UNIMPLEMENTED();
6029}
6030
6031void Context::fogx(GLenum pname, GLfixed param)
6032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::fogxv(GLenum pname, const GLfixed *param)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::getFixedv(GLenum pname, GLfixed *params)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6082{
6083 UNIMPLEMENTED();
6084}
6085
6086void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6092{
6093 UNIMPLEMENTED();
6094}
6095
6096void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6102{
6103 UNIMPLEMENTED();
6104}
6105
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006106void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::lightModelf(GLenum pname, GLfloat param)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::lightModelfv(GLenum pname, const GLfloat *params)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::lightModelx(GLenum pname, GLfixed param)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::lightModelxv(GLenum pname, const GLfixed *param)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::lineWidthx(GLfixed width)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::loadIdentity()
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::loadMatrixf(const GLfloat *m)
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::loadMatrixx(const GLfixed *m)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::logicOp(GLenum opcode)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::matrixMode(GLenum mode)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::multMatrixf(const GLfloat *m)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::multMatrixx(const GLfixed *m)
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::pointParameterf(GLenum pname, GLfloat param)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::pointParameterx(GLenum pname, GLfixed param)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::pointSize(GLfloat size)
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::pointSizex(GLfixed size)
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6277{
6278 UNIMPLEMENTED();
6279}
6280
6281void Context::popMatrix()
6282{
6283 UNIMPLEMENTED();
6284}
6285
6286void Context::pushMatrix()
6287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::shadeModel(GLenum mode)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6322{
6323 UNIMPLEMENTED();
6324}
6325
6326void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6327{
6328 UNIMPLEMENTED();
6329}
6330
6331void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6332{
6333 UNIMPLEMENTED();
6334}
6335
6336void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6337{
6338 UNIMPLEMENTED();
6339}
6340
6341void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6342{
6343 UNIMPLEMENTED();
6344}
6345
6346void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6347{
6348 UNIMPLEMENTED();
6349}
6350
6351void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6352{
6353 UNIMPLEMENTED();
6354}
6355
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006356void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006357{
6358 UNIMPLEMENTED();
6359}
6360
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006361void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006362{
6363 UNIMPLEMENTED();
6364}
6365
6366void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6367{
6368 UNIMPLEMENTED();
6369}
6370
6371void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6372{
6373 UNIMPLEMENTED();
6374}
6375
6376void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6377{
6378 UNIMPLEMENTED();
6379}
6380
6381void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6382{
6383 UNIMPLEMENTED();
6384}
6385
6386void Context::drawTexfv(const GLfloat *coords)
6387{
6388 UNIMPLEMENTED();
6389}
6390
6391void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6392{
6393 UNIMPLEMENTED();
6394}
6395
6396void Context::drawTexiv(const GLint *coords)
6397{
6398 UNIMPLEMENTED();
6399}
6400
6401void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6402{
6403 UNIMPLEMENTED();
6404}
6405
6406void Context::drawTexsv(const GLshort *coords)
6407{
6408 UNIMPLEMENTED();
6409}
6410
6411void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6412{
6413 UNIMPLEMENTED();
6414}
6415
6416void Context::drawTexxv(const GLfixed *coords)
6417{
6418 UNIMPLEMENTED();
6419}
6420
6421void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6422{
6423 UNIMPLEMENTED();
6424}
6425
6426void Context::loadPaletteFromModelViewMatrix()
6427{
6428 UNIMPLEMENTED();
6429}
6430
6431void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6432{
6433 UNIMPLEMENTED();
6434}
6435
6436void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6437{
6438 UNIMPLEMENTED();
6439}
6440
6441void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6442{
6443 UNIMPLEMENTED();
6444}
6445
6446GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6447{
6448 UNIMPLEMENTED();
6449 return 0;
6450}
6451
Jamie Madill5b772312018-03-08 20:28:32 -05006452bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6453{
6454 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6455 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6456 // to the fact that it is stored internally as a float, and so would require conversion
6457 // if returned from Context::getIntegerv. Since this conversion is already implemented
6458 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6459 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6460 // application.
6461 switch (pname)
6462 {
6463 case GL_COMPRESSED_TEXTURE_FORMATS:
6464 {
6465 *type = GL_INT;
6466 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6467 return true;
6468 }
6469 case GL_SHADER_BINARY_FORMATS:
6470 {
6471 *type = GL_INT;
6472 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6473 return true;
6474 }
6475
6476 case GL_MAX_VERTEX_ATTRIBS:
6477 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6478 case GL_MAX_VARYING_VECTORS:
6479 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6480 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6481 case GL_MAX_TEXTURE_IMAGE_UNITS:
6482 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6483 case GL_MAX_RENDERBUFFER_SIZE:
6484 case GL_NUM_SHADER_BINARY_FORMATS:
6485 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6486 case GL_ARRAY_BUFFER_BINDING:
6487 case GL_FRAMEBUFFER_BINDING:
6488 case GL_RENDERBUFFER_BINDING:
6489 case GL_CURRENT_PROGRAM:
6490 case GL_PACK_ALIGNMENT:
6491 case GL_UNPACK_ALIGNMENT:
6492 case GL_GENERATE_MIPMAP_HINT:
6493 case GL_RED_BITS:
6494 case GL_GREEN_BITS:
6495 case GL_BLUE_BITS:
6496 case GL_ALPHA_BITS:
6497 case GL_DEPTH_BITS:
6498 case GL_STENCIL_BITS:
6499 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6500 case GL_CULL_FACE_MODE:
6501 case GL_FRONT_FACE:
6502 case GL_ACTIVE_TEXTURE:
6503 case GL_STENCIL_FUNC:
6504 case GL_STENCIL_VALUE_MASK:
6505 case GL_STENCIL_REF:
6506 case GL_STENCIL_FAIL:
6507 case GL_STENCIL_PASS_DEPTH_FAIL:
6508 case GL_STENCIL_PASS_DEPTH_PASS:
6509 case GL_STENCIL_BACK_FUNC:
6510 case GL_STENCIL_BACK_VALUE_MASK:
6511 case GL_STENCIL_BACK_REF:
6512 case GL_STENCIL_BACK_FAIL:
6513 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6514 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6515 case GL_DEPTH_FUNC:
6516 case GL_BLEND_SRC_RGB:
6517 case GL_BLEND_SRC_ALPHA:
6518 case GL_BLEND_DST_RGB:
6519 case GL_BLEND_DST_ALPHA:
6520 case GL_BLEND_EQUATION_RGB:
6521 case GL_BLEND_EQUATION_ALPHA:
6522 case GL_STENCIL_WRITEMASK:
6523 case GL_STENCIL_BACK_WRITEMASK:
6524 case GL_STENCIL_CLEAR_VALUE:
6525 case GL_SUBPIXEL_BITS:
6526 case GL_MAX_TEXTURE_SIZE:
6527 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6528 case GL_SAMPLE_BUFFERS:
6529 case GL_SAMPLES:
6530 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6531 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6532 case GL_TEXTURE_BINDING_2D:
6533 case GL_TEXTURE_BINDING_CUBE_MAP:
6534 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6535 {
6536 *type = GL_INT;
6537 *numParams = 1;
6538 return true;
6539 }
6540 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6541 {
6542 if (!getExtensions().packReverseRowOrder)
6543 {
6544 return false;
6545 }
6546 *type = GL_INT;
6547 *numParams = 1;
6548 return true;
6549 }
6550 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6551 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6552 {
6553 if (!getExtensions().textureRectangle)
6554 {
6555 return false;
6556 }
6557 *type = GL_INT;
6558 *numParams = 1;
6559 return true;
6560 }
6561 case GL_MAX_DRAW_BUFFERS_EXT:
6562 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6563 {
6564 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6565 {
6566 return false;
6567 }
6568 *type = GL_INT;
6569 *numParams = 1;
6570 return true;
6571 }
6572 case GL_MAX_VIEWPORT_DIMS:
6573 {
6574 *type = GL_INT;
6575 *numParams = 2;
6576 return true;
6577 }
6578 case GL_VIEWPORT:
6579 case GL_SCISSOR_BOX:
6580 {
6581 *type = GL_INT;
6582 *numParams = 4;
6583 return true;
6584 }
6585 case GL_SHADER_COMPILER:
6586 case GL_SAMPLE_COVERAGE_INVERT:
6587 case GL_DEPTH_WRITEMASK:
6588 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6589 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6590 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6591 // bool-natural
6592 case GL_SAMPLE_COVERAGE:
6593 case GL_SCISSOR_TEST:
6594 case GL_STENCIL_TEST:
6595 case GL_DEPTH_TEST:
6596 case GL_BLEND:
6597 case GL_DITHER:
6598 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6599 {
6600 *type = GL_BOOL;
6601 *numParams = 1;
6602 return true;
6603 }
6604 case GL_COLOR_WRITEMASK:
6605 {
6606 *type = GL_BOOL;
6607 *numParams = 4;
6608 return true;
6609 }
6610 case GL_POLYGON_OFFSET_FACTOR:
6611 case GL_POLYGON_OFFSET_UNITS:
6612 case GL_SAMPLE_COVERAGE_VALUE:
6613 case GL_DEPTH_CLEAR_VALUE:
6614 case GL_LINE_WIDTH:
6615 {
6616 *type = GL_FLOAT;
6617 *numParams = 1;
6618 return true;
6619 }
6620 case GL_ALIASED_LINE_WIDTH_RANGE:
6621 case GL_ALIASED_POINT_SIZE_RANGE:
6622 case GL_DEPTH_RANGE:
6623 {
6624 *type = GL_FLOAT;
6625 *numParams = 2;
6626 return true;
6627 }
6628 case GL_COLOR_CLEAR_VALUE:
6629 case GL_BLEND_COLOR:
6630 {
6631 *type = GL_FLOAT;
6632 *numParams = 4;
6633 return true;
6634 }
6635 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6636 if (!getExtensions().textureFilterAnisotropic)
6637 {
6638 return false;
6639 }
6640 *type = GL_FLOAT;
6641 *numParams = 1;
6642 return true;
6643 case GL_TIMESTAMP_EXT:
6644 if (!getExtensions().disjointTimerQuery)
6645 {
6646 return false;
6647 }
6648 *type = GL_INT_64_ANGLEX;
6649 *numParams = 1;
6650 return true;
6651 case GL_GPU_DISJOINT_EXT:
6652 if (!getExtensions().disjointTimerQuery)
6653 {
6654 return false;
6655 }
6656 *type = GL_INT;
6657 *numParams = 1;
6658 return true;
6659 case GL_COVERAGE_MODULATION_CHROMIUM:
6660 if (!getExtensions().framebufferMixedSamples)
6661 {
6662 return false;
6663 }
6664 *type = GL_INT;
6665 *numParams = 1;
6666 return true;
6667 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6668 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6669 {
6670 return false;
6671 }
6672 *type = GL_INT;
6673 *numParams = 1;
6674 return true;
6675 }
6676
6677 if (getExtensions().debug)
6678 {
6679 switch (pname)
6680 {
6681 case GL_DEBUG_LOGGED_MESSAGES:
6682 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6683 case GL_DEBUG_GROUP_STACK_DEPTH:
6684 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6685 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6686 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6687 case GL_MAX_LABEL_LENGTH:
6688 *type = GL_INT;
6689 *numParams = 1;
6690 return true;
6691
6692 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6693 case GL_DEBUG_OUTPUT:
6694 *type = GL_BOOL;
6695 *numParams = 1;
6696 return true;
6697 }
6698 }
6699
6700 if (getExtensions().multisampleCompatibility)
6701 {
6702 switch (pname)
6703 {
6704 case GL_MULTISAMPLE_EXT:
6705 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6706 *type = GL_BOOL;
6707 *numParams = 1;
6708 return true;
6709 }
6710 }
6711
6712 if (getExtensions().pathRendering)
6713 {
6714 switch (pname)
6715 {
6716 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6717 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6718 *type = GL_FLOAT;
6719 *numParams = 16;
6720 return true;
6721 }
6722 }
6723
6724 if (getExtensions().bindGeneratesResource)
6725 {
6726 switch (pname)
6727 {
6728 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6729 *type = GL_BOOL;
6730 *numParams = 1;
6731 return true;
6732 }
6733 }
6734
6735 if (getExtensions().clientArrays)
6736 {
6737 switch (pname)
6738 {
6739 case GL_CLIENT_ARRAYS_ANGLE:
6740 *type = GL_BOOL;
6741 *numParams = 1;
6742 return true;
6743 }
6744 }
6745
6746 if (getExtensions().sRGBWriteControl)
6747 {
6748 switch (pname)
6749 {
6750 case GL_FRAMEBUFFER_SRGB_EXT:
6751 *type = GL_BOOL;
6752 *numParams = 1;
6753 return true;
6754 }
6755 }
6756
6757 if (getExtensions().robustResourceInitialization &&
6758 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6759 {
6760 *type = GL_BOOL;
6761 *numParams = 1;
6762 return true;
6763 }
6764
6765 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6766 {
6767 *type = GL_BOOL;
6768 *numParams = 1;
6769 return true;
6770 }
6771
6772 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6773 switch (pname)
6774 {
6775 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6776 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6777 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6778 {
6779 return false;
6780 }
6781 *type = GL_INT;
6782 *numParams = 1;
6783 return true;
6784
6785 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6786 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6787 {
6788 return false;
6789 }
6790 *type = GL_INT;
6791 *numParams = 1;
6792 return true;
6793
6794 case GL_PROGRAM_BINARY_FORMATS_OES:
6795 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6796 {
6797 return false;
6798 }
6799 *type = GL_INT;
6800 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6801 return true;
6802
6803 case GL_PACK_ROW_LENGTH:
6804 case GL_PACK_SKIP_ROWS:
6805 case GL_PACK_SKIP_PIXELS:
6806 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6807 {
6808 return false;
6809 }
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 case GL_UNPACK_ROW_LENGTH:
6814 case GL_UNPACK_SKIP_ROWS:
6815 case GL_UNPACK_SKIP_PIXELS:
6816 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT;
6821 *numParams = 1;
6822 return true;
6823 case GL_VERTEX_ARRAY_BINDING:
6824 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT;
6829 *numParams = 1;
6830 return true;
6831 case GL_PIXEL_PACK_BUFFER_BINDING:
6832 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6833 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6834 {
6835 return false;
6836 }
6837 *type = GL_INT;
6838 *numParams = 1;
6839 return true;
6840 case GL_MAX_SAMPLES:
6841 {
6842 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6843 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6844 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6845 {
6846 return false;
6847 }
6848 *type = GL_INT;
6849 *numParams = 1;
6850 return true;
6851
6852 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6853 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6854 {
6855 return false;
6856 }
6857 *type = GL_INT;
6858 *numParams = 1;
6859 return true;
6860 }
6861 }
6862
6863 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6864 {
6865 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6866 {
6867 return false;
6868 }
6869 *type = GL_INT;
6870 *numParams = 1;
6871 return true;
6872 }
6873
6874 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6875 {
6876 *type = GL_INT;
6877 *numParams = 1;
6878 return true;
6879 }
6880
6881 if (getClientVersion() < Version(3, 0))
6882 {
6883 return false;
6884 }
6885
6886 // Check for ES3.0+ parameter names
6887 switch (pname)
6888 {
6889 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6890 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6891 case GL_UNIFORM_BUFFER_BINDING:
6892 case GL_TRANSFORM_FEEDBACK_BINDING:
6893 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6894 case GL_COPY_READ_BUFFER_BINDING:
6895 case GL_COPY_WRITE_BUFFER_BINDING:
6896 case GL_SAMPLER_BINDING:
6897 case GL_READ_BUFFER:
6898 case GL_TEXTURE_BINDING_3D:
6899 case GL_TEXTURE_BINDING_2D_ARRAY:
6900 case GL_MAX_3D_TEXTURE_SIZE:
6901 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6902 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6903 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6904 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6905 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6906 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6907 case GL_MAX_VARYING_COMPONENTS:
6908 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6909 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6910 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6911 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6912 case GL_NUM_EXTENSIONS:
6913 case GL_MAJOR_VERSION:
6914 case GL_MINOR_VERSION:
6915 case GL_MAX_ELEMENTS_INDICES:
6916 case GL_MAX_ELEMENTS_VERTICES:
6917 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6918 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6919 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6920 case GL_UNPACK_IMAGE_HEIGHT:
6921 case GL_UNPACK_SKIP_IMAGES:
6922 {
6923 *type = GL_INT;
6924 *numParams = 1;
6925 return true;
6926 }
6927
6928 case GL_MAX_ELEMENT_INDEX:
6929 case GL_MAX_UNIFORM_BLOCK_SIZE:
6930 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6931 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6932 case GL_MAX_SERVER_WAIT_TIMEOUT:
6933 {
6934 *type = GL_INT_64_ANGLEX;
6935 *numParams = 1;
6936 return true;
6937 }
6938
6939 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6940 case GL_TRANSFORM_FEEDBACK_PAUSED:
6941 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6942 case GL_RASTERIZER_DISCARD:
6943 {
6944 *type = GL_BOOL;
6945 *numParams = 1;
6946 return true;
6947 }
6948
6949 case GL_MAX_TEXTURE_LOD_BIAS:
6950 {
6951 *type = GL_FLOAT;
6952 *numParams = 1;
6953 return true;
6954 }
6955 }
6956
6957 if (getExtensions().requestExtension)
6958 {
6959 switch (pname)
6960 {
6961 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965 }
6966 }
6967
6968 if (getClientVersion() < Version(3, 1))
6969 {
6970 return false;
6971 }
6972
6973 switch (pname)
6974 {
6975 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6976 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6977 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6978 case GL_MAX_FRAMEBUFFER_WIDTH:
6979 case GL_MAX_FRAMEBUFFER_HEIGHT:
6980 case GL_MAX_FRAMEBUFFER_SAMPLES:
6981 case GL_MAX_SAMPLE_MASK_WORDS:
6982 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6983 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6984 case GL_MAX_INTEGER_SAMPLES:
6985 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6986 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6987 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6988 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6989 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6990 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6991 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6992 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6993 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6994 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6995 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6996 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6997 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6998 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6999 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7000 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7001 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7002 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7003 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7004 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7005 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7006 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7007 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7008 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7009 case GL_MAX_UNIFORM_LOCATIONS:
7010 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7011 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7012 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7013 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7014 case GL_MAX_IMAGE_UNITS:
7015 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7016 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7017 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7018 case GL_SHADER_STORAGE_BUFFER_BINDING:
7019 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7020 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7021 *type = GL_INT;
7022 *numParams = 1;
7023 return true;
7024 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7025 *type = GL_INT_64_ANGLEX;
7026 *numParams = 1;
7027 return true;
7028 case GL_SAMPLE_MASK:
7029 *type = GL_BOOL;
7030 *numParams = 1;
7031 return true;
7032 }
7033
7034 if (getExtensions().geometryShader)
7035 {
7036 switch (pname)
7037 {
7038 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7039 case GL_LAYER_PROVOKING_VERTEX_EXT:
7040 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7041 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7042 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7043 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7044 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7045 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7046 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7047 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7048 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7049 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7050 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7051 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7052 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7053 *type = GL_INT;
7054 *numParams = 1;
7055 return true;
7056 }
7057 }
7058
7059 return false;
7060}
7061
7062bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7063{
7064 if (getClientVersion() < Version(3, 0))
7065 {
7066 return false;
7067 }
7068
7069 switch (target)
7070 {
7071 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7072 case GL_UNIFORM_BUFFER_BINDING:
7073 {
7074 *type = GL_INT;
7075 *numParams = 1;
7076 return true;
7077 }
7078 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7079 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7080 case GL_UNIFORM_BUFFER_START:
7081 case GL_UNIFORM_BUFFER_SIZE:
7082 {
7083 *type = GL_INT_64_ANGLEX;
7084 *numParams = 1;
7085 return true;
7086 }
7087 }
7088
7089 if (getClientVersion() < Version(3, 1))
7090 {
7091 return false;
7092 }
7093
7094 switch (target)
7095 {
7096 case GL_IMAGE_BINDING_LAYERED:
7097 {
7098 *type = GL_BOOL;
7099 *numParams = 1;
7100 return true;
7101 }
7102 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7103 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7104 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7105 case GL_SHADER_STORAGE_BUFFER_BINDING:
7106 case GL_VERTEX_BINDING_BUFFER:
7107 case GL_VERTEX_BINDING_DIVISOR:
7108 case GL_VERTEX_BINDING_OFFSET:
7109 case GL_VERTEX_BINDING_STRIDE:
7110 case GL_SAMPLE_MASK_VALUE:
7111 case GL_IMAGE_BINDING_NAME:
7112 case GL_IMAGE_BINDING_LEVEL:
7113 case GL_IMAGE_BINDING_LAYER:
7114 case GL_IMAGE_BINDING_ACCESS:
7115 case GL_IMAGE_BINDING_FORMAT:
7116 {
7117 *type = GL_INT;
7118 *numParams = 1;
7119 return true;
7120 }
7121 case GL_ATOMIC_COUNTER_BUFFER_START:
7122 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7123 case GL_SHADER_STORAGE_BUFFER_START:
7124 case GL_SHADER_STORAGE_BUFFER_SIZE:
7125 {
7126 *type = GL_INT_64_ANGLEX;
7127 *numParams = 1;
7128 return true;
7129 }
7130 }
7131
7132 return false;
7133}
7134
7135Program *Context::getProgram(GLuint handle) const
7136{
7137 return mState.mShaderPrograms->getProgram(handle);
7138}
7139
7140Shader *Context::getShader(GLuint handle) const
7141{
7142 return mState.mShaderPrograms->getShader(handle);
7143}
7144
7145bool Context::isTextureGenerated(GLuint texture) const
7146{
7147 return mState.mTextures->isHandleGenerated(texture);
7148}
7149
7150bool Context::isBufferGenerated(GLuint buffer) const
7151{
7152 return mState.mBuffers->isHandleGenerated(buffer);
7153}
7154
7155bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7156{
7157 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7158}
7159
7160bool Context::isFramebufferGenerated(GLuint framebuffer) const
7161{
7162 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7163}
7164
7165bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7166{
7167 return mState.mPipelines->isHandleGenerated(pipeline);
7168}
7169
7170bool Context::usingDisplayTextureShareGroup() const
7171{
7172 return mDisplayTextureShareGroup;
7173}
7174
7175GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7176{
7177 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7178 internalformat == GL_DEPTH_STENCIL
7179 ? GL_DEPTH24_STENCIL8
7180 : internalformat;
7181}
7182
Jamie Madillc29968b2016-01-20 11:17:23 -05007183} // namespace gl