blob: 71ac7c3f42924d7c4659f3d3a759059780166b15 [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);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800434 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800435
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400436 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437}
438
Jamie Madill4928b7c2017-06-20 12:57:39 -0400439egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440{
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000442 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400443 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400445 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446
Corentin Wallez80b24112015-08-25 16:41:57 -0400447 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000448 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400449 if (query.second != nullptr)
450 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400451 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400452 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000453 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400454 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400457 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400458 if (vertexArray.second)
459 {
460 vertexArray.second->onDestroy(this);
461 }
Jamie Madill57a89722013-07-02 11:57:03 -0400462 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400463 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400464
Corentin Wallez80b24112015-08-25 16:41:57 -0400465 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500466 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500467 if (transformFeedback.second != nullptr)
468 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500469 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500470 }
Geoff Langc8058452014-02-03 12:04:11 -0500471 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400472 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500473
Jamie Madill5b772312018-03-08 20:28:32 -0500474 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400475 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800476 if (zeroTexture.get() != nullptr)
477 {
478 ANGLE_TRY(zeroTexture->onDestroy(this));
479 zeroTexture.set(this, nullptr);
480 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400481 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000482
Corentin Wallezccab69d2017-01-27 16:57:15 -0500483 SafeDelete(mSurfacelessFramebuffer);
484
Jamie Madill4928b7c2017-06-20 12:57:39 -0400485 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400486 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500487
Jamie Madill4928b7c2017-06-20 12:57:39 -0400488 mGLState.reset(this);
489
Jamie Madill6c1f6712017-02-14 19:08:04 -0500490 mState.mBuffers->release(this);
491 mState.mShaderPrograms->release(this);
492 mState.mTextures->release(this);
493 mState.mRenderbuffers->release(this);
494 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400495 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500496 mState.mPaths->release(this);
497 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800498 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400499
Jamie Madill76e471e2017-10-21 09:56:01 -0400500 mImplementation->onDestroy(this);
501
Jamie Madill4928b7c2017-06-20 12:57:39 -0400502 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503}
504
Jamie Madill70ee0f62017-02-06 16:04:20 -0500505Context::~Context()
506{
507}
508
Jamie Madill4928b7c2017-06-20 12:57:39 -0400509egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510{
Jamie Madill61e16b42017-06-19 11:13:23 -0400511 mCurrentDisplay = display;
512
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513 if (!mHasBeenCurrent)
514 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500516 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400517 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000518
Corentin Wallezc295e512017-01-27 17:47:50 -0500519 int width = 0;
520 int height = 0;
521 if (surface != nullptr)
522 {
523 width = surface->getWidth();
524 height = surface->getHeight();
525 }
526
527 mGLState.setViewportParams(0, 0, width, height);
528 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000529
530 mHasBeenCurrent = true;
531 }
532
Jamie Madill1b94d432015-08-07 13:23:23 -0400533 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700534 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400535 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400536
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500538
539 Framebuffer *newDefault = nullptr;
540 if (surface != nullptr)
541 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400542 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500543 mCurrentSurface = surface;
544 newDefault = surface->getDefaultFramebuffer();
545 }
546 else
547 {
548 if (mSurfacelessFramebuffer == nullptr)
549 {
550 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
551 }
552
553 newDefault = mSurfacelessFramebuffer;
554 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000555
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 // Update default framebuffer, the binding of the previous default
557 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400558 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700559 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700561 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700563 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400564 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700565 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400566 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500567 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400568 }
Ian Ewell292f0052016-02-04 10:37:32 -0500569
570 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571 mImplementation->onMakeCurrent(this);
572 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000573}
574
Jamie Madill4928b7c2017-06-20 12:57:39 -0400575egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400576{
Corentin Wallez37c39792015-08-20 14:19:46 -0400577 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500578 Framebuffer *currentDefault = nullptr;
579 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400580 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500581 currentDefault = mCurrentSurface->getDefaultFramebuffer();
582 }
583 else if (mSurfacelessFramebuffer != nullptr)
584 {
585 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400586 }
587
Corentin Wallezc295e512017-01-27 17:47:50 -0500588 if (mGLState.getReadFramebuffer() == currentDefault)
589 {
590 mGLState.setReadFramebufferBinding(nullptr);
591 }
592 if (mGLState.getDrawFramebuffer() == currentDefault)
593 {
594 mGLState.setDrawFramebufferBinding(nullptr);
595 }
596 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
597
598 if (mCurrentSurface)
599 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400600 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500601 mCurrentSurface = nullptr;
602 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400603
604 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400605}
606
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607GLuint Context::createBuffer()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
612GLuint Context::createProgram()
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
617GLuint Context::createShader(GLenum type)
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620}
621
622GLuint Context::createTexture()
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625}
626
627GLuint Context::createRenderbuffer()
628{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500629 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630}
631
Sami Väisänene45e53b2016-05-25 10:36:04 +0300632GLuint Context::createPaths(GLsizei range)
633{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500634 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300635 if (resultOrError.isError())
636 {
637 handleError(resultOrError.getError());
638 return 0;
639 }
640 return resultOrError.getResult();
641}
642
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643// Returns an unused framebuffer name
644GLuint Context::createFramebuffer()
645{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500646 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000647}
648
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500649void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500651 for (int i = 0; i < n; i++)
652 {
653 GLuint handle = mFenceNVHandleAllocator.allocate();
654 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
655 fences[i] = handle;
656 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657}
658
Yunchao Hea336b902017-08-02 16:05:21 +0800659GLuint Context::createProgramPipeline()
660{
661 return mState.mPipelines->createProgramPipeline();
662}
663
Jiajia Qin5451d532017-11-16 17:16:34 +0800664GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
665{
666 UNIMPLEMENTED();
667 return 0u;
668}
669
James Darpinian4d9d4832018-03-13 12:43:28 -0700670void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671{
James Darpinian4d9d4832018-03-13 12:43:28 -0700672 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
673 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674 {
675 detachBuffer(buffer);
676 }
Jamie Madill893ab082014-05-16 16:56:10 -0400677
James Darpinian4d9d4832018-03-13 12:43:28 -0700678 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteShader(GLuint shader)
682{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500683 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686void Context::deleteProgram(GLuint program)
687{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691void Context::deleteTexture(GLuint texture)
692{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500693 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694 {
695 detachTexture(texture);
696 }
697
Jamie Madill6c1f6712017-02-14 19:08:04 -0500698 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699}
700
701void Context::deleteRenderbuffer(GLuint renderbuffer)
702{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500703 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704 {
705 detachRenderbuffer(renderbuffer);
706 }
Jamie Madill893ab082014-05-16 16:56:10 -0400707
Jamie Madill6c1f6712017-02-14 19:08:04 -0500708 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000709}
710
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400711void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400712{
713 // The spec specifies the underlying Fence object is not deleted until all current
714 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
715 // and since our API is currently designed for being called from a single thread, we can delete
716 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400717 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400718}
719
Yunchao Hea336b902017-08-02 16:05:21 +0800720void Context::deleteProgramPipeline(GLuint pipeline)
721{
722 if (mState.mPipelines->getProgramPipeline(pipeline))
723 {
724 detachProgramPipeline(pipeline);
725 }
726
727 mState.mPipelines->deleteObject(this, pipeline);
728}
729
Sami Väisänene45e53b2016-05-25 10:36:04 +0300730void Context::deletePaths(GLuint first, GLsizei range)
731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300733}
734
735bool Context::hasPathData(GLuint path) const
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738 if (pathObj == nullptr)
739 return false;
740
741 return pathObj->hasPathData();
742}
743
744bool Context::hasPath(GLuint path) const
745{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500746 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747}
748
749void Context::setPathCommands(GLuint path,
750 GLsizei numCommands,
751 const GLubyte *commands,
752 GLsizei numCoords,
753 GLenum coordType,
754 const void *coords)
755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757
758 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
759}
760
Jamie Madill007530e2017-12-28 14:27:04 -0500761void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300762{
Jamie Madill007530e2017-12-28 14:27:04 -0500763 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300764
765 switch (pname)
766 {
767 case GL_PATH_STROKE_WIDTH_CHROMIUM:
768 pathObj->setStrokeWidth(value);
769 break;
770 case GL_PATH_END_CAPS_CHROMIUM:
771 pathObj->setEndCaps(static_cast<GLenum>(value));
772 break;
773 case GL_PATH_JOIN_STYLE_CHROMIUM:
774 pathObj->setJoinStyle(static_cast<GLenum>(value));
775 break;
776 case GL_PATH_MITER_LIMIT_CHROMIUM:
777 pathObj->setMiterLimit(value);
778 break;
779 case GL_PATH_STROKE_BOUND_CHROMIUM:
780 pathObj->setStrokeBound(value);
781 break;
782 default:
783 UNREACHABLE();
784 break;
785 }
786}
787
Jamie Madill007530e2017-12-28 14:27:04 -0500788void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300789{
Jamie Madill007530e2017-12-28 14:27:04 -0500790 // TODO(jmadill): Should use proper clamping/casting.
791 pathParameterf(path, pname, static_cast<GLfloat>(value));
792}
793
794void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
795{
796 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797
798 switch (pname)
799 {
800 case GL_PATH_STROKE_WIDTH_CHROMIUM:
801 *value = pathObj->getStrokeWidth();
802 break;
803 case GL_PATH_END_CAPS_CHROMIUM:
804 *value = static_cast<GLfloat>(pathObj->getEndCaps());
805 break;
806 case GL_PATH_JOIN_STYLE_CHROMIUM:
807 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
808 break;
809 case GL_PATH_MITER_LIMIT_CHROMIUM:
810 *value = pathObj->getMiterLimit();
811 break;
812 case GL_PATH_STROKE_BOUND_CHROMIUM:
813 *value = pathObj->getStrokeBound();
814 break;
815 default:
816 UNREACHABLE();
817 break;
818 }
819}
820
Jamie Madill007530e2017-12-28 14:27:04 -0500821void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
822{
823 GLfloat val = 0.0f;
824 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
825 if (value)
826 *value = static_cast<GLint>(val);
827}
828
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
830{
831 mGLState.setPathStencilFunc(func, ref, mask);
832}
833
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834void Context::deleteFramebuffer(GLuint framebuffer)
835{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500836 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 {
838 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000839 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500840
Jamie Madill6c1f6712017-02-14 19:08:04 -0500841 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842}
843
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500844void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500846 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500848 GLuint fence = fences[i];
849
850 FenceNV *fenceObject = nullptr;
851 if (mFenceNVMap.erase(fence, &fenceObject))
852 {
853 mFenceNVHandleAllocator.release(fence);
854 delete fenceObject;
855 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856 }
857}
858
Geoff Lang70d0f492015-12-10 17:45:46 -0500859Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Jamie Madill570f7c82014-07-03 10:38:54 -0400864Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867}
868
Geoff Lang70d0f492015-12-10 17:45:46 -0500869Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500871 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872}
873
Jamie Madill70b5bb02017-08-28 13:32:37 -0400874Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400875{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400876 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400877}
878
Jamie Madill57a89722013-07-02 11:57:03 -0400879VertexArray *Context::getVertexArray(GLuint handle) const
880{
Jamie Madill96a483b2017-06-27 16:49:21 -0400881 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400882}
883
Jamie Madilldc356042013-07-19 16:36:57 -0400884Sampler *Context::getSampler(GLuint handle) const
885{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500886 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400887}
888
Geoff Langc8058452014-02-03 12:04:11 -0500889TransformFeedback *Context::getTransformFeedback(GLuint handle) const
890{
Jamie Madill96a483b2017-06-27 16:49:21 -0400891 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500892}
893
Yunchao Hea336b902017-08-02 16:05:21 +0800894ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
895{
896 return mState.mPipelines->getProgramPipeline(handle);
897}
898
Geoff Lang70d0f492015-12-10 17:45:46 -0500899LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
900{
901 switch (identifier)
902 {
903 case GL_BUFFER:
904 return getBuffer(name);
905 case GL_SHADER:
906 return getShader(name);
907 case GL_PROGRAM:
908 return getProgram(name);
909 case GL_VERTEX_ARRAY:
910 return getVertexArray(name);
911 case GL_QUERY:
912 return getQuery(name);
913 case GL_TRANSFORM_FEEDBACK:
914 return getTransformFeedback(name);
915 case GL_SAMPLER:
916 return getSampler(name);
917 case GL_TEXTURE:
918 return getTexture(name);
919 case GL_RENDERBUFFER:
920 return getRenderbuffer(name);
921 case GL_FRAMEBUFFER:
922 return getFramebuffer(name);
923 default:
924 UNREACHABLE();
925 return nullptr;
926 }
927}
928
929LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
930{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400931 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500932}
933
Martin Radev9d901792016-07-15 15:58:58 +0300934void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
935{
936 LabeledObject *object = getLabeledObject(identifier, name);
937 ASSERT(object != nullptr);
938
939 std::string labelName = GetObjectLabelFromPointer(length, label);
940 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400941
942 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
943 // specified object is active until we do this.
944 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300945}
946
947void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
948{
949 LabeledObject *object = getLabeledObjectFromPtr(ptr);
950 ASSERT(object != nullptr);
951
952 std::string labelName = GetObjectLabelFromPointer(length, label);
953 object->setLabel(labelName);
954}
955
956void Context::getObjectLabel(GLenum identifier,
957 GLuint name,
958 GLsizei bufSize,
959 GLsizei *length,
960 GLchar *label) const
961{
962 LabeledObject *object = getLabeledObject(identifier, name);
963 ASSERT(object != nullptr);
964
965 const std::string &objectLabel = object->getLabel();
966 GetObjectLabelBase(objectLabel, bufSize, length, label);
967}
968
969void Context::getObjectPtrLabel(const void *ptr,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObjectFromPtr(ptr);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
Jamie Madilldc356042013-07-19 16:36:57 -0400981bool Context::isSampler(GLuint samplerName) const
982{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400984}
985
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800986void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500988 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989
Jamie Madilldedd7b92014-11-05 16:30:36 -0500990 if (handle == 0)
991 {
992 texture = mZeroTextures[target].get();
993 }
994 else
995 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500996 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500997 }
998
999 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001000 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001001}
1002
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001003void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001005 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1006 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001007 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008}
1009
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001010void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001012 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1013 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001014 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001015}
1016
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001017void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001018{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001019 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001020 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001021}
1022
Shao80957d92017-02-20 21:25:59 +08001023void Context::bindVertexBuffer(GLuint bindingIndex,
1024 GLuint bufferHandle,
1025 GLintptr offset,
1026 GLsizei stride)
1027{
1028 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001029 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001030}
1031
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001032void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001033{
Geoff Lang76b10c92014-09-05 16:28:14 -04001034 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001035 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001036 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001037 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001038}
1039
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001040void Context::bindImageTexture(GLuint unit,
1041 GLuint texture,
1042 GLint level,
1043 GLboolean layered,
1044 GLint layer,
1045 GLenum access,
1046 GLenum format)
1047{
1048 Texture *tex = mState.mTextures->getTexture(texture);
1049 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1050}
1051
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001052void Context::useProgram(GLuint program)
1053{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001054 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001055}
1056
Jiajia Qin5451d532017-11-16 17:16:34 +08001057void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1058{
1059 UNIMPLEMENTED();
1060}
1061
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001062void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001063{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001064 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001065 TransformFeedback *transformFeedback =
1066 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001067 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001068}
1069
Yunchao Hea336b902017-08-02 16:05:21 +08001070void Context::bindProgramPipeline(GLuint pipelineHandle)
1071{
1072 ProgramPipeline *pipeline =
1073 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1074 mGLState.setProgramPipelineBinding(this, pipeline);
1075}
1076
Jamie Madillf0e04492017-08-26 15:28:42 -04001077void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001080 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081
Geoff Lang5aad9672014-09-08 11:10:42 -04001082 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001083 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001084
1085 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001087}
1088
Jamie Madillf0e04492017-08-26 15:28:42 -04001089void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001091 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001092 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093
Jamie Madillf0e04492017-08-26 15:28:42 -04001094 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095
Geoff Lang5aad9672014-09-08 11:10:42 -04001096 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001097 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098}
1099
Jamie Madillf0e04492017-08-26 15:28:42 -04001100void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001101{
1102 ASSERT(target == GL_TIMESTAMP_EXT);
1103
1104 Query *queryObject = getQuery(id, true, target);
1105 ASSERT(queryObject);
1106
Jamie Madillf0e04492017-08-26 15:28:42 -04001107 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001108}
1109
1110void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1111{
1112 switch (pname)
1113 {
1114 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001115 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116 break;
1117 case GL_QUERY_COUNTER_BITS_EXT:
1118 switch (target)
1119 {
1120 case GL_TIME_ELAPSED_EXT:
1121 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1122 break;
1123 case GL_TIMESTAMP_EXT:
1124 params[0] = getExtensions().queryCounterBitsTimestamp;
1125 break;
1126 default:
1127 UNREACHABLE();
1128 params[0] = 0;
1129 break;
1130 }
1131 break;
1132 default:
1133 UNREACHABLE();
1134 return;
1135 }
1136}
1137
Geoff Lang2186c382016-10-14 10:54:54 -04001138void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139{
Geoff Lang2186c382016-10-14 10:54:54 -04001140 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144{
Geoff Lang2186c382016-10-14 10:54:54 -04001145 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001146}
1147
Geoff Lang2186c382016-10-14 10:54:54 -04001148void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001149{
Geoff Lang2186c382016-10-14 10:54:54 -04001150 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001151}
1152
Geoff Lang2186c382016-10-14 10:54:54 -04001153void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001154{
Geoff Lang2186c382016-10-14 10:54:54 -04001155 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001156}
1157
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001158Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001160 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161}
1162
Jamie Madill2f348d22017-06-05 10:50:59 -04001163FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001164{
Jamie Madill96a483b2017-06-27 16:49:21 -04001165 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166}
1167
Jamie Madill2f348d22017-06-05 10:50:59 -04001168Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169{
Jamie Madill96a483b2017-06-27 16:49:21 -04001170 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001172 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001174
1175 Query *query = mQueryMap.query(handle);
1176 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001177 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001178 query = new Query(mImplementation->createQuery(type), handle);
1179 query->addRef();
1180 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001182 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183}
1184
Geoff Lang70d0f492015-12-10 17:45:46 -05001185Query *Context::getQuery(GLuint handle) const
1186{
Jamie Madill96a483b2017-06-27 16:49:21 -04001187 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001188}
1189
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001190Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001191{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001192 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1193 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001194}
1195
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001196Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001197{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001198 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199}
1200
Geoff Lang492a7e42014-11-05 13:27:06 -05001201Compiler *Context::getCompiler() const
1202{
Jamie Madill2f348d22017-06-05 10:50:59 -04001203 if (mCompiler.get() == nullptr)
1204 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001205 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001206 }
1207 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001208}
1209
Jamie Madillc1d770e2017-04-13 17:31:24 -04001210void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211{
1212 switch (pname)
1213 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001214 case GL_SHADER_COMPILER:
1215 *params = GL_TRUE;
1216 break;
1217 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1218 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1219 break;
1220 default:
1221 mGLState.getBooleanv(pname, params);
1222 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224}
1225
Jamie Madillc1d770e2017-04-13 17:31:24 -04001226void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227{
Shannon Woods53a94a82014-06-24 15:20:36 -04001228 // Queries about context capabilities and maximums are answered by Context.
1229 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 switch (pname)
1231 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001232 case GL_ALIASED_LINE_WIDTH_RANGE:
1233 params[0] = mCaps.minAliasedLineWidth;
1234 params[1] = mCaps.maxAliasedLineWidth;
1235 break;
1236 case GL_ALIASED_POINT_SIZE_RANGE:
1237 params[0] = mCaps.minAliasedPointSize;
1238 params[1] = mCaps.maxAliasedPointSize;
1239 break;
1240 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1241 ASSERT(mExtensions.textureFilterAnisotropic);
1242 *params = mExtensions.maxTextureAnisotropy;
1243 break;
1244 case GL_MAX_TEXTURE_LOD_BIAS:
1245 *params = mCaps.maxLODBias;
1246 break;
1247
1248 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1249 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1250 {
1251 ASSERT(mExtensions.pathRendering);
1252 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1253 memcpy(params, m, 16 * sizeof(GLfloat));
1254 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001255 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001256
Jamie Madill231c7f52017-04-26 13:45:37 -04001257 default:
1258 mGLState.getFloatv(pname, params);
1259 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001260 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001261}
1262
Jamie Madillc1d770e2017-04-13 17:31:24 -04001263void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264{
Shannon Woods53a94a82014-06-24 15:20:36 -04001265 // Queries about context capabilities and maximums are answered by Context.
1266 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001267
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268 switch (pname)
1269 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001270 case GL_MAX_VERTEX_ATTRIBS:
1271 *params = mCaps.maxVertexAttributes;
1272 break;
1273 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1274 *params = mCaps.maxVertexUniformVectors;
1275 break;
1276 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1277 *params = mCaps.maxVertexUniformComponents;
1278 break;
1279 case GL_MAX_VARYING_VECTORS:
1280 *params = mCaps.maxVaryingVectors;
1281 break;
1282 case GL_MAX_VARYING_COMPONENTS:
1283 *params = mCaps.maxVertexOutputComponents;
1284 break;
1285 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1286 *params = mCaps.maxCombinedTextureImageUnits;
1287 break;
1288 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1289 *params = mCaps.maxVertexTextureImageUnits;
1290 break;
1291 case GL_MAX_TEXTURE_IMAGE_UNITS:
1292 *params = mCaps.maxTextureImageUnits;
1293 break;
1294 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1295 *params = mCaps.maxFragmentUniformVectors;
1296 break;
1297 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1298 *params = mCaps.maxFragmentUniformComponents;
1299 break;
1300 case GL_MAX_RENDERBUFFER_SIZE:
1301 *params = mCaps.maxRenderbufferSize;
1302 break;
1303 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1304 *params = mCaps.maxColorAttachments;
1305 break;
1306 case GL_MAX_DRAW_BUFFERS_EXT:
1307 *params = mCaps.maxDrawBuffers;
1308 break;
1309 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1310 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1311 case GL_SUBPIXEL_BITS:
1312 *params = 4;
1313 break;
1314 case GL_MAX_TEXTURE_SIZE:
1315 *params = mCaps.max2DTextureSize;
1316 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001317 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1318 *params = mCaps.maxRectangleTextureSize;
1319 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1321 *params = mCaps.maxCubeMapTextureSize;
1322 break;
1323 case GL_MAX_3D_TEXTURE_SIZE:
1324 *params = mCaps.max3DTextureSize;
1325 break;
1326 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1327 *params = mCaps.maxArrayTextureLayers;
1328 break;
1329 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1330 *params = mCaps.uniformBufferOffsetAlignment;
1331 break;
1332 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1333 *params = mCaps.maxUniformBufferBindings;
1334 break;
1335 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1336 *params = mCaps.maxVertexUniformBlocks;
1337 break;
1338 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1339 *params = mCaps.maxFragmentUniformBlocks;
1340 break;
1341 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1342 *params = mCaps.maxCombinedTextureImageUnits;
1343 break;
1344 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1345 *params = mCaps.maxVertexOutputComponents;
1346 break;
1347 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1348 *params = mCaps.maxFragmentInputComponents;
1349 break;
1350 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1351 *params = mCaps.minProgramTexelOffset;
1352 break;
1353 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1354 *params = mCaps.maxProgramTexelOffset;
1355 break;
1356 case GL_MAJOR_VERSION:
1357 *params = getClientVersion().major;
1358 break;
1359 case GL_MINOR_VERSION:
1360 *params = getClientVersion().minor;
1361 break;
1362 case GL_MAX_ELEMENTS_INDICES:
1363 *params = mCaps.maxElementsIndices;
1364 break;
1365 case GL_MAX_ELEMENTS_VERTICES:
1366 *params = mCaps.maxElementsVertices;
1367 break;
1368 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1369 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1370 break;
1371 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1372 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1373 break;
1374 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1375 *params = mCaps.maxTransformFeedbackSeparateComponents;
1376 break;
1377 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1378 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1379 break;
1380 case GL_MAX_SAMPLES_ANGLE:
1381 *params = mCaps.maxSamples;
1382 break;
1383 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001385 params[0] = mCaps.maxViewportWidth;
1386 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001387 }
1388 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001389 case GL_COMPRESSED_TEXTURE_FORMATS:
1390 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1391 params);
1392 break;
1393 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1394 *params = mResetStrategy;
1395 break;
1396 case GL_NUM_SHADER_BINARY_FORMATS:
1397 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1398 break;
1399 case GL_SHADER_BINARY_FORMATS:
1400 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1401 break;
1402 case GL_NUM_PROGRAM_BINARY_FORMATS:
1403 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1404 break;
1405 case GL_PROGRAM_BINARY_FORMATS:
1406 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1407 break;
1408 case GL_NUM_EXTENSIONS:
1409 *params = static_cast<GLint>(mExtensionStrings.size());
1410 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001411
Jamie Madill231c7f52017-04-26 13:45:37 -04001412 // GL_KHR_debug
1413 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1414 *params = mExtensions.maxDebugMessageLength;
1415 break;
1416 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1417 *params = mExtensions.maxDebugLoggedMessages;
1418 break;
1419 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1420 *params = mExtensions.maxDebugGroupStackDepth;
1421 break;
1422 case GL_MAX_LABEL_LENGTH:
1423 *params = mExtensions.maxLabelLength;
1424 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001425
Martin Radeve5285d22017-07-14 16:23:53 +03001426 // GL_ANGLE_multiview
1427 case GL_MAX_VIEWS_ANGLE:
1428 *params = mExtensions.maxViews;
1429 break;
1430
Jamie Madill231c7f52017-04-26 13:45:37 -04001431 // GL_EXT_disjoint_timer_query
1432 case GL_GPU_DISJOINT_EXT:
1433 *params = mImplementation->getGPUDisjoint();
1434 break;
1435 case GL_MAX_FRAMEBUFFER_WIDTH:
1436 *params = mCaps.maxFramebufferWidth;
1437 break;
1438 case GL_MAX_FRAMEBUFFER_HEIGHT:
1439 *params = mCaps.maxFramebufferHeight;
1440 break;
1441 case GL_MAX_FRAMEBUFFER_SAMPLES:
1442 *params = mCaps.maxFramebufferSamples;
1443 break;
1444 case GL_MAX_SAMPLE_MASK_WORDS:
1445 *params = mCaps.maxSampleMaskWords;
1446 break;
1447 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1448 *params = mCaps.maxColorTextureSamples;
1449 break;
1450 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1451 *params = mCaps.maxDepthTextureSamples;
1452 break;
1453 case GL_MAX_INTEGER_SAMPLES:
1454 *params = mCaps.maxIntegerSamples;
1455 break;
1456 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1457 *params = mCaps.maxVertexAttribRelativeOffset;
1458 break;
1459 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1460 *params = mCaps.maxVertexAttribBindings;
1461 break;
1462 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1463 *params = mCaps.maxVertexAttribStride;
1464 break;
1465 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1466 *params = mCaps.maxVertexAtomicCounterBuffers;
1467 break;
1468 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1469 *params = mCaps.maxVertexAtomicCounters;
1470 break;
1471 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1472 *params = mCaps.maxVertexImageUniforms;
1473 break;
1474 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1475 *params = mCaps.maxVertexShaderStorageBlocks;
1476 break;
1477 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1478 *params = mCaps.maxFragmentAtomicCounterBuffers;
1479 break;
1480 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1481 *params = mCaps.maxFragmentAtomicCounters;
1482 break;
1483 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1484 *params = mCaps.maxFragmentImageUniforms;
1485 break;
1486 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1487 *params = mCaps.maxFragmentShaderStorageBlocks;
1488 break;
1489 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1490 *params = mCaps.minProgramTextureGatherOffset;
1491 break;
1492 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1493 *params = mCaps.maxProgramTextureGatherOffset;
1494 break;
1495 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1496 *params = mCaps.maxComputeWorkGroupInvocations;
1497 break;
1498 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1499 *params = mCaps.maxComputeUniformBlocks;
1500 break;
1501 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1502 *params = mCaps.maxComputeTextureImageUnits;
1503 break;
1504 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1505 *params = mCaps.maxComputeSharedMemorySize;
1506 break;
1507 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1508 *params = mCaps.maxComputeUniformComponents;
1509 break;
1510 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1511 *params = mCaps.maxComputeAtomicCounterBuffers;
1512 break;
1513 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1514 *params = mCaps.maxComputeAtomicCounters;
1515 break;
1516 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1517 *params = mCaps.maxComputeImageUniforms;
1518 break;
1519 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1520 *params = mCaps.maxCombinedComputeUniformComponents;
1521 break;
1522 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1523 *params = mCaps.maxComputeShaderStorageBlocks;
1524 break;
1525 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1526 *params = mCaps.maxCombinedShaderOutputResources;
1527 break;
1528 case GL_MAX_UNIFORM_LOCATIONS:
1529 *params = mCaps.maxUniformLocations;
1530 break;
1531 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1532 *params = mCaps.maxAtomicCounterBufferBindings;
1533 break;
1534 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1535 *params = mCaps.maxAtomicCounterBufferSize;
1536 break;
1537 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1538 *params = mCaps.maxCombinedAtomicCounterBuffers;
1539 break;
1540 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1541 *params = mCaps.maxCombinedAtomicCounters;
1542 break;
1543 case GL_MAX_IMAGE_UNITS:
1544 *params = mCaps.maxImageUnits;
1545 break;
1546 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1547 *params = mCaps.maxCombinedImageUniforms;
1548 break;
1549 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1550 *params = mCaps.maxShaderStorageBufferBindings;
1551 break;
1552 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1553 *params = mCaps.maxCombinedShaderStorageBlocks;
1554 break;
1555 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1556 *params = mCaps.shaderStorageBufferOffsetAlignment;
1557 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001558
1559 // GL_EXT_geometry_shader
1560 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1561 *params = mCaps.maxFramebufferLayers;
1562 break;
1563 case GL_LAYER_PROVOKING_VERTEX_EXT:
1564 *params = mCaps.layerProvokingVertex;
1565 break;
1566 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1567 *params = mCaps.maxGeometryUniformComponents;
1568 break;
1569 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1570 *params = mCaps.maxGeometryUniformBlocks;
1571 break;
1572 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1573 *params = mCaps.maxCombinedGeometryUniformComponents;
1574 break;
1575 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1576 *params = mCaps.maxGeometryInputComponents;
1577 break;
1578 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1579 *params = mCaps.maxGeometryOutputComponents;
1580 break;
1581 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1582 *params = mCaps.maxGeometryOutputVertices;
1583 break;
1584 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1585 *params = mCaps.maxGeometryTotalOutputComponents;
1586 break;
1587 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1588 *params = mCaps.maxGeometryShaderInvocations;
1589 break;
1590 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1591 *params = mCaps.maxGeometryTextureImageUnits;
1592 break;
1593 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1594 *params = mCaps.maxGeometryAtomicCounterBuffers;
1595 break;
1596 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1597 *params = mCaps.maxGeometryAtomicCounters;
1598 break;
1599 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1600 *params = mCaps.maxGeometryImageUniforms;
1601 break;
1602 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1603 *params = mCaps.maxGeometryShaderStorageBlocks;
1604 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001606 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001608 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001609}
1610
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001611void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001612{
Shannon Woods53a94a82014-06-24 15:20:36 -04001613 // Queries about context capabilities and maximums are answered by Context.
1614 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001615 switch (pname)
1616 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 case GL_MAX_ELEMENT_INDEX:
1618 *params = mCaps.maxElementIndex;
1619 break;
1620 case GL_MAX_UNIFORM_BLOCK_SIZE:
1621 *params = mCaps.maxUniformBlockSize;
1622 break;
1623 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1624 *params = mCaps.maxCombinedVertexUniformComponents;
1625 break;
1626 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1627 *params = mCaps.maxCombinedFragmentUniformComponents;
1628 break;
1629 case GL_MAX_SERVER_WAIT_TIMEOUT:
1630 *params = mCaps.maxServerWaitTimeout;
1631 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001632
Jamie Madill231c7f52017-04-26 13:45:37 -04001633 // GL_EXT_disjoint_timer_query
1634 case GL_TIMESTAMP_EXT:
1635 *params = mImplementation->getTimestamp();
1636 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001637
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1639 *params = mCaps.maxShaderStorageBlockSize;
1640 break;
1641 default:
1642 UNREACHABLE();
1643 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001644 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001645}
1646
Geoff Lang70d0f492015-12-10 17:45:46 -05001647void Context::getPointerv(GLenum pname, void **params) const
1648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001649 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001650}
1651
Martin Radev66fb8202016-07-28 11:45:20 +03001652void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001653{
Shannon Woods53a94a82014-06-24 15:20:36 -04001654 // Queries about context capabilities and maximums are answered by Context.
1655 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001656
1657 GLenum nativeType;
1658 unsigned int numParams;
1659 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1660 ASSERT(queryStatus);
1661
1662 if (nativeType == GL_INT)
1663 {
1664 switch (target)
1665 {
1666 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1667 ASSERT(index < 3u);
1668 *data = mCaps.maxComputeWorkGroupCount[index];
1669 break;
1670 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1671 ASSERT(index < 3u);
1672 *data = mCaps.maxComputeWorkGroupSize[index];
1673 break;
1674 default:
1675 mGLState.getIntegeri_v(target, index, data);
1676 }
1677 }
1678 else
1679 {
1680 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1681 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001682}
1683
Martin Radev66fb8202016-07-28 11:45:20 +03001684void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001685{
Shannon Woods53a94a82014-06-24 15:20:36 -04001686 // Queries about context capabilities and maximums are answered by Context.
1687 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001688
1689 GLenum nativeType;
1690 unsigned int numParams;
1691 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1692 ASSERT(queryStatus);
1693
1694 if (nativeType == GL_INT_64_ANGLEX)
1695 {
1696 mGLState.getInteger64i_v(target, index, data);
1697 }
1698 else
1699 {
1700 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1701 }
1702}
1703
1704void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1705{
1706 // Queries about context capabilities and maximums are answered by Context.
1707 // Queries about current GL state values are answered by State.
1708
1709 GLenum nativeType;
1710 unsigned int numParams;
1711 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1712 ASSERT(queryStatus);
1713
1714 if (nativeType == GL_BOOL)
1715 {
1716 mGLState.getBooleani_v(target, index, data);
1717 }
1718 else
1719 {
1720 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1721 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001722}
1723
Corentin Wallez336129f2017-10-17 15:55:40 -04001724void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001725{
1726 Buffer *buffer = mGLState.getTargetBuffer(target);
1727 QueryBufferParameteriv(buffer, pname, params);
1728}
1729
1730void Context::getFramebufferAttachmentParameteriv(GLenum target,
1731 GLenum attachment,
1732 GLenum pname,
1733 GLint *params)
1734{
1735 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001736 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001737}
1738
1739void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1740{
1741 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1742 QueryRenderbufferiv(this, renderbuffer, pname, params);
1743}
1744
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001745void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001746{
1747 Texture *texture = getTargetTexture(target);
1748 QueryTexParameterfv(texture, pname, params);
1749}
1750
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001751void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001752{
1753 Texture *texture = getTargetTexture(target);
1754 QueryTexParameteriv(texture, pname, params);
1755}
Jiajia Qin5451d532017-11-16 17:16:34 +08001756
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001757void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001758{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001759 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001760 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001761}
1762
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001763void Context::getTexLevelParameterfv(TextureTarget target,
1764 GLint level,
1765 GLenum pname,
1766 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001767{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001768 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001769 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001770}
1771
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001772void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001773{
1774 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001775 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001776 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001777}
1778
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001779void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001780{
1781 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001782 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001783 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001784}
1785
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001786void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001787{
1788 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001789 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001790 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001791}
1792
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001793void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001794{
1795 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001796 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001797 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001798}
1799
Jamie Madill675fe712016-12-19 13:07:54 -05001800void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001802 // No-op if zero count
1803 if (count == 0)
1804 {
1805 return;
1806 }
1807
Jamie Madill05b35b22017-10-03 09:01:44 -04001808 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001809 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1810 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001811}
1812
Jamie Madill675fe712016-12-19 13:07:54 -05001813void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001814{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001815 // No-op if zero count
1816 if (count == 0 || instanceCount == 0)
1817 {
1818 return;
1819 }
1820
Jamie Madill05b35b22017-10-03 09:01:44 -04001821 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001822 ANGLE_CONTEXT_TRY(
1823 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1824 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001825}
1826
Jamie Madill876429b2017-04-20 15:46:24 -04001827void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001828{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001829 // No-op if zero count
1830 if (count == 0)
1831 {
1832 return;
1833 }
1834
Jamie Madill05b35b22017-10-03 09:01:44 -04001835 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001836 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001837}
1838
Jamie Madill675fe712016-12-19 13:07:54 -05001839void Context::drawElementsInstanced(GLenum mode,
1840 GLsizei count,
1841 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001842 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001843 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001844{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001845 // No-op if zero count
1846 if (count == 0 || instances == 0)
1847 {
1848 return;
1849 }
1850
Jamie Madill05b35b22017-10-03 09:01:44 -04001851 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001852 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001853 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001854}
1855
Jamie Madill675fe712016-12-19 13:07:54 -05001856void Context::drawRangeElements(GLenum mode,
1857 GLuint start,
1858 GLuint end,
1859 GLsizei count,
1860 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001861 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001862{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001863 // No-op if zero count
1864 if (count == 0)
1865 {
1866 return;
1867 }
1868
Jamie Madill05b35b22017-10-03 09:01:44 -04001869 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001870 ANGLE_CONTEXT_TRY(
1871 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001872}
1873
Jamie Madill876429b2017-04-20 15:46:24 -04001874void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001875{
Jamie Madill05b35b22017-10-03 09:01:44 -04001876 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001877 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001878}
1879
Jamie Madill876429b2017-04-20 15:46:24 -04001880void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001881{
Jamie Madill05b35b22017-10-03 09:01:44 -04001882 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001883 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001884}
1885
Jamie Madill675fe712016-12-19 13:07:54 -05001886void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001887{
Jamie Madillafa02a22017-11-23 12:57:38 -05001888 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001889}
1890
Jamie Madill675fe712016-12-19 13:07:54 -05001891void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001892{
Jamie Madillafa02a22017-11-23 12:57:38 -05001893 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001894}
1895
Austin Kinross6ee1e782015-05-29 17:05:37 -07001896void Context::insertEventMarker(GLsizei length, const char *marker)
1897{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001898 ASSERT(mImplementation);
1899 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001900}
1901
1902void Context::pushGroupMarker(GLsizei length, const char *marker)
1903{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001904 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001905
1906 if (marker == nullptr)
1907 {
1908 // From the EXT_debug_marker spec,
1909 // "If <marker> is null then an empty string is pushed on the stack."
1910 mImplementation->pushGroupMarker(length, "");
1911 }
1912 else
1913 {
1914 mImplementation->pushGroupMarker(length, marker);
1915 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001916}
1917
1918void Context::popGroupMarker()
1919{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001920 ASSERT(mImplementation);
1921 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001922}
1923
Geoff Langd8605522016-04-13 10:19:12 -04001924void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1925{
1926 Program *programObject = getProgram(program);
1927 ASSERT(programObject);
1928
1929 programObject->bindUniformLocation(location, name);
1930}
1931
Sami Väisänena797e062016-05-12 15:23:40 +03001932void Context::setCoverageModulation(GLenum components)
1933{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001934 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001935}
1936
Sami Väisänene45e53b2016-05-25 10:36:04 +03001937void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1938{
1939 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1940}
1941
1942void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1943{
1944 GLfloat I[16];
1945 angle::Matrix<GLfloat>::setToIdentity(I);
1946
1947 mGLState.loadPathRenderingMatrix(matrixMode, I);
1948}
1949
1950void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1951{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001952 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001953 if (!pathObj)
1954 return;
1955
1956 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001957 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001958
1959 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1960}
1961
1962void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1963{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001964 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001965 if (!pathObj)
1966 return;
1967
1968 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001969 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001970
1971 mImplementation->stencilStrokePath(pathObj, reference, mask);
1972}
1973
1974void Context::coverFillPath(GLuint path, GLenum coverMode)
1975{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001976 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001977 if (!pathObj)
1978 return;
1979
1980 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001981 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001982
1983 mImplementation->coverFillPath(pathObj, coverMode);
1984}
1985
1986void Context::coverStrokePath(GLuint path, GLenum coverMode)
1987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001988 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001989 if (!pathObj)
1990 return;
1991
1992 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001993 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001994
1995 mImplementation->coverStrokePath(pathObj, coverMode);
1996}
1997
1998void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1999{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002000 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002001 if (!pathObj)
2002 return;
2003
2004 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002005 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002006
2007 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2008}
2009
2010void Context::stencilThenCoverStrokePath(GLuint path,
2011 GLint reference,
2012 GLuint mask,
2013 GLenum coverMode)
2014{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002015 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002016 if (!pathObj)
2017 return;
2018
2019 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002020 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002021
2022 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2023}
2024
Sami Väisänend59ca052016-06-21 16:10:00 +03002025void Context::coverFillPathInstanced(GLsizei numPaths,
2026 GLenum pathNameType,
2027 const void *paths,
2028 GLuint pathBase,
2029 GLenum coverMode,
2030 GLenum transformType,
2031 const GLfloat *transformValues)
2032{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002033 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002034
2035 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002036 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002037
2038 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2039}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002040
Sami Väisänend59ca052016-06-21 16:10:00 +03002041void Context::coverStrokePathInstanced(GLsizei numPaths,
2042 GLenum pathNameType,
2043 const void *paths,
2044 GLuint pathBase,
2045 GLenum coverMode,
2046 GLenum transformType,
2047 const GLfloat *transformValues)
2048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002049 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002050
2051 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002052 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002053
2054 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2055 transformValues);
2056}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002057
Sami Väisänend59ca052016-06-21 16:10:00 +03002058void Context::stencilFillPathInstanced(GLsizei numPaths,
2059 GLenum pathNameType,
2060 const void *paths,
2061 GLuint pathBase,
2062 GLenum fillMode,
2063 GLuint mask,
2064 GLenum transformType,
2065 const GLfloat *transformValues)
2066{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002067 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002068
2069 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002070 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002071
2072 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2073 transformValues);
2074}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002075
Sami Väisänend59ca052016-06-21 16:10:00 +03002076void Context::stencilStrokePathInstanced(GLsizei numPaths,
2077 GLenum pathNameType,
2078 const void *paths,
2079 GLuint pathBase,
2080 GLint reference,
2081 GLuint mask,
2082 GLenum transformType,
2083 const GLfloat *transformValues)
2084{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002085 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002086
2087 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002088 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002089
2090 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2091 transformValues);
2092}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002093
Sami Väisänend59ca052016-06-21 16:10:00 +03002094void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2095 GLenum pathNameType,
2096 const void *paths,
2097 GLuint pathBase,
2098 GLenum fillMode,
2099 GLuint mask,
2100 GLenum coverMode,
2101 GLenum transformType,
2102 const GLfloat *transformValues)
2103{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002104 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002105
2106 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002107 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002108
2109 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2110 transformType, transformValues);
2111}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002112
Sami Väisänend59ca052016-06-21 16:10:00 +03002113void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2114 GLenum pathNameType,
2115 const void *paths,
2116 GLuint pathBase,
2117 GLint reference,
2118 GLuint mask,
2119 GLenum coverMode,
2120 GLenum transformType,
2121 const GLfloat *transformValues)
2122{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002123 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002124
2125 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002126 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002127
2128 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2129 transformType, transformValues);
2130}
2131
Sami Väisänen46eaa942016-06-29 10:26:37 +03002132void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2133{
2134 auto *programObject = getProgram(program);
2135
2136 programObject->bindFragmentInputLocation(location, name);
2137}
2138
2139void Context::programPathFragmentInputGen(GLuint program,
2140 GLint location,
2141 GLenum genMode,
2142 GLint components,
2143 const GLfloat *coeffs)
2144{
2145 auto *programObject = getProgram(program);
2146
Jamie Madillbd044ed2017-06-05 12:59:21 -04002147 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002148}
2149
jchen1015015f72017-03-16 13:54:21 +08002150GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2151{
jchen10fd7c3b52017-03-21 15:36:03 +08002152 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002153 return QueryProgramResourceIndex(programObject, programInterface, name);
2154}
2155
jchen10fd7c3b52017-03-21 15:36:03 +08002156void Context::getProgramResourceName(GLuint program,
2157 GLenum programInterface,
2158 GLuint index,
2159 GLsizei bufSize,
2160 GLsizei *length,
2161 GLchar *name)
2162{
2163 const auto *programObject = getProgram(program);
2164 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2165}
2166
jchen10191381f2017-04-11 13:59:04 +08002167GLint Context::getProgramResourceLocation(GLuint program,
2168 GLenum programInterface,
2169 const GLchar *name)
2170{
2171 const auto *programObject = getProgram(program);
2172 return QueryProgramResourceLocation(programObject, programInterface, name);
2173}
2174
jchen10880683b2017-04-12 16:21:55 +08002175void Context::getProgramResourceiv(GLuint program,
2176 GLenum programInterface,
2177 GLuint index,
2178 GLsizei propCount,
2179 const GLenum *props,
2180 GLsizei bufSize,
2181 GLsizei *length,
2182 GLint *params)
2183{
2184 const auto *programObject = getProgram(program);
2185 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2186 length, params);
2187}
2188
jchen10d9cd7b72017-08-30 15:04:25 +08002189void Context::getProgramInterfaceiv(GLuint program,
2190 GLenum programInterface,
2191 GLenum pname,
2192 GLint *params)
2193{
2194 const auto *programObject = getProgram(program);
2195 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2196}
2197
Jamie Madill71c88b32017-09-14 22:20:29 -04002198void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002199{
Geoff Langda5777c2014-07-11 09:52:58 -04002200 if (error.isError())
2201 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002202 GLenum code = error.getCode();
2203 mErrors.insert(code);
2204 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2205 {
2206 markContextLost();
2207 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002208
Geoff Langee6884e2017-11-09 16:51:11 -05002209 ASSERT(!error.getMessage().empty());
2210 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2211 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002212 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002213}
2214
2215// Get one of the recorded errors and clear its flag, if any.
2216// [OpenGL ES 2.0.24] section 2.5 page 13.
2217GLenum Context::getError()
2218{
Geoff Langda5777c2014-07-11 09:52:58 -04002219 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002220 {
Geoff Langda5777c2014-07-11 09:52:58 -04002221 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002222 }
Geoff Langda5777c2014-07-11 09:52:58 -04002223 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224 {
Geoff Langda5777c2014-07-11 09:52:58 -04002225 GLenum error = *mErrors.begin();
2226 mErrors.erase(mErrors.begin());
2227 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002229}
2230
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231// NOTE: this function should not assume that this context is current!
2232void Context::markContextLost()
2233{
2234 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002235 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002236 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002237 mContextLostForced = true;
2238 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002239 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002240}
2241
2242bool Context::isContextLost()
2243{
2244 return mContextLost;
2245}
2246
Jamie Madillfa920eb2018-01-04 11:45:50 -05002247GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002248{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002249 // Even if the application doesn't want to know about resets, we want to know
2250 // as it will allow us to skip all the calls.
2251 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002253 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002254 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002255 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002256 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002257
2258 // EXT_robustness, section 2.6: If the reset notification behavior is
2259 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2260 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2261 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002262 }
2263
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2265 // status should be returned at least once, and GL_NO_ERROR should be returned
2266 // once the device has finished resetting.
2267 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002268 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002269 ASSERT(mResetStatus == GL_NO_ERROR);
2270 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002271
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002272 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002273 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002274 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002275 }
2276 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002277 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002278 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002279 // If markContextLost was used to mark the context lost then
2280 // assume that is not recoverable, and continue to report the
2281 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002282 mResetStatus = mImplementation->getResetStatus();
2283 }
Jamie Madill893ab082014-05-16 16:56:10 -04002284
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002285 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002286}
2287
2288bool Context::isResetNotificationEnabled()
2289{
2290 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2291}
2292
Corentin Walleze3b10e82015-05-20 11:06:25 -04002293const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002294{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002295 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002296}
2297
2298EGLenum Context::getClientType() const
2299{
2300 return mClientType;
2301}
2302
2303EGLenum Context::getRenderBuffer() const
2304{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002305 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2306 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002307 {
2308 return EGL_NONE;
2309 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002310
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002311 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002312 ASSERT(backAttachment != nullptr);
2313 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002314}
2315
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002316VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002317{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002318 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002319 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2320 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002321 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002322 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2323 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002324
Jamie Madill96a483b2017-06-27 16:49:21 -04002325 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002326 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002327
2328 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002329}
2330
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002331TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002332{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002333 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002334 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2335 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002336 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002337 transformFeedback =
2338 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002339 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002340 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002341 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002342
2343 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002344}
2345
2346bool Context::isVertexArrayGenerated(GLuint vertexArray)
2347{
Jamie Madill96a483b2017-06-27 16:49:21 -04002348 ASSERT(mVertexArrayMap.contains(0));
2349 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002350}
2351
2352bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2353{
Jamie Madill96a483b2017-06-27 16:49:21 -04002354 ASSERT(mTransformFeedbackMap.contains(0));
2355 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002356}
2357
Shannon Woods53a94a82014-06-24 15:20:36 -04002358void Context::detachTexture(GLuint texture)
2359{
2360 // Simple pass-through to State's detachTexture method, as textures do not require
2361 // allocation map management either here or in the resource manager at detach time.
2362 // Zero textures are held by the Context, and we don't attempt to request them from
2363 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002364 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002365}
2366
James Darpinian4d9d4832018-03-13 12:43:28 -07002367void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368{
Yuly Novikov5807a532015-12-03 13:01:22 -05002369 // Simple pass-through to State's detachBuffer method, since
2370 // only buffer attachments to container objects that are bound to the current context
2371 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002372
Yuly Novikov5807a532015-12-03 13:01:22 -05002373 // [OpenGL ES 3.2] section 5.1.2 page 45:
2374 // Attachments to unbound container objects, such as
2375 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2376 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002377 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002378}
2379
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002380void Context::detachFramebuffer(GLuint framebuffer)
2381{
Shannon Woods53a94a82014-06-24 15:20:36 -04002382 // Framebuffer detachment is handled by Context, because 0 is a valid
2383 // Framebuffer object, and a pointer to it must be passed from Context
2384 // to State at binding time.
2385
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002386 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002387 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2388 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2389 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002390
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002391 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002392 {
2393 bindReadFramebuffer(0);
2394 }
2395
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002396 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002397 {
2398 bindDrawFramebuffer(0);
2399 }
2400}
2401
2402void Context::detachRenderbuffer(GLuint renderbuffer)
2403{
Jamie Madilla02315b2017-02-23 14:14:47 -05002404 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002405}
2406
Jamie Madill57a89722013-07-02 11:57:03 -04002407void Context::detachVertexArray(GLuint vertexArray)
2408{
Jamie Madill77a72f62015-04-14 11:18:32 -04002409 // Vertex array detachment is handled by Context, because 0 is a valid
2410 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002411 // binding time.
2412
Jamie Madill57a89722013-07-02 11:57:03 -04002413 // [OpenGL ES 3.0.2] section 2.10 page 43:
2414 // If a vertex array object that is currently bound is deleted, the binding
2415 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002416 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002417 {
2418 bindVertexArray(0);
2419 }
2420}
2421
Geoff Langc8058452014-02-03 12:04:11 -05002422void Context::detachTransformFeedback(GLuint transformFeedback)
2423{
Corentin Walleza2257da2016-04-19 16:43:12 -04002424 // Transform feedback detachment is handled by Context, because 0 is a valid
2425 // transform feedback, and a pointer to it must be passed from Context to State at
2426 // binding time.
2427
2428 // The OpenGL specification doesn't mention what should happen when the currently bound
2429 // transform feedback object is deleted. Since it is a container object, we treat it like
2430 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002431 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002432 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002433 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002434 }
Geoff Langc8058452014-02-03 12:04:11 -05002435}
2436
Jamie Madilldc356042013-07-19 16:36:57 -04002437void Context::detachSampler(GLuint sampler)
2438{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002439 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002440}
2441
Yunchao Hea336b902017-08-02 16:05:21 +08002442void Context::detachProgramPipeline(GLuint pipeline)
2443{
2444 mGLState.detachProgramPipeline(this, pipeline);
2445}
2446
Jamie Madill3ef140a2017-08-26 23:11:21 -04002447void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002448{
Shaodde78e82017-05-22 14:13:27 +08002449 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002450}
2451
Jamie Madille29d1672013-07-19 16:36:57 -04002452void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2453{
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002457 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002458}
Jamie Madille29d1672013-07-19 16:36:57 -04002459
Geoff Langc1984ed2016-10-07 12:41:00 -04002460void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2461{
2462 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002464 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002465 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002466}
2467
2468void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2469{
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002471 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002472 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002473 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002474}
2475
Geoff Langc1984ed2016-10-07 12:41:00 -04002476void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002477{
Geoff Langc1984ed2016-10-07 12:41:00 -04002478 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002479 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002480 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002481 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002482}
2483
Geoff Langc1984ed2016-10-07 12:41:00 -04002484void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002485{
Geoff Langc1984ed2016-10-07 12:41:00 -04002486 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002487 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002488 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002489 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002490}
Jamie Madill9675b802013-07-19 16:36:59 -04002491
Geoff Langc1984ed2016-10-07 12:41:00 -04002492void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2493{
2494 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002495 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002496 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002497 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002498}
2499
Olli Etuahof0fee072016-03-30 15:11:58 +03002500void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2501{
2502 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002503 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002504}
2505
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002506void Context::initRendererString()
2507{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002508 std::ostringstream rendererString;
2509 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002510 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002511 rendererString << ")";
2512
Geoff Langcec35902014-04-16 10:52:36 -04002513 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002514}
2515
Geoff Langc339c4e2016-11-29 10:37:36 -05002516void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002517{
Geoff Langc339c4e2016-11-29 10:37:36 -05002518 const Version &clientVersion = getClientVersion();
2519
2520 std::ostringstream versionString;
2521 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2522 << ANGLE_VERSION_STRING << ")";
2523 mVersionString = MakeStaticString(versionString.str());
2524
2525 std::ostringstream shadingLanguageVersionString;
2526 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2527 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2528 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2529 << ")";
2530 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002531}
2532
Geoff Langcec35902014-04-16 10:52:36 -04002533void Context::initExtensionStrings()
2534{
Geoff Langc339c4e2016-11-29 10:37:36 -05002535 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2536 std::ostringstream combinedStringStream;
2537 std::copy(strings.begin(), strings.end(),
2538 std::ostream_iterator<const char *>(combinedStringStream, " "));
2539 return MakeStaticString(combinedStringStream.str());
2540 };
2541
2542 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002543 for (const auto &extensionString : mExtensions.getStrings())
2544 {
2545 mExtensionStrings.push_back(MakeStaticString(extensionString));
2546 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002547 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002548
Bryan Bernhart58806562017-01-05 13:09:31 -08002549 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2550
Geoff Langc339c4e2016-11-29 10:37:36 -05002551 mRequestableExtensionStrings.clear();
2552 for (const auto &extensionInfo : GetExtensionInfoMap())
2553 {
2554 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002555 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2556 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002557 {
2558 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2559 }
2560 }
2561 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002562}
2563
Geoff Langc339c4e2016-11-29 10:37:36 -05002564const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002565{
Geoff Langc339c4e2016-11-29 10:37:36 -05002566 switch (name)
2567 {
2568 case GL_VENDOR:
2569 return reinterpret_cast<const GLubyte *>("Google Inc.");
2570
2571 case GL_RENDERER:
2572 return reinterpret_cast<const GLubyte *>(mRendererString);
2573
2574 case GL_VERSION:
2575 return reinterpret_cast<const GLubyte *>(mVersionString);
2576
2577 case GL_SHADING_LANGUAGE_VERSION:
2578 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2579
2580 case GL_EXTENSIONS:
2581 return reinterpret_cast<const GLubyte *>(mExtensionString);
2582
2583 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2584 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2585
2586 default:
2587 UNREACHABLE();
2588 return nullptr;
2589 }
Geoff Langcec35902014-04-16 10:52:36 -04002590}
2591
Geoff Langc339c4e2016-11-29 10:37:36 -05002592const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002593{
Geoff Langc339c4e2016-11-29 10:37:36 -05002594 switch (name)
2595 {
2596 case GL_EXTENSIONS:
2597 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2598
2599 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2600 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2601
2602 default:
2603 UNREACHABLE();
2604 return nullptr;
2605 }
Geoff Langcec35902014-04-16 10:52:36 -04002606}
2607
2608size_t Context::getExtensionStringCount() const
2609{
2610 return mExtensionStrings.size();
2611}
2612
Geoff Lang111a99e2017-10-17 10:58:41 -04002613bool Context::isExtensionRequestable(const char *name)
2614{
2615 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2616 auto extension = extensionInfos.find(name);
2617
2618 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2619 return extension != extensionInfos.end() && extension->second.Requestable &&
2620 nativeExtensions.*(extension->second.ExtensionsMember);
2621}
2622
Geoff Langc339c4e2016-11-29 10:37:36 -05002623void Context::requestExtension(const char *name)
2624{
2625 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2626 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2627 const auto &extension = extensionInfos.at(name);
2628 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002629 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002630
2631 if (mExtensions.*(extension.ExtensionsMember))
2632 {
2633 // Extension already enabled
2634 return;
2635 }
2636
2637 mExtensions.*(extension.ExtensionsMember) = true;
2638 updateCaps();
2639 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002640
Jamie Madill2f348d22017-06-05 10:50:59 -04002641 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2642 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002643
Jamie Madill81c2e252017-09-09 23:32:46 -04002644 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2645 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002646 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002647 for (auto &zeroTexture : mZeroTextures)
2648 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002649 if (zeroTexture.get() != nullptr)
2650 {
2651 zeroTexture->signalDirty(this, InitState::Initialized);
2652 }
Geoff Lang9aded172017-04-05 11:07:56 -04002653 }
2654
2655 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002656}
2657
2658size_t Context::getRequestableExtensionStringCount() const
2659{
2660 return mRequestableExtensionStrings.size();
2661}
2662
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002663void Context::beginTransformFeedback(GLenum primitiveMode)
2664{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002665 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002666 ASSERT(transformFeedback != nullptr);
2667 ASSERT(!transformFeedback->isPaused());
2668
Jamie Madill6c1f6712017-02-14 19:08:04 -05002669 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002670}
2671
2672bool Context::hasActiveTransformFeedback(GLuint program) const
2673{
2674 for (auto pair : mTransformFeedbackMap)
2675 {
2676 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2677 {
2678 return true;
2679 }
2680 }
2681 return false;
2682}
2683
Geoff Langb433e872017-10-05 14:01:47 -04002684void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002685{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002686 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002687
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002688 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2689 if (getClientVersion() < Version(2, 0))
2690 {
2691 mCaps.maxMultitextureUnits = 4;
2692 mCaps.maxClipPlanes = 6;
2693 mCaps.maxLights = 8;
2694 mCaps.maxModelviewMatrixStackDepth = 16;
2695 mCaps.maxProjectionMatrixStackDepth = 16;
2696 mCaps.maxTextureMatrixStackDepth = 16;
2697 }
2698
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002699 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002700
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002701 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002702
Geoff Langeb66a6e2016-10-31 13:06:12 -04002703 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002704 {
2705 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002706 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002707 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002708 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002709 mExtensions.multiview = false;
2710 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002711 }
2712
Jiawei Shao89be29a2017-11-06 14:36:45 +08002713 if (getClientVersion() < ES_3_1)
2714 {
2715 // Disable ES3.1+ extensions
2716 mExtensions.geometryShader = false;
2717 }
2718
Geoff Langeb66a6e2016-10-31 13:06:12 -04002719 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002720 {
2721 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002722 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002723 }
2724
Jamie Madill00ed7a12016-05-19 13:13:38 -04002725 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002726 mExtensions.bindUniformLocation = true;
2727 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002728 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002729 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002730 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002731
2732 // Enable the no error extension if the context was created with the flag.
2733 mExtensions.noError = mSkipValidation;
2734
Corentin Wallezccab69d2017-01-27 16:57:15 -05002735 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002736 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002737
Geoff Lang70d0f492015-12-10 17:45:46 -05002738 // Explicitly enable GL_KHR_debug
2739 mExtensions.debug = true;
2740 mExtensions.maxDebugMessageLength = 1024;
2741 mExtensions.maxDebugLoggedMessages = 1024;
2742 mExtensions.maxDebugGroupStackDepth = 1024;
2743 mExtensions.maxLabelLength = 1024;
2744
Geoff Langff5b2d52016-09-07 11:32:23 -04002745 // Explicitly enable GL_ANGLE_robust_client_memory
2746 mExtensions.robustClientMemory = true;
2747
Jamie Madille08a1d32017-03-07 17:24:06 -05002748 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002749 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002750
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002751 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2752 // supports it.
2753 mExtensions.robustBufferAccessBehavior =
2754 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2755
Jamie Madillc43be722017-07-13 16:22:14 -04002756 // Enable the cache control query unconditionally.
2757 mExtensions.programCacheControl = true;
2758
Geoff Lang301d1612014-07-09 10:34:37 -04002759 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002760 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002761
Jamie Madill0f80ed82017-09-19 00:24:56 -04002762 if (getClientVersion() < ES_3_1)
2763 {
2764 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2765 }
2766 else
2767 {
2768 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2769 }
Geoff Lang301d1612014-07-09 10:34:37 -04002770
Jamie Madill0f80ed82017-09-19 00:24:56 -04002771 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2772 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2773 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2774
2775 // Limit textures as well, so we can use fast bitsets with texture bindings.
2776 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2777 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2778 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002779
Jiawei Shaodb342272017-09-27 10:21:45 +08002780 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2781
Geoff Langc287ea62016-09-16 14:46:51 -04002782 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002783 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002784 for (const auto &extensionInfo : GetExtensionInfoMap())
2785 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04002786 // If the user has requested that extensions start disabled and they are requestable,
2787 // disable them.
2788 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002789 {
2790 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2791 }
2792 }
2793
2794 // Generate texture caps
2795 updateCaps();
2796}
2797
2798void Context::updateCaps()
2799{
Geoff Lang900013c2014-07-07 11:32:19 -04002800 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002801 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002802
Jamie Madill7b62cf92017-11-02 15:20:49 -04002803 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002804 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002805 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002806 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002807
Geoff Lang0d8b7242015-09-09 14:56:53 -04002808 // Update the format caps based on the client version and extensions.
2809 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2810 // ES3.
2811 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002812 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002813 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002814 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002815 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002816 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002817
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002818 // OpenGL ES does not support multisampling with non-rendererable formats
2819 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002820 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002821 (getClientVersion() < ES_3_1 &&
2822 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002823 {
Geoff Langd87878e2014-09-19 15:42:59 -04002824 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002825 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002826 else
2827 {
2828 // We may have limited the max samples for some required renderbuffer formats due to
2829 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2830 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2831
2832 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2833 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2834 // exception of signed and unsigned integer formats."
2835 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2836 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2837 {
2838 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2839 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2840 }
2841
2842 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2843 if (getClientVersion() >= ES_3_1)
2844 {
2845 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2846 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2847 // the exception that the signed and unsigned integer formats are required only to
2848 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2849 // multisamples, which must be at least one."
2850 if (formatInfo.componentType == GL_INT ||
2851 formatInfo.componentType == GL_UNSIGNED_INT)
2852 {
2853 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2854 }
2855
2856 // GLES 3.1 section 19.3.1.
2857 if (formatCaps.texturable)
2858 {
2859 if (formatInfo.depthBits > 0)
2860 {
2861 mCaps.maxDepthTextureSamples =
2862 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2863 }
2864 else if (formatInfo.redBits > 0)
2865 {
2866 mCaps.maxColorTextureSamples =
2867 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2868 }
2869 }
2870 }
2871 }
Geoff Langd87878e2014-09-19 15:42:59 -04002872
2873 if (formatCaps.texturable && formatInfo.compressed)
2874 {
Geoff Langca271392017-04-05 12:30:00 -04002875 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002876 }
2877
Geoff Langca271392017-04-05 12:30:00 -04002878 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002879 }
Jamie Madill32447362017-06-28 14:53:52 -04002880
2881 // If program binary is disabled, blank out the memory cache pointer.
2882 if (!mImplementation->getNativeExtensions().getProgramBinary)
2883 {
2884 mMemoryProgramCache = nullptr;
2885 }
Corentin Walleze4477002017-12-01 14:39:58 -05002886
2887 // Compute which buffer types are allowed
2888 mValidBufferBindings.reset();
2889 mValidBufferBindings.set(BufferBinding::ElementArray);
2890 mValidBufferBindings.set(BufferBinding::Array);
2891
2892 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2893 {
2894 mValidBufferBindings.set(BufferBinding::PixelPack);
2895 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2896 }
2897
2898 if (getClientVersion() >= ES_3_0)
2899 {
2900 mValidBufferBindings.set(BufferBinding::CopyRead);
2901 mValidBufferBindings.set(BufferBinding::CopyWrite);
2902 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2903 mValidBufferBindings.set(BufferBinding::Uniform);
2904 }
2905
2906 if (getClientVersion() >= ES_3_1)
2907 {
2908 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2909 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2910 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2911 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2912 }
Geoff Lang493daf52014-07-03 13:38:44 -04002913}
2914
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002915void Context::initWorkarounds()
2916{
Jamie Madill761b02c2017-06-23 16:27:06 -04002917 // Apply back-end workarounds.
2918 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2919
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002920 // Lose the context upon out of memory error if the application is
2921 // expecting to watch for those events.
2922 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2923}
2924
Jamie Madill05b35b22017-10-03 09:01:44 -04002925Error Context::prepareForDraw()
2926{
Geoff Langa8cb2872018-03-09 16:09:40 -05002927 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002928
2929 if (isRobustResourceInitEnabled())
2930 {
2931 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2932 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2933 }
2934
Geoff Langa8cb2872018-03-09 16:09:40 -05002935 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04002936 return NoError();
2937}
2938
2939Error Context::prepareForClear(GLbitfield mask)
2940{
Geoff Langa8cb2872018-03-09 16:09:40 -05002941 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002942 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05002943 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04002944 return NoError();
2945}
2946
2947Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2948{
Geoff Langa8cb2872018-03-09 16:09:40 -05002949 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002950 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2951 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05002952 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002953 return NoError();
2954}
2955
Geoff Langa8cb2872018-03-09 16:09:40 -05002956Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002957{
Geoff Langa8cb2872018-03-09 16:09:40 -05002958 ANGLE_TRY(syncDirtyObjects());
2959 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002960 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002961}
2962
Geoff Langa8cb2872018-03-09 16:09:40 -05002963Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002964{
Geoff Langa8cb2872018-03-09 16:09:40 -05002965 ANGLE_TRY(syncDirtyObjects(objectMask));
2966 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04002967 return NoError();
2968}
2969
Geoff Langa8cb2872018-03-09 16:09:40 -05002970Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04002971{
2972 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2973 mImplementation->syncState(this, dirtyBits);
2974 mGLState.clearDirtyBits();
2975 return NoError();
2976}
2977
Geoff Langa8cb2872018-03-09 16:09:40 -05002978Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002979{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002980 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002981 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002982 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002983 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002984}
Jamie Madillc29968b2016-01-20 11:17:23 -05002985
Geoff Langa8cb2872018-03-09 16:09:40 -05002986Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04002987{
2988 return mGLState.syncDirtyObjects(this);
2989}
2990
Geoff Langa8cb2872018-03-09 16:09:40 -05002991Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002992{
2993 return mGLState.syncDirtyObjects(this, objectMask);
2994}
2995
Jamie Madillc29968b2016-01-20 11:17:23 -05002996void Context::blitFramebuffer(GLint srcX0,
2997 GLint srcY0,
2998 GLint srcX1,
2999 GLint srcY1,
3000 GLint dstX0,
3001 GLint dstY0,
3002 GLint dstX1,
3003 GLint dstY1,
3004 GLbitfield mask,
3005 GLenum filter)
3006{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003007 if (mask == 0)
3008 {
3009 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3010 // buffers are copied.
3011 return;
3012 }
3013
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003014 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003015 ASSERT(drawFramebuffer);
3016
3017 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3018 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3019
Jamie Madillbc918e72018-03-08 09:47:21 -05003020 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003021
Jamie Madillc564c072017-06-01 12:45:42 -04003022 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003023}
Jamie Madillc29968b2016-01-20 11:17:23 -05003024
3025void Context::clear(GLbitfield mask)
3026{
Geoff Langd4fff502017-09-22 11:28:28 -04003027 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3028 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003029}
3030
3031void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3032{
Geoff Langd4fff502017-09-22 11:28:28 -04003033 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3034 ANGLE_CONTEXT_TRY(
3035 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003036}
3037
3038void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3039{
Geoff Langd4fff502017-09-22 11:28:28 -04003040 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3041 ANGLE_CONTEXT_TRY(
3042 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003043}
3044
3045void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3046{
Geoff Langd4fff502017-09-22 11:28:28 -04003047 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3048 ANGLE_CONTEXT_TRY(
3049 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003050}
3051
3052void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3053{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003054 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 ASSERT(framebufferObject);
3056
3057 // If a buffer is not present, the clear has no effect
3058 if (framebufferObject->getDepthbuffer() == nullptr &&
3059 framebufferObject->getStencilbuffer() == nullptr)
3060 {
3061 return;
3062 }
3063
Geoff Langd4fff502017-09-22 11:28:28 -04003064 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3065 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003066}
3067
3068void Context::readPixels(GLint x,
3069 GLint y,
3070 GLsizei width,
3071 GLsizei height,
3072 GLenum format,
3073 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003074 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003075{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003076 if (width == 0 || height == 0)
3077 {
3078 return;
3079 }
3080
Jamie Madillbc918e72018-03-08 09:47:21 -05003081 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003082
Jamie Madillb6664922017-07-25 12:55:04 -04003083 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3084 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003085
3086 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003087 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003088}
3089
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003090void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003091 GLint level,
3092 GLenum internalformat,
3093 GLint x,
3094 GLint y,
3095 GLsizei width,
3096 GLsizei height,
3097 GLint border)
3098{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003099 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003100 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003101
Jamie Madillc29968b2016-01-20 11:17:23 -05003102 Rectangle sourceArea(x, y, width, height);
3103
Jamie Madill05b35b22017-10-03 09:01:44 -04003104 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003105 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003106 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003107}
3108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003109void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003110 GLint level,
3111 GLint xoffset,
3112 GLint yoffset,
3113 GLint x,
3114 GLint y,
3115 GLsizei width,
3116 GLsizei height)
3117{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003118 if (width == 0 || height == 0)
3119 {
3120 return;
3121 }
3122
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003123 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003124 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003125
Jamie Madillc29968b2016-01-20 11:17:23 -05003126 Offset destOffset(xoffset, yoffset, 0);
3127 Rectangle sourceArea(x, y, width, height);
3128
Jamie Madill05b35b22017-10-03 09:01:44 -04003129 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003130 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003131 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003132}
3133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003134void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003135 GLint level,
3136 GLint xoffset,
3137 GLint yoffset,
3138 GLint zoffset,
3139 GLint x,
3140 GLint y,
3141 GLsizei width,
3142 GLsizei height)
3143{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003144 if (width == 0 || height == 0)
3145 {
3146 return;
3147 }
3148
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003149 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003150 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003151
Jamie Madillc29968b2016-01-20 11:17:23 -05003152 Offset destOffset(xoffset, yoffset, zoffset);
3153 Rectangle sourceArea(x, y, width, height);
3154
Jamie Madill05b35b22017-10-03 09:01:44 -04003155 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3156 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003157 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3158 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003159}
3160
3161void Context::framebufferTexture2D(GLenum target,
3162 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003163 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003164 GLuint texture,
3165 GLint level)
3166{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003167 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003168 ASSERT(framebuffer);
3169
3170 if (texture != 0)
3171 {
3172 Texture *textureObj = getTexture(texture);
3173
3174 ImageIndex index = ImageIndex::MakeInvalid();
3175
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003176 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003177 {
3178 index = ImageIndex::Make2D(level);
3179 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003180 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003181 {
3182 index = ImageIndex::MakeRectangle(level);
3183 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003184 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003185 {
3186 ASSERT(level == 0);
3187 index = ImageIndex::Make2DMultisample();
3188 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 else
3190 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003191 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003192 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 }
3194
Jamie Madilla02315b2017-02-23 14:14:47 -05003195 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003196 }
3197 else
3198 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003199 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003200 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003201
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003202 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003203}
3204
3205void Context::framebufferRenderbuffer(GLenum target,
3206 GLenum attachment,
3207 GLenum renderbuffertarget,
3208 GLuint renderbuffer)
3209{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003210 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003211 ASSERT(framebuffer);
3212
3213 if (renderbuffer != 0)
3214 {
3215 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003216
3217 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003218 renderbufferObject);
3219 }
3220 else
3221 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003222 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003223 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003224
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003225 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003226}
3227
3228void Context::framebufferTextureLayer(GLenum target,
3229 GLenum attachment,
3230 GLuint texture,
3231 GLint level,
3232 GLint layer)
3233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003234 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003235 ASSERT(framebuffer);
3236
3237 if (texture != 0)
3238 {
3239 Texture *textureObject = getTexture(texture);
3240
3241 ImageIndex index = ImageIndex::MakeInvalid();
3242
Corentin Wallez99d492c2018-02-27 15:17:10 -05003243 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003244 {
3245 index = ImageIndex::Make3D(level, layer);
3246 }
3247 else
3248 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003249 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003250 index = ImageIndex::Make2DArray(level, layer);
3251 }
3252
Jamie Madilla02315b2017-02-23 14:14:47 -05003253 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003254 }
3255 else
3256 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003257 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003258 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003259
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003260 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003261}
3262
Martin Radev137032d2017-07-13 10:11:12 +03003263void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3264 GLenum attachment,
3265 GLuint texture,
3266 GLint level,
3267 GLint baseViewIndex,
3268 GLsizei numViews)
3269{
Martin Radev82ef7742017-08-08 17:44:58 +03003270 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3271 ASSERT(framebuffer);
3272
3273 if (texture != 0)
3274 {
3275 Texture *textureObj = getTexture(texture);
3276
Martin Radev18b75ba2017-08-15 15:50:40 +03003277 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003278 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3279 numViews, baseViewIndex);
3280 }
3281 else
3282 {
3283 framebuffer->resetAttachment(this, attachment);
3284 }
3285
3286 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003287}
3288
3289void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3290 GLenum attachment,
3291 GLuint texture,
3292 GLint level,
3293 GLsizei numViews,
3294 const GLint *viewportOffsets)
3295{
Martin Radev5dae57b2017-07-14 16:15:55 +03003296 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3297 ASSERT(framebuffer);
3298
3299 if (texture != 0)
3300 {
3301 Texture *textureObj = getTexture(texture);
3302
3303 ImageIndex index = ImageIndex::Make2D(level);
3304 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3305 textureObj, numViews, viewportOffsets);
3306 }
3307 else
3308 {
3309 framebuffer->resetAttachment(this, attachment);
3310 }
3311
3312 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003313}
3314
Jamie Madillc29968b2016-01-20 11:17:23 -05003315void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3316{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003317 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003318 ASSERT(framebuffer);
3319 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003320 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003321}
3322
3323void Context::readBuffer(GLenum mode)
3324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003325 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003326 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003327 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003328}
3329
3330void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3331{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003332 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003333 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003334
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003335 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003336 ASSERT(framebuffer);
3337
3338 // The specification isn't clear what should be done when the framebuffer isn't complete.
3339 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003340 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003341}
3342
3343void Context::invalidateFramebuffer(GLenum target,
3344 GLsizei numAttachments,
3345 const GLenum *attachments)
3346{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003347 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003348 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003349
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003350 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003351 ASSERT(framebuffer);
3352
Jamie Madille98b1b52018-03-08 09:47:23 -05003353 bool complete = false;
3354 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3355 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003356 {
Jamie Madill437fa652016-05-03 15:13:24 -04003357 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003358 }
Jamie Madill437fa652016-05-03 15:13:24 -04003359
Jamie Madill4928b7c2017-06-20 12:57:39 -04003360 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003361}
3362
3363void Context::invalidateSubFramebuffer(GLenum target,
3364 GLsizei numAttachments,
3365 const GLenum *attachments,
3366 GLint x,
3367 GLint y,
3368 GLsizei width,
3369 GLsizei height)
3370{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003371 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003372 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003373
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003374 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003375 ASSERT(framebuffer);
3376
Jamie Madille98b1b52018-03-08 09:47:23 -05003377 bool complete = false;
3378 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3379 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003380 {
Jamie Madill437fa652016-05-03 15:13:24 -04003381 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003382 }
Jamie Madill437fa652016-05-03 15:13:24 -04003383
3384 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003385 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003386}
3387
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003388void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003389 GLint level,
3390 GLint internalformat,
3391 GLsizei width,
3392 GLsizei height,
3393 GLint border,
3394 GLenum format,
3395 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003396 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003397{
Jamie Madillbc918e72018-03-08 09:47:21 -05003398 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003399
3400 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003401 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003402 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3403 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003404}
3405
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003406void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003407 GLint level,
3408 GLint internalformat,
3409 GLsizei width,
3410 GLsizei height,
3411 GLsizei depth,
3412 GLint border,
3413 GLenum format,
3414 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003415 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003416{
Jamie Madillbc918e72018-03-08 09:47:21 -05003417 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003418
3419 Extents size(width, height, depth);
3420 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003421 handleError(texture->setImage(this, mGLState.getUnpackState(),
3422 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3423 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003424}
3425
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003426void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003427 GLint level,
3428 GLint xoffset,
3429 GLint yoffset,
3430 GLsizei width,
3431 GLsizei height,
3432 GLenum format,
3433 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003434 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003435{
3436 // Zero sized uploads are valid but no-ops
3437 if (width == 0 || height == 0)
3438 {
3439 return;
3440 }
3441
Jamie Madillbc918e72018-03-08 09:47:21 -05003442 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003443
3444 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003445 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003446 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3447 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003448}
3449
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003450void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003451 GLint level,
3452 GLint xoffset,
3453 GLint yoffset,
3454 GLint zoffset,
3455 GLsizei width,
3456 GLsizei height,
3457 GLsizei depth,
3458 GLenum format,
3459 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003460 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003461{
3462 // Zero sized uploads are valid but no-ops
3463 if (width == 0 || height == 0 || depth == 0)
3464 {
3465 return;
3466 }
3467
Jamie Madillbc918e72018-03-08 09:47:21 -05003468 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003469
3470 Box area(xoffset, yoffset, zoffset, width, height, depth);
3471 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003472 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3473 NonCubeTextureTypeToTarget(target), level, area, format, type,
3474 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003475}
3476
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003477void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003478 GLint level,
3479 GLenum internalformat,
3480 GLsizei width,
3481 GLsizei height,
3482 GLint border,
3483 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003484 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003485{
Jamie Madillbc918e72018-03-08 09:47:21 -05003486 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003487
3488 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003489 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003490 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3491 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003492 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003493}
3494
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003495void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003496 GLint level,
3497 GLenum internalformat,
3498 GLsizei width,
3499 GLsizei height,
3500 GLsizei depth,
3501 GLint border,
3502 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003503 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003504{
Jamie Madillbc918e72018-03-08 09:47:21 -05003505 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003506
3507 Extents size(width, height, depth);
3508 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003509 handleError(texture->setCompressedImage(
3510 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3511 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003512}
3513
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003514void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003515 GLint level,
3516 GLint xoffset,
3517 GLint yoffset,
3518 GLsizei width,
3519 GLsizei height,
3520 GLenum format,
3521 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003522 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003523{
Jamie Madillbc918e72018-03-08 09:47:21 -05003524 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003525
3526 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003527 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003528 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3529 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003530 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003531}
3532
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003533void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003534 GLint level,
3535 GLint xoffset,
3536 GLint yoffset,
3537 GLint zoffset,
3538 GLsizei width,
3539 GLsizei height,
3540 GLsizei depth,
3541 GLenum format,
3542 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003543 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003544{
3545 // Zero sized uploads are valid but no-ops
3546 if (width == 0 || height == 0)
3547 {
3548 return;
3549 }
3550
Jamie Madillbc918e72018-03-08 09:47:21 -05003551 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003552
3553 Box area(xoffset, yoffset, zoffset, width, height, depth);
3554 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003555 handleError(texture->setCompressedSubImage(
3556 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3557 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003558}
3559
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003560void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003561{
3562 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003563 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003564}
3565
Jamie Madill007530e2017-12-28 14:27:04 -05003566void Context::copyTexture(GLuint sourceId,
3567 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003568 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003569 GLuint destId,
3570 GLint destLevel,
3571 GLint internalFormat,
3572 GLenum destType,
3573 GLboolean unpackFlipY,
3574 GLboolean unpackPremultiplyAlpha,
3575 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003576{
Jamie Madillbc918e72018-03-08 09:47:21 -05003577 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003578
3579 gl::Texture *sourceTexture = getTexture(sourceId);
3580 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003581 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3582 sourceLevel, ConvertToBool(unpackFlipY),
3583 ConvertToBool(unpackPremultiplyAlpha),
3584 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003585}
3586
Jamie Madill007530e2017-12-28 14:27:04 -05003587void Context::copySubTexture(GLuint sourceId,
3588 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003589 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003590 GLuint destId,
3591 GLint destLevel,
3592 GLint xoffset,
3593 GLint yoffset,
3594 GLint x,
3595 GLint y,
3596 GLsizei width,
3597 GLsizei height,
3598 GLboolean unpackFlipY,
3599 GLboolean unpackPremultiplyAlpha,
3600 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003601{
3602 // Zero sized copies are valid but no-ops
3603 if (width == 0 || height == 0)
3604 {
3605 return;
3606 }
3607
Jamie Madillbc918e72018-03-08 09:47:21 -05003608 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003609
3610 gl::Texture *sourceTexture = getTexture(sourceId);
3611 gl::Texture *destTexture = getTexture(destId);
3612 Offset offset(xoffset, yoffset, 0);
3613 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003614 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3615 ConvertToBool(unpackFlipY),
3616 ConvertToBool(unpackPremultiplyAlpha),
3617 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003618}
3619
Jamie Madill007530e2017-12-28 14:27:04 -05003620void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003621{
Jamie Madillbc918e72018-03-08 09:47:21 -05003622 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003623
3624 gl::Texture *sourceTexture = getTexture(sourceId);
3625 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003626 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003627}
3628
Corentin Wallez336129f2017-10-17 15:55:40 -04003629void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003632 ASSERT(buffer);
3633
Geoff Lang496c02d2016-10-20 11:38:11 -07003634 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003635}
3636
Corentin Wallez336129f2017-10-17 15:55:40 -04003637void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003640 ASSERT(buffer);
3641
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003642 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003643 if (error.isError())
3644 {
Jamie Madill437fa652016-05-03 15:13:24 -04003645 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003646 return nullptr;
3647 }
3648
3649 return buffer->getMapPointer();
3650}
3651
Corentin Wallez336129f2017-10-17 15:55:40 -04003652GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003655 ASSERT(buffer);
3656
3657 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003658 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003659 if (error.isError())
3660 {
Jamie Madill437fa652016-05-03 15:13:24 -04003661 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003662 return GL_FALSE;
3663 }
3664
3665 return result;
3666}
3667
Corentin Wallez336129f2017-10-17 15:55:40 -04003668void *Context::mapBufferRange(BufferBinding target,
3669 GLintptr offset,
3670 GLsizeiptr length,
3671 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003672{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003673 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003674 ASSERT(buffer);
3675
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003676 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003677 if (error.isError())
3678 {
Jamie Madill437fa652016-05-03 15:13:24 -04003679 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003680 return nullptr;
3681 }
3682
3683 return buffer->getMapPointer();
3684}
3685
Corentin Wallez336129f2017-10-17 15:55:40 -04003686void Context::flushMappedBufferRange(BufferBinding /*target*/,
3687 GLintptr /*offset*/,
3688 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003689{
3690 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3691}
3692
Jamie Madillbc918e72018-03-08 09:47:21 -05003693Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003694{
Geoff Langa8cb2872018-03-09 16:09:40 -05003695 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003696}
3697
Jamie Madillbc918e72018-03-08 09:47:21 -05003698Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003699{
Geoff Langa8cb2872018-03-09 16:09:40 -05003700 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003701}
3702
Jamie Madillbc918e72018-03-08 09:47:21 -05003703Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003704{
Geoff Langa8cb2872018-03-09 16:09:40 -05003705 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003706}
3707
Jiajia Qin5451d532017-11-16 17:16:34 +08003708void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3709{
3710 UNIMPLEMENTED();
3711}
3712
Jamie Madillc20ab272016-06-09 07:20:46 -07003713void Context::activeTexture(GLenum texture)
3714{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716}
3717
Jamie Madill876429b2017-04-20 15:46:24 -04003718void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003719{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003721}
3722
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003723void Context::blendEquation(GLenum mode)
3724{
3725 mGLState.setBlendEquation(mode, mode);
3726}
3727
Jamie Madillc20ab272016-06-09 07:20:46 -07003728void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003733void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3734{
3735 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3736}
3737
Jamie Madillc20ab272016-06-09 07:20:46 -07003738void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741}
3742
Jamie Madill876429b2017-04-20 15:46:24 -04003743void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
Jamie Madill876429b2017-04-20 15:46:24 -04003748void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
3753void Context::clearStencil(GLint s)
3754{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003755 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003756}
3757
3758void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3759{
Geoff Lang92019432017-11-20 13:09:34 -05003760 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3761 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003762}
3763
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003764void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003765{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003766 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003767}
3768
3769void Context::depthFunc(GLenum func)
3770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772}
3773
3774void Context::depthMask(GLboolean flag)
3775{
Geoff Lang92019432017-11-20 13:09:34 -05003776 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003777}
3778
Jamie Madill876429b2017-04-20 15:46:24 -04003779void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003780{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::disable(GLenum cap)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::disableVertexAttribArray(GLuint index)
3790{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003792}
3793
3794void Context::enable(GLenum cap)
3795{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::enableVertexAttribArray(GLuint index)
3800{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802}
3803
3804void Context::frontFace(GLenum mode)
3805{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003806 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003807}
3808
3809void Context::hint(GLenum target, GLenum mode)
3810{
3811 switch (target)
3812 {
3813 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815 break;
3816
3817 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003819 break;
3820
3821 default:
3822 UNREACHABLE();
3823 return;
3824 }
3825}
3826
3827void Context::lineWidth(GLfloat width)
3828{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003829 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003830}
3831
3832void Context::pixelStorei(GLenum pname, GLint param)
3833{
3834 switch (pname)
3835 {
3836 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003838 break;
3839
3840 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003842 break;
3843
3844 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 break;
3847
3848 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003849 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851 break;
3852
3853 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003854 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856 break;
3857
3858 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003859 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861 break;
3862
3863 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003864 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866 break;
3867
3868 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003869 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003871 break;
3872
3873 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003874 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003876 break;
3877
3878 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003879 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003880 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003881 break;
3882
3883 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003884 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003885 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003886 break;
3887
3888 default:
3889 UNREACHABLE();
3890 return;
3891 }
3892}
3893
3894void Context::polygonOffset(GLfloat factor, GLfloat units)
3895{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003896 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
Jamie Madill876429b2017-04-20 15:46:24 -04003899void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003900{
Geoff Lang92019432017-11-20 13:09:34 -05003901 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003902}
3903
Jiawei Shaodb342272017-09-27 10:21:45 +08003904void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3905{
3906 mGLState.setSampleMaskParams(maskNumber, mask);
3907}
3908
Jamie Madillc20ab272016-06-09 07:20:46 -07003909void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3910{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003911 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003912}
3913
3914void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3915{
3916 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3917 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003918 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003919 }
3920
3921 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3922 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003923 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003924 }
3925}
3926
3927void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3928{
3929 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3930 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003931 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003932 }
3933
3934 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3935 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003936 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003937 }
3938}
3939
3940void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3941{
3942 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3943 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003944 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003945 }
3946
3947 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3948 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003949 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003950 }
3951}
3952
3953void Context::vertexAttrib1f(GLuint index, GLfloat x)
3954{
3955 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003956 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003957}
3958
3959void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3960{
3961 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003962 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003963}
3964
3965void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3966{
3967 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003969}
3970
3971void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3972{
3973 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003974 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003975}
3976
3977void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3978{
3979 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003980 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003981}
3982
3983void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3984{
3985 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003986 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003987}
3988
3989void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3990{
3991 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003993}
3994
3995void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3996{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003997 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003998}
3999
4000void Context::vertexAttribPointer(GLuint index,
4001 GLint size,
4002 GLenum type,
4003 GLboolean normalized,
4004 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004005 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004006{
Corentin Wallez336129f2017-10-17 15:55:40 -04004007 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004008 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004009}
4010
Shao80957d92017-02-20 21:25:59 +08004011void Context::vertexAttribFormat(GLuint attribIndex,
4012 GLint size,
4013 GLenum type,
4014 GLboolean normalized,
4015 GLuint relativeOffset)
4016{
Geoff Lang92019432017-11-20 13:09:34 -05004017 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004018 relativeOffset);
4019}
4020
4021void Context::vertexAttribIFormat(GLuint attribIndex,
4022 GLint size,
4023 GLenum type,
4024 GLuint relativeOffset)
4025{
4026 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4027}
4028
4029void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4030{
Shaodde78e82017-05-22 14:13:27 +08004031 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004032}
4033
Jiajia Qin5451d532017-11-16 17:16:34 +08004034void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004035{
4036 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4037}
4038
Jamie Madillc20ab272016-06-09 07:20:46 -07004039void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4040{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004041 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004042}
4043
4044void Context::vertexAttribIPointer(GLuint index,
4045 GLint size,
4046 GLenum type,
4047 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004048 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004049{
Corentin Wallez336129f2017-10-17 15:55:40 -04004050 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4051 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004052}
4053
4054void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4055{
4056 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004057 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004058}
4059
4060void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4061{
4062 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004063 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004064}
4065
4066void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4067{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004068 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004069}
4070
4071void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4072{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004073 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004074}
4075
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004076void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4077{
4078 const VertexAttribCurrentValueData &currentValues =
4079 getGLState().getVertexAttribCurrentValue(index);
4080 const VertexArray *vao = getGLState().getVertexArray();
4081 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4082 currentValues, pname, params);
4083}
4084
4085void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4086{
4087 const VertexAttribCurrentValueData &currentValues =
4088 getGLState().getVertexAttribCurrentValue(index);
4089 const VertexArray *vao = getGLState().getVertexArray();
4090 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4091 currentValues, pname, params);
4092}
4093
4094void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4095{
4096 const VertexAttribCurrentValueData &currentValues =
4097 getGLState().getVertexAttribCurrentValue(index);
4098 const VertexArray *vao = getGLState().getVertexArray();
4099 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4100 currentValues, pname, params);
4101}
4102
4103void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4104{
4105 const VertexAttribCurrentValueData &currentValues =
4106 getGLState().getVertexAttribCurrentValue(index);
4107 const VertexArray *vao = getGLState().getVertexArray();
4108 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4109 currentValues, pname, params);
4110}
4111
Jamie Madill876429b2017-04-20 15:46:24 -04004112void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004113{
4114 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4115 QueryVertexAttribPointerv(attrib, pname, pointer);
4116}
4117
Jamie Madillc20ab272016-06-09 07:20:46 -07004118void Context::debugMessageControl(GLenum source,
4119 GLenum type,
4120 GLenum severity,
4121 GLsizei count,
4122 const GLuint *ids,
4123 GLboolean enabled)
4124{
4125 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004126 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004127 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004128}
4129
4130void Context::debugMessageInsert(GLenum source,
4131 GLenum type,
4132 GLuint id,
4133 GLenum severity,
4134 GLsizei length,
4135 const GLchar *buf)
4136{
4137 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004138 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004139}
4140
4141void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4142{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004143 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004144}
4145
4146GLuint Context::getDebugMessageLog(GLuint count,
4147 GLsizei bufSize,
4148 GLenum *sources,
4149 GLenum *types,
4150 GLuint *ids,
4151 GLenum *severities,
4152 GLsizei *lengths,
4153 GLchar *messageLog)
4154{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004155 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4156 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004157}
4158
4159void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4160{
4161 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004162 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004163 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004164}
4165
4166void Context::popDebugGroup()
4167{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004168 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004169 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004170}
4171
Corentin Wallez336129f2017-10-17 15:55:40 -04004172void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004173{
4174 Buffer *buffer = mGLState.getTargetBuffer(target);
4175 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004176 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004177}
4178
Corentin Wallez336129f2017-10-17 15:55:40 -04004179void Context::bufferSubData(BufferBinding target,
4180 GLintptr offset,
4181 GLsizeiptr size,
4182 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004183{
4184 if (data == nullptr)
4185 {
4186 return;
4187 }
4188
4189 Buffer *buffer = mGLState.getTargetBuffer(target);
4190 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004191 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004192}
4193
Jamie Madillef300b12016-10-07 15:12:09 -04004194void Context::attachShader(GLuint program, GLuint shader)
4195{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004196 Program *programObject = mState.mShaderPrograms->getProgram(program);
4197 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004198 ASSERT(programObject && shaderObject);
4199 programObject->attachShader(shaderObject);
4200}
4201
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004202const Workarounds &Context::getWorkarounds() const
4203{
4204 return mWorkarounds;
4205}
4206
Corentin Wallez336129f2017-10-17 15:55:40 -04004207void Context::copyBufferSubData(BufferBinding readTarget,
4208 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004209 GLintptr readOffset,
4210 GLintptr writeOffset,
4211 GLsizeiptr size)
4212{
4213 // if size is zero, the copy is a successful no-op
4214 if (size == 0)
4215 {
4216 return;
4217 }
4218
4219 // TODO(jmadill): cache these.
4220 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4221 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4222
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004223 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004224}
4225
Jamie Madill01a80ee2016-11-07 12:06:18 -05004226void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4227{
4228 Program *programObject = getProgram(program);
4229 // TODO(jmadill): Re-use this from the validation if possible.
4230 ASSERT(programObject);
4231 programObject->bindAttributeLocation(index, name);
4232}
4233
Corentin Wallez336129f2017-10-17 15:55:40 -04004234void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004235{
Corentin Wallez336129f2017-10-17 15:55:40 -04004236 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4237 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004238}
4239
Corentin Wallez336129f2017-10-17 15:55:40 -04004240void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004241{
4242 bindBufferRange(target, index, buffer, 0, 0);
4243}
4244
Corentin Wallez336129f2017-10-17 15:55:40 -04004245void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004246 GLuint index,
4247 GLuint buffer,
4248 GLintptr offset,
4249 GLsizeiptr size)
4250{
Corentin Wallez336129f2017-10-17 15:55:40 -04004251 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4252 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004253}
4254
Jamie Madill01a80ee2016-11-07 12:06:18 -05004255void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4256{
4257 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4258 {
4259 bindReadFramebuffer(framebuffer);
4260 }
4261
4262 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4263 {
4264 bindDrawFramebuffer(framebuffer);
4265 }
4266}
4267
4268void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4269{
4270 ASSERT(target == GL_RENDERBUFFER);
4271 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004272 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004273 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004274}
4275
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004276void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004277 GLsizei samples,
4278 GLenum internalformat,
4279 GLsizei width,
4280 GLsizei height,
4281 GLboolean fixedsamplelocations)
4282{
4283 Extents size(width, height, 1);
4284 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004285 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4286 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004287}
4288
4289void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4290{
JiangYizhou5b03f472017-01-09 10:22:53 +08004291 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4292 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004293 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004294 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004295
4296 switch (pname)
4297 {
4298 case GL_SAMPLE_POSITION:
4299 handleError(framebuffer->getSamplePosition(index, val));
4300 break;
4301 default:
4302 UNREACHABLE();
4303 }
4304}
4305
Jamie Madille8fb6402017-02-14 17:56:40 -05004306void Context::renderbufferStorage(GLenum target,
4307 GLenum internalformat,
4308 GLsizei width,
4309 GLsizei height)
4310{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004311 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4312 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4313
Jamie Madille8fb6402017-02-14 17:56:40 -05004314 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004315 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004316}
4317
4318void Context::renderbufferStorageMultisample(GLenum target,
4319 GLsizei samples,
4320 GLenum internalformat,
4321 GLsizei width,
4322 GLsizei height)
4323{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004324 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4325 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004326
4327 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004328 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004329 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004330}
4331
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004332void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4333{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004334 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004335 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004336}
4337
JiangYizhoue18e6392017-02-20 10:32:23 +08004338void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4339{
4340 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4341 QueryFramebufferParameteriv(framebuffer, pname, params);
4342}
4343
Jiajia Qin5451d532017-11-16 17:16:34 +08004344void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004345{
4346 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4347 SetFramebufferParameteri(framebuffer, pname, param);
4348}
4349
Jamie Madillb3f26b92017-07-19 15:07:41 -04004350Error Context::getScratchBuffer(size_t requstedSizeBytes,
4351 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004352{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004353 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4354 {
4355 return OutOfMemory() << "Failed to allocate internal buffer.";
4356 }
4357 return NoError();
4358}
4359
4360Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4361 angle::MemoryBuffer **zeroBufferOut) const
4362{
4363 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004364 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004365 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004366 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004367 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004368}
4369
Xinghua Cao10a4d432017-11-28 14:46:26 +08004370Error Context::prepareForDispatch()
4371{
Geoff Langa8cb2872018-03-09 16:09:40 -05004372 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004373
4374 if (isRobustResourceInitEnabled())
4375 {
4376 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4377 }
4378
4379 return NoError();
4380}
4381
Xinghua Cao2b396592017-03-29 15:36:04 +08004382void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4383{
4384 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4385 {
4386 return;
4387 }
4388
Xinghua Cao10a4d432017-11-28 14:46:26 +08004389 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004390 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004391}
4392
Jiajia Qin5451d532017-11-16 17:16:34 +08004393void Context::dispatchComputeIndirect(GLintptr indirect)
4394{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004395 ANGLE_CONTEXT_TRY(prepareForDispatch());
4396 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004397}
4398
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004399void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004400 GLsizei levels,
4401 GLenum internalFormat,
4402 GLsizei width,
4403 GLsizei height)
4404{
4405 Extents size(width, height, 1);
4406 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004407 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004408}
4409
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004410void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004411 GLsizei levels,
4412 GLenum internalFormat,
4413 GLsizei width,
4414 GLsizei height,
4415 GLsizei depth)
4416{
4417 Extents size(width, height, depth);
4418 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004419 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004420}
4421
Jiajia Qin5451d532017-11-16 17:16:34 +08004422void Context::memoryBarrier(GLbitfield barriers)
4423{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004424 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004425}
4426
4427void Context::memoryBarrierByRegion(GLbitfield barriers)
4428{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004429 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004430}
4431
Jamie Madillc1d770e2017-04-13 17:31:24 -04004432GLenum Context::checkFramebufferStatus(GLenum target)
4433{
4434 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4435 ASSERT(framebuffer);
4436
Jamie Madille98b1b52018-03-08 09:47:23 -05004437 GLenum status = GL_NONE;
4438 Error err = framebuffer->checkStatus(this, &status);
4439 if (err.isError())
4440 {
4441 handleError(err);
4442 return 0;
4443 }
4444 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004445}
4446
4447void Context::compileShader(GLuint shader)
4448{
4449 Shader *shaderObject = GetValidShader(this, shader);
4450 if (!shaderObject)
4451 {
4452 return;
4453 }
4454 shaderObject->compile(this);
4455}
4456
4457void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4458{
4459 for (int i = 0; i < n; i++)
4460 {
4461 deleteBuffer(buffers[i]);
4462 }
4463}
4464
4465void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4466{
4467 for (int i = 0; i < n; i++)
4468 {
4469 if (framebuffers[i] != 0)
4470 {
4471 deleteFramebuffer(framebuffers[i]);
4472 }
4473 }
4474}
4475
4476void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4477{
4478 for (int i = 0; i < n; i++)
4479 {
4480 deleteRenderbuffer(renderbuffers[i]);
4481 }
4482}
4483
4484void Context::deleteTextures(GLsizei n, const GLuint *textures)
4485{
4486 for (int i = 0; i < n; i++)
4487 {
4488 if (textures[i] != 0)
4489 {
4490 deleteTexture(textures[i]);
4491 }
4492 }
4493}
4494
4495void Context::detachShader(GLuint program, GLuint shader)
4496{
4497 Program *programObject = getProgram(program);
4498 ASSERT(programObject);
4499
4500 Shader *shaderObject = getShader(shader);
4501 ASSERT(shaderObject);
4502
4503 programObject->detachShader(this, shaderObject);
4504}
4505
4506void Context::genBuffers(GLsizei n, GLuint *buffers)
4507{
4508 for (int i = 0; i < n; i++)
4509 {
4510 buffers[i] = createBuffer();
4511 }
4512}
4513
4514void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4515{
4516 for (int i = 0; i < n; i++)
4517 {
4518 framebuffers[i] = createFramebuffer();
4519 }
4520}
4521
4522void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4523{
4524 for (int i = 0; i < n; i++)
4525 {
4526 renderbuffers[i] = createRenderbuffer();
4527 }
4528}
4529
4530void Context::genTextures(GLsizei n, GLuint *textures)
4531{
4532 for (int i = 0; i < n; i++)
4533 {
4534 textures[i] = createTexture();
4535 }
4536}
4537
4538void Context::getActiveAttrib(GLuint program,
4539 GLuint index,
4540 GLsizei bufsize,
4541 GLsizei *length,
4542 GLint *size,
4543 GLenum *type,
4544 GLchar *name)
4545{
4546 Program *programObject = getProgram(program);
4547 ASSERT(programObject);
4548 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4549}
4550
4551void Context::getActiveUniform(GLuint program,
4552 GLuint index,
4553 GLsizei bufsize,
4554 GLsizei *length,
4555 GLint *size,
4556 GLenum *type,
4557 GLchar *name)
4558{
4559 Program *programObject = getProgram(program);
4560 ASSERT(programObject);
4561 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4562}
4563
4564void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4565{
4566 Program *programObject = getProgram(program);
4567 ASSERT(programObject);
4568 programObject->getAttachedShaders(maxcount, count, shaders);
4569}
4570
4571GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4572{
4573 Program *programObject = getProgram(program);
4574 ASSERT(programObject);
4575 return programObject->getAttributeLocation(name);
4576}
4577
4578void Context::getBooleanv(GLenum pname, GLboolean *params)
4579{
4580 GLenum nativeType;
4581 unsigned int numParams = 0;
4582 getQueryParameterInfo(pname, &nativeType, &numParams);
4583
4584 if (nativeType == GL_BOOL)
4585 {
4586 getBooleanvImpl(pname, params);
4587 }
4588 else
4589 {
4590 CastStateValues(this, nativeType, pname, numParams, params);
4591 }
4592}
4593
4594void Context::getFloatv(GLenum pname, GLfloat *params)
4595{
4596 GLenum nativeType;
4597 unsigned int numParams = 0;
4598 getQueryParameterInfo(pname, &nativeType, &numParams);
4599
4600 if (nativeType == GL_FLOAT)
4601 {
4602 getFloatvImpl(pname, params);
4603 }
4604 else
4605 {
4606 CastStateValues(this, nativeType, pname, numParams, params);
4607 }
4608}
4609
4610void Context::getIntegerv(GLenum pname, GLint *params)
4611{
4612 GLenum nativeType;
4613 unsigned int numParams = 0;
4614 getQueryParameterInfo(pname, &nativeType, &numParams);
4615
4616 if (nativeType == GL_INT)
4617 {
4618 getIntegervImpl(pname, params);
4619 }
4620 else
4621 {
4622 CastStateValues(this, nativeType, pname, numParams, params);
4623 }
4624}
4625
4626void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4627{
4628 Program *programObject = getProgram(program);
4629 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004630 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004631}
4632
Jiajia Qin5451d532017-11-16 17:16:34 +08004633void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4634{
4635 UNIMPLEMENTED();
4636}
4637
Jamie Madillbe849e42017-05-02 15:49:00 -04004638void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004639{
4640 Program *programObject = getProgram(program);
4641 ASSERT(programObject);
4642 programObject->getInfoLog(bufsize, length, infolog);
4643}
4644
Jiajia Qin5451d532017-11-16 17:16:34 +08004645void Context::getProgramPipelineInfoLog(GLuint pipeline,
4646 GLsizei bufSize,
4647 GLsizei *length,
4648 GLchar *infoLog)
4649{
4650 UNIMPLEMENTED();
4651}
4652
Jamie Madillc1d770e2017-04-13 17:31:24 -04004653void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4654{
4655 Shader *shaderObject = getShader(shader);
4656 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004657 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004658}
4659
4660void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4661{
4662 Shader *shaderObject = getShader(shader);
4663 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004664 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004665}
4666
4667void Context::getShaderPrecisionFormat(GLenum shadertype,
4668 GLenum precisiontype,
4669 GLint *range,
4670 GLint *precision)
4671{
4672 // TODO(jmadill): Compute shaders.
4673
4674 switch (shadertype)
4675 {
4676 case GL_VERTEX_SHADER:
4677 switch (precisiontype)
4678 {
4679 case GL_LOW_FLOAT:
4680 mCaps.vertexLowpFloat.get(range, precision);
4681 break;
4682 case GL_MEDIUM_FLOAT:
4683 mCaps.vertexMediumpFloat.get(range, precision);
4684 break;
4685 case GL_HIGH_FLOAT:
4686 mCaps.vertexHighpFloat.get(range, precision);
4687 break;
4688
4689 case GL_LOW_INT:
4690 mCaps.vertexLowpInt.get(range, precision);
4691 break;
4692 case GL_MEDIUM_INT:
4693 mCaps.vertexMediumpInt.get(range, precision);
4694 break;
4695 case GL_HIGH_INT:
4696 mCaps.vertexHighpInt.get(range, precision);
4697 break;
4698
4699 default:
4700 UNREACHABLE();
4701 return;
4702 }
4703 break;
4704
4705 case GL_FRAGMENT_SHADER:
4706 switch (precisiontype)
4707 {
4708 case GL_LOW_FLOAT:
4709 mCaps.fragmentLowpFloat.get(range, precision);
4710 break;
4711 case GL_MEDIUM_FLOAT:
4712 mCaps.fragmentMediumpFloat.get(range, precision);
4713 break;
4714 case GL_HIGH_FLOAT:
4715 mCaps.fragmentHighpFloat.get(range, precision);
4716 break;
4717
4718 case GL_LOW_INT:
4719 mCaps.fragmentLowpInt.get(range, precision);
4720 break;
4721 case GL_MEDIUM_INT:
4722 mCaps.fragmentMediumpInt.get(range, precision);
4723 break;
4724 case GL_HIGH_INT:
4725 mCaps.fragmentHighpInt.get(range, precision);
4726 break;
4727
4728 default:
4729 UNREACHABLE();
4730 return;
4731 }
4732 break;
4733
4734 default:
4735 UNREACHABLE();
4736 return;
4737 }
4738}
4739
4740void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4741{
4742 Shader *shaderObject = getShader(shader);
4743 ASSERT(shaderObject);
4744 shaderObject->getSource(bufsize, length, source);
4745}
4746
4747void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4748{
4749 Program *programObject = getProgram(program);
4750 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004751 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004752}
4753
4754void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4755{
4756 Program *programObject = getProgram(program);
4757 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004758 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004759}
4760
4761GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4762{
4763 Program *programObject = getProgram(program);
4764 ASSERT(programObject);
4765 return programObject->getUniformLocation(name);
4766}
4767
4768GLboolean Context::isBuffer(GLuint buffer)
4769{
4770 if (buffer == 0)
4771 {
4772 return GL_FALSE;
4773 }
4774
4775 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4776}
4777
4778GLboolean Context::isEnabled(GLenum cap)
4779{
4780 return mGLState.getEnableFeature(cap);
4781}
4782
4783GLboolean Context::isFramebuffer(GLuint framebuffer)
4784{
4785 if (framebuffer == 0)
4786 {
4787 return GL_FALSE;
4788 }
4789
4790 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4791}
4792
4793GLboolean Context::isProgram(GLuint program)
4794{
4795 if (program == 0)
4796 {
4797 return GL_FALSE;
4798 }
4799
4800 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4801}
4802
4803GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4804{
4805 if (renderbuffer == 0)
4806 {
4807 return GL_FALSE;
4808 }
4809
4810 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4811}
4812
4813GLboolean Context::isShader(GLuint shader)
4814{
4815 if (shader == 0)
4816 {
4817 return GL_FALSE;
4818 }
4819
4820 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4821}
4822
4823GLboolean Context::isTexture(GLuint texture)
4824{
4825 if (texture == 0)
4826 {
4827 return GL_FALSE;
4828 }
4829
4830 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4831}
4832
4833void Context::linkProgram(GLuint program)
4834{
4835 Program *programObject = getProgram(program);
4836 ASSERT(programObject);
4837 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004838 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004839}
4840
4841void Context::releaseShaderCompiler()
4842{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004843 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004844}
4845
4846void Context::shaderBinary(GLsizei n,
4847 const GLuint *shaders,
4848 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004849 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004850 GLsizei length)
4851{
4852 // No binary shader formats are supported.
4853 UNIMPLEMENTED();
4854}
4855
4856void Context::shaderSource(GLuint shader,
4857 GLsizei count,
4858 const GLchar *const *string,
4859 const GLint *length)
4860{
4861 Shader *shaderObject = getShader(shader);
4862 ASSERT(shaderObject);
4863 shaderObject->setSource(count, string, length);
4864}
4865
4866void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4867{
4868 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4869}
4870
4871void Context::stencilMask(GLuint mask)
4872{
4873 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4874}
4875
4876void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4877{
4878 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4879}
4880
4881void Context::uniform1f(GLint location, GLfloat x)
4882{
4883 Program *program = mGLState.getProgram();
4884 program->setUniform1fv(location, 1, &x);
4885}
4886
4887void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4888{
4889 Program *program = mGLState.getProgram();
4890 program->setUniform1fv(location, count, v);
4891}
4892
4893void Context::uniform1i(GLint location, GLint x)
4894{
4895 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004896 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4897 {
4898 mGLState.setObjectDirty(GL_PROGRAM);
4899 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004900}
4901
4902void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4903{
4904 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004905 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4906 {
4907 mGLState.setObjectDirty(GL_PROGRAM);
4908 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004909}
4910
4911void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4912{
4913 GLfloat xy[2] = {x, y};
4914 Program *program = mGLState.getProgram();
4915 program->setUniform2fv(location, 1, xy);
4916}
4917
4918void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4919{
4920 Program *program = mGLState.getProgram();
4921 program->setUniform2fv(location, count, v);
4922}
4923
4924void Context::uniform2i(GLint location, GLint x, GLint y)
4925{
4926 GLint xy[2] = {x, y};
4927 Program *program = mGLState.getProgram();
4928 program->setUniform2iv(location, 1, xy);
4929}
4930
4931void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4932{
4933 Program *program = mGLState.getProgram();
4934 program->setUniform2iv(location, count, v);
4935}
4936
4937void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4938{
4939 GLfloat xyz[3] = {x, y, z};
4940 Program *program = mGLState.getProgram();
4941 program->setUniform3fv(location, 1, xyz);
4942}
4943
4944void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4945{
4946 Program *program = mGLState.getProgram();
4947 program->setUniform3fv(location, count, v);
4948}
4949
4950void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4951{
4952 GLint xyz[3] = {x, y, z};
4953 Program *program = mGLState.getProgram();
4954 program->setUniform3iv(location, 1, xyz);
4955}
4956
4957void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4958{
4959 Program *program = mGLState.getProgram();
4960 program->setUniform3iv(location, count, v);
4961}
4962
4963void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4964{
4965 GLfloat xyzw[4] = {x, y, z, w};
4966 Program *program = mGLState.getProgram();
4967 program->setUniform4fv(location, 1, xyzw);
4968}
4969
4970void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4971{
4972 Program *program = mGLState.getProgram();
4973 program->setUniform4fv(location, count, v);
4974}
4975
4976void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4977{
4978 GLint xyzw[4] = {x, y, z, w};
4979 Program *program = mGLState.getProgram();
4980 program->setUniform4iv(location, 1, xyzw);
4981}
4982
4983void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4984{
4985 Program *program = mGLState.getProgram();
4986 program->setUniform4iv(location, count, v);
4987}
4988
4989void Context::uniformMatrix2fv(GLint location,
4990 GLsizei count,
4991 GLboolean transpose,
4992 const GLfloat *value)
4993{
4994 Program *program = mGLState.getProgram();
4995 program->setUniformMatrix2fv(location, count, transpose, value);
4996}
4997
4998void Context::uniformMatrix3fv(GLint location,
4999 GLsizei count,
5000 GLboolean transpose,
5001 const GLfloat *value)
5002{
5003 Program *program = mGLState.getProgram();
5004 program->setUniformMatrix3fv(location, count, transpose, value);
5005}
5006
5007void Context::uniformMatrix4fv(GLint location,
5008 GLsizei count,
5009 GLboolean transpose,
5010 const GLfloat *value)
5011{
5012 Program *program = mGLState.getProgram();
5013 program->setUniformMatrix4fv(location, count, transpose, value);
5014}
5015
5016void Context::validateProgram(GLuint program)
5017{
5018 Program *programObject = getProgram(program);
5019 ASSERT(programObject);
5020 programObject->validate(mCaps);
5021}
5022
Jiajia Qin5451d532017-11-16 17:16:34 +08005023void Context::validateProgramPipeline(GLuint pipeline)
5024{
5025 UNIMPLEMENTED();
5026}
5027
Jamie Madilld04908b2017-06-09 14:15:35 -04005028void Context::getProgramBinary(GLuint program,
5029 GLsizei bufSize,
5030 GLsizei *length,
5031 GLenum *binaryFormat,
5032 void *binary)
5033{
5034 Program *programObject = getProgram(program);
5035 ASSERT(programObject != nullptr);
5036
5037 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5038}
5039
5040void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5041{
5042 Program *programObject = getProgram(program);
5043 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005044
Jamie Madilld04908b2017-06-09 14:15:35 -04005045 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5046}
5047
Jamie Madillff325f12017-08-26 15:06:05 -04005048void Context::uniform1ui(GLint location, GLuint v0)
5049{
5050 Program *program = mGLState.getProgram();
5051 program->setUniform1uiv(location, 1, &v0);
5052}
5053
5054void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5055{
5056 Program *program = mGLState.getProgram();
5057 const GLuint xy[] = {v0, v1};
5058 program->setUniform2uiv(location, 1, xy);
5059}
5060
5061void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5062{
5063 Program *program = mGLState.getProgram();
5064 const GLuint xyz[] = {v0, v1, v2};
5065 program->setUniform3uiv(location, 1, xyz);
5066}
5067
5068void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5069{
5070 Program *program = mGLState.getProgram();
5071 const GLuint xyzw[] = {v0, v1, v2, v3};
5072 program->setUniform4uiv(location, 1, xyzw);
5073}
5074
5075void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5076{
5077 Program *program = mGLState.getProgram();
5078 program->setUniform1uiv(location, count, value);
5079}
5080void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5081{
5082 Program *program = mGLState.getProgram();
5083 program->setUniform2uiv(location, count, value);
5084}
5085
5086void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5087{
5088 Program *program = mGLState.getProgram();
5089 program->setUniform3uiv(location, count, value);
5090}
5091
5092void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5093{
5094 Program *program = mGLState.getProgram();
5095 program->setUniform4uiv(location, count, value);
5096}
5097
Jamie Madillf0e04492017-08-26 15:28:42 -04005098void Context::genQueries(GLsizei n, GLuint *ids)
5099{
5100 for (GLsizei i = 0; i < n; i++)
5101 {
5102 GLuint handle = mQueryHandleAllocator.allocate();
5103 mQueryMap.assign(handle, nullptr);
5104 ids[i] = handle;
5105 }
5106}
5107
5108void Context::deleteQueries(GLsizei n, const GLuint *ids)
5109{
5110 for (int i = 0; i < n; i++)
5111 {
5112 GLuint query = ids[i];
5113
5114 Query *queryObject = nullptr;
5115 if (mQueryMap.erase(query, &queryObject))
5116 {
5117 mQueryHandleAllocator.release(query);
5118 if (queryObject)
5119 {
5120 queryObject->release(this);
5121 }
5122 }
5123 }
5124}
5125
5126GLboolean Context::isQuery(GLuint id)
5127{
5128 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5129}
5130
Jamie Madillc8c95812017-08-26 18:40:09 -04005131void Context::uniformMatrix2x3fv(GLint location,
5132 GLsizei count,
5133 GLboolean transpose,
5134 const GLfloat *value)
5135{
5136 Program *program = mGLState.getProgram();
5137 program->setUniformMatrix2x3fv(location, count, transpose, value);
5138}
5139
5140void Context::uniformMatrix3x2fv(GLint location,
5141 GLsizei count,
5142 GLboolean transpose,
5143 const GLfloat *value)
5144{
5145 Program *program = mGLState.getProgram();
5146 program->setUniformMatrix3x2fv(location, count, transpose, value);
5147}
5148
5149void Context::uniformMatrix2x4fv(GLint location,
5150 GLsizei count,
5151 GLboolean transpose,
5152 const GLfloat *value)
5153{
5154 Program *program = mGLState.getProgram();
5155 program->setUniformMatrix2x4fv(location, count, transpose, value);
5156}
5157
5158void Context::uniformMatrix4x2fv(GLint location,
5159 GLsizei count,
5160 GLboolean transpose,
5161 const GLfloat *value)
5162{
5163 Program *program = mGLState.getProgram();
5164 program->setUniformMatrix4x2fv(location, count, transpose, value);
5165}
5166
5167void Context::uniformMatrix3x4fv(GLint location,
5168 GLsizei count,
5169 GLboolean transpose,
5170 const GLfloat *value)
5171{
5172 Program *program = mGLState.getProgram();
5173 program->setUniformMatrix3x4fv(location, count, transpose, value);
5174}
5175
5176void Context::uniformMatrix4x3fv(GLint location,
5177 GLsizei count,
5178 GLboolean transpose,
5179 const GLfloat *value)
5180{
5181 Program *program = mGLState.getProgram();
5182 program->setUniformMatrix4x3fv(location, count, transpose, value);
5183}
5184
Jamie Madilld7576732017-08-26 18:49:50 -04005185void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5186{
5187 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5188 {
5189 GLuint vertexArray = arrays[arrayIndex];
5190
5191 if (arrays[arrayIndex] != 0)
5192 {
5193 VertexArray *vertexArrayObject = nullptr;
5194 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5195 {
5196 if (vertexArrayObject != nullptr)
5197 {
5198 detachVertexArray(vertexArray);
5199 vertexArrayObject->onDestroy(this);
5200 }
5201
5202 mVertexArrayHandleAllocator.release(vertexArray);
5203 }
5204 }
5205 }
5206}
5207
5208void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5209{
5210 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5211 {
5212 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5213 mVertexArrayMap.assign(vertexArray, nullptr);
5214 arrays[arrayIndex] = vertexArray;
5215 }
5216}
5217
5218bool Context::isVertexArray(GLuint array)
5219{
5220 if (array == 0)
5221 {
5222 return GL_FALSE;
5223 }
5224
5225 VertexArray *vao = getVertexArray(array);
5226 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5227}
5228
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005229void Context::endTransformFeedback()
5230{
5231 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5232 transformFeedback->end(this);
5233}
5234
5235void Context::transformFeedbackVaryings(GLuint program,
5236 GLsizei count,
5237 const GLchar *const *varyings,
5238 GLenum bufferMode)
5239{
5240 Program *programObject = getProgram(program);
5241 ASSERT(programObject);
5242 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5243}
5244
5245void Context::getTransformFeedbackVarying(GLuint program,
5246 GLuint index,
5247 GLsizei bufSize,
5248 GLsizei *length,
5249 GLsizei *size,
5250 GLenum *type,
5251 GLchar *name)
5252{
5253 Program *programObject = getProgram(program);
5254 ASSERT(programObject);
5255 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5256}
5257
5258void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5259{
5260 for (int i = 0; i < n; i++)
5261 {
5262 GLuint transformFeedback = ids[i];
5263 if (transformFeedback == 0)
5264 {
5265 continue;
5266 }
5267
5268 TransformFeedback *transformFeedbackObject = nullptr;
5269 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5270 {
5271 if (transformFeedbackObject != nullptr)
5272 {
5273 detachTransformFeedback(transformFeedback);
5274 transformFeedbackObject->release(this);
5275 }
5276
5277 mTransformFeedbackHandleAllocator.release(transformFeedback);
5278 }
5279 }
5280}
5281
5282void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5283{
5284 for (int i = 0; i < n; i++)
5285 {
5286 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5287 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5288 ids[i] = transformFeedback;
5289 }
5290}
5291
5292bool Context::isTransformFeedback(GLuint id)
5293{
5294 if (id == 0)
5295 {
5296 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5297 // returns FALSE
5298 return GL_FALSE;
5299 }
5300
5301 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5302 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5303}
5304
5305void Context::pauseTransformFeedback()
5306{
5307 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5308 transformFeedback->pause();
5309}
5310
5311void Context::resumeTransformFeedback()
5312{
5313 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5314 transformFeedback->resume();
5315}
5316
Jamie Madill12e957f2017-08-26 21:42:26 -04005317void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5318{
5319 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005320 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005321}
5322
5323GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5324{
5325 const Program *programObject = getProgram(program);
5326 return programObject->getFragDataLocation(name);
5327}
5328
5329void Context::getUniformIndices(GLuint program,
5330 GLsizei uniformCount,
5331 const GLchar *const *uniformNames,
5332 GLuint *uniformIndices)
5333{
5334 const Program *programObject = getProgram(program);
5335 if (!programObject->isLinked())
5336 {
5337 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5338 {
5339 uniformIndices[uniformId] = GL_INVALID_INDEX;
5340 }
5341 }
5342 else
5343 {
5344 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5345 {
5346 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5347 }
5348 }
5349}
5350
5351void Context::getActiveUniformsiv(GLuint program,
5352 GLsizei uniformCount,
5353 const GLuint *uniformIndices,
5354 GLenum pname,
5355 GLint *params)
5356{
5357 const Program *programObject = getProgram(program);
5358 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5359 {
5360 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005361 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005362 }
5363}
5364
5365GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5366{
5367 const Program *programObject = getProgram(program);
5368 return programObject->getUniformBlockIndex(uniformBlockName);
5369}
5370
5371void Context::getActiveUniformBlockiv(GLuint program,
5372 GLuint uniformBlockIndex,
5373 GLenum pname,
5374 GLint *params)
5375{
5376 const Program *programObject = getProgram(program);
5377 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5378}
5379
5380void Context::getActiveUniformBlockName(GLuint program,
5381 GLuint uniformBlockIndex,
5382 GLsizei bufSize,
5383 GLsizei *length,
5384 GLchar *uniformBlockName)
5385{
5386 const Program *programObject = getProgram(program);
5387 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5388}
5389
5390void Context::uniformBlockBinding(GLuint program,
5391 GLuint uniformBlockIndex,
5392 GLuint uniformBlockBinding)
5393{
5394 Program *programObject = getProgram(program);
5395 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5396}
5397
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005398GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5399{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005400 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5401 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005402
Jamie Madill70b5bb02017-08-28 13:32:37 -04005403 Sync *syncObject = getSync(syncHandle);
5404 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005405 if (error.isError())
5406 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005407 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005408 handleError(error);
5409 return nullptr;
5410 }
5411
Jamie Madill70b5bb02017-08-28 13:32:37 -04005412 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005413}
5414
5415GLboolean Context::isSync(GLsync sync)
5416{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005417 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005418}
5419
5420GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5421{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005422 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005423
5424 GLenum result = GL_WAIT_FAILED;
5425 handleError(syncObject->clientWait(flags, timeout, &result));
5426 return result;
5427}
5428
5429void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5430{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005431 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005432 handleError(syncObject->serverWait(flags, timeout));
5433}
5434
5435void Context::getInteger64v(GLenum pname, GLint64 *params)
5436{
5437 GLenum nativeType = GL_NONE;
5438 unsigned int numParams = 0;
5439 getQueryParameterInfo(pname, &nativeType, &numParams);
5440
5441 if (nativeType == GL_INT_64_ANGLEX)
5442 {
5443 getInteger64vImpl(pname, params);
5444 }
5445 else
5446 {
5447 CastStateValues(this, nativeType, pname, numParams, params);
5448 }
5449}
5450
Corentin Wallez336129f2017-10-17 15:55:40 -04005451void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005452{
5453 Buffer *buffer = mGLState.getTargetBuffer(target);
5454 QueryBufferParameteri64v(buffer, pname, params);
5455}
5456
5457void Context::genSamplers(GLsizei count, GLuint *samplers)
5458{
5459 for (int i = 0; i < count; i++)
5460 {
5461 samplers[i] = mState.mSamplers->createSampler();
5462 }
5463}
5464
5465void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5466{
5467 for (int i = 0; i < count; i++)
5468 {
5469 GLuint sampler = samplers[i];
5470
5471 if (mState.mSamplers->getSampler(sampler))
5472 {
5473 detachSampler(sampler);
5474 }
5475
5476 mState.mSamplers->deleteObject(this, sampler);
5477 }
5478}
5479
5480void Context::getInternalformativ(GLenum target,
5481 GLenum internalformat,
5482 GLenum pname,
5483 GLsizei bufSize,
5484 GLint *params)
5485{
5486 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5487 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5488}
5489
Jiajia Qin5451d532017-11-16 17:16:34 +08005490void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5491{
5492 programUniform1iv(program, location, 1, &v0);
5493}
5494
5495void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5496{
5497 GLint xy[2] = {v0, v1};
5498 programUniform2iv(program, location, 1, xy);
5499}
5500
5501void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5502{
5503 GLint xyz[3] = {v0, v1, v2};
5504 programUniform3iv(program, location, 1, xyz);
5505}
5506
5507void Context::programUniform4i(GLuint program,
5508 GLint location,
5509 GLint v0,
5510 GLint v1,
5511 GLint v2,
5512 GLint v3)
5513{
5514 GLint xyzw[4] = {v0, v1, v2, v3};
5515 programUniform4iv(program, location, 1, xyzw);
5516}
5517
5518void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5519{
5520 programUniform1uiv(program, location, 1, &v0);
5521}
5522
5523void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5524{
5525 GLuint xy[2] = {v0, v1};
5526 programUniform2uiv(program, location, 1, xy);
5527}
5528
5529void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5530{
5531 GLuint xyz[3] = {v0, v1, v2};
5532 programUniform3uiv(program, location, 1, xyz);
5533}
5534
5535void Context::programUniform4ui(GLuint program,
5536 GLint location,
5537 GLuint v0,
5538 GLuint v1,
5539 GLuint v2,
5540 GLuint v3)
5541{
5542 GLuint xyzw[4] = {v0, v1, v2, v3};
5543 programUniform4uiv(program, location, 1, xyzw);
5544}
5545
5546void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5547{
5548 programUniform1fv(program, location, 1, &v0);
5549}
5550
5551void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5552{
5553 GLfloat xy[2] = {v0, v1};
5554 programUniform2fv(program, location, 1, xy);
5555}
5556
5557void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5558{
5559 GLfloat xyz[3] = {v0, v1, v2};
5560 programUniform3fv(program, location, 1, xyz);
5561}
5562
5563void Context::programUniform4f(GLuint program,
5564 GLint location,
5565 GLfloat v0,
5566 GLfloat v1,
5567 GLfloat v2,
5568 GLfloat v3)
5569{
5570 GLfloat xyzw[4] = {v0, v1, v2, v3};
5571 programUniform4fv(program, location, 1, xyzw);
5572}
5573
Jamie Madill81c2e252017-09-09 23:32:46 -04005574void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5575{
5576 Program *programObject = getProgram(program);
5577 ASSERT(programObject);
5578 if (programObject->setUniform1iv(location, count, value) ==
5579 Program::SetUniformResult::SamplerChanged)
5580 {
5581 mGLState.setObjectDirty(GL_PROGRAM);
5582 }
5583}
5584
Jiajia Qin5451d532017-11-16 17:16:34 +08005585void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5586{
5587 Program *programObject = getProgram(program);
5588 ASSERT(programObject);
5589 programObject->setUniform2iv(location, count, value);
5590}
5591
5592void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5593{
5594 Program *programObject = getProgram(program);
5595 ASSERT(programObject);
5596 programObject->setUniform3iv(location, count, value);
5597}
5598
5599void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
5603 programObject->setUniform4iv(location, count, value);
5604}
5605
5606void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5607{
5608 Program *programObject = getProgram(program);
5609 ASSERT(programObject);
5610 programObject->setUniform1uiv(location, count, value);
5611}
5612
5613void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5614{
5615 Program *programObject = getProgram(program);
5616 ASSERT(programObject);
5617 programObject->setUniform2uiv(location, count, value);
5618}
5619
5620void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5621{
5622 Program *programObject = getProgram(program);
5623 ASSERT(programObject);
5624 programObject->setUniform3uiv(location, count, value);
5625}
5626
5627void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5628{
5629 Program *programObject = getProgram(program);
5630 ASSERT(programObject);
5631 programObject->setUniform4uiv(location, count, value);
5632}
5633
5634void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5635{
5636 Program *programObject = getProgram(program);
5637 ASSERT(programObject);
5638 programObject->setUniform1fv(location, count, value);
5639}
5640
5641void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5642{
5643 Program *programObject = getProgram(program);
5644 ASSERT(programObject);
5645 programObject->setUniform2fv(location, count, value);
5646}
5647
5648void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5649{
5650 Program *programObject = getProgram(program);
5651 ASSERT(programObject);
5652 programObject->setUniform3fv(location, count, value);
5653}
5654
5655void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5656{
5657 Program *programObject = getProgram(program);
5658 ASSERT(programObject);
5659 programObject->setUniform4fv(location, count, value);
5660}
5661
5662void Context::programUniformMatrix2fv(GLuint program,
5663 GLint location,
5664 GLsizei count,
5665 GLboolean transpose,
5666 const GLfloat *value)
5667{
5668 Program *programObject = getProgram(program);
5669 ASSERT(programObject);
5670 programObject->setUniformMatrix2fv(location, count, transpose, value);
5671}
5672
5673void Context::programUniformMatrix3fv(GLuint program,
5674 GLint location,
5675 GLsizei count,
5676 GLboolean transpose,
5677 const GLfloat *value)
5678{
5679 Program *programObject = getProgram(program);
5680 ASSERT(programObject);
5681 programObject->setUniformMatrix3fv(location, count, transpose, value);
5682}
5683
5684void Context::programUniformMatrix4fv(GLuint program,
5685 GLint location,
5686 GLsizei count,
5687 GLboolean transpose,
5688 const GLfloat *value)
5689{
5690 Program *programObject = getProgram(program);
5691 ASSERT(programObject);
5692 programObject->setUniformMatrix4fv(location, count, transpose, value);
5693}
5694
5695void Context::programUniformMatrix2x3fv(GLuint program,
5696 GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *programObject = getProgram(program);
5702 ASSERT(programObject);
5703 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5704}
5705
5706void Context::programUniformMatrix3x2fv(GLuint program,
5707 GLint location,
5708 GLsizei count,
5709 GLboolean transpose,
5710 const GLfloat *value)
5711{
5712 Program *programObject = getProgram(program);
5713 ASSERT(programObject);
5714 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5715}
5716
5717void Context::programUniformMatrix2x4fv(GLuint program,
5718 GLint location,
5719 GLsizei count,
5720 GLboolean transpose,
5721 const GLfloat *value)
5722{
5723 Program *programObject = getProgram(program);
5724 ASSERT(programObject);
5725 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5726}
5727
5728void Context::programUniformMatrix4x2fv(GLuint program,
5729 GLint location,
5730 GLsizei count,
5731 GLboolean transpose,
5732 const GLfloat *value)
5733{
5734 Program *programObject = getProgram(program);
5735 ASSERT(programObject);
5736 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5737}
5738
5739void Context::programUniformMatrix3x4fv(GLuint program,
5740 GLint location,
5741 GLsizei count,
5742 GLboolean transpose,
5743 const GLfloat *value)
5744{
5745 Program *programObject = getProgram(program);
5746 ASSERT(programObject);
5747 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5748}
5749
5750void Context::programUniformMatrix4x3fv(GLuint program,
5751 GLint location,
5752 GLsizei count,
5753 GLboolean transpose,
5754 const GLfloat *value)
5755{
5756 Program *programObject = getProgram(program);
5757 ASSERT(programObject);
5758 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5759}
5760
Jamie Madill81c2e252017-09-09 23:32:46 -04005761void Context::onTextureChange(const Texture *texture)
5762{
5763 // Conservatively assume all textures are dirty.
5764 // TODO(jmadill): More fine-grained update.
5765 mGLState.setObjectDirty(GL_TEXTURE);
5766}
5767
James Darpiniane8a93c62018-01-04 18:02:24 -08005768bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5769{
5770 return mGLState.isCurrentTransformFeedback(tf);
5771}
5772bool Context::isCurrentVertexArray(const VertexArray *va) const
5773{
5774 return mGLState.isCurrentVertexArray(va);
5775}
5776
Yunchao Hea336b902017-08-02 16:05:21 +08005777void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5778{
5779 for (int i = 0; i < count; i++)
5780 {
5781 pipelines[i] = createProgramPipeline();
5782 }
5783}
5784
5785void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5786{
5787 for (int i = 0; i < count; i++)
5788 {
5789 if (pipelines[i] != 0)
5790 {
5791 deleteProgramPipeline(pipelines[i]);
5792 }
5793 }
5794}
5795
5796GLboolean Context::isProgramPipeline(GLuint pipeline)
5797{
5798 if (pipeline == 0)
5799 {
5800 return GL_FALSE;
5801 }
5802
5803 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5804}
5805
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005806void Context::finishFenceNV(GLuint fence)
5807{
5808 FenceNV *fenceObject = getFenceNV(fence);
5809
5810 ASSERT(fenceObject && fenceObject->isSet());
5811 handleError(fenceObject->finish());
5812}
5813
5814void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5815{
5816 FenceNV *fenceObject = getFenceNV(fence);
5817
5818 ASSERT(fenceObject && fenceObject->isSet());
5819
5820 switch (pname)
5821 {
5822 case GL_FENCE_STATUS_NV:
5823 {
5824 // GL_NV_fence spec:
5825 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5826 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5827 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5828 GLboolean status = GL_TRUE;
5829 if (fenceObject->getStatus() != GL_TRUE)
5830 {
5831 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5832 }
5833 *params = status;
5834 break;
5835 }
5836
5837 case GL_FENCE_CONDITION_NV:
5838 {
5839 *params = static_cast<GLint>(fenceObject->getCondition());
5840 break;
5841 }
5842
5843 default:
5844 UNREACHABLE();
5845 }
5846}
5847
5848void Context::getTranslatedShaderSource(GLuint shader,
5849 GLsizei bufsize,
5850 GLsizei *length,
5851 GLchar *source)
5852{
5853 Shader *shaderObject = getShader(shader);
5854 ASSERT(shaderObject);
5855 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5856}
5857
5858void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5859{
5860 Program *programObject = getProgram(program);
5861 ASSERT(programObject);
5862
5863 programObject->getUniformfv(this, location, params);
5864}
5865
5866void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5867{
5868 Program *programObject = getProgram(program);
5869 ASSERT(programObject);
5870
5871 programObject->getUniformiv(this, location, params);
5872}
5873
5874GLboolean Context::isFenceNV(GLuint fence)
5875{
5876 FenceNV *fenceObject = getFenceNV(fence);
5877
5878 if (fenceObject == nullptr)
5879 {
5880 return GL_FALSE;
5881 }
5882
5883 // GL_NV_fence spec:
5884 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5885 // existing fence.
5886 return fenceObject->isSet();
5887}
5888
5889void Context::readnPixels(GLint x,
5890 GLint y,
5891 GLsizei width,
5892 GLsizei height,
5893 GLenum format,
5894 GLenum type,
5895 GLsizei bufSize,
5896 void *data)
5897{
5898 return readPixels(x, y, width, height, format, type, data);
5899}
5900
Jamie Madill007530e2017-12-28 14:27:04 -05005901void Context::setFenceNV(GLuint fence, GLenum condition)
5902{
5903 ASSERT(condition == GL_ALL_COMPLETED_NV);
5904
5905 FenceNV *fenceObject = getFenceNV(fence);
5906 ASSERT(fenceObject != nullptr);
5907 handleError(fenceObject->set(condition));
5908}
5909
5910GLboolean Context::testFenceNV(GLuint fence)
5911{
5912 FenceNV *fenceObject = getFenceNV(fence);
5913
5914 ASSERT(fenceObject != nullptr);
5915 ASSERT(fenceObject->isSet() == GL_TRUE);
5916
5917 GLboolean result = GL_TRUE;
5918 Error error = fenceObject->test(&result);
5919 if (error.isError())
5920 {
5921 handleError(error);
5922 return GL_TRUE;
5923 }
5924
5925 return result;
5926}
5927
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005928void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005929{
5930 Texture *texture = getTargetTexture(target);
5931 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005932 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005933}
5934
Jamie Madillfa920eb2018-01-04 11:45:50 -05005935void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005936{
5937 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5938 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5939 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5940}
5941
Jamie Madillfa920eb2018-01-04 11:45:50 -05005942void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5943{
5944 UNIMPLEMENTED();
5945}
5946
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005947void Context::alphaFunc(GLenum func, GLfloat ref)
5948{
5949 UNIMPLEMENTED();
5950}
5951
5952void Context::alphaFuncx(GLenum func, GLfixed ref)
5953{
5954 UNIMPLEMENTED();
5955}
5956
5957void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5958{
5959 UNIMPLEMENTED();
5960}
5961
5962void Context::clearDepthx(GLfixed depth)
5963{
5964 UNIMPLEMENTED();
5965}
5966
5967void Context::clientActiveTexture(GLenum texture)
5968{
5969 UNIMPLEMENTED();
5970}
5971
5972void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5973{
5974 UNIMPLEMENTED();
5975}
5976
5977void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5978{
5979 UNIMPLEMENTED();
5980}
5981
5982void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5983{
5984 UNIMPLEMENTED();
5985}
5986
5987void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5988{
5989 UNIMPLEMENTED();
5990}
5991
5992void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5993{
5994 UNIMPLEMENTED();
5995}
5996
5997void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5998{
5999 UNIMPLEMENTED();
6000}
6001
6002void Context::cullFace(GLenum mode)
6003{
6004 UNIMPLEMENTED();
6005}
6006
6007void Context::depthRangex(GLfixed n, GLfixed f)
6008{
6009 UNIMPLEMENTED();
6010}
6011
6012void Context::disableClientState(GLenum array)
6013{
6014 UNIMPLEMENTED();
6015}
6016
6017void Context::enableClientState(GLenum array)
6018{
6019 UNIMPLEMENTED();
6020}
6021
6022void Context::fogf(GLenum pname, GLfloat param)
6023{
6024 UNIMPLEMENTED();
6025}
6026
6027void Context::fogfv(GLenum pname, const GLfloat *params)
6028{
6029 UNIMPLEMENTED();
6030}
6031
6032void Context::fogx(GLenum pname, GLfixed param)
6033{
6034 UNIMPLEMENTED();
6035}
6036
6037void Context::fogxv(GLenum pname, const GLfixed *param)
6038{
6039 UNIMPLEMENTED();
6040}
6041
6042void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6043{
6044 UNIMPLEMENTED();
6045}
6046
6047void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6048{
6049 UNIMPLEMENTED();
6050}
6051
6052void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6053{
6054 UNIMPLEMENTED();
6055}
6056
6057void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6058{
6059 UNIMPLEMENTED();
6060}
6061
6062void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6063{
6064 UNIMPLEMENTED();
6065}
6066
6067void Context::getFixedv(GLenum pname, GLfixed *params)
6068{
6069 UNIMPLEMENTED();
6070}
6071
6072void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6073{
6074 UNIMPLEMENTED();
6075}
6076
6077void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6078{
6079 UNIMPLEMENTED();
6080}
6081
6082void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6083{
6084 UNIMPLEMENTED();
6085}
6086
6087void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6088{
6089 UNIMPLEMENTED();
6090}
6091
6092void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6093{
6094 UNIMPLEMENTED();
6095}
6096
6097void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6098{
6099 UNIMPLEMENTED();
6100}
6101
6102void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6103{
6104 UNIMPLEMENTED();
6105}
6106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006107void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006108{
6109 UNIMPLEMENTED();
6110}
6111
6112void Context::lightModelf(GLenum pname, GLfloat param)
6113{
6114 UNIMPLEMENTED();
6115}
6116
6117void Context::lightModelfv(GLenum pname, const GLfloat *params)
6118{
6119 UNIMPLEMENTED();
6120}
6121
6122void Context::lightModelx(GLenum pname, GLfixed param)
6123{
6124 UNIMPLEMENTED();
6125}
6126
6127void Context::lightModelxv(GLenum pname, const GLfixed *param)
6128{
6129 UNIMPLEMENTED();
6130}
6131
6132void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6133{
6134 UNIMPLEMENTED();
6135}
6136
6137void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6138{
6139 UNIMPLEMENTED();
6140}
6141
6142void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6143{
6144 UNIMPLEMENTED();
6145}
6146
6147void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6148{
6149 UNIMPLEMENTED();
6150}
6151
6152void Context::lineWidthx(GLfixed width)
6153{
6154 UNIMPLEMENTED();
6155}
6156
6157void Context::loadIdentity()
6158{
6159 UNIMPLEMENTED();
6160}
6161
6162void Context::loadMatrixf(const GLfloat *m)
6163{
6164 UNIMPLEMENTED();
6165}
6166
6167void Context::loadMatrixx(const GLfixed *m)
6168{
6169 UNIMPLEMENTED();
6170}
6171
6172void Context::logicOp(GLenum opcode)
6173{
6174 UNIMPLEMENTED();
6175}
6176
6177void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6178{
6179 UNIMPLEMENTED();
6180}
6181
6182void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6183{
6184 UNIMPLEMENTED();
6185}
6186
6187void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6188{
6189 UNIMPLEMENTED();
6190}
6191
6192void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6193{
6194 UNIMPLEMENTED();
6195}
6196
6197void Context::matrixMode(GLenum mode)
6198{
6199 UNIMPLEMENTED();
6200}
6201
6202void Context::multMatrixf(const GLfloat *m)
6203{
6204 UNIMPLEMENTED();
6205}
6206
6207void Context::multMatrixx(const GLfixed *m)
6208{
6209 UNIMPLEMENTED();
6210}
6211
6212void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6213{
6214 UNIMPLEMENTED();
6215}
6216
6217void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6218{
6219 UNIMPLEMENTED();
6220}
6221
6222void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6223{
6224 UNIMPLEMENTED();
6225}
6226
6227void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6228{
6229 UNIMPLEMENTED();
6230}
6231
6232void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6233{
6234 UNIMPLEMENTED();
6235}
6236
6237void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6238{
6239 UNIMPLEMENTED();
6240}
6241
6242void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6243{
6244 UNIMPLEMENTED();
6245}
6246
6247void Context::pointParameterf(GLenum pname, GLfloat param)
6248{
6249 UNIMPLEMENTED();
6250}
6251
6252void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6253{
6254 UNIMPLEMENTED();
6255}
6256
6257void Context::pointParameterx(GLenum pname, GLfixed param)
6258{
6259 UNIMPLEMENTED();
6260}
6261
6262void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6263{
6264 UNIMPLEMENTED();
6265}
6266
6267void Context::pointSize(GLfloat size)
6268{
6269 UNIMPLEMENTED();
6270}
6271
6272void Context::pointSizex(GLfixed size)
6273{
6274 UNIMPLEMENTED();
6275}
6276
6277void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6278{
6279 UNIMPLEMENTED();
6280}
6281
6282void Context::popMatrix()
6283{
6284 UNIMPLEMENTED();
6285}
6286
6287void Context::pushMatrix()
6288{
6289 UNIMPLEMENTED();
6290}
6291
6292void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6293{
6294 UNIMPLEMENTED();
6295}
6296
6297void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6298{
6299 UNIMPLEMENTED();
6300}
6301
6302void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6303{
6304 UNIMPLEMENTED();
6305}
6306
6307void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6308{
6309 UNIMPLEMENTED();
6310}
6311
6312void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6313{
6314 UNIMPLEMENTED();
6315}
6316
6317void Context::shadeModel(GLenum mode)
6318{
6319 UNIMPLEMENTED();
6320}
6321
6322void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6323{
6324 UNIMPLEMENTED();
6325}
6326
6327void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6328{
6329 UNIMPLEMENTED();
6330}
6331
6332void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6333{
6334 UNIMPLEMENTED();
6335}
6336
6337void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6338{
6339 UNIMPLEMENTED();
6340}
6341
6342void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6343{
6344 UNIMPLEMENTED();
6345}
6346
6347void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6348{
6349 UNIMPLEMENTED();
6350}
6351
6352void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6353{
6354 UNIMPLEMENTED();
6355}
6356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006357void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006358{
6359 UNIMPLEMENTED();
6360}
6361
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006362void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006363{
6364 UNIMPLEMENTED();
6365}
6366
6367void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6368{
6369 UNIMPLEMENTED();
6370}
6371
6372void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6373{
6374 UNIMPLEMENTED();
6375}
6376
6377void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6378{
6379 UNIMPLEMENTED();
6380}
6381
6382void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6383{
6384 UNIMPLEMENTED();
6385}
6386
6387void Context::drawTexfv(const GLfloat *coords)
6388{
6389 UNIMPLEMENTED();
6390}
6391
6392void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6393{
6394 UNIMPLEMENTED();
6395}
6396
6397void Context::drawTexiv(const GLint *coords)
6398{
6399 UNIMPLEMENTED();
6400}
6401
6402void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6403{
6404 UNIMPLEMENTED();
6405}
6406
6407void Context::drawTexsv(const GLshort *coords)
6408{
6409 UNIMPLEMENTED();
6410}
6411
6412void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6413{
6414 UNIMPLEMENTED();
6415}
6416
6417void Context::drawTexxv(const GLfixed *coords)
6418{
6419 UNIMPLEMENTED();
6420}
6421
6422void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6423{
6424 UNIMPLEMENTED();
6425}
6426
6427void Context::loadPaletteFromModelViewMatrix()
6428{
6429 UNIMPLEMENTED();
6430}
6431
6432void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6433{
6434 UNIMPLEMENTED();
6435}
6436
6437void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6438{
6439 UNIMPLEMENTED();
6440}
6441
6442void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6443{
6444 UNIMPLEMENTED();
6445}
6446
6447GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6448{
6449 UNIMPLEMENTED();
6450 return 0;
6451}
6452
Jamie Madill5b772312018-03-08 20:28:32 -05006453bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6454{
6455 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6456 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6457 // to the fact that it is stored internally as a float, and so would require conversion
6458 // if returned from Context::getIntegerv. Since this conversion is already implemented
6459 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6460 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6461 // application.
6462 switch (pname)
6463 {
6464 case GL_COMPRESSED_TEXTURE_FORMATS:
6465 {
6466 *type = GL_INT;
6467 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6468 return true;
6469 }
6470 case GL_SHADER_BINARY_FORMATS:
6471 {
6472 *type = GL_INT;
6473 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6474 return true;
6475 }
6476
6477 case GL_MAX_VERTEX_ATTRIBS:
6478 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6479 case GL_MAX_VARYING_VECTORS:
6480 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6481 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6482 case GL_MAX_TEXTURE_IMAGE_UNITS:
6483 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6484 case GL_MAX_RENDERBUFFER_SIZE:
6485 case GL_NUM_SHADER_BINARY_FORMATS:
6486 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6487 case GL_ARRAY_BUFFER_BINDING:
6488 case GL_FRAMEBUFFER_BINDING:
6489 case GL_RENDERBUFFER_BINDING:
6490 case GL_CURRENT_PROGRAM:
6491 case GL_PACK_ALIGNMENT:
6492 case GL_UNPACK_ALIGNMENT:
6493 case GL_GENERATE_MIPMAP_HINT:
6494 case GL_RED_BITS:
6495 case GL_GREEN_BITS:
6496 case GL_BLUE_BITS:
6497 case GL_ALPHA_BITS:
6498 case GL_DEPTH_BITS:
6499 case GL_STENCIL_BITS:
6500 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6501 case GL_CULL_FACE_MODE:
6502 case GL_FRONT_FACE:
6503 case GL_ACTIVE_TEXTURE:
6504 case GL_STENCIL_FUNC:
6505 case GL_STENCIL_VALUE_MASK:
6506 case GL_STENCIL_REF:
6507 case GL_STENCIL_FAIL:
6508 case GL_STENCIL_PASS_DEPTH_FAIL:
6509 case GL_STENCIL_PASS_DEPTH_PASS:
6510 case GL_STENCIL_BACK_FUNC:
6511 case GL_STENCIL_BACK_VALUE_MASK:
6512 case GL_STENCIL_BACK_REF:
6513 case GL_STENCIL_BACK_FAIL:
6514 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6515 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6516 case GL_DEPTH_FUNC:
6517 case GL_BLEND_SRC_RGB:
6518 case GL_BLEND_SRC_ALPHA:
6519 case GL_BLEND_DST_RGB:
6520 case GL_BLEND_DST_ALPHA:
6521 case GL_BLEND_EQUATION_RGB:
6522 case GL_BLEND_EQUATION_ALPHA:
6523 case GL_STENCIL_WRITEMASK:
6524 case GL_STENCIL_BACK_WRITEMASK:
6525 case GL_STENCIL_CLEAR_VALUE:
6526 case GL_SUBPIXEL_BITS:
6527 case GL_MAX_TEXTURE_SIZE:
6528 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6529 case GL_SAMPLE_BUFFERS:
6530 case GL_SAMPLES:
6531 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6532 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6533 case GL_TEXTURE_BINDING_2D:
6534 case GL_TEXTURE_BINDING_CUBE_MAP:
6535 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6536 {
6537 *type = GL_INT;
6538 *numParams = 1;
6539 return true;
6540 }
6541 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6542 {
6543 if (!getExtensions().packReverseRowOrder)
6544 {
6545 return false;
6546 }
6547 *type = GL_INT;
6548 *numParams = 1;
6549 return true;
6550 }
6551 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6552 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6553 {
6554 if (!getExtensions().textureRectangle)
6555 {
6556 return false;
6557 }
6558 *type = GL_INT;
6559 *numParams = 1;
6560 return true;
6561 }
6562 case GL_MAX_DRAW_BUFFERS_EXT:
6563 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6564 {
6565 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6566 {
6567 return false;
6568 }
6569 *type = GL_INT;
6570 *numParams = 1;
6571 return true;
6572 }
6573 case GL_MAX_VIEWPORT_DIMS:
6574 {
6575 *type = GL_INT;
6576 *numParams = 2;
6577 return true;
6578 }
6579 case GL_VIEWPORT:
6580 case GL_SCISSOR_BOX:
6581 {
6582 *type = GL_INT;
6583 *numParams = 4;
6584 return true;
6585 }
6586 case GL_SHADER_COMPILER:
6587 case GL_SAMPLE_COVERAGE_INVERT:
6588 case GL_DEPTH_WRITEMASK:
6589 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6590 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6591 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6592 // bool-natural
6593 case GL_SAMPLE_COVERAGE:
6594 case GL_SCISSOR_TEST:
6595 case GL_STENCIL_TEST:
6596 case GL_DEPTH_TEST:
6597 case GL_BLEND:
6598 case GL_DITHER:
6599 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6600 {
6601 *type = GL_BOOL;
6602 *numParams = 1;
6603 return true;
6604 }
6605 case GL_COLOR_WRITEMASK:
6606 {
6607 *type = GL_BOOL;
6608 *numParams = 4;
6609 return true;
6610 }
6611 case GL_POLYGON_OFFSET_FACTOR:
6612 case GL_POLYGON_OFFSET_UNITS:
6613 case GL_SAMPLE_COVERAGE_VALUE:
6614 case GL_DEPTH_CLEAR_VALUE:
6615 case GL_LINE_WIDTH:
6616 {
6617 *type = GL_FLOAT;
6618 *numParams = 1;
6619 return true;
6620 }
6621 case GL_ALIASED_LINE_WIDTH_RANGE:
6622 case GL_ALIASED_POINT_SIZE_RANGE:
6623 case GL_DEPTH_RANGE:
6624 {
6625 *type = GL_FLOAT;
6626 *numParams = 2;
6627 return true;
6628 }
6629 case GL_COLOR_CLEAR_VALUE:
6630 case GL_BLEND_COLOR:
6631 {
6632 *type = GL_FLOAT;
6633 *numParams = 4;
6634 return true;
6635 }
6636 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6637 if (!getExtensions().textureFilterAnisotropic)
6638 {
6639 return false;
6640 }
6641 *type = GL_FLOAT;
6642 *numParams = 1;
6643 return true;
6644 case GL_TIMESTAMP_EXT:
6645 if (!getExtensions().disjointTimerQuery)
6646 {
6647 return false;
6648 }
6649 *type = GL_INT_64_ANGLEX;
6650 *numParams = 1;
6651 return true;
6652 case GL_GPU_DISJOINT_EXT:
6653 if (!getExtensions().disjointTimerQuery)
6654 {
6655 return false;
6656 }
6657 *type = GL_INT;
6658 *numParams = 1;
6659 return true;
6660 case GL_COVERAGE_MODULATION_CHROMIUM:
6661 if (!getExtensions().framebufferMixedSamples)
6662 {
6663 return false;
6664 }
6665 *type = GL_INT;
6666 *numParams = 1;
6667 return true;
6668 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6669 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6670 {
6671 return false;
6672 }
6673 *type = GL_INT;
6674 *numParams = 1;
6675 return true;
6676 }
6677
6678 if (getExtensions().debug)
6679 {
6680 switch (pname)
6681 {
6682 case GL_DEBUG_LOGGED_MESSAGES:
6683 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6684 case GL_DEBUG_GROUP_STACK_DEPTH:
6685 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6686 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6687 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6688 case GL_MAX_LABEL_LENGTH:
6689 *type = GL_INT;
6690 *numParams = 1;
6691 return true;
6692
6693 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6694 case GL_DEBUG_OUTPUT:
6695 *type = GL_BOOL;
6696 *numParams = 1;
6697 return true;
6698 }
6699 }
6700
6701 if (getExtensions().multisampleCompatibility)
6702 {
6703 switch (pname)
6704 {
6705 case GL_MULTISAMPLE_EXT:
6706 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6707 *type = GL_BOOL;
6708 *numParams = 1;
6709 return true;
6710 }
6711 }
6712
6713 if (getExtensions().pathRendering)
6714 {
6715 switch (pname)
6716 {
6717 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6718 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6719 *type = GL_FLOAT;
6720 *numParams = 16;
6721 return true;
6722 }
6723 }
6724
6725 if (getExtensions().bindGeneratesResource)
6726 {
6727 switch (pname)
6728 {
6729 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6730 *type = GL_BOOL;
6731 *numParams = 1;
6732 return true;
6733 }
6734 }
6735
6736 if (getExtensions().clientArrays)
6737 {
6738 switch (pname)
6739 {
6740 case GL_CLIENT_ARRAYS_ANGLE:
6741 *type = GL_BOOL;
6742 *numParams = 1;
6743 return true;
6744 }
6745 }
6746
6747 if (getExtensions().sRGBWriteControl)
6748 {
6749 switch (pname)
6750 {
6751 case GL_FRAMEBUFFER_SRGB_EXT:
6752 *type = GL_BOOL;
6753 *numParams = 1;
6754 return true;
6755 }
6756 }
6757
6758 if (getExtensions().robustResourceInitialization &&
6759 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6760 {
6761 *type = GL_BOOL;
6762 *numParams = 1;
6763 return true;
6764 }
6765
6766 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6767 {
6768 *type = GL_BOOL;
6769 *numParams = 1;
6770 return true;
6771 }
6772
6773 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6774 switch (pname)
6775 {
6776 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6777 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6778 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6779 {
6780 return false;
6781 }
6782 *type = GL_INT;
6783 *numParams = 1;
6784 return true;
6785
6786 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6787 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6788 {
6789 return false;
6790 }
6791 *type = GL_INT;
6792 *numParams = 1;
6793 return true;
6794
6795 case GL_PROGRAM_BINARY_FORMATS_OES:
6796 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6797 {
6798 return false;
6799 }
6800 *type = GL_INT;
6801 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6802 return true;
6803
6804 case GL_PACK_ROW_LENGTH:
6805 case GL_PACK_SKIP_ROWS:
6806 case GL_PACK_SKIP_PIXELS:
6807 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6808 {
6809 return false;
6810 }
6811 *type = GL_INT;
6812 *numParams = 1;
6813 return true;
6814 case GL_UNPACK_ROW_LENGTH:
6815 case GL_UNPACK_SKIP_ROWS:
6816 case GL_UNPACK_SKIP_PIXELS:
6817 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6818 {
6819 return false;
6820 }
6821 *type = GL_INT;
6822 *numParams = 1;
6823 return true;
6824 case GL_VERTEX_ARRAY_BINDING:
6825 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6826 {
6827 return false;
6828 }
6829 *type = GL_INT;
6830 *numParams = 1;
6831 return true;
6832 case GL_PIXEL_PACK_BUFFER_BINDING:
6833 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6834 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6835 {
6836 return false;
6837 }
6838 *type = GL_INT;
6839 *numParams = 1;
6840 return true;
6841 case GL_MAX_SAMPLES:
6842 {
6843 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6844 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6845 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6846 {
6847 return false;
6848 }
6849 *type = GL_INT;
6850 *numParams = 1;
6851 return true;
6852
6853 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6854 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6855 {
6856 return false;
6857 }
6858 *type = GL_INT;
6859 *numParams = 1;
6860 return true;
6861 }
6862 }
6863
6864 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6865 {
6866 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6867 {
6868 return false;
6869 }
6870 *type = GL_INT;
6871 *numParams = 1;
6872 return true;
6873 }
6874
6875 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6876 {
6877 *type = GL_INT;
6878 *numParams = 1;
6879 return true;
6880 }
6881
6882 if (getClientVersion() < Version(3, 0))
6883 {
6884 return false;
6885 }
6886
6887 // Check for ES3.0+ parameter names
6888 switch (pname)
6889 {
6890 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6891 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6892 case GL_UNIFORM_BUFFER_BINDING:
6893 case GL_TRANSFORM_FEEDBACK_BINDING:
6894 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6895 case GL_COPY_READ_BUFFER_BINDING:
6896 case GL_COPY_WRITE_BUFFER_BINDING:
6897 case GL_SAMPLER_BINDING:
6898 case GL_READ_BUFFER:
6899 case GL_TEXTURE_BINDING_3D:
6900 case GL_TEXTURE_BINDING_2D_ARRAY:
6901 case GL_MAX_3D_TEXTURE_SIZE:
6902 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6903 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6904 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6905 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6906 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6907 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6908 case GL_MAX_VARYING_COMPONENTS:
6909 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6910 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6911 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6912 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6913 case GL_NUM_EXTENSIONS:
6914 case GL_MAJOR_VERSION:
6915 case GL_MINOR_VERSION:
6916 case GL_MAX_ELEMENTS_INDICES:
6917 case GL_MAX_ELEMENTS_VERTICES:
6918 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6919 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6920 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6921 case GL_UNPACK_IMAGE_HEIGHT:
6922 case GL_UNPACK_SKIP_IMAGES:
6923 {
6924 *type = GL_INT;
6925 *numParams = 1;
6926 return true;
6927 }
6928
6929 case GL_MAX_ELEMENT_INDEX:
6930 case GL_MAX_UNIFORM_BLOCK_SIZE:
6931 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6932 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6933 case GL_MAX_SERVER_WAIT_TIMEOUT:
6934 {
6935 *type = GL_INT_64_ANGLEX;
6936 *numParams = 1;
6937 return true;
6938 }
6939
6940 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6941 case GL_TRANSFORM_FEEDBACK_PAUSED:
6942 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6943 case GL_RASTERIZER_DISCARD:
6944 {
6945 *type = GL_BOOL;
6946 *numParams = 1;
6947 return true;
6948 }
6949
6950 case GL_MAX_TEXTURE_LOD_BIAS:
6951 {
6952 *type = GL_FLOAT;
6953 *numParams = 1;
6954 return true;
6955 }
6956 }
6957
6958 if (getExtensions().requestExtension)
6959 {
6960 switch (pname)
6961 {
6962 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6963 *type = GL_INT;
6964 *numParams = 1;
6965 return true;
6966 }
6967 }
6968
6969 if (getClientVersion() < Version(3, 1))
6970 {
6971 return false;
6972 }
6973
6974 switch (pname)
6975 {
6976 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6977 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6978 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6979 case GL_MAX_FRAMEBUFFER_WIDTH:
6980 case GL_MAX_FRAMEBUFFER_HEIGHT:
6981 case GL_MAX_FRAMEBUFFER_SAMPLES:
6982 case GL_MAX_SAMPLE_MASK_WORDS:
6983 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6984 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6985 case GL_MAX_INTEGER_SAMPLES:
6986 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6987 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6988 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6989 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6990 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6991 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6992 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6993 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6994 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6995 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6996 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6997 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6998 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6999 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7000 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7001 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7002 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7003 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7004 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7005 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7006 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7007 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7008 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7009 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7010 case GL_MAX_UNIFORM_LOCATIONS:
7011 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7012 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7013 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7014 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7015 case GL_MAX_IMAGE_UNITS:
7016 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7017 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7018 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7019 case GL_SHADER_STORAGE_BUFFER_BINDING:
7020 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7021 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7022 *type = GL_INT;
7023 *numParams = 1;
7024 return true;
7025 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7026 *type = GL_INT_64_ANGLEX;
7027 *numParams = 1;
7028 return true;
7029 case GL_SAMPLE_MASK:
7030 *type = GL_BOOL;
7031 *numParams = 1;
7032 return true;
7033 }
7034
7035 if (getExtensions().geometryShader)
7036 {
7037 switch (pname)
7038 {
7039 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7040 case GL_LAYER_PROVOKING_VERTEX_EXT:
7041 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7042 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7043 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7044 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7045 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7046 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7047 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7048 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7049 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7050 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7051 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7052 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7053 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7054 *type = GL_INT;
7055 *numParams = 1;
7056 return true;
7057 }
7058 }
7059
7060 return false;
7061}
7062
7063bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7064{
7065 if (getClientVersion() < Version(3, 0))
7066 {
7067 return false;
7068 }
7069
7070 switch (target)
7071 {
7072 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7073 case GL_UNIFORM_BUFFER_BINDING:
7074 {
7075 *type = GL_INT;
7076 *numParams = 1;
7077 return true;
7078 }
7079 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7080 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7081 case GL_UNIFORM_BUFFER_START:
7082 case GL_UNIFORM_BUFFER_SIZE:
7083 {
7084 *type = GL_INT_64_ANGLEX;
7085 *numParams = 1;
7086 return true;
7087 }
7088 }
7089
7090 if (getClientVersion() < Version(3, 1))
7091 {
7092 return false;
7093 }
7094
7095 switch (target)
7096 {
7097 case GL_IMAGE_BINDING_LAYERED:
7098 {
7099 *type = GL_BOOL;
7100 *numParams = 1;
7101 return true;
7102 }
7103 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7104 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7105 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7106 case GL_SHADER_STORAGE_BUFFER_BINDING:
7107 case GL_VERTEX_BINDING_BUFFER:
7108 case GL_VERTEX_BINDING_DIVISOR:
7109 case GL_VERTEX_BINDING_OFFSET:
7110 case GL_VERTEX_BINDING_STRIDE:
7111 case GL_SAMPLE_MASK_VALUE:
7112 case GL_IMAGE_BINDING_NAME:
7113 case GL_IMAGE_BINDING_LEVEL:
7114 case GL_IMAGE_BINDING_LAYER:
7115 case GL_IMAGE_BINDING_ACCESS:
7116 case GL_IMAGE_BINDING_FORMAT:
7117 {
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121 }
7122 case GL_ATOMIC_COUNTER_BUFFER_START:
7123 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7124 case GL_SHADER_STORAGE_BUFFER_START:
7125 case GL_SHADER_STORAGE_BUFFER_SIZE:
7126 {
7127 *type = GL_INT_64_ANGLEX;
7128 *numParams = 1;
7129 return true;
7130 }
7131 }
7132
7133 return false;
7134}
7135
7136Program *Context::getProgram(GLuint handle) const
7137{
7138 return mState.mShaderPrograms->getProgram(handle);
7139}
7140
7141Shader *Context::getShader(GLuint handle) const
7142{
7143 return mState.mShaderPrograms->getShader(handle);
7144}
7145
7146bool Context::isTextureGenerated(GLuint texture) const
7147{
7148 return mState.mTextures->isHandleGenerated(texture);
7149}
7150
7151bool Context::isBufferGenerated(GLuint buffer) const
7152{
7153 return mState.mBuffers->isHandleGenerated(buffer);
7154}
7155
7156bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7157{
7158 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7159}
7160
7161bool Context::isFramebufferGenerated(GLuint framebuffer) const
7162{
7163 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7164}
7165
7166bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7167{
7168 return mState.mPipelines->isHandleGenerated(pipeline);
7169}
7170
7171bool Context::usingDisplayTextureShareGroup() const
7172{
7173 return mDisplayTextureShareGroup;
7174}
7175
7176GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7177{
7178 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7179 internalformat == GL_DEPTH_STENCIL
7180 ? GL_DEPTH24_STENCIL8
7181 : internalformat;
7182}
7183
Jamie Madillc29968b2016-01-20 11:17:23 -05007184} // namespace gl