blob: e7fdbab52455738776574e775879364f21e97c2f [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
Jiawei Shao385b3e02018-03-21 09:43:28 +0800617GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618{
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
Jiawei Shao385b3e02018-03-21 09:43:28 +0800664GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800665{
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;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001605 // GLES1 emulation: Caps queries
1606 case GL_MAX_TEXTURE_UNITS:
1607 *params = mCaps.maxMultitextureUnits;
1608 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001609 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001610 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001612 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001613}
1614
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001615void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001616{
Shannon Woods53a94a82014-06-24 15:20:36 -04001617 // Queries about context capabilities and maximums are answered by Context.
1618 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001619 switch (pname)
1620 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001621 case GL_MAX_ELEMENT_INDEX:
1622 *params = mCaps.maxElementIndex;
1623 break;
1624 case GL_MAX_UNIFORM_BLOCK_SIZE:
1625 *params = mCaps.maxUniformBlockSize;
1626 break;
1627 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1628 *params = mCaps.maxCombinedVertexUniformComponents;
1629 break;
1630 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1631 *params = mCaps.maxCombinedFragmentUniformComponents;
1632 break;
1633 case GL_MAX_SERVER_WAIT_TIMEOUT:
1634 *params = mCaps.maxServerWaitTimeout;
1635 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001636
Jamie Madill231c7f52017-04-26 13:45:37 -04001637 // GL_EXT_disjoint_timer_query
1638 case GL_TIMESTAMP_EXT:
1639 *params = mImplementation->getTimestamp();
1640 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001641
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1643 *params = mCaps.maxShaderStorageBlockSize;
1644 break;
1645 default:
1646 UNREACHABLE();
1647 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001648 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001649}
1650
Geoff Lang70d0f492015-12-10 17:45:46 -05001651void Context::getPointerv(GLenum pname, void **params) const
1652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001653 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001654}
1655
Martin Radev66fb8202016-07-28 11:45:20 +03001656void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001657{
Shannon Woods53a94a82014-06-24 15:20:36 -04001658 // Queries about context capabilities and maximums are answered by Context.
1659 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001660
1661 GLenum nativeType;
1662 unsigned int numParams;
1663 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1664 ASSERT(queryStatus);
1665
1666 if (nativeType == GL_INT)
1667 {
1668 switch (target)
1669 {
1670 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1671 ASSERT(index < 3u);
1672 *data = mCaps.maxComputeWorkGroupCount[index];
1673 break;
1674 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1675 ASSERT(index < 3u);
1676 *data = mCaps.maxComputeWorkGroupSize[index];
1677 break;
1678 default:
1679 mGLState.getIntegeri_v(target, index, data);
1680 }
1681 }
1682 else
1683 {
1684 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1685 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001686}
1687
Martin Radev66fb8202016-07-28 11:45:20 +03001688void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001689{
Shannon Woods53a94a82014-06-24 15:20:36 -04001690 // Queries about context capabilities and maximums are answered by Context.
1691 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001692
1693 GLenum nativeType;
1694 unsigned int numParams;
1695 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1696 ASSERT(queryStatus);
1697
1698 if (nativeType == GL_INT_64_ANGLEX)
1699 {
1700 mGLState.getInteger64i_v(target, index, data);
1701 }
1702 else
1703 {
1704 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1705 }
1706}
1707
1708void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1709{
1710 // Queries about context capabilities and maximums are answered by Context.
1711 // Queries about current GL state values are answered by State.
1712
1713 GLenum nativeType;
1714 unsigned int numParams;
1715 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1716 ASSERT(queryStatus);
1717
1718 if (nativeType == GL_BOOL)
1719 {
1720 mGLState.getBooleani_v(target, index, data);
1721 }
1722 else
1723 {
1724 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1725 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001726}
1727
Corentin Wallez336129f2017-10-17 15:55:40 -04001728void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001729{
1730 Buffer *buffer = mGLState.getTargetBuffer(target);
1731 QueryBufferParameteriv(buffer, pname, params);
1732}
1733
1734void Context::getFramebufferAttachmentParameteriv(GLenum target,
1735 GLenum attachment,
1736 GLenum pname,
1737 GLint *params)
1738{
1739 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001740 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001741}
1742
1743void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1744{
1745 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1746 QueryRenderbufferiv(this, renderbuffer, pname, params);
1747}
1748
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001749void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001750{
1751 Texture *texture = getTargetTexture(target);
1752 QueryTexParameterfv(texture, pname, params);
1753}
1754
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001755void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001756{
1757 Texture *texture = getTargetTexture(target);
1758 QueryTexParameteriv(texture, pname, params);
1759}
Jiajia Qin5451d532017-11-16 17:16:34 +08001760
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001761void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001762{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001763 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001764 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001765}
1766
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001767void Context::getTexLevelParameterfv(TextureTarget target,
1768 GLint level,
1769 GLenum pname,
1770 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001771{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001772 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001773 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001774}
1775
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001776void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001777{
1778 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001779 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001780 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001781}
1782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001783void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001784{
1785 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001786 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001787 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001788}
1789
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001790void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001791{
1792 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001793 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001794 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001795}
1796
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001797void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001798{
1799 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001800 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001801 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001802}
1803
Jamie Madill675fe712016-12-19 13:07:54 -05001804void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001805{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001806 // No-op if zero count
1807 if (count == 0)
1808 {
1809 return;
1810 }
1811
Jamie Madill05b35b22017-10-03 09:01:44 -04001812 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001813 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1814 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001815}
1816
Jamie Madill675fe712016-12-19 13:07:54 -05001817void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001818{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001819 // No-op if zero count
1820 if (count == 0 || instanceCount == 0)
1821 {
1822 return;
1823 }
1824
Jamie Madill05b35b22017-10-03 09:01:44 -04001825 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001826 ANGLE_CONTEXT_TRY(
1827 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1828 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001829}
1830
Jamie Madill876429b2017-04-20 15:46:24 -04001831void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001832{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001833 // No-op if zero count
1834 if (count == 0)
1835 {
1836 return;
1837 }
1838
Jamie Madill05b35b22017-10-03 09:01:44 -04001839 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001840 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001841}
1842
Jamie Madill675fe712016-12-19 13:07:54 -05001843void Context::drawElementsInstanced(GLenum mode,
1844 GLsizei count,
1845 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001846 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001847 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001848{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001849 // No-op if zero count
1850 if (count == 0 || instances == 0)
1851 {
1852 return;
1853 }
1854
Jamie Madill05b35b22017-10-03 09:01:44 -04001855 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001856 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001857 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001858}
1859
Jamie Madill675fe712016-12-19 13:07:54 -05001860void Context::drawRangeElements(GLenum mode,
1861 GLuint start,
1862 GLuint end,
1863 GLsizei count,
1864 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001865 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001866{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001867 // No-op if zero count
1868 if (count == 0)
1869 {
1870 return;
1871 }
1872
Jamie Madill05b35b22017-10-03 09:01:44 -04001873 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001874 ANGLE_CONTEXT_TRY(
1875 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001876}
1877
Jamie Madill876429b2017-04-20 15:46:24 -04001878void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001879{
Jamie Madill05b35b22017-10-03 09:01:44 -04001880 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001881 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001882}
1883
Jamie Madill876429b2017-04-20 15:46:24 -04001884void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001885{
Jamie Madill05b35b22017-10-03 09:01:44 -04001886 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001887 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001888}
1889
Jamie Madill675fe712016-12-19 13:07:54 -05001890void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001891{
Jamie Madillafa02a22017-11-23 12:57:38 -05001892 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001893}
1894
Jamie Madill675fe712016-12-19 13:07:54 -05001895void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001896{
Jamie Madillafa02a22017-11-23 12:57:38 -05001897 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001898}
1899
Austin Kinross6ee1e782015-05-29 17:05:37 -07001900void Context::insertEventMarker(GLsizei length, const char *marker)
1901{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001902 ASSERT(mImplementation);
1903 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001904}
1905
1906void Context::pushGroupMarker(GLsizei length, const char *marker)
1907{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001908 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001909
1910 if (marker == nullptr)
1911 {
1912 // From the EXT_debug_marker spec,
1913 // "If <marker> is null then an empty string is pushed on the stack."
1914 mImplementation->pushGroupMarker(length, "");
1915 }
1916 else
1917 {
1918 mImplementation->pushGroupMarker(length, marker);
1919 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001920}
1921
1922void Context::popGroupMarker()
1923{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001924 ASSERT(mImplementation);
1925 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001926}
1927
Geoff Langd8605522016-04-13 10:19:12 -04001928void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1929{
1930 Program *programObject = getProgram(program);
1931 ASSERT(programObject);
1932
1933 programObject->bindUniformLocation(location, name);
1934}
1935
Sami Väisänena797e062016-05-12 15:23:40 +03001936void Context::setCoverageModulation(GLenum components)
1937{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001938 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001939}
1940
Sami Väisänene45e53b2016-05-25 10:36:04 +03001941void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1942{
1943 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1944}
1945
1946void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1947{
1948 GLfloat I[16];
1949 angle::Matrix<GLfloat>::setToIdentity(I);
1950
1951 mGLState.loadPathRenderingMatrix(matrixMode, I);
1952}
1953
1954void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1955{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001956 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001957 if (!pathObj)
1958 return;
1959
1960 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001961 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001962
1963 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1964}
1965
1966void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1967{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001968 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001969 if (!pathObj)
1970 return;
1971
1972 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001973 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001974
1975 mImplementation->stencilStrokePath(pathObj, reference, mask);
1976}
1977
1978void Context::coverFillPath(GLuint path, GLenum coverMode)
1979{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001980 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001981 if (!pathObj)
1982 return;
1983
1984 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001985 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001986
1987 mImplementation->coverFillPath(pathObj, coverMode);
1988}
1989
1990void Context::coverStrokePath(GLuint path, GLenum coverMode)
1991{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001992 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001993 if (!pathObj)
1994 return;
1995
1996 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001997 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001998
1999 mImplementation->coverStrokePath(pathObj, coverMode);
2000}
2001
2002void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2003{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002004 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002005 if (!pathObj)
2006 return;
2007
2008 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002009 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002010
2011 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2012}
2013
2014void Context::stencilThenCoverStrokePath(GLuint path,
2015 GLint reference,
2016 GLuint mask,
2017 GLenum coverMode)
2018{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002019 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002020 if (!pathObj)
2021 return;
2022
2023 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002024 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002025
2026 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2027}
2028
Sami Väisänend59ca052016-06-21 16:10:00 +03002029void Context::coverFillPathInstanced(GLsizei numPaths,
2030 GLenum pathNameType,
2031 const void *paths,
2032 GLuint pathBase,
2033 GLenum coverMode,
2034 GLenum transformType,
2035 const GLfloat *transformValues)
2036{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002037 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002038
2039 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002040 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002041
2042 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2043}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002044
Sami Väisänend59ca052016-06-21 16:10:00 +03002045void Context::coverStrokePathInstanced(GLsizei numPaths,
2046 GLenum pathNameType,
2047 const void *paths,
2048 GLuint pathBase,
2049 GLenum coverMode,
2050 GLenum transformType,
2051 const GLfloat *transformValues)
2052{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002053 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002054
2055 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002056 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002057
2058 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2059 transformValues);
2060}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002061
Sami Väisänend59ca052016-06-21 16:10:00 +03002062void Context::stencilFillPathInstanced(GLsizei numPaths,
2063 GLenum pathNameType,
2064 const void *paths,
2065 GLuint pathBase,
2066 GLenum fillMode,
2067 GLuint mask,
2068 GLenum transformType,
2069 const GLfloat *transformValues)
2070{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002071 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002072
2073 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002074 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002075
2076 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2077 transformValues);
2078}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002079
Sami Väisänend59ca052016-06-21 16:10:00 +03002080void Context::stencilStrokePathInstanced(GLsizei numPaths,
2081 GLenum pathNameType,
2082 const void *paths,
2083 GLuint pathBase,
2084 GLint reference,
2085 GLuint mask,
2086 GLenum transformType,
2087 const GLfloat *transformValues)
2088{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002089 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002090
2091 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002092 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002093
2094 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2095 transformValues);
2096}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002097
Sami Väisänend59ca052016-06-21 16:10:00 +03002098void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2099 GLenum pathNameType,
2100 const void *paths,
2101 GLuint pathBase,
2102 GLenum fillMode,
2103 GLuint mask,
2104 GLenum coverMode,
2105 GLenum transformType,
2106 const GLfloat *transformValues)
2107{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002108 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002109
2110 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002111 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002112
2113 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2114 transformType, transformValues);
2115}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002116
Sami Väisänend59ca052016-06-21 16:10:00 +03002117void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2118 GLenum pathNameType,
2119 const void *paths,
2120 GLuint pathBase,
2121 GLint reference,
2122 GLuint mask,
2123 GLenum coverMode,
2124 GLenum transformType,
2125 const GLfloat *transformValues)
2126{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002127 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002128
2129 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002130 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002131
2132 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2133 transformType, transformValues);
2134}
2135
Sami Väisänen46eaa942016-06-29 10:26:37 +03002136void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2137{
2138 auto *programObject = getProgram(program);
2139
2140 programObject->bindFragmentInputLocation(location, name);
2141}
2142
2143void Context::programPathFragmentInputGen(GLuint program,
2144 GLint location,
2145 GLenum genMode,
2146 GLint components,
2147 const GLfloat *coeffs)
2148{
2149 auto *programObject = getProgram(program);
2150
Jamie Madillbd044ed2017-06-05 12:59:21 -04002151 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002152}
2153
jchen1015015f72017-03-16 13:54:21 +08002154GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2155{
jchen10fd7c3b52017-03-21 15:36:03 +08002156 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002157 return QueryProgramResourceIndex(programObject, programInterface, name);
2158}
2159
jchen10fd7c3b52017-03-21 15:36:03 +08002160void Context::getProgramResourceName(GLuint program,
2161 GLenum programInterface,
2162 GLuint index,
2163 GLsizei bufSize,
2164 GLsizei *length,
2165 GLchar *name)
2166{
2167 const auto *programObject = getProgram(program);
2168 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2169}
2170
jchen10191381f2017-04-11 13:59:04 +08002171GLint Context::getProgramResourceLocation(GLuint program,
2172 GLenum programInterface,
2173 const GLchar *name)
2174{
2175 const auto *programObject = getProgram(program);
2176 return QueryProgramResourceLocation(programObject, programInterface, name);
2177}
2178
jchen10880683b2017-04-12 16:21:55 +08002179void Context::getProgramResourceiv(GLuint program,
2180 GLenum programInterface,
2181 GLuint index,
2182 GLsizei propCount,
2183 const GLenum *props,
2184 GLsizei bufSize,
2185 GLsizei *length,
2186 GLint *params)
2187{
2188 const auto *programObject = getProgram(program);
2189 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2190 length, params);
2191}
2192
jchen10d9cd7b72017-08-30 15:04:25 +08002193void Context::getProgramInterfaceiv(GLuint program,
2194 GLenum programInterface,
2195 GLenum pname,
2196 GLint *params)
2197{
2198 const auto *programObject = getProgram(program);
2199 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2200}
2201
Jamie Madill71c88b32017-09-14 22:20:29 -04002202void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203{
Geoff Langda5777c2014-07-11 09:52:58 -04002204 if (error.isError())
2205 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002206 GLenum code = error.getCode();
2207 mErrors.insert(code);
2208 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2209 {
2210 markContextLost();
2211 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002212
Geoff Langee6884e2017-11-09 16:51:11 -05002213 ASSERT(!error.getMessage().empty());
2214 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2215 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002216 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002217}
2218
2219// Get one of the recorded errors and clear its flag, if any.
2220// [OpenGL ES 2.0.24] section 2.5 page 13.
2221GLenum Context::getError()
2222{
Geoff Langda5777c2014-07-11 09:52:58 -04002223 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224 {
Geoff Langda5777c2014-07-11 09:52:58 -04002225 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226 }
Geoff Langda5777c2014-07-11 09:52:58 -04002227 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228 {
Geoff Langda5777c2014-07-11 09:52:58 -04002229 GLenum error = *mErrors.begin();
2230 mErrors.erase(mErrors.begin());
2231 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002233}
2234
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235// NOTE: this function should not assume that this context is current!
2236void Context::markContextLost()
2237{
2238 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002239 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002240 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002241 mContextLostForced = true;
2242 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002243 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002244}
2245
2246bool Context::isContextLost()
2247{
2248 return mContextLost;
2249}
2250
Jamie Madillfa920eb2018-01-04 11:45:50 -05002251GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002253 // Even if the application doesn't want to know about resets, we want to know
2254 // as it will allow us to skip all the calls.
2255 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002256 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002257 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002258 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002259 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002260 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002261
2262 // EXT_robustness, section 2.6: If the reset notification behavior is
2263 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2264 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2265 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002266 }
2267
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2269 // status should be returned at least once, and GL_NO_ERROR should be returned
2270 // once the device has finished resetting.
2271 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002272 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002273 ASSERT(mResetStatus == GL_NO_ERROR);
2274 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002275
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002276 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002277 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002278 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002279 }
2280 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002281 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002282 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002283 // If markContextLost was used to mark the context lost then
2284 // assume that is not recoverable, and continue to report the
2285 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002286 mResetStatus = mImplementation->getResetStatus();
2287 }
Jamie Madill893ab082014-05-16 16:56:10 -04002288
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002289 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002290}
2291
2292bool Context::isResetNotificationEnabled()
2293{
2294 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2295}
2296
Corentin Walleze3b10e82015-05-20 11:06:25 -04002297const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002298{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002299 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002300}
2301
2302EGLenum Context::getClientType() const
2303{
2304 return mClientType;
2305}
2306
2307EGLenum Context::getRenderBuffer() const
2308{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002309 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2310 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002311 {
2312 return EGL_NONE;
2313 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002314
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002315 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002316 ASSERT(backAttachment != nullptr);
2317 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002318}
2319
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002320VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002321{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002322 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002323 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2324 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002325 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002326 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2327 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002328
Jamie Madill96a483b2017-06-27 16:49:21 -04002329 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002330 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002331
2332 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002333}
2334
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002335TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002336{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002337 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002338 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2339 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002340 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002341 transformFeedback =
2342 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002343 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002344 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002345 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002346
2347 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002348}
2349
2350bool Context::isVertexArrayGenerated(GLuint vertexArray)
2351{
Jamie Madill96a483b2017-06-27 16:49:21 -04002352 ASSERT(mVertexArrayMap.contains(0));
2353 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002354}
2355
2356bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2357{
Jamie Madill96a483b2017-06-27 16:49:21 -04002358 ASSERT(mTransformFeedbackMap.contains(0));
2359 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002360}
2361
Shannon Woods53a94a82014-06-24 15:20:36 -04002362void Context::detachTexture(GLuint texture)
2363{
2364 // Simple pass-through to State's detachTexture method, as textures do not require
2365 // allocation map management either here or in the resource manager at detach time.
2366 // Zero textures are held by the Context, and we don't attempt to request them from
2367 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002368 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002369}
2370
James Darpinian4d9d4832018-03-13 12:43:28 -07002371void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372{
Yuly Novikov5807a532015-12-03 13:01:22 -05002373 // Simple pass-through to State's detachBuffer method, since
2374 // only buffer attachments to container objects that are bound to the current context
2375 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002376
Yuly Novikov5807a532015-12-03 13:01:22 -05002377 // [OpenGL ES 3.2] section 5.1.2 page 45:
2378 // Attachments to unbound container objects, such as
2379 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2380 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002381 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002382}
2383
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002384void Context::detachFramebuffer(GLuint framebuffer)
2385{
Shannon Woods53a94a82014-06-24 15:20:36 -04002386 // Framebuffer detachment is handled by Context, because 0 is a valid
2387 // Framebuffer object, and a pointer to it must be passed from Context
2388 // to State at binding time.
2389
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002390 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002391 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2392 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2393 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002394
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002395 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396 {
2397 bindReadFramebuffer(0);
2398 }
2399
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002400 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002401 {
2402 bindDrawFramebuffer(0);
2403 }
2404}
2405
2406void Context::detachRenderbuffer(GLuint renderbuffer)
2407{
Jamie Madilla02315b2017-02-23 14:14:47 -05002408 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002409}
2410
Jamie Madill57a89722013-07-02 11:57:03 -04002411void Context::detachVertexArray(GLuint vertexArray)
2412{
Jamie Madill77a72f62015-04-14 11:18:32 -04002413 // Vertex array detachment is handled by Context, because 0 is a valid
2414 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002415 // binding time.
2416
Jamie Madill57a89722013-07-02 11:57:03 -04002417 // [OpenGL ES 3.0.2] section 2.10 page 43:
2418 // If a vertex array object that is currently bound is deleted, the binding
2419 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002420 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002421 {
2422 bindVertexArray(0);
2423 }
2424}
2425
Geoff Langc8058452014-02-03 12:04:11 -05002426void Context::detachTransformFeedback(GLuint transformFeedback)
2427{
Corentin Walleza2257da2016-04-19 16:43:12 -04002428 // Transform feedback detachment is handled by Context, because 0 is a valid
2429 // transform feedback, and a pointer to it must be passed from Context to State at
2430 // binding time.
2431
2432 // The OpenGL specification doesn't mention what should happen when the currently bound
2433 // transform feedback object is deleted. Since it is a container object, we treat it like
2434 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002435 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002436 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002437 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002438 }
Geoff Langc8058452014-02-03 12:04:11 -05002439}
2440
Jamie Madilldc356042013-07-19 16:36:57 -04002441void Context::detachSampler(GLuint sampler)
2442{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002443 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002444}
2445
Yunchao Hea336b902017-08-02 16:05:21 +08002446void Context::detachProgramPipeline(GLuint pipeline)
2447{
2448 mGLState.detachProgramPipeline(this, pipeline);
2449}
2450
Jamie Madill3ef140a2017-08-26 23:11:21 -04002451void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002452{
Shaodde78e82017-05-22 14:13:27 +08002453 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002454}
2455
Jamie Madille29d1672013-07-19 16:36:57 -04002456void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2457{
Geoff Langc1984ed2016-10-07 12:41:00 -04002458 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002459 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002461 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462}
Jamie Madille29d1672013-07-19 16:36:57 -04002463
Geoff Langc1984ed2016-10-07 12:41:00 -04002464void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2465{
2466 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002467 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002468 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002469 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002470}
2471
2472void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2473{
Geoff Langc1984ed2016-10-07 12:41:00 -04002474 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002475 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002476 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002477 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002478}
2479
Geoff Langc1984ed2016-10-07 12:41:00 -04002480void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002481{
Geoff Langc1984ed2016-10-07 12:41:00 -04002482 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002483 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002484 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002485 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002486}
2487
Geoff Langc1984ed2016-10-07 12:41:00 -04002488void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002489{
Geoff Langc1984ed2016-10-07 12:41:00 -04002490 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002491 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002492 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002493 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002494}
Jamie Madill9675b802013-07-19 16:36:59 -04002495
Geoff Langc1984ed2016-10-07 12:41:00 -04002496void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2497{
2498 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002499 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002500 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002501 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002502}
2503
Olli Etuahof0fee072016-03-30 15:11:58 +03002504void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2505{
2506 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002507 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002508}
2509
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002510void Context::initRendererString()
2511{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002512 std::ostringstream rendererString;
2513 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002514 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002515 rendererString << ")";
2516
Geoff Langcec35902014-04-16 10:52:36 -04002517 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002518}
2519
Geoff Langc339c4e2016-11-29 10:37:36 -05002520void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521{
Geoff Langc339c4e2016-11-29 10:37:36 -05002522 const Version &clientVersion = getClientVersion();
2523
2524 std::ostringstream versionString;
2525 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2526 << ANGLE_VERSION_STRING << ")";
2527 mVersionString = MakeStaticString(versionString.str());
2528
2529 std::ostringstream shadingLanguageVersionString;
2530 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2531 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2532 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2533 << ")";
2534 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002535}
2536
Geoff Langcec35902014-04-16 10:52:36 -04002537void Context::initExtensionStrings()
2538{
Geoff Langc339c4e2016-11-29 10:37:36 -05002539 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2540 std::ostringstream combinedStringStream;
2541 std::copy(strings.begin(), strings.end(),
2542 std::ostream_iterator<const char *>(combinedStringStream, " "));
2543 return MakeStaticString(combinedStringStream.str());
2544 };
2545
2546 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002547 for (const auto &extensionString : mExtensions.getStrings())
2548 {
2549 mExtensionStrings.push_back(MakeStaticString(extensionString));
2550 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002551 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002552
Bryan Bernhart58806562017-01-05 13:09:31 -08002553 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2554
Geoff Langc339c4e2016-11-29 10:37:36 -05002555 mRequestableExtensionStrings.clear();
2556 for (const auto &extensionInfo : GetExtensionInfoMap())
2557 {
2558 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002559 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2560 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002561 {
2562 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2563 }
2564 }
2565 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002566}
2567
Geoff Langc339c4e2016-11-29 10:37:36 -05002568const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002569{
Geoff Langc339c4e2016-11-29 10:37:36 -05002570 switch (name)
2571 {
2572 case GL_VENDOR:
2573 return reinterpret_cast<const GLubyte *>("Google Inc.");
2574
2575 case GL_RENDERER:
2576 return reinterpret_cast<const GLubyte *>(mRendererString);
2577
2578 case GL_VERSION:
2579 return reinterpret_cast<const GLubyte *>(mVersionString);
2580
2581 case GL_SHADING_LANGUAGE_VERSION:
2582 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2583
2584 case GL_EXTENSIONS:
2585 return reinterpret_cast<const GLubyte *>(mExtensionString);
2586
2587 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2588 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2589
2590 default:
2591 UNREACHABLE();
2592 return nullptr;
2593 }
Geoff Langcec35902014-04-16 10:52:36 -04002594}
2595
Geoff Langc339c4e2016-11-29 10:37:36 -05002596const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002597{
Geoff Langc339c4e2016-11-29 10:37:36 -05002598 switch (name)
2599 {
2600 case GL_EXTENSIONS:
2601 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2602
2603 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2604 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2605
2606 default:
2607 UNREACHABLE();
2608 return nullptr;
2609 }
Geoff Langcec35902014-04-16 10:52:36 -04002610}
2611
2612size_t Context::getExtensionStringCount() const
2613{
2614 return mExtensionStrings.size();
2615}
2616
Geoff Lang111a99e2017-10-17 10:58:41 -04002617bool Context::isExtensionRequestable(const char *name)
2618{
2619 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2620 auto extension = extensionInfos.find(name);
2621
2622 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2623 return extension != extensionInfos.end() && extension->second.Requestable &&
2624 nativeExtensions.*(extension->second.ExtensionsMember);
2625}
2626
Geoff Langc339c4e2016-11-29 10:37:36 -05002627void Context::requestExtension(const char *name)
2628{
2629 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2630 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2631 const auto &extension = extensionInfos.at(name);
2632 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002633 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002634
2635 if (mExtensions.*(extension.ExtensionsMember))
2636 {
2637 // Extension already enabled
2638 return;
2639 }
2640
2641 mExtensions.*(extension.ExtensionsMember) = true;
2642 updateCaps();
2643 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002644
Jamie Madill2f348d22017-06-05 10:50:59 -04002645 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2646 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002647
Jamie Madill81c2e252017-09-09 23:32:46 -04002648 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2649 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002650 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002651 for (auto &zeroTexture : mZeroTextures)
2652 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002653 if (zeroTexture.get() != nullptr)
2654 {
2655 zeroTexture->signalDirty(this, InitState::Initialized);
2656 }
Geoff Lang9aded172017-04-05 11:07:56 -04002657 }
2658
2659 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002660}
2661
2662size_t Context::getRequestableExtensionStringCount() const
2663{
2664 return mRequestableExtensionStrings.size();
2665}
2666
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002667void Context::beginTransformFeedback(GLenum primitiveMode)
2668{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002669 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002670 ASSERT(transformFeedback != nullptr);
2671 ASSERT(!transformFeedback->isPaused());
2672
Jamie Madill6c1f6712017-02-14 19:08:04 -05002673 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002674}
2675
2676bool Context::hasActiveTransformFeedback(GLuint program) const
2677{
2678 for (auto pair : mTransformFeedbackMap)
2679 {
2680 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2681 {
2682 return true;
2683 }
2684 }
2685 return false;
2686}
2687
Geoff Langb433e872017-10-05 14:01:47 -04002688void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002689{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002690 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002691
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002692 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2693 if (getClientVersion() < Version(2, 0))
2694 {
2695 mCaps.maxMultitextureUnits = 4;
2696 mCaps.maxClipPlanes = 6;
2697 mCaps.maxLights = 8;
2698 mCaps.maxModelviewMatrixStackDepth = 16;
2699 mCaps.maxProjectionMatrixStackDepth = 16;
2700 mCaps.maxTextureMatrixStackDepth = 16;
2701 }
2702
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002703 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002704
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002705 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002706
Geoff Langeb66a6e2016-10-31 13:06:12 -04002707 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002708 {
2709 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002710 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002711 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002712 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002713 mExtensions.multiview = false;
2714 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002715 }
2716
Jiawei Shao89be29a2017-11-06 14:36:45 +08002717 if (getClientVersion() < ES_3_1)
2718 {
2719 // Disable ES3.1+ extensions
2720 mExtensions.geometryShader = false;
2721 }
2722
Geoff Langeb66a6e2016-10-31 13:06:12 -04002723 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002724 {
2725 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002726 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002727 }
2728
Jamie Madill00ed7a12016-05-19 13:13:38 -04002729 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002730 mExtensions.bindUniformLocation = true;
2731 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002732 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002733 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002734 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002735
2736 // Enable the no error extension if the context was created with the flag.
2737 mExtensions.noError = mSkipValidation;
2738
Corentin Wallezccab69d2017-01-27 16:57:15 -05002739 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002740 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002741
Geoff Lang70d0f492015-12-10 17:45:46 -05002742 // Explicitly enable GL_KHR_debug
2743 mExtensions.debug = true;
2744 mExtensions.maxDebugMessageLength = 1024;
2745 mExtensions.maxDebugLoggedMessages = 1024;
2746 mExtensions.maxDebugGroupStackDepth = 1024;
2747 mExtensions.maxLabelLength = 1024;
2748
Geoff Langff5b2d52016-09-07 11:32:23 -04002749 // Explicitly enable GL_ANGLE_robust_client_memory
2750 mExtensions.robustClientMemory = true;
2751
Jamie Madille08a1d32017-03-07 17:24:06 -05002752 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002753 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002754
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002755 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2756 // supports it.
2757 mExtensions.robustBufferAccessBehavior =
2758 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2759
Jamie Madillc43be722017-07-13 16:22:14 -04002760 // Enable the cache control query unconditionally.
2761 mExtensions.programCacheControl = true;
2762
Geoff Lang301d1612014-07-09 10:34:37 -04002763 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002764 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002765
Jamie Madill0f80ed82017-09-19 00:24:56 -04002766 if (getClientVersion() < ES_3_1)
2767 {
2768 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2769 }
2770 else
2771 {
2772 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2773 }
Geoff Lang301d1612014-07-09 10:34:37 -04002774
Jamie Madill0f80ed82017-09-19 00:24:56 -04002775 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2776 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2777 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2778
2779 // Limit textures as well, so we can use fast bitsets with texture bindings.
2780 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2781 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2782 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002783
Jiawei Shaodb342272017-09-27 10:21:45 +08002784 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2785
Geoff Langc287ea62016-09-16 14:46:51 -04002786 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002787 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002788 for (const auto &extensionInfo : GetExtensionInfoMap())
2789 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04002790 // If the user has requested that extensions start disabled and they are requestable,
2791 // disable them.
2792 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002793 {
2794 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2795 }
2796 }
2797
2798 // Generate texture caps
2799 updateCaps();
2800}
2801
2802void Context::updateCaps()
2803{
Geoff Lang900013c2014-07-07 11:32:19 -04002804 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002805 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002806
Jamie Madill7b62cf92017-11-02 15:20:49 -04002807 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002808 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002809 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002810 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002811
Geoff Lang0d8b7242015-09-09 14:56:53 -04002812 // Update the format caps based on the client version and extensions.
2813 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2814 // ES3.
2815 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002816 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002817 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002818 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002819 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002820 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002821
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002822 // OpenGL ES does not support multisampling with non-rendererable formats
2823 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002824 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002825 (getClientVersion() < ES_3_1 &&
2826 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002827 {
Geoff Langd87878e2014-09-19 15:42:59 -04002828 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002829 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002830 else
2831 {
2832 // We may have limited the max samples for some required renderbuffer formats due to
2833 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2834 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2835
2836 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2837 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2838 // exception of signed and unsigned integer formats."
2839 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2840 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2841 {
2842 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2843 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2844 }
2845
2846 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2847 if (getClientVersion() >= ES_3_1)
2848 {
2849 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2850 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2851 // the exception that the signed and unsigned integer formats are required only to
2852 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2853 // multisamples, which must be at least one."
2854 if (formatInfo.componentType == GL_INT ||
2855 formatInfo.componentType == GL_UNSIGNED_INT)
2856 {
2857 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2858 }
2859
2860 // GLES 3.1 section 19.3.1.
2861 if (formatCaps.texturable)
2862 {
2863 if (formatInfo.depthBits > 0)
2864 {
2865 mCaps.maxDepthTextureSamples =
2866 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2867 }
2868 else if (formatInfo.redBits > 0)
2869 {
2870 mCaps.maxColorTextureSamples =
2871 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2872 }
2873 }
2874 }
2875 }
Geoff Langd87878e2014-09-19 15:42:59 -04002876
2877 if (formatCaps.texturable && formatInfo.compressed)
2878 {
Geoff Langca271392017-04-05 12:30:00 -04002879 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002880 }
2881
Geoff Langca271392017-04-05 12:30:00 -04002882 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002883 }
Jamie Madill32447362017-06-28 14:53:52 -04002884
2885 // If program binary is disabled, blank out the memory cache pointer.
2886 if (!mImplementation->getNativeExtensions().getProgramBinary)
2887 {
2888 mMemoryProgramCache = nullptr;
2889 }
Corentin Walleze4477002017-12-01 14:39:58 -05002890
2891 // Compute which buffer types are allowed
2892 mValidBufferBindings.reset();
2893 mValidBufferBindings.set(BufferBinding::ElementArray);
2894 mValidBufferBindings.set(BufferBinding::Array);
2895
2896 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2897 {
2898 mValidBufferBindings.set(BufferBinding::PixelPack);
2899 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2900 }
2901
2902 if (getClientVersion() >= ES_3_0)
2903 {
2904 mValidBufferBindings.set(BufferBinding::CopyRead);
2905 mValidBufferBindings.set(BufferBinding::CopyWrite);
2906 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2907 mValidBufferBindings.set(BufferBinding::Uniform);
2908 }
2909
2910 if (getClientVersion() >= ES_3_1)
2911 {
2912 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2913 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2914 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2915 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2916 }
Geoff Lang493daf52014-07-03 13:38:44 -04002917}
2918
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002919void Context::initWorkarounds()
2920{
Jamie Madill761b02c2017-06-23 16:27:06 -04002921 // Apply back-end workarounds.
2922 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2923
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002924 // Lose the context upon out of memory error if the application is
2925 // expecting to watch for those events.
2926 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2927}
2928
Jamie Madill05b35b22017-10-03 09:01:44 -04002929Error Context::prepareForDraw()
2930{
Geoff Langa8cb2872018-03-09 16:09:40 -05002931 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002932
2933 if (isRobustResourceInitEnabled())
2934 {
2935 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2936 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2937 }
2938
Geoff Langa8cb2872018-03-09 16:09:40 -05002939 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04002940 return NoError();
2941}
2942
2943Error Context::prepareForClear(GLbitfield mask)
2944{
Geoff Langa8cb2872018-03-09 16:09:40 -05002945 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002946 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05002947 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04002948 return NoError();
2949}
2950
2951Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2952{
Geoff Langa8cb2872018-03-09 16:09:40 -05002953 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002954 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2955 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05002956 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002957 return NoError();
2958}
2959
Geoff Langa8cb2872018-03-09 16:09:40 -05002960Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002961{
Geoff Langa8cb2872018-03-09 16:09:40 -05002962 ANGLE_TRY(syncDirtyObjects());
2963 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002964 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002965}
2966
Geoff Langa8cb2872018-03-09 16:09:40 -05002967Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002968{
Geoff Langa8cb2872018-03-09 16:09:40 -05002969 ANGLE_TRY(syncDirtyObjects(objectMask));
2970 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04002971 return NoError();
2972}
2973
Geoff Langa8cb2872018-03-09 16:09:40 -05002974Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04002975{
2976 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2977 mImplementation->syncState(this, dirtyBits);
2978 mGLState.clearDirtyBits();
2979 return NoError();
2980}
2981
Geoff Langa8cb2872018-03-09 16:09:40 -05002982Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002983{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002984 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002985 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002986 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002987 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002988}
Jamie Madillc29968b2016-01-20 11:17:23 -05002989
Geoff Langa8cb2872018-03-09 16:09:40 -05002990Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04002991{
2992 return mGLState.syncDirtyObjects(this);
2993}
2994
Geoff Langa8cb2872018-03-09 16:09:40 -05002995Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002996{
2997 return mGLState.syncDirtyObjects(this, objectMask);
2998}
2999
Jamie Madillc29968b2016-01-20 11:17:23 -05003000void Context::blitFramebuffer(GLint srcX0,
3001 GLint srcY0,
3002 GLint srcX1,
3003 GLint srcY1,
3004 GLint dstX0,
3005 GLint dstY0,
3006 GLint dstX1,
3007 GLint dstY1,
3008 GLbitfield mask,
3009 GLenum filter)
3010{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003011 if (mask == 0)
3012 {
3013 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3014 // buffers are copied.
3015 return;
3016 }
3017
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003018 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003019 ASSERT(drawFramebuffer);
3020
3021 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3022 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3023
Jamie Madillbc918e72018-03-08 09:47:21 -05003024 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003025
Jamie Madillc564c072017-06-01 12:45:42 -04003026 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003027}
Jamie Madillc29968b2016-01-20 11:17:23 -05003028
3029void Context::clear(GLbitfield mask)
3030{
Geoff Langd4fff502017-09-22 11:28:28 -04003031 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3032 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003033}
3034
3035void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3036{
Geoff Langd4fff502017-09-22 11:28:28 -04003037 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3038 ANGLE_CONTEXT_TRY(
3039 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003040}
3041
3042void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3043{
Geoff Langd4fff502017-09-22 11:28:28 -04003044 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3045 ANGLE_CONTEXT_TRY(
3046 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003047}
3048
3049void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3050{
Geoff Langd4fff502017-09-22 11:28:28 -04003051 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3052 ANGLE_CONTEXT_TRY(
3053 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003054}
3055
3056void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003058 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003059 ASSERT(framebufferObject);
3060
3061 // If a buffer is not present, the clear has no effect
3062 if (framebufferObject->getDepthbuffer() == nullptr &&
3063 framebufferObject->getStencilbuffer() == nullptr)
3064 {
3065 return;
3066 }
3067
Geoff Langd4fff502017-09-22 11:28:28 -04003068 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3069 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003070}
3071
3072void Context::readPixels(GLint x,
3073 GLint y,
3074 GLsizei width,
3075 GLsizei height,
3076 GLenum format,
3077 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003078 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003079{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003080 if (width == 0 || height == 0)
3081 {
3082 return;
3083 }
3084
Jamie Madillbc918e72018-03-08 09:47:21 -05003085 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003086
Jamie Madillb6664922017-07-25 12:55:04 -04003087 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3088 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003089
3090 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003091 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003092}
3093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003094void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003095 GLint level,
3096 GLenum internalformat,
3097 GLint x,
3098 GLint y,
3099 GLsizei width,
3100 GLsizei height,
3101 GLint border)
3102{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003103 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003104 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003105
Jamie Madillc29968b2016-01-20 11:17:23 -05003106 Rectangle sourceArea(x, y, width, height);
3107
Jamie Madill05b35b22017-10-03 09:01:44 -04003108 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003109 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003110 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003111}
3112
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003113void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003114 GLint level,
3115 GLint xoffset,
3116 GLint yoffset,
3117 GLint x,
3118 GLint y,
3119 GLsizei width,
3120 GLsizei height)
3121{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003122 if (width == 0 || height == 0)
3123 {
3124 return;
3125 }
3126
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003127 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003128 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003129
Jamie Madillc29968b2016-01-20 11:17:23 -05003130 Offset destOffset(xoffset, yoffset, 0);
3131 Rectangle sourceArea(x, y, width, height);
3132
Jamie Madill05b35b22017-10-03 09:01:44 -04003133 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003134 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003135 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003136}
3137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003138void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003139 GLint level,
3140 GLint xoffset,
3141 GLint yoffset,
3142 GLint zoffset,
3143 GLint x,
3144 GLint y,
3145 GLsizei width,
3146 GLsizei height)
3147{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003148 if (width == 0 || height == 0)
3149 {
3150 return;
3151 }
3152
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003153 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003154 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003155
Jamie Madillc29968b2016-01-20 11:17:23 -05003156 Offset destOffset(xoffset, yoffset, zoffset);
3157 Rectangle sourceArea(x, y, width, height);
3158
Jamie Madill05b35b22017-10-03 09:01:44 -04003159 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3160 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003161 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3162 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003163}
3164
3165void Context::framebufferTexture2D(GLenum target,
3166 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003167 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003168 GLuint texture,
3169 GLint level)
3170{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003171 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003172 ASSERT(framebuffer);
3173
3174 if (texture != 0)
3175 {
3176 Texture *textureObj = getTexture(texture);
3177
3178 ImageIndex index = ImageIndex::MakeInvalid();
3179
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003180 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003181 {
3182 index = ImageIndex::Make2D(level);
3183 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003184 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003185 {
3186 index = ImageIndex::MakeRectangle(level);
3187 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003188 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003189 {
3190 ASSERT(level == 0);
3191 index = ImageIndex::Make2DMultisample();
3192 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 else
3194 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003195 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003196 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003197 }
3198
Jamie Madilla02315b2017-02-23 14:14:47 -05003199 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003200 }
3201 else
3202 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003203 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003204 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003205
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003206 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003207}
3208
3209void Context::framebufferRenderbuffer(GLenum target,
3210 GLenum attachment,
3211 GLenum renderbuffertarget,
3212 GLuint renderbuffer)
3213{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003214 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003215 ASSERT(framebuffer);
3216
3217 if (renderbuffer != 0)
3218 {
3219 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003220
3221 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003222 renderbufferObject);
3223 }
3224 else
3225 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003226 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003227 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003228
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003229 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003230}
3231
3232void Context::framebufferTextureLayer(GLenum target,
3233 GLenum attachment,
3234 GLuint texture,
3235 GLint level,
3236 GLint layer)
3237{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003238 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003239 ASSERT(framebuffer);
3240
3241 if (texture != 0)
3242 {
3243 Texture *textureObject = getTexture(texture);
3244
3245 ImageIndex index = ImageIndex::MakeInvalid();
3246
Corentin Wallez99d492c2018-02-27 15:17:10 -05003247 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003248 {
3249 index = ImageIndex::Make3D(level, layer);
3250 }
3251 else
3252 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003253 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003254 index = ImageIndex::Make2DArray(level, layer);
3255 }
3256
Jamie Madilla02315b2017-02-23 14:14:47 -05003257 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003258 }
3259 else
3260 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003261 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003262 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003263
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003264 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003265}
3266
Martin Radev137032d2017-07-13 10:11:12 +03003267void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3268 GLenum attachment,
3269 GLuint texture,
3270 GLint level,
3271 GLint baseViewIndex,
3272 GLsizei numViews)
3273{
Martin Radev82ef7742017-08-08 17:44:58 +03003274 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3275 ASSERT(framebuffer);
3276
3277 if (texture != 0)
3278 {
3279 Texture *textureObj = getTexture(texture);
3280
Martin Radev18b75ba2017-08-15 15:50:40 +03003281 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003282 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3283 numViews, baseViewIndex);
3284 }
3285 else
3286 {
3287 framebuffer->resetAttachment(this, attachment);
3288 }
3289
3290 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003291}
3292
3293void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3294 GLenum attachment,
3295 GLuint texture,
3296 GLint level,
3297 GLsizei numViews,
3298 const GLint *viewportOffsets)
3299{
Martin Radev5dae57b2017-07-14 16:15:55 +03003300 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3301 ASSERT(framebuffer);
3302
3303 if (texture != 0)
3304 {
3305 Texture *textureObj = getTexture(texture);
3306
3307 ImageIndex index = ImageIndex::Make2D(level);
3308 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3309 textureObj, numViews, viewportOffsets);
3310 }
3311 else
3312 {
3313 framebuffer->resetAttachment(this, attachment);
3314 }
3315
3316 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003317}
3318
Jamie Madillc29968b2016-01-20 11:17:23 -05003319void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3320{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003321 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003322 ASSERT(framebuffer);
3323 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003324 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003325}
3326
3327void Context::readBuffer(GLenum mode)
3328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003329 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003330 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003331 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003332}
3333
3334void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3335{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003336 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003337 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003338
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003339 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003340 ASSERT(framebuffer);
3341
3342 // The specification isn't clear what should be done when the framebuffer isn't complete.
3343 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003344 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003345}
3346
3347void Context::invalidateFramebuffer(GLenum target,
3348 GLsizei numAttachments,
3349 const GLenum *attachments)
3350{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003351 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003352 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003353
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003354 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003355 ASSERT(framebuffer);
3356
Jamie Madille98b1b52018-03-08 09:47:23 -05003357 bool complete = false;
3358 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3359 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003360 {
Jamie Madill437fa652016-05-03 15:13:24 -04003361 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003362 }
Jamie Madill437fa652016-05-03 15:13:24 -04003363
Jamie Madill4928b7c2017-06-20 12:57:39 -04003364 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003365}
3366
3367void Context::invalidateSubFramebuffer(GLenum target,
3368 GLsizei numAttachments,
3369 const GLenum *attachments,
3370 GLint x,
3371 GLint y,
3372 GLsizei width,
3373 GLsizei height)
3374{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003375 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003376 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003377
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003378 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003379 ASSERT(framebuffer);
3380
Jamie Madille98b1b52018-03-08 09:47:23 -05003381 bool complete = false;
3382 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3383 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003384 {
Jamie Madill437fa652016-05-03 15:13:24 -04003385 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003386 }
Jamie Madill437fa652016-05-03 15:13:24 -04003387
3388 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003389 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003390}
3391
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003392void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003393 GLint level,
3394 GLint internalformat,
3395 GLsizei width,
3396 GLsizei height,
3397 GLint border,
3398 GLenum format,
3399 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003400 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003401{
Jamie Madillbc918e72018-03-08 09:47:21 -05003402 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003403
3404 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003405 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003406 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3407 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003408}
3409
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003410void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003411 GLint level,
3412 GLint internalformat,
3413 GLsizei width,
3414 GLsizei height,
3415 GLsizei depth,
3416 GLint border,
3417 GLenum format,
3418 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003419 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003420{
Jamie Madillbc918e72018-03-08 09:47:21 -05003421 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003422
3423 Extents size(width, height, depth);
3424 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003425 handleError(texture->setImage(this, mGLState.getUnpackState(),
3426 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3427 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003428}
3429
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003430void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003431 GLint level,
3432 GLint xoffset,
3433 GLint yoffset,
3434 GLsizei width,
3435 GLsizei height,
3436 GLenum format,
3437 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003438 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003439{
3440 // Zero sized uploads are valid but no-ops
3441 if (width == 0 || height == 0)
3442 {
3443 return;
3444 }
3445
Jamie Madillbc918e72018-03-08 09:47:21 -05003446 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003447
3448 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003449 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003450 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3451 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003452}
3453
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003454void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003455 GLint level,
3456 GLint xoffset,
3457 GLint yoffset,
3458 GLint zoffset,
3459 GLsizei width,
3460 GLsizei height,
3461 GLsizei depth,
3462 GLenum format,
3463 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003464 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003465{
3466 // Zero sized uploads are valid but no-ops
3467 if (width == 0 || height == 0 || depth == 0)
3468 {
3469 return;
3470 }
3471
Jamie Madillbc918e72018-03-08 09:47:21 -05003472 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003473
3474 Box area(xoffset, yoffset, zoffset, width, height, depth);
3475 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003476 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3477 NonCubeTextureTypeToTarget(target), level, area, format, type,
3478 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003479}
3480
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003481void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003482 GLint level,
3483 GLenum internalformat,
3484 GLsizei width,
3485 GLsizei height,
3486 GLint border,
3487 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003488 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003489{
Jamie Madillbc918e72018-03-08 09:47:21 -05003490 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003491
3492 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003493 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003494 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3495 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003496 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003497}
3498
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003499void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003500 GLint level,
3501 GLenum internalformat,
3502 GLsizei width,
3503 GLsizei height,
3504 GLsizei depth,
3505 GLint border,
3506 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003507 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003508{
Jamie Madillbc918e72018-03-08 09:47:21 -05003509 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003510
3511 Extents size(width, height, depth);
3512 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003513 handleError(texture->setCompressedImage(
3514 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3515 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003516}
3517
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003518void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003519 GLint level,
3520 GLint xoffset,
3521 GLint yoffset,
3522 GLsizei width,
3523 GLsizei height,
3524 GLenum format,
3525 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003526 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003527{
Jamie Madillbc918e72018-03-08 09:47:21 -05003528 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003529
3530 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003531 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003532 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3533 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003535}
3536
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003537void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003538 GLint level,
3539 GLint xoffset,
3540 GLint yoffset,
3541 GLint zoffset,
3542 GLsizei width,
3543 GLsizei height,
3544 GLsizei depth,
3545 GLenum format,
3546 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003547 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003548{
3549 // Zero sized uploads are valid but no-ops
3550 if (width == 0 || height == 0)
3551 {
3552 return;
3553 }
3554
Jamie Madillbc918e72018-03-08 09:47:21 -05003555 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003556
3557 Box area(xoffset, yoffset, zoffset, width, height, depth);
3558 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003559 handleError(texture->setCompressedSubImage(
3560 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3561 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003562}
3563
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003564void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003565{
3566 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003567 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003568}
3569
Jamie Madill007530e2017-12-28 14:27:04 -05003570void Context::copyTexture(GLuint sourceId,
3571 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003572 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003573 GLuint destId,
3574 GLint destLevel,
3575 GLint internalFormat,
3576 GLenum destType,
3577 GLboolean unpackFlipY,
3578 GLboolean unpackPremultiplyAlpha,
3579 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003580{
Jamie Madillbc918e72018-03-08 09:47:21 -05003581 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003582
3583 gl::Texture *sourceTexture = getTexture(sourceId);
3584 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003585 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3586 sourceLevel, ConvertToBool(unpackFlipY),
3587 ConvertToBool(unpackPremultiplyAlpha),
3588 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003589}
3590
Jamie Madill007530e2017-12-28 14:27:04 -05003591void Context::copySubTexture(GLuint sourceId,
3592 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003593 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003594 GLuint destId,
3595 GLint destLevel,
3596 GLint xoffset,
3597 GLint yoffset,
3598 GLint x,
3599 GLint y,
3600 GLsizei width,
3601 GLsizei height,
3602 GLboolean unpackFlipY,
3603 GLboolean unpackPremultiplyAlpha,
3604 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003605{
3606 // Zero sized copies are valid but no-ops
3607 if (width == 0 || height == 0)
3608 {
3609 return;
3610 }
3611
Jamie Madillbc918e72018-03-08 09:47:21 -05003612 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003613
3614 gl::Texture *sourceTexture = getTexture(sourceId);
3615 gl::Texture *destTexture = getTexture(destId);
3616 Offset offset(xoffset, yoffset, 0);
3617 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003618 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3619 ConvertToBool(unpackFlipY),
3620 ConvertToBool(unpackPremultiplyAlpha),
3621 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003622}
3623
Jamie Madill007530e2017-12-28 14:27:04 -05003624void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003625{
Jamie Madillbc918e72018-03-08 09:47:21 -05003626 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003627
3628 gl::Texture *sourceTexture = getTexture(sourceId);
3629 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003630 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003631}
3632
Corentin Wallez336129f2017-10-17 15:55:40 -04003633void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003636 ASSERT(buffer);
3637
Geoff Lang496c02d2016-10-20 11:38:11 -07003638 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003639}
3640
Corentin Wallez336129f2017-10-17 15:55:40 -04003641void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003644 ASSERT(buffer);
3645
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003646 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003647 if (error.isError())
3648 {
Jamie Madill437fa652016-05-03 15:13:24 -04003649 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003650 return nullptr;
3651 }
3652
3653 return buffer->getMapPointer();
3654}
3655
Corentin Wallez336129f2017-10-17 15:55:40 -04003656GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003659 ASSERT(buffer);
3660
3661 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003662 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003663 if (error.isError())
3664 {
Jamie Madill437fa652016-05-03 15:13:24 -04003665 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003666 return GL_FALSE;
3667 }
3668
3669 return result;
3670}
3671
Corentin Wallez336129f2017-10-17 15:55:40 -04003672void *Context::mapBufferRange(BufferBinding target,
3673 GLintptr offset,
3674 GLsizeiptr length,
3675 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003676{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003677 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003678 ASSERT(buffer);
3679
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003680 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003681 if (error.isError())
3682 {
Jamie Madill437fa652016-05-03 15:13:24 -04003683 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003684 return nullptr;
3685 }
3686
3687 return buffer->getMapPointer();
3688}
3689
Corentin Wallez336129f2017-10-17 15:55:40 -04003690void Context::flushMappedBufferRange(BufferBinding /*target*/,
3691 GLintptr /*offset*/,
3692 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003693{
3694 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3695}
3696
Jamie Madillbc918e72018-03-08 09:47:21 -05003697Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003698{
Geoff Langa8cb2872018-03-09 16:09:40 -05003699 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003700}
3701
Jamie Madillbc918e72018-03-08 09:47:21 -05003702Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003703{
Geoff Langa8cb2872018-03-09 16:09:40 -05003704 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003705}
3706
Jamie Madillbc918e72018-03-08 09:47:21 -05003707Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003708{
Geoff Langa8cb2872018-03-09 16:09:40 -05003709 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003710}
3711
Jiajia Qin5451d532017-11-16 17:16:34 +08003712void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3713{
3714 UNIMPLEMENTED();
3715}
3716
Jamie Madillc20ab272016-06-09 07:20:46 -07003717void Context::activeTexture(GLenum texture)
3718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
Jamie Madill876429b2017-04-20 15:46:24 -04003722void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003723{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003725}
3726
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003727void Context::blendEquation(GLenum mode)
3728{
3729 mGLState.setBlendEquation(mode, mode);
3730}
3731
Jamie Madillc20ab272016-06-09 07:20:46 -07003732void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003735}
3736
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003737void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3738{
3739 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3740}
3741
Jamie Madillc20ab272016-06-09 07:20:46 -07003742void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003745}
3746
Jamie Madill876429b2017-04-20 15:46:24 -04003747void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003750}
3751
Jamie Madill876429b2017-04-20 15:46:24 -04003752void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003753{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003755}
3756
3757void Context::clearStencil(GLint s)
3758{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003759 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003760}
3761
3762void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3763{
Geoff Lang92019432017-11-20 13:09:34 -05003764 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3765 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003766}
3767
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003768void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003769{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771}
3772
3773void Context::depthFunc(GLenum func)
3774{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776}
3777
3778void Context::depthMask(GLboolean flag)
3779{
Geoff Lang92019432017-11-20 13:09:34 -05003780 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003781}
3782
Jamie Madill876429b2017-04-20 15:46:24 -04003783void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003784{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786}
3787
3788void Context::disable(GLenum cap)
3789{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791}
3792
3793void Context::disableVertexAttribArray(GLuint index)
3794{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796}
3797
3798void Context::enable(GLenum cap)
3799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003801}
3802
3803void Context::enableVertexAttribArray(GLuint index)
3804{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003805 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003806}
3807
3808void Context::frontFace(GLenum mode)
3809{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003811}
3812
3813void Context::hint(GLenum target, GLenum mode)
3814{
3815 switch (target)
3816 {
3817 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003819 break;
3820
3821 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003823 break;
3824
3825 default:
3826 UNREACHABLE();
3827 return;
3828 }
3829}
3830
3831void Context::lineWidth(GLfloat width)
3832{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003834}
3835
3836void Context::pixelStorei(GLenum pname, GLint param)
3837{
3838 switch (pname)
3839 {
3840 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003842 break;
3843
3844 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 break;
3847
3848 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850 break;
3851
3852 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003853 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003854 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003855 break;
3856
3857 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003858 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003860 break;
3861
3862 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003863 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865 break;
3866
3867 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003868 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870 break;
3871
3872 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003873 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875 break;
3876
3877 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003878 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003880 break;
3881
3882 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003883 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003885 break;
3886
3887 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003888 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003890 break;
3891
3892 default:
3893 UNREACHABLE();
3894 return;
3895 }
3896}
3897
3898void Context::polygonOffset(GLfloat factor, GLfloat units)
3899{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003901}
3902
Jamie Madill876429b2017-04-20 15:46:24 -04003903void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003904{
Geoff Lang92019432017-11-20 13:09:34 -05003905 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003906}
3907
Jiawei Shaodb342272017-09-27 10:21:45 +08003908void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3909{
3910 mGLState.setSampleMaskParams(maskNumber, mask);
3911}
3912
Jamie Madillc20ab272016-06-09 07:20:46 -07003913void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3914{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
3918void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3919{
3920 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3921 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003922 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003923 }
3924
3925 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3926 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003927 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003928 }
3929}
3930
3931void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3932{
3933 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3934 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003935 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003936 }
3937
3938 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3939 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003940 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003941 }
3942}
3943
3944void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3945{
3946 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3947 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003949 }
3950
3951 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3952 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003953 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003954 }
3955}
3956
3957void Context::vertexAttrib1f(GLuint index, GLfloat x)
3958{
3959 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003960 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003961}
3962
3963void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3964{
3965 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003966 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003967}
3968
3969void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3970{
3971 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003972 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3976{
3977 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003978 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003979}
3980
3981void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3982{
3983 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003984 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003985}
3986
3987void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3988{
3989 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003991}
3992
3993void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3994{
3995 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003996 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4000{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004void Context::vertexAttribPointer(GLuint index,
4005 GLint size,
4006 GLenum type,
4007 GLboolean normalized,
4008 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004009 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004010{
Corentin Wallez336129f2017-10-17 15:55:40 -04004011 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004012 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004013}
4014
Shao80957d92017-02-20 21:25:59 +08004015void Context::vertexAttribFormat(GLuint attribIndex,
4016 GLint size,
4017 GLenum type,
4018 GLboolean normalized,
4019 GLuint relativeOffset)
4020{
Geoff Lang92019432017-11-20 13:09:34 -05004021 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004022 relativeOffset);
4023}
4024
4025void Context::vertexAttribIFormat(GLuint attribIndex,
4026 GLint size,
4027 GLenum type,
4028 GLuint relativeOffset)
4029{
4030 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4031}
4032
4033void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4034{
Shaodde78e82017-05-22 14:13:27 +08004035 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004036}
4037
Jiajia Qin5451d532017-11-16 17:16:34 +08004038void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004039{
4040 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4041}
4042
Jamie Madillc20ab272016-06-09 07:20:46 -07004043void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4044{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004045 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004046}
4047
4048void Context::vertexAttribIPointer(GLuint index,
4049 GLint size,
4050 GLenum type,
4051 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004052 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004053{
Corentin Wallez336129f2017-10-17 15:55:40 -04004054 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4055 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004056}
4057
4058void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4059{
4060 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004061 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004062}
4063
4064void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4065{
4066 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004067 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004068}
4069
4070void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4071{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004072 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004073}
4074
4075void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4076{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004077 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004078}
4079
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004080void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4081{
4082 const VertexAttribCurrentValueData &currentValues =
4083 getGLState().getVertexAttribCurrentValue(index);
4084 const VertexArray *vao = getGLState().getVertexArray();
4085 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4086 currentValues, pname, params);
4087}
4088
4089void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4090{
4091 const VertexAttribCurrentValueData &currentValues =
4092 getGLState().getVertexAttribCurrentValue(index);
4093 const VertexArray *vao = getGLState().getVertexArray();
4094 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4095 currentValues, pname, params);
4096}
4097
4098void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4099{
4100 const VertexAttribCurrentValueData &currentValues =
4101 getGLState().getVertexAttribCurrentValue(index);
4102 const VertexArray *vao = getGLState().getVertexArray();
4103 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4104 currentValues, pname, params);
4105}
4106
4107void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4108{
4109 const VertexAttribCurrentValueData &currentValues =
4110 getGLState().getVertexAttribCurrentValue(index);
4111 const VertexArray *vao = getGLState().getVertexArray();
4112 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4113 currentValues, pname, params);
4114}
4115
Jamie Madill876429b2017-04-20 15:46:24 -04004116void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004117{
4118 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4119 QueryVertexAttribPointerv(attrib, pname, pointer);
4120}
4121
Jamie Madillc20ab272016-06-09 07:20:46 -07004122void Context::debugMessageControl(GLenum source,
4123 GLenum type,
4124 GLenum severity,
4125 GLsizei count,
4126 const GLuint *ids,
4127 GLboolean enabled)
4128{
4129 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004130 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004131 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004132}
4133
4134void Context::debugMessageInsert(GLenum source,
4135 GLenum type,
4136 GLuint id,
4137 GLenum severity,
4138 GLsizei length,
4139 const GLchar *buf)
4140{
4141 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004143}
4144
4145void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4146{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004147 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004148}
4149
4150GLuint Context::getDebugMessageLog(GLuint count,
4151 GLsizei bufSize,
4152 GLenum *sources,
4153 GLenum *types,
4154 GLuint *ids,
4155 GLenum *severities,
4156 GLsizei *lengths,
4157 GLchar *messageLog)
4158{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004159 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4160 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004161}
4162
4163void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4164{
4165 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004166 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004167 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004168}
4169
4170void Context::popDebugGroup()
4171{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004172 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004173 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004174}
4175
Corentin Wallez336129f2017-10-17 15:55:40 -04004176void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004177{
4178 Buffer *buffer = mGLState.getTargetBuffer(target);
4179 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004180 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004181}
4182
Corentin Wallez336129f2017-10-17 15:55:40 -04004183void Context::bufferSubData(BufferBinding target,
4184 GLintptr offset,
4185 GLsizeiptr size,
4186 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004187{
4188 if (data == nullptr)
4189 {
4190 return;
4191 }
4192
4193 Buffer *buffer = mGLState.getTargetBuffer(target);
4194 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004195 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004196}
4197
Jamie Madillef300b12016-10-07 15:12:09 -04004198void Context::attachShader(GLuint program, GLuint shader)
4199{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004200 Program *programObject = mState.mShaderPrograms->getProgram(program);
4201 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004202 ASSERT(programObject && shaderObject);
4203 programObject->attachShader(shaderObject);
4204}
4205
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004206const Workarounds &Context::getWorkarounds() const
4207{
4208 return mWorkarounds;
4209}
4210
Corentin Wallez336129f2017-10-17 15:55:40 -04004211void Context::copyBufferSubData(BufferBinding readTarget,
4212 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004213 GLintptr readOffset,
4214 GLintptr writeOffset,
4215 GLsizeiptr size)
4216{
4217 // if size is zero, the copy is a successful no-op
4218 if (size == 0)
4219 {
4220 return;
4221 }
4222
4223 // TODO(jmadill): cache these.
4224 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4225 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4226
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004227 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004228}
4229
Jamie Madill01a80ee2016-11-07 12:06:18 -05004230void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4231{
4232 Program *programObject = getProgram(program);
4233 // TODO(jmadill): Re-use this from the validation if possible.
4234 ASSERT(programObject);
4235 programObject->bindAttributeLocation(index, name);
4236}
4237
Corentin Wallez336129f2017-10-17 15:55:40 -04004238void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004239{
Corentin Wallez336129f2017-10-17 15:55:40 -04004240 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4241 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004242}
4243
Corentin Wallez336129f2017-10-17 15:55:40 -04004244void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004245{
4246 bindBufferRange(target, index, buffer, 0, 0);
4247}
4248
Corentin Wallez336129f2017-10-17 15:55:40 -04004249void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004250 GLuint index,
4251 GLuint buffer,
4252 GLintptr offset,
4253 GLsizeiptr size)
4254{
Corentin Wallez336129f2017-10-17 15:55:40 -04004255 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4256 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004257}
4258
Jamie Madill01a80ee2016-11-07 12:06:18 -05004259void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4260{
4261 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4262 {
4263 bindReadFramebuffer(framebuffer);
4264 }
4265
4266 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4267 {
4268 bindDrawFramebuffer(framebuffer);
4269 }
4270}
4271
4272void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4273{
4274 ASSERT(target == GL_RENDERBUFFER);
4275 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004276 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004277 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004278}
4279
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004280void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004281 GLsizei samples,
4282 GLenum internalformat,
4283 GLsizei width,
4284 GLsizei height,
4285 GLboolean fixedsamplelocations)
4286{
4287 Extents size(width, height, 1);
4288 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004289 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4290 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004291}
4292
4293void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4294{
JiangYizhou5b03f472017-01-09 10:22:53 +08004295 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4296 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004297 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004298 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004299
4300 switch (pname)
4301 {
4302 case GL_SAMPLE_POSITION:
4303 handleError(framebuffer->getSamplePosition(index, val));
4304 break;
4305 default:
4306 UNREACHABLE();
4307 }
4308}
4309
Jamie Madille8fb6402017-02-14 17:56:40 -05004310void Context::renderbufferStorage(GLenum target,
4311 GLenum internalformat,
4312 GLsizei width,
4313 GLsizei height)
4314{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004315 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4316 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4317
Jamie Madille8fb6402017-02-14 17:56:40 -05004318 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004319 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004320}
4321
4322void Context::renderbufferStorageMultisample(GLenum target,
4323 GLsizei samples,
4324 GLenum internalformat,
4325 GLsizei width,
4326 GLsizei height)
4327{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004328 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4329 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004330
4331 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004332 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004333 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004334}
4335
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004336void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4337{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004338 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004339 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004340}
4341
JiangYizhoue18e6392017-02-20 10:32:23 +08004342void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4343{
4344 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4345 QueryFramebufferParameteriv(framebuffer, pname, params);
4346}
4347
Jiajia Qin5451d532017-11-16 17:16:34 +08004348void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004349{
4350 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4351 SetFramebufferParameteri(framebuffer, pname, param);
4352}
4353
Jamie Madillb3f26b92017-07-19 15:07:41 -04004354Error Context::getScratchBuffer(size_t requstedSizeBytes,
4355 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004356{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004357 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4358 {
4359 return OutOfMemory() << "Failed to allocate internal buffer.";
4360 }
4361 return NoError();
4362}
4363
4364Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4365 angle::MemoryBuffer **zeroBufferOut) const
4366{
4367 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004368 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004369 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004370 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004371 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004372}
4373
Xinghua Cao10a4d432017-11-28 14:46:26 +08004374Error Context::prepareForDispatch()
4375{
Geoff Langa8cb2872018-03-09 16:09:40 -05004376 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004377
4378 if (isRobustResourceInitEnabled())
4379 {
4380 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4381 }
4382
4383 return NoError();
4384}
4385
Xinghua Cao2b396592017-03-29 15:36:04 +08004386void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4387{
4388 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4389 {
4390 return;
4391 }
4392
Xinghua Cao10a4d432017-11-28 14:46:26 +08004393 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004394 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004395}
4396
Jiajia Qin5451d532017-11-16 17:16:34 +08004397void Context::dispatchComputeIndirect(GLintptr indirect)
4398{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004399 ANGLE_CONTEXT_TRY(prepareForDispatch());
4400 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004401}
4402
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004403void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004404 GLsizei levels,
4405 GLenum internalFormat,
4406 GLsizei width,
4407 GLsizei height)
4408{
4409 Extents size(width, height, 1);
4410 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004411 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004412}
4413
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004414void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004415 GLsizei levels,
4416 GLenum internalFormat,
4417 GLsizei width,
4418 GLsizei height,
4419 GLsizei depth)
4420{
4421 Extents size(width, height, depth);
4422 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004423 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004424}
4425
Jiajia Qin5451d532017-11-16 17:16:34 +08004426void Context::memoryBarrier(GLbitfield barriers)
4427{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004428 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004429}
4430
4431void Context::memoryBarrierByRegion(GLbitfield barriers)
4432{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004433 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004434}
4435
Jamie Madillc1d770e2017-04-13 17:31:24 -04004436GLenum Context::checkFramebufferStatus(GLenum target)
4437{
4438 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4439 ASSERT(framebuffer);
4440
Jamie Madille98b1b52018-03-08 09:47:23 -05004441 GLenum status = GL_NONE;
4442 Error err = framebuffer->checkStatus(this, &status);
4443 if (err.isError())
4444 {
4445 handleError(err);
4446 return 0;
4447 }
4448 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004449}
4450
4451void Context::compileShader(GLuint shader)
4452{
4453 Shader *shaderObject = GetValidShader(this, shader);
4454 if (!shaderObject)
4455 {
4456 return;
4457 }
4458 shaderObject->compile(this);
4459}
4460
4461void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4462{
4463 for (int i = 0; i < n; i++)
4464 {
4465 deleteBuffer(buffers[i]);
4466 }
4467}
4468
4469void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4470{
4471 for (int i = 0; i < n; i++)
4472 {
4473 if (framebuffers[i] != 0)
4474 {
4475 deleteFramebuffer(framebuffers[i]);
4476 }
4477 }
4478}
4479
4480void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4481{
4482 for (int i = 0; i < n; i++)
4483 {
4484 deleteRenderbuffer(renderbuffers[i]);
4485 }
4486}
4487
4488void Context::deleteTextures(GLsizei n, const GLuint *textures)
4489{
4490 for (int i = 0; i < n; i++)
4491 {
4492 if (textures[i] != 0)
4493 {
4494 deleteTexture(textures[i]);
4495 }
4496 }
4497}
4498
4499void Context::detachShader(GLuint program, GLuint shader)
4500{
4501 Program *programObject = getProgram(program);
4502 ASSERT(programObject);
4503
4504 Shader *shaderObject = getShader(shader);
4505 ASSERT(shaderObject);
4506
4507 programObject->detachShader(this, shaderObject);
4508}
4509
4510void Context::genBuffers(GLsizei n, GLuint *buffers)
4511{
4512 for (int i = 0; i < n; i++)
4513 {
4514 buffers[i] = createBuffer();
4515 }
4516}
4517
4518void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4519{
4520 for (int i = 0; i < n; i++)
4521 {
4522 framebuffers[i] = createFramebuffer();
4523 }
4524}
4525
4526void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4527{
4528 for (int i = 0; i < n; i++)
4529 {
4530 renderbuffers[i] = createRenderbuffer();
4531 }
4532}
4533
4534void Context::genTextures(GLsizei n, GLuint *textures)
4535{
4536 for (int i = 0; i < n; i++)
4537 {
4538 textures[i] = createTexture();
4539 }
4540}
4541
4542void Context::getActiveAttrib(GLuint program,
4543 GLuint index,
4544 GLsizei bufsize,
4545 GLsizei *length,
4546 GLint *size,
4547 GLenum *type,
4548 GLchar *name)
4549{
4550 Program *programObject = getProgram(program);
4551 ASSERT(programObject);
4552 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4553}
4554
4555void Context::getActiveUniform(GLuint program,
4556 GLuint index,
4557 GLsizei bufsize,
4558 GLsizei *length,
4559 GLint *size,
4560 GLenum *type,
4561 GLchar *name)
4562{
4563 Program *programObject = getProgram(program);
4564 ASSERT(programObject);
4565 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4566}
4567
4568void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4569{
4570 Program *programObject = getProgram(program);
4571 ASSERT(programObject);
4572 programObject->getAttachedShaders(maxcount, count, shaders);
4573}
4574
4575GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4576{
4577 Program *programObject = getProgram(program);
4578 ASSERT(programObject);
4579 return programObject->getAttributeLocation(name);
4580}
4581
4582void Context::getBooleanv(GLenum pname, GLboolean *params)
4583{
4584 GLenum nativeType;
4585 unsigned int numParams = 0;
4586 getQueryParameterInfo(pname, &nativeType, &numParams);
4587
4588 if (nativeType == GL_BOOL)
4589 {
4590 getBooleanvImpl(pname, params);
4591 }
4592 else
4593 {
4594 CastStateValues(this, nativeType, pname, numParams, params);
4595 }
4596}
4597
4598void Context::getFloatv(GLenum pname, GLfloat *params)
4599{
4600 GLenum nativeType;
4601 unsigned int numParams = 0;
4602 getQueryParameterInfo(pname, &nativeType, &numParams);
4603
4604 if (nativeType == GL_FLOAT)
4605 {
4606 getFloatvImpl(pname, params);
4607 }
4608 else
4609 {
4610 CastStateValues(this, nativeType, pname, numParams, params);
4611 }
4612}
4613
4614void Context::getIntegerv(GLenum pname, GLint *params)
4615{
4616 GLenum nativeType;
4617 unsigned int numParams = 0;
4618 getQueryParameterInfo(pname, &nativeType, &numParams);
4619
4620 if (nativeType == GL_INT)
4621 {
4622 getIntegervImpl(pname, params);
4623 }
4624 else
4625 {
4626 CastStateValues(this, nativeType, pname, numParams, params);
4627 }
4628}
4629
4630void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4631{
4632 Program *programObject = getProgram(program);
4633 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004634 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004635}
4636
Jiajia Qin5451d532017-11-16 17:16:34 +08004637void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4638{
4639 UNIMPLEMENTED();
4640}
4641
Jamie Madillbe849e42017-05-02 15:49:00 -04004642void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004643{
4644 Program *programObject = getProgram(program);
4645 ASSERT(programObject);
4646 programObject->getInfoLog(bufsize, length, infolog);
4647}
4648
Jiajia Qin5451d532017-11-16 17:16:34 +08004649void Context::getProgramPipelineInfoLog(GLuint pipeline,
4650 GLsizei bufSize,
4651 GLsizei *length,
4652 GLchar *infoLog)
4653{
4654 UNIMPLEMENTED();
4655}
4656
Jamie Madillc1d770e2017-04-13 17:31:24 -04004657void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4658{
4659 Shader *shaderObject = getShader(shader);
4660 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004661 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004662}
4663
4664void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4665{
4666 Shader *shaderObject = getShader(shader);
4667 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004668 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004669}
4670
4671void Context::getShaderPrecisionFormat(GLenum shadertype,
4672 GLenum precisiontype,
4673 GLint *range,
4674 GLint *precision)
4675{
4676 // TODO(jmadill): Compute shaders.
4677
4678 switch (shadertype)
4679 {
4680 case GL_VERTEX_SHADER:
4681 switch (precisiontype)
4682 {
4683 case GL_LOW_FLOAT:
4684 mCaps.vertexLowpFloat.get(range, precision);
4685 break;
4686 case GL_MEDIUM_FLOAT:
4687 mCaps.vertexMediumpFloat.get(range, precision);
4688 break;
4689 case GL_HIGH_FLOAT:
4690 mCaps.vertexHighpFloat.get(range, precision);
4691 break;
4692
4693 case GL_LOW_INT:
4694 mCaps.vertexLowpInt.get(range, precision);
4695 break;
4696 case GL_MEDIUM_INT:
4697 mCaps.vertexMediumpInt.get(range, precision);
4698 break;
4699 case GL_HIGH_INT:
4700 mCaps.vertexHighpInt.get(range, precision);
4701 break;
4702
4703 default:
4704 UNREACHABLE();
4705 return;
4706 }
4707 break;
4708
4709 case GL_FRAGMENT_SHADER:
4710 switch (precisiontype)
4711 {
4712 case GL_LOW_FLOAT:
4713 mCaps.fragmentLowpFloat.get(range, precision);
4714 break;
4715 case GL_MEDIUM_FLOAT:
4716 mCaps.fragmentMediumpFloat.get(range, precision);
4717 break;
4718 case GL_HIGH_FLOAT:
4719 mCaps.fragmentHighpFloat.get(range, precision);
4720 break;
4721
4722 case GL_LOW_INT:
4723 mCaps.fragmentLowpInt.get(range, precision);
4724 break;
4725 case GL_MEDIUM_INT:
4726 mCaps.fragmentMediumpInt.get(range, precision);
4727 break;
4728 case GL_HIGH_INT:
4729 mCaps.fragmentHighpInt.get(range, precision);
4730 break;
4731
4732 default:
4733 UNREACHABLE();
4734 return;
4735 }
4736 break;
4737
4738 default:
4739 UNREACHABLE();
4740 return;
4741 }
4742}
4743
4744void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4745{
4746 Shader *shaderObject = getShader(shader);
4747 ASSERT(shaderObject);
4748 shaderObject->getSource(bufsize, length, source);
4749}
4750
4751void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4752{
4753 Program *programObject = getProgram(program);
4754 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004755 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004756}
4757
4758void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4759{
4760 Program *programObject = getProgram(program);
4761 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004762 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004763}
4764
4765GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4766{
4767 Program *programObject = getProgram(program);
4768 ASSERT(programObject);
4769 return programObject->getUniformLocation(name);
4770}
4771
4772GLboolean Context::isBuffer(GLuint buffer)
4773{
4774 if (buffer == 0)
4775 {
4776 return GL_FALSE;
4777 }
4778
4779 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4780}
4781
4782GLboolean Context::isEnabled(GLenum cap)
4783{
4784 return mGLState.getEnableFeature(cap);
4785}
4786
4787GLboolean Context::isFramebuffer(GLuint framebuffer)
4788{
4789 if (framebuffer == 0)
4790 {
4791 return GL_FALSE;
4792 }
4793
4794 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4795}
4796
4797GLboolean Context::isProgram(GLuint program)
4798{
4799 if (program == 0)
4800 {
4801 return GL_FALSE;
4802 }
4803
4804 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4805}
4806
4807GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4808{
4809 if (renderbuffer == 0)
4810 {
4811 return GL_FALSE;
4812 }
4813
4814 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4815}
4816
4817GLboolean Context::isShader(GLuint shader)
4818{
4819 if (shader == 0)
4820 {
4821 return GL_FALSE;
4822 }
4823
4824 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4825}
4826
4827GLboolean Context::isTexture(GLuint texture)
4828{
4829 if (texture == 0)
4830 {
4831 return GL_FALSE;
4832 }
4833
4834 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4835}
4836
4837void Context::linkProgram(GLuint program)
4838{
4839 Program *programObject = getProgram(program);
4840 ASSERT(programObject);
4841 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004842 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004843}
4844
4845void Context::releaseShaderCompiler()
4846{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004847 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004848}
4849
4850void Context::shaderBinary(GLsizei n,
4851 const GLuint *shaders,
4852 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004853 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004854 GLsizei length)
4855{
4856 // No binary shader formats are supported.
4857 UNIMPLEMENTED();
4858}
4859
4860void Context::shaderSource(GLuint shader,
4861 GLsizei count,
4862 const GLchar *const *string,
4863 const GLint *length)
4864{
4865 Shader *shaderObject = getShader(shader);
4866 ASSERT(shaderObject);
4867 shaderObject->setSource(count, string, length);
4868}
4869
4870void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4871{
4872 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4873}
4874
4875void Context::stencilMask(GLuint mask)
4876{
4877 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4878}
4879
4880void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4881{
4882 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4883}
4884
4885void Context::uniform1f(GLint location, GLfloat x)
4886{
4887 Program *program = mGLState.getProgram();
4888 program->setUniform1fv(location, 1, &x);
4889}
4890
4891void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4892{
4893 Program *program = mGLState.getProgram();
4894 program->setUniform1fv(location, count, v);
4895}
4896
4897void Context::uniform1i(GLint location, GLint x)
4898{
4899 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004900 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4901 {
4902 mGLState.setObjectDirty(GL_PROGRAM);
4903 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004904}
4905
4906void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4907{
4908 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004909 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4910 {
4911 mGLState.setObjectDirty(GL_PROGRAM);
4912 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004913}
4914
4915void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4916{
4917 GLfloat xy[2] = {x, y};
4918 Program *program = mGLState.getProgram();
4919 program->setUniform2fv(location, 1, xy);
4920}
4921
4922void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4923{
4924 Program *program = mGLState.getProgram();
4925 program->setUniform2fv(location, count, v);
4926}
4927
4928void Context::uniform2i(GLint location, GLint x, GLint y)
4929{
4930 GLint xy[2] = {x, y};
4931 Program *program = mGLState.getProgram();
4932 program->setUniform2iv(location, 1, xy);
4933}
4934
4935void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4936{
4937 Program *program = mGLState.getProgram();
4938 program->setUniform2iv(location, count, v);
4939}
4940
4941void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4942{
4943 GLfloat xyz[3] = {x, y, z};
4944 Program *program = mGLState.getProgram();
4945 program->setUniform3fv(location, 1, xyz);
4946}
4947
4948void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4949{
4950 Program *program = mGLState.getProgram();
4951 program->setUniform3fv(location, count, v);
4952}
4953
4954void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4955{
4956 GLint xyz[3] = {x, y, z};
4957 Program *program = mGLState.getProgram();
4958 program->setUniform3iv(location, 1, xyz);
4959}
4960
4961void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4962{
4963 Program *program = mGLState.getProgram();
4964 program->setUniform3iv(location, count, v);
4965}
4966
4967void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4968{
4969 GLfloat xyzw[4] = {x, y, z, w};
4970 Program *program = mGLState.getProgram();
4971 program->setUniform4fv(location, 1, xyzw);
4972}
4973
4974void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4975{
4976 Program *program = mGLState.getProgram();
4977 program->setUniform4fv(location, count, v);
4978}
4979
4980void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4981{
4982 GLint xyzw[4] = {x, y, z, w};
4983 Program *program = mGLState.getProgram();
4984 program->setUniform4iv(location, 1, xyzw);
4985}
4986
4987void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4988{
4989 Program *program = mGLState.getProgram();
4990 program->setUniform4iv(location, count, v);
4991}
4992
4993void Context::uniformMatrix2fv(GLint location,
4994 GLsizei count,
4995 GLboolean transpose,
4996 const GLfloat *value)
4997{
4998 Program *program = mGLState.getProgram();
4999 program->setUniformMatrix2fv(location, count, transpose, value);
5000}
5001
5002void Context::uniformMatrix3fv(GLint location,
5003 GLsizei count,
5004 GLboolean transpose,
5005 const GLfloat *value)
5006{
5007 Program *program = mGLState.getProgram();
5008 program->setUniformMatrix3fv(location, count, transpose, value);
5009}
5010
5011void Context::uniformMatrix4fv(GLint location,
5012 GLsizei count,
5013 GLboolean transpose,
5014 const GLfloat *value)
5015{
5016 Program *program = mGLState.getProgram();
5017 program->setUniformMatrix4fv(location, count, transpose, value);
5018}
5019
5020void Context::validateProgram(GLuint program)
5021{
5022 Program *programObject = getProgram(program);
5023 ASSERT(programObject);
5024 programObject->validate(mCaps);
5025}
5026
Jiajia Qin5451d532017-11-16 17:16:34 +08005027void Context::validateProgramPipeline(GLuint pipeline)
5028{
5029 UNIMPLEMENTED();
5030}
5031
Jamie Madilld04908b2017-06-09 14:15:35 -04005032void Context::getProgramBinary(GLuint program,
5033 GLsizei bufSize,
5034 GLsizei *length,
5035 GLenum *binaryFormat,
5036 void *binary)
5037{
5038 Program *programObject = getProgram(program);
5039 ASSERT(programObject != nullptr);
5040
5041 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5042}
5043
5044void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5045{
5046 Program *programObject = getProgram(program);
5047 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005048
Jamie Madilld04908b2017-06-09 14:15:35 -04005049 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5050}
5051
Jamie Madillff325f12017-08-26 15:06:05 -04005052void Context::uniform1ui(GLint location, GLuint v0)
5053{
5054 Program *program = mGLState.getProgram();
5055 program->setUniform1uiv(location, 1, &v0);
5056}
5057
5058void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5059{
5060 Program *program = mGLState.getProgram();
5061 const GLuint xy[] = {v0, v1};
5062 program->setUniform2uiv(location, 1, xy);
5063}
5064
5065void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5066{
5067 Program *program = mGLState.getProgram();
5068 const GLuint xyz[] = {v0, v1, v2};
5069 program->setUniform3uiv(location, 1, xyz);
5070}
5071
5072void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5073{
5074 Program *program = mGLState.getProgram();
5075 const GLuint xyzw[] = {v0, v1, v2, v3};
5076 program->setUniform4uiv(location, 1, xyzw);
5077}
5078
5079void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5080{
5081 Program *program = mGLState.getProgram();
5082 program->setUniform1uiv(location, count, value);
5083}
5084void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5085{
5086 Program *program = mGLState.getProgram();
5087 program->setUniform2uiv(location, count, value);
5088}
5089
5090void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5091{
5092 Program *program = mGLState.getProgram();
5093 program->setUniform3uiv(location, count, value);
5094}
5095
5096void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5097{
5098 Program *program = mGLState.getProgram();
5099 program->setUniform4uiv(location, count, value);
5100}
5101
Jamie Madillf0e04492017-08-26 15:28:42 -04005102void Context::genQueries(GLsizei n, GLuint *ids)
5103{
5104 for (GLsizei i = 0; i < n; i++)
5105 {
5106 GLuint handle = mQueryHandleAllocator.allocate();
5107 mQueryMap.assign(handle, nullptr);
5108 ids[i] = handle;
5109 }
5110}
5111
5112void Context::deleteQueries(GLsizei n, const GLuint *ids)
5113{
5114 for (int i = 0; i < n; i++)
5115 {
5116 GLuint query = ids[i];
5117
5118 Query *queryObject = nullptr;
5119 if (mQueryMap.erase(query, &queryObject))
5120 {
5121 mQueryHandleAllocator.release(query);
5122 if (queryObject)
5123 {
5124 queryObject->release(this);
5125 }
5126 }
5127 }
5128}
5129
5130GLboolean Context::isQuery(GLuint id)
5131{
5132 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5133}
5134
Jamie Madillc8c95812017-08-26 18:40:09 -04005135void Context::uniformMatrix2x3fv(GLint location,
5136 GLsizei count,
5137 GLboolean transpose,
5138 const GLfloat *value)
5139{
5140 Program *program = mGLState.getProgram();
5141 program->setUniformMatrix2x3fv(location, count, transpose, value);
5142}
5143
5144void Context::uniformMatrix3x2fv(GLint location,
5145 GLsizei count,
5146 GLboolean transpose,
5147 const GLfloat *value)
5148{
5149 Program *program = mGLState.getProgram();
5150 program->setUniformMatrix3x2fv(location, count, transpose, value);
5151}
5152
5153void Context::uniformMatrix2x4fv(GLint location,
5154 GLsizei count,
5155 GLboolean transpose,
5156 const GLfloat *value)
5157{
5158 Program *program = mGLState.getProgram();
5159 program->setUniformMatrix2x4fv(location, count, transpose, value);
5160}
5161
5162void Context::uniformMatrix4x2fv(GLint location,
5163 GLsizei count,
5164 GLboolean transpose,
5165 const GLfloat *value)
5166{
5167 Program *program = mGLState.getProgram();
5168 program->setUniformMatrix4x2fv(location, count, transpose, value);
5169}
5170
5171void Context::uniformMatrix3x4fv(GLint location,
5172 GLsizei count,
5173 GLboolean transpose,
5174 const GLfloat *value)
5175{
5176 Program *program = mGLState.getProgram();
5177 program->setUniformMatrix3x4fv(location, count, transpose, value);
5178}
5179
5180void Context::uniformMatrix4x3fv(GLint location,
5181 GLsizei count,
5182 GLboolean transpose,
5183 const GLfloat *value)
5184{
5185 Program *program = mGLState.getProgram();
5186 program->setUniformMatrix4x3fv(location, count, transpose, value);
5187}
5188
Jamie Madilld7576732017-08-26 18:49:50 -04005189void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5190{
5191 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5192 {
5193 GLuint vertexArray = arrays[arrayIndex];
5194
5195 if (arrays[arrayIndex] != 0)
5196 {
5197 VertexArray *vertexArrayObject = nullptr;
5198 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5199 {
5200 if (vertexArrayObject != nullptr)
5201 {
5202 detachVertexArray(vertexArray);
5203 vertexArrayObject->onDestroy(this);
5204 }
5205
5206 mVertexArrayHandleAllocator.release(vertexArray);
5207 }
5208 }
5209 }
5210}
5211
5212void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5213{
5214 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5215 {
5216 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5217 mVertexArrayMap.assign(vertexArray, nullptr);
5218 arrays[arrayIndex] = vertexArray;
5219 }
5220}
5221
5222bool Context::isVertexArray(GLuint array)
5223{
5224 if (array == 0)
5225 {
5226 return GL_FALSE;
5227 }
5228
5229 VertexArray *vao = getVertexArray(array);
5230 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5231}
5232
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005233void Context::endTransformFeedback()
5234{
5235 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5236 transformFeedback->end(this);
5237}
5238
5239void Context::transformFeedbackVaryings(GLuint program,
5240 GLsizei count,
5241 const GLchar *const *varyings,
5242 GLenum bufferMode)
5243{
5244 Program *programObject = getProgram(program);
5245 ASSERT(programObject);
5246 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5247}
5248
5249void Context::getTransformFeedbackVarying(GLuint program,
5250 GLuint index,
5251 GLsizei bufSize,
5252 GLsizei *length,
5253 GLsizei *size,
5254 GLenum *type,
5255 GLchar *name)
5256{
5257 Program *programObject = getProgram(program);
5258 ASSERT(programObject);
5259 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5260}
5261
5262void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5263{
5264 for (int i = 0; i < n; i++)
5265 {
5266 GLuint transformFeedback = ids[i];
5267 if (transformFeedback == 0)
5268 {
5269 continue;
5270 }
5271
5272 TransformFeedback *transformFeedbackObject = nullptr;
5273 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5274 {
5275 if (transformFeedbackObject != nullptr)
5276 {
5277 detachTransformFeedback(transformFeedback);
5278 transformFeedbackObject->release(this);
5279 }
5280
5281 mTransformFeedbackHandleAllocator.release(transformFeedback);
5282 }
5283 }
5284}
5285
5286void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5287{
5288 for (int i = 0; i < n; i++)
5289 {
5290 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5291 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5292 ids[i] = transformFeedback;
5293 }
5294}
5295
5296bool Context::isTransformFeedback(GLuint id)
5297{
5298 if (id == 0)
5299 {
5300 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5301 // returns FALSE
5302 return GL_FALSE;
5303 }
5304
5305 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5306 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5307}
5308
5309void Context::pauseTransformFeedback()
5310{
5311 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5312 transformFeedback->pause();
5313}
5314
5315void Context::resumeTransformFeedback()
5316{
5317 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5318 transformFeedback->resume();
5319}
5320
Jamie Madill12e957f2017-08-26 21:42:26 -04005321void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5322{
5323 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005324 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005325}
5326
5327GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5328{
5329 const Program *programObject = getProgram(program);
5330 return programObject->getFragDataLocation(name);
5331}
5332
5333void Context::getUniformIndices(GLuint program,
5334 GLsizei uniformCount,
5335 const GLchar *const *uniformNames,
5336 GLuint *uniformIndices)
5337{
5338 const Program *programObject = getProgram(program);
5339 if (!programObject->isLinked())
5340 {
5341 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5342 {
5343 uniformIndices[uniformId] = GL_INVALID_INDEX;
5344 }
5345 }
5346 else
5347 {
5348 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5349 {
5350 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5351 }
5352 }
5353}
5354
5355void Context::getActiveUniformsiv(GLuint program,
5356 GLsizei uniformCount,
5357 const GLuint *uniformIndices,
5358 GLenum pname,
5359 GLint *params)
5360{
5361 const Program *programObject = getProgram(program);
5362 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5363 {
5364 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005365 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005366 }
5367}
5368
5369GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5370{
5371 const Program *programObject = getProgram(program);
5372 return programObject->getUniformBlockIndex(uniformBlockName);
5373}
5374
5375void Context::getActiveUniformBlockiv(GLuint program,
5376 GLuint uniformBlockIndex,
5377 GLenum pname,
5378 GLint *params)
5379{
5380 const Program *programObject = getProgram(program);
5381 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5382}
5383
5384void Context::getActiveUniformBlockName(GLuint program,
5385 GLuint uniformBlockIndex,
5386 GLsizei bufSize,
5387 GLsizei *length,
5388 GLchar *uniformBlockName)
5389{
5390 const Program *programObject = getProgram(program);
5391 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5392}
5393
5394void Context::uniformBlockBinding(GLuint program,
5395 GLuint uniformBlockIndex,
5396 GLuint uniformBlockBinding)
5397{
5398 Program *programObject = getProgram(program);
5399 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5400}
5401
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005402GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5403{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005404 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5405 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005406
Jamie Madill70b5bb02017-08-28 13:32:37 -04005407 Sync *syncObject = getSync(syncHandle);
5408 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005409 if (error.isError())
5410 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005411 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005412 handleError(error);
5413 return nullptr;
5414 }
5415
Jamie Madill70b5bb02017-08-28 13:32:37 -04005416 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005417}
5418
5419GLboolean Context::isSync(GLsync sync)
5420{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005421 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005422}
5423
5424GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5425{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005426 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005427
5428 GLenum result = GL_WAIT_FAILED;
5429 handleError(syncObject->clientWait(flags, timeout, &result));
5430 return result;
5431}
5432
5433void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5434{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005435 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005436 handleError(syncObject->serverWait(flags, timeout));
5437}
5438
5439void Context::getInteger64v(GLenum pname, GLint64 *params)
5440{
5441 GLenum nativeType = GL_NONE;
5442 unsigned int numParams = 0;
5443 getQueryParameterInfo(pname, &nativeType, &numParams);
5444
5445 if (nativeType == GL_INT_64_ANGLEX)
5446 {
5447 getInteger64vImpl(pname, params);
5448 }
5449 else
5450 {
5451 CastStateValues(this, nativeType, pname, numParams, params);
5452 }
5453}
5454
Corentin Wallez336129f2017-10-17 15:55:40 -04005455void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005456{
5457 Buffer *buffer = mGLState.getTargetBuffer(target);
5458 QueryBufferParameteri64v(buffer, pname, params);
5459}
5460
5461void Context::genSamplers(GLsizei count, GLuint *samplers)
5462{
5463 for (int i = 0; i < count; i++)
5464 {
5465 samplers[i] = mState.mSamplers->createSampler();
5466 }
5467}
5468
5469void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5470{
5471 for (int i = 0; i < count; i++)
5472 {
5473 GLuint sampler = samplers[i];
5474
5475 if (mState.mSamplers->getSampler(sampler))
5476 {
5477 detachSampler(sampler);
5478 }
5479
5480 mState.mSamplers->deleteObject(this, sampler);
5481 }
5482}
5483
5484void Context::getInternalformativ(GLenum target,
5485 GLenum internalformat,
5486 GLenum pname,
5487 GLsizei bufSize,
5488 GLint *params)
5489{
5490 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5491 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5492}
5493
Jiajia Qin5451d532017-11-16 17:16:34 +08005494void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5495{
5496 programUniform1iv(program, location, 1, &v0);
5497}
5498
5499void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5500{
5501 GLint xy[2] = {v0, v1};
5502 programUniform2iv(program, location, 1, xy);
5503}
5504
5505void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5506{
5507 GLint xyz[3] = {v0, v1, v2};
5508 programUniform3iv(program, location, 1, xyz);
5509}
5510
5511void Context::programUniform4i(GLuint program,
5512 GLint location,
5513 GLint v0,
5514 GLint v1,
5515 GLint v2,
5516 GLint v3)
5517{
5518 GLint xyzw[4] = {v0, v1, v2, v3};
5519 programUniform4iv(program, location, 1, xyzw);
5520}
5521
5522void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5523{
5524 programUniform1uiv(program, location, 1, &v0);
5525}
5526
5527void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5528{
5529 GLuint xy[2] = {v0, v1};
5530 programUniform2uiv(program, location, 1, xy);
5531}
5532
5533void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5534{
5535 GLuint xyz[3] = {v0, v1, v2};
5536 programUniform3uiv(program, location, 1, xyz);
5537}
5538
5539void Context::programUniform4ui(GLuint program,
5540 GLint location,
5541 GLuint v0,
5542 GLuint v1,
5543 GLuint v2,
5544 GLuint v3)
5545{
5546 GLuint xyzw[4] = {v0, v1, v2, v3};
5547 programUniform4uiv(program, location, 1, xyzw);
5548}
5549
5550void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5551{
5552 programUniform1fv(program, location, 1, &v0);
5553}
5554
5555void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5556{
5557 GLfloat xy[2] = {v0, v1};
5558 programUniform2fv(program, location, 1, xy);
5559}
5560
5561void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5562{
5563 GLfloat xyz[3] = {v0, v1, v2};
5564 programUniform3fv(program, location, 1, xyz);
5565}
5566
5567void Context::programUniform4f(GLuint program,
5568 GLint location,
5569 GLfloat v0,
5570 GLfloat v1,
5571 GLfloat v2,
5572 GLfloat v3)
5573{
5574 GLfloat xyzw[4] = {v0, v1, v2, v3};
5575 programUniform4fv(program, location, 1, xyzw);
5576}
5577
Jamie Madill81c2e252017-09-09 23:32:46 -04005578void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5579{
5580 Program *programObject = getProgram(program);
5581 ASSERT(programObject);
5582 if (programObject->setUniform1iv(location, count, value) ==
5583 Program::SetUniformResult::SamplerChanged)
5584 {
5585 mGLState.setObjectDirty(GL_PROGRAM);
5586 }
5587}
5588
Jiajia Qin5451d532017-11-16 17:16:34 +08005589void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject);
5593 programObject->setUniform2iv(location, count, value);
5594}
5595
5596void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5597{
5598 Program *programObject = getProgram(program);
5599 ASSERT(programObject);
5600 programObject->setUniform3iv(location, count, value);
5601}
5602
5603void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5604{
5605 Program *programObject = getProgram(program);
5606 ASSERT(programObject);
5607 programObject->setUniform4iv(location, count, value);
5608}
5609
5610void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5611{
5612 Program *programObject = getProgram(program);
5613 ASSERT(programObject);
5614 programObject->setUniform1uiv(location, count, value);
5615}
5616
5617void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5618{
5619 Program *programObject = getProgram(program);
5620 ASSERT(programObject);
5621 programObject->setUniform2uiv(location, count, value);
5622}
5623
5624void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5625{
5626 Program *programObject = getProgram(program);
5627 ASSERT(programObject);
5628 programObject->setUniform3uiv(location, count, value);
5629}
5630
5631void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5632{
5633 Program *programObject = getProgram(program);
5634 ASSERT(programObject);
5635 programObject->setUniform4uiv(location, count, value);
5636}
5637
5638void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5639{
5640 Program *programObject = getProgram(program);
5641 ASSERT(programObject);
5642 programObject->setUniform1fv(location, count, value);
5643}
5644
5645void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5646{
5647 Program *programObject = getProgram(program);
5648 ASSERT(programObject);
5649 programObject->setUniform2fv(location, count, value);
5650}
5651
5652void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5653{
5654 Program *programObject = getProgram(program);
5655 ASSERT(programObject);
5656 programObject->setUniform3fv(location, count, value);
5657}
5658
5659void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5660{
5661 Program *programObject = getProgram(program);
5662 ASSERT(programObject);
5663 programObject->setUniform4fv(location, count, value);
5664}
5665
5666void Context::programUniformMatrix2fv(GLuint program,
5667 GLint location,
5668 GLsizei count,
5669 GLboolean transpose,
5670 const GLfloat *value)
5671{
5672 Program *programObject = getProgram(program);
5673 ASSERT(programObject);
5674 programObject->setUniformMatrix2fv(location, count, transpose, value);
5675}
5676
5677void Context::programUniformMatrix3fv(GLuint program,
5678 GLint location,
5679 GLsizei count,
5680 GLboolean transpose,
5681 const GLfloat *value)
5682{
5683 Program *programObject = getProgram(program);
5684 ASSERT(programObject);
5685 programObject->setUniformMatrix3fv(location, count, transpose, value);
5686}
5687
5688void Context::programUniformMatrix4fv(GLuint program,
5689 GLint location,
5690 GLsizei count,
5691 GLboolean transpose,
5692 const GLfloat *value)
5693{
5694 Program *programObject = getProgram(program);
5695 ASSERT(programObject);
5696 programObject->setUniformMatrix4fv(location, count, transpose, value);
5697}
5698
5699void Context::programUniformMatrix2x3fv(GLuint program,
5700 GLint location,
5701 GLsizei count,
5702 GLboolean transpose,
5703 const GLfloat *value)
5704{
5705 Program *programObject = getProgram(program);
5706 ASSERT(programObject);
5707 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5708}
5709
5710void Context::programUniformMatrix3x2fv(GLuint program,
5711 GLint location,
5712 GLsizei count,
5713 GLboolean transpose,
5714 const GLfloat *value)
5715{
5716 Program *programObject = getProgram(program);
5717 ASSERT(programObject);
5718 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5719}
5720
5721void Context::programUniformMatrix2x4fv(GLuint program,
5722 GLint location,
5723 GLsizei count,
5724 GLboolean transpose,
5725 const GLfloat *value)
5726{
5727 Program *programObject = getProgram(program);
5728 ASSERT(programObject);
5729 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5730}
5731
5732void Context::programUniformMatrix4x2fv(GLuint program,
5733 GLint location,
5734 GLsizei count,
5735 GLboolean transpose,
5736 const GLfloat *value)
5737{
5738 Program *programObject = getProgram(program);
5739 ASSERT(programObject);
5740 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5741}
5742
5743void Context::programUniformMatrix3x4fv(GLuint program,
5744 GLint location,
5745 GLsizei count,
5746 GLboolean transpose,
5747 const GLfloat *value)
5748{
5749 Program *programObject = getProgram(program);
5750 ASSERT(programObject);
5751 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5752}
5753
5754void Context::programUniformMatrix4x3fv(GLuint program,
5755 GLint location,
5756 GLsizei count,
5757 GLboolean transpose,
5758 const GLfloat *value)
5759{
5760 Program *programObject = getProgram(program);
5761 ASSERT(programObject);
5762 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5763}
5764
Jamie Madill81c2e252017-09-09 23:32:46 -04005765void Context::onTextureChange(const Texture *texture)
5766{
5767 // Conservatively assume all textures are dirty.
5768 // TODO(jmadill): More fine-grained update.
5769 mGLState.setObjectDirty(GL_TEXTURE);
5770}
5771
James Darpiniane8a93c62018-01-04 18:02:24 -08005772bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5773{
5774 return mGLState.isCurrentTransformFeedback(tf);
5775}
5776bool Context::isCurrentVertexArray(const VertexArray *va) const
5777{
5778 return mGLState.isCurrentVertexArray(va);
5779}
5780
Yunchao Hea336b902017-08-02 16:05:21 +08005781void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5782{
5783 for (int i = 0; i < count; i++)
5784 {
5785 pipelines[i] = createProgramPipeline();
5786 }
5787}
5788
5789void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5790{
5791 for (int i = 0; i < count; i++)
5792 {
5793 if (pipelines[i] != 0)
5794 {
5795 deleteProgramPipeline(pipelines[i]);
5796 }
5797 }
5798}
5799
5800GLboolean Context::isProgramPipeline(GLuint pipeline)
5801{
5802 if (pipeline == 0)
5803 {
5804 return GL_FALSE;
5805 }
5806
5807 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5808}
5809
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005810void Context::finishFenceNV(GLuint fence)
5811{
5812 FenceNV *fenceObject = getFenceNV(fence);
5813
5814 ASSERT(fenceObject && fenceObject->isSet());
5815 handleError(fenceObject->finish());
5816}
5817
5818void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5819{
5820 FenceNV *fenceObject = getFenceNV(fence);
5821
5822 ASSERT(fenceObject && fenceObject->isSet());
5823
5824 switch (pname)
5825 {
5826 case GL_FENCE_STATUS_NV:
5827 {
5828 // GL_NV_fence spec:
5829 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5830 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5831 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5832 GLboolean status = GL_TRUE;
5833 if (fenceObject->getStatus() != GL_TRUE)
5834 {
5835 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5836 }
5837 *params = status;
5838 break;
5839 }
5840
5841 case GL_FENCE_CONDITION_NV:
5842 {
5843 *params = static_cast<GLint>(fenceObject->getCondition());
5844 break;
5845 }
5846
5847 default:
5848 UNREACHABLE();
5849 }
5850}
5851
5852void Context::getTranslatedShaderSource(GLuint shader,
5853 GLsizei bufsize,
5854 GLsizei *length,
5855 GLchar *source)
5856{
5857 Shader *shaderObject = getShader(shader);
5858 ASSERT(shaderObject);
5859 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5860}
5861
5862void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5863{
5864 Program *programObject = getProgram(program);
5865 ASSERT(programObject);
5866
5867 programObject->getUniformfv(this, location, params);
5868}
5869
5870void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5871{
5872 Program *programObject = getProgram(program);
5873 ASSERT(programObject);
5874
5875 programObject->getUniformiv(this, location, params);
5876}
5877
5878GLboolean Context::isFenceNV(GLuint fence)
5879{
5880 FenceNV *fenceObject = getFenceNV(fence);
5881
5882 if (fenceObject == nullptr)
5883 {
5884 return GL_FALSE;
5885 }
5886
5887 // GL_NV_fence spec:
5888 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5889 // existing fence.
5890 return fenceObject->isSet();
5891}
5892
5893void Context::readnPixels(GLint x,
5894 GLint y,
5895 GLsizei width,
5896 GLsizei height,
5897 GLenum format,
5898 GLenum type,
5899 GLsizei bufSize,
5900 void *data)
5901{
5902 return readPixels(x, y, width, height, format, type, data);
5903}
5904
Jamie Madill007530e2017-12-28 14:27:04 -05005905void Context::setFenceNV(GLuint fence, GLenum condition)
5906{
5907 ASSERT(condition == GL_ALL_COMPLETED_NV);
5908
5909 FenceNV *fenceObject = getFenceNV(fence);
5910 ASSERT(fenceObject != nullptr);
5911 handleError(fenceObject->set(condition));
5912}
5913
5914GLboolean Context::testFenceNV(GLuint fence)
5915{
5916 FenceNV *fenceObject = getFenceNV(fence);
5917
5918 ASSERT(fenceObject != nullptr);
5919 ASSERT(fenceObject->isSet() == GL_TRUE);
5920
5921 GLboolean result = GL_TRUE;
5922 Error error = fenceObject->test(&result);
5923 if (error.isError())
5924 {
5925 handleError(error);
5926 return GL_TRUE;
5927 }
5928
5929 return result;
5930}
5931
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005932void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005933{
5934 Texture *texture = getTargetTexture(target);
5935 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005936 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005937}
5938
Jamie Madillfa920eb2018-01-04 11:45:50 -05005939void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005940{
5941 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5942 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5943 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5944}
5945
Jamie Madillfa920eb2018-01-04 11:45:50 -05005946void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5947{
5948 UNIMPLEMENTED();
5949}
5950
Jamie Madill5b772312018-03-08 20:28:32 -05005951bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
5952{
5953 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
5954 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
5955 // to the fact that it is stored internally as a float, and so would require conversion
5956 // if returned from Context::getIntegerv. Since this conversion is already implemented
5957 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
5958 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
5959 // application.
5960 switch (pname)
5961 {
5962 case GL_COMPRESSED_TEXTURE_FORMATS:
5963 {
5964 *type = GL_INT;
5965 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
5966 return true;
5967 }
5968 case GL_SHADER_BINARY_FORMATS:
5969 {
5970 *type = GL_INT;
5971 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
5972 return true;
5973 }
5974
5975 case GL_MAX_VERTEX_ATTRIBS:
5976 case GL_MAX_VERTEX_UNIFORM_VECTORS:
5977 case GL_MAX_VARYING_VECTORS:
5978 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
5979 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
5980 case GL_MAX_TEXTURE_IMAGE_UNITS:
5981 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
5982 case GL_MAX_RENDERBUFFER_SIZE:
5983 case GL_NUM_SHADER_BINARY_FORMATS:
5984 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
5985 case GL_ARRAY_BUFFER_BINDING:
5986 case GL_FRAMEBUFFER_BINDING:
5987 case GL_RENDERBUFFER_BINDING:
5988 case GL_CURRENT_PROGRAM:
5989 case GL_PACK_ALIGNMENT:
5990 case GL_UNPACK_ALIGNMENT:
5991 case GL_GENERATE_MIPMAP_HINT:
5992 case GL_RED_BITS:
5993 case GL_GREEN_BITS:
5994 case GL_BLUE_BITS:
5995 case GL_ALPHA_BITS:
5996 case GL_DEPTH_BITS:
5997 case GL_STENCIL_BITS:
5998 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
5999 case GL_CULL_FACE_MODE:
6000 case GL_FRONT_FACE:
6001 case GL_ACTIVE_TEXTURE:
6002 case GL_STENCIL_FUNC:
6003 case GL_STENCIL_VALUE_MASK:
6004 case GL_STENCIL_REF:
6005 case GL_STENCIL_FAIL:
6006 case GL_STENCIL_PASS_DEPTH_FAIL:
6007 case GL_STENCIL_PASS_DEPTH_PASS:
6008 case GL_STENCIL_BACK_FUNC:
6009 case GL_STENCIL_BACK_VALUE_MASK:
6010 case GL_STENCIL_BACK_REF:
6011 case GL_STENCIL_BACK_FAIL:
6012 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6013 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6014 case GL_DEPTH_FUNC:
6015 case GL_BLEND_SRC_RGB:
6016 case GL_BLEND_SRC_ALPHA:
6017 case GL_BLEND_DST_RGB:
6018 case GL_BLEND_DST_ALPHA:
6019 case GL_BLEND_EQUATION_RGB:
6020 case GL_BLEND_EQUATION_ALPHA:
6021 case GL_STENCIL_WRITEMASK:
6022 case GL_STENCIL_BACK_WRITEMASK:
6023 case GL_STENCIL_CLEAR_VALUE:
6024 case GL_SUBPIXEL_BITS:
6025 case GL_MAX_TEXTURE_SIZE:
6026 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6027 case GL_SAMPLE_BUFFERS:
6028 case GL_SAMPLES:
6029 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6030 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6031 case GL_TEXTURE_BINDING_2D:
6032 case GL_TEXTURE_BINDING_CUBE_MAP:
6033 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6034 {
6035 *type = GL_INT;
6036 *numParams = 1;
6037 return true;
6038 }
6039 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6040 {
6041 if (!getExtensions().packReverseRowOrder)
6042 {
6043 return false;
6044 }
6045 *type = GL_INT;
6046 *numParams = 1;
6047 return true;
6048 }
6049 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6050 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6051 {
6052 if (!getExtensions().textureRectangle)
6053 {
6054 return false;
6055 }
6056 *type = GL_INT;
6057 *numParams = 1;
6058 return true;
6059 }
6060 case GL_MAX_DRAW_BUFFERS_EXT:
6061 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6062 {
6063 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6064 {
6065 return false;
6066 }
6067 *type = GL_INT;
6068 *numParams = 1;
6069 return true;
6070 }
6071 case GL_MAX_VIEWPORT_DIMS:
6072 {
6073 *type = GL_INT;
6074 *numParams = 2;
6075 return true;
6076 }
6077 case GL_VIEWPORT:
6078 case GL_SCISSOR_BOX:
6079 {
6080 *type = GL_INT;
6081 *numParams = 4;
6082 return true;
6083 }
6084 case GL_SHADER_COMPILER:
6085 case GL_SAMPLE_COVERAGE_INVERT:
6086 case GL_DEPTH_WRITEMASK:
6087 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6088 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6089 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6090 // bool-natural
6091 case GL_SAMPLE_COVERAGE:
6092 case GL_SCISSOR_TEST:
6093 case GL_STENCIL_TEST:
6094 case GL_DEPTH_TEST:
6095 case GL_BLEND:
6096 case GL_DITHER:
6097 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6098 {
6099 *type = GL_BOOL;
6100 *numParams = 1;
6101 return true;
6102 }
6103 case GL_COLOR_WRITEMASK:
6104 {
6105 *type = GL_BOOL;
6106 *numParams = 4;
6107 return true;
6108 }
6109 case GL_POLYGON_OFFSET_FACTOR:
6110 case GL_POLYGON_OFFSET_UNITS:
6111 case GL_SAMPLE_COVERAGE_VALUE:
6112 case GL_DEPTH_CLEAR_VALUE:
6113 case GL_LINE_WIDTH:
6114 {
6115 *type = GL_FLOAT;
6116 *numParams = 1;
6117 return true;
6118 }
6119 case GL_ALIASED_LINE_WIDTH_RANGE:
6120 case GL_ALIASED_POINT_SIZE_RANGE:
6121 case GL_DEPTH_RANGE:
6122 {
6123 *type = GL_FLOAT;
6124 *numParams = 2;
6125 return true;
6126 }
6127 case GL_COLOR_CLEAR_VALUE:
6128 case GL_BLEND_COLOR:
6129 {
6130 *type = GL_FLOAT;
6131 *numParams = 4;
6132 return true;
6133 }
6134 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6135 if (!getExtensions().textureFilterAnisotropic)
6136 {
6137 return false;
6138 }
6139 *type = GL_FLOAT;
6140 *numParams = 1;
6141 return true;
6142 case GL_TIMESTAMP_EXT:
6143 if (!getExtensions().disjointTimerQuery)
6144 {
6145 return false;
6146 }
6147 *type = GL_INT_64_ANGLEX;
6148 *numParams = 1;
6149 return true;
6150 case GL_GPU_DISJOINT_EXT:
6151 if (!getExtensions().disjointTimerQuery)
6152 {
6153 return false;
6154 }
6155 *type = GL_INT;
6156 *numParams = 1;
6157 return true;
6158 case GL_COVERAGE_MODULATION_CHROMIUM:
6159 if (!getExtensions().framebufferMixedSamples)
6160 {
6161 return false;
6162 }
6163 *type = GL_INT;
6164 *numParams = 1;
6165 return true;
6166 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6167 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6168 {
6169 return false;
6170 }
6171 *type = GL_INT;
6172 *numParams = 1;
6173 return true;
6174 }
6175
6176 if (getExtensions().debug)
6177 {
6178 switch (pname)
6179 {
6180 case GL_DEBUG_LOGGED_MESSAGES:
6181 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6182 case GL_DEBUG_GROUP_STACK_DEPTH:
6183 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6184 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6185 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6186 case GL_MAX_LABEL_LENGTH:
6187 *type = GL_INT;
6188 *numParams = 1;
6189 return true;
6190
6191 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6192 case GL_DEBUG_OUTPUT:
6193 *type = GL_BOOL;
6194 *numParams = 1;
6195 return true;
6196 }
6197 }
6198
6199 if (getExtensions().multisampleCompatibility)
6200 {
6201 switch (pname)
6202 {
6203 case GL_MULTISAMPLE_EXT:
6204 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6205 *type = GL_BOOL;
6206 *numParams = 1;
6207 return true;
6208 }
6209 }
6210
6211 if (getExtensions().pathRendering)
6212 {
6213 switch (pname)
6214 {
6215 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6216 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6217 *type = GL_FLOAT;
6218 *numParams = 16;
6219 return true;
6220 }
6221 }
6222
6223 if (getExtensions().bindGeneratesResource)
6224 {
6225 switch (pname)
6226 {
6227 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6228 *type = GL_BOOL;
6229 *numParams = 1;
6230 return true;
6231 }
6232 }
6233
6234 if (getExtensions().clientArrays)
6235 {
6236 switch (pname)
6237 {
6238 case GL_CLIENT_ARRAYS_ANGLE:
6239 *type = GL_BOOL;
6240 *numParams = 1;
6241 return true;
6242 }
6243 }
6244
6245 if (getExtensions().sRGBWriteControl)
6246 {
6247 switch (pname)
6248 {
6249 case GL_FRAMEBUFFER_SRGB_EXT:
6250 *type = GL_BOOL;
6251 *numParams = 1;
6252 return true;
6253 }
6254 }
6255
6256 if (getExtensions().robustResourceInitialization &&
6257 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6258 {
6259 *type = GL_BOOL;
6260 *numParams = 1;
6261 return true;
6262 }
6263
6264 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6265 {
6266 *type = GL_BOOL;
6267 *numParams = 1;
6268 return true;
6269 }
6270
6271 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6272 switch (pname)
6273 {
6274 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6275 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6276 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6277 {
6278 return false;
6279 }
6280 *type = GL_INT;
6281 *numParams = 1;
6282 return true;
6283
6284 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6285 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6286 {
6287 return false;
6288 }
6289 *type = GL_INT;
6290 *numParams = 1;
6291 return true;
6292
6293 case GL_PROGRAM_BINARY_FORMATS_OES:
6294 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6295 {
6296 return false;
6297 }
6298 *type = GL_INT;
6299 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6300 return true;
6301
6302 case GL_PACK_ROW_LENGTH:
6303 case GL_PACK_SKIP_ROWS:
6304 case GL_PACK_SKIP_PIXELS:
6305 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6306 {
6307 return false;
6308 }
6309 *type = GL_INT;
6310 *numParams = 1;
6311 return true;
6312 case GL_UNPACK_ROW_LENGTH:
6313 case GL_UNPACK_SKIP_ROWS:
6314 case GL_UNPACK_SKIP_PIXELS:
6315 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6316 {
6317 return false;
6318 }
6319 *type = GL_INT;
6320 *numParams = 1;
6321 return true;
6322 case GL_VERTEX_ARRAY_BINDING:
6323 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6324 {
6325 return false;
6326 }
6327 *type = GL_INT;
6328 *numParams = 1;
6329 return true;
6330 case GL_PIXEL_PACK_BUFFER_BINDING:
6331 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6332 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6333 {
6334 return false;
6335 }
6336 *type = GL_INT;
6337 *numParams = 1;
6338 return true;
6339 case GL_MAX_SAMPLES:
6340 {
6341 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6342 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6343 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6344 {
6345 return false;
6346 }
6347 *type = GL_INT;
6348 *numParams = 1;
6349 return true;
6350
6351 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6352 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6353 {
6354 return false;
6355 }
6356 *type = GL_INT;
6357 *numParams = 1;
6358 return true;
6359 }
6360 }
6361
6362 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6363 {
6364 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6365 {
6366 return false;
6367 }
6368 *type = GL_INT;
6369 *numParams = 1;
6370 return true;
6371 }
6372
6373 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6374 {
6375 *type = GL_INT;
6376 *numParams = 1;
6377 return true;
6378 }
6379
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006380 if (getClientVersion() < Version(2, 0))
6381 {
6382 switch (pname)
6383 {
6384 case GL_ALPHA_TEST_FUNC:
6385 *type = GL_INT;
6386 *numParams = 1;
6387 return true;
6388 case GL_ALPHA_TEST_REF:
6389 *type = GL_FLOAT;
6390 *numParams = 1;
6391 return true;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07006392 case GL_MAX_TEXTURE_UNITS:
6393 *type = GL_INT;
6394 *numParams = 1;
6395 return true;
6396 case GL_CLIENT_ACTIVE_TEXTURE:
6397 *type = GL_INT;
6398 *numParams = 1;
6399 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006400 case GL_CURRENT_COLOR:
6401 *type = GL_FLOAT;
6402 *numParams = 4;
6403 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006404 }
6405 }
6406
Jamie Madill5b772312018-03-08 20:28:32 -05006407 if (getClientVersion() < Version(3, 0))
6408 {
6409 return false;
6410 }
6411
6412 // Check for ES3.0+ parameter names
6413 switch (pname)
6414 {
6415 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6416 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6417 case GL_UNIFORM_BUFFER_BINDING:
6418 case GL_TRANSFORM_FEEDBACK_BINDING:
6419 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6420 case GL_COPY_READ_BUFFER_BINDING:
6421 case GL_COPY_WRITE_BUFFER_BINDING:
6422 case GL_SAMPLER_BINDING:
6423 case GL_READ_BUFFER:
6424 case GL_TEXTURE_BINDING_3D:
6425 case GL_TEXTURE_BINDING_2D_ARRAY:
6426 case GL_MAX_3D_TEXTURE_SIZE:
6427 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6428 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6429 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6430 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6431 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6432 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6433 case GL_MAX_VARYING_COMPONENTS:
6434 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6435 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6436 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6437 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6438 case GL_NUM_EXTENSIONS:
6439 case GL_MAJOR_VERSION:
6440 case GL_MINOR_VERSION:
6441 case GL_MAX_ELEMENTS_INDICES:
6442 case GL_MAX_ELEMENTS_VERTICES:
6443 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6444 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6445 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6446 case GL_UNPACK_IMAGE_HEIGHT:
6447 case GL_UNPACK_SKIP_IMAGES:
6448 {
6449 *type = GL_INT;
6450 *numParams = 1;
6451 return true;
6452 }
6453
6454 case GL_MAX_ELEMENT_INDEX:
6455 case GL_MAX_UNIFORM_BLOCK_SIZE:
6456 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6457 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6458 case GL_MAX_SERVER_WAIT_TIMEOUT:
6459 {
6460 *type = GL_INT_64_ANGLEX;
6461 *numParams = 1;
6462 return true;
6463 }
6464
6465 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6466 case GL_TRANSFORM_FEEDBACK_PAUSED:
6467 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6468 case GL_RASTERIZER_DISCARD:
6469 {
6470 *type = GL_BOOL;
6471 *numParams = 1;
6472 return true;
6473 }
6474
6475 case GL_MAX_TEXTURE_LOD_BIAS:
6476 {
6477 *type = GL_FLOAT;
6478 *numParams = 1;
6479 return true;
6480 }
6481 }
6482
6483 if (getExtensions().requestExtension)
6484 {
6485 switch (pname)
6486 {
6487 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6488 *type = GL_INT;
6489 *numParams = 1;
6490 return true;
6491 }
6492 }
6493
6494 if (getClientVersion() < Version(3, 1))
6495 {
6496 return false;
6497 }
6498
6499 switch (pname)
6500 {
6501 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6502 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6503 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6504 case GL_MAX_FRAMEBUFFER_WIDTH:
6505 case GL_MAX_FRAMEBUFFER_HEIGHT:
6506 case GL_MAX_FRAMEBUFFER_SAMPLES:
6507 case GL_MAX_SAMPLE_MASK_WORDS:
6508 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6509 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6510 case GL_MAX_INTEGER_SAMPLES:
6511 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6512 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6513 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6514 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6515 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6516 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6517 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6518 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6519 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6520 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6521 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6522 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6523 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6524 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6525 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6526 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6527 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6528 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
6529 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
6530 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
6531 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
6532 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
6533 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
6534 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
6535 case GL_MAX_UNIFORM_LOCATIONS:
6536 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
6537 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
6538 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
6539 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
6540 case GL_MAX_IMAGE_UNITS:
6541 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
6542 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
6543 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
6544 case GL_SHADER_STORAGE_BUFFER_BINDING:
6545 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
6546 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
6547 *type = GL_INT;
6548 *numParams = 1;
6549 return true;
6550 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
6551 *type = GL_INT_64_ANGLEX;
6552 *numParams = 1;
6553 return true;
6554 case GL_SAMPLE_MASK:
6555 *type = GL_BOOL;
6556 *numParams = 1;
6557 return true;
6558 }
6559
6560 if (getExtensions().geometryShader)
6561 {
6562 switch (pname)
6563 {
6564 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
6565 case GL_LAYER_PROVOKING_VERTEX_EXT:
6566 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
6567 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
6568 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
6569 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
6570 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
6571 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
6572 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
6573 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
6574 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
6575 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
6576 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
6577 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
6578 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
6579 *type = GL_INT;
6580 *numParams = 1;
6581 return true;
6582 }
6583 }
6584
6585 return false;
6586}
6587
6588bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
6589{
6590 if (getClientVersion() < Version(3, 0))
6591 {
6592 return false;
6593 }
6594
6595 switch (target)
6596 {
6597 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6598 case GL_UNIFORM_BUFFER_BINDING:
6599 {
6600 *type = GL_INT;
6601 *numParams = 1;
6602 return true;
6603 }
6604 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
6605 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
6606 case GL_UNIFORM_BUFFER_START:
6607 case GL_UNIFORM_BUFFER_SIZE:
6608 {
6609 *type = GL_INT_64_ANGLEX;
6610 *numParams = 1;
6611 return true;
6612 }
6613 }
6614
6615 if (getClientVersion() < Version(3, 1))
6616 {
6617 return false;
6618 }
6619
6620 switch (target)
6621 {
6622 case GL_IMAGE_BINDING_LAYERED:
6623 {
6624 *type = GL_BOOL;
6625 *numParams = 1;
6626 return true;
6627 }
6628 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
6629 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
6630 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6631 case GL_SHADER_STORAGE_BUFFER_BINDING:
6632 case GL_VERTEX_BINDING_BUFFER:
6633 case GL_VERTEX_BINDING_DIVISOR:
6634 case GL_VERTEX_BINDING_OFFSET:
6635 case GL_VERTEX_BINDING_STRIDE:
6636 case GL_SAMPLE_MASK_VALUE:
6637 case GL_IMAGE_BINDING_NAME:
6638 case GL_IMAGE_BINDING_LEVEL:
6639 case GL_IMAGE_BINDING_LAYER:
6640 case GL_IMAGE_BINDING_ACCESS:
6641 case GL_IMAGE_BINDING_FORMAT:
6642 {
6643 *type = GL_INT;
6644 *numParams = 1;
6645 return true;
6646 }
6647 case GL_ATOMIC_COUNTER_BUFFER_START:
6648 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
6649 case GL_SHADER_STORAGE_BUFFER_START:
6650 case GL_SHADER_STORAGE_BUFFER_SIZE:
6651 {
6652 *type = GL_INT_64_ANGLEX;
6653 *numParams = 1;
6654 return true;
6655 }
6656 }
6657
6658 return false;
6659}
6660
6661Program *Context::getProgram(GLuint handle) const
6662{
6663 return mState.mShaderPrograms->getProgram(handle);
6664}
6665
6666Shader *Context::getShader(GLuint handle) const
6667{
6668 return mState.mShaderPrograms->getShader(handle);
6669}
6670
6671bool Context::isTextureGenerated(GLuint texture) const
6672{
6673 return mState.mTextures->isHandleGenerated(texture);
6674}
6675
6676bool Context::isBufferGenerated(GLuint buffer) const
6677{
6678 return mState.mBuffers->isHandleGenerated(buffer);
6679}
6680
6681bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
6682{
6683 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
6684}
6685
6686bool Context::isFramebufferGenerated(GLuint framebuffer) const
6687{
6688 return mState.mFramebuffers->isHandleGenerated(framebuffer);
6689}
6690
6691bool Context::isProgramPipelineGenerated(GLuint pipeline) const
6692{
6693 return mState.mPipelines->isHandleGenerated(pipeline);
6694}
6695
6696bool Context::usingDisplayTextureShareGroup() const
6697{
6698 return mDisplayTextureShareGroup;
6699}
6700
6701GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
6702{
6703 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
6704 internalformat == GL_DEPTH_STENCIL
6705 ? GL_DEPTH24_STENCIL8
6706 : internalformat;
6707}
6708
Jamie Madillc29968b2016-01-20 11:17:23 -05006709} // namespace gl